public static void equip(final MapleClient c, final short src, short dst) { Equip source = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(src); Equip target = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(dst); if (dst == -12 && target != null) { if (c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -13) == null) { dst = (short) -13; target = null; } for (int i = 0; i < 2; i++) { if (c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) (i - 16)) == null) { dst = (short) (i - 16); target = null; } } if (target != null) { return; } } if (isPE(source.getId(), dst) || source == null || (MapleItemInformationProvider.getInstance().getReqLevel(source.getId()) > c.getPlayer().getLevel() && c.getPlayer().gmLevel() < 1) || (((source.getId() >= 1902000 && source.getId() <= 1902002) || source.getId() == 1912000) && c.getPlayer().getJobType() != 0) || (((source.getId() >= 1902005 && source.getId() <= 1902007) || source.getId() == 1912005) && c.getPlayer().getJobType() != 1) || (((source.getId() >= 1902015 && source.getId() <= 1902018) || source.getId() == 1912011) && !c.getPlayer().isAran())) { return; } if (MapleItemInformationProvider.getInstance().isUntradeableOnEquip(source.getId())) { source.setFlag((byte) InventoryConstants.UNTRADEABLE); c.announce(InventoryFactory.updateSlot(source)); } if (dst == -6) { // unequip the overall final IItem top = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -5); if (top != null && isOverall(top.getId())) { if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) { c.announce(InventoryFactory.getInventoryFull()); c.announce(InventoryFactory.getShowInventoryFull()); return; } unequip( c, (short) -5, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot()); } } else if (dst == -5) { // equip overall final IItem bottom = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -6); if (bottom != null && isOverall(source.getId())) { if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) { c.announce(InventoryFactory.getInventoryFull()); c.announce(InventoryFactory.getShowInventoryFull()); return; } unequip( c, (short) -6, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot()); } } else if (dst == -10) { // check if weapon is two-handed final IItem weapon = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -11); if (weapon != null && MapleItemInformationProvider.getInstance().isTwoHanded(weapon.getId())) { if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) { c.announce(InventoryFactory.getInventoryFull()); c.announce(InventoryFactory.getShowInventoryFull()); return; } unequip( c, (short) -11, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot()); } } else if (dst == -11) { // unequip shield final IItem shield = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -10); if (shield != null && MapleItemInformationProvider.getInstance().isTwoHanded(source.getId())) { if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) { c.announce(InventoryFactory.getInventoryFull()); c.announce(InventoryFactory.getShowInventoryFull()); return; } unequip( c, (short) -10, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot()); } } if (dst == -18) { if (c.getPlayer().getMount() != null) { c.getPlayer().getMount().setId(source.getId()); } } c.getPlayer().getInventory(MapleInventoryType.EQUIP).removeSlot(src); if (target != null) { c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).removeSlot(dst); } 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 && isWeapon(source.getId())) { c.getPlayer().cancelBuffStats(MapleBuffStat.BOOSTER); } c.announce(InventoryFactory.moveInventoryItem(MapleInventoryType.EQUIP, src, dst, (byte) 2)); c.getPlayer().equipChanged(); if (source.getId() >= 1112001 && source.getId() <= 1112006) { c.getPlayer().setMarriageRing(MapleRing.loadFromDB(c.getPlayer())); c.announce(IntraPersonalFactory.getCharInfo(c.getPlayer())); c.getPlayer().getMap().removePlayer(c.getPlayer()); c.getPlayer().getMap().addPlayer(c.getPlayer()); } }
public static boolean addById(MapleClient c, int Id, short quantity, String owner, int petid) { final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance(); final MapleInventoryType type = ii.getInventoryType(Id); if (!type.equals(MapleInventoryType.EQUIP)) { final short slotMax = ii.getSlotMax(c, Id); final List<IItem> existing = c.getPlayer().getInventory(type).listById(Id); if (!InventoryConstants.isRechargable(Id)) { if (existing.size() > 0) { // first update all existing slots to slotMax Iterator<IItem> i = existing.iterator(); while (quantity > 0) { if (i.hasNext()) { Item eItem = (Item) i.next(); short oldQ = eItem.getQuantity(); if (oldQ < slotMax && (eItem.getOwner().equals(owner) || owner == null)) { short newQ = (short) Math.min(oldQ + quantity, slotMax); quantity -= (newQ - oldQ); eItem.setQuantity(newQ); c.announce(InventoryFactory.updateInventorySlot(type, eItem)); } } else { break; } } } while (quantity > 0 || InventoryConstants.isRechargable(Id)) { short newQ = (short) Math.min(quantity, slotMax); if (newQ != 0) { quantity -= newQ; Item nItem = new Item(Id, (short) 0, newQ, petid); short newSlot = c.getPlayer().getInventory(type).addItem(nItem); if (newSlot == -1) { c.announce(InventoryFactory.getInventoryFull()); c.announce(InventoryFactory.getShowInventoryFull()); return false; } if (owner != null) { nItem.setOwner(owner); } c.announce(InventoryFactory.addInventorySlot(type, nItem)); if ((InventoryConstants.isRechargable(Id)) && quantity == 0) { break; } } else { c.announce(IntraPersonalFactory.enableActions()); return false; } } } else { final Item nItem = new Item(Id, (short) 0, quantity); final short newSlot = c.getPlayer().getInventory(type).addItem(nItem); if (newSlot == -1) { c.announce(InventoryFactory.getInventoryFull()); c.announce(InventoryFactory.getShowInventoryFull()); return false; } c.announce(InventoryFactory.addInventorySlot(type, nItem)); c.announce(IntraPersonalFactory.enableActions()); } } else if (quantity == 1) { IItem nEquip = ii.getEquipById(Id); if (owner != null) { nEquip.setOwner(owner); } short newSlot = c.getPlayer().getInventory(type).addItem(nEquip); if (newSlot == -1) { c.announce(InventoryFactory.getInventoryFull()); c.announce(InventoryFactory.getShowInventoryFull()); return false; } c.announce(InventoryFactory.addInventorySlot(type, nEquip)); } else { throw new RuntimeException("Trying to create equip with non-one quantity"); } return true; }
public static boolean addFromDrop( final MapleClient c, final IItem item, final boolean show, final boolean showAnyMessage) { final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance(); if (ii.isPickupRestricted(item.getId()) && c.getPlayer().getItemQuantity(item.getId(), true) > 0 && showAnyMessage) { c.announce(InventoryFactory.getInventoryFull()); c.announce(InventoryFactory.showItemUnavailable()); return false; } final MapleInventoryType type = ii.getInventoryType(item.getId()); short quantity = item.getQuantity(); if (!type.equals(MapleInventoryType.EQUIP)) { final short slotMax = ii.getSlotMax(c, item.getId()); final List<IItem> existing = c.getPlayer().getInventory(type).listById(item.getId()); if (!InventoryConstants.isRechargable(item.getId())) { if (existing.size() > 0) { // first update all existing slots to slotMax Iterator<IItem> i = existing.iterator(); while (quantity > 0) { if (i.hasNext()) { final Item eItem = (Item) i.next(); final 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); short newQi = (short) Math.min(quantity, slotMax); quantity -= newQi; Item nItem = new Item(item.getId(), (short) 0, newQi); nItem.setOwner(item.getOwner()); if (c.getPlayer().getInventory(type).fakeAddItem(nItem) == -1) { eItem.setQuantity(oldQ); return false; } quantity += newQi; c.announce(InventoryFactory.updateInventorySlot(type, eItem, showAnyMessage)); } } else { break; } } } while (quantity > 0 || InventoryConstants.isRechargable(item.getId())) { final short newQ = (short) Math.min(quantity, slotMax); quantity -= newQ; final Item nItem = new Item(item.getId(), (short) 0, newQ); nItem.setOwner(item.getOwner()); final short newSlot = c.getPlayer().getInventory(type).addItem(nItem); if (newSlot == -1) { if (showAnyMessage) { c.announce(InventoryFactory.getInventoryFull()); c.announce(InventoryFactory.getShowInventoryFull()); } item.setQuantity((short) (quantity + newQ)); return false; } c.announce(InventoryFactory.addInventorySlot(type, nItem, true)); if ((InventoryConstants.isRechargable(item.getId())) && quantity == 0) { break; } } } else { final Item nItem = new Item(item.getId(), (short) 0, quantity); final short newSlot = c.getPlayer().getInventory(type).addItem(nItem); if (newSlot == -1) { if (showAnyMessage) { c.announce(InventoryFactory.getInventoryFull()); c.announce(InventoryFactory.getShowInventoryFull()); } return false; } c.announce(InventoryFactory.addInventorySlot(type, nItem)); c.announce(IntraPersonalFactory.enableActions()); } } else if (quantity == 1) { final short newSlot = c.getPlayer().getInventory(type).addItem(item); if (newSlot == -1) { if (showAnyMessage) { c.announce(InventoryFactory.getInventoryFull()); c.announce(InventoryFactory.getShowInventoryFull()); } return false; } c.announce(InventoryFactory.addInventorySlot(type, item, true)); } else { return false; } if (show) { c.announce(EffectFactory.getShowItemGain(item.getId(), item.getQuantity())); } return true; }