Ejemplo n.º 1
0
 public static final void CurePot(final LittleEndianAccessor slea, final MapleClient c) {
   final int itemid = slea.readInt();
   final Item slot =
       c.getPlayer().getInventory(MapleInventoryType.ETC).getItem((short) slea.readInt());
   if (slot == null
       || slot.getQuantity() <= 0
       || slot.getItemId() != itemid
       || itemid / 10000 != 434) {
     c.getSession().write(CWvsContext.enableActions());
     return;
   }
   final int index = slea.readInt() - 1;
   if (index < 0
       || index >= c.getPlayer().getImps().length
       || c.getPlayer().getImps()[index] == null
       || c.getPlayer().getImps()[index].getState() != 4) {
     c.getSession().write(CWvsContext.enableActions());
     return;
   }
   c.getPlayer().getImps()[index].setState(1);
   c.getSession()
       .write(
           CWvsContext.updateImp(
               c.getPlayer().getImps()[index], ImpFlag.STATE.getValue(), index, false));
   MapleInventoryManipulator.removeFromSlot(
       c, MapleInventoryType.ETC, slot.getPosition(), (short) 1, false, false);
 }
Ejemplo n.º 2
0
 public static final void UsePot(final LittleEndianAccessor slea, final MapleClient c) {
   final int itemid = slea.readInt();
   final Item slot = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slea.readShort());
   if (slot == null
       || slot.getQuantity() <= 0
       || slot.getItemId() != itemid
       || itemid / 10000 != 244
       || MapleItemInformationProvider.getInstance().getPot(itemid) == null) {
     c.getSession().write(CWvsContext.enableActions());
     return;
   }
   c.getSession().write(CWvsContext.enableActions());
   for (int i = 0; i < c.getPlayer().getImps().length; i++) {
     if (c.getPlayer().getImps()[i] == null) {
       c.getPlayer().getImps()[i] = new MapleImp(itemid);
       c.getSession()
           .write(
               CWvsContext.updateImp(
                   c.getPlayer().getImps()[i], ImpFlag.SUMMONED.getValue(), i, false));
       MapleInventoryManipulator.removeFromSlot(
           c, MapleInventoryType.USE, slot.getPosition(), (short) 1, false, false);
       return;
     }
   }
 }
