use of client.inventory.MapleInventoryType in project HeavenMS by ronancpl.
the class MapleCharacter method sellAllItemsFromName.
public int sellAllItemsFromName(byte invTypeId, String name) {
// player decides from which inventory items should be sold.
MapleInventoryType type = MapleInventoryType.getByType(invTypeId);
Item it = getInventory(type).findByName(name);
if (it == null) {
return (-1);
}
return (sellAllItemsFromPosition(ii, type, it.getPosition()));
}
use of client.inventory.MapleInventoryType in project HeavenMS by ronancpl.
the class DueyHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!ServerConstants.USE_DUEY) {
c.announce(MaplePacketCreator.enableActions());
return;
}
byte operation = slea.readByte();
if (operation == Actions.TOSERVER_SEND_ITEM.getCode()) {
final int fee = 5000;
byte inventId = slea.readByte();
short itemPos = slea.readShort();
short amount = slea.readShort();
int mesos = slea.readInt();
String recipient = slea.readMapleAsciiString();
if (mesos < 0 || ((long) mesos + fee + getFee(mesos)) > Integer.MAX_VALUE || (amount < 1 && mesos == 0)) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with duey.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to use duey with mesos " + mesos + " and amount " + amount + "\r\n");
c.disconnect(true, false);
return;
}
int finalcost = mesos + fee + getFee(mesos);
boolean send = false;
if (c.getPlayer().getMeso() >= finalcost) {
int accid = getAccIdFromCNAME(recipient, true);
if (accid != -1) {
if (accid != c.getAccID()) {
send = true;
} else {
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_SAMEACC_ERROR.getCode()));
}
} else {
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_NAME_DOES_NOT_EXIST.getCode()));
}
} else {
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_NOT_ENOUGH_MESOS.getCode()));
}
MapleClient rClient = null;
int channel = c.getWorldServer().find(recipient);
if (channel > -1) {
Channel rcserv = c.getWorldServer().getChannel(channel);
rClient = rcserv.getPlayerStorage().getCharacterByName(recipient).getClient();
}
if (send) {
if (inventId > 0) {
MapleInventoryType inv = MapleInventoryType.getByType(inventId);
Item item = c.getPlayer().getInventory(inv).getItem(itemPos);
if (item != null && c.getPlayer().getItemQuantity(item.getItemId(), false) >= amount) {
c.getPlayer().gainMeso(-finalcost, false);
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_SUCCESSFULLY_SENT.getCode()));
if (ItemConstants.isRechargable(item.getItemId())) {
MapleInventoryManipulator.removeFromSlot(c, inv, itemPos, item.getQuantity(), true);
} else {
MapleInventoryManipulator.removeFromSlot(c, inv, itemPos, amount, true, false);
}
addItemToDB(item, amount, mesos, c.getPlayer().getName(), getAccIdFromCNAME(recipient, false));
} else {
if (item != null) {
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_INCORRECT_REQUEST.getCode()));
}
return;
}
} else {
c.getPlayer().gainMeso(-finalcost, false);
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_SUCCESSFULLY_SENT.getCode()));
addMesoToDB(mesos, c.getPlayer().getName(), getAccIdFromCNAME(recipient, false));
}
if (rClient != null && rClient.isLoggedIn() && !rClient.getPlayer().isAwayFromWorld()) {
showDueyNotification(rClient, rClient.getPlayer());
}
}
} else if (operation == Actions.TOSERVER_REMOVE_PACKAGE.getCode()) {
int packageid = slea.readInt();
removeItemFromDB(packageid);
c.announce(MaplePacketCreator.removeItemFromDuey(true, packageid));
} else if (operation == Actions.TOSERVER_CLAIM_PACKAGE.getCode()) {
int packageid = slea.readInt();
List<DueyPackages> packages = new LinkedList<>();
DueyPackages dp = null;
Connection con = null;
try {
con = DatabaseConnection.getConnection();
DueyPackages dueypack;
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM dueypackages LEFT JOIN dueyitems USING (PackageId) WHERE PackageId = ?")) {
ps.setInt(1, packageid);
try (ResultSet rs = ps.executeQuery()) {
dueypack = null;
if (rs.next()) {
dueypack = getItemByPID(rs);
dueypack.setSender(rs.getString("SenderName"));
dueypack.setMesos(rs.getInt("Mesos"));
dueypack.setSentTime(rs.getString("TimeStamp"));
packages.add(dueypack);
}
}
}
dp = dueypack;
if (dp == null) {
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_UNKNOWN_ERROR.getCode()));
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to receive package from duey with id " + packageid + "\r\n");
return;
}
if (dp.getItem() != null) {
if (!MapleInventoryManipulator.checkSpace(c, dp.getItem().getItemId(), dp.getItem().getQuantity(), dp.getItem().getOwner())) {
int itemid = dp.getItem().getItemId();
if (MapleItemInformationProvider.getInstance().isPickupRestricted(itemid) && c.getPlayer().getInventory(ItemConstants.getInventoryType(itemid)).findById(itemid) != null) {
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_RECEIVER_WITH_UNIQUE.getCode()));
} else {
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_NO_FREE_SLOTS.getCode()));
}
return;
} else {
MapleInventoryManipulator.addFromDrop(c, dp.getItem(), false);
}
}
long gainmesos = 0;
long totalmesos = (long) dp.getMesos() + (long) c.getPlayer().getMeso();
if (totalmesos < 0 || dp.getMesos() < 0)
gainmesos = 0;
else {
totalmesos = Math.min(totalmesos, Integer.MAX_VALUE);
gainmesos = totalmesos - c.getPlayer().getMeso();
}
c.getPlayer().gainMeso((int) gainmesos, false);
removeItemFromDB(packageid);
c.announce(MaplePacketCreator.removeItemFromDuey(false, packageid));
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
use of client.inventory.MapleInventoryType 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.MapleInventoryType in project HeavenMS by ronancpl.
the class ItemAction method check.
@Override
public boolean check(MapleCharacter chr, Integer extSelection) {
List<Pair<Item, MapleInventoryType>> gainList = new LinkedList<>();
List<Pair<Item, MapleInventoryType>> selectList = new LinkedList<>();
List<Pair<Item, MapleInventoryType>> randomList = new LinkedList<>();
List<Integer> allSlotUsed = new ArrayList(5);
for (byte i = 0; i < 5; i++) allSlotUsed.add(0);
for (ItemData item : items) {
if (!canGetItem(item, chr)) {
continue;
}
MapleInventoryType type = ItemConstants.getInventoryType(item.getId());
if (item.getProp() != null) {
Item toItem = new Item(item.getId(), (short) 0, (short) item.getCount());
if (item.getProp() < 0) {
selectList.add(new Pair<>(toItem, type));
} else {
randomList.add(new Pair<>(toItem, type));
}
} else {
if (item.getCount() > 0) {
// Make sure they can hold the item.
Item toItem = new Item(item.getId(), (short) 0, (short) item.getCount());
gainList.add(new Pair<>(toItem, type));
} else {
// Make sure they actually have the item.
int quantity = item.getCount() * -1;
int freeSlotCount = chr.getInventory(type).freeSlotCountById(item.getId(), quantity);
if (freeSlotCount == -1) {
if (type.equals(MapleInventoryType.EQUIP) && chr.getInventory(MapleInventoryType.EQUIPPED).countById(item.getId()) > quantity)
continue;
chr.dropMessage(1, "Please check if you have enough items in your inventory.");
return false;
} else {
// more slots available from the given items!
int idx = type.getType() - 1;
allSlotUsed.set(idx, allSlotUsed.get(idx) - freeSlotCount);
}
}
}
}
if (!randomList.isEmpty()) {
int result;
MapleClient c = chr.getClient();
List<Integer> rndUsed = new ArrayList(5);
for (byte i = 0; i < 5; i++) rndUsed.add(allSlotUsed.get(i));
for (Pair<Item, MapleInventoryType> it : randomList) {
int idx = it.getRight().getType() - 1;
result = MapleInventoryManipulator.checkSpaceProgressively(c, it.getLeft().getItemId(), it.getLeft().getQuantity(), "", rndUsed.get(idx));
if (result % 2 == 0) {
chr.dropMessage(1, "Please check if you have enough space in your inventory.");
return false;
}
allSlotUsed.set(idx, Math.max(allSlotUsed.get(idx), result >> 1));
}
}
if (!selectList.isEmpty()) {
Pair<Item, MapleInventoryType> selected = selectList.get(extSelection);
gainList.add(selected);
}
if (!MapleInventory.checkSpots(chr, gainList, allSlotUsed)) {
chr.dropMessage(1, "Please check if you have enough space in your inventory.");
return false;
}
return true;
}
use of client.inventory.MapleInventoryType in project HeavenMS by ronancpl.
the class Commands method executeHeavenMsCommandLv4.
public static boolean executeHeavenMsCommandLv4(Channel cserv, Server srv, MapleClient c, String[] sub) {
// SuperGM
MapleCharacter player = c.getPlayer();
switch(sub[0]) {
case "servermessage":
c.getWorldServer().setServerMessage(joinStringFrom(sub, 1));
break;
case "proitem":
if (sub.length < 3) {
player.yellowMessage("Syntax: !proitem <itemid> <statvalue>");
break;
}
int itemid = Integer.parseInt(sub[1]);
short multiply = Short.parseShort(sub[2]);
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
MapleInventoryType type = ItemConstants.getInventoryType(itemid);
if (type.equals(MapleInventoryType.EQUIP)) {
Item it = ii.getEquipById(itemid);
it.setOwner(player.getName());
hardsetItemStats((Equip) it, multiply);
MapleInventoryManipulator.addFromDrop(c, it);
} else {
player.dropMessage(6, "Make sure it's an equippable item.");
}
break;
case "seteqstat":
if (sub.length < 2) {
player.yellowMessage("Syntax: !seteqstat <statvalue>");
break;
}
int newStat = Integer.parseInt(sub[1]);
MapleInventory equip = player.getInventory(MapleInventoryType.EQUIP);
for (byte i = 1; i <= equip.getSlotLimit(); i++) {
try {
Equip eu = (Equip) equip.getItem(i);
if (eu == null)
continue;
short incval = (short) newStat;
eu.setWdef(incval);
eu.setAcc(incval);
eu.setAvoid(incval);
eu.setJump(incval);
eu.setMatk(incval);
eu.setMdef(incval);
eu.setHp(incval);
eu.setMp(incval);
eu.setSpeed(incval);
eu.setWatk(incval);
eu.setDex(incval);
eu.setInt(incval);
eu.setStr(incval);
eu.setLuk(incval);
byte flag = eu.getFlag();
flag |= ItemConstants.UNTRADEABLE;
eu.setFlag(flag);
player.forceUpdateItem(eu);
} catch (Exception e) {
e.printStackTrace();
}
}
break;
case "exprate":
if (sub.length < 2) {
player.yellowMessage("Syntax: !exprate <newrate>");
break;
}
int exprate = Math.max(Integer.parseInt(sub[1]), 1);
c.getWorldServer().setExpRate(exprate);
c.getWorldServer().broadcastPacket(MaplePacketCreator.serverNotice(6, "[Rate] Exp Rate has been changed to " + exprate + "x."));
break;
case "mesorate":
if (sub.length < 2) {
player.yellowMessage("Syntax: !mesorate <newrate>");
break;
}
int mesorate = Math.max(Integer.parseInt(sub[1]), 1);
c.getWorldServer().setMesoRate(mesorate);
c.getWorldServer().broadcastPacket(MaplePacketCreator.serverNotice(6, "[Rate] Meso Rate has been changed to " + mesorate + "x."));
break;
case "droprate":
if (sub.length < 2) {
player.yellowMessage("Syntax: !droprate <newrate>");
break;
}
int droprate = Math.max(Integer.parseInt(sub[1]), 1);
c.getWorldServer().setDropRate(droprate);
c.getWorldServer().broadcastPacket(MaplePacketCreator.serverNotice(6, "[Rate] Drop Rate has been changed to " + droprate + "x."));
break;
case "questrate":
if (sub.length < 2) {
player.yellowMessage("Syntax: !questrate <newrate>");
break;
}
int questrate = Math.max(Integer.parseInt(sub[1]), 1);
c.getWorldServer().setQuestRate(questrate);
c.getWorldServer().broadcastPacket(MaplePacketCreator.serverNotice(6, "[Rate] Quest Rate has been changed to " + questrate + "x."));
break;
case "itemvac":
List<MapleMapObject> list = player.getMap().getMapObjectsInRange(player.getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.ITEM));
for (MapleMapObject item : list) {
player.pickupItem(item);
}
break;
case "forcevac":
List<MapleMapObject> items = player.getMap().getMapObjectsInRange(player.getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.ITEM));
for (MapleMapObject item : items) {
MapleMapItem mapItem = (MapleMapItem) item;
if (mapItem.getMeso() > 0) {
player.gainMeso(mapItem.getMeso(), true);
} else if (mapItem.getItemId() == 4031865 || mapItem.getItemId() == 4031866) {
// Add NX to account, show effect and make item disappear
player.getCashShop().gainCash(1, mapItem.getItemId() == 4031865 ? 100 : 250);
} else if (mapItem.getItem().getItemId() >= 5000000 && mapItem.getItem().getItemId() <= 5000100) {
int petId = MaplePet.createPet(mapItem.getItem().getItemId());
if (petId == -1) {
continue;
}
MapleInventoryManipulator.addById(c, mapItem.getItem().getItemId(), mapItem.getItem().getQuantity(), null, petId);
} else {
MapleInventoryManipulator.addFromDrop(c, mapItem.getItem(), true);
}
player.getMap().pickItemDrop(MaplePacketCreator.removeItemFromMap(mapItem.getObjectId(), 2, player.getId()), mapItem);
}
break;
case "zakum":
player.getMap().spawnFakeMonsterOnGroundBelow(MapleLifeFactory.getMonster(8800000), player.getPosition());
for (int x = 8800003; x < 8800011; x++) {
player.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(x), player.getPosition());
}
break;
case "horntail":
final Point targetPoint = player.getPosition();
final MapleMap targetMap = player.getMap();
targetMap.spawnHorntailOnGroundBelow(targetPoint);
break;
case "pinkbean":
player.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(8820001), player.getPosition());
break;
case "pap":
player.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(8500001), player.getPosition());
break;
case "pianus":
player.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(8510000), player.getPosition());
break;
case "cake":
MapleMonster monster = MapleLifeFactory.getMonster(9400606);
if (sub.length > 1) {
int newHp = Integer.parseInt(sub[1]);
if (newHp < 0)
newHp = Integer.MAX_VALUE;
monster.getStats().setHp(newHp);
monster.setStartingHp(newHp);
}
player.getMap().spawnMonsterOnGroundBelow(monster, player.getPosition());
break;
default:
return false;
}
return true;
}
Aggregations