Search in sources :

Example 11 with MapleItemInformationProvider

use of server.MapleItemInformationProvider in project HeavenMS by ronancpl.

the class MaplePacketCreator method addItemInfo.

private static void addItemInfo(final MaplePacketLittleEndianWriter mplew, Item item, boolean zeroPosition) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    boolean isCash = ii.isCash(item.getItemId());
    boolean isPet = item.getPetId() > -1;
    boolean isRing = false;
    Equip equip = null;
    short pos = item.getPosition();
    byte itemType = item.getItemType();
    if (itemType == 1) {
        equip = (Equip) item;
        isRing = equip.getRingId() > -1;
    }
    if (!zeroPosition) {
        if (equip != null) {
            if (pos < 0) {
                pos *= -1;
            }
            mplew.writeShort(pos > 100 ? pos - 100 : pos);
        } else {
            mplew.write(pos);
        }
    }
    mplew.write(itemType);
    mplew.writeInt(item.getItemId());
    mplew.writeBool(isCash);
    if (isCash) {
        mplew.writeLong(isPet ? item.getPetId() : isRing ? equip.getRingId() : item.getCashId());
    }
    addExpirationTime(mplew, item.getExpiration());
    if (isPet) {
        MaplePet pet = item.getPet();
        mplew.writeAsciiString(StringUtil.getRightPaddedStr(pet.getName(), '\0', 13));
        mplew.write(pet.getLevel());
        mplew.writeShort(pet.getCloseness());
        mplew.write(pet.getFullness());
        addExpirationTime(mplew, item.getExpiration());
        mplew.writeInt(0);
        // wonder what this is
        mplew.write(new byte[] { (byte) 0x50, (byte) 0x46 });
        mplew.writeInt(0);
        return;
    }
    if (equip == null) {
        mplew.writeShort(item.getQuantity());
        mplew.writeMapleAsciiString(item.getOwner());
        // flag
        mplew.writeShort(item.getFlag());
        if (ItemConstants.isRechargable(item.getItemId())) {
            mplew.writeInt(2);
            mplew.write(new byte[] { (byte) 0x54, 0, 0, (byte) 0x34 });
        }
        return;
    }
    // upgrade slots
    mplew.write(equip.getUpgradeSlots());
    // level
    mplew.write(equip.getLevel());
    // str
    mplew.writeShort(equip.getStr());
    // dex
    mplew.writeShort(equip.getDex());
    // int
    mplew.writeShort(equip.getInt());
    // luk
    mplew.writeShort(equip.getLuk());
    // hp
    mplew.writeShort(equip.getHp());
    // mp
    mplew.writeShort(equip.getMp());
    // watk
    mplew.writeShort(equip.getWatk());
    // matk
    mplew.writeShort(equip.getMatk());
    // wdef
    mplew.writeShort(equip.getWdef());
    // mdef
    mplew.writeShort(equip.getMdef());
    // accuracy
    mplew.writeShort(equip.getAcc());
    // avoid
    mplew.writeShort(equip.getAvoid());
    // hands
    mplew.writeShort(equip.getHands());
    // speed
    mplew.writeShort(equip.getSpeed());
    // jump
    mplew.writeShort(equip.getJump());
    // owner name
    mplew.writeMapleAsciiString(equip.getOwner());
    // Item Flags
    mplew.writeShort(equip.getFlag());
    if (isCash) {
        for (int i = 0; i < 10; i++) {
            mplew.write(0x40);
        }
    } else {
        mplew.write(0);
        // Item Level
        mplew.write(equip.getItemLevel());
        mplew.writeShort(0);
        // Works pretty weird :s
        mplew.writeShort(equip.getItemExp());
        // WTF NEXON ARE YOU SERIOUS?
        mplew.writeInt(equip.getVicious());
        mplew.writeLong(0);
    }
    mplew.writeLong(getTime(-2));
    mplew.writeInt(-1);
}
Also used : Equip(client.inventory.Equip) MapleItemInformationProvider(server.MapleItemInformationProvider) MaplePet(client.inventory.MaplePet) Point(java.awt.Point)

Example 12 with MapleItemInformationProvider

use of server.MapleItemInformationProvider in project HeavenMS by ronancpl.

the class ItemRequirement method check.

@Override
public boolean check(MapleCharacter chr, Integer npcid) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    for (Integer itemId : items.keySet()) {
        int countNeeded = items.get(itemId);
        int count = 0;
        MapleInventoryType iType = ItemConstants.getInventoryType(itemId);
        if (iType.equals(MapleInventoryType.UNDEFINED)) {
            return false;
        }
        for (Item item : chr.getInventory(iType).listById(itemId)) {
            count += item.getQuantity();
        }
        // Weird stuff, nexon made some quests only available when wearing gm clothes. This enables us to accept it ><
        if (iType.equals(MapleInventoryType.EQUIP)) {
            if (chr.isGM()) {
                for (Item item : chr.getInventory(MapleInventoryType.EQUIPPED).listById(itemId)) {
                    count += item.getQuantity();
                }
            } else {
                if (count < countNeeded) {
                    if (chr.getInventory(MapleInventoryType.EQUIPPED).countById(itemId) + count >= countNeeded) {
                        chr.dropMessage(5, "Unequip the required " + ii.getName(itemId) + " before trying this quest operation.");
                        return false;
                    }
                }
            }
        }
        if (count < countNeeded || countNeeded <= 0 && count > 0) {
            return false;
        }
    }
    return true;
}
Also used : Item(client.inventory.Item) MapleInventoryType(client.inventory.MapleInventoryType) MapleItemInformationProvider(server.MapleItemInformationProvider)

