/** * 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); } }
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; } }