From 2bf1563b202954bafba94820718ddda2b8ceea8f Mon Sep 17 00:00:00 2001 From: GJ Date: Wed, 21 Mar 2012 02:03:22 -0400 Subject: [PATCH] Implemented slow/speed effects for Stick alt-fire. --- .../nossr50/listeners/mcEntityListener.java | 24 +++++++ .../java/com/gmail/nossr50/skills/Staves.java | 65 +++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java index 9ebfe743c..b1adba185 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java @@ -5,6 +5,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.Wolf; import org.bukkit.event.EventHandler; @@ -39,6 +40,7 @@ import com.gmail.nossr50.skills.Acrobatics; import com.gmail.nossr50.skills.Archery; import com.gmail.nossr50.skills.BlastMining; import com.gmail.nossr50.skills.Skills; +import com.gmail.nossr50.skills.Staves; import com.gmail.nossr50.skills.Taming; public class mcEntityListener implements Listener { @@ -80,6 +82,28 @@ public class mcEntityListener implements Listener { if (!m.isInvincible(livingDefender, event)) { Combat.combatChecks(event, plugin); } + + if (attacker.hasMetadata("mcmmoFiredFromStaff")) { + event.setDamage(0); + + Projectile projectile = (Projectile) attacker; + Player shooter = (Player) projectile.getShooter(); + + switch (attacker.getType()) { + case EGG: + Staves.eggEffect(livingDefender, shooter); + break; + + case FIREBALL: + break; + + case SNOWBALL: + break; + + default: + break; + } + } } } diff --git a/src/main/java/com/gmail/nossr50/skills/Staves.java b/src/main/java/com/gmail/nossr50/skills/Staves.java index 09d95c2de..f2fa477fe 100644 --- a/src/main/java/com/gmail/nossr50/skills/Staves.java +++ b/src/main/java/com/gmail/nossr50/skills/Staves.java @@ -1,16 +1,23 @@ package com.gmail.nossr50.skills; +import java.util.Collection; + import org.bukkit.Material; import org.bukkit.entity.Egg; import org.bukkit.entity.Fireball; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.entity.Snowball; import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.party.Party; public class Staves { + /** * Fire a projectile on alt-fire from a staff. @@ -41,4 +48,62 @@ public class Staves { projectile.setMetadata("mcmmoFiredFromStaff", new FixedMetadataValue(plugin, true)); } + + /** + * Handle the effects of the Stick's projectile. + * + * @param target Entity hit by the projectile + * @param shooter Player who fired the projectile + */ + public static void eggEffect(LivingEntity target, Player shooter) { + final int TICKS_PER_SECOND = 20; + final int MAX_SLOW_DURATION_SECONDS = 240; + final int MAX_SPEED_DURATION_SECONDS = 800; + + Collection potionEffects = target.getActivePotionEffects(); + + int duration = durationCalulate(); + int amplifier = amplifierCalulate(); + PotionEffectType type; + + if (target instanceof Player && Party.getInstance().inSameParty((Player) target, shooter)) { + type = PotionEffectType.SPEED; + } + else { + type = PotionEffectType.SLOW; + } + + for (PotionEffect effect : potionEffects) { + if (effect.getType().equals(type)) { + duration = duration + effect.getDuration(); + break; + } + } + + if (type.equals(PotionEffectType.SLOW) && duration > (TICKS_PER_SECOND * MAX_SLOW_DURATION_SECONDS)) { + duration = (TICKS_PER_SECOND * MAX_SLOW_DURATION_SECONDS); + } + else if (type.equals(PotionEffectType.SPEED) && duration > (TICKS_PER_SECOND * MAX_SPEED_DURATION_SECONDS)) { + duration = (TICKS_PER_SECOND * MAX_SPEED_DURATION_SECONDS); + } + + target.addPotionEffect(new PotionEffect(type, duration, amplifier)); + + if (type.equals(PotionEffectType.SLOW)) { + shooter.sendMessage("Your enemy was slowed!"); //TODO: Use mcLocale + } + else { + shooter.sendMessage("Your ally's speed was boosted!"); //TODO: Use mcLocale + } + } + + private static int durationCalulate() { + //TODO: Calculate duration based off time held + return 80; + } + + private static int amplifierCalulate() { + //TODO: Calculate amplifier based off skill level + return 10; + } }