From 9ebf96cfd5e6b06b09a6b3ebe5eafc78eab0781a Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 30 Apr 2018 11:42:01 +0100 Subject: [PATCH] Bacon Brawl refactor --- .../game/games/baconbrawl/BaconBrawl.java | 127 ++++++++++++------ 1 file changed, 84 insertions(+), 43 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/baconbrawl/BaconBrawl.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/baconbrawl/BaconBrawl.java index cdd365af7..30acdfeeb 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/baconbrawl/BaconBrawl.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/baconbrawl/BaconBrawl.java @@ -1,17 +1,25 @@ package nautilus.game.arcade.game.games.baconbrawl; +import java.util.concurrent.TimeUnit; + import org.bukkit.GameMode; +import org.bukkit.Sound; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import mineplex.core.common.util.C; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTime; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.SoloGame; import nautilus.game.arcade.game.games.baconbrawl.kits.KitMamaPig; import nautilus.game.arcade.game.games.baconbrawl.kits.KitPig; @@ -21,26 +29,31 @@ import nautilus.game.arcade.kit.Kit; public class BaconBrawl extends SoloGame { - public BaconBrawl(ArcadeManager manager) + + private static final String[] DESCRIPTION = + { + "Knock other pigs out of the arena!", + "Last pig in the arena wins!", + "Knockback increases over time!" + }; + + private double _knockbackMagnitude = 1.5; + private long _increaseLast, _increaseTime = TimeUnit.SECONDS.toMillis(50); + + public BaconBrawl(ArcadeManager manager) { - super(manager, GameType.BaconBrawl, + super(manager, GameType.BaconBrawl, new Kit[] + { + new KitPig(manager), + new KitMamaPig(manager), + new KitSheepPig(manager) + }, DESCRIPTION); - new Kit[] - { - new KitPig(manager), - new KitMamaPig(manager), - new KitSheepPig(manager) - }, - - new String[] - { - "Knock other pigs out of the arena!", - "Last pig in the arena wins!" - }); - DamageTeamSelf = true; HungerSet = 20; PrepareFreeze = false; + StrictAntiHack = true; + PlayerGameMode = GameMode.ADVENTURE; registerChatStats( Kills, @@ -53,53 +66,81 @@ public class BaconBrawl extends SoloGame ); new CompassModule() - .setGiveCompass(true) - .setGiveCompassToSpecs(true) - .setGiveCompassToAlive(false) .register(this); - - StrictAntiHack = true; - - PlayerGameMode = GameMode.ADVENTURE; } - + @EventHandler - public void Hunger(UpdateEvent event) + public void live(GameStateChangeEvent event) { - if (event.getType() != UpdateType.SLOW) + if (event.GetState() != GameState.Live) + { return; - - if (!IsLive()) + } + + _increaseLast = System.currentTimeMillis(); + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOW || !IsLive()) + { return; - + } + for (Player player : GetPlayers(true)) { if (player.getFoodLevel() <= 0) { - Manager.GetDamage().NewDamageEvent(player, null, null, - DamageCause.STARVATION, 4, false, true, false, - "Starvation", GetName()); + Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.STARVATION, 4, false, true, false, GetName(), "Starvation"); } - + UtilPlayer.hunger(player, -1); } + + if (_increaseTime > 0 && UtilTime.elapsed(_increaseLast, _increaseTime)) + { + _increaseLast = System.currentTimeMillis(); + _increaseTime -= TimeUnit.SECONDS.toMillis(5); + _knockbackMagnitude *= 1.2; + + String message = C.cGreenB + "The ground begins to tremble... All pigs now take more knockback!"; + + for (Player player : UtilServer.getPlayersCollection()) + { + player.sendMessage(message); + player.playSound(player.getLocation(), Sound.ENDERDRAGON_WINGS, 1, 0.5F); + } + } } - + @EventHandler - public void HungerRestore(CustomDamageEvent event) + public void hungerRestore(CustomDamageEvent event) { Player damager = event.GetDamagerPlayer(true); + if (damager != null) - UtilPlayer.hunger(damager, 2); - } - - @EventHandler - public void DamageEvent(CustomDamageEvent event) - { - if (event.GetCause() == DamageCause.ENTITY_ATTACK || event.GetCause() == DamageCause.CUSTOM || event.GetCause() == DamageCause.PROJECTILE) { - event.GetDamageeEntity().setHealth(event.GetDamageeEntity().getMaxHealth()); - event.AddKnockback("Pig Wrestle", 1.5 + ((System.currentTimeMillis() - GetStateTime()) / 120000d)); + UtilPlayer.hunger(damager, 2); + } + } + + @EventHandler + public void knockback(CustomDamageEvent event) + { + if (!IsLive()) + { + return; + } + + DamageCause cause = event.GetCause(); + + if (cause == DamageCause.ENTITY_ATTACK || cause == DamageCause.CUSTOM || cause == DamageCause.PROJECTILE) + { + LivingEntity entity = event.GetDamageeEntity(); + + entity.setHealth(entity.getMaxHealth()); + event.AddKnockback("Pig Wrestle", _knockbackMagnitude); } } }