Search in sources :

Example 51 with Item

use of client.inventory.Item in project HeavenMS by ronancpl.

the class UseSummonBagHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    // [4A 00][6C 4C F2 02][02 00][63 0B 20 00]
    if (!c.getPlayer().isAlive()) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    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) {
        MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short) 1, false);
        int[][] toSpawn = MapleItemInformationProvider.getInstance().getSummonMobs(itemId);
        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());
}
Also used : Item(client.inventory.Item)

Example 52 with Item

use of client.inventory.Item in project HeavenMS by ronancpl.

the class WeddingHandler method handlePacket.

@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    // System.out.println("Wedding Packet: " + slea);
    MapleCharacter chr = c.getPlayer();
    byte operation = slea.readByte();
    switch(operation) {
        case // Add an item to the Wedding Registry
        0x06:
            short slot = slea.readShort();
            int itemid = slea.readInt();
            short quantity = slea.readShort();
            MapleInventoryType type = ItemConstants.getInventoryType(itemid);
            Item item = chr.getInventory(type).getItem(slot);
            if (itemid == item.getItemId() && quantity <= item.getQuantity()) {
                c.announce(MaplePacketCreator.addItemToWeddingRegistry(chr, item));
            }
    }
}
Also used : Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) MapleInventoryType(client.inventory.MapleInventoryType)

Example 53 with Item

use of client.inventory.Item in project HeavenMS by ronancpl.

the class MaplePacketCreator method addCharEquips.

private static void addCharEquips(final MaplePacketLittleEndianWriter mplew, MapleCharacter chr) {
    MapleInventory equip = chr.getInventory(MapleInventoryType.EQUIPPED);
    Collection<Item> ii = MapleItemInformationProvider.getInstance().canWearEquipment(chr, equip.list());
    Map<Short, Integer> myEquip = new LinkedHashMap<>();
    Map<Short, Integer> maskedEquip = new LinkedHashMap<>();
    for (Item item : ii) {
        short pos = (byte) (item.getPosition() * -1);
        if (pos < 100 && myEquip.get(pos) == null) {
            myEquip.put(pos, item.getItemId());
        } else if (pos > 100 && pos != 111) {
            // don't ask. o.o
            pos -= 100;
            if (myEquip.get(pos) != null) {
                maskedEquip.put(pos, myEquip.get(pos));
            }
            myEquip.put(pos, item.getItemId());
        } else if (myEquip.get(pos) != null) {
            maskedEquip.put(pos, item.getItemId());
        }
    }
    for (Entry<Short, Integer> entry : myEquip.entrySet()) {
        mplew.write(entry.getKey());
        mplew.writeInt(entry.getValue());
    }
    mplew.write(0xFF);
    for (Entry<Short, Integer> entry : maskedEquip.entrySet()) {
        mplew.write(entry.getKey());
        mplew.writeInt(entry.getValue());
    }
    mplew.write(0xFF);
    Item cWeapon = equip.getItem((short) -111);
    mplew.writeInt(cWeapon != null ? cWeapon.getItemId() : 0);
    for (int i = 0; i < 3; i++) {
        if (chr.getPet(i) != null) {
            mplew.writeInt(chr.getPet(i).getItemId());
        } else {
            mplew.writeInt(0);
        }
    }
}
Also used : MapleMapItem(server.maps.MapleMapItem) SpecialCashItem(server.CashShop.SpecialCashItem) CashItem(server.CashShop.CashItem) Item(client.inventory.Item) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) MapleShopItem(server.MapleShopItem) MapleInventory(client.inventory.MapleInventory) Point(java.awt.Point) LinkedHashMap(java.util.LinkedHashMap)

Example 54 with Item

use of client.inventory.Item in project HeavenMS by ronancpl.

the class MaplePacketCreator method showBoughtCashPackage.

public static byte[] showBoughtCashPackage(List<Item> cashPackage, int accountId) {
    final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
    mplew.writeShort(SendOpcode.CASHSHOP_OPERATION.getValue());
    mplew.write(0x89);
    mplew.write(cashPackage.size());
    for (Item item : cashPackage) {
        addCashItemInformation(mplew, item, accountId);
    }
    mplew.writeShort(0);
    return mplew.getPacket();
}
Also used : MapleMapItem(server.maps.MapleMapItem) SpecialCashItem(server.CashShop.SpecialCashItem) CashItem(server.CashShop.CashItem) Item(client.inventory.Item) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) MapleShopItem(server.MapleShopItem) MaplePacketLittleEndianWriter(tools.data.output.MaplePacketLittleEndianWriter)

Example 55 with Item

use of client.inventory.Item in project HeavenMS by ronancpl.

