Merge pull request 'Improve TimeTechKO performance and behaviour' (#348) from betterTimeTechKO into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #348 Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Commit
4867505899
@ -19,87 +19,95 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
|
||||||
import de.steamwar.fightsystem.countdown.Countdown;
|
import de.steamwar.fightsystem.countdown.Countdown;
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.listener.Recording;
|
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
|
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||||
import de.steamwar.fightsystem.states.StateDependentTask;
|
import de.steamwar.fightsystem.states.StateDependentTask;
|
||||||
import de.steamwar.fightsystem.utils.Message;
|
import de.steamwar.fightsystem.utils.Message;
|
||||||
import de.steamwar.fightsystem.utils.SWSound;
|
import de.steamwar.fightsystem.utils.SWSound;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
|
|
||||||
public class WinconditionTimeTechKO extends Wincondition {
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class WinconditionTimeTechKO extends Wincondition implements Listener {
|
||||||
|
|
||||||
private static final int TECH_KO_TIME_IN_S = 90;
|
private static final int TECH_KO_TIME_IN_S = 90;
|
||||||
private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S*10;
|
private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S/2;
|
||||||
|
|
||||||
private final double toggle = Config.SpecSpawn.getZ();
|
private final Map<Integer, FightTeam> spawnLocations = new HashMap<>();
|
||||||
private final FightTeam smallerZteam;
|
private final Map<FightTeam, TechKOCountdown> countdowns = new HashMap<>();
|
||||||
private final FightTeam biggerZteam;
|
private final Map<FightTeam, Integer> currentTime = new HashMap<>();
|
||||||
|
|
||||||
private int smallerZtime = TECH_KO_HALF_TIME;
|
|
||||||
private int biggerZtime = TECH_KO_HALF_TIME;
|
|
||||||
private TechKOCountdown smallerZcountdown = null;
|
|
||||||
private TechKOCountdown biggerZcountdown = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Works only for z-Axis fight direction for performance reasons
|
|
||||||
*/
|
|
||||||
public WinconditionTimeTechKO(){
|
public WinconditionTimeTechKO(){
|
||||||
super("TechKO");
|
super("TechKO");
|
||||||
|
|
||||||
if(Config.blueNegZ()) {
|
new StateDependentListener(Winconditions.TIME_TECH_KO, FightState.Running, this);
|
||||||
smallerZteam = Fight.getBlueTeam();
|
new StateDependentTask(Winconditions.TIME_TECH_KO, FightState.Running, this::run, 20, 20);
|
||||||
biggerZteam = Fight.getRedTeam();
|
new StateDependent(Winconditions.TIME_TECH_KO, FightState.Running) {
|
||||||
}else{
|
@Override
|
||||||
smallerZteam = Fight.getRedTeam();
|
public void enable() {
|
||||||
biggerZteam = Fight.getBlueTeam();
|
Fight.teams().forEach(team -> currentTime.put(team, TECH_KO_HALF_TIME));
|
||||||
}
|
}
|
||||||
|
|
||||||
new StateDependentTask(Winconditions.TIME_TECH_KO, FightState.Running, this::run, 1, 1){
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
super.disable();
|
spawnLocations.clear();
|
||||||
if(smallerZcountdown != null){
|
currentTime.clear();
|
||||||
smallerZcountdown.disable();
|
countdowns.values().forEach(Countdown::disable);
|
||||||
smallerZcountdown = null;
|
countdowns.clear();
|
||||||
}
|
}
|
||||||
if(biggerZcountdown != null){
|
}.register();
|
||||||
biggerZcountdown.disable();
|
}
|
||||||
biggerZcountdown = null;
|
|
||||||
|
@EventHandler
|
||||||
|
public void onSpawn(EntitySpawnEvent e) {
|
||||||
|
if(e.getEntityType() != EntityType.PRIMED_TNT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Location location = e.getLocation();
|
||||||
|
for(FightTeam team : Fight.teams()) {
|
||||||
|
if(team.getExtendRegion().inRegion(location)) {
|
||||||
|
spawnLocations.put(e.getEntity().getEntityId(), team);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onExplode(EntityExplodeEvent e) {
|
||||||
|
if(e.getEntityType() != EntityType.PRIMED_TNT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
FightTeam spawn = spawnLocations.remove(e.getEntity().getEntityId());
|
||||||
|
if(spawn == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Location location = e.getLocation();
|
||||||
|
for(FightTeam team : Fight.teams()) {
|
||||||
|
if(team != spawn && team.getExtendRegion().inRegion(location)) {
|
||||||
|
currentTime.put(spawn, TECH_KO_HALF_TIME);
|
||||||
|
TechKOCountdown countdown = countdowns.remove(spawn);
|
||||||
|
if(countdown != null)
|
||||||
|
countdown.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void run(){
|
private void run(){
|
||||||
Recording.iterateOverEntities(Recording.primedTnt::isInstance, tnt -> {
|
currentTime.entrySet().forEach(entry -> {
|
||||||
double z = tnt.getLocation().getZ();
|
entry.setValue(entry.getValue() - 1);
|
||||||
boolean smallerZ = z < toggle;
|
if(entry.getValue() == 0)
|
||||||
boolean wasSmallerZ = z - tnt.getVelocity().getZ() < toggle;
|
countdowns.put(entry.getKey(), new TechKOCountdown(entry.getKey(), TECH_KO_HALF_TIME));
|
||||||
if(wasSmallerZ && !smallerZ) {
|
|
||||||
smallerZtime = TECH_KO_HALF_TIME;
|
|
||||||
if(smallerZcountdown != null){
|
|
||||||
smallerZcountdown.disable();
|
|
||||||
smallerZcountdown = null;
|
|
||||||
}
|
|
||||||
}else if(!wasSmallerZ && smallerZ){
|
|
||||||
biggerZtime = TECH_KO_HALF_TIME;
|
|
||||||
if(biggerZcountdown != null){
|
|
||||||
biggerZcountdown.disable();
|
|
||||||
biggerZcountdown = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if(smallerZtime == 0)
|
|
||||||
smallerZcountdown = new TechKOCountdown(smallerZteam, TECH_KO_HALF_TIME / 20);
|
|
||||||
if(biggerZtime == 0)
|
|
||||||
biggerZcountdown = new TechKOCountdown(biggerZteam, TECH_KO_HALF_TIME / 20);
|
|
||||||
|
|
||||||
smallerZtime--;
|
|
||||||
biggerZtime--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TechKOCountdown extends Countdown {
|
private class TechKOCountdown extends Countdown {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren