use of client.inventory.ModifyInventory in project HeavenMS by ronancpl.
the class MapleCharacter method forceUpdateItem.
public void forceUpdateItem(Item item) {
final List<ModifyInventory> mods = new LinkedList<>();
mods.add(new ModifyInventory(3, item));
mods.add(new ModifyInventory(0, item));
client.announce(MaplePacketCreator.modifyInventory(true, mods));
}
use of client.inventory.ModifyInventory in project HeavenMS by ronancpl.
the class InventorySortHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
chr.getAutobanManager().setTimestamp(3, slea.readInt(), 3);
byte inventoryType = slea.readByte();
if (!ServerConstants.USE_ITEM_SORT) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (inventoryType < 1 || inventoryType > 5) {
c.disconnect(false, false);
return;
}
MapleInventory inventory = chr.getInventory(MapleInventoryType.getByType(inventoryType));
ArrayList<Item> itemarray = new ArrayList<>();
List<ModifyInventory> mods = new ArrayList<>();
for (short i = 1; i <= inventory.getSlotLimit(); i++) {
Item item = inventory.getItem(i);
if (item != null) {
itemarray.add((Item) item.copy());
}
}
for (Item item : itemarray) {
inventory.removeSlot(item.getPosition());
mods.add(new ModifyInventory(3, item));
}
int invTypeCriteria = (MapleInventoryType.getByType(inventoryType) == MapleInventoryType.EQUIP) ? 3 : 1;
int sortCriteria = (ServerConstants.USE_ITEM_SORT_BY_NAME == true) ? 2 : 0;
PairedQuicksort pq = new PairedQuicksort(itemarray, sortCriteria, invTypeCriteria);
for (Item item : itemarray) {
inventory.addItem(item);
// to prevent crashes
mods.add(new ModifyInventory(0, item.copy()));
}
itemarray.clear();
c.announce(MaplePacketCreator.modifyInventory(true, mods));
c.announce(MaplePacketCreator.finishedSort2(inventoryType));
c.announce(MaplePacketCreator.enableActions());
}
use of client.inventory.ModifyInventory in project HeavenMS by ronancpl.
the class MapleInventoryManipulator method equip.
public static void equip(MapleClient c, short src, short dst) {
Equip source = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(src);
if (source == null || !MapleItemInformationProvider.getInstance().canWearEquipment(c.getPlayer(), source, dst)) {
c.announce(MaplePacketCreator.enableActions());
return;
} else if ((((source.getItemId() >= 1902000 && source.getItemId() <= 1902002) || source.getItemId() == 1912000) && c.getPlayer().isCygnus()) || ((source.getItemId() >= 1902005 && source.getItemId() <= 1902007) || source.getItemId() == 1912005) && !c.getPlayer().isCygnus()) {
// Adventurer taming equipment
return;
}
boolean itemChanged = false;
if (MapleItemInformationProvider.getInstance().isUntradeableOnEquip(source.getItemId())) {
source.setFlag((byte) ItemConstants.UNTRADEABLE);
itemChanged = true;
}
if (source.getRingId() > -1) {
c.getPlayer().getRingById(source.getRingId()).equip();
}
if (dst == -6) {
// unequip the overall
Item top = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -5);
if (top != null && ItemConstants.isOverall(top.getItemId())) {
if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
c.announce(MaplePacketCreator.getInventoryFull());
c.announce(MaplePacketCreator.getShowInventoryFull());
return;
}
unequip(c, (byte) -5, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
}
} else if (dst == -5) {
final Item bottom = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -6);
if (bottom != null && ItemConstants.isOverall(source.getItemId())) {
if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
c.announce(MaplePacketCreator.getInventoryFull());
c.announce(MaplePacketCreator.getShowInventoryFull());
return;
}
unequip(c, (byte) -6, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
}
} else if (dst == -10) {
// check if weapon is two-handed
Item weapon = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -11);
if (weapon != null && MapleItemInformationProvider.getInstance().isTwoHanded(weapon.getItemId())) {
if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
c.announce(MaplePacketCreator.getInventoryFull());
c.announce(MaplePacketCreator.getShowInventoryFull());
return;
}
unequip(c, (byte) -11, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
}
} else if (dst == -11) {
Item shield = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -10);
if (shield != null && MapleItemInformationProvider.getInstance().isTwoHanded(source.getItemId())) {
if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
c.announce(MaplePacketCreator.getInventoryFull());
c.announce(MaplePacketCreator.getShowInventoryFull());
return;
}
unequip(c, (byte) -10, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
}
}
if (dst == -18) {
if (c.getPlayer().getMount() != null) {
c.getPlayer().getMount().setItemId(source.getItemId());
}
}
if (source.getItemId() == 1122017) {
c.getPlayer().equipPendantOfSpirit();
}
// 1112413, 1112414, 1112405 (Lilin's Ring)
source = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(src);
Equip target = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(dst);
c.getPlayer().getInventory(MapleInventoryType.EQUIP).removeSlot(src);
if (target != null) {
c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).removeSlot(dst);
}
final List<ModifyInventory> mods = new ArrayList<>();
if (itemChanged) {
mods.add(new ModifyInventory(3, source));
// to prevent crashes
mods.add(new ModifyInventory(0, source.copy()));
}
source.setPosition(dst);
c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).addFromDB(source);
if (target != null) {
target.setPosition(src);
c.getPlayer().getInventory(MapleInventoryType.EQUIP).addFromDB(target);
}
if (c.getPlayer().getBuffedValue(MapleBuffStat.BOOSTER) != null && ItemConstants.isWeapon(source.getItemId())) {
c.getPlayer().cancelBuffStats(MapleBuffStat.BOOSTER);
}
mods.add(new ModifyInventory(2, source, src));
c.announce(MaplePacketCreator.modifyInventory(true, mods));
c.getPlayer().equipChanged();
}
use of client.inventory.ModifyInventory in project HeavenMS by ronancpl.
the class MapleInventoryManipulator method addFromDrop.
public static boolean addFromDrop(MapleClient c, Item item, boolean show, int petId) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
MapleInventoryType type = item.getInventoryType();
if (ii.isPickupRestricted(item.getItemId()) && c.getPlayer().haveItemWithId(item.getItemId(), true)) {
c.announce(MaplePacketCreator.getInventoryFull());
c.announce(MaplePacketCreator.showItemUnavailable());
return false;
}
short quantity = item.getQuantity();
if (!type.equals(MapleInventoryType.EQUIP)) {
short slotMax = ii.getSlotMax(c, item.getItemId());
List<Item> existing = c.getPlayer().getInventory(type).listById(item.getItemId());
if (!ItemConstants.isRechargable(item.getItemId()) && petId == -1) {
if (existing.size() > 0) {
// first update all existing slots to slotMax
Iterator<Item> i = existing.iterator();
while (quantity > 0) {
if (i.hasNext()) {
Item eItem = (Item) i.next();
short oldQ = eItem.getQuantity();
if (oldQ < slotMax && item.getOwner().equals(eItem.getOwner())) {
short newQ = (short) Math.min(oldQ + quantity, slotMax);
quantity -= (newQ - oldQ);
eItem.setQuantity(newQ);
c.announce(MaplePacketCreator.modifyInventory(true, Collections.singletonList(new ModifyInventory(1, eItem))));
}
} else {
break;
}
}
}
while (quantity > 0) {
short newQ = (short) Math.min(quantity, slotMax);
quantity -= newQ;
Item nItem = new Item(item.getItemId(), (short) 0, newQ, petId);
nItem.setExpiration(item.getExpiration());
nItem.setOwner(item.getOwner());
nItem.setFlag(item.getFlag());
short newSlot = c.getPlayer().getInventory(type).addItem(nItem);
if (newSlot == -1) {
c.announce(MaplePacketCreator.getInventoryFull());
c.announce(MaplePacketCreator.getShowInventoryFull());
item.setQuantity((short) (quantity + newQ));
return false;
}
c.announce(MaplePacketCreator.modifyInventory(true, Collections.singletonList(new ModifyInventory(0, nItem))));
}
} else {
Item nItem = new Item(item.getItemId(), (short) 0, quantity, petId);
nItem.setExpiration(item.getExpiration());
short newSlot = c.getPlayer().getInventory(type).addItem(nItem);
if (newSlot == -1) {
c.announce(MaplePacketCreator.getInventoryFull());
c.announce(MaplePacketCreator.getShowInventoryFull());
return false;
}
c.announce(MaplePacketCreator.modifyInventory(true, Collections.singletonList(new ModifyInventory(0, nItem))));
c.announce(MaplePacketCreator.enableActions());
}
} else if (quantity == 1) {
short newSlot = c.getPlayer().getInventory(type).addItem(item);
if (newSlot == -1) {
c.announce(MaplePacketCreator.getInventoryFull());
c.announce(MaplePacketCreator.getShowInventoryFull());
return false;
}
c.announce(MaplePacketCreator.modifyInventory(true, Collections.singletonList(new ModifyInventory(0, item))));
} else {
FilePrinter.printError(FilePrinter.ITEM, "Tried to pickup Equip id " + item.getItemId() + " containing more than 1 quantity --> " + quantity);
c.announce(MaplePacketCreator.getInventoryFull());
c.announce(MaplePacketCreator.showItemUnavailable());
return false;
}
if (show) {
c.announce(MaplePacketCreator.getShowItemGain(item.getItemId(), item.getQuantity()));
}
return true;
}
use of client.inventory.ModifyInventory in project HeavenMS by ronancpl.
the class MapleInventoryManipulator method removeFromSlot.
public static void removeFromSlot(MapleClient c, MapleInventoryType type, short slot, short quantity, boolean fromDrop, boolean consume) {
Item item = c.getPlayer().getInventory(type).getItem(slot);
boolean allowZero = consume && ItemConstants.isRechargable(item.getItemId());
c.getPlayer().getInventory(type).removeItem(slot, quantity, allowZero);
if (item.getQuantity() == 0 && !allowZero) {
c.announce(MaplePacketCreator.modifyInventory(fromDrop, Collections.singletonList(new ModifyInventory(3, item))));
} else {
c.announce(MaplePacketCreator.modifyInventory(fromDrop, Collections.singletonList(new ModifyInventory(1, item))));
}
}
Aggregations