Search in sources :

Example 61 with Item

use of client.inventory.Item 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 62 with Item

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

the class MapleShop method sell.

public void sell(MapleClient c, MapleInventoryType type, short slot, short quantity) {
    if (quantity == 0xFFFF || quantity == 0) {
        quantity = 1;
    }
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    Item item = c.getPlayer().getInventory(type).getItem((short) slot);
    if (item == null) {
        // Basic check
        return;
    }
    if (ItemConstants.isRechargable(item.getItemId())) {
        quantity = item.getQuantity();
    }
    if (quantity < 0) {
        return;
    }
    short iQuant = item.getQuantity();
    if (iQuant == 0xFFFF) {
        iQuant = 1;
    }
    if (quantity <= iQuant && iQuant > 0) {
        MapleInventoryManipulator.removeFromSlot(c, type, (byte) slot, quantity, false);
        double price;
        if (ItemConstants.isRechargable(item.getItemId())) {
            price = ii.getWholePrice(item.getItemId()) / (double) ii.getSlotMax(c, item.getItemId());
        } else {
            price = ii.getPrice(item.getItemId());
        }
        int recvMesos = (int) Math.max(Math.ceil(price * quantity), 0);
        if (price != -1 && recvMesos > 0) {
            c.getPlayer().gainMeso(recvMesos, false);
        }
        c.announce(MaplePacketCreator.shopTransaction((byte) 0x8));
    }
}
Also used : Item(client.inventory.Item)

Example 63 with Item

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

the class MapleShop method recharge.

public void recharge(MapleClient c, short slot) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    Item item = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
    if (item == null || !ItemConstants.isRechargable(item.getItemId())) {
        return;
    }
    short slotMax = ii.getSlotMax(c, item.getItemId());
    if (item.getQuantity() < 0) {
        return;
    }
    if (item.getQuantity() < slotMax) {
        int price = (int) Math.round(ii.getPrice(item.getItemId()) * (slotMax - item.getQuantity()));
        if (c.getPlayer().getMeso() >= price) {
            item.setQuantity(slotMax);
            c.getPlayer().forceUpdateItem(item);
            c.getPlayer().gainMeso(-price, false, true, false);
            c.announce(MaplePacketCreator.shopTransaction((byte) 0x8));
        } else {
            c.announce(MaplePacketCreator.serverNotice(1, "You do not have enough mesos."));
            c.announce(MaplePacketCreator.enableActions());
        }
    }
}
Also used : Item(client.inventory.Item)

Example 64 with Item

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

the class MapleStatEffect method applyTo.

