From b07cf6bddea861e323cae0912465e0bb74fc1143 Mon Sep 17 00:00:00 2001 From: GJ Date: Fri, 3 May 2013 15:49:29 -0400 Subject: [PATCH] It's now possible to run away from the Kraken. --- .../gmail/nossr50/config/AdvancedConfig.java | 2 + .../runnables/skills/KrakenAttackTask.java | 48 +++++++++++++++++-- .../skills/fishing/FishingManager.java | 20 ++++++-- src/main/resources/advanced.yml | 5 +- 4 files changed, 68 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java index c49c9a86b..6c55bb360 100644 --- a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java +++ b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java @@ -289,6 +289,8 @@ public class AdvancedConfig extends AutoUpdateConfigLoader { public String getKrakenName() { return config.getString("Kraken.Name", "The Kraken"); } public String getServerUnleashMessage() { return config.getString("Kraken.Unleashed_Message.Server", "(PLAYER) has unleashed the kraken!"); } public String getPlayerUnleashMessage() { return config.getString("Kraken.Unleashed_Message.Player", "THE KRAKEN HAS BEEN UNLEASHED!"); } + public String getPlayerDefeatMessage() { return config.getString("Kraken.Defeated_Message.Killed", "You have slain the kraken!"); } + public String getPlayerEscapeMessage() { return config.getString("Kraken.Defeated_Message.Escape", "You have escaped from the kraken!"); } public int getKrakenAttackInterval() { return config.getInt("Kraken.Attack_Interval_Seconds", 1); } public int getKrakenAttackDamage() { return config.getInt("Kraken.Attack_Damage", 1); } } diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/KrakenAttackTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/KrakenAttackTask.java index 0ca18aea4..c90f315cf 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/KrakenAttackTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/KrakenAttackTask.java @@ -13,6 +13,7 @@ import com.gmail.nossr50.util.Misc; public class KrakenAttackTask extends BukkitRunnable { private Squid kraken; private Player player; + private Location location; private final boolean GLOBAL_SOUNDS = AdvancedConfig.getInstance().getKrakenGlobalSoundsEnabled(); public KrakenAttackTask(Squid kraken, Player player) { @@ -20,15 +21,57 @@ public class KrakenAttackTask extends BukkitRunnable { this.player = player; } + public KrakenAttackTask(Squid kraken, Player player, Location location) { + this.kraken = kraken; + this.player = player; + this.location = location; + } + @Override public void run() { + if (location != null) { + Location playerLocation = player.getLocation(); + + if (player.isValid() && playerLocation.getBlock().isLiquid()) { + World world = player.getWorld(); + + player.damage(AdvancedConfig.getInstance().getKrakenAttackDamage(), kraken); + + if (GLOBAL_SOUNDS) { + world.playSound(playerLocation, Sound.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch()); + } + else { + player.playSound(playerLocation, Sound.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch()); + } + + world.strikeLightningEffect(playerLocation); + } + else { + player.sendMessage(AdvancedConfig.getInstance().getPlayerEscapeMessage()); + player.resetPlayerWeather(); + cancel(); + } + + return; + } + if (!kraken.isValid()) { + player.sendMessage(AdvancedConfig.getInstance().getPlayerDefeatMessage()); player.resetPlayerWeather(); - this.cancel(); + cancel(); } if (player.isValid()) { Location location = player.getLocation(); + + if (!location.getBlock().isLiquid()) { + player.sendMessage(AdvancedConfig.getInstance().getPlayerEscapeMessage()); + kraken.remove(); + player.resetPlayerWeather(); + cancel(); + return; + } + World world = player.getWorld(); kraken.teleport(player); @@ -41,12 +84,11 @@ public class KrakenAttackTask extends BukkitRunnable { player.playSound(location, Sound.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch()); } - world.playSound(location, Sound.GHAST_SCREAM, Misc.GHAST_VOLUME, Misc.getGhastPitch()); world.strikeLightningEffect(location); } else { kraken.remove(); - this.cancel(); + cancel(); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java b/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java index ae09af291..56eea4836 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java @@ -5,7 +5,6 @@ import java.util.Collections; import java.util.List; import org.bukkit.ChatColor; -import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; @@ -66,6 +65,10 @@ public class FishingManager extends SkillManager { return Permissions.masterAngler(getPlayer()); } +// public boolean unleashTheKraken() { +// +// } + private boolean unleashTheKraken() { if (fishingTries < AdvancedConfig.getInstance().getKrakenTriesBeforeRelease() || fishingTries <= Misc.getRandom().nextInt(200)) { return false; @@ -102,14 +105,25 @@ public class FishingManager extends SkillManager { String globalMessage = AdvancedConfig.getInstance().getServerUnleashMessage(); if (!globalMessage.isEmpty()) { - mcMMO.p.getServer().broadcastMessage(AdvancedConfig.getInstance().getServerUnleashMessage().replace("(PLAYER)", player.getDisplayName() + ChatColor.RED)); + mcMMO.p.getServer().broadcastMessage(ChatColor.RED + AdvancedConfig.getInstance().getServerUnleashMessage().replace("(PLAYER)", player.getDisplayName())); } + player.setItemInHand(null); + Squid kraken = (Squid) world.spawnEntity(player.getEyeLocation(), EntityType.SQUID); kraken.setCustomName(AdvancedConfig.getInstance().getKrakenName()); + kraken.remove(); + + if (!kraken.isValid()) { + int attackInterval = AdvancedConfig.getInstance().getKrakenAttackInterval() * 20; + new KrakenAttackTask(kraken, player, player.getLocation()).runTaskTimer(mcMMO.p, attackInterval, attackInterval); + + fishingTries = 1; + return true; + } + kraken.setMaxHealth(AdvancedConfig.getInstance().getKrakenHealth()); kraken.setHealth(kraken.getMaxHealth()); - player.setItemInHand(null); int attackInterval = AdvancedConfig.getInstance().getKrakenAttackInterval() * 20; new KrakenAttackTask(kraken, player).runTaskTimer(mcMMO.p, attackInterval, attackInterval); diff --git a/src/main/resources/advanced.yml b/src/main/resources/advanced.yml index b1bd44981..a9adf9662 100644 --- a/src/main/resources/advanced.yml +++ b/src/main/resources/advanced.yml @@ -425,4 +425,7 @@ Kraken: Global_Sounds: true Unleashed_Message: Server: (PLAYER) has unleashed the kraken! - Player: THE KRAKEN HAS BEEN UNLEASHED! \ No newline at end of file + Player: THE KRAKEN HAS BEEN UNLEASHED! + Defeated_Message: + Escape: You have escaped from the kraken! + Killed: You have slain the kraken! \ No newline at end of file