use of server.maps.MaplePlayerShop in project HeavenMS by ronancpl.
the class MapleCharacter method closePlayerShop.
public void closePlayerShop() {
MaplePlayerShop mps = this.getPlayerShop();
if (mps == null)
return;
if (mps.isOwner(this)) {
mps.setOpen(false);
client.getWorldServer().unregisterPlayerShop(mps);
for (MaplePlayerShopItem mpsi : mps.getItems()) {
if (mpsi.getBundles() >= 2) {
Item iItem = mpsi.getItem().copy();
iItem.setQuantity((short) (mpsi.getBundles() * iItem.getQuantity()));
MapleInventoryManipulator.addFromDrop(this.getClient(), iItem, false);
} else if (mpsi.isExist()) {
MapleInventoryManipulator.addFromDrop(this.getClient(), mpsi.getItem(), true);
}
}
mps.closeShop();
} else {
mps.removeVisitor(this);
}
this.setPlayerShop(null);
}
use of server.maps.MaplePlayerShop in project HeavenMS by ronancpl.
the class MaplePacketCreator method spawnPlayerMapObject.
/**
* Gets a packet spawning a player as a mapobject to other clients.
*
* @param chr The character to spawn to other clients.
* @return The spawn player packet.
*/
public static byte[] spawnPlayerMapObject(MapleCharacter chr) {
final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.SPAWN_PLAYER.getValue());
mplew.writeInt(chr.getId());
// v83
mplew.write(chr.getLevel());
mplew.writeMapleAsciiString(chr.getName());
if (chr.getGuildId() < 1) {
mplew.writeMapleAsciiString("");
mplew.write(new byte[6]);
} else {
MapleGuildSummary gs = chr.getClient().getWorldServer().getGuildSummary(chr.getGuildId(), chr.getWorld());
if (gs != null) {
mplew.writeMapleAsciiString(gs.getName());
mplew.writeShort(gs.getLogoBG());
mplew.write(gs.getLogoBGColor());
mplew.writeShort(gs.getLogo());
mplew.write(gs.getLogoColor());
} else {
mplew.writeMapleAsciiString("");
mplew.write(new byte[6]);
}
}
mplew.writeInt(0);
// v83
mplew.writeShort(0);
mplew.write(0xFC);
mplew.write(1);
if (chr.getBuffedValue(MapleBuffStat.MORPH) != null) {
mplew.writeInt(2);
} else {
mplew.writeInt(0);
}
long buffmask = 0;
Integer buffvalue = null;
if (chr.getBuffedValue(MapleBuffStat.DARKSIGHT) != null && !chr.isHidden()) {
buffmask |= MapleBuffStat.DARKSIGHT.getValue();
}
if (chr.getBuffedValue(MapleBuffStat.COMBO) != null) {
buffmask |= MapleBuffStat.COMBO.getValue();
buffvalue = Integer.valueOf(chr.getBuffedValue(MapleBuffStat.COMBO).intValue());
}
if (chr.getBuffedValue(MapleBuffStat.SHADOWPARTNER) != null) {
buffmask |= MapleBuffStat.SHADOWPARTNER.getValue();
}
if (chr.getBuffedValue(MapleBuffStat.SOULARROW) != null) {
buffmask |= MapleBuffStat.SOULARROW.getValue();
}
if (chr.getBuffedValue(MapleBuffStat.MORPH) != null) {
buffvalue = Integer.valueOf(chr.getBuffedValue(MapleBuffStat.MORPH).intValue());
}
if (chr.getBuffedValue(MapleBuffStat.ENERGY_CHARGE) != null) {
buffmask |= MapleBuffStat.ENERGY_CHARGE.getValue();
buffvalue = Integer.valueOf(chr.getBuffedValue(MapleBuffStat.ENERGY_CHARGE).intValue());
}
// AREN'T THESE
mplew.writeInt((int) ((buffmask >> 32) & 0xffffffffL));
if (buffvalue != null) {
if (chr.getBuffedValue(MapleBuffStat.MORPH) != null) {
// TEST
mplew.writeShort(buffvalue);
} else {
mplew.write(buffvalue.byteValue());
}
}
mplew.writeInt((int) (buffmask & 0xffffffffL));
int CHAR_MAGIC_SPAWN = Randomizer.nextInt();
mplew.skip(6);
mplew.writeInt(CHAR_MAGIC_SPAWN);
mplew.skip(11);
// v74
mplew.writeInt(CHAR_MAGIC_SPAWN);
mplew.skip(11);
mplew.writeInt(CHAR_MAGIC_SPAWN);
mplew.writeShort(0);
mplew.write(0);
final Item mount = chr.getInventory(MapleInventoryType.EQUIPPED).getItem((short) -18);
if (chr.getBuffedValue(MapleBuffStat.MONSTER_RIDING) != null && mount != null) {
mplew.writeInt(mount.getItemId());
mplew.writeInt(1004);
} else {
mplew.writeLong(0);
}
mplew.writeInt(CHAR_MAGIC_SPAWN);
mplew.skip(9);
mplew.writeInt(CHAR_MAGIC_SPAWN);
mplew.writeShort(0);
// actually not 0, why is it 0 then?
mplew.writeInt(0);
mplew.skip(10);
mplew.writeInt(CHAR_MAGIC_SPAWN);
mplew.skip(13);
mplew.writeInt(CHAR_MAGIC_SPAWN);
mplew.writeShort(0);
mplew.write(0);
mplew.writeShort(chr.getJob().getId());
/* replace "mplew.writeShort(chr.getJob().getId())" with this snippet for 3rd person FJ animation on all classes
if (chr.getJob().isA(MapleJob.HERMIT) || chr.getJob().isA(MapleJob.DAWNWARRIOR2) || chr.getJob().isA(MapleJob.NIGHTWALKER2)) {
mplew.writeShort(chr.getJob().getId());
} else {
mplew.writeShort(412);
}*/
addCharLook(mplew, chr, false);
mplew.writeInt(chr.getInventory(MapleInventoryType.CASH).countById(5110000));
mplew.writeInt(chr.getItemEffect());
mplew.writeInt(ItemConstants.getInventoryType(chr.getChair()) == MapleInventoryType.SETUP ? chr.getChair() : 0);
mplew.writePos(chr.getPosition());
mplew.write(chr.getStance());
// chr.getFh()
mplew.writeShort(0);
mplew.write(0);
MaplePet[] pet = chr.getPets();
for (int i = 0; i < 3; i++) {
if (pet[i] != null) {
addPetInfo(mplew, pet[i], false);
}
}
// end of pets
mplew.write(0);
if (chr.getMount() == null) {
// mob level
mplew.writeInt(1);
// mob exp + tiredness
mplew.writeLong(0);
} else {
mplew.writeInt(chr.getMount().getLevel());
mplew.writeInt(chr.getMount().getExp());
mplew.writeInt(chr.getMount().getTiredness());
}
MaplePlayerShop mps = chr.getPlayerShop();
if (mps != null && mps.isOwner(chr)) {
if (mps.hasFreeSlot()) {
addAnnounceBox(mplew, mps, mps.getVisitors().length);
} else {
addAnnounceBox(mplew, mps, 1);
}
} else if (chr.getMiniGame() != null && chr.getMiniGame().isOwner(chr)) {
if (chr.getMiniGame().hasFreeSlot()) {
addAnnounceBox(mplew, chr.getMiniGame(), 1, 0, 1, 0);
} else {
addAnnounceBox(mplew, chr.getMiniGame(), 1, 0, 2, 1);
}
} else {
mplew.write(0);
}
if (chr.getChalkboard() != null) {
mplew.write(1);
mplew.writeMapleAsciiString(chr.getChalkboard());
} else {
mplew.write(0);
}
// crush
addRingLook(mplew, chr, true);
// friendship
addRingLook(mplew, chr, false);
addMarriageRingLook(mplew, chr);
// new year seems to crash sometimes...
encodeNewYearCardInfo(mplew, chr);
mplew.skip(2);
// only needed in specific fields
mplew.write(chr.getTeam());
return mplew.getPacket();
}
use of server.maps.MaplePlayerShop 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.MaplePlayerShop in project HeavenMS by ronancpl.
the class World method getAvailableItemBundles.
public List<Pair<MaplePlayerShopItem, AbstractMapleMapObject>> getAvailableItemBundles(int itemid) {
List<Pair<MaplePlayerShopItem, AbstractMapleMapObject>> hmsAvailable = new ArrayList<>();
for (MapleHiredMerchant hm : getActiveMerchants()) {
List<MaplePlayerShopItem> itemBundles = hm.sendAvailableBundles(itemid);
for (MaplePlayerShopItem mpsi : itemBundles) {
hmsAvailable.add(new Pair<>(mpsi, (AbstractMapleMapObject) hm));
}
}
for (MaplePlayerShop ps : getActivePlayerShops()) {
List<MaplePlayerShopItem> itemBundles = ps.sendAvailableBundles(itemid);
for (MaplePlayerShopItem mpsi : itemBundles) {
hmsAvailable.add(new Pair<>(mpsi, (AbstractMapleMapObject) ps));
}
}
Collections.sort(hmsAvailable, new Comparator<Pair<MaplePlayerShopItem, AbstractMapleMapObject>>() {
@Override
public int compare(Pair<MaplePlayerShopItem, AbstractMapleMapObject> p1, Pair<MaplePlayerShopItem, AbstractMapleMapObject> p2) {
return p1.getLeft().getPrice() - p2.getLeft().getPrice();
}
});
// truncates the list to have up to 200 elements
hmsAvailable.subList(0, Math.min(hmsAvailable.size(), 200));
return hmsAvailable;
}
use of server.maps.MaplePlayerShop in project HeavenMS by ronancpl.
the class World method getActivePlayerShops.
public List<MaplePlayerShop> getActivePlayerShops() {
List<MaplePlayerShop> psList = new ArrayList<>();
activePlayerShopsLock.lock();
try {
for (MaplePlayerShop mps : activePlayerShops.values()) {
psList.add(mps);
}
return psList;
} finally {
activePlayerShopsLock.unlock();
}
}
Aggregations