use of client.inventory.Item in project HeavenMS by ronancpl.
the class InventoryMergeHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
chr.getAutobanManager().setTimestamp(2, slea.readInt(), 3);
MapleInventoryType inventoryType = MapleInventoryType.getByType(slea.readByte());
if (!ServerConstants.USE_ITEM_SORT) {
c.announce(MaplePacketCreator.enableActions());
return;
}
MapleInventory inventory = c.getPlayer().getInventory(inventoryType);
// ------------------- RonanLana's SLOT MERGER -----------------
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
Item srcItem, dstItem;
for (short dst = 1; dst <= inventory.getSlotLimit(); dst++) {
dstItem = inventory.getItem(dst);
if (dstItem == null)
continue;
for (short src = (short) (dst + 1); src <= inventory.getSlotLimit(); src++) {
srcItem = inventory.getItem(src);
if (srcItem == null)
continue;
if (dstItem.getItemId() != srcItem.getItemId())
continue;
if (dstItem.getQuantity() == ii.getSlotMax(c, inventory.getItem(dst).getItemId()))
break;
MapleInventoryManipulator.move(c, inventoryType, src, dst);
}
}
// ------------------------------------------------------------
inventory = c.getPlayer().getInventory(inventoryType);
boolean sorted = false;
while (!sorted) {
short freeSlot = inventory.getNextFreeSlot();
if (freeSlot != -1) {
short itemSlot = -1;
for (short i = (short) (freeSlot + 1); i <= inventory.getSlotLimit(); i = (short) (i + 1)) {
if (inventory.getItem(i) != null) {
itemSlot = i;
break;
}
}
if (itemSlot > 0) {
MapleInventoryManipulator.move(c, inventoryType, itemSlot, freeSlot);
} else {
sorted = true;
}
} else {
sorted = true;
}
}
c.announce(MaplePacketCreator.finishedSort(inventoryType.getType()));
c.announce(MaplePacketCreator.enableActions());
}
use of client.inventory.Item 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.Item in project HeavenMS by ronancpl.
the class ScriptedItemHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
// trash stamp (thx rmzero)
slea.readInt();
// item sl0t (thx rmzero)
short itemSlot = slea.readShort();
// itemId
int itemId = slea.readInt();
scriptedItem info = ii.getScriptedItemInfo(itemId);
if (info == null)
return;
ItemScriptManager ism = ItemScriptManager.getInstance();
Item item = c.getPlayer().getInventory(ItemConstants.getInventoryType(itemId)).getItem(itemSlot);
if (item == null || item.getItemId() != itemId || item.getQuantity() < 1 || !ism.scriptExists(info.getScript())) {
return;
}
ism.getItemScript(c, info.getScript());
c.announce(MaplePacketCreator.enableActions());
// NPCScriptManager.getInstance().start(c, info.getNpc(), null, null);
}
use of client.inventory.Item in project HeavenMS by ronancpl.
the class SkillBookHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!c.getPlayer().isAlive()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
slea.readInt();
short slot = (short) slea.readShort();
int itemId = slea.readInt();
MapleCharacter player = c.getPlayer();
Item toUse = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
if (toUse != null && toUse.getQuantity() == 1) {
if (toUse.getItemId() != itemId) {
return;
}
Map<String, Integer> skilldata = MapleItemInformationProvider.getInstance().getSkillStats(toUse.getItemId(), c.getPlayer().getJob().getId());
boolean canuse;
boolean success = false;
int skill = 0;
int maxlevel = 0;
if (skilldata == null) {
return;
}
Skill skill2 = SkillFactory.getSkill(skilldata.get("skillid"));
if (skilldata.get("skillid") == 0) {
canuse = false;
} else if ((player.getSkillLevel(skill2) >= skilldata.get("reqSkillLevel") || skilldata.get("reqSkillLevel") == 0) && player.getMasterLevel(skill2) < skilldata.get("masterLevel")) {
canuse = true;
if (MapleItemInformationProvider.rollSuccessChance(skilldata.get("success"))) {
success = true;
player.changeSkillLevel(skill2, player.getSkillLevel(skill2), Math.max(skilldata.get("masterLevel"), player.getMasterLevel(skill2)), -1);
} else {
success = false;
// player.dropMessage("The skill book lights up, but the skill winds up as if nothing happened.");
}
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short) 1, false);
} else {
canuse = false;
}
player.getClient().announce(MaplePacketCreator.skillBookSuccess(player, skill, maxlevel, canuse, success));
}
}
use of client.inventory.Item in project HeavenMS by ronancpl.
the class UseItemHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!c.getPlayer().isAlive()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
slea.readInt();
short slot = slea.readShort();
int itemId = slea.readInt();
Item toUse = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
if (toUse != null && toUse.getQuantity() > 0 && toUse.getItemId() == itemId) {
if (itemId == 2022178 || itemId == 2050004) {
c.getPlayer().dispelDebuffs();
remove(c, slot);
return;
} else if (itemId == 2050001) {
c.getPlayer().dispelDebuff(MapleDisease.DARKNESS);
remove(c, slot);
return;
} else if (itemId == 2050002) {
c.getPlayer().dispelDebuff(MapleDisease.WEAKEN);
c.getPlayer().dispelDebuff(MapleDisease.SLOW);
remove(c, slot);
return;
} else if (itemId == 2050003) {
c.getPlayer().dispelDebuff(MapleDisease.SEAL);
c.getPlayer().dispelDebuff(MapleDisease.CURSE);
remove(c, slot);
return;
} else if (ItemConstants.isTownScroll(itemId)) {
if (ii.getItemEffect(toUse.getItemId()).applyTo(c.getPlayer())) {
remove(c, slot);
}
return;
} else if (ItemConstants.isAntibanishScroll(itemId)) {
if (ii.getItemEffect(toUse.getItemId()).applyTo(c.getPlayer())) {
remove(c, slot);
} else {
c.getPlayer().dropMessage(5, "You cannot recover from a banish state at the moment.");
}
return;
}
remove(c, slot);
ii.getItemEffect(toUse.getItemId()).applyTo(c.getPlayer());
c.getPlayer().checkBerserk(c.getPlayer().isHidden());
}
}
Aggregations