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;
|
2019-03-09 19:40:12 +01:00
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
import de.steamwar.fightsystem.Config;
|
2019-09-05 18:26:13 +02:00
|
|
|
import de.steamwar.fightsystem.fight.Fight;
|
2021-03-10 22:45:17 +01:00
|
|
|
import de.steamwar.fightsystem.fight.FightTeam;
|
2020-01-11 12:53:31 +01:00
|
|
|
import de.steamwar.fightsystem.states.FightState;
|
2021-03-12 15:43:32 +01:00
|
|
|
import de.steamwar.fightsystem.states.StateDependentListener;
|
2019-03-09 19:40:12 +01:00
|
|
|
import org.bukkit.event.EventHandler;
|
2021-03-12 15:43:32 +01:00
|
|
|
import org.bukkit.event.Listener;
|
2019-03-09 19:40:12 +01:00
|
|
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
|
|
|
2021-03-10 22:45:17 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2020-01-11 15:44:40 +01:00
|
|
|
|
2021-03-12 15:43:32 +01:00
|
|
|
public class WinconditionPercentSystem extends Wincondition implements Listener, PrintableWincondition, PercentWincondition {
|
2019-03-09 19:40:12 +01:00
|
|
|
|
2021-03-10 22:45:17 +01:00
|
|
|
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
2019-03-09 19:40:12 +01:00
|
|
|
|
2019-04-05 19:32:59 +02:00
|
|
|
public WinconditionPercentSystem() {
|
2021-03-12 15:43:32 +01:00
|
|
|
super("Percent", "§cTeam ", " §chat den Gegnern");
|
2021-03-10 22:45:17 +01:00
|
|
|
teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam()));
|
|
|
|
teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam()));
|
2021-03-12 15:43:32 +01:00
|
|
|
|
|
|
|
new StateDependentListener(Winconditions.PERCENT_SYSTEM, FightState.Running, this);
|
2021-03-24 10:18:00 +01:00
|
|
|
if(Config.ActiveWinconditions.contains(Winconditions.PERCENT_SYSTEM)){
|
|
|
|
printableWinconditions.add(this);
|
|
|
|
percentWincondition = this;
|
|
|
|
}
|
2019-04-05 19:32:59 +02:00
|
|
|
}
|
2019-03-09 19:40:12 +01:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void handleEntityExplode(EntityExplodeEvent event) {
|
2021-03-10 22:45:17 +01:00
|
|
|
teamMap.values().forEach(teamPercent -> teamPercent.check(event));
|
2019-03-09 19:40:12 +01:00
|
|
|
}
|
|
|
|
|
2021-03-10 22:45:17 +01:00
|
|
|
@Override
|
|
|
|
public String getDisplay(FightTeam team) {
|
|
|
|
return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%";
|
2019-04-14 01:23:46 +02:00
|
|
|
}
|
2019-03-09 19:40:12 +01:00
|
|
|
|
2021-03-10 22:45:17 +01:00
|
|
|
@Override
|
|
|
|
public double getPercent(FightTeam team) {
|
|
|
|
return teamMap.get(team).percent;
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TeamPercent {
|
|
|
|
|
|
|
|
private final FightTeam team;
|
2021-03-20 17:25:13 +01:00
|
|
|
private final int volume;
|
2021-03-10 22:45:17 +01:00
|
|
|
private double percent;
|
|
|
|
private int destroyedBlocks;
|
|
|
|
|
|
|
|
private TeamPercent(FightTeam team) {
|
|
|
|
this.team = team;
|
2021-03-20 17:25:13 +01:00
|
|
|
this.volume = team.getSchemRegion().volume();
|
2021-03-10 22:45:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void check(EntityExplodeEvent event) {
|
2021-03-20 14:49:43 +01:00
|
|
|
if(!team.getExtendRegion().inRegion(event.getEntity().getLocation())){
|
2021-03-10 22:45:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
destroyedBlocks += event.blockList().size();
|
2021-03-20 17:25:13 +01:00
|
|
|
percent = (double)destroyedBlocks * 100 / volume;
|
2021-03-10 22:45:17 +01:00
|
|
|
if(percent >= Config.PercentWin) {
|
2021-03-12 15:43:32 +01:00
|
|
|
win(Fight.getOpposite(team));
|
2021-03-10 22:45:17 +01:00
|
|
|
}
|
|
|
|
}
|
2019-04-14 01:23:46 +02:00
|
|
|
}
|
2019-03-09 19:40:12 +01:00
|
|
|
}
|