Exemplo n.º 1
0
  /**
   * Used to split item into 2 items
   *
   * @param player
   * @param itemObjId
   * @param splitAmount
   * @param slotNum
   * @param sourceStorageType
   * @param desetinationStorageType
   */
  public void splitItem(
      Player player,
      int itemObjId,
      int splitAmount,
      int slotNum,
      int sourceStorageType,
      int destinationStorageType) {
    Storage sourceStorage = player.getStorage(sourceStorageType);
    Storage destinationStorage = player.getStorage(destinationStorageType);

    Item itemToSplit = sourceStorage.getItemByObjId(itemObjId);
    if (itemToSplit == null) {
      itemToSplit = sourceStorage.getKinahItem();
      if (itemToSplit.getObjectId() != itemObjId || itemToSplit == null) {
        log.warn(
            String.format(
                "CHECKPOINT: attempt to split null item %d %d %d",
                itemObjId, splitAmount, slotNum));
        return;
      }
    }

    // To move kinah from inventory to warehouse and vise versa client using split item packet
    if (itemToSplit.getItemTemplate().isKinah()) {
      moveKinah(player, sourceStorage, splitAmount);
      return;
    }

    int oldItemCount = itemToSplit.getItemCount() - splitAmount;

    if (itemToSplit.getItemCount() < splitAmount || oldItemCount == 0) return;

    Item newItem = newItem(itemToSplit.getItemTemplate().getTemplateId(), splitAmount);
    newItem.setEquipmentSlot(slotNum);
    if (destinationStorage.putToBag(newItem) != null) {
      itemToSplit.decreaseItemCount(splitAmount);

      List<Item> itemsToUpdate = new ArrayList<Item>();
      itemsToUpdate.add(newItem);

      sendStorageUpdatePacket(player, destinationStorageType, itemsToUpdate.get(0));

      sendUpdateItemPacket(player, sourceStorageType, itemToSplit);
    } else {
      releaseItemId(newItem);
    }
  }
Exemplo n.º 2
0
  /**
   * Used to merge 2 items in inventory
   *
   * @param player
   * @param sourceItemObjId
   * @param itemAmount
   * @param destinationObjId
   */
  public void mergeItems(
      Player player,
      int sourceItemObjId,
      int itemAmount,
      int destinationObjId,
      int sourceStorageType,
      int destinationStorageType) {
    if (itemAmount == 0) return;

    Storage sourceStorage = player.getStorage(sourceStorageType);
    Storage destinationStorage = player.getStorage(destinationStorageType);

    Item sourceItem = sourceStorage.getItemByObjId(sourceItemObjId);
    Item destinationItem = destinationStorage.getItemByObjId(destinationObjId);

    if (sourceItem == null || destinationItem == null) return; // Invalid object id provided

    if (sourceItem.getItemTemplate().getTemplateId()
        != destinationItem.getItemTemplate().getTemplateId()) return; // Invalid item type

    if (sourceItem.getItemCount() < itemAmount) return; // Invalid item amount

    if (sourceItem.getItemCount() == itemAmount) {
      destinationItem.increaseItemCount(itemAmount);
      sourceStorage.removeFromBag(sourceItem, true);

      sendDeleteItemPacket(player, sourceStorageType, sourceItem.getObjectId());

      sendUpdateItemPacket(player, destinationStorageType, destinationItem);

    } else if (sourceItem.getItemCount() > itemAmount) {
      sourceItem.decreaseItemCount(itemAmount);
      destinationItem.increaseItemCount(itemAmount);

      sendUpdateItemPacket(player, sourceStorageType, sourceItem);

      sendUpdateItemPacket(player, destinationStorageType, destinationItem);
    } else return; // cant happen in theory, but...
  }