use of client.inventory.MapleInventory in project HeavenMS by ronancpl.
the class AdminCommandHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!c.getPlayer().isGM()) {
return;
}
byte mode = slea.readByte();
String victim;
MapleCharacter target;
switch(mode) {
case // Level1~Level8 & Package1~Package2
0x00:
int[][] toSpawn = MapleItemInformationProvider.getInstance().getSummonMobs(slea.readInt());
for (int z = 0; z < toSpawn.length; z++) {
int[] toSpawnChild = toSpawn[z];
if (Randomizer.nextInt(101) <= toSpawnChild[1]) {
c.getPlayer().getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(toSpawnChild[0]), c.getPlayer().getPosition());
}
}
c.announce(MaplePacketCreator.enableActions());
break;
case 0x01:
{
// /d (inv)
byte type = slea.readByte();
MapleInventory in = c.getPlayer().getInventory(MapleInventoryType.getByType(type));
for (short i = 1; i <= in.getSlotLimit(); i++) {
// TODO What is the point of this loop?
if (in.getItem(i) != null) {
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.getByType(type), i, in.getItem(i).getQuantity(), false);
}
return;
}
break;
}
case // Exp
0x02:
c.getPlayer().setExp(slea.readInt());
break;
case // /ban <name>
0x03:
c.getPlayer().yellowMessage("Please use !ban <IGN> <Reason>");
break;
case // /block <name> <duration (in days)> <HACK/BOT/AD/HARASS/CURSE/SCAM/MISCONDUCT/SELL/ICASH/TEMP/GM/IPROGRAM/MEGAPHONE>
0x04:
victim = slea.readMapleAsciiString();
// reason
int type = slea.readByte();
int duration = slea.readInt();
String description = slea.readMapleAsciiString();
String reason = c.getPlayer().getName() + " used /ban to ban";
target = c.getChannelServer().getPlayerStorage().getCharacterByName(victim);
if (target != null) {
String readableTargetName = MapleCharacter.makeMapleReadable(target.getName());
String ip = target.getClient().getSession().getRemoteAddress().toString().split(":")[0];
reason += readableTargetName + " (IP: " + ip + ")";
if (duration == -1) {
target.ban(description + " " + reason);
} else {
target.block(type, duration, description);
target.sendPolice(duration, reason, 6000);
}
c.announce(MaplePacketCreator.getGMEffect(4, (byte) 0));
} else if (MapleCharacter.ban(victim, reason, false)) {
c.announce(MaplePacketCreator.getGMEffect(4, (byte) 0));
} else {
c.announce(MaplePacketCreator.getGMEffect(6, (byte) 1));
}
break;
case // /h, information by vana (and tele mode f1) ... hide ofcourse
0x10:
c.getPlayer().Hide(slea.readByte() == 1);
break;
case // Entering a map
0x11:
switch(slea.readByte()) {
case // /u
0:
StringBuilder sb = new StringBuilder("USERS ON THIS MAP: ");
for (MapleCharacter mc : c.getPlayer().getMap().getCharacters()) {
sb.append(mc.getName());
sb.append(" ");
}
c.getPlayer().message(sb.toString());
break;
case // /uclip and entering a map
12:
break;
}
break;
case // Send
0x12:
victim = slea.readMapleAsciiString();
int mapId = slea.readInt();
c.getChannelServer().getPlayerStorage().getCharacterByName(victim).changeMap(c.getChannelServer().getMapFactory().getMap(mapId));
break;
case // Kill
0x15:
int mobToKill = slea.readInt();
int amount = slea.readInt();
List<MapleMapObject> monsterx = c.getPlayer().getMap().getMapObjectsInRange(c.getPlayer().getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.MONSTER));
for (int x = 0; x < amount; x++) {
MapleMonster monster = (MapleMonster) monsterx.get(x);
if (monster.getId() == mobToKill) {
c.getPlayer().getMap().killMonster(monster, c.getPlayer(), true);
monster.giveExpToCharacter(c.getPlayer(), monster.getExp(), true, 1);
}
}
break;
case // Questreset
0x16:
MapleQuest.getInstance(slea.readShort()).reset(c.getPlayer());
break;
case // Summon
0x17:
int mobId = slea.readInt();
int quantity = slea.readInt();
for (int i = 0; i < quantity; i++) {
c.getPlayer().getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(mobId), c.getPlayer().getPosition());
}
break;
case // Maple & Mobhp
0x18:
int mobHp = slea.readInt();
c.getPlayer().dropMessage("Monsters HP");
List<MapleMapObject> monsters = c.getPlayer().getMap().getMapObjectsInRange(c.getPlayer().getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.MONSTER));
for (MapleMapObject mobs : monsters) {
MapleMonster monster = (MapleMonster) mobs;
if (monster.getId() == mobHp) {
c.getPlayer().dropMessage(monster.getName() + ": " + monster.getHp());
}
}
break;
case // Warn
0x1E:
victim = slea.readMapleAsciiString();
String message = slea.readMapleAsciiString();
target = c.getChannelServer().getPlayerStorage().getCharacterByName(victim);
if (target != null) {
target.getClient().announce(MaplePacketCreator.serverNotice(1, message));
c.announce(MaplePacketCreator.getGMEffect(0x1E, (byte) 1));
} else {
c.announce(MaplePacketCreator.getGMEffect(0x1E, (byte) 0));
}
break;
case // /Artifact Ranking
0x24:
break;
case // Testing purpose
0x77:
if (slea.available() == 4) {
System.out.println(slea.readInt());
} else if (slea.available() == 2) {
System.out.println(slea.readShort());
}
break;
default:
System.out.println("New GM packet encountered (MODE : " + mode + ": " + slea.toString());
break;
}
}
use of client.inventory.MapleInventory in project HeavenMS by ronancpl.
the class StorageHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
byte mode = slea.readByte();
final MapleStorage storage = chr.getStorage();
if (chr.getLevel() < 15) {
chr.dropMessage(1, "You may only use the storage once you have reached level 15.");
c.announce(MaplePacketCreator.enableActions());
return;
}
if (mode == 4) {
// take out
byte type = slea.readByte();
byte slot = slea.readByte();
if (slot < 0 || slot > storage.getSlots()) {
// removal starts at zero
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with storage.");
FilePrinter.print(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to work with storage slot " + slot + "\r\n");
c.disconnect(true, false);
return;
}
slot = storage.getSlot(MapleInventoryType.getByType(type), slot);
Item item = storage.getItem(slot);
if (item != null) {
if (MapleItemInformationProvider.getInstance().isPickupRestricted(item.getItemId()) && chr.haveItemWithId(item.getItemId(), true)) {
c.announce(MaplePacketCreator.getStorageError((byte) 0x0C));
return;
}
if (chr.getMap().getId() == 910000000) {
if (chr.getMeso() < 1000) {
c.announce(MaplePacketCreator.getStorageError((byte) 0x0B));
return;
} else {
chr.gainMeso(-1000, false);
}
}
if (MapleInventoryManipulator.checkSpace(c, item.getItemId(), item.getQuantity(), item.getOwner())) {
// actually the same but idc
item = storage.takeOut(slot);
String itemName = MapleItemInformationProvider.getInstance().getName(item.getItemId());
FilePrinter.print(FilePrinter.STORAGE + c.getAccountName() + ".txt", c.getPlayer().getName() + " took out " + item.getQuantity() + " " + itemName + " (" + item.getItemId() + ")\r\n");
if ((item.getFlag() & ItemConstants.KARMA) == ItemConstants.KARMA) {
// items with scissors of karma used on them are reset once traded
item.setFlag((byte) (item.getFlag() ^ ItemConstants.KARMA));
}
MapleInventoryManipulator.addFromDrop(c, item, false);
storage.sendTakenOut(c, item.getInventoryType());
} else {
c.announce(MaplePacketCreator.getStorageError((byte) 0x0A));
}
}
} else if (mode == 5) {
// store
short slot = slea.readShort();
int itemId = slea.readInt();
short quantity = slea.readShort();
MapleInventoryType slotType = ItemConstants.getInventoryType(itemId);
MapleInventory Inv = chr.getInventory(slotType);
if (slot < 1 || slot > Inv.getSlotLimit()) {
// player inv starts at one
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with storage.");
FilePrinter.print(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to store item at slot " + slot + "\r\n");
c.disconnect(true, false);
return;
}
if (quantity < 1 || chr.getItemQuantity(itemId, false) < quantity) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (storage.isFull()) {
c.announce(MaplePacketCreator.getStorageError((byte) 0x11));
return;
}
short meso = (short) (chr.getMap().getId() == 910000000 ? -500 : -100);
if (chr.getMeso() < meso) {
c.announce(MaplePacketCreator.getStorageError((byte) 0x0B));
} else {
MapleInventoryType invType = ItemConstants.getInventoryType(itemId);
Item item = chr.getInventory(invType).getItem(slot).copy();
if (item.getItemId() == itemId && (item.getQuantity() >= quantity || ItemConstants.isRechargable(itemId))) {
if (ItemConstants.isRechargable(itemId)) {
quantity = item.getQuantity();
}
chr.gainMeso(meso, false, true, false);
MapleInventoryManipulator.removeFromSlot(c, invType, slot, quantity, false);
item.setQuantity(quantity);
storage.store(item);
storage.sendStored(c, ItemConstants.getInventoryType(itemId));
String itemName = MapleItemInformationProvider.getInstance().getName(item.getItemId());
FilePrinter.print(FilePrinter.STORAGE + c.getAccountName() + ".txt", c.getPlayer().getName() + " stored " + item.getQuantity() + " " + itemName + " (" + item.getItemId() + ")\r\n");
}
}
} else if (mode == 6) {
// arrange items
if (ServerConstants.USE_STORAGE_ITEM_SORT)
storage.arrangeItems(c);
c.announce(MaplePacketCreator.enableActions());
} else if (mode == 7) {
// meso
int meso = slea.readInt();
int storageMesos = storage.getMeso();
int playerMesos = chr.getMeso();
if ((meso > 0 && storageMesos >= meso) || (meso < 0 && playerMesos >= -meso)) {
if (meso < 0 && (storageMesos - meso) < 0) {
meso = -2147483648 + storageMesos;
if (meso < playerMesos) {
c.announce(MaplePacketCreator.enableActions());
return;
}
} else if (meso > 0 && (playerMesos + meso) < 0) {
meso = 2147483647 - playerMesos;
if (meso > storageMesos) {
c.announce(MaplePacketCreator.enableActions());
return;
}
}
storage.setMeso(storageMesos - meso);
chr.gainMeso(meso, false, true, false);
FilePrinter.print(FilePrinter.STORAGE + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + (meso > 0 ? " took out " : " stored ") + Math.abs(meso) + " mesos\r\n");
} else {
c.announce(MaplePacketCreator.enableActions());
return;
}
storage.sendMeso(c);
} else if (mode == 8) {
// close
storage.close();
}
}
use of client.inventory.MapleInventory in project HeavenMS by ronancpl.
the class ScrollHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
// whatever...
slea.readInt();
short slot = slea.readShort();
short dst = slea.readShort();
byte ws = (byte) slea.readShort();
// white scroll being used?
boolean whiteScroll = false;
// legendary spirit skill
boolean legendarySpirit = false;
if ((ws & 2) == 2) {
whiteScroll = true;
}
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
Equip toScroll = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(dst);
Skill LegendarySpirit = SkillFactory.getSkill(1003);
if (c.getPlayer().getSkillLevel(LegendarySpirit) > 0 && dst >= 0) {
legendarySpirit = true;
toScroll = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(dst);
}
byte oldLevel = toScroll.getLevel();
byte oldSlots = toScroll.getUpgradeSlots();
MapleInventory useInventory = c.getPlayer().getInventory(MapleInventoryType.USE);
Item scroll = useInventory.getItem(slot);
Item wscroll = null;
if (((Equip) toScroll).getUpgradeSlots() < 1 && !ItemConstants.isCleanSlate(scroll.getItemId())) {
c.announce(MaplePacketCreator.getInventoryFull());
return;
}
List<Integer> scrollReqs = ii.getScrollReqs(scroll.getItemId());
if (scrollReqs.size() > 0 && !scrollReqs.contains(toScroll.getItemId())) {
c.announce(MaplePacketCreator.getInventoryFull());
return;
}
if (whiteScroll) {
wscroll = useInventory.findById(2340000);
if (wscroll == null || wscroll.getItemId() != 2340000) {
whiteScroll = false;
}
}
if (!ItemConstants.isChaosScroll(scroll.getItemId()) && !ItemConstants.isCleanSlate(scroll.getItemId())) {
if (!canScroll(scroll.getItemId(), toScroll.getItemId())) {
return;
}
}
if (ItemConstants.isCleanSlate(scroll.getItemId()) && !(toScroll.getLevel() + toScroll.getUpgradeSlots() < ii.getEquipStats(toScroll.getItemId()).get("tuc"))) {
// upgrade slots can be over because of hammers
return;
}
Equip scrolled = (Equip) ii.scrollEquipWithId(toScroll, scroll.getItemId(), whiteScroll, 0, c.getPlayer().isGM());
// fail
ScrollResult scrollSuccess = Equip.ScrollResult.FAIL;
if (scrolled == null) {
scrollSuccess = Equip.ScrollResult.CURSE;
} else if (scrolled.getLevel() > oldLevel || (ItemConstants.isCleanSlate(scroll.getItemId()) && scrolled.getUpgradeSlots() == oldSlots + 1) || ItemConstants.isFlagModifier(scroll.getItemId(), scrolled.getFlag())) {
scrollSuccess = Equip.ScrollResult.SUCCESS;
}
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, scroll.getPosition(), (short) 1, false);
if (whiteScroll && !ItemConstants.isCleanSlate(scroll.getItemId())) {
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, wscroll.getPosition(), (short) 1, false, false);
}
final List<ModifyInventory> mods = new ArrayList<>();
if (scrollSuccess == Equip.ScrollResult.CURSE) {
mods.add(new ModifyInventory(3, toScroll));
if (dst < 0) {
c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).removeItem(toScroll.getPosition());
} else {
c.getPlayer().getInventory(MapleInventoryType.EQUIP).removeItem(toScroll.getPosition());
}
} else {
mods.add(new ModifyInventory(3, scrolled));
mods.add(new ModifyInventory(0, scrolled));
}
c.announce(MaplePacketCreator.modifyInventory(true, mods));
c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.getScrollEffect(c.getPlayer().getId(), scrollSuccess, legendarySpirit));
if (dst < 0 && (scrollSuccess == Equip.ScrollResult.SUCCESS || scrollSuccess == Equip.ScrollResult.CURSE)) {
c.getPlayer().equipChanged();
}
}
use of client.inventory.MapleInventory in project HeavenMS by ronancpl.
the class CreateCharHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
String name = slea.readMapleAsciiString();
if (!MapleCharacter.canCreateChar(name)) {
return;
}
MapleCharacter newchar = MapleCharacter.getDefault(c);
newchar.setWorld(c.getWorld());
int job = slea.readInt();
int face = slea.readInt();
int hair = slea.readInt();
int hairColor = slea.readInt();
int skincolor = slea.readInt();
newchar.setSkinColor(MapleSkinColor.getById(skincolor));
int top = slea.readInt();
int bottom = slea.readInt();
int shoes = slea.readInt();
int weapon = slea.readInt();
newchar.setGender(slea.readByte());
newchar.setName(name);
newchar.setHair(hair + hairColor);
newchar.setFace(face);
int[] items = new int[] { weapon, top, bottom, shoes, hair, face };
for (int i = 0; i < items.length; i++) {
if (!isLegal(items[i])) {
AutobanFactory.PACKET_EDIT.alert(newchar, name + " tried to packet edit in character creation.");
FilePrinter.printError(FilePrinter.EXPLOITS + newchar + ".txt", "Tried to packet edit in char creation.");
c.disconnect(true, false);
return;
}
}
if (job == 0) {
// Knights of Cygnus
newchar.setJob(MapleJob.NOBLESSE);
newchar.setMapId(130030000);
newchar.getInventory(MapleInventoryType.ETC).addItem(new Item(4161047, (short) 0, (short) 1));
} else if (job == 1) {
// Adventurer
newchar.setJob(MapleJob.BEGINNER);
newchar.setMapId(/*specialJobType == 2 ? 3000600 : */
10000);
newchar.getInventory(MapleInventoryType.ETC).addItem(new Item(4161001, (short) 0, (short) 1));
} else if (job == 2) {
// Aran
newchar.setJob(MapleJob.LEGEND);
newchar.setMapId(914000000);
newchar.getInventory(MapleInventoryType.ETC).addItem(new Item(4161048, (short) 0, (short) 1));
} else {
c.announce(MaplePacketCreator.deleteCharResponse(0, 9));
return;
}
MapleInventory equipped = newchar.getInventory(MapleInventoryType.EQUIPPED);
Item eq_top = MapleItemInformationProvider.getInstance().getEquipById(top);
eq_top.setPosition((byte) -5);
equipped.addFromDB(eq_top);
Item eq_bottom = MapleItemInformationProvider.getInstance().getEquipById(bottom);
eq_bottom.setPosition((byte) -6);
equipped.addFromDB(eq_bottom);
Item eq_shoes = MapleItemInformationProvider.getInstance().getEquipById(shoes);
eq_shoes.setPosition((byte) -7);
equipped.addFromDB(eq_shoes);
Item eq_weapon = MapleItemInformationProvider.getInstance().getEquipById(weapon);
eq_weapon.setPosition((byte) -11);
equipped.addFromDB(eq_weapon.copy());
if (!newchar.insertNewChar()) {
c.announce(MaplePacketCreator.deleteCharResponse(0, 9));
return;
}
c.announce(MaplePacketCreator.addNewCharEntry(newchar));
Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.sendYellowTip("[NEW CHAR]: " + c.getAccountName() + " has created a new character with IGN " + name));
}
use of client.inventory.MapleInventory in project HeavenMS by ronancpl.
the class MaplePacketCreator method addInventoryInfo.
private static void addInventoryInfo(final MaplePacketLittleEndianWriter mplew, MapleCharacter chr) {
for (byte i = 1; i <= 5; i++) {
mplew.write(chr.getInventory(MapleInventoryType.getByType(i)).getSlotLimit());
}
mplew.writeLong(getTime(-2));
MapleInventory iv = chr.getInventory(MapleInventoryType.EQUIPPED);
Collection<Item> equippedC = iv.list();
List<Item> equipped = new ArrayList<>(equippedC.size());
List<Item> equippedCash = new ArrayList<>(equippedC.size());
for (Item item : equippedC) {
if (item.getPosition() <= -100) {
equippedCash.add((Item) item);
} else {
equipped.add((Item) item);
}
}
Collections.sort(equipped);
for (Item item : equipped) {
addItemInfo(mplew, item);
}
// start of equip cash
mplew.writeShort(0);
for (Item item : equippedCash) {
addItemInfo(mplew, item);
}
// start of equip inventory
mplew.writeShort(0);
for (Item item : chr.getInventory(MapleInventoryType.EQUIP).list()) {
addItemInfo(mplew, item);
}
mplew.writeInt(0);
for (Item item : chr.getInventory(MapleInventoryType.USE).list()) {
addItemInfo(mplew, item);
}
mplew.write(0);
for (Item item : chr.getInventory(MapleInventoryType.SETUP).list()) {
addItemInfo(mplew, item);
}
mplew.write(0);
for (Item item : chr.getInventory(MapleInventoryType.ETC).list()) {
addItemInfo(mplew, item);
}
mplew.write(0);
for (Item item : chr.getInventory(MapleInventoryType.CASH).list()) {
addItemInfo(mplew, item);
}
}
Aggregations