use of client.inventory.Item in project HeavenMS by ronancpl.
the class MapleStorageInventory method sortItems.
public List<Item> sortItems() {
ArrayList<Item> itemarray = new ArrayList<>();
for (short i = 1; i <= this.getSlotLimit(); i++) {
Item item = this.getItem(i);
if (item != null) {
itemarray.add((Item) item.copy());
}
}
for (Item item : itemarray) {
this.removeSlot(item.getPosition());
}
int invTypeCriteria = 1;
int sortCriteria = (ServerConstants.USE_ITEM_SORT_BY_NAME == true) ? 2 : 0;
PairedQuicksort pq = new PairedQuicksort(itemarray, sortCriteria, invTypeCriteria);
inventory.clear();
return itemarray;
}
use of client.inventory.Item in project HeavenMS by ronancpl.
the class MapleStorageInventory method PartitionByItemId.
private void PartitionByItemId(int Esq, int Dir, ArrayList<Item> A) {
Item x, w;
i = Esq;
j = Dir;
x = A.get((i + j) / 2);
do {
while (x.getItemId() > A.get(i).getItemId()) i++;
while (x.getItemId() < A.get(j).getItemId()) j--;
if (i <= j) {
w = A.get(i);
A.set(i, A.get(j));
A.set(j, w);
i++;
j--;
}
} while (i <= j);
}
use of client.inventory.Item in project HeavenMS by ronancpl.
the class MapleStorageInventory method move.
private void move(short sSlot, short dSlot, short slotMax) {
Item source = (Item) inventory.get(sSlot);
Item target = (Item) inventory.get(dSlot);
if (source == null) {
return;
}
if (target == null) {
source.setPosition(dSlot);
inventory.put(dSlot, source);
inventory.remove(sSlot);
} else if (target.getItemId() == source.getItemId() && !ItemConstants.isRechargable(source.getItemId()) && !MapleItemInformationProvider.getInstance().isPickupRestricted(source.getItemId()) && isSameOwner(source, target)) {
if (isEquipOrCash(source)) {
swap(target, source);
} else if (source.getQuantity() + target.getQuantity() > slotMax) {
short rest = (short) ((source.getQuantity() + target.getQuantity()) - slotMax);
source.setQuantity(rest);
target.setQuantity(slotMax);
} else {
target.setQuantity((short) (source.getQuantity() + target.getQuantity()));
inventory.remove(sSlot);
}
} else {
swap(target, source);
}
}
use of client.inventory.Item in project HeavenMS by ronancpl.
the class MapleStorageInventory method mergeItems.
public void mergeItems() {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
Item srcItem, dstItem;
for (short dst = 1; dst <= this.getSlotLimit(); dst++) {
dstItem = this.getItem(dst);
if (dstItem == null)
continue;
for (short src = (short) (dst + 1); src <= this.getSlotLimit(); src++) {
srcItem = this.getItem(src);
if (srcItem == null)
continue;
if (dstItem.getItemId() != srcItem.getItemId())
continue;
if (dstItem.getQuantity() == ii.getSlotMax(c, this.getItem(dst).getItemId()))
break;
moveItem(src, dst);
}
}
boolean sorted = false;
while (!sorted) {
short freeSlot = this.getNextFreeSlot();
if (freeSlot != -1) {
short itemSlot = -1;
for (short i = (short) (freeSlot + 1); i <= this.getSlotLimit(); i = (short) (i + 1)) {
if (this.getItem(i) != null) {
itemSlot = i;
break;
}
}
if (itemSlot > 0) {
moveItem(itemSlot, freeSlot);
} else {
sorted = true;
}
} else {
sorted = true;
}
}
}
use of client.inventory.Item in project HeavenMS by ronancpl.
the class UseSolomonHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
slea.readInt();
short slot = slea.readShort();
int itemId = slea.readInt();
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
Item slotItem = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
int gachaexp = ii.getExpById(itemId);
if (c.getPlayer().getInventory(MapleInventoryType.USE).countById(itemId) <= 0 || slotItem.getItemId() != itemId || c.getPlayer().getLevel() > ii.getMaxLevelById(itemId)) {
return;
}
if ((c.getPlayer().getGachaExp() + gachaexp) > Integer.MAX_VALUE) {
return;
}
c.getPlayer().gainGachaExp(gachaexp);
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short) 1, false);
c.announce(MaplePacketCreator.enableActions());
}
Aggregations