Search in sources :

Example 26 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class TrockAddMapHandler method handlePacket.

public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    byte type = slea.readByte();
    boolean vip = slea.readByte() == 1;
    if (type == 0x00) {
        int mapId = slea.readInt();
        if (vip)
            chr.deleteFromVipTrocks(mapId);
        else
            chr.deleteFromTrocks(mapId);
        c.announce(MaplePacketCreator.trockRefreshMapList(chr, true, vip));
    } else if (type == 0x01) {
        if (!FieldLimit.CANNOTVIPROCK.check(chr.getMap().getFieldLimit())) {
            if (vip)
                chr.addVipTrockMap();
            else
                chr.addTrockMap();
            c.announce(MaplePacketCreator.trockRefreshMapList(chr, false, vip));
        } else {
            chr.message("You may not save this map.");
        }
    }
}
Also used : MapleCharacter(client.MapleCharacter)

Example 27 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class MapleHiredMerchant method buy.

public void buy(MapleClient c, int item, short quantity) {
    synchronized (items) {
        MaplePlayerShopItem pItem = items.get(item);
        Item newItem = pItem.getItem().copy();
        newItem.setQuantity((short) ((pItem.getItem().getQuantity() * quantity)));
        if ((newItem.getFlag() & ItemConstants.KARMA) == ItemConstants.KARMA) {
            newItem.setFlag((byte) (newItem.getFlag() ^ ItemConstants.KARMA));
        }
        if (quantity < 1 || pItem.getBundles() < 1 || !pItem.isExist() || pItem.getBundles() < quantity) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        } else if (newItem.getInventoryType().equals(MapleInventoryType.EQUIP) && newItem.getQuantity() > 1) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        } else if (!pItem.isExist()) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        int price = (int) Math.min((long) pItem.getPrice() * quantity, Integer.MAX_VALUE);
        if (c.getPlayer().getMeso() >= price) {
            if (canBuy(c, newItem)) {
                c.getPlayer().gainMeso(-price, false);
                // idea thanks to vcoc
                announceItemSold(newItem, price);
                synchronized (sold) {
                    sold.add(new SoldItem(c.getPlayer().getName(), pItem.getItem().getItemId(), quantity, price));
                }
                pItem.setBundles((short) (pItem.getBundles() - quantity));
                if (pItem.getBundles() < 1) {
                    pItem.setDoesExist(false);
                }
                MapleCharacter owner = Server.getInstance().getWorld(world).getPlayerStorage().getCharacterByName(ownerName);
                if (owner != null) {
                    owner.addMerchantMesos(price);
                } else {
                    try {
                        Connection con = DatabaseConnection.getConnection();
                        try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET MerchantMesos = MerchantMesos + " + price + " WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
                            ps.setInt(1, ownerId);
                            ps.executeUpdate();
                        }
                        con.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } else {
                c.getPlayer().dropMessage(1, "Your inventory is full. Please clean a slot before buying this item.");
            }
        } else {
            c.getPlayer().dropMessage(1, "You do not have enough mesos.");
        }
        try {
            this.saveItems(false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 28 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class MapleMap method spawnRangedMapObject.

private void spawnRangedMapObject(MapleMapObject mapobject, DelayedPacketCreation packetbakery, SpawnCondition condition) {
    chrRLock.lock();
    try {
        int curOID = getUsableOID();
        mapobject.setObjectId(curOID);
        for (MapleCharacter chr : characters) {
            if (condition == null || condition.canSpawn(chr)) {
                if (chr.getPosition().distanceSq(mapobject.getPosition()) <= getRangedDistance()) {
                    packetbakery.sendPackets(chr.getClient());
                    chr.addVisibleMapObject(mapobject);
                }
            }
        }
    } finally {
        chrRLock.unlock();
    }
}
Also used : MapleCharacter(client.MapleCharacter) Point(java.awt.Point) SpawnPoint(server.life.SpawnPoint)

Example 29 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class MapleMap method updateMonsterController.

/**
 * Automagically finds a new controller for the given monster from the chars
 * on the map...
 *
 * @param monster
 */
public void updateMonsterController(MapleMonster monster) {
    monster.lockMonster();
    try {
        if (!monster.isAlive()) {
            return;
        }
        if (monster.getController() != null) {
            if (monster.getController().getMap() != this) {
                monster.getController().stopControllingMonster(monster);
            } else {
                return;
            }
        }
        int mincontrolled = -1;
        MapleCharacter newController = null;
        chrRLock.lock();
        try {
            for (MapleCharacter chr : characters) {
                if (!chr.isHidden() && (chr.getControlledMonsters().size() < mincontrolled || mincontrolled == -1)) {
                    mincontrolled = chr.getControlledMonsters().size();
                    newController = chr;
                }
            }
        } finally {
            chrRLock.unlock();
        }
        if (newController != null) {
            // was a new controller found? (if not no one is on the map)
            if (monster.isFirstAttack()) {
                newController.controlMonster(monster, true);
                monster.setControllerHasAggro(true);
                monster.setControllerKnowsAboutAggro(true);
            } else {
                newController.controlMonster(monster, false);
            }
        }
    } finally {
        monster.unlockMonster();
    }
}
Also used : MapleCharacter(client.MapleCharacter) Point(java.awt.Point) SpawnPoint(server.life.SpawnPoint)

Example 30 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class MapleMap method getNumPlayersInRect.

public final int getNumPlayersInRect(final Rectangle rect) {
    int ret = 0;
    chrRLock.lock();
    try {
        final Iterator<MapleCharacter> ltr = characters.iterator();
        while (ltr.hasNext()) {
            if (rect.contains(ltr.next().getPosition())) {
                ret++;
            }
        }
    } finally {
        chrRLock.unlock();
    }
    return ret;
}
Also used : MapleCharacter(client.MapleCharacter) Point(java.awt.Point) SpawnPoint(server.life.SpawnPoint)

Aggregations

MapleCharacter (client.MapleCharacter)163 Point (java.awt.Point)32 SQLException (java.sql.SQLException)22 Item (client.inventory.Item)21 Connection (java.sql.Connection)15 PreparedStatement (java.sql.PreparedStatement)15 MapleMonster (server.life.MapleMonster)15 MapleMapObject (server.maps.MapleMapObject)15 DatabaseConnection (tools.DatabaseConnection)15 MapleMap (server.maps.MapleMap)14 ArrayList (java.util.ArrayList)13 Skill (client.Skill)12 SpawnPoint (server.life.SpawnPoint)12 LinkedList (java.util.LinkedList)11 MapleInventory (client.inventory.MapleInventory)10 World (net.server.world.World)10 MapleStatEffect (server.MapleStatEffect)10 MapleInventoryType (client.inventory.MapleInventoryType)9 ResultSet (java.sql.ResultSet)9 MapleItemInformationProvider (server.MapleItemInformationProvider)9