Browse Source

Changed alt-fire on staves to all use the same function.

GJ 13 years ago
parent
commit
7f9d5d0183
1 changed files with 130 additions and 71 deletions
  1. 130 71
      src/main/java/com/gmail/nossr50/skills/Staves.java

+ 130 - 71
src/main/java/com/gmail/nossr50/skills/Staves.java

@@ -6,10 +6,10 @@ import org.bukkit.Material;
 import org.bukkit.entity.Egg;
 import org.bukkit.entity.Entity;
 import org.bukkit.entity.EntityType;
-import org.bukkit.entity.Fireball;
 import org.bukkit.entity.LivingEntity;
 import org.bukkit.entity.Player;
 import org.bukkit.entity.Projectile;
+import org.bukkit.entity.SmallFireball;
 import org.bukkit.entity.Snowball;
 import org.bukkit.event.entity.EntityDamageByEntityEvent;
 import org.bukkit.metadata.FixedMetadataValue;
@@ -21,6 +21,11 @@ import com.gmail.nossr50.party.Party;
 
 public class Staves {
 
+    /**
+     * Handle the projectile effects from the staves.
+     *
+     * @param event The event to modify
+     */
     public static void altFireCheck(EntityDamageByEntityEvent event) {
         LivingEntity defender = (LivingEntity) event.getEntity();
         Entity attacker = event.getDamager();
@@ -30,24 +35,9 @@ public class Staves {
 
             Projectile projectile = (Projectile) attacker;
             Player shooter = (Player) projectile.getShooter();
+            EntityType type = attacker.getType();
 
-            switch (attacker.getType()) {
-            case EGG:
-                eggEffect(defender, shooter);
-                break;
-
-            case FIREBALL:
-                break;
-
-            case SNOWBALL:
-                if (defender.getType().equals(EntityType.PLAYER)) {
-                    snowballEffect((Player) defender, shooter);
-                }
-                break;
-
-            default:
-                break;
-            }
+            projectileEffects(defender, shooter, type);
         }
     }
 
@@ -67,7 +57,9 @@ public class Staves {
 
         switch (type) {
         case BLAZE_ROD:
-            projectile = attacker.launchProjectile(Fireball.class);
+            projectile = attacker.launchProjectile(SmallFireball.class);
+            ((SmallFireball) projectile).setIsIncendiary(false);
+            ((SmallFireball) projectile).setYield(0f);
             break;
 
         case BONE:
@@ -86,58 +78,6 @@ 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
-     */
-    private 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<PotionEffect> 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
-            if (target instanceof Player) {
-                ((Player) target).sendMessage("You were slowed!"); //TODO: Use mcLocale
-            }
-        }
-        else {
-            shooter.sendMessage("Your ally's speed was boosted!"); //TODO: Use mcLocale
-            ((Player) target).sendMessage("Your speed was boosted!"); //TODO: Use mcLocale
-        }
-    }
-
     /**
      * Handle the effects of the Bone's projectile.
      *
@@ -215,6 +155,125 @@ public class Staves {
         }
     }
 
+    /**
+     * Handle the special effects from the staff projectiles.
+     *
+     * @param defender The defending entity
+     * @param shooter The attacking player
+     * @param type The type of projectile
+     */
+    private static void projectileEffects(LivingEntity target, Player shooter, EntityType projectile) {
+        final int TICKS_PER_SECOND = 20;
+        final int MAX_SLOW_DURATION_SECONDS = 240;
+        final int MAX_SPEED_DURATION_SECONDS = 480;
+        final int MAX_WEAKNESS_DURATION_SECONDS = 240;
+        final int MAX_STRENGTH_DURATION_SECONDS = 480;
+        final int MAX_POISON_DURATION_SECONDS = 120;
+        final int MAX_REGEN_DURATION_SECONDS = 120;
+
+        Collection<PotionEffect> potionEffects = target.getActivePotionEffects();
+
+        int duration = durationCalulate();
+        int amplifier = amplifierCalulate();
+        PotionEffectType potionType = null;
+
+        if (target instanceof Player && Party.getInstance().inSameParty((Player) target, shooter)) {
+            switch (projectile) {
+            case EGG:
+                potionType = PotionEffectType.REGENERATION;
+                break;
+
+            case SMALL_FIREBALL:
+                potionType = PotionEffectType.SPEED;
+                break;
+
+            case SNOWBALL:
+                potionType = PotionEffectType.INCREASE_DAMAGE;
+                break;
+
+            default:
+                break;
+            }
+        }
+        else {
+            switch (projectile) {
+            case EGG:
+                potionType = PotionEffectType.POISON;
+                break;
+
+            case SMALL_FIREBALL:
+                potionType = PotionEffectType.SLOW;
+                break;
+
+            case SNOWBALL:
+                potionType = PotionEffectType.WEAKNESS;
+                break;
+
+            default:
+                break;
+            }
+        }
+
+        for (PotionEffect effect : potionEffects) {
+            if (effect.getType().equals(potionType)) {
+                duration = duration + effect.getDuration();
+                break;
+            }
+        }
+
+        if (potionType.equals(PotionEffectType.SLOW) && duration > (TICKS_PER_SECOND * MAX_SLOW_DURATION_SECONDS)) {
+            duration = (TICKS_PER_SECOND * MAX_SLOW_DURATION_SECONDS);
+        }
+        else if (potionType.equals(PotionEffectType.SPEED) && duration > (TICKS_PER_SECOND * MAX_SPEED_DURATION_SECONDS)) {
+            duration = (TICKS_PER_SECOND * MAX_SPEED_DURATION_SECONDS);
+        }
+        else if (potionType.equals(PotionEffectType.WEAKNESS) && duration > (TICKS_PER_SECOND * MAX_WEAKNESS_DURATION_SECONDS)) {
+            duration = (TICKS_PER_SECOND * MAX_WEAKNESS_DURATION_SECONDS);
+        }
+        else if (potionType.equals(PotionEffectType.INCREASE_DAMAGE) && duration > (TICKS_PER_SECOND * MAX_STRENGTH_DURATION_SECONDS)) {
+            duration = (TICKS_PER_SECOND * MAX_STRENGTH_DURATION_SECONDS);
+        }
+        else if (potionType.equals(PotionEffectType.POISON) && duration > (TICKS_PER_SECOND * MAX_POISON_DURATION_SECONDS)) {
+            duration = (TICKS_PER_SECOND * MAX_POISON_DURATION_SECONDS);
+        }
+        else if (potionType.equals(PotionEffectType.REGENERATION) && duration > (TICKS_PER_SECOND * MAX_REGEN_DURATION_SECONDS)) {
+            duration = (TICKS_PER_SECOND * MAX_REGEN_DURATION_SECONDS);
+        }
+
+        target.addPotionEffect(new PotionEffect(potionType, duration, amplifier));
+
+        if (potionType.equals(PotionEffectType.SLOW)) {
+            shooter.sendMessage("Your enemy was slowed!"); //TODO: Use mcLocale
+            if (target instanceof Player) {
+                ((Player) target).sendMessage("You were slowed!"); //TODO: Use mcLocale
+            }
+        }
+        else if (potionType.equals(PotionEffectType.SPEED)) {
+            shooter.sendMessage("Your ally's speed was boosted!"); //TODO: Use mcLocale
+            ((Player) target).sendMessage("Your speed was boosted!"); //TODO: Use mcLocale
+        }
+        else if (potionType.equals(PotionEffectType.WEAKNESS)) {
+            shooter.sendMessage("Your enemy was weakened!"); //TODO: Use mcLocale
+            if (target instanceof Player) {
+                ((Player) target).sendMessage("You were weakened!"); //TODO: Use mcLocale
+            }
+        }
+        else if (potionType.equals(PotionEffectType.INCREASE_DAMAGE)) {
+            shooter.sendMessage("Your ally's was strengthened!"); //TODO: Use mcLocale
+            ((Player) target).sendMessage("You were strengthened!"); //TODO: Use mcLocale
+        }
+        else if (potionType.equals(PotionEffectType.POISON)) {
+            shooter.sendMessage("Your enemy was poisoned!"); //TODO: Use mcLocale
+            if (target instanceof Player) {
+                ((Player) target).sendMessage("You were poisoned!"); //TODO: Use mcLocale
+            }
+        }
+        else if (potionType.equals(PotionEffectType.REGENERATION)) {
+            shooter.sendMessage("Your ally's began regaining health!"); //TODO: Use mcLocale
+            ((Player) target).sendMessage("You began regaining health!"); //TODO: Use mcLocale
+        }
+    }
+
     private static int durationCalulate() {
         //TODO: Calculate duration based off time held
         return 80;