Exemplo n.º 1
0
  private final void useBlockCheckerItem(final L2PcInstance castor, L2ItemInstance item) {
    final int blockCheckerArena = castor.getBlockCheckerArena();
    if (blockCheckerArena == -1) {
      SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
      msg.addItemName(item);
      castor.sendPacket(msg);
      return;
    }

    final L2Skill sk = item.getEtcItem().getSkills()[0].getSkill();
    if (sk == null) return;

    if (!castor.destroyItem("Consume", item, 1, castor, true)) return;

    final L2BlockInstance block = (L2BlockInstance) castor.getTarget();

    final ArenaParticipantsHolder holder =
        HandysBlockCheckerManager.getInstance().getHolder(blockCheckerArena);
    if (holder != null) {
      final int team = holder.getPlayerTeam(castor);
      for (final L2PcInstance pc :
          block.getKnownList().getKnownPlayersInRadius(sk.getEffectRange())) {
        final int enemyTeam = holder.getPlayerTeam(pc);
        if (enemyTeam != -1 && enemyTeam != team) sk.getEffects(castor, pc);
      }
    } else
      _log.warning(
          "Char: "
              + castor.getName()
              + "["
              + castor.getObjectId()
              + "] has unknown block checker arena");
  }
Exemplo n.º 2
0
  /* (non-Javadoc)
   * @see l2.brick.gameserver.handler.IItemHandler#useItem(l2.brick.gameserver.model.actor.L2Playable, l2.brick.gameserver.model.L2ItemInstance, boolean)
   */
  @Override
  public void useItem(L2Playable playable, L2ItemInstance item, boolean forceUse) {
    if (!(playable instanceof L2PcInstance)) return;

    final L2PcInstance activeChar = (L2PcInstance) playable;

    final int itemId = item.getItemId();
    switch (itemId) {
      case 13787: // Handy's Block Checker Bond
        useBlockCheckerItem(activeChar, item);
        break;
      case 13788: // Handy's Block Checker Land Mine
        useBlockCheckerItem(activeChar, item);
        break;
      default:
        _log.warning("EventItemHandler: Item with id: " + itemId + " is not handled");
    }
  }
  @Override
  protected void runImpl() {
    if (_skillId <= 0 || _skillLvl <= 0) // minimal sanity check
    return;

    L2PcInstance player = getClient().getActiveChar();
    if (player == null) return;

    if (player.getClassId().level() < 3) // requires to have 3rd class quest completed
    {
      player.sendPacket(SystemMessageId.YOU_CANNOT_USE_SKILL_ENCHANT_IN_THIS_CLASS);
      return;
    }

    if (player.getLevel() < 76) {
      player.sendPacket(SystemMessageId.YOU_CANNOT_USE_SKILL_ENCHANT_ON_THIS_LEVEL);
      return;
    }

    if (!player.isAllowedToEnchantSkills()) {
      player.sendPacket(SystemMessageId.YOU_CANNOT_USE_SKILL_ENCHANT_ATTACKING_TRANSFORMED_BOAT);
      return;
    }

    L2EnchantSkillLearn s = EnchantGroupsTable.getInstance().getSkillEnchantmentBySkillId(_skillId);
    if (s == null) return;

    if (_skillLvl % 100 == 0) {
      _skillLvl = s.getBaseLevel();
    }

    L2Skill skill = SkillTable.getInstance().getInfo(_skillId, _skillLvl);
    if (skill == null) return;

    int reqItemId = EnchantGroupsTable.UNTRAIN_ENCHANT_BOOK;

    final int beforeUntrainSkillLevel = player.getSkillLevel(_skillId);
    if (beforeUntrainSkillLevel - 1 != _skillLvl
        && (beforeUntrainSkillLevel % 100 != 1 || _skillLvl != s.getBaseLevel())) return;

    EnchantSkillDetail esd = s.getEnchantSkillDetail(beforeUntrainSkillLevel);

    int requiredSp = esd.getSpCost();
    int requireditems = esd.getAdenaCost();

    L2ItemInstance spb = player.getInventory().getItemByItemId(reqItemId);
    if (Config.ES_SP_BOOK_NEEDED) {
      if (spb == null) // Haven't spellbook
      {
        player.sendPacket(
            SystemMessageId.YOU_DONT_HAVE_ALL_OF_THE_ITEMS_NEEDED_TO_ENCHANT_THAT_SKILL);
        return;
      }
    }

    if (player.getInventory().getAdena() < requireditems) {
      player.sendPacket(
          SystemMessageId.YOU_DONT_HAVE_ALL_OF_THE_ITEMS_NEEDED_TO_ENCHANT_THAT_SKILL);
      return;
    }

    boolean check = true;
    if (Config.ES_SP_BOOK_NEEDED) {
      check &= player.destroyItem("Consume", spb.getObjectId(), 1, player, true);
    }

    check &=
        player.destroyItemByItemId("Consume", PcInventory.ADENA_ID, requireditems, player, true);

    if (!check) {
      player.sendPacket(
          SystemMessageId.YOU_DONT_HAVE_ALL_OF_THE_ITEMS_NEEDED_TO_ENCHANT_THAT_SKILL);
      return;
    }

    player.getStat().addSp((int) (requiredSp * 0.8));

    if (Config.LOG_SKILL_ENCHANTS) {
      LogRecord record = new LogRecord(Level.INFO, "Untrain");
      record.setParameters(new Object[] {player, skill, spb});
      record.setLoggerName("skill");
      _logEnchant.log(record);
    }

    player.addSkill(skill, true);
    player.sendPacket(ExEnchantSkillResult.valueOf(true));

    if (Config.DEBUG) {
      _log.fine(
          "Learned skill ID: "
              + _skillId
              + " Level: "
              + _skillLvl
              + " for "
              + requiredSp
              + " SP, "
              + requireditems
              + " Adena.");
    }

    player.sendPacket(new UserInfo(player));
    player.sendPacket(new ExBrExtraUserInfo(player));

    if (_skillLvl > 100) {
      SystemMessage sm =
          SystemMessage.getSystemMessage(
              SystemMessageId.UNTRAIN_SUCCESSFUL_SKILL_S1_ENCHANT_LEVEL_DECREASED_BY_ONE);
      sm.addSkillName(_skillId);
      player.sendPacket(sm);
    } else {
      SystemMessage sm =
          SystemMessage.getSystemMessage(
              SystemMessageId.UNTRAIN_SUCCESSFUL_SKILL_S1_ENCHANT_LEVEL_RESETED);
      sm.addSkillName(_skillId);
      player.sendPacket(sm);
    }
    player.sendSkillList();
    final int afterUntrainSkillLevel = player.getSkillLevel(_skillId);
    player.sendPacket(new ExEnchantSkillInfo(_skillId, afterUntrainSkillLevel));
    player.sendPacket(
        new ExEnchantSkillInfoDetail(2, _skillId, afterUntrainSkillLevel - 1, player));
    player.updateShortCuts(_skillId, afterUntrainSkillLevel);
  }