2020-08-26 18:24:44 +02:00
|
|
|
/*
|
|
|
|
This file is a part of the SteamWar software.
|
|
|
|
|
|
|
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-09-05 18:26:13 +02:00
|
|
|
package de.steamwar.fightsystem.winconditions;
|
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
import de.steamwar.fightsystem.Config;
|
2021-03-12 15:43:32 +01:00
|
|
|
import de.steamwar.fightsystem.countdown.Countdown;
|
|
|
|
import de.steamwar.fightsystem.countdown.SWSound;
|
2019-09-05 18:26:13 +02:00
|
|
|
import de.steamwar.fightsystem.fight.Fight;
|
|
|
|
import de.steamwar.fightsystem.fight.FightTeam;
|
2020-01-11 15:44:40 +01:00
|
|
|
import de.steamwar.fightsystem.states.FightState;
|
2021-03-12 15:43:32 +01:00
|
|
|
import de.steamwar.fightsystem.states.StateDependentTask;
|
2019-09-05 18:26:13 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.TNTPrimed;
|
|
|
|
|
2021-03-12 15:43:32 +01:00
|
|
|
public class WinconditionTimeTechKO extends Wincondition {
|
2019-09-05 18:26:13 +02:00
|
|
|
|
|
|
|
private static final int TECH_KO_TIME_IN_S = 90;
|
|
|
|
private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S*10;
|
|
|
|
|
2020-12-24 14:53:29 +01:00
|
|
|
private final World world = Bukkit.getWorlds().get(0);
|
|
|
|
private final double toggle = Config.SpecSpawn.getZ();
|
|
|
|
private final FightTeam smallerZteam;
|
|
|
|
private final FightTeam biggerZteam;
|
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
private int smallerZtime = TECH_KO_HALF_TIME;
|
|
|
|
private int biggerZtime = TECH_KO_HALF_TIME;
|
2019-09-05 18:26:13 +02:00
|
|
|
private TechKOCountdown smallerZcountdown = null;
|
|
|
|
private TechKOCountdown biggerZcountdown = null;
|
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
/**
|
|
|
|
* Works only for z-Axis fight direction for performance reasons
|
|
|
|
*/
|
2021-03-10 22:45:17 +01:00
|
|
|
public WinconditionTimeTechKO(){
|
2021-03-12 15:43:32 +01:00
|
|
|
super("TechKO", "", " §chat den Gegner Tech K.O. gesetzt!");
|
2020-12-24 14:53:29 +01:00
|
|
|
|
|
|
|
if(Config.TeamBluetoReddistanceZ > 0) {
|
|
|
|
smallerZteam = Fight.getBlueTeam();
|
|
|
|
biggerZteam = Fight.getRedTeam();
|
|
|
|
}else{
|
|
|
|
smallerZteam = Fight.getRedTeam();
|
|
|
|
biggerZteam = Fight.getBlueTeam();
|
|
|
|
}
|
2019-09-05 18:26:13 +02:00
|
|
|
|
2021-03-12 15:43:32 +01:00
|
|
|
new StateDependentTask(Winconditions.TIME_TECH_KO, FightState.Running, this::run, 1, 1){
|
|
|
|
@Override
|
|
|
|
public void disable() {
|
|
|
|
super.disable();
|
|
|
|
if(smallerZcountdown != null){
|
|
|
|
smallerZcountdown.disable();
|
|
|
|
smallerZcountdown = null;
|
|
|
|
}
|
|
|
|
if(biggerZcountdown != null){
|
|
|
|
biggerZcountdown.disable();
|
|
|
|
biggerZcountdown = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2020-01-11 15:44:40 +01:00
|
|
|
}
|
|
|
|
|
2019-09-05 18:26:13 +02:00
|
|
|
private void run(){
|
|
|
|
for(TNTPrimed tnt : world.getEntitiesByClass(TNTPrimed.class)){
|
2020-12-24 14:53:29 +01:00
|
|
|
double z = tnt.getLocation().getZ();
|
|
|
|
boolean smallerZ = z < toggle;
|
|
|
|
boolean wasSmallerZ = z - tnt.getVelocity().getZ() < toggle;
|
|
|
|
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;
|
|
|
|
}
|
2019-09-05 18:26:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-24 14:53:29 +01:00
|
|
|
if(smallerZtime == 0)
|
|
|
|
smallerZcountdown = new TechKOCountdown(smallerZteam, TECH_KO_HALF_TIME / 20);
|
|
|
|
if(biggerZtime == 0)
|
|
|
|
biggerZcountdown = new TechKOCountdown(biggerZteam, TECH_KO_HALF_TIME / 20);
|
2019-09-05 18:26:13 +02:00
|
|
|
|
|
|
|
smallerZtime--;
|
|
|
|
biggerZtime--;
|
|
|
|
}
|
2021-03-12 15:43:32 +01:00
|
|
|
|
|
|
|
private class TechKOCountdown extends Countdown {
|
|
|
|
private final FightTeam team;
|
|
|
|
|
|
|
|
public TechKOCountdown(FightTeam team, int countdownTime) {
|
|
|
|
super(countdownTime, SWSound.BLOCK_NOTE_PLING, false);
|
|
|
|
this.team = team;
|
|
|
|
super.enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final String countdownCounting() {
|
|
|
|
return "bis " + team.getColoredName() + " §feinen Schuss abgegeben haben muss!";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void countdownFinished() {
|
|
|
|
win(Fight.getOpposite(team));
|
|
|
|
}
|
|
|
|
}
|
2019-09-05 18:26:13 +02:00
|
|
|
}
|