use of server.maps.MapleMapObject in project HeavenMS by ronancpl.
the class DamageSummonHandler method handlePacket.
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int oid = slea.readInt();
// -1
slea.skip(1);
int damage = slea.readInt();
int monsterIdFrom = slea.readInt();
MapleCharacter player = c.getPlayer();
MapleMapObject mmo = player.getMap().getMapObject(oid);
if (mmo != null && mmo instanceof MapleSummon) {
MapleSummon summon = (MapleSummon) mmo;
summon.addHP(-damage);
if (summon.getHP() <= 0) {
player.cancelEffectFromBuffStat(MapleBuffStat.PUPPET);
}
player.getMap().broadcastMessage(player, MaplePacketCreator.damageSummon(player.getId(), oid, damage, monsterIdFrom), summon.getPosition());
}
}
use of server.maps.MapleMapObject in project HeavenMS by ronancpl.
the class PetLootHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
if (System.currentTimeMillis() - chr.getPetLootCd() < ServerConstants.PET_LOOT_UPON_ATTACK) {
c.announce(MaplePacketCreator.enableActions());
return;
}
int petIndex = chr.getPetIndex(slea.readInt());
MaplePet pet = chr.getPet(petIndex);
if (pet == null || !pet.isSummoned()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
slea.skip(13);
int oid = slea.readInt();
MapleMapObject ob = chr.getMap().getMapObject(oid);
if (ob == null) {
c.getSession().write(MaplePacketCreator.enableActions());
return;
}
if (chr.getInventory(MapleInventoryType.EQUIPPED).findById(1812007) != null) {
final Set<Integer> petIgnore = chr.getExcludedItems();
MapleMapItem mapitem = (MapleMapItem) ob;
if (!petIgnore.isEmpty()) {
if (chr.getInventory(MapleInventoryType.EQUIPPED).findById(1812000) != null) {
// Meso magnet
if (mapitem.getMeso() > 0 && petIgnore.contains(Integer.MAX_VALUE)) {
c.getSession().write(MaplePacketCreator.enableActions());
return;
}
} else if (chr.getInventory(MapleInventoryType.EQUIPPED).findById(1812001) != null) {
// Item Pouch
if (petIgnore.contains(mapitem.getItem().getItemId())) {
c.getSession().write(MaplePacketCreator.enableActions());
return;
}
}
}
}
chr.pickupItem(ob, petIndex);
}
use of server.maps.MapleMapObject in project HeavenMS by ronancpl.
the class PlayerInteractionHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
byte mode = slea.readByte();
MapleCharacter chr = c.getPlayer();
if (mode == Action.CREATE.getCode()) {
byte createType = slea.readByte();
if (createType == 3) {
// trade
MapleTrade.startTrade(chr);
} else if (createType == 1) {
// omok mini game
if (chr.getChalkboard() != null || FieldLimit.CANNOTMINIGAME.check(chr.getMap().getFieldLimit())) {
return;
}
String desc = slea.readMapleAsciiString();
// 20 6E 4E
slea.readByte();
// 20 6E 4E
int type = slea.readByte();
MapleMiniGame game = new MapleMiniGame(chr, desc);
chr.setMiniGame(game);
game.setPieceType(type);
game.setGameType("omok");
chr.getMap().addMapObject(game);
chr.getMap().broadcastMessage(MaplePacketCreator.addOmokBox(chr, 1, 0));
game.sendOmok(c, type);
} else if (createType == 2) {
// matchcard
if (chr.getChalkboard() != null) {
return;
}
String desc = slea.readMapleAsciiString();
// 20 6E 4E
slea.readByte();
// 20 6E 4E
int type = slea.readByte();
MapleMiniGame game = new MapleMiniGame(chr, desc);
game.setPieceType(type);
if (type == 0) {
game.setMatchesToWin(6);
} else if (type == 1) {
game.setMatchesToWin(10);
} else if (type == 2) {
game.setMatchesToWin(15);
}
game.setGameType("matchcard");
chr.setMiniGame(game);
chr.getMap().addMapObject(game);
chr.getMap().broadcastMessage(MaplePacketCreator.addMatchCardBox(chr, 1, 0));
game.sendMatchCard(c, type);
} else if (createType == 4 || createType == 5) {
// shop
if (!chr.getMap().getMapObjectsInRange(chr.getPosition(), 23000, Arrays.asList(MapleMapObjectType.SHOP, MapleMapObjectType.HIRED_MERCHANT)).isEmpty()) {
return;
}
String desc = slea.readMapleAsciiString();
slea.skip(3);
int itemId = slea.readInt();
if (chr.getInventory(MapleInventoryType.CASH).countById(itemId) < 1) {
return;
}
if (GameConstants.isFreeMarketRoom(chr.getMapId()) || itemId > 5030000 && itemId < 5030012 || itemId > 5140000 && itemId < 5140006) {
if (createType == 4) {
MaplePlayerShop shop = new MaplePlayerShop(c.getPlayer(), desc);
chr.setPlayerShop(shop);
chr.getMap().addMapObject(shop);
shop.sendShop(c);
c.getWorldServer().registerPlayerShop(shop);
// c.announce(MaplePacketCreator.getPlayerShopRemoveVisitor(1));
} else {
MapleHiredMerchant merchant = new MapleHiredMerchant(chr, itemId, desc);
chr.setHiredMerchant(merchant);
c.getWorldServer().registerHiredMerchant(merchant);
chr.getClient().getChannelServer().addHiredMerchant(chr.getId(), merchant);
chr.announce(MaplePacketCreator.getHiredMerchant(chr, merchant, true));
}
}
}
} else if (mode == Action.INVITE.getCode()) {
int otherPlayer = slea.readInt();
if (chr.getId() == chr.getMap().getCharacterById(otherPlayer).getId()) {
return;
}
MapleTrade.inviteTrade(chr, chr.getMap().getCharacterById(otherPlayer));
} else if (mode == Action.DECLINE.getCode()) {
MapleTrade.declineTrade(chr);
} else if (mode == Action.VISIT.getCode()) {
if (chr.getTrade() != null && chr.getTrade().getPartner() != null) {
if (!chr.getTrade().isFullTrade() && !chr.getTrade().getPartner().isFullTrade()) {
MapleTrade.visitTrade(chr, chr.getTrade().getPartner().getChr());
} else {
// Ill be nice and not dc u
c.announce(MaplePacketCreator.enableActions());
return;
}
} else {
int oid = slea.readInt();
MapleMapObject ob = chr.getMap().getMapObject(oid);
if (ob instanceof MaplePlayerShop) {
MaplePlayerShop shop = (MaplePlayerShop) ob;
shop.visitShop(chr);
} else if (ob instanceof MapleMiniGame) {
MapleMiniGame game = (MapleMiniGame) ob;
if (game.hasFreeSlot() && !game.isVisitor(c.getPlayer())) {
game.addVisitor(c.getPlayer());
chr.setMiniGame(game);
switch(game.getGameType()) {
case "omok":
game.sendOmok(c, game.getPieceType());
break;
case "matchcard":
game.sendMatchCard(c, game.getPieceType());
break;
}
} else {
chr.getClient().announce(MaplePacketCreator.getMiniGameFull());
}
} else if (ob instanceof MapleHiredMerchant && chr.getHiredMerchant() == null) {
MapleHiredMerchant merchant = (MapleHiredMerchant) ob;
if (merchant.isOwner(c.getPlayer())) {
merchant.setOpen(false);
merchant.removeAllVisitors();
c.announce(MaplePacketCreator.getHiredMerchant(chr, merchant, false));
} else if (!merchant.isOpen()) {
c.announce(MaplePacketCreator.hiredMerchantMaintenanceMessage());
return;
} else if (!merchant.addVisitor(c.getPlayer())) {
chr.dropMessage(1, "This shop has reached it's maximum capacity, please come by later.");
return;
} else {
c.announce(MaplePacketCreator.getHiredMerchant(c.getPlayer(), merchant, false));
}
chr.setHiredMerchant(merchant);
}
}
} else if (mode == Action.CHAT.getCode()) {
// chat lol
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (chr.getTrade() != null) {
chr.getTrade().chat(slea.readMapleAsciiString());
} else if (chr.getPlayerShop() != null) {
// mini game
MaplePlayerShop shop = chr.getPlayerShop();
if (shop != null) {
shop.chat(c, slea.readMapleAsciiString());
}
} else if (chr.getMiniGame() != null) {
MapleMiniGame game = chr.getMiniGame();
if (game != null) {
game.chat(c, slea.readMapleAsciiString());
}
} else if (merchant != null) {
merchant.sendMessage(c.getPlayer(), slea.readMapleAsciiString());
}
} else if (mode == Action.EXIT.getCode()) {
if (chr.getTrade() != null) {
MapleTrade.cancelTrade(c.getPlayer());
} else {
chr.closePlayerShop();
chr.closeMiniGame();
chr.closeHiredMerchant(true);
}
} else if (mode == Action.OPEN.getCode()) {
MaplePlayerShop shop = chr.getPlayerShop();
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (shop != null && shop.isOwner(c.getPlayer())) {
// 01
slea.readByte();
if (ServerConstants.USE_ERASE_PERMIT_ON_OPENSHOP) {
try {
MapleInventoryManipulator.removeById(c, MapleInventoryType.CASH, 5140000, 1, true, false);
}// fella does not have a player shop permit...
catch (RuntimeException re) {
}
}
chr.getMap().broadcastMessage(MaplePacketCreator.addCharBox(c.getPlayer(), 4));
shop.setOpen(true);
} else if (merchant != null && merchant.isOwner(c.getPlayer())) {
chr.setHasMerchant(true);
merchant.setOpen(true);
chr.getMap().addMapObject(merchant);
chr.setHiredMerchant(null);
chr.getMap().broadcastMessage(MaplePacketCreator.spawnHiredMerchant(merchant));
slea.readByte();
}
} else if (mode == Action.READY.getCode()) {
MapleMiniGame game = chr.getMiniGame();
game.broadcast(MaplePacketCreator.getMiniGameReady(game));
} else if (mode == Action.UN_READY.getCode()) {
MapleMiniGame game = chr.getMiniGame();
game.broadcast(MaplePacketCreator.getMiniGameUnReady(game));
} else if (mode == Action.START.getCode()) {
MapleMiniGame game = chr.getMiniGame();
if (game.getGameType().equals("omok")) {
game.broadcast(MaplePacketCreator.getMiniGameStart(game, game.getLoser()));
chr.getMap().broadcastMessage(MaplePacketCreator.addOmokBox(game.getOwner(), 2, 1));
}
if (game.getGameType().equals("matchcard")) {
game.shuffleList();
game.broadcast(MaplePacketCreator.getMatchCardStart(game, game.getLoser()));
chr.getMap().broadcastMessage(MaplePacketCreator.addMatchCardBox(game.getOwner(), 2, 1));
}
} else if (mode == Action.GIVE_UP.getCode()) {
MapleMiniGame game = chr.getMiniGame();
if (game.getGameType().equals("omok")) {
if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMiniGameOwnerForfeit(game));
} else {
game.broadcast(MaplePacketCreator.getMiniGameVisitorForfeit(game));
}
}
if (game.getGameType().equals("matchcard")) {
if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMatchCardVisitorWin(game));
} else {
game.broadcast(MaplePacketCreator.getMatchCardOwnerWin(game));
}
}
} else if (mode == Action.REQUEST_TIE.getCode()) {
MapleMiniGame game = chr.getMiniGame();
if (game.isOwner(c.getPlayer())) {
game.broadcastToVisitor(MaplePacketCreator.getMiniGameRequestTie(game));
} else {
game.getOwner().getClient().announce(MaplePacketCreator.getMiniGameRequestTie(game));
}
} else if (mode == Action.ANSWER_TIE.getCode()) {
MapleMiniGame game = chr.getMiniGame();
slea.readByte();
if (game.getGameType().equals("omok")) {
game.broadcast(MaplePacketCreator.getMiniGameTie(game));
}
if (game.getGameType().equals("matchcard")) {
game.broadcast(MaplePacketCreator.getMatchCardTie(game));
}
} else if (mode == Action.SKIP.getCode()) {
MapleMiniGame game = chr.getMiniGame();
if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMiniGameSkipOwner(game));
} else {
game.broadcast(MaplePacketCreator.getMiniGameSkipVisitor(game));
}
} else if (mode == Action.MOVE_OMOK.getCode()) {
// x point
int x = slea.readInt();
// y point
int y = slea.readInt();
// piece ( 1 or 2; Owner has one piece, visitor has another, it switches every game.)
int type = slea.readByte();
chr.getMiniGame().setPiece(x, y, type, c.getPlayer());
} else if (mode == Action.SELECT_CARD.getCode()) {
// 1st turn = 1; 2nd turn = 0
int turn = slea.readByte();
// slot
int slot = slea.readByte();
MapleMiniGame game = chr.getMiniGame();
int firstslot = game.getFirstSlot();
if (turn == 1) {
game.setFirstSlot(slot);
if (game.isOwner(c.getPlayer())) {
game.broadcastToVisitor(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, turn));
} else {
game.getOwner().getClient().announce(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, turn));
}
} else if ((game.getCardId(firstslot + 1)) == (game.getCardId(slot + 1))) {
if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 2));
game.setOwnerPoints();
} else {
game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 3));
game.setVisitorPoints();
}
} else if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 0));
} else {
game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 1));
}
} else if (mode == Action.SET_MESO.getCode()) {
chr.getTrade().setMeso(slea.readInt());
} else if (mode == Action.SET_ITEMS.getCode()) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
MapleInventoryType ivType = MapleInventoryType.getByType(slea.readByte());
Item item = chr.getInventory(ivType).getItem(slea.readShort());
short quantity = slea.readShort();
byte targetSlot = slea.readByte();
if (quantity < 1 || quantity > item.getQuantity()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (chr.getTrade() != null) {
if ((quantity <= item.getQuantity() && quantity >= 0) || ItemConstants.isRechargable(item.getItemId())) {
if (ii.isDropRestricted(item.getItemId())) {
// ensure that undroppable items do not make it to the trade window
if (!((item.getFlag() & ItemConstants.KARMA) == ItemConstants.KARMA)) {
c.announce(MaplePacketCreator.enableActions());
return;
}
}
Item tradeItem = item.copy();
if (ItemConstants.isRechargable(item.getItemId())) {
tradeItem.setQuantity(item.getQuantity());
MapleInventoryManipulator.removeFromSlot(c, ivType, item.getPosition(), item.getQuantity(), true);
} else {
tradeItem.setQuantity(quantity);
MapleInventoryManipulator.removeFromSlot(c, ivType, item.getPosition(), quantity, true);
}
tradeItem.setPosition(targetSlot);
chr.getTrade().addItem(tradeItem);
}
}
} else if (mode == Action.CONFIRM.getCode()) {
MapleTrade.completeTrade(c.getPlayer());
} else if (mode == Action.ADD_ITEM.getCode() || mode == Action.PUT_ITEM.getCode()) {
MapleInventoryType ivType = MapleInventoryType.getByType(slea.readByte());
short slot = slea.readShort();
short bundles = slea.readShort();
if (chr.getInventory(ivType).getItem(slot) == null || chr.getItemQuantity(chr.getInventory(ivType).getItem(slot).getItemId(), false) < bundles || chr.getInventory(ivType).getItem(slot).getFlag() == ItemConstants.UNTRADEABLE) {
return;
}
short perBundle = slea.readShort();
int price = slea.readInt();
if (perBundle <= 0 || perBundle * bundles > 2000 || bundles <= 0 || price <= 0 || price > Integer.MAX_VALUE) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with hired merchants.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " might of possibly packet edited Hired Merchants\nperBundle: " + perBundle + "\nperBundle * bundles (This multiplied cannot be greater than 2000): " + perBundle * bundles + "\nbundles: " + bundles + "\nprice: " + price);
return;
}
Item ivItem = chr.getInventory(ivType).getItem(slot);
Item sellItem = ivItem.copy();
if (chr.getItemQuantity(ivItem.getItemId(), false) < perBundle * bundles) {
return;
} else if (ServerConstants.USE_ENFORCE_UNMERCHABLE_PET && ItemConstants.isPet(ivItem.getItemId())) {
c.announce(MaplePacketCreator.serverNotice(1, "Pets are not allowed to be sold on the Player Shop."));
return;
}
sellItem.setQuantity(perBundle);
MaplePlayerShopItem shopItem = new MaplePlayerShopItem(sellItem, bundles, price);
MaplePlayerShop shop = chr.getPlayerShop();
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (shop != null && shop.isOwner(c.getPlayer())) {
if (ivItem != null && ivItem.getQuantity() >= bundles * perBundle) {
shop.addItem(shopItem);
c.announce(MaplePacketCreator.getPlayerShopItemUpdate(shop));
}
} else if (merchant != null && merchant.isOwner(c.getPlayer())) {
merchant.addItem(shopItem);
c.announce(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
}
if (ItemConstants.isRechargable(ivItem.getItemId())) {
MapleInventoryManipulator.removeFromSlot(c, ivType, slot, ivItem.getQuantity(), true);
} else {
MapleInventoryManipulator.removeFromSlot(c, ivType, slot, (short) (bundles * perBundle), true);
}
} else if (mode == Action.REMOVE_ITEM.getCode()) {
MaplePlayerShop shop = chr.getPlayerShop();
if (shop != null && shop.isOwner(c.getPlayer())) {
int slot = slea.readShort();
if (slot >= shop.getItems().size() || slot < 0) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with a player shop.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to remove item at slot " + slot + "\r\n");
c.disconnect(true, false);
return;
}
MaplePlayerShopItem shopItem = shop.getItems().get(slot);
Item ivItem = shopItem.getItem().copy();
shop.removeItem(slot);
ivItem.setQuantity(shopItem.getBundles());
MapleInventoryManipulator.addFromDrop(c, ivItem, false);
c.announce(MaplePacketCreator.getPlayerShopItemUpdate(shop));
}
} else if (mode == Action.MERCHANT_MESO.getCode()) {
// Hmmmm
/*if (!chr.getHiredMerchant().isOwner(chr) || chr.getMerchantMeso() < 1) return;
int possible = Integer.MAX_VALUE - chr.getMerchantMeso();
if (possible > 0) {
if (possible < chr.getMerchantMeso()) {
chr.gainMeso(possible, false);
chr.setMerchantMeso(chr.getMerchantMeso() - possible);
} else {
chr.gainMeso(chr.getMerchantMeso(), false);
chr.setMerchantMeso(0);
}
c.announce(MaplePacketCreator.updateHiredMerchant(chr.getHiredMerchant(), chr));
}*/
} else if (mode == Action.MERCHANT_ORGANIZE.getCode()) {
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (!merchant.isOwner(chr))
return;
if (chr.getMerchantMeso() > 0) {
int possible = Integer.MAX_VALUE - chr.getMerchantMeso();
if (possible > 0) {
if (possible < chr.getMerchantMeso()) {
chr.gainMeso(possible, false);
chr.setMerchantMeso(chr.getMerchantMeso() - possible);
} else {
chr.gainMeso(chr.getMerchantMeso(), false);
chr.setMerchantMeso(0);
}
}
}
for (int i = 0; i < merchant.getItems().size(); i++) {
if (!merchant.getItems().get(i).isExist())
merchant.removeFromSlot(i);
}
if (merchant.getItems().isEmpty()) {
c.announce(MaplePacketCreator.hiredMerchantOwnerLeave());
c.announce(MaplePacketCreator.leaveHiredMerchant(0x00, 0x03));
merchant.closeShop(c, false);
chr.setHasMerchant(false);
return;
}
c.announce(MaplePacketCreator.updateHiredMerchant(merchant, chr));
} else if (mode == Action.BUY.getCode() || mode == Action.MERCHANT_BUY.getCode()) {
int itemid = slea.readByte();
short quantity = slea.readShort();
if (quantity < 1) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with a hired merchant and or player shop.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to buy item " + itemid + " with quantity " + quantity + "\r\n");
c.disconnect(true, false);
return;
}
MaplePlayerShop shop = chr.getPlayerShop();
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (shop != null && shop.isVisitor(c.getPlayer())) {
shop.buy(c, itemid, quantity);
shop.broadcast(MaplePacketCreator.getPlayerShopItemUpdate(shop));
} else if (merchant != null && !merchant.isOwner(chr)) {
merchant.buy(c, itemid, quantity);
merchant.broadcastToVisitorsThreadsafe(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
}
} else if (mode == Action.TAKE_ITEM_BACK.getCode()) {
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (merchant != null && merchant.isOwner(c.getPlayer())) {
int slot = slea.readShort();
MaplePlayerShopItem shopItem = merchant.getItems().get(slot);
if (!MapleInventory.checkSpot(chr, shopItem.getItem())) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (shopItem.getBundles() > 0) {
Item iitem = shopItem.getItem();
iitem.setQuantity((short) (shopItem.getItem().getQuantity() * shopItem.getBundles()));
MapleInventoryManipulator.addFromDrop(c, iitem, true);
}
merchant.removeFromSlot(slot);
c.announce(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
}
} else if (mode == Action.CLOSE_MERCHANT.getCode()) {
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (merchant != null && merchant.isOwner(c.getPlayer())) {
c.announce(MaplePacketCreator.hiredMerchantOwnerLeave());
c.announce(MaplePacketCreator.leaveHiredMerchant(0x00, 0x03));
merchant.closeShop(c, false);
chr.setHasMerchant(false);
}
} else if (mode == Action.MAINTENANCE_OFF.getCode()) {
MapleHiredMerchant merchant = chr.getHiredMerchant();
if (merchant != null) {
if (merchant.getItems().isEmpty() && merchant.isOwner(c.getPlayer())) {
merchant.closeShop(c, false);
chr.setHasMerchant(false);
}
if (merchant.isOwner(c.getPlayer())) {
merchant.clearMessages();
merchant.setOpen(true);
}
}
chr.setHiredMerchant(null);
c.announce(MaplePacketCreator.enableActions());
} else if (mode == Action.BAN_PLAYER.getCode()) {
slea.skip(1);
if (chr.getPlayerShop() != null && chr.getPlayerShop().isOwner(c.getPlayer())) {
chr.getPlayerShop().banPlayer(slea.readMapleAsciiString());
}
}
}
use of server.maps.MapleMapObject in project HeavenMS by ronancpl.
the class TakeDamageHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
List<MapleCharacter> banishPlayers = new ArrayList<>();
MapleCharacter chr = c.getPlayer();
slea.readInt();
byte damagefrom = slea.readByte();
// Element
slea.readByte();
int damage = slea.readInt();
int oid = 0, monsteridfrom = 0, pgmr = 0, direction = 0;
int pos_x = 0, pos_y = 0, fake = 0;
boolean is_pgmr = false, is_pg = true, is_deadly = false;
int mpattack = 0;
MapleMonster attacker = null;
final MapleMap map = chr.getMap();
if (damagefrom != -3 && damagefrom != -4) {
monsteridfrom = slea.readInt();
oid = slea.readInt();
try {
MapleMapObject mmo = map.getMapObject(oid);
if (mmo instanceof MapleMonster) {
attacker = (MapleMonster) mmo;
if (attacker.getId() != monsteridfrom) {
attacker = null;
}
}
if (attacker != null) {
List<loseItem> loseItems;
if (attacker.isBuffed(MonsterStatus.NEUTRALISE)) {
return;
}
if (damage > 0) {
MapleMonster assaulter = map.getMonsterById(monsteridfrom);
if (assaulter != null) {
loseItems = assaulter.getStats().loseItem();
if (loseItems != null) {
MapleInventoryType type;
final int playerpos = chr.getPosition().x;
byte d = 1;
Point pos = new Point(0, chr.getPosition().y);
for (loseItem loseItem : loseItems) {
type = ItemConstants.getInventoryType(loseItem.getId());
for (byte b = 0; b < loseItem.getX(); b++) {
// LOL?
if (Randomizer.nextInt(101) >= loseItem.getChance()) {
if (chr.haveItem(loseItem.getId())) {
pos.x = (int) (playerpos + ((d % 2 == 0) ? (25 * (d + 1) / 2) : -(25 * (d / 2))));
MapleInventoryManipulator.removeById(c, type, loseItem.getId(), 1, false, false);
map.spawnItemDrop(chr, chr, new Item(loseItem.getId(), (short) 0, (short) 1), map.calcDropPos(pos, chr.getPosition()), true, true);
d++;
} else {
break;
}
}
}
}
map.removeMapObject(attacker);
}
}
}
} else {
return;
}
} catch (ClassCastException e) {
// this happens due to mob on last map damaging player just before changing maps
e.printStackTrace();
FilePrinter.printError(FilePrinter.EXCEPTION_CAUGHT, "Attacker is not a mob-type, rather is a " + map.getMapObject(oid).getClass().getName() + " entity.");
return;
}
direction = slea.readByte();
}
if (damagefrom != -1 && damagefrom != -2 && attacker != null) {
MobAttackInfo attackInfo = MobAttackInfoFactory.getMobAttackInfo(attacker, damagefrom);
if (attackInfo != null) {
if (attackInfo.isDeadlyAttack()) {
mpattack = chr.getMp() - 1;
is_deadly = true;
}
mpattack += attackInfo.getMpBurn();
MobSkill mobSkill = MobSkillFactory.getMobSkill(attackInfo.getDiseaseSkill(), attackInfo.getDiseaseLevel());
if (mobSkill != null && damage > 0) {
mobSkill.applyEffect(chr, attacker, false, banishPlayers);
}
attacker.setMp(attacker.getMp() - attackInfo.getMpCon());
if (chr.getBuffedValue(MapleBuffStat.MANA_REFLECTION) != null && damage > 0 && !attacker.isBoss()) {
int jobid = chr.getJob().getId();
if (jobid == 212 || jobid == 222 || jobid == 232) {
int id = jobid * 10000 + 1002;
Skill manaReflectSkill = SkillFactory.getSkill(id);
if (chr.isBuffFrom(MapleBuffStat.MANA_REFLECTION, manaReflectSkill) && chr.getSkillLevel(manaReflectSkill) > 0 && manaReflectSkill.getEffect(chr.getSkillLevel(manaReflectSkill)).makeChanceResult()) {
int bouncedamage = (damage * manaReflectSkill.getEffect(chr.getSkillLevel(manaReflectSkill)).getX() / 100);
if (bouncedamage > attacker.getMaxHp() / 5) {
bouncedamage = attacker.getMaxHp() / 5;
}
map.damageMonster(chr, attacker, bouncedamage);
map.broadcastMessage(chr, MaplePacketCreator.damageMonster(oid, bouncedamage), true);
chr.getClient().announce(MaplePacketCreator.showOwnBuffEffect(id, 5));
map.broadcastMessage(chr, MaplePacketCreator.showBuffeffect(chr.getId(), id, 5), false);
}
}
}
}
}
if (damage == -1) {
fake = 4020002 + (chr.getJob().getId() / 10 - 40) * 100000;
}
// in dojo player cannot use pot, so deadly attacks should be turned off as well
if (is_deadly && chr.getMap().isDojoMap() && !ServerConstants.USE_DEADLY_DOJO) {
damage = 0;
mpattack = 0;
}
if (damage == 0) {
chr.getAutobanManager().addMiss();
} else {
chr.getAutobanManager().resetMisses();
}
if (damage > 0 && !chr.isHidden()) {
if (attacker != null && damagefrom == -1 && chr.getBuffedValue(MapleBuffStat.POWERGUARD) != null) {
// PG works on bosses, but only at half of the rate.
int bouncedamage = (int) (damage * (chr.getBuffedValue(MapleBuffStat.POWERGUARD).doubleValue() / (attacker.isBoss() ? 200 : 100)));
bouncedamage = Math.min(bouncedamage, attacker.getMaxHp() / 10);
damage -= bouncedamage;
map.damageMonster(chr, attacker, bouncedamage);
map.broadcastMessage(chr, MaplePacketCreator.damageMonster(oid, bouncedamage), false, true);
chr.checkMonsterAggro(attacker);
}
if (attacker != null && damagefrom == -1 && chr.getBuffedValue(MapleBuffStat.BODY_PRESSURE) != null) {
Skill skill = SkillFactory.getSkill(Aran.BODY_PRESSURE);
final MapleStatEffect eff = skill.getEffect(chr.getSkillLevel(skill));
if (!attacker.alreadyBuffedStats().contains(MonsterStatus.NEUTRALISE)) {
if (!attacker.isBoss() && eff.makeChanceResult()) {
attacker.applyStatus(chr, new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.NEUTRALISE, 1), skill, null, false), false, (eff.getDuration() / 10) * 2, false);
}
}
}
if (damagefrom != -3 && damagefrom != -4) {
int achilles = 0;
Skill achilles1 = null;
int jobid = chr.getJob().getId();
if (jobid < 200 && jobid % 10 == 2) {
achilles1 = SkillFactory.getSkill(jobid * 10000 + (jobid == 112 ? 4 : 5));
achilles = chr.getSkillLevel(achilles1);
}
if (achilles != 0 && achilles1 != null) {
damage *= (achilles1.getEffect(achilles).getX() / 1000.0);
}
}
Integer mesoguard = chr.getBuffedValue(MapleBuffStat.MESOGUARD);
if (chr.getBuffedValue(MapleBuffStat.MAGIC_GUARD) != null && mpattack == 0) {
int mploss = (int) (damage * (chr.getBuffedValue(MapleBuffStat.MAGIC_GUARD).doubleValue() / 100.0));
int hploss = damage - mploss;
int curmp = chr.getMp();
if (mploss > curmp) {
hploss += mploss - curmp;
mploss = curmp;
}
chr.addMPHP(-hploss, -mploss);
} else if (mesoguard != null) {
damage = Math.round(damage / 2);
int mesoloss = (int) (damage * (mesoguard.doubleValue() / 100.0));
if (chr.getMeso() < mesoloss) {
chr.gainMeso(-chr.getMeso(), false);
chr.cancelBuffStats(MapleBuffStat.MESOGUARD);
} else {
chr.gainMeso(-mesoloss, false);
}
chr.addMPHP(-damage, -mpattack);
} else {
if (chr.getBuffedValue(MapleBuffStat.MONSTER_RIDING) != null) {
if (chr.getBuffedValue(MapleBuffStat.MONSTER_RIDING).intValue() == Corsair.BATTLE_SHIP) {
chr.decreaseBattleshipHp(damage);
}
}
chr.addMPHP(-damage, -mpattack);
}
}
if (!chr.isHidden()) {
map.broadcastMessage(chr, MaplePacketCreator.damagePlayer(damagefrom, monsteridfrom, chr.getId(), damage, fake, direction, is_pgmr, pgmr, is_pg, oid, pos_x, pos_y), false);
chr.checkBerserk(true);
} else {
map.broadcastGMMessage(chr, MaplePacketCreator.damagePlayer(damagefrom, monsteridfrom, chr.getId(), damage, fake, direction, is_pgmr, pgmr, is_pg, oid, pos_x, pos_y), false);
chr.checkBerserk(false);
}
if (GameConstants.isDojo(map.getId())) {
chr.setDojoEnergy(chr.getDojoEnergy() + ServerConstants.DOJO_ENERGY_DMG);
c.announce(MaplePacketCreator.getEnergy("energy", chr.getDojoEnergy()));
}
for (MapleCharacter player : banishPlayers) {
// chill, if this list ever gets non-empty an attacker does exist, trust me :)
player.changeMapBanish(attacker.getBanish().getMap(), attacker.getBanish().getPortal(), attacker.getBanish().getMsg());
}
}
use of server.maps.MapleMapObject in project HeavenMS by ronancpl.
the class NPCTalkHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!c.getPlayer().isAlive()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (System.currentTimeMillis() - c.getPlayer().getNpcCooldown() < ServerConstants.BLOCK_NPC_RACE_CONDT) {
c.announce(MaplePacketCreator.enableActions());
return;
}
int oid = slea.readInt();
MapleMapObject obj = c.getPlayer().getMap().getMapObject(oid);
if (obj instanceof MapleNPC) {
MapleNPC npc = (MapleNPC) obj;
if (ServerConstants.USE_DEBUG == true)
c.getPlayer().dropMessage(5, "Talking to NPC " + npc.getId());
if (npc.getId() == 9010009) {
// is duey
c.getPlayer().setNpcCooldown(System.currentTimeMillis());
c.announce(MaplePacketCreator.sendDuey((byte) 8, DueyHandler.loadItems(c.getPlayer())));
} else {
if (c.getCM() != null || c.getQM() != null) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (npc.getId() >= 9100100 && npc.getId() <= 9100200) {
// Custom handling for gachapon scripts to reduce the amount of scripts needed.
NPCScriptManager.getInstance().start(c, npc.getId(), "gachapon", null);
} else {
boolean hasNpcScript = NPCScriptManager.getInstance().start(c, npc.getId(), oid, null);
if (!hasNpcScript) {
if (!npc.hasShop()) {
FilePrinter.printError(FilePrinter.NPC_UNCODED, "NPC " + npc.getName() + "(" + npc.getId() + ") is not coded.\r\n");
return;
} else if (c.getPlayer().getShop() != null) {
c.announce(MaplePacketCreator.enableActions());
return;
}
npc.sendShop(c);
}
}
}
} else if (obj instanceof PlayerNPCs) {
NPCScriptManager.getInstance().start(c, ((PlayerNPCs) obj).getId(), null);
}
}
Aggregations