From 13a167c7625325ae02f5e7502167b8f93a1f0b70 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 3 Aug 2016 15:36:35 +0200 Subject: [PATCH] Add capture flag option --- .../dungeonsxl/listener/PlayerListener.java | 10 +++++ .../dre2n/dungeonsxl/player/DGamePlayer.java | 41 ++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index f1e5f6b7..7e56c210 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -664,6 +664,16 @@ public class PlayerListener implements Listener { @EventHandler public void onMove(PlayerMoveEvent event) { Player player = event.getPlayer(); + DGameWorld gameWorld = DGameWorld.getByWorld(player.getWorld()); + DGamePlayer gamePlayer = DGamePlayer.getByPlayer(player); + if (gameWorld != null && gamePlayer != null && gamePlayer.isStealing()) { + DGroup group = gamePlayer.getDGroup(); + Location startLocation = gameWorld.getStartLocation(group); + + if (startLocation.distance(player.getLocation()) < 3) { + gamePlayer.captureFlag(); + } + } DLootInventory inventory = DLootInventory.getByPlayer(player); if (inventory != null && player.getLocation().getBlock().getRelative(0, 1, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, -1, 0).getType() != Material.PORTAL diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index abdd7e14..76452c40 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -30,6 +30,7 @@ import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerDeathEv import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerFinishEvent; import io.github.dre2n.dungeonsxl.event.requirement.RequirementCheckEvent; import io.github.dre2n.dungeonsxl.game.Game; +import io.github.dre2n.dungeonsxl.game.GameGoal; import io.github.dre2n.dungeonsxl.game.GameRules; import io.github.dre2n.dungeonsxl.game.GameType; import io.github.dre2n.dungeonsxl.game.GameTypeDefault; @@ -79,6 +80,7 @@ public class DGamePlayer extends DInstancePlayer { private int initialLives = -1; private int lives; + private ItemStack oldHelmet; private DGroup stealing; public DGamePlayer(Player player, DGameWorld world) { @@ -410,13 +412,49 @@ public class DGamePlayer extends DInstancePlayer { */ public void setRobbedGroup(DGroup dGroup) { if (dGroup != null) { - player.getInventory().getHelmet().setType(Material.WOOL); + oldHelmet = player.getInventory().getHelmet(); + player.getInventory().setHelmet(new ItemStack(Material.WOOL, 1, getDGroup().getDColor().getWoolData())); } stealing = dGroup; } /* Actions */ + public void captureFlag() { + if (stealing == null) { + return; + } + + Game game = Game.getByWorld(getWorld()); + if (game == null) { + return; + } + + game.sendMessage(DMessages.GROUP_FLAG_CAPTURED.getMessage(getName(), stealing.getName())); + + GameRules rules = game.getRules(); + + getDGroup().setScore(getDGroup().getScore() + 1); + if (rules.getScoreGoal() == dGroup.getScore()) { + dGroup.winGame(); + } + + stealing.setScore(stealing.getScore() - 1); + if (stealing.getScore() == -1) { + for (DGamePlayer member : stealing.getDGamePlayers()) { + member.kill(); + } + game.sendMessage(DMessages.GROUP_DEFEATED.getMessage(stealing.getName())); + } + + stealing = null; + player.getInventory().setHelmet(oldHelmet); + + if (game.getDGroups().size() == 1) { + dGroup.winGame(); + } + } + @Override public void leave() { leave(true); @@ -921,6 +959,7 @@ public class DGamePlayer extends DInstancePlayer { GameType gameType = game.getType(); if (gameType != null && gameType != GameTypeDefault.CUSTOM) { + if (gameType.getGameGoal() == GameGoal.LAST_MAN_STANDING) { if (game.getDGroups().size() == 1) { game.getDGroups().get(0).winGame(); }