diff --git a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java index 48008d91..a07af2c7 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -19,9 +19,11 @@ package io.github.dre2n.dungeonsxl.game; import io.github.dre2n.commons.util.playerutil.PlayerUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.MessageConfig; +import io.github.dre2n.dungeonsxl.dungeon.Dungeon; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.sign.DSign; import io.github.dre2n.dungeonsxl.sign.MobSign; +import io.github.dre2n.dungeonsxl.trigger.ProgressTrigger; import io.github.dre2n.dungeonsxl.world.GameWorld; import java.util.ArrayList; import java.util.Arrays; @@ -136,6 +138,36 @@ public class Game { this.world = world; } + /** + * Refers to the DGroup with the best progress. + * + * @return the unplayed floors + */ + public List getUnplayedFloors() { + List unplayedFloors = new ArrayList<>(); + for (DGroup dGroup : dGroups) { + if (dGroup.getUnplayedFloors().size() < unplayedFloors.size()) { + unplayedFloors = dGroup.getUnplayedFloors(); + } + } + return unplayedFloors; + } + + /** + * Refers to the DGroup with the best progress. + * + * @return the floorCount + */ + public int getFloorCount() { + int floorCount = 0; + for (DGroup dGroup : dGroups) { + if (dGroup.getFloorCount() > floorCount) { + floorCount = dGroup.getFloorCount(); + } + } + return floorCount; + } + /** * @return the waveCount */ @@ -192,6 +224,15 @@ public class Game { waveKills.clear(); } + /** + * Refers to a DGroup. + * + * @return the dungeon + */ + public Dungeon getDungeon() { + return dGroups.get(0).getDungeon(); + } + /** * @return the players in all dGroups */ @@ -221,6 +262,13 @@ public class Game { waveCount++; resetWaveKills(); + Set triggers = ProgressTrigger.getByGameWorld(world); + for (ProgressTrigger trigger : triggers) { + if (getWaveCount() >= trigger.getWaveCount() & getFloorCount() >= trigger.getFloorCount() - 1 || !getUnplayedFloors().contains(trigger.getFloor()) & trigger.getFloor() != null) { + trigger.onTrigger(); + } + } + int delay = world.getConfig().getTimeToNextWave(); sendMessage(plugin.getMessageConfig().getMessage(MessageConfig.Messages.GROUP_WAVE_FINISHED, String.valueOf(waveCount), String.valueOf(delay))); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java index c35b25d9..1da04c96 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -425,7 +425,7 @@ public class DGroup { public boolean isEmpty() { return players.isEmpty(); } - + /* Actions */ /** * Remove the group from the List diff --git a/src/main/java/io/github/dre2n/dungeonsxl/trigger/ProgressTrigger.java b/src/main/java/io/github/dre2n/dungeonsxl/trigger/ProgressTrigger.java new file mode 100644 index 00000000..bfc0947b --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/trigger/ProgressTrigger.java @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.trigger; + +import io.github.dre2n.dungeonsxl.event.trigger.TriggerActionEvent; +import io.github.dre2n.dungeonsxl.world.GameWorld; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * @author Frank Baumann, Daniel Saukel + */ +public class ProgressTrigger extends Trigger { + + private static Map> triggers = new HashMap<>(); + + private TriggerType type = TriggerTypeDefault.PROGRESS; + + private String floor; + private int floorCount; + private int waveCount; + + public ProgressTrigger(int floorCount, int waveCount) { + this.floorCount = floorCount; + this.waveCount = waveCount; + } + + public ProgressTrigger(String floor) { + this.floor = floor; + } + + /* Getters and setters */ + /** + * @return the specific floor that must be finished + */ + public String getFloor() { + return floor; + } + + /** + * @param floor + * the specific floor to set + */ + public void setFloor(String floor) { + this.floor = floor; + } + + /** + * @return the floor count to trigger + */ + public int getFloorCount() { + return floorCount; + } + + /** + * @param floorCount + * the floor count to set + */ + public void setFloorCount(int floorCount) { + this.floorCount = floorCount; + } + + /** + * @return the wave count to trigger + */ + public int getWaveCount() { + return waveCount; + } + + /** + * @param waveCount + * the wave count to set + */ + public void setWaveCount(int waveCount) { + this.waveCount = waveCount; + } + + /* Actions */ + public void onTrigger() { + TriggerActionEvent event = new TriggerActionEvent(this); + + if (event.isCancelled()) { + return; + } + + setTriggered(true); + updateDSigns(); + } + + @Override + public void register(GameWorld gameWorld) { + if (!hasTriggers(gameWorld)) { + ArrayList list = new ArrayList<>(); + list.add(this); + triggers.put(gameWorld, list); + + } else { + triggers.get(gameWorld).add(this); + } + } + + @Override + public void unregister(GameWorld gameWorld) { + if (hasTriggers(gameWorld)) { + triggers.get(gameWorld).remove(this); + } + } + + @Override + public TriggerType getType() { + return type; + } + + public static ProgressTrigger getOrCreate(int floorCount, int waveCount, GameWorld gameWorld) { + if (floorCount == 0 & waveCount == 0 || floorCount < 0 || waveCount < 0) { + return null; + } + return new ProgressTrigger(floorCount, waveCount); + } + + public static ProgressTrigger getOrCreate(String floor, GameWorld gameWorld) { + return new ProgressTrigger(floor); + } + + public static Set getByGameWorld(GameWorld gameWorld) { + Set toReturn = new HashSet<>(); + for (ProgressTrigger trigger : triggers.get(gameWorld)) { + toReturn.add(trigger); + } + return toReturn; + } + + public static boolean hasTriggers(GameWorld gameWorld) { + return !triggers.isEmpty() && triggers.containsKey(gameWorld); + } + +} diff --git a/src/main/java/io/github/dre2n/dungeonsxl/trigger/Trigger.java b/src/main/java/io/github/dre2n/dungeonsxl/trigger/Trigger.java index 4f7fb95a..cb9858a5 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/trigger/Trigger.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/trigger/Trigger.java @@ -146,6 +146,19 @@ public abstract class Trigger { return MobTrigger.getOrCreate(value, dSign.getGameWorld()); } + } else if (type == TriggerTypeDefault.PROGRESS) { + + if (value != null) { + if (value.matches("[0-99]/[0-999]")) { + int floorCount = NumberUtil.parseInt(value.split("/")[0]); + int waveCount = NumberUtil.parseInt(value.split("/")[1]); + return ProgressTrigger.getOrCreate(floorCount, waveCount, dSign.getGameWorld()); + + } else { + return ProgressTrigger.getOrCreate(value, dSign.getGameWorld()); + } + } + } else if (type == TriggerTypeDefault.USE_ITEM) { if (value != null) { diff --git a/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypeDefault.java b/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypeDefault.java index b8421b3a..03d7d8e0 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypeDefault.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/trigger/TriggerTypeDefault.java @@ -24,6 +24,7 @@ public enum TriggerTypeDefault implements TriggerType { DISTANCE("D", DistanceTrigger.class), INTERACT("I", InteractTrigger.class), MOB("M", MobTrigger.class), + PROGRESS("P", ProgressTrigger.class), REDSTONE("R", RedstoneTrigger.class), SIGN("T", SignTrigger.class), USE_ITEM("U", UseItemTrigger.class),