/**
   * Actions:
   *
   * <ul>
   *   <li>Check if the killing object is a player, and then find the party they belong to.
   *   <li>Add a blood offering item to the leader of the party.
   *   <li>Update the party leader's inventory to show the new item addition.
   * </ul>
   */
  @Override
  public void doItemDrop(L2Character lastAttacker) {
    L2PcInstance killingChar = null;

    if (!(lastAttacker instanceof L2PcInstance)) {
      return;
    }

    killingChar = (L2PcInstance) lastAttacker;
    L2Party associatedParty = killingChar.getParty();

    if (associatedParty == null) {
      return;
    }

    L2PcInstance partyLeader = associatedParty.getLeader();
    L2ItemInstance addedOfferings =
        partyLeader
            .getInventory()
            .addItem(
                "Sign",
                SevenSignsFestival.FESTIVAL_OFFERING_ID,
                _bonusMultiplier,
                partyLeader,
                this);

    InventoryUpdate iu = new InventoryUpdate();

    if (addedOfferings.getCount() != _bonusMultiplier) {
      iu.addModifiedItem(addedOfferings);
    } else {
      iu.addNewItem(addedOfferings);
    }

    partyLeader.sendPacket(iu);

    super.doItemDrop(lastAttacker); // Normal drop
  }
  private void setEnchant(L2PcInstance activeChar, int ench, int armorType) {
    // get the target
    L2Object target = activeChar.getTarget();
    if (target == null) {
      target = activeChar;
    }
    L2PcInstance player = null;
    if (target instanceof L2PcInstance) {
      player = (L2PcInstance) target;
    } else {
      activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
      return;
    }

    // now we need to find the equipped weapon of the targeted character...
    int curEnchant = 0; // display purposes only
    L2ItemInstance itemInstance = null;

    // only attempt to enchant if there is a weapon equipped
    L2ItemInstance parmorInstance = player.getInventory().getPaperdollItem(armorType);
    if ((parmorInstance != null) && (parmorInstance.getLocationSlot() == armorType)) {
      itemInstance = parmorInstance;
    }

    if (itemInstance != null) {
      curEnchant = itemInstance.getEnchantLevel();

      // set enchant value
      player.getInventory().unEquipItemInSlot(armorType);
      itemInstance.setEnchantLevel(ench);
      player.getInventory().equipItem(itemInstance);

      // send packets
      InventoryUpdate iu = new InventoryUpdate();
      iu.addModifiedItem(itemInstance);
      player.sendPacket(iu);
      player.broadcastPacket(new CharInfo(player));
      player.sendPacket(new UserInfo(player));
      player.broadcastPacket(new ExBrExtraUserInfo(player));

      // informations
      activeChar.sendMessage(
          "Changed enchantment of "
              + player.getName()
              + "'s "
              + itemInstance.getItem().getName()
              + " from "
              + curEnchant
              + " to "
              + ench
              + ".");
      player.sendMessage(
          "Admin has changed the enchantment of your "
              + itemInstance.getItem().getName()
              + " from "
              + curEnchant
              + " to "
              + ench
              + ".");
    }
  }
예제 #3
0
  public synchronized void computeNewHeroes(List<StatsSet> newHeroes) {
    updateHeroes(true);

    for (Integer objectId : _heroes.keySet()) {
      final L2PcInstance player = L2World.getInstance().getPlayer(objectId);
      if (player == null) {
        continue;
      }

      player.setHero(false);

      for (int i = 0; i < Inventory.PAPERDOLL_TOTALSLOTS; i++) {
        L2ItemInstance equippedItem = player.getInventory().getPaperdollItem(i);
        if ((equippedItem != null) && equippedItem.isHeroItem()) {
          player.getInventory().unEquipItemInSlot(i);
        }
      }

      final InventoryUpdate iu = new InventoryUpdate();
      for (L2ItemInstance item : player.getInventory().getAvailableItems(false, false, false)) {
        if ((item != null) && item.isHeroItem()) {
          player.destroyItem("Hero", item, null, true);
          iu.addRemovedItem(item);
        }
      }

      if (!iu.getItems().isEmpty()) {
        player.sendPacket(iu);
      }

      player.broadcastUserInfo();
    }

    if (newHeroes.isEmpty()) {
      _heroes.clear();
      return;
    }

    Map<Integer, StatsSet> heroes = new FastMap<>();

    for (StatsSet hero : newHeroes) {
      int charId = hero.getInt(Olympiad.CHAR_ID);

      if ((_completeHeroes != null) && _completeHeroes.containsKey(charId)) {
        StatsSet oldHero = _completeHeroes.get(charId);
        int count = oldHero.getInt(COUNT);
        oldHero.set(COUNT, count + 1);
        oldHero.set(PLAYED, 1);
        oldHero.set(CLAIMED, false);
        heroes.put(charId, oldHero);
      } else {
        StatsSet newHero = new StatsSet();
        newHero.set(Olympiad.CHAR_NAME, hero.getString(Olympiad.CHAR_NAME));
        newHero.set(Olympiad.CLASS_ID, hero.getInt(Olympiad.CLASS_ID));
        newHero.set(COUNT, 1);
        newHero.set(PLAYED, 1);
        newHero.set(CLAIMED, false);
        heroes.put(charId, newHero);
      }
    }

    deleteItemsInDb();

    _heroes.clear();
    _heroes.putAll(heroes);

    heroes.clear();

    updateHeroes(false);
  }
  @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);
  }