the class MaplePacketCreator method spawnPlayerMapObject.

/**
 * Gets a packet spawning a player as a mapobject to other clients.
 *
 * @param chr The character to spawn to other clients.
 * @return The spawn player packet.
 */
public static byte[] spawnPlayerMapObject(MapleCharacter chr) {
    final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
    mplew.writeShort(SendOpcode.SPAWN_PLAYER.getValue());
    mplew.writeInt(chr.getId());
    // v83
    mplew.write(chr.getLevel());
    mplew.writeMapleAsciiString(chr.getName());
    if (chr.getGuildId() < 1) {
        mplew.writeMapleAsciiString("");
        mplew.write(new byte[6]);
    } else {
        MapleGuildSummary gs = chr.getClient().getWorldServer().getGuildSummary(chr.getGuildId(), chr.getWorld());
        if (gs != null) {
            mplew.writeMapleAsciiString(gs.getName());
            mplew.writeShort(gs.getLogoBG());
            mplew.write(gs.getLogoBGColor());
            mplew.writeShort(gs.getLogo());
            mplew.write(gs.getLogoColor());
        } else {
            mplew.writeMapleAsciiString("");
            mplew.write(new byte[6]);
        }
    }
    mplew.writeInt(0);
    // v83
    mplew.writeShort(0);
    mplew.write(0xFC);
    mplew.write(1);
    if (chr.getBuffedValue(MapleBuffStat.MORPH) != null) {
        mplew.writeInt(2);
    } else {
        mplew.writeInt(0);
    }
    long buffmask = 0;
    Integer buffvalue = null;
    if (chr.getBuffedValue(MapleBuffStat.DARKSIGHT) != null && !chr.isHidden()) {
        buffmask |= MapleBuffStat.DARKSIGHT.getValue();
    }
    if (chr.getBuffedValue(MapleBuffStat.COMBO) != null) {
        buffmask |= MapleBuffStat.COMBO.getValue();
        buffvalue = Integer.valueOf(chr.getBuffedValue(MapleBuffStat.COMBO).intValue());
    }
    if (chr.getBuffedValue(MapleBuffStat.SHADOWPARTNER) != null) {
        buffmask |= MapleBuffStat.SHADOWPARTNER.getValue();
    }
    if (chr.getBuffedValue(MapleBuffStat.SOULARROW) != null) {
        buffmask |= MapleBuffStat.SOULARROW.getValue();
    }
    if (chr.getBuffedValue(MapleBuffStat.MORPH) != null) {
        buffvalue = Integer.valueOf(chr.getBuffedValue(MapleBuffStat.MORPH).intValue());
    }
    if (chr.getBuffedValue(MapleBuffStat.ENERGY_CHARGE) != null) {
        buffmask |= MapleBuffStat.ENERGY_CHARGE.getValue();
        buffvalue = Integer.valueOf(chr.getBuffedValue(MapleBuffStat.ENERGY_CHARGE).intValue());
    }
    // AREN'T THESE
    mplew.writeInt((int) ((buffmask >> 32) & 0xffffffffL));
    if (buffvalue != null) {
        if (chr.getBuffedValue(MapleBuffStat.MORPH) != null) {
            // TEST
            mplew.writeShort(buffvalue);
        } else {
            mplew.write(buffvalue.byteValue());
        }
    }
    mplew.writeInt((int) (buffmask & 0xffffffffL));
    int CHAR_MAGIC_SPAWN = Randomizer.nextInt();
    mplew.skip(6);
    mplew.writeInt(CHAR_MAGIC_SPAWN);
    mplew.skip(11);
    // v74
    mplew.writeInt(CHAR_MAGIC_SPAWN);
    mplew.skip(11);
    mplew.writeInt(CHAR_MAGIC_SPAWN);
    mplew.writeShort(0);
    mplew.write(0);
    final Item mount = chr.getInventory(MapleInventoryType.EQUIPPED).getItem((short) -18);
    if (chr.getBuffedValue(MapleBuffStat.MONSTER_RIDING) != null && mount != null) {
        mplew.writeInt(mount.getItemId());
        mplew.writeInt(1004);
    } else {
        mplew.writeLong(0);
    }
    mplew.writeInt(CHAR_MAGIC_SPAWN);
    mplew.skip(9);
    mplew.writeInt(CHAR_MAGIC_SPAWN);
    mplew.writeShort(0);
    // actually not 0, why is it 0 then?
    mplew.writeInt(0);
    mplew.skip(10);
    mplew.writeInt(CHAR_MAGIC_SPAWN);
    mplew.skip(13);
    mplew.writeInt(CHAR_MAGIC_SPAWN);
    mplew.writeShort(0);
    mplew.write(0);
    mplew.writeShort(chr.getJob().getId());
    /* replace "mplew.writeShort(chr.getJob().getId())" with this snippet for 3rd person FJ animation on all classes
                if (chr.getJob().isA(MapleJob.HERMIT) || chr.getJob().isA(MapleJob.DAWNWARRIOR2) || chr.getJob().isA(MapleJob.NIGHTWALKER2)) {
			mplew.writeShort(chr.getJob().getId());
                } else {
			mplew.writeShort(412);
                }*/
    addCharLook(mplew, chr, false);
    mplew.writeInt(chr.getInventory(MapleInventoryType.CASH).countById(5110000));
    mplew.writeInt(chr.getItemEffect());
    mplew.writeInt(ItemConstants.getInventoryType(chr.getChair()) == MapleInventoryType.SETUP ? chr.getChair() : 0);
    mplew.writePos(chr.getPosition());
    mplew.write(chr.getStance());
    // chr.getFh()
    mplew.writeShort(0);
    mplew.write(0);
    MaplePet[] pet = chr.getPets();
    for (int i = 0; i < 3; i++) {
        if (pet[i] != null) {
            addPetInfo(mplew, pet[i], false);
        }
    }
    // end of pets
    mplew.write(0);
    if (chr.getMount() == null) {
        // mob level
        mplew.writeInt(1);
        // mob exp + tiredness
        mplew.writeLong(0);
    } else {
        mplew.writeInt(chr.getMount().getLevel());
        mplew.writeInt(chr.getMount().getExp());
        mplew.writeInt(chr.getMount().getTiredness());
    }
    MaplePlayerShop mps = chr.getPlayerShop();
    if (mps != null && mps.isOwner(chr)) {
        if (mps.hasFreeSlot()) {
            addAnnounceBox(mplew, mps, mps.getVisitors().length);
        } else {
            addAnnounceBox(mplew, mps, 1);
        }
    } else if (chr.getMiniGame() != null && chr.getMiniGame().isOwner(chr)) {
        if (chr.getMiniGame().hasFreeSlot()) {
            addAnnounceBox(mplew, chr.getMiniGame(), 1, 0, 1, 0);
        } else {
            addAnnounceBox(mplew, chr.getMiniGame(), 1, 0, 2, 1);
        }
    } else {
        mplew.write(0);
    }
    if (chr.getChalkboard() != null) {
        mplew.write(1);
        mplew.writeMapleAsciiString(chr.getChalkboard());
    } else {
        mplew.write(0);
    }
    // crush
    addRingLook(mplew, chr, true);
    // friendship
    addRingLook(mplew, chr, false);
    addMarriageRingLook(mplew, chr);
    // new year seems to crash sometimes...
    encodeNewYearCardInfo(mplew, chr);
    mplew.skip(2);
    // only needed in specific fields
    mplew.write(chr.getTeam());
    return mplew.getPacket();
}
Also used : MapleMapItem(server.maps.MapleMapItem) SpecialCashItem(server.CashShop.SpecialCashItem) CashItem(server.CashShop.CashItem) Item(client.inventory.Item) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) MapleShopItem(server.MapleShopItem) MaplePacketLittleEndianWriter(tools.data.output.MaplePacketLittleEndianWriter) MapleGuildSummary(net.server.guild.MapleGuildSummary) MaplePlayerShop(server.maps.MaplePlayerShop) MaplePet(client.inventory.MaplePet) Point(java.awt.Point)

Aggregations

Item (client.inventory.Item)124 MapleMapItem (server.maps.MapleMapItem)33 Equip (client.inventory.Equip)31 ArrayList (java.util.ArrayList)31 MaplePlayerShopItem (server.maps.MaplePlayerShopItem)31 Point (java.awt.Point)29 SQLException (java.sql.SQLException)25 MapleCharacter (client.MapleCharacter)21 MapleInventoryType (client.inventory.MapleInventoryType)20 PreparedStatement (java.sql.PreparedStatement)20 Connection (java.sql.Connection)19 DatabaseConnection (tools.DatabaseConnection)19 MapleInventory (client.inventory.MapleInventory)18 MapleItemInformationProvider (server.MapleItemInformationProvider)18 ResultSet (java.sql.ResultSet)16 Pair (tools.Pair)15 CashItem (server.CashShop.CashItem)13 SpecialCashItem (server.CashShop.SpecialCashItem)12 MapleShopItem (server.MapleShopItem)12 MaplePacketLittleEndianWriter (tools.data.output.MaplePacketLittleEndianWriter)11