Files
sweetgum-server/src/net/server/channel/handlers/ItemSortHandler.java
T
ronancpl 83d20e3c8b Skillbook announcer + isInJobTree fix
Abdula is now the Skillbook announcer NPC. Fixed some inconguencies with
the isInJobTree function, now properly returning if a skill id does make
presence on a player's current job path or not.
2017-06-05 21:08:35 -03:00

99 lines
3.8 KiB
Java

/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <[email protected]>
Matthias Butz <[email protected]>
Jan Christian Meyer <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import constants.ServerConstants;
import net.AbstractMaplePacketHandler;
import server.MapleInventoryManipulator;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleCharacter;
import client.MapleClient;
import client.inventory.Item;
import client.inventory.MapleInventory;
import client.inventory.MapleInventoryType;
import server.MapleItemInformationProvider;
public final class ItemSortHandler extends AbstractMaplePacketHandler {
@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());
}
}