Ejemplo n.º 3
0
 @Override
 public boolean equals(Object obj) {
   if (!(obj instanceof Item)) {
     return false;
   }
   final Item ite = (Item) obj;
   return uniqueid == ite.getUniqueId()
       && id == ite.getItemId()
       && quantity == ite.getQuantity()
       && Math.abs(position) == Math.abs(ite.getPosition());
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
  public static final void ItemMaker(final LittleEndianAccessor slea, final MapleClient c) {
    // System.out.println(slea.toString()); //change?
    final int makerType = slea.readInt();

    switch (makerType) {
      case 1:
        { // Gem
          final int toCreate = slea.readInt();

          if (GameConstants.isGem(toCreate)) {
            final GemCreateEntry gem = ItemMakerFactory.getInstance().getGemInfo(toCreate);
            if (gem == null) {
              return;
            }
            if (!hasSkill(c, gem.getReqSkillLevel())) {
              return; // H4x
            }
            if (c.getPlayer().getMeso() < gem.getCost()) {
              return; // H4x
            }
            final int randGemGiven = getRandomGem(gem.getRandomReward());

            if (c.getPlayer().getInventory(GameConstants.getInventoryType(randGemGiven)).isFull()) {
              return; // We'll do handling for this later
            }
            final int taken = checkRequiredNRemove(c, gem.getReqRecipes());
            if (taken == 0) {
              return; // We'll do handling for this later
            }
            c.getPlayer().gainMeso(-gem.getCost(), false);
            MapleInventoryManipulator.addById(
                c,
                randGemGiven,
                (byte) (taken == randGemGiven ? 9 : 1),
                "Made by Gem "
                    + toCreate
                    + " on "
                    + FileoutputUtil.CurrentReadable_Date()); // Gem is always 1

            c.getSession().write(EffectPacket.ItemMaker_Success());
            c.getPlayer()
                .getMap()
                .broadcastMessage(
                    c.getPlayer(),
                    EffectPacket.ItemMaker_Success_3rdParty(c.getPlayer().getId()),
                    false);
          } else if (GameConstants.isOtherGem(toCreate)) {
            // non-gems that are gems
            // stim and numEnchanter always 0
            final GemCreateEntry gem = ItemMakerFactory.getInstance().getGemInfo(toCreate);
            if (gem == null) {
              return;
            }
            if (!hasSkill(c, gem.getReqSkillLevel())) {
              return; // H4x
            }
            if (c.getPlayer().getMeso() < gem.getCost()) {
              return; // H4x
            }

            if (c.getPlayer().getInventory(GameConstants.getInventoryType(toCreate)).isFull()) {
              return; // We'll do handling for this later
            }
            if (checkRequiredNRemove(c, gem.getReqRecipes()) == 0) {
              return; // We'll do handling for this later
            }
            c.getPlayer().gainMeso(-gem.getCost(), false);
            if (GameConstants.getInventoryType(toCreate) == MapleInventoryType.EQUIP) {
              MapleInventoryManipulator.addbyItem(
                  c, MapleItemInformationProvider.getInstance().getEquipById(toCreate));
            } else {
              MapleInventoryManipulator.addById(
                  c,
                  toCreate,
                  (byte) 1,
                  "Made by Gem "
                      + toCreate
                      + " on "
                      + FileoutputUtil.CurrentReadable_Date()); // Gem is always 1
            }

            c.getSession().write(EffectPacket.ItemMaker_Success());
            c.getPlayer()
                .getMap()
                .broadcastMessage(
                    c.getPlayer(),
                    EffectPacket.ItemMaker_Success_3rdParty(c.getPlayer().getId()),
                    false);
          } else {
            final boolean stimulator = slea.readByte() > 0;
            final int numEnchanter = slea.readInt();

            final ItemMakerCreateEntry create =
                ItemMakerFactory.getInstance().getCreateInfo(toCreate);
            if (create == null) {
              return;
            }
            if (numEnchanter > create.getTUC()) {
              return; // h4x
            }
            if (!hasSkill(c, create.getReqSkillLevel())) {
              return; // H4x
            }
            if (c.getPlayer().getMeso() < create.getCost()) {
              return; // H4x
            }
            if (c.getPlayer().getInventory(GameConstants.getInventoryType(toCreate)).isFull()) {
              return; // We'll do handling for this later
            }
            if (checkRequiredNRemove(c, create.getReqItems()) == 0) {
              return; // We'll do handling for this later
            }
            c.getPlayer().gainMeso(-create.getCost(), false);

            final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
            final Equip toGive = (Equip) ii.getEquipById(toCreate);

            if (stimulator || numEnchanter > 0) {
              if (c.getPlayer().haveItem(create.getStimulator(), 1, false, true)) {
                ii.randomizeStats_Above(toGive);
                MapleInventoryManipulator.removeById(
                    c, MapleInventoryType.ETC, create.getStimulator(), 1, false, false);
              }
              for (int i = 0; i < numEnchanter; i++) {
                final int enchant = slea.readInt();
                if (c.getPlayer().haveItem(enchant, 1, false, true)) {
                  final Map<String, Integer> stats = ii.getEquipStats(enchant);
                  if (stats != null) {
                    addEnchantStats(stats, toGive);
                    MapleInventoryManipulator.removeById(
                        c, MapleInventoryType.ETC, enchant, 1, false, false);
                  }
                }
              }
            }
            if (!stimulator || Randomizer.nextInt(10) != 0) {
              MapleInventoryManipulator.addbyItem(c, toGive);
              c.getPlayer()
                  .getMap()
                  .broadcastMessage(
                      c.getPlayer(),
                      EffectPacket.ItemMaker_Success_3rdParty(c.getPlayer().getId()),
                      false);
            } else {
              c.getPlayer().dropMessage(5, "The item was overwhelmed by the stimulator.");
            }
            c.getSession().write(EffectPacket.ItemMaker_Success());
          }
          break;
        }
      case 3:
        { // Making Crystals
          final int etc = slea.readInt();
          if (c.getPlayer().haveItem(etc, 100, false, true)) {
            MapleInventoryManipulator.addById(
                c,
                getCreateCrystal(etc),
                (short) 1,
                "Made by Maker " + etc + " on " + FileoutputUtil.CurrentReadable_Date());
            MapleInventoryManipulator.removeById(c, MapleInventoryType.ETC, etc, 100, false, false);

            c.getSession().write(EffectPacket.ItemMaker_Success());
            c.getPlayer()
                .getMap()
                .broadcastMessage(
                    c.getPlayer(),
                    EffectPacket.ItemMaker_Success_3rdParty(c.getPlayer().getId()),
                    false);
          }
          break;
        }
      case 4:
        { // Disassembling EQ.
          final int itemId = slea.readInt();
          c.getPlayer().updateTick(slea.readInt());
          final byte slot = (byte) slea.readInt();

          final Item toUse = c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(slot);
          if (toUse == null || toUse.getItemId() != itemId || toUse.getQuantity() < 1) {
            return;
          }
          final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();

          if (!ii.isDropRestricted(itemId) && !ii.isAccountShared(itemId)) {
            final int[] toGive = getCrystal(itemId, ii.getReqLevel(itemId));
            MapleInventoryManipulator.addById(
                c,
                toGive[0],
                (byte) toGive[1],
                "Made by disassemble " + itemId + " on " + FileoutputUtil.CurrentReadable_Date());
            MapleInventoryManipulator.removeFromSlot(
                c, MapleInventoryType.EQUIP, slot, (byte) 1, false);
          }
          c.getSession().write(EffectPacket.ItemMaker_Success());
          c.getPlayer()
              .getMap()
              .broadcastMessage(
                  c.getPlayer(),
                  EffectPacket.ItemMaker_Success_3rdParty(c.getPlayer().getId()),
                  false);
          break;
        }
    }
  }
Ejemplo n.º 6
0
 public static final void FeedPot(final LittleEndianAccessor slea, final MapleClient c) {
   final int itemid = slea.readInt();
   final Item slot =
       c.getPlayer()
           .getInventory(GameConstants.getInventoryType(itemid))
           .getItem((short) slea.readInt());
   if (slot == null || slot.getQuantity() <= 0 || slot.getItemId() != itemid) {
     c.getSession().write(CWvsContext.enableActions());
     return;
   }
   final int level =
       GameConstants.getInventoryType(itemid) == MapleInventoryType.ETC
           ? MapleItemInformationProvider.getInstance().getItemMakeLevel(itemid)
           : MapleItemInformationProvider.getInstance().getReqLevel(itemid);
   if (level <= 0
       || level < (Math.min(120, c.getPlayer().getLevel()) - 50)
       || (GameConstants.getInventoryType(itemid) != MapleInventoryType.ETC
           && GameConstants.getInventoryType(itemid) != MapleInventoryType.EQUIP)) {
     c.getPlayer().dropMessage(1, "The item must be within 50 levels of you.");
     c.getSession().write(CWvsContext.enableActions());
     return;
   }
   final int index = slea.readInt() - 1;
   if (index < 0
       || index >= c.getPlayer().getImps().length
       || c.getPlayer().getImps()[index] == null
       || c.getPlayer().getImps()[index].getLevel()
           >= (MapleItemInformationProvider.getInstance()
                   .getPot(c.getPlayer().getImps()[index].getItemId())
                   .right
               - 1)
       || c.getPlayer().getImps()[index].getState() != 1) {
     c.getSession().write(CWvsContext.enableActions());
     return;
   }
   int mask = ImpFlag.FULLNESS.getValue();
   mask |= ImpFlag.FULLNESS_2.getValue();
   mask |= ImpFlag.UPDATE_TIME.getValue();
   mask |= ImpFlag.AWAKE_TIME.getValue();
   // this is where the magic happens
   c.getPlayer()
       .getImps()[index]
       .setFullness(
           c.getPlayer().getImps()[index].getFullness()
               + (100
                   * (GameConstants.getInventoryType(itemid) == MapleInventoryType.EQUIP
                       ? 2
                       : 1)));
   if (Randomizer.nextBoolean()) {
     mask |= ImpFlag.CLOSENESS.getValue();
     c.getPlayer()
         .getImps()[index]
         .setCloseness(
             c.getPlayer().getImps()[index].getCloseness()
                 + 1
                 + (Randomizer.nextInt(
                     5
                         * (GameConstants.getInventoryType(itemid) == MapleInventoryType.EQUIP
                             ? 2
                             : 1))));
   } else if (Randomizer.nextInt(5) == 0) { // 1/10 chance of sickness
     c.getPlayer().getImps()[index].setState(4); // sick
     mask |= ImpFlag.STATE.getValue();
   }
   if (c.getPlayer().getImps()[index].getFullness() >= 1000) {
     c.getPlayer().getImps()[index].setState(1);
     c.getPlayer().getImps()[index].setFullness(0);
     c.getPlayer().getImps()[index].setLevel(c.getPlayer().getImps()[index].getLevel() + 1);
     mask |= ImpFlag.SUMMONED.getValue();
     if (c.getPlayer().getImps()[index].getLevel()
         >= (MapleItemInformationProvider.getInstance()
                 .getPot(c.getPlayer().getImps()[index].getItemId())
                 .right
             - 1)) {
       c.getPlayer().getImps()[index].setState(5);
     }
   }
   MapleInventoryManipulator.removeFromSlot(
       c, GameConstants.getInventoryType(itemid), slot.getPosition(), (short) 1, false, false);
   c.getSession().write(CWvsContext.updateImp(c.getPlayer().getImps()[index], mask, index, false));
 }