Added mob waves and the wave trigger

Still needs a trigger to trigger other signs
This commit is contained in:
Daniel Saukel 2016-04-26 20:44:14 +02:00
parent bac30d3dbb
commit 53ef4f2280
20 changed files with 651 additions and 389 deletions

View File

@ -22,8 +22,8 @@ import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.MessageConfig;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -74,6 +74,8 @@ public class GameCommand extends BRCommand {
MessageUtil.sendMessage(sender, "&bGame type: &e" + (game.getType() == null ? "Not started yet" : game.getType()));
MessageUtil.sendMessage(sender, "&bDungeon: &e" + (dGroup.getDungeonName() == null ? "N/A" : dGroup.getDungeonName()));
MessageUtil.sendMessage(sender, "&bMap: &e" + (dGroup.getMapName() == null ? "N/A" : dGroup.getMapName()));
MessageUtil.sendMessage(sender, "&bWaves finished: &e" + game.getWaveCount());
MessageUtil.sendMessage(sender, "&bKills: &e" + game.getGameKills() + " / Game; " + game.getWaveKills() + " / Wave");
}
}

View File

@ -79,6 +79,7 @@ public class WorldConfig {
private boolean isLobbyDisabled = false;
private int timeToNextPlay = 0;
private int timeToNextLoot = 0;
private int timeToNextWave = 10;
private int timeUntilKickOfflinePlayer = -1;
private int timeToFinish = -1;
@ -295,6 +296,12 @@ public class WorldConfig {
timeToNextLoot = plugin.getDefaultConfig().timeToNextLoot;
}
if (configFile.contains("timeToNextWave")) {
timeToNextWave = configFile.getInt("timeToNextWave");
} else {
timeToNextWave = plugin.getDefaultConfig().timeToNextWave;
}
if (configFile.contains("timeUntilKickOfflinePlayer")) {
timeUntilKickOfflinePlayer = configFile.getInt("timeUntilKickOfflinePlayer");
} else {
@ -579,6 +586,13 @@ public class WorldConfig {
return timeToNextLoot;
}
/**
* @return the break between two waves
*/
public int getTimeToNextWave() {
return timeToNextWave;
}
/**
* @return the time until a player gets kicked from his group if he is offline
*/

View File

@ -16,13 +16,22 @@
*/
package io.github.dre2n.dungeonsxl.game;
import io.github.dre2n.dungeonsxl.world.GameWorld;
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.player.DGroup;
import io.github.dre2n.dungeonsxl.sign.DSign;
import io.github.dre2n.dungeonsxl.sign.MobSign;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
/**
* @author Daniel Saukel
@ -35,6 +44,9 @@ public class Game {
private boolean started;
private GameType type;
private GameWorld world;
private int waveCount;
private Map<String, Integer> gameKills = new HashMap<>();
private Map<String, Integer> waveKills = new HashMap<>();
public Game(DGroup dGroup) {
dGroups.add(dGroup);
@ -124,6 +136,73 @@ public class Game {
this.world = world;
}
/**
* @return the waveCount
*/
public int getWaveCount() {
return waveCount;
}
/**
* @param waveCount
* the waveCount to set
*/
public void setWaveCount(int waveCount) {
this.waveCount = waveCount;
}
/**
* @return how many mobs have been killed in the game
*/
public int getGameKills() {
int count = 0;
for (String killer : gameKills.keySet()) {
count += gameKills.get(killer);
}
return count;
}
/**
* @return how many mobs have been killed in the last game
*/
public int getWaveKills() {
int count = 0;
for (String killer : waveKills.keySet()) {
count += waveKills.get(killer);
}
return count;
}
/**
* @param killer
* the killer; null if the killer is not a player
*/
public void addKill(String killer) {
if (killer == null) {
killer = "N/A";
}
waveKills.put(killer, waveKills.get(killer) == null ? 1 : waveKills.get(killer) + 1);
}
/**
* Adds the values of the wave kills map to the game kills map and resets the wave kills.
*/
public void resetWaveKills() {
gameKills.putAll(waveKills);
waveKills.clear();
}
/**
* @return the players in all dGroups
*/
public Set<Player> getPlayers() {
Set<Player> toReturn = new HashSet<>();
for (DGroup dGroup : dGroups) {
toReturn.addAll(dGroup.getPlayers());
}
return toReturn;
}
/**
* @return if the DGroup list is empty
*/
@ -131,7 +210,55 @@ public class Game {
return dGroups.isEmpty();
}
// Static
/* Actions */
/**
* @param mobCountIncreaseRate
* the new mob count will be increased by this rate
* @param teleport
* whether or not to teleport the players to the start location
*/
public void finishWave(final double mobCountIncreaseRate, final boolean teleport) {
waveCount++;
resetWaveKills();
int delay = world.getConfig().getTimeToNextWave();
sendMessage(plugin.getMessageConfig().getMessage(MessageConfig.Messages.GROUP_WAVE_FINISHED, String.valueOf(waveCount), String.valueOf(delay)));
new BukkitRunnable() {
@Override
public void run() {
if (teleport) {
for (Player player : getPlayers()) {
PlayerUtil.secureTeleport(player, world.getLocStart());
}
}
for (DSign dSign : world.getDSigns()) {
if (!(dSign instanceof MobSign)) {
continue;
}
MobSign mobSign = (MobSign) dSign;
int newAmount = (int) Math.ceil(mobSign.getInitialAmount() * mobCountIncreaseRate);
mobSign.setAmount(newAmount);
mobSign.setInitialAmount(newAmount);
mobSign.initializeTask();
}
}
}.runTaskLater(plugin, delay * 20);
}
/**
* @param message the message to send
*/
public void sendMessage(String message) {
for (DGroup dGroup : dGroups) {
dGroup.sendMessage(message);
}
}
/* Statics */
public static Game getByDGroup(DGroup dGroup) {
for (Game game : plugin.getGames()) {
if (game.getDGroups().contains(dGroup)) {

View File

@ -43,7 +43,7 @@ public enum GameTypeDefault implements GameType {
private String signName;
private boolean playerVersusPlayer;
private boolean friendlyFire;
private boolean mobWaves;// TODO: Implementing
private boolean mobWaves;
private boolean rewards;
private boolean showTime;
private boolean build;

View File

@ -18,14 +18,14 @@ package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.world.EditWorld;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.dungeonsxl.mob.DMob;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.world.EditWorld;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.World;
@ -90,7 +90,11 @@ public class EntityListener implements Listener {
if (gameWorld.isPlaying()) {
if (entity.getType() != EntityType.PLAYER) {
event.getDrops().clear();
DMob.onDeath(event);
DMob dMob = DMob.getByEntity(entity);
if (dMob != null) {
dMob.onDeath(event);
}
}
}
}
@ -110,6 +114,31 @@ public class EntityListener implements Listener {
if (!gameWorld.isPlaying()) {
event.setCancelled(true);
}
if (!(event.getEntity() instanceof LivingEntity)) {
return;
}
boolean dead = ((LivingEntity) event.getEntity()).getHealth() - event.getFinalDamage() <= 0;
if (dead && DMob.getByEntity(event.getEntity()) != null) {
String killer = null;
if (event instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) event).getDamager();
if (damager instanceof Projectile) {
if (((Projectile) damager).getShooter() instanceof Player) {
damager = (Player) ((Projectile) damager).getShooter();
}
}
if (damager instanceof Player) {
killer = damager.getName();
}
}
gameWorld.getGame().addKill(killer);
}
}
@EventHandler(priority = EventPriority.HIGH)
@ -155,27 +184,23 @@ public class EntityListener implements Listener {
DGroup attackerDGroup = null;
DGroup attackedDGroup = null;
if (attackerEntity instanceof Player && attackedEntity instanceof Player) {
attackerPlayer = (Player) attackerEntity;
attackedPlayer = (Player) attackedEntity;
if (attackerEntity instanceof LivingEntity && attackedEntity instanceof LivingEntity) {
if (attackerEntity instanceof Player && attackedEntity instanceof Player) {
attackerPlayer = (Player) attackerEntity;
attackedPlayer = (Player) attackedEntity;
attackerDGroup = DGroup.getByPlayer(attackerPlayer);
attackedDGroup = DGroup.getByPlayer(attackedPlayer);
attackerDGroup = DGroup.getByPlayer(attackerPlayer);
attackedDGroup = DGroup.getByPlayer(attackedPlayer);
if (!pvp) {
event.setCancelled(true);
}
if (attackerDGroup != null && attackedDGroup != null) {
if (!friendlyFire && attackerDGroup.equals(attackedDGroup)) {
if (!pvp) {
event.setCancelled(true);
}
}
}
if (attackerEntity instanceof LivingEntity && attackedEntity instanceof LivingEntity) {
if (!(attackerEntity instanceof Player) && !(attackedEntity instanceof Player)) {
event.setCancelled(true);
if (attackerDGroup != null && attackedDGroup != null) {
if (!friendlyFire && attackerDGroup.equals(attackedDGroup)) {
event.setCancelled(true);
}
}
}
// Check Dogs

View File

@ -17,9 +17,13 @@
package io.github.dre2n.dungeonsxl.mob;
import io.github.dre2n.dungeonsxl.event.dmob.DMobDeathEvent;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.trigger.MobTrigger;
import io.github.dre2n.dungeonsxl.trigger.WaveTrigger;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.util.Random;
import java.util.Set;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
@ -50,22 +54,11 @@ public class DMob {
}
public DMob(LivingEntity entity, GameWorld gameWorld, DMobType type, String trigger) {
gameWorld.addDMob(this);
this.entity = entity;
this.type = type;
this(entity, gameWorld, type);
this.trigger = trigger;
/* Remove DropChance of equipment */
this.entity.getEquipment().setHelmetDropChance(0);
this.entity.getEquipment().setChestplateDropChance(0);
this.entity.getEquipment().setLeggingsDropChance(0);
this.entity.getEquipment().setBootsDropChance(0);
this.entity.getEquipment().setItemInHandDropChance(0);
}
/* Statics */
public static void onDeath(EntityDeathEvent event) {
public void onDeath(EntityDeathEvent event) {
if (!(event.getEntity() instanceof LivingEntity)) {
return;
}
@ -78,43 +71,56 @@ public class DMob {
return;
}
for (DMob dMob : gameWorld.getDMobs()) {
if (dMob.entity != victim) {
continue;
}
DMobDeathEvent dMobDeathEvent = new DMobDeathEvent(this, event);
DMobDeathEvent dMobDeathEvent = new DMobDeathEvent(dMob, event);
if (dMobDeathEvent.isCancelled()) {
return;
}
if (dMob.type != null) {
for (ItemStack itemStack : dMob.type.getDrops().keySet()) {
Random randomGenerator = new Random();
int random = randomGenerator.nextInt(100);
if (dMob.type.getDrops().get(itemStack) > random) {
event.getDrops().add(itemStack);
}
}
name = dMob.type.getName();
} else if (dMob.type == null && dMob.trigger != null) {// <=MythicMobs mob
name = dMob.trigger;
} else {
name = victim.getType().getName();
}
MobTrigger trigger = MobTrigger.get(name, gameWorld);
if (trigger != null) {
trigger.onTrigger();
}
gameWorld.removeDMob(dMob);
if (dMobDeathEvent.isCancelled()) {
return;
}
if (type != null) {
for (ItemStack itemStack : type.getDrops().keySet()) {
Random randomGenerator = new Random();
int random = randomGenerator.nextInt(100);
if (type.getDrops().get(itemStack) > random) {
event.getDrops().add(itemStack);
}
}
name = type.getName();
} else if (type == null && trigger != null) {// <=MythicMobs mob
name = trigger;
} else {
name = victim.getType().getName();
}
MobTrigger mobTriger = MobTrigger.get(name, gameWorld);
if (mobTriger != null) {
mobTriger.onTrigger();
}
Set<WaveTrigger> waveTriggers = WaveTrigger.getByGameWorld(gameWorld);
for (WaveTrigger waveTrigger : waveTriggers) {
if (Game.getByGameWorld(gameWorld).getWaveKills() >= Math.ceil(gameWorld.getMobCount() * waveTrigger.getMustKillRate())) {
waveTrigger.onTrigger();
}
}
gameWorld.removeDMob(this);
}
/* Statics */
public static DMob getByEntity(Entity entity) {
GameWorld gameWorld = GameWorld.getByWorld(entity.getWorld());
for (DMob dMob : gameWorld.getDMobs()) {
if (dMob.entity == entity) {
return dMob;
}
}
return null;
}
}

View File

@ -17,7 +17,6 @@
package io.github.dre2n.dungeonsxl.player;
import io.github.dre2n.commons.util.messageutil.MessageUtil;
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.config.MessageConfig.Messages;
@ -30,12 +29,12 @@ import io.github.dre2n.dungeonsxl.event.reward.RewardAdditionEvent;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.dungeonsxl.global.GameSign;
import io.github.dre2n.dungeonsxl.global.GroupSign;
import io.github.dre2n.dungeonsxl.requirement.Requirement;
import io.github.dre2n.dungeonsxl.reward.Reward;
import io.github.dre2n.dungeonsxl.task.TimeIsRunningTask;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@ -63,7 +62,6 @@ public class DGroup {
private GameWorld gameWorld;
private boolean playing;
private int floorCount;
private int waveCount;
private List<Reward> rewards = new ArrayList<>();
private BukkitTask timeIsRunningTask;
@ -377,21 +375,6 @@ public class DGroup {
this.floorCount = floorCount;
}
/**
* @return the waveCount
*/
public int getWaveCount() {
return waveCount;
}
/**
* @param waveCount
* the waveCount to set
*/
public void setWaveCount(int waveCount) {
this.waveCount = waveCount;
}
/**
* @return the rewards
*/
@ -442,7 +425,8 @@ public class DGroup {
public boolean isEmpty() {
return players.isEmpty();
}
/* Actions */
/**
* Remove the group from the List
*/
@ -547,16 +531,6 @@ public class DGroup {
GroupSign.updatePerGroup(this);
}
public void finishWave(double mobCountIncreaseRate) {
for (DGroup dGroup : DGroup.getByGameWorld(gameWorld)) {
dGroup.sendMessage(messageConfig.getMessage(Messages.GROUP_WAVE_FINISHED, String.valueOf(dGroup.getWaveCount()) + "TIME"));// TODO
for (Player player : dGroup.getPlayers()) {
PlayerUtil.secureTeleport(player, gameWorld.getLocStart());
}
}
}
/**
* Send a message to all players in the group
*/

View File

@ -27,7 +27,6 @@ import io.github.dre2n.dungeonsxl.config.MessageConfig;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.DLootInventory;
import io.github.dre2n.dungeonsxl.world.EditWorld;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishDungeonEvent;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishFloorEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerFinishEvent;
@ -36,9 +35,10 @@ import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerUpdateEvent;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.dungeonsxl.reward.Reward;
import io.github.dre2n.dungeonsxl.trigger.DistanceTrigger;
import io.github.dre2n.dungeonsxl.world.EditWorld;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList;
@ -473,7 +473,7 @@ public class DPlayer extends DGlobalPlayer {
this.lives = lives;
}
// ...
/* Actions */
public void escape() {
delete();
savePlayer.reset(false);
@ -761,6 +761,8 @@ public class DPlayer extends DGlobalPlayer {
return;
}
Game.getByDGroup(dGroup).resetWaveKills();
for (Player player : dGroup.getPlayers()) {
DPlayer dPlayer = getByPlayer(player);
dPlayer.leave();

View File

@ -0,0 +1,210 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.dungeonsxl.task.MobSpawnTask;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.scheduler.BukkitTask;
/**
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
*/
public class DMobSign extends DSign implements MobSign {
private DSignType type = DSignTypeDefault.MOB;
// Variables
private String mob;
private int maxInterval = 1;
private int interval = 0;
private int amount = 1;
private int initialAmount = 1;
private boolean initialized;
private boolean active;
private BukkitTask task;
public DMobSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
}
@Override
public String getMob() {
return mob;
}
@Override
public void setMob(String mob) {
this.mob = mob;
}
@Override
public int getMaxInterval() {
return maxInterval;
}
@Override
public void setMaxInterval(int maxInterval) {
this.maxInterval = maxInterval;
}
@Override
public int getInterval() {
return interval;
}
@Override
public void setInterval(int interval) {
this.interval = interval;
}
@Override
public int getAmount() {
return amount;
}
@Override
public void setAmount(int amount) {
this.amount = amount;
}
@Override
public int getInitialAmount() {
return initialAmount;
}
@Override
public void setInitialAmount(int initialAmount) {
this.initialAmount = initialAmount;
}
@Override
public boolean isInitialized() {
return initialized;
}
@Override
public void setInitialized(boolean initialized) {
this.initialized = initialized;
}
@Override
public boolean isActive() {
return active;
}
@Override
public void setActive(boolean active) {
this.active = active;
}
@Override
public BukkitTask getTask() {
return task;
}
@Override
public void setTask(BukkitTask task) {
this.task = task;
}
@Override
public void initializeTask() {
task = new MobSpawnTask(this).runTaskTimer(plugin, 0L, 20L);
}
@Override
public boolean check() {
String lines[] = getSign().getLines();
if (lines[1].isEmpty() || lines[2].isEmpty()) {
return false;
}
if (lines[1] == null) {
return false;
}
String[] attributes = lines[2].split(",");
if (attributes.length == 2) {
return true;
} else {
return false;
}
}
@Override
public void onInit() {
String lines[] = getSign().getLines();
if (!lines[1].isEmpty() && !lines[2].isEmpty()) {
String mob = lines[1];
if (mob != null) {
String[] attributes = lines[2].split(",");
if (attributes.length == 2) {
this.mob = mob;
maxInterval = NumberUtil.parseInt(attributes[0]);
amount = NumberUtil.parseInt(attributes[1]);
initialAmount = amount;
}
}
}
getSign().getBlock().setType(Material.AIR);
initialized = true;
}
@Override
public void onTrigger() {
if (!initialized || active) {
return;
}
initializeTask();
active = true;
}
@Override
public void onDisable() {
if (!initialized || !active) {
return;
}
killTask();
interval = 0;
active = false;
}
public void killTask() {
if (!initialized || !active) {
return;
}
if (task != null) {
task.cancel();
task = null;
}
}
@Override
public DSignType getType() {
return type;
}
}

View File

@ -18,8 +18,9 @@ package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.event.dsign.DSignRegistrationEvent;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.trigger.Trigger;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashSet;
@ -93,6 +94,13 @@ public abstract class DSign {
return gameWorld;
}
/**
* @return the game
*/
public Game getGame() {
return Game.getByGameWorld(gameWorld);
}
/**
* @return the triggers
*/
@ -136,10 +144,6 @@ public abstract class DSign {
return;
}
if (triggers.size() != 1) {
continue;
}
if (trigger.getPlayer() == null) {
continue;
}

View File

@ -32,7 +32,7 @@ public enum DSignTypeDefault implements DSignType {
INTERACT("Interact", "dxl.sign.interact", true, InteractSign.class),
LEAVE("Leave", "dxl.sign.leave", true, LeaveSign.class),
LOBBY("Lobby", "dxl.sign.lobby", true, LobbySign.class),
MOB("Mob", "dxl.sign.mob", false, MobSign.class),
MOB("Mob", "dxl.sign.mob", false, DMobSign.class),
MESSAGE("MSG", "dxl.sign.msg", false, MessageSign.class),
MYTHIC_MOBS("MythicMobs", "dxl.sign.mob", false, MythicMobsSign.class),
PLACE("Place", "dxl.sign.place", false, PlaceSign.class),

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
* Copyright (C) 2016 Daniel Saukel
*
* 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
@ -16,213 +16,104 @@
*/
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.dungeonsxl.task.MobSpawnTask;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.scheduler.BukkitTask;
/**
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
* @author Daniel Saukel
*/
public class MobSign extends DSign {
private DSignType type = DSignTypeDefault.MOB;
// Variables
private String mob;
private int maxinterval = 1;
private int interval = 0;
private int amount = 1;
private boolean initialized;
private boolean active;
private BukkitTask task;
public MobSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
}
public interface MobSign {
/**
* @return the mob
*/
public String getMob() {
return mob;
}
public String getMob();
/**
* @param mob
* the mob to set
*/
public void setMob(String mob) {
this.mob = mob;
}
public void setMob(String mob);
/**
* @return the maxinterval
* @return the the maximum interval between mob spawns
*/
public int getMaxinterval() {
return maxinterval;
}
public int getMaxInterval();
/**
* @param maxinterval
* the maxinterval to set
* @param maxInterval
* the maximum interval between mob spawns
*/
public void setMaxinterval(int maxinterval) {
this.maxinterval = maxinterval;
}
public void setMaxInterval(int maxInterval);
/**
* @return the interval
* @return the spawn interval
*/
public int getInterval() {
return interval;
}
public int getInterval();
/**
* @param interval
* the interval to set
* the spawn interval
*/
public void setInterval(int interval) {
this.interval = interval;
}
public void setInterval(int interval);
/**
* @return the amount
* @return the amount of mobs
*/
public int getAmount() {
return amount;
}
public int getAmount();
/**
* @param amount
* the amount to set
* the amount of mobs to set
*/
public void setAmount(int amount) {
this.amount = amount;
}
public void setAmount(int amount);
/**
* @return the initialized
* @return the initial amount of mobs
*/
public boolean isInitialized() {
return initialized;
}
public int getInitialAmount();
/**
* @param amount
* the amount of mobs to set
*/
public void setInitialAmount(int initialAmount);
/**
* @return if the sign is initialized
*/
public boolean isInitialized();
/**
* @param initialized
* the initialized to set
* set the sign initialized
*/
public void setInitialized(boolean initialized) {
this.initialized = initialized;
}
public void setInitialized(boolean initialized);
/**
* @return the active
* @return if the sign is active
*/
public boolean isActive() {
return active;
}
public boolean isActive();
/**
* @param active
* the active to set
* set the sign active
*/
public void setActive(boolean active) {
this.active = active;
}
public void setActive(boolean active);
/**
* @return the task
* @return the spawn task
*/
public BukkitTask getTask() {
return task;
}
public BukkitTask getTask();
/**
* @param task
* the task to set
*/
public void setTask(BukkitTask task) {
this.task = task;
}
public void setTask(BukkitTask task);
@Override
public boolean check() {
String lines[] = getSign().getLines();
if (lines[1].isEmpty() || lines[2].isEmpty()) {
return false;
}
if (lines[1] == null) {
return false;
}
String[] attributes = lines[2].split(",");
if (attributes.length == 2) {
return true;
} else {
return false;
}
}
@Override
public void onInit() {
String lines[] = getSign().getLines();
if (!lines[1].isEmpty() && !lines[2].isEmpty()) {
String mob = lines[1];
if (mob != null) {
String[] attributes = lines[2].split(",");
if (attributes.length == 2) {
this.mob = mob;
maxinterval = NumberUtil.parseInt(attributes[0]);
amount = NumberUtil.parseInt(attributes[1]);
}
}
}
getSign().getBlock().setType(Material.AIR);
initialized = true;
}
@Override
public void onTrigger() {
if (!initialized || active) {
return;
}
task = new MobSpawnTask(this).runTaskTimer(plugin, 0L, 20L);
active = true;
}
@Override
public void onDisable() {
if (!initialized || !active) {
return;
}
killTask();
interval = 0;
active = false;
}
public void killTask() {
if (!initialized || !active) {
return;
}
if (task != null) {
task.cancel();
task = null;
}
}
@Override
public DSignType getType() {
return type;
}
/**
* Start a new spawn task.
*/
public void initializeTask();
}

View File

@ -17,8 +17,8 @@
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.dungeonsxl.task.MythicMobSpawnTask;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.Material;
@ -31,15 +31,16 @@ import org.bukkit.scheduler.BukkitTask;
/**
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
*/
public class MythicMobsSign extends DSign {
public class MythicMobsSign extends DSign implements MobSign {
private DSignType type = DSignTypeDefault.MYTHIC_MOBS;
// Variables
private String mob;
private int maxinterval = 1;
private int maxInterval = 1;
private int interval = 0;
private int amount = 1;
private int initialAmount = 1;
private boolean initialized;
private boolean active;
private BukkitTask task;
@ -51,96 +52,91 @@ public class MythicMobsSign extends DSign {
super(sign, gameWorld);
}
/**
* @return the mob
*/
@Override
public String getMob() {
return mob;
}
/**
* @param mob
* the mob to set
*/
@Override
public void setMob(String mob) {
this.mob = mob;
}
/**
* @return the maxinterval
*/
public int getMaxinterval() {
return maxinterval;
@Override
public int getMaxInterval() {
return maxInterval;
}
/**
* @param maxinterval
* the maxinterval to set
*/
public void setMaxinterval(int maxinterval) {
this.maxinterval = maxinterval;
@Override
public void setMaxInterval(int maxInterval) {
this.maxInterval = maxInterval;
}
/**
* @return the interval
*/
@Override
public int getInterval() {
return interval;
}
/**
* @param interval
* the interval to set
*/
@Override
public void setInterval(int interval) {
this.interval = interval;
}
/**
* @return the amount
*/
@Override
public int getAmount() {
return amount;
}
/**
* @param amount
* the amount to set
*/
@Override
public void setAmount(int amount) {
this.amount = amount;
}
/**
* @return the initialized
*/
@Override
public int getInitialAmount() {
return initialAmount;
}
@Override
public void setInitialAmount(int initialAmount) {
this.initialAmount = initialAmount;
}
@Override
public boolean isInitialized() {
return initialized;
}
/**
* @param initialized
* the initialized to set
*/
@Override
public void setInitialized(boolean initialized) {
this.initialized = initialized;
}
/**
* @return the active
*/
@Override
public boolean isActive() {
return active;
}
/**
* @param active
* the active to set
*/
@Override
public void setActive(boolean active) {
this.active = active;
}
@Override
public BukkitTask getTask() {
return task;
}
@Override
public void setTask(BukkitTask task) {
this.task = task;
}
@Override
public void initializeTask() {
task = new MythicMobSpawnTask(this).runTaskTimer(plugin, 0L, 20L);
}
/**
* @return the spawnLocation
*/
@ -186,21 +182,6 @@ public class MythicMobsSign extends DSign {
this.mythicMobs = mythicMobs;
}
/**
* @return the task
*/
public BukkitTask getTask() {
return task;
}
/**
* @param task
* the task to set
*/
public void setTask(BukkitTask task) {
this.task = task;
}
@Override
public boolean check() {
String lines[] = getSign().getLines();
@ -224,15 +205,16 @@ public class MythicMobsSign extends DSign {
@Override
public void onInit() {
String lines[] = getSign().getLines();
if (lines[1].isEmpty() || lines[2].equals("")) {
if (lines[1].isEmpty() || lines[2].isEmpty()) {
} else {
String mob = lines[1];
if (mob != null) {
String[] attributes = lines[2].split(",");
if (attributes.length == 2) {
this.setMob(mob);
setMaxinterval(NumberUtil.parseInt(attributes[0]));
setMaxInterval(NumberUtil.parseInt(attributes[0]));
setAmount(NumberUtil.parseInt(attributes[1]));
initialAmount = amount;
}
}
}
@ -247,7 +229,7 @@ public class MythicMobsSign extends DSign {
return;
}
task = new MythicMobSpawnTask(this).runTaskTimer(plugin, 0L, 20L);
initializeTask();
active = true;
}

View File

@ -17,9 +17,8 @@
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.trigger.InteractTrigger;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Sign;
@ -33,6 +32,7 @@ public class WaveSign extends DSign {
private DSignType type = DSignTypeDefault.WAVE;
private double mobCountIncreaseRate;
private boolean teleport;
public WaveSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
@ -53,6 +53,21 @@ public class WaveSign extends DSign {
this.mobCountIncreaseRate = mobCountIncreaseRate;
}
/**
* @return if the group members will be teleported to the start location
*/
public boolean getTeleport() {
return teleport;
}
/**
* @param teleport
* Set if the players shall get teleported to the start location
*/
public void setTeleport(boolean teleport) {
this.teleport = teleport;
}
@Override
public boolean check() {
return true;
@ -65,6 +80,10 @@ public class WaveSign extends DSign {
mobCountIncreaseRate = NumberUtil.parseDouble(lines[1], 2);
}
if (!lines[2].isEmpty()) {
teleport = lines[2].equals("+") || lines[2].equals("true");
}
if (!getTriggers().isEmpty()) {
getSign().getBlock().setType(Material.AIR);
return;
@ -85,24 +104,13 @@ public class WaveSign extends DSign {
@Override
public boolean onPlayerTrigger(Player player) {
DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup == null) {
return true;
}
if (getGameWorld() == null) {
return true;
}
dGroup.finishWave(mobCountIncreaseRate);
getGame().finishWave(mobCountIncreaseRate, teleport);
return true;
}
@Override
public void onTrigger() {
for (DGroup dGroup : plugin.getDGroups()) {
dGroup.finishWave(mobCountIncreaseRate);
}
getGame().finishWave(mobCountIncreaseRate, teleport);
}
@Override

View File

@ -16,10 +16,10 @@
*/
package io.github.dre2n.dungeonsxl.task;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.dungeonsxl.mob.DMob;
import io.github.dre2n.dungeonsxl.mob.DMobType;
import io.github.dre2n.dungeonsxl.sign.MobSign;
import io.github.dre2n.dungeonsxl.sign.DMobSign;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@ -35,9 +35,9 @@ import org.bukkit.scheduler.BukkitRunnable;
*/
public class MobSpawnTask extends BukkitRunnable {
private MobSign sign;
private DMobSign sign;
public MobSpawnTask(MobSign sign) {
public MobSpawnTask(DMobSign sign) {
this.sign = sign;
}
@ -84,11 +84,10 @@ public class MobSpawnTask extends BukkitRunnable {
} else {
sign.killTask();
sign.remove();
}
}
sign.setInterval(sign.getMaxinterval());
sign.setInterval(sign.getMaxInterval());
} else {
sign.killTask();

View File

@ -16,9 +16,9 @@
*/
package io.github.dre2n.dungeonsxl.task;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.dungeonsxl.mob.DMob;
import io.github.dre2n.dungeonsxl.sign.MythicMobsSign;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.scheduler.BukkitRunnable;
@ -60,11 +60,10 @@ public class MythicMobSpawnTask extends BukkitRunnable {
sign.setAmount(sign.getAmount() - 1);
} else {
sign.killTask();
sign.remove();
}
}
sign.setInterval(sign.getMaxinterval());
sign.setInterval(sign.getMaxInterval());
} else {
sign.killTask();

View File

@ -51,7 +51,7 @@ public class MobTrigger extends Trigger {
@Override
public void register(GameWorld gameWorld) {
if (!hasTriggers(gameWorld)) {
ArrayList<MobTrigger> list = new ArrayList<MobTrigger>();
ArrayList<MobTrigger> list = new ArrayList<>();
list.add(this);
triggers.put(gameWorld, list);

View File

@ -19,8 +19,8 @@ package io.github.dre2n.dungeonsxl.trigger;
import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.event.trigger.TriggerRegistrationEvent;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.dungeonsxl.sign.DSign;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashSet;
@ -107,7 +107,7 @@ public abstract class Trigger {
}
public void updateDSigns() {
for (DSign dSign : dSigns.toArray(new DSign[dSigns.size()])) {
for (DSign dSign : dSigns) {
dSign.onUpdate();
}
}
@ -155,7 +155,7 @@ public abstract class Trigger {
} else if (type == TriggerTypeDefault.WAVE) {
if (value != null) {
return WaveTrigger.getOrCreate(NumberUtil.parseInt(value, 1), dSign.getGameWorld());
return WaveTrigger.getOrCreate(NumberUtil.parseDouble(value, 1), dSign.getGameWorld());
}
} else if (type != null) {

View File

@ -20,7 +20,9 @@ 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
@ -31,10 +33,25 @@ public class WaveTrigger extends Trigger {
private TriggerType type = TriggerTypeDefault.WAVE;
private int mustKillAmount;
private double mustKillRate = 1;
public WaveTrigger(int mustKillAmount) {
this.mustKillAmount = mustKillAmount;
public WaveTrigger(double mustKillRate) {
this.mustKillRate = mustKillRate;
}
/**
* @return the minimal mob kill rate to trigger the wave
*/
public double getMustKillRate() {
return mustKillRate;
}
/**
* @param mustKillRate
* the minimal mob kill rate to trigger the wave to set
*/
public void setMustKillRate(double mustKillRate) {
this.mustKillRate = mustKillRate;
}
public void onTrigger() {
@ -46,12 +63,13 @@ public class WaveTrigger extends Trigger {
setTriggered(true);
updateDSigns();
setTriggered(false);
}
@Override
public void register(GameWorld gameWorld) {
if (!hasTriggers(gameWorld)) {
ArrayList<WaveTrigger> list = new ArrayList<WaveTrigger>();
ArrayList<WaveTrigger> list = new ArrayList<>();
list.add(this);
triggers.put(gameWorld, list);
@ -72,40 +90,24 @@ public class WaveTrigger extends Trigger {
return type;
}
public static WaveTrigger getOrCreate(int mustKillAmount, GameWorld gameWorld) {
WaveTrigger trigger = get(gameWorld);
if (trigger != null) {
return trigger;
}
return new WaveTrigger(mustKillAmount);
/* Statics */
public static WaveTrigger getOrCreate(double mustKillRate, GameWorld gameWorld) {
return new WaveTrigger(mustKillRate);
}
public static WaveTrigger get(GameWorld gameWorld) {
if (hasTriggers(gameWorld)) {
for (WaveTrigger trigger : triggers.get(gameWorld)) {
return trigger;
}
/**
* @return the WaveTriggers in the GameWorld
*/
public static Set<WaveTrigger> getByGameWorld(GameWorld gameWorld) {
Set<WaveTrigger> toReturn = new HashSet<>();
for (WaveTrigger trigger : triggers.get(gameWorld)) {
toReturn.add(trigger);
}
return null;
return toReturn;
}
public static boolean hasTriggers(GameWorld gameWorld) {
return !triggers.isEmpty() && triggers.containsKey(gameWorld);
}
/**
* @return the mustKillAmount
*/
public int getMustKillAmount() {
return mustKillAmount;
}
/**
* @param mustKillAmount
* the mustKillAmount to set
*/
public void setMustKillAmount(int mustKillAmount) {
this.mustKillAmount = mustKillAmount;
}
}

View File

@ -22,7 +22,6 @@ import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.world.EditWorld;
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldLoadEvent;
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldStartGameEvent;
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldUnloadEvent;
@ -35,6 +34,7 @@ import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.requirement.Requirement;
import io.github.dre2n.dungeonsxl.sign.DSign;
import io.github.dre2n.dungeonsxl.sign.MobSign;
import io.github.dre2n.dungeonsxl.trigger.RedstoneTrigger;
import java.io.File;
import java.io.FileInputStream;
@ -338,6 +338,23 @@ public class GameWorld {
this.dSigns = dSigns;
}
/**
* @return the potential amount of mobs in the world
*/
public int getMobCount() {
int mobCount = 0;
for (DSign dSign : dSigns) {
if (!(dSign instanceof MobSign)) {
continue;
}
mobCount += ((MobSign) dSign).getInitialAmount();
}
return mobCount;
}
/**
* @return the worldConfig
*/