public Item toItem(CashItem cItem, int uniqueid, String gift) { if (uniqueid <= 0) { uniqueid = MapleInventoryIdentifier.getInstance(); } long period = cItem.getExpire(); if ((period <= 0 && GameConstants.getInventoryType(cItem.getItemId()) != MapleInventoryType.EQUIP) || GameConstants.isPet(cItem.getItemId())) { period = GameConstants.GMS ? 90 : 45; } if (cItem.getItemId() >= 5000100 && cItem.getItemId() < 5000200) { // permanent pet period = 20000; // permanent time millis } Item ret; if (GameConstants.getInventoryType(cItem.getItemId()) == MapleInventoryType.EQUIP) { Equip eq = (Equip) MapleItemInformationProvider.getInstance().getEquipById(cItem.getItemId(), uniqueid); if (period > 0) { eq.setExpiration( (long) (System.currentTimeMillis() + (long) (period * 24 * 60 * 60 * 1000))); } eq.setGMLog("Cash Shop: " + cItem.getSN() + " on " + FileoutputUtil.CurrentReadable_Date()); eq.setGiftFrom(gift); if (GameConstants.isEffectRing(cItem.getItemId()) && uniqueid > 0) { MapleRing ring = MapleRing.loadFromDb(uniqueid); if (ring != null) { eq.setRing(ring); } } ret = eq.copy(); } else { Item item = new Item(cItem.getItemId(), (byte) 0, (short) cItem.getQuantity(), (byte) 0, uniqueid); if (period > 0) { item.setExpiration( (long) (System.currentTimeMillis() + (long) (period * 24 * 60 * 60 * 1000))); } item.setGMLog("Cash Shop: " + cItem.getSN() + " on " + FileoutputUtil.CurrentReadable_Date()); item.setGiftFrom(gift); if (GameConstants.isPet(cItem.getItemId())) { final MaplePet pet = MaplePet.createPet(cItem.getItemId(), uniqueid); if (pet != null) { item.setPet(pet); } } ret = item.copy(); } return ret; }
public static void MTSOperation(final LittleEndianAccessor slea, final MapleClient c) { final MTSCart cart = MTSStorage.getInstance().getCart(c.getPlayer().getId()); // System.out.println(slea.toString()); if (slea.available() <= 0) { doMTSPackets(cart, c); return; } final byte op = slea.readByte(); if (op == 2) { // put up for sale final byte invType = slea.readByte(); // 1 = equip 2 = everything else if (invType != 1 && invType != 2) { // pet? c.getSession().write(MTSCSPacket.getMTSFailSell()); doMTSPackets(cart, c); return; } final int itemid = slea.readInt(); // itemid if (slea.readByte() != 0) { c.getSession().write(MTSCSPacket.getMTSFailSell()); doMTSPackets(cart, c); return; // we don't like uniqueIDs } slea.skip(12); // expiration, -1, don't matter short stars = 1, quantity = 1; byte slot = 0; if (invType == 1) { slea.skip(32); } else { stars = slea.readShort(); // the entire quantity of the item } slea.readMapleAsciiString(); // owner // again? =/ if (invType == 1) { slea.skip(50); slot = (byte) slea.readInt(); slea.skip(4); // skip the quantity int, equips are always 1 } else { slea.readShort(); // flag if (GameConstants.isThrowingStar(itemid) || GameConstants.isBullet(itemid)) { slea.skip(8); // recharge ID thing } slot = (byte) slea.readInt(); if (GameConstants.isThrowingStar(itemid) || GameConstants.isBullet(itemid)) { quantity = stars; // this is due to stars you need to use the entire quantity, not specified slea.skip(4); // so just skip the quantity int } else { quantity = (short) slea.readInt(); // specified quantity } } final int price = slea.readInt(); final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance(); final MapleInventoryType type = GameConstants.getInventoryType(itemid); final Item item = c.getPlayer().getInventory(type).getItem(slot).copy(); if (ii.isCash(itemid) || quantity <= 0 || item == null || item.getQuantity() <= 0 || item.getItemId() != itemid || item.getUniqueId() > 0 || item.getQuantity() < quantity || price < ServerConstants.MIN_MTS || c.getPlayer().getMeso() < ServerConstants.MTS_MESO || cart.getNotYetSold().size() >= 10 || ii.isDropRestricted(itemid) || ii.isAccountShared(itemid) || item.getExpiration() > -1 || item.getFlag() > 0) { c.getSession().write(MTSCSPacket.getMTSFailSell()); doMTSPackets(cart, c); return; } if (type == MapleInventoryType.EQUIP) { final Equip eq = (Equip) item; if (eq.getState() > 0 || eq.getEnhance() > 0 || eq.getDurability() > -1) { c.getSession().write(MTSCSPacket.getMTSFailSell()); doMTSPackets(cart, c); return; } } if (quantity >= 50 && item.getItemId() == 2340000) { c.setMonitored(true); // hack check } final long expiration = (System.currentTimeMillis() + (7L * 24 * 60 * 60 * 1000)); item.setQuantity(quantity); MTSStorage.getInstance() .addToBuyNow( cart, item, price, c.getPlayer().getId(), c.getPlayer().getName(), expiration); MapleInventoryManipulator.removeFromSlot(c, type, slot, quantity, false); c.getPlayer().gainMeso(-ServerConstants.MTS_MESO, false); c.getSession().write(MTSCSPacket.getMTSConfirmSell()); } else if (op == 5) { // change page/tab cart.changeInfo(slea.readInt(), slea.readInt(), slea.readInt()); } else if (op == 6) { // search cart.changeInfo(slea.readInt(), slea.readInt(), 0); slea.readInt(); // always 0? cart.changeCurrentView( MTSStorage.getInstance() .getSearch( slea.readInt() > 0, slea.readMapleAsciiString(), cart.getType(), cart.getTab())); } else if (op == 7) { // cancel sale if (!MTSStorage.getInstance().removeFromBuyNow(slea.readInt(), c.getPlayer().getId(), true)) { c.getSession().write(MTSCSPacket.getMTSFailCancel()); } else { c.getSession().write(MTSCSPacket.getMTSConfirmCancel()); sendMTSPackets(cart, c, true); return; } } else if (op == 8) { // transfer item final int id = Integer.MAX_VALUE - slea.readInt(); // fake id if (id >= cart.getInventory().size()) { c.getPlayer().dropMessage(1, "Please try it again later."); sendMTSPackets(cart, c, true); return; } final Item item = cart.getInventory().get(id); // by index // System.out.println("NumItems: " + cart.getInventory().size() + ", ID: " + id + ", // ItemExists?: " + (item != null)); if (item != null && item.getQuantity() > 0 && MapleInventoryManipulator.checkSpace( c, item.getItemId(), item.getQuantity(), item.getOwner())) { Item item_ = item.copy(); short pos = MapleInventoryManipulator.addbyItem(c, item_, true); if (pos >= 0) { if (item_.getPet() != null) { item_.getPet().setInventoryPosition(pos); c.getPlayer().addPet(item_.getPet()); } cart.removeFromInventory(item); c.getSession() .write( MTSCSPacket.getMTSConfirmTransfer( GameConstants.getInventoryType(item_.getItemId()).getType(), pos)); // IF this is actually pos and pos sendMTSPackets(cart, c, true); return; } else { // System.out.println("addByItem is less than 0"); c.getSession().write(MTSCSPacket.getMTSFailBuy()); } } else { // System.out.println("CheckSpace return false"); c.getSession().write(MTSCSPacket.getMTSFailBuy()); } } else if (op == 9) { // add to cart final int id = slea.readInt(); if (MTSStorage.getInstance().checkCart(id, c.getPlayer().getId()) && cart.addToCart(id)) { c.getSession().write(MTSCSPacket.addToCartMessage(false, false)); } else { c.getSession().write(MTSCSPacket.addToCartMessage(true, false)); } } else if (op == 10) { // delete from cart final int id = slea.readInt(); if (cart.getCart().contains(id)) { cart.removeFromCart(id); c.getSession().write(MTSCSPacket.addToCartMessage(false, true)); } else { c.getSession().write(MTSCSPacket.addToCartMessage(true, true)); } } else if (op == 16 || op == 17) { // buyNow, buy from cart final MTSItemInfo mts = MTSStorage.getInstance().getSingleItem(slea.readInt()); if (mts != null && mts.getCharacterId() != c.getPlayer().getId()) { if (c.getPlayer().getCSPoints(1) > mts.getRealPrice()) { if (MTSStorage.getInstance() .removeFromBuyNow(mts.getId(), c.getPlayer().getId(), false)) { c.getPlayer().modifyCSPoints(1, -mts.getRealPrice(), false); MTSStorage.getInstance().getCart(mts.getCharacterId()).increaseOwedNX(mts.getPrice()); c.getSession().write(MTSCSPacket.getMTSConfirmBuy()); sendMTSPackets(cart, c, true); return; } else { c.getSession().write(MTSCSPacket.getMTSFailBuy()); } } else { c.getSession().write(MTSCSPacket.getMTSFailBuy()); } } else { c.getSession().write(MTSCSPacket.getMTSFailBuy()); } } else if (c.getPlayer().isAdmin()) { // System.out.println("New MTS Op " + op + ", \n" + slea.toString()); } doMTSPackets(cart, c); }
private static void addEnchantStats(final Map<String, Integer> stats, final Equip item) { Integer s = stats.get("PAD"); if (s != null && s != 0) { item.setWatk((short) (item.getWatk() + s)); } s = stats.get("MAD"); if (s != null && s != 0) { item.setMatk((short) (item.getMatk() + s)); } s = stats.get("ACC"); if (s != null && s != 0) { item.setAcc((short) (item.getAcc() + s)); } s = stats.get("EVA"); if (s != null && s != 0) { item.setAvoid((short) (item.getAvoid() + s)); } s = stats.get("Speed"); if (s != null && s != 0) { item.setSpeed((short) (item.getSpeed() + s)); } s = stats.get("Jump"); if (s != null && s != 0) { item.setJump((short) (item.getJump() + s)); } s = stats.get("MaxHP"); if (s != null && s != 0) { item.setHp((short) (item.getHp() + s)); } s = stats.get("MaxMP"); if (s != null && s != 0) { item.setMp((short) (item.getMp() + s)); } s = stats.get("STR"); if (s != null && s != 0) { item.setStr((short) (item.getStr() + s)); } s = stats.get("DEX"); if (s != null && s != 0) { item.setDex((short) (item.getDex() + s)); } s = stats.get("INT"); if (s != null && s != 0) { item.setInt((short) (item.getInt() + s)); } s = stats.get("LUK"); if (s != null && s != 0) { item.setLuk((short) (item.getLuk() + s)); } s = stats.get("randOption"); if (s != null && s != 0) { final int ma = item.getMatk(), wa = item.getWatk(); if (wa > 0) { item.setWatk((short) (Randomizer.nextBoolean() ? (wa + s) : (wa - s))); } if (ma > 0) { item.setMatk((short) (Randomizer.nextBoolean() ? (ma + s) : (ma - s))); } } s = stats.get("randStat"); if (s != null && s != 0) { final int str = item.getStr(), dex = item.getDex(), luk = item.getLuk(), int_ = item.getInt(); if (str > 0) { item.setStr((short) (Randomizer.nextBoolean() ? (str + s) : (str - s))); } if (dex > 0) { item.setDex((short) (Randomizer.nextBoolean() ? (dex + s) : (dex - s))); } if (int_ > 0) { item.setInt((short) (Randomizer.nextBoolean() ? (int_ + s) : (int_ - s))); } if (luk > 0) { item.setLuk((short) (Randomizer.nextBoolean() ? (luk + s) : (luk - s))); } } }