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.");
}
}
}
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();
}
}
}
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();
}
}
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();
}
}
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;
}
Aggregations