Exemplo n.º 1
0
 @Override
 public PostCastAction castSpell(Player player, SpellCastState state, float power, String[] args) {
   if (state == SpellCastState.NORMAL) {
     Block block = null;
     if (targeted) {
       block = getTargetedBlock(player, power);
     } else {
       block = player.getLocation().subtract(0, 1, 0).getBlock();
     }
     if (block != null) {
       SpellTargetLocationEvent event =
           new SpellTargetLocationEvent(this, player, block.getLocation(), power);
       Bukkit.getPluginManager().callEvent(event);
       if (event.isCancelled()) {
         block = null;
       } else {
         block = event.getTargetLocation().getBlock();
         power = event.getPower();
       }
     }
     if (block != null) {
       boolean farmed = farm(block, Math.round(radius * power));
       if (!farmed) return noTarget(player);
       playSpellEffects(EffectPosition.CASTER, player);
       if (targeted) {
         playSpellEffects(EffectPosition.TARGET, block.getLocation());
       }
     } else {
       return noTarget(player);
     }
   }
   return PostCastAction.HANDLE_NORMALLY;
 }
Exemplo n.º 2
0
 private boolean activateSpells(
     Player caster, LivingEntity target, Location location, float basePower) {
   SpellCastState state = getCastState(caster);
   MagicSpells.debug(
       3,
       "Activating passive spell '"
           + name
           + "' for player "
           + caster.getName()
           + " (state: "
           + state
           + ")");
   if (!disabled
       && (chance >= .999 || random.nextFloat() <= chance)
       && state == SpellCastState.NORMAL) {
     disabled = true;
     SpellCastEvent event =
         new SpellCastEvent(
             this,
             caster,
             SpellCastState.NORMAL,
             basePower,
             null,
             this.cooldown,
             this.reagents.clone(),
             0);
     Bukkit.getPluginManager().callEvent(event);
     if (!event.isCancelled() && event.getSpellCastState() == SpellCastState.NORMAL) {
       if (event.haveReagentsChanged() && !hasReagents(caster, event.getReagents())) {
         disabled = false;
         return false;
       }
       setCooldown(caster, event.getCooldown());
       basePower = event.getPower();
       for (Spell spell : spells) {
         MagicSpells.debug(3, "    Casting spell effect '" + spell.getName() + "'");
         if (castWithoutTarget) {
           MagicSpells.debug(3, "    Casting without target");
           spell.castSpell(caster, SpellCastState.NORMAL, basePower, null);
           playSpellEffects(EffectPosition.CASTER, caster);
         } else if (spell instanceof TargetedEntitySpell
             && target != null
             && !isNonTargetedExternal(spell)) {
           MagicSpells.debug(3, "    Casting at entity");
           SpellTargetEvent targetEvent = new SpellTargetEvent(this, caster, target, basePower);
           Bukkit.getPluginManager().callEvent(targetEvent);
           if (!targetEvent.isCancelled()) {
             target = targetEvent.getTarget();
             ((TargetedEntitySpell) spell).castAtEntity(caster, target, targetEvent.getPower());
             playSpellEffects(caster, target);
           } else {
             MagicSpells.debug(3, "      Target cancelled (TE)");
           }
         } else if (spell instanceof TargetedLocationSpell
             && (location != null || target != null)) {
           MagicSpells.debug(3, "    Casting at location");
           Location loc = null;
           if (location != null) {
             loc = location;
           } else if (target != null) {
             loc = target.getLocation();
           }
           if (loc != null) {
             SpellTargetLocationEvent targetEvent =
                 new SpellTargetLocationEvent(this, caster, loc, basePower);
             Bukkit.getPluginManager().callEvent(targetEvent);
             if (!targetEvent.isCancelled()) {
               loc = targetEvent.getTargetLocation();
               ((TargetedLocationSpell) spell).castAtLocation(caster, loc, targetEvent.getPower());
               playSpellEffects(caster, loc);
             } else {
               MagicSpells.debug(3, "      Target cancelled (TL)");
             }
           }
         } else {
           MagicSpells.debug(3, "    Casting normally");
           float power = basePower;
           if (target != null) {
             SpellTargetEvent targetEvent = new SpellTargetEvent(this, caster, target, power);
             Bukkit.getPluginManager().callEvent(targetEvent);
             if (!targetEvent.isCancelled()) {
               power = targetEvent.getPower();
             } else {
               MagicSpells.debug(3, "      Target cancelled (UE)");
               continue;
             }
           } else if (location != null) {
             SpellTargetLocationEvent targetEvent =
                 new SpellTargetLocationEvent(this, caster, location, basePower);
             Bukkit.getPluginManager().callEvent(targetEvent);
             if (!targetEvent.isCancelled()) {
               power = targetEvent.getPower();
             } else {
               MagicSpells.debug(3, "      Target cancelled (UL)");
               continue;
             }
           }
           spell.castSpell(caster, SpellCastState.NORMAL, power, null);
           playSpellEffects(EffectPosition.CASTER, caster);
         }
       }
       removeReagents(caster, event.getReagents());
       sendMessage(caster, strCastSelf);
       SpellCastedEvent event2 =
           new SpellCastedEvent(
               this,
               caster,
               SpellCastState.NORMAL,
               basePower,
               null,
               event.getCooldown(),
               event.getReagents(),
               PostCastAction.HANDLE_NORMALLY);
       Bukkit.getPluginManager().callEvent(event2);
       disabled = false;
       return true;
     } else {
       MagicSpells.debug(3, "   Passive spell canceled");
       disabled = false;
       return false;
     }
   } else if (state != SpellCastState.NORMAL && sendFailureMessages) {
     if (state == SpellCastState.ON_COOLDOWN) {
       MagicSpells.sendMessage(
           caster, formatMessage(strOnCooldown, "%c", Math.round(getCooldown(caster)) + ""));
     } else if (state == SpellCastState.MISSING_REAGENTS) {
       MagicSpells.sendMessage(caster, strMissingReagents);
       if (MagicSpells.showStrCostOnMissingReagents() && strCost != null && !strCost.isEmpty()) {
         MagicSpells.sendMessage(caster, "    (" + strCost + ")");
       }
     }
   }
   return false;
 }