// primary: the player caster of the buff
private boolean applyTo(MapleCharacter applyfrom, MapleCharacter applyto, boolean primary, Point pos, boolean useMaxRange) {
    if (skill && (sourceid == GM.HIDE || sourceid == SuperGM.HIDE)) {
        applyto.toggleHide(false);
        return true;
    }
    int hpchange = calcHPChange(applyfrom, primary);
    int mpchange = calcMPChange(applyfrom, primary);
    if (primary) {
        if (itemConNo != 0) {
            if (!applyto.getClient().getAbstractPlayerInteraction().hasItem(itemCon, itemConNo)) {
                applyto.getClient().announce(MaplePacketCreator.enableActions());
                return false;
            }
            MapleInventoryManipulator.removeById(applyto.getClient(), ItemConstants.getInventoryType(itemCon), itemCon, itemConNo, false, true);
        }
    }
    List<Pair<MapleStat, Integer>> hpmpupdate = new ArrayList<>(2);
    if (!primary) {
        if (isResurrection()) {
            hpchange = applyto.getMaxHp();
            applyto.setStance(0);
            applyto.getMap().broadcastMessage(applyto, MaplePacketCreator.removePlayerFromMap(applyto.getId()), false);
            applyto.getMap().broadcastMessage(applyto, MaplePacketCreator.spawnPlayerMapObject(applyto), false);
        }
    }
    if (isDispel() && makeChanceResult()) {
        applyto.dispelDebuffs();
    } else if (isCureAllAbnormalStatus()) {
        applyto.dispelDebuff(MapleDisease.SEDUCE);
        applyto.dispelDebuff(MapleDisease.ZOMBIFY);
        applyto.dispelDebuffs();
    } else if (isComboReset()) {
        applyto.setCombo((short) 0);
    }
    /*if (applyfrom.getMp() < getMpCon()) {
         AutobanFactory.MPCON.addPoint(applyfrom.getAutobanManager(), "mpCon hack for skill:" + sourceid + "; Player MP: " + applyto.getMp() + " MP Needed: " + getMpCon());
         } */
    if (hpchange != 0) {
        if (hpchange < 0 && (-hpchange) >= applyto.getHp() && (!applyto.hasDisease(MapleDisease.ZOMBIFY) || hpCon > 0)) {
            if (!applyto.isGM()) {
                applyto.getClient().announce(MaplePacketCreator.enableActions());
                return false;
            }
        }
        int newHp = applyto.getHp() + hpchange;
        if (newHp < 1) {
            newHp = 1;
        }
        applyto.setHp(newHp);
        hpmpupdate.add(new Pair<>(MapleStat.HP, Integer.valueOf(applyto.getHp())));
    }
    int newMp = applyto.getMp() + mpchange;
    if (mpchange != 0) {
        if (mpchange < 0 && -mpchange > applyto.getMp()) {
            if (!applyto.isGM()) {
                applyto.getClient().announce(MaplePacketCreator.enableActions());
                return false;
            } else {
                newMp = 0;
            }
        }
        applyto.setMp(newMp);
        hpmpupdate.add(new Pair<>(MapleStat.MP, Integer.valueOf(applyto.getMp())));
    }
    applyto.getClient().announce(MaplePacketCreator.updatePlayerStats(hpmpupdate, true, applyto));
    if (moveTo != -1) {
        if (moveTo != applyto.getMapId()) {
            MapleMap target;
            MaplePortal pt;
            if (moveTo == 999999999) {
                if (sourceid != 2030100) {
                    target = applyto.getMap().getReturnMap();
                    pt = target.getRandomPlayerSpawnpoint();
                } else {
                    if (!applyto.canRecoverLastBanish())
                        return false;
                    Pair<Integer, Integer> lastBanishInfo = applyto.getLastBanishData();
                    target = applyto.getWarpMap(lastBanishInfo.getLeft());
                    pt = target.getPortal(lastBanishInfo.getRight());
                }
            } else {
                target = applyto.getClient().getWorldServer().getChannel(applyto.getClient().getChannel()).getMapFactory().getMap(moveTo);
                int targetid = target.getId() / 10000000;
                if (targetid != 60 && applyto.getMapId() / 10000000 != 61 && targetid != applyto.getMapId() / 10000000 && targetid != 21 && targetid != 20 && targetid != 12 && (applyto.getMapId() / 10000000 != 10 && applyto.getMapId() / 10000000 != 12)) {
                    return false;
                }
                pt = target.getRandomPlayerSpawnpoint();
            }
            applyto.changeMap(target, pt);
        } else {
            return false;
        }
    }
    if (isShadowClaw()) {
        int projectile = 0;
        MapleInventory use = applyto.getInventory(MapleInventoryType.USE);
        for (int i = 1; i <= use.getSlotLimit(); i++) {
            // impose order...
            Item item = use.getItem((short) i);
            if (item != null) {
                if (ItemConstants.isThrowingStar(item.getItemId()) && item.getQuantity() >= 200) {
                    projectile = item.getItemId();
                    break;
                }
            }
        }
        if (projectile == 0) {
            return false;
        } else {
            MapleInventoryManipulator.removeById(applyto.getClient(), MapleInventoryType.USE, projectile, 200, false, true);
        }
    }
    SummonMovementType summonMovementType = getSummonMovementType();
    if (overTime || isCygnusFA() || summonMovementType != null) {
        if (summonMovementType != null && pos != null) {
            if (summonMovementType.getValue() == summonMovementType.STATIONARY.getValue())
                applyto.cancelBuffStats(MapleBuffStat.PUPPET);
            else
                applyto.cancelBuffStats(MapleBuffStat.SUMMON);
        }
        applyBuffEffect(applyfrom, applyto, primary);
    }
    if (primary && (overTime || isHeal())) {
        applyBuff(applyfrom, useMaxRange);
    }
    if (primary && isMonsterBuff()) {
        applyMonsterBuff(applyfrom);
    }
    if (this.getFatigue() != 0) {
        applyto.getMount().setTiredness(applyto.getMount().getTiredness() + this.getFatigue());
    }
    if (summonMovementType != null && pos != null) {
        final MapleSummon tosummon = new MapleSummon(applyfrom, sourceid, pos, summonMovementType);
        applyfrom.getMap().spawnSummon(tosummon);
        applyfrom.addSummon(sourceid, tosummon);
        tosummon.addHP(x);
        if (isBeholder()) {
            tosummon.addHP(1);
        }
    }
    if (isMagicDoor() && !FieldLimit.DOOR.check(applyto.getMap().getFieldLimit())) {
        // Magic Door
        int y = applyto.getFh();
        if (y == 0) {
            y = applyto.getPosition().y;
        }
        Point doorPosition = new Point(applyto.getPosition().x, y);
        MapleDoor door = new MapleDoor(applyto, doorPosition);
        if (door.getOwnerId() >= 0) {
            if (applyto.getParty() != null) {
                for (MaplePartyCharacter partyMember : applyto.getParty().getMembers()) {
                    partyMember.getPlayer().addDoor(door.getOwnerId(), door);
                    partyMember.addDoor(door.getOwnerId(), door);
                }
                applyto.silentPartyUpdate();
            } else {
                applyto.addDoor(door.getOwnerId(), door);
            }
            door.getTarget().spawnDoor(door.getAreaDoor());
            door.getTown().spawnDoor(door.getTownDoor());
            applyto.disableDoorSpawn();
        } else {
            MapleInventoryManipulator.addFromDrop(applyto.getClient(), new Item(4006000, (short) 0, (short) 1), false);
            if (door.getOwnerId() == -3)
                applyto.dropMessage(5, "Mystic Door cannot be cast far from a spawn point. Nearest one is at " + door.getDoorStatus().getRight() + "pts " + door.getDoorStatus().getLeft());
            else if (door.getOwnerId() == -2)
                applyto.dropMessage(5, "Mystic Door cannot be cast on a slope, try elsewhere.");
            else
                applyto.dropMessage(5, "There are no door portals available for the town at this moment. Try again later.");
            // cancel door buff
            applyto.cancelBuffStats(MapleBuffStat.SOULARROW);
        }
    } else if (isMist()) {
        Rectangle bounds = calculateBoundingBox(sourceid == NightWalker.POISON_BOMB ? pos : applyfrom.getPosition(), applyfrom.isFacingLeft());
        MapleMist mist = new MapleMist(bounds, applyfrom, this);
        applyfrom.getMap().spawnMist(mist, getDuration(), mist.isPoisonMist(), false, mist.isRecoveryMist());
    } else if (isTimeLeap()) {
        applyto.removeAllCooldownsExcept(Buccaneer.TIME_LEAP, true);
    } else if (isHyperBody() && !primary) {
        applyto.getMap().broadcastMessage(applyto, MaplePacketCreator.removePlayerFromMap(applyto.getId()), false);
        applyto.getMap().broadcastMessage(applyto, MaplePacketCreator.spawnPlayerMapObject(applyto), false);
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) Point(java.awt.Point) MapleInventory(client.inventory.MapleInventory) Point(java.awt.Point) MapleMap(server.maps.MapleMap) Item(client.inventory.Item) MapleMist(server.maps.MapleMist) MapleSummon(server.maps.MapleSummon) Pair(tools.Pair) SummonMovementType(server.maps.SummonMovementType) MapleDoor(server.maps.MapleDoor) MaplePartyCharacter(net.server.world.MaplePartyCharacter)

Example 65 with Item

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

the class MapleStorageInventory method PartitionByQuantity.

private void PartitionByQuantity(int Esq, int Dir, ArrayList<Item> A) {
    Item x, w;
    i = Esq;
    j = Dir;
    x = A.get((i + j) / 2);
    do {
        while (x.getQuantity() > A.get(i).getQuantity()) i++;
        while (x.getQuantity() < A.get(j).getQuantity()) j--;
        if (i <= j) {
            w = A.get(i);
            A.set(i, A.get(j));
            A.set(j, w);
            i++;
            j--;
        }
    } while (i <= j);
}
Also used : Item(client.inventory.Item)

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