Esempio n. 1
0
  @Override
  public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets) {
    boolean acted = true;

    L2PcInstance player = null;
    if (activeChar instanceof L2PcInstance) {
      player = (L2PcInstance) activeChar;
    }

    if (skill.getEffectId() != 0) {
      L2Skill sk =
          SkillTable.getInstance()
              .getInfo(skill.getEffectId(), skill.getEffectLvl() == 0 ? 1 : skill.getEffectLvl());

      if (sk != null) {
        skill = sk;
      }
    }

    boolean ss = activeChar.isSoulshotCharged(skill);
    boolean sps = activeChar.isSpiritshotCharged(skill);
    boolean bss = activeChar.isBlessedSpiritshotCharged(skill);

    L2Character target;
    for (L2Object obj : targets) {
      if (obj instanceof L2Character) {
        target = (L2Character) obj;
      } else {
        continue;
      }

      byte shld = 0;

      if (Reflect.calcSkillReflect(target, skill) == Variables.SKILL_REFLECT_SUCCEED) {
        target = activeChar;
      }

      // Персонаж, владеющий ПО, не может быть бафнутым и не сам не может никого бафать
      if (skill.getSkillType() == L2SkillType.BUFF
          && activeChar.isNpc()
          && ((L2Npc) activeChar).getClanHall() != null) {
        if (!target.equals(activeChar)) {
          if (target instanceof L2PcInstance) {
            L2PcInstance trg = (L2PcInstance) target;
            if (trg.isCursedWeaponEquipped()) {
              continue;
            }
            // Avoiding block checker players get buffed from outside
            else if (trg.getEventController().isInHandysBlockCheckerEventArena()) {
              continue;
            }
          } else if (player != null && player.isCursedWeaponEquipped()) {
            continue;
          }
        }
      }

      switch (skill.getSkillType()) {
        case HOT:
        case CPHOT:
        case MPHOT:
          if (activeChar.isInvul()) {
            continue;
          }
          break;
      }

      if (skill.isOffensive() || skill.isDebuff()) {
        shld = Shield.calcShldUse(activeChar, target, skill);
        acted = Skills.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss);
      }

      if (acted) {
        if (skill.isToggle()) {
          for (L2Effect e : target.getAllEffects()) {
            if (e != null && e.getSkill().getId() == skill.getId()) {
              e.exit();
              return;
            }
          }
        }

        // if this is a debuff let the duel manager know about it
        // so the debuff can be removed after the duel
        // (player & target must be in the same duel)
        if (target instanceof L2PcInstance
            && ((L2PcInstance) target).isInDuel()
            && (skill.getSkillType() == L2SkillType.DEBUFF
                || skill.getSkillType() == L2SkillType.BUFF)
            && player != null
            && player.getDuelId() == ((L2PcInstance) target).getDuelId()) {
          DuelManager dm = DuelManager.getInstance();
          for (L2Effect buff : skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss))) {
            if (buff != null) {
              dm.onBuff((L2PcInstance) target, buff);
            }
          }
        } else {
          L2Effect[] effects = skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));

          if (target instanceof L2PcInstance && !target.getPets().isEmpty()) {
            for (L2Summon pet : target.getPets()) {
              if (!pet.equals(activeChar)
                  && pet instanceof L2SummonInstance
                  && effects.length > 0) {
                if (effects[0].canBeStolen() || skill.isHeroSkill() || skill.isStatic()) {
                  skill.getEffects(activeChar, pet, new Env(shld, ss, sps, bss));
                }
              }
            }
          }
        }

        if (skill.getSkillType() == L2SkillType.AGGDEBUFF) {
          if (target instanceof L2Attackable) {
            target
                .getAI()
                .notifyEvent(CtrlEvent.EVT_AGGRESSION, activeChar, (int) skill.getPower());
          } else if (target instanceof L2Playable) {
            if (target.getTarget().equals(activeChar)) {
              target.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, activeChar);
            } else {
              target.setTarget(activeChar);
            }
          }
        }
      } else {
        activeChar.sendPacket(SystemMessageId.ATTACK_FAILED);
      }

      // Possibility of a lethal strike
      BlowDamage.calcLethalHit(activeChar, target, skill);
    }

    // self Effect :]
    if (skill.hasSelfEffects()) {
      L2Effect effect = activeChar.getFirstEffect(skill.getId());
      if (effect != null && effect.isSelfEffect()) {
        // Replace old effect with new one.
        effect.exit();
      }
      skill.getEffectsSelf(activeChar);
    }

    activeChar.spsUncharge(skill);
  }