Bacon Brawl refactor

This commit is contained in:
Sam 2018-04-30 11:42:01 +01:00 committed by Alexander Meech
parent bca212a544
commit 9ebf96cfd5

View File

@ -1,17 +1,25 @@
package nautilus.game.arcade.game.games.baconbrawl; package nautilus.game.arcade.game.games.baconbrawl;
import java.util.concurrent.TimeUnit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Sound;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilPlayer; 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.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType; import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.SoloGame; import nautilus.game.arcade.game.SoloGame;
import nautilus.game.arcade.game.games.baconbrawl.kits.KitMamaPig; import nautilus.game.arcade.game.games.baconbrawl.kits.KitMamaPig;
import nautilus.game.arcade.game.games.baconbrawl.kits.KitPig; 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 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; DamageTeamSelf = true;
HungerSet = 20; HungerSet = 20;
PrepareFreeze = false; PrepareFreeze = false;
StrictAntiHack = true;
PlayerGameMode = GameMode.ADVENTURE;
registerChatStats( registerChatStats(
Kills, Kills,
@ -53,53 +66,81 @@ public class BaconBrawl extends SoloGame
); );
new CompassModule() new CompassModule()
.setGiveCompass(true)
.setGiveCompassToSpecs(true)
.setGiveCompassToAlive(false)
.register(this); .register(this);
StrictAntiHack = true;
PlayerGameMode = GameMode.ADVENTURE;
} }
@EventHandler @EventHandler
public void Hunger(UpdateEvent event) public void live(GameStateChangeEvent event)
{ {
if (event.getType() != UpdateType.SLOW) if (event.GetState() != GameState.Live)
{
return; return;
}
if (!IsLive())
_increaseLast = System.currentTimeMillis();
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOW || !IsLive())
{
return; return;
}
for (Player player : GetPlayers(true)) for (Player player : GetPlayers(true))
{ {
if (player.getFoodLevel() <= 0) if (player.getFoodLevel() <= 0)
{ {
Manager.GetDamage().NewDamageEvent(player, null, null, Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.STARVATION, 4, false, true, false, GetName(), "Starvation");
DamageCause.STARVATION, 4, false, true, false,
"Starvation", GetName());
} }
UtilPlayer.hunger(player, -1); 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 @EventHandler
public void HungerRestore(CustomDamageEvent event) public void hungerRestore(CustomDamageEvent event)
{ {
Player damager = event.GetDamagerPlayer(true); Player damager = event.GetDamagerPlayer(true);
if (damager != null) 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()); UtilPlayer.hunger(damager, 2);
event.AddKnockback("Pig Wrestle", 1.5 + ((System.currentTimeMillis() - GetStateTime()) / 120000d)); }
}
@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);
} }
} }
} }