Ejemplo n.º 1
0
  /**
   * Adds item count to player inventory I moved this method to service cause right implementation
   * of it is critical to server operation and could cause starvation of object ids.
   *
   * <p>This packet will send necessary packets to client (initialize used only from quest engine
   *
   * @param player
   * @param itemId
   * @param count - amount of item that were not added to player's inventory
   */
  public int addItem(Player player, int itemId, int count, boolean isQuestItem) {
    Storage inventory = player.getInventory();

    ItemTemplate itemTemplate = DataManager.ITEM_DATA.getItemTemplate(itemId);
    if (itemTemplate == null) return count;

    int maxStackCount = itemTemplate.getMaxStackCount();

    if (itemId == ItemId.KINAH.value()) {
      inventory.increaseKinah(count);
      return 0;
    } else {
      /** Increase count of existing items */
      List<Item> existingItems =
          inventory.getAllItemsByItemId(
              itemId); // look for existing in equipment. need for power shards.
      for (Item existingItem : existingItems) {
        if (count == 0) break;

        int freeCount = maxStackCount - existingItem.getItemCount();
        if (count <= freeCount) {
          existingItem.increaseItemCount(count);
          count = 0;
        } else {
          existingItem.increaseItemCount(freeCount);
          count -= freeCount;
        }

        updateItem(player, existingItem, false);
      }

      /** Create new stacks */
      while (!inventory.isFull() && count > 0) {
        // item count still more than maxStack value
        if (count > maxStackCount) {
          Item item = newItem(itemId, maxStackCount);
          item.setQuest(isQuestItem);
          count -= maxStackCount;
          inventory.putToBag(item);
          updateItem(player, item, true);
        } else {
          Item item = newItem(itemId, count);
          item.setQuest(isQuestItem);
          inventory.putToBag(item);
          updateItem(player, item, true);
          count = 0;
        }
      }

      return count;
    }
  }
Ejemplo n.º 2
0
  public void moveKinah(Player player, Storage source, int splitAmount) {
    if (source.getKinahItem().getItemCount() < splitAmount) return;

    switch (source.getStorageType()) {
      case 0:
        {
          Storage destination = player.getStorage(StorageType.ACCOUNT_WAREHOUSE.getId());
          int chksum =
              (source.getKinahItem().getItemCount() - splitAmount)
                  + (destination.getKinahItem().getItemCount() + splitAmount);

          if (chksum
              != source.getKinahItem().getItemCount() + destination.getKinahItem().getItemCount())
            return;

          source.decreaseKinah(splitAmount);
          destination.increaseKinah(splitAmount);
          break;
        }

      case 2:
        {
          Storage destination = player.getStorage(StorageType.CUBE.getId());
          int chksum =
              (source.getKinahItem().getItemCount() - splitAmount)
                  + (destination.getKinahItem().getItemCount() + splitAmount);

          if (chksum
              != source.getKinahItem().getItemCount() + destination.getKinahItem().getItemCount())
            return;

          source.decreaseKinah(splitAmount);
          destination.increaseKinah(splitAmount);
          break;
        }
      default:
        break;
    }
  }