コード例 #1
0
ファイル: ItemService.java プロジェクト: shanecode/aion-dev
  public void moveItem(
      Player player, int itemObjId, int sourceStorageType, int destinationStorageType, int slot) {
    Storage sourceStorage = player.getStorage(sourceStorageType);
    Item item = player.getStorage(sourceStorageType).getItemByObjId(itemObjId);

    if (item == null) return;

    item.setEquipmentSlot(slot);

    if (sourceStorageType == destinationStorageType) return;

    Storage destinationStorage = player.getStorage(destinationStorageType);
    List<Item> existingItems =
        destinationStorage.getItemsByItemId(item.getItemTemplate().getTemplateId());

    int count = item.getItemCount();
    int maxStackCount = item.getItemTemplate().getMaxStackCount();

    for (Item existingItem : existingItems) {
      if (count == 0) break;

      int freeCount = maxStackCount - existingItem.getItemCount();
      if (count <= freeCount) {
        existingItem.increaseItemCount(count);
        count = 0;
        sendDeleteItemPacket(player, sourceStorageType, item.getObjectId());
        sourceStorage.removeFromBag(item, true);

      } else {
        existingItem.increaseItemCount(freeCount);
        count -= freeCount;
      }
      sendStorageUpdatePacket(player, destinationStorageType, existingItem);
    }

    while (!destinationStorage.isFull() && count > 0) {
      // item count still more than maxStack value
      if (count > maxStackCount) {
        count -= maxStackCount;
        Item newitem = newItem(item.getItemTemplate().getTemplateId(), maxStackCount);
        newitem = destinationStorage.putToBag(newitem);
        sendStorageUpdatePacket(player, destinationStorageType, newitem);

      } else {
        item.setItemCount(count);
        sourceStorage.removeFromBag(item, false);
        sendDeleteItemPacket(player, sourceStorageType, item.getObjectId());
        Item newitem = destinationStorage.putToBag(item);
        sendStorageUpdatePacket(player, destinationStorageType, newitem);

        count = 0;
      }
    }

    if (count > 0) // if storage is full and some items left
    {
      item.setItemCount(count);
      sendUpdateItemPacket(player, sourceStorageType, item);
    }
  }
コード例 #2
0
ファイル: ItemService.java プロジェクト: shanecode/aion-dev
  public void switchStoragesItems(
      Player player,
      int sourceStorageType,
      int sourceItemObjId,
      int replaceStorageType,
      int replaceItemObjId) {
    Storage sourceStorage = player.getStorage(sourceStorageType);
    Storage replaceStorage = player.getStorage(replaceStorageType);

    Item sourceItem = sourceStorage.getItemByObjId(sourceItemObjId);
    if (sourceItem == null) return;

    Item replaceItem = replaceStorage.getItemByObjId(replaceItemObjId);
    if (replaceItem == null) return;

    int sourceSlot = sourceItem.getEquipmentSlot();
    int replaceSlot = replaceItem.getEquipmentSlot();

    sourceItem.setEquipmentSlot(replaceSlot);
    replaceItem.setEquipmentSlot(sourceSlot);

    sourceStorage.removeFromBag(sourceItem, false);
    replaceStorage.removeFromBag(replaceItem, false);

    Item newSourceItem = sourceStorage.putToBag(replaceItem);
    Item newReplaceItem = replaceStorage.putToBag(sourceItem);

    sendDeleteItemPacket(player, sourceStorageType, sourceItemObjId);
    sendStorageUpdatePacket(player, sourceStorageType, newSourceItem);

    sendDeleteItemPacket(player, replaceStorageType, replaceItemObjId);
    sendStorageUpdatePacket(player, replaceStorageType, newReplaceItem);
  }
コード例 #3
0
ファイル: ItemService.java プロジェクト: shanecode/aion-dev
  /**
   * 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);
    }
  }
コード例 #4
0
ファイル: ItemService.java プロジェクト: shanecode/aion-dev
  /**
   * 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...
  }
コード例 #5
0
ファイル: ItemService.java プロジェクト: shanecode/aion-dev
  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;
    }
  }
コード例 #6
0
ファイル: ItemService.java プロジェクト: shanecode/aion-dev
  /**
   * Loads item stones from DB for each item in a list if item is ARMOR or WEAPON
   *
   * @param itemList
   */
  public void loadItemStones(Player player) {
    List<Item> itemList = new ArrayList<Item>();
    itemList.addAll(player.getStorage(StorageType.CUBE.getId()).getStorageItems());
    itemList.addAll(player.getStorage(StorageType.REGULAR_WAREHOUSE.getId()).getStorageItems());
    itemList.addAll(player.getStorage(StorageType.ACCOUNT_WAREHOUSE.getId()).getStorageItems());
    itemList.addAll(player.getEquipment().getEquippedItems());

    for (Item item : itemList) {
      if (item.getItemTemplate().isArmor() || item.getItemTemplate().isWeapon()) {
        item.setItemStones(DAOManager.getDAO(ItemStoneListDAO.class).load(item.getObjectId()));

        // if item equipped - apply stats of item stone
        if (item.isEquipped()
            && item.getEquipmentSlot() != ItemSlot.MAIN_OFF_HAND.getSlotIdMask()
            && item.getEquipmentSlot() != ItemSlot.SUB_OFF_HAND.getSlotIdMask()) {
          for (ItemStone itemStone : item.getItemStones()) {
            ItemEquipmentListener.addStoneStats(itemStone, player.getGameStats());
          }
        }
      }
    }
  }