Esempio n. 1
0
  /**
   * Cast a skill for active summon.<br>
   * Target is specified as a parameter but can be overwrited or ignored depending on skill type.
   *
   * @param skillId the skill Id to be casted by the summon
   * @param target the target to cast the skill on, overwritten or ignored depending on skill type
   * @param pet if {@code true} it'll validate a pet, if {@code false} it will validate a servitor
   */
  private void useSkill(int skillId, L2Object target, boolean pet) {
    final L2PcInstance activeChar = getActiveChar();
    if (activeChar == null) {
      return;
    }

    if (pet) {
      final L2Summon summon = activeChar.getPet();
      if (!validateSummon(summon, pet)) {
        return;
      }

      if (!canControl(summon)) {
        return;
      }

      final int lvl =
          PetDataTable.getInstance()
              .getPetData(summon.getId())
              .getAvailableLevel(skillId, summon.getLevel());

      if (lvl > 0) {
        summon.setTarget(target);
        summon.useMagic(
            SkillData.getInstance().getSkill(skillId, lvl), _ctrlPressed, _shiftPressed);
      }

      if (skillId == SWITCH_STANCE_ID) {
        summon.switchMode();
      }
    } else {
      final L2Summon servitor = activeChar.getAnyServitor();
      if (!validateSummon(servitor, pet)) {
        return;
      }

      final int lvl = SummonSkillsTable.getInstance().getAvailableLevel(servitor, skillId);

      if (lvl > 0) {
        servitor.setTarget(target);
        servitor.useMagic(
            SkillData.getInstance().getSkill(skillId, lvl), _ctrlPressed, _shiftPressed);
      }
    }
  }
Esempio n. 2
0
  /**
   * Cast a skill for all active summon.<br>
   * Target is retrieved from owner's target
   *
   * @param skillId the skill Id to use
   */
  private void useServitorsSkill(int skillId) {
    final L2PcInstance activeChar = getActiveChar();
    if (activeChar == null) {
      return;
    }

    activeChar
        .getServitors()
        .values()
        .forEach(
            servitor -> {
              if (!validateSummon(servitor, false)) {
                return;
              }

              final int lvl = SummonSkillsTable.getInstance().getAvailableLevel(servitor, skillId);

              if (lvl > 0) {
                servitor.setTarget(activeChar.getTarget());
                servitor.useMagic(
                    SkillData.getInstance().getSkill(skillId, lvl), _ctrlPressed, _shiftPressed);
              }
            });
  }