Example 13 with MapleItemInformationProvider

use of server.MapleItemInformationProvider in project HeavenMS by ronancpl.

the class ReactorActionManager method dropItems.

public void dropItems(boolean delayed, int posX, int posY, boolean meso, int mesoChance, final int minMeso, final int maxMeso, int minItems) {
    if (c.getPlayer() == null)
        return;
    List<ReactorDropEntry> items = generateDropList(getDropChances(), c.getPlayer().getDropRate(), meso, mesoChance, minItems);
    if (items.size() % 2 == 0)
        posX -= 12;
    final Point dropPos = new Point(posX, posY);
    if (!delayed) {
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        byte p = 1;
        for (ReactorDropEntry d : items) {
            dropPos.x = (int) (posX + ((p % 2 == 0) ? (25 * ((p + 1) / 2)) : -(25 * (p / 2))));
            p++;
            if (d.itemId == 0) {
                int range = maxMeso - minMeso;
                int displayDrop = (int) (Math.random() * range) + minMeso;
                int mesoDrop = (displayDrop * client.getWorldServer().getMesoRate());
                reactor.getMap().spawnMesoDrop(mesoDrop, reactor.getMap().calcDropPos(dropPos, reactor.getPosition()), reactor, client.getPlayer(), false, (byte) 2);
            } else {
                Item drop;
                if (ItemConstants.getInventoryType(d.itemId) != MapleInventoryType.EQUIP) {
                    drop = new Item(d.itemId, (short) 0, (short) 1);
                } else {
                    drop = ii.randomizeStats((Equip) ii.getEquipById(d.itemId));
                }
                reactor.getMap().dropFromReactor(getPlayer(), reactor, drop, dropPos, (short) d.questid);
            }
        }
    } else {
        final MapleCharacter chr = client.getPlayer();
        final MapleReactor r = reactor;
        final List<ReactorDropEntry> dropItems = items;
        final int worldMesoRate = client.getWorldServer().getMesoRate();
        dropPos.x -= (12 * items.size());
        sprayTask = TimerManager.getInstance().register(new Runnable() {

            @Override
            public void run() {
                if (dropItems.isEmpty()) {
                    sprayTask.cancel(false);
                    return;
                }
                ReactorDropEntry d = dropItems.remove(0);
                if (d.itemId == 0) {
                    int range = maxMeso - minMeso;
                    int displayDrop = (int) (Math.random() * range) + minMeso;
                    int mesoDrop = (displayDrop * worldMesoRate);
                    r.getMap().spawnMesoDrop(mesoDrop, r.getMap().calcDropPos(dropPos, r.getPosition()), r, chr, false, (byte) 2);
                } else {
                    Item drop;
                    if (ItemConstants.getInventoryType(d.itemId) != MapleInventoryType.EQUIP) {
                        drop = new Item(d.itemId, (short) 0, (short) 1);
                    } else {
                        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
                        drop = ii.randomizeStats((Equip) ii.getEquipById(d.itemId));
                    }
                    r.getMap().dropFromReactor(getPlayer(), r, drop, dropPos, (short) d.questid);
                }
                dropPos.x += 25;
            }
        }, 100);
    }
}
Also used : ReactorDropEntry(server.maps.ReactorDropEntry) Item(client.inventory.Item) Equip(client.inventory.Equip) MapleCharacter(client.MapleCharacter) MapleReactor(server.maps.MapleReactor) MapleItemInformationProvider(server.MapleItemInformationProvider) Point(java.awt.Point) Point(java.awt.Point)

Example 14 with MapleItemInformationProvider

use of server.MapleItemInformationProvider in project HeavenMS by ronancpl.

the class ReactorActionManager method generateDropList.

private static List<ReactorDropEntry> generateDropList(List<ReactorDropEntry> drops, int dropRate, boolean meso, int mesoChance, int minItems) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    List<ReactorDropEntry> items = new ArrayList<>();
    List<ReactorDropEntry> questItems = new ArrayList<>();
    int numItems = 0;
    if (meso && Math.random() < (1 / (double) mesoChance)) {
        items.add(new ReactorDropEntry(0, mesoChance, -1));
    }
    for (ReactorDropEntry mde : drops) {
        if (Math.random() < (dropRate / (double) mde.chance)) {
            if (!ii.isQuestItem(mde.itemId)) {
                items.add(mde);
            } else {
                questItems.add(mde);
            }
            numItems++;
        }
    }
    while (numItems < minItems) {
        items.add(new ReactorDropEntry(0, mesoChance, -1));
        numItems++;
    }
    java.util.Collections.shuffle(items);
    java.util.Collections.shuffle(questItems);
    items.addAll(questItems);
    return items;
}
Also used : ReactorDropEntry(server.maps.ReactorDropEntry) MapleItemInformationProvider(server.MapleItemInformationProvider) ArrayList(java.util.ArrayList) Point(java.awt.Point)

