@Override
  protected void runImpl() {
    // Get the current L2PcInstance of the player
    final L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null) {
      return;
    }

    // Get the level of the used skill
    int level = activeChar.getSkillLevel(_skillId);
    if (level <= 0) {
      activeChar.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    // Get the L2Skill template corresponding to the skillID received from the client
    Skill skill = SkillData.getInstance().getSkill(_skillId, level);

    // Check the validity of the skill
    if (skill != null) {
      activeChar.setCurrentSkillWorldPosition(new Location(_x, _y, _z));

      // normally magicskilluse packet turns char client side but for these skills, it doesn't (even
      // with correct target)
      activeChar.setHeading(
          Util.calculateHeadingFrom(activeChar.getX(), activeChar.getY(), _x, _y));
      Broadcast.toKnownPlayers(activeChar, new ValidateLocation(activeChar));

      activeChar.useMagic(skill, _ctrlPressed, _shiftPressed);
    } else {
      activeChar.sendPacket(ActionFailed.STATIC_PACKET);
      _log.warning("No skill found with id " + _skillId + " and level " + level + " !!");
    }
  }
  @Override
  protected void runImpl() {
    if ((_skillId <= 0) || (_skillLvl <= 0)) {
      return;
    }

    L2PcInstance activeChar = getClient().getActiveChar();

    if (activeChar == null) {
      return;
    }

    int reqSkillLvl = -2;

    if ((_type == 0) || (_type == 1)) {
      reqSkillLvl = _skillLvl - 1; // enchant
    } else if (_type == 2) {
      reqSkillLvl = _skillLvl + 1; // untrain
    } else if (_type == 3) {
      reqSkillLvl = _skillLvl; // change route
    }

    int playerSkillLvl = activeChar.getSkillLevel(_skillId);

    // dont have such skill
    if (playerSkillLvl == -1) {
      return;
    }

    // if reqlvl is 100,200,.. check base skill lvl enchant
    if ((reqSkillLvl % 100) == 0) {
      L2EnchantSkillLearn esl =
          EnchantGroupsData.getInstance().getSkillEnchantmentBySkillId(_skillId);
      if (esl != null) {
        // if player dont have min level to enchant
        if (playerSkillLvl != esl.getBaseLevel()) {
          return;
        }
      }
      // enchant data dont exist?
      else {
        return;
      }
    } else if (playerSkillLvl != reqSkillLvl) {
      // change route is different skill lvl but same enchant
      if ((_type == 3) && ((playerSkillLvl % 100) != (_skillLvl % 100))) {
        return;
      }
    }

    // send skill enchantment detail
    ExEnchantSkillInfoDetail esd =
        new ExEnchantSkillInfoDetail(_type, _skillId, _skillLvl, activeChar);
    activeChar.sendPacket(esd);
  }
Ejemplo n.º 3
0
  @Override
  protected void runImpl() {
    L2PcInstance activeChar = getClient().getActiveChar();

    if (activeChar == null) {
      _log.fine("RequestCrystalizeItem: activeChar was null");
      return;
    }

    if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("crystallize")) {
      activeChar.sendMessage("You are crystallizing too fast.");
      return;
    }

    if (_count <= 0) {
      Util.handleIllegalPlayerAction(
          activeChar,
          "[RequestCrystallizeItem] count <= 0! ban! oid: "
              + _objectId
              + " owner: "
              + activeChar.getName(),
          Config.DEFAULT_PUNISH);
      return;
    }

    if ((activeChar.getPrivateStoreType() != PrivateStoreType.NONE)
        || !activeChar.isInCrystallize()) {
      activeChar.sendPacket(
          SystemMessageId
              .WHILE_OPERATING_A_PRIVATE_STORE_OR_WORKSHOP_YOU_CANNOT_DISCARD_DESTROY_OR_TRADE_AN_ITEM);
      return;
    }

    int skillLevel = activeChar.getSkillLevel(CommonSkill.CRYSTALLIZE.getId());
    if (skillLevel <= 0) {
      activeChar.sendPacket(
          SystemMessageId
              .YOU_MAY_NOT_CRYSTALLIZE_THIS_ITEM_YOUR_CRYSTALLIZATION_SKILL_LEVEL_IS_TOO_LOW);
      activeChar.sendPacket(ActionFailed.STATIC_PACKET);
      if ((activeChar.getRace() != Race.DWARF)
          && (activeChar.getClassId().ordinal() != 117)
          && (activeChar.getClassId().ordinal() != 55)) {
        _log.info(
            "Player "
                + activeChar.getClient()
                + " used crystalize with classid: "
                + activeChar.getClassId().ordinal());
      }
      return;
    }

    PcInventory inventory = activeChar.getInventory();
    if (inventory != null) {
      L2ItemInstance item = inventory.getItemByObjectId(_objectId);
      if (item == null) {
        activeChar.sendPacket(ActionFailed.STATIC_PACKET);
        return;
      }

      if (item.isHeroItem()) {
        return;
      }

      if (_count > item.getCount()) {
        _count = activeChar.getInventory().getItemByObjectId(_objectId).getCount();
      }
    }

    final L2ItemInstance itemToRemove = activeChar.getInventory().getItemByObjectId(_objectId);
    if ((itemToRemove == null) || itemToRemove.isShadowItem() || itemToRemove.isTimeLimitedItem()) {
      return;
    }

    if (!itemToRemove.getItem().isCrystallizable()
        || (itemToRemove.getItem().getCrystalCount() <= 0)
        || (itemToRemove.getItem().getCrystalType() == CrystalType.NONE)) {
      _log.warning(
          activeChar.getName()
              + " ("
              + activeChar.getObjectId()
              + ") tried to crystallize "
              + itemToRemove.getItem().getId());
      return;
    }

    if (!activeChar.getInventory().canManipulateWithItemId(itemToRemove.getId())) {
      activeChar.sendMessage("You cannot use this item.");
      return;
    }

    // Check if the char can crystallize items and return if false;
    boolean canCrystallize = true;

    switch (itemToRemove.getItem().getCrystalTypePlus()) {
      case D:
        {
          if (skillLevel < 1) {
            canCrystallize = false;
          }
          break;
        }
      case C:
        {
          if (skillLevel < 2) {
            canCrystallize = false;
          }
          break;
        }
      case B:
        {
          if (skillLevel < 3) {
            canCrystallize = false;
          }
          break;
        }
      case A:
        {
          if (skillLevel < 4) {
            canCrystallize = false;
          }
          break;
        }
      case S:
        {
          if (skillLevel < 5) {
            canCrystallize = false;
          }
          break;
        }
      case R:
        {
          if (skillLevel < 6) {
            canCrystallize = false;
          }
          break;
        }
    }

    if (!canCrystallize) {
      activeChar.sendPacket(
          SystemMessageId
              .YOU_MAY_NOT_CRYSTALLIZE_THIS_ITEM_YOUR_CRYSTALLIZATION_SKILL_LEVEL_IS_TOO_LOW);
      activeChar.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    // activeChar.setInCrystallize(true);

    // unequip if needed
    SystemMessage sm;
    if (itemToRemove.isEquipped()) {
      L2ItemInstance[] unequiped =
          activeChar.getInventory().unEquipItemInSlotAndRecord(itemToRemove.getLocationSlot());
      InventoryUpdate iu = new InventoryUpdate();
      for (L2ItemInstance item : unequiped) {
        iu.addModifiedItem(item);
      }
      activeChar.sendPacket(iu);

      if (itemToRemove.getEnchantLevel() > 0) {
        sm = SystemMessage.getSystemMessage(SystemMessageId.THE_EQUIPMENT_S1_S2_HAS_BEEN_REMOVED);
        sm.addInt(itemToRemove.getEnchantLevel());
        sm.addItemName(itemToRemove);
      } else {
        sm = SystemMessage.getSystemMessage(SystemMessageId.S1_HAS_BEEN_UNEQUIPPED);
        sm.addItemName(itemToRemove);
      }
      activeChar.sendPacket(sm);
    }

    // remove from inventory
    final L2ItemInstance removedItem =
        activeChar.getInventory().destroyItem("Crystalize", _objectId, _count, activeChar, null);

    final InventoryUpdate iu = new InventoryUpdate();
    iu.addRemovedItem(removedItem);
    activeChar.sendPacket(iu);

    final int crystalId = itemToRemove.getItem().getCrystalItemId();
    final int crystalAmount = itemToRemove.getCrystalCount();

    final List<ItemChanceHolder> items = new ArrayList<>();
    items.add(new ItemChanceHolder(crystalId, 100, crystalAmount));

    final CrystalizationData data =
        ItemCrystalizationData.getInstance().getCrystalization(itemToRemove.getId());
    if (data != null) {
      data.getItems().stream().filter(holder -> (holder.getId() != crystalId)).forEach(items::add);
    }

    for (ItemChanceHolder holder : items) {
      final double rand = Rnd.nextDouble() * 100;
      if (rand < holder.getChance()) {
        // add crystals
        final L2ItemInstance createdItem =
            activeChar
                .getInventory()
                .addItem("Crystalize", holder.getId(), holder.getCount(), activeChar, activeChar);

        sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_EARNED_S2_S1_S);
        sm.addItemName(createdItem);
        sm.addLong(holder.getCount());
        activeChar.sendPacket(sm);
      }
    }

    sm = SystemMessage.getSystemMessage(SystemMessageId.S1_HAS_BEEN_CRYSTALLIZED);
    sm.addItemName(removedItem);
    activeChar.sendPacket(sm);

    activeChar.broadcastUserInfo();

    L2World.getInstance().removeObject(removedItem);

    activeChar.setInCrystallize(false);
  }