Example 15 with MapleItemInformationProvider

use of server.MapleItemInformationProvider in project HeavenMS by ronancpl.

the class AbstractPlayerInteraction method gainItem.

public Item gainItem(int id, short quantity, boolean randomStats, boolean showMessage, long expires, MaplePet from) {
    Item item = null;
    MaplePet evolved;
    int petId = -1;
    if (quantity >= 0) {
        if (ItemConstants.isPet(id)) {
            petId = MaplePet.createPet(id);
            if (from != null) {
                evolved = MaplePet.loadFromDb(id, (short) 0, petId);
                Point pos = getPlayer().getPosition();
                pos.y -= 12;
                evolved.setPos(pos);
                evolved.setFh(getPlayer().getMap().getFootholds().findBelow(evolved.getPos()).getId());
                evolved.setStance(0);
                evolved.setSummoned(true);
                evolved.setName(from.getName().compareTo(MapleItemInformationProvider.getInstance().getName(from.getItemId())) != 0 ? from.getName() : MapleItemInformationProvider.getInstance().getName(id));
                evolved.setCloseness(from.getCloseness());
                evolved.setFullness(from.getFullness());
                evolved.setLevel(from.getLevel());
                evolved.saveToDb();
            }
        // MapleInventoryManipulator.addById(c, id, (short) 1, null, petId, expires == -1 ? -1 : System.currentTimeMillis() + expires);
        }
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        if (ItemConstants.getInventoryType(id).equals(MapleInventoryType.EQUIP)) {
            item = ii.getEquipById(id);
            if (item != null) {
                Equip it = (Equip) item;
                if (ItemConstants.isAccessory(item.getItemId()) && it.getUpgradeSlots() <= 0)
                    it.setUpgradeSlots(3);
                if (ServerConstants.USE_ENHANCED_CRAFTING == true && c.getPlayer().getCS() == true) {
                    Equip eqp = (Equip) item;
                    if (!(c.getPlayer().isGM() && ServerConstants.USE_PERFECT_GM_SCROLL)) {
                        eqp.setUpgradeSlots((byte) (eqp.getUpgradeSlots() + 1));
                    }
                    item = MapleItemInformationProvider.getInstance().scrollEquipWithId(item, 2049100, true, 2049100, c.getPlayer().isGM());
                }
            }
        } else {
            item = new Item(id, (short) 0, quantity, petId);
        }
        if (expires >= 0)
            item.setExpiration(System.currentTimeMillis() + expires);
        item.setPetId(petId);
        if (!MapleInventoryManipulator.checkSpace(c, id, quantity, "")) {
            c.getPlayer().dropMessage(1, "Your inventory is full. Please remove an item from your " + ItemConstants.getInventoryType(id).name() + " inventory.");
            return null;
        }
        if (ItemConstants.getInventoryType(id) == MapleInventoryType.EQUIP) {
            if (randomStats) {
                item = ii.randomizeStats((Equip) item);
                MapleInventoryManipulator.addFromDrop(c, ii.randomizeStats((Equip) item), false, petId);
            } else {
                MapleInventoryManipulator.addFromDrop(c, (Equip) item, false, petId);
            }
        } else {
            MapleInventoryManipulator.addFromDrop(c, item, false, petId);
        }
    } else {
        MapleInventoryManipulator.removeById(c, ItemConstants.getInventoryType(id), id, -quantity, true, false);
    }
    if (showMessage) {
        c.announce(MaplePacketCreator.getShowItemGain(id, quantity, true));
    }
    return item;
}
Also used : Item(client.inventory.Item) Equip(client.inventory.Equip) MapleItemInformationProvider(server.MapleItemInformationProvider) Point(java.awt.Point) MaplePet(client.inventory.MaplePet) Point(java.awt.Point)

Aggregations

MapleItemInformationProvider (server.MapleItemInformationProvider)26 Item (client.inventory.Item)18 Equip (client.inventory.Equip)10 MapleCharacter (client.MapleCharacter)9 Point (java.awt.Point)9 MapleInventoryType (client.inventory.MapleInventoryType)5 ArrayList (java.util.ArrayList)5 SpawnPoint (server.life.SpawnPoint)5 SQLException (java.sql.SQLException)4 MapleMap (server.maps.MapleMap)4 Skill (client.Skill)3 MapleInventory (client.inventory.MapleInventory)3 MaplePet (client.inventory.MaplePet)3 MapleMonster (server.life.MapleMonster)3 MapleMapItem (server.maps.MapleMapItem)3 MapleMapObject (server.maps.MapleMapObject)3 ScrollResult (client.inventory.Equip.ScrollResult)2 ModifyInventory (client.inventory.ModifyInventory)2 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2