public static boolean checkSpace(
     final MapleClient c, final int Id, int quantity, final String owner) {
   final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
   final MapleInventoryType type = ii.getInventoryType(Id);
   if (!type.equals(MapleInventoryType.EQUIP)) {
     final short slotMax = ii.getSlotMax(c, Id);
     final List<IItem> existing = c.getPlayer().getInventory(type).listById(Id);
     if (!InventoryConstants.isRechargable(Id)) {
       if (existing.size() > 0) {
         for (IItem eItem : existing) {
           final short oldQ = eItem.getQuantity();
           if (oldQ < slotMax && owner.equals(eItem.getOwner())) {
             final short newQ = (short) Math.min(oldQ + quantity, slotMax);
             quantity -= (newQ - oldQ);
           }
           if (quantity <= 0) {
             break;
           }
         }
       }
     }
     final int numSlotsNeeded;
     if (slotMax > 0) {
       numSlotsNeeded = (int) (Math.ceil(((double) quantity) / slotMax));
     } else if (InventoryConstants.isRechargable(Id)) {
       numSlotsNeeded = 1;
     } else {
       numSlotsNeeded = 1;
       System.out.println("checkSpace error");
     }
     return !c.getPlayer().getInventory(type).isFull(numSlotsNeeded - 1);
   } else {
     return !c.getPlayer().getInventory(type).isFull();
   }
 }
Example #2
0
 public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   if (!c.getPlayer().isAlive()) {
     c.getSession().write(MaplePacketCreator.enableActions());
     return;
   }
   MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
   slea.readInt();
   byte slot = (byte) slea.readShort();
   int itemId = slea.readInt();
   IItem toUse = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
   if (toUse != null && toUse.getQuantity() > 0 && toUse.getItemId() == itemId) {
     if (itemId == 2022178 || itemId == 2022433 || itemId == 2050004) {
       c.getPlayer().dispelDebuffs();
       remove(c, slot);
       return;
     } else if (itemId == 2050003) {
       c.getPlayer().dispelSeal();
       remove(c, slot);
       return;
     }
     if (isTownScroll(itemId)) {
       if (ii.getItemEffect(toUse.getItemId()).applyTo(c.getPlayer())) {
         remove(c, slot);
       }
       c.getSession().write(MaplePacketCreator.enableActions());
       return;
     }
     remove(c, slot);
     ii.getItemEffect(toUse.getItemId()).applyTo(c.getPlayer());
     c.getPlayer().checkBerserk();
   }
 }
Example #3
0
 public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   if (!c.getPlayer().isAlive()) {
     c.announce(MaplePacketCreator.enableActions());
     return;
   }
   slea.readInt();
   byte slot = (byte) slea.readShort();
   int itemId = slea.readInt();
   MapleCharacter player = c.getPlayer();
   IItem toUse = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
   if (toUse != null && toUse.getQuantity() == 1) {
     if (toUse.getItemId() != itemId) {
       return;
     }
     Map<String, Integer> skilldata =
         MapleItemInformationProvider.getInstance()
             .getSkillStats(toUse.getItemId(), c.getPlayer().getJob().getId());
     boolean canuse = false;
     boolean success = false;
     int skill = 0;
     int maxlevel = 0;
     if (skilldata == null) {
       return;
     }
     if (skilldata.get("skillid") == 0) {
       canuse = false;
     } else if (player.getMasterLevel(SkillFactory.getSkill(skilldata.get("skillid")))
             >= skilldata.get("reqSkillLevel")
         || skilldata.get("reqSkillLevel") == 0) {
       canuse = true;
       if (Randomizer.nextInt(101) < skilldata.get("success") && skilldata.get("success") != 0) {
         success = true;
         ISkill skill2 = SkillFactory.getSkill(skilldata.get("skillid"));
         player.changeSkillLevel(
             skill2,
             player.getSkillLevel(skill2),
             Math.max(skilldata.get("masterLevel"), player.getMasterLevel(skill2)),
             -1);
       } else {
         success = false;
         player.message(
             "The skill book lights up, but the skill winds up as if nothing happened.");
       }
       MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short) 1, false);
     } else {
       canuse = false;
     }
     player
         .getClient()
         .announce(MaplePacketCreator.skillBookSuccess(player, skill, maxlevel, canuse, success));
   }
 }
 public static void removeFromSlot(
     final MapleClient c,
     final MapleInventoryType type,
     final short slot,
     final short quantity,
     final boolean fromDrop,
     final boolean consume) {
   final IItem item = c.getPlayer().getInventory(type).getItem(slot);
   final boolean allowZero = consume && InventoryConstants.isRechargable(item.getId());
   c.getPlayer().getInventory(type).removeItem(slot, quantity, allowZero);
   if (item.getQuantity() == 0 && !allowZero) {
     c.announce(InventoryFactory.clearInventoryItem(type, item.getPosition(), fromDrop));
   } else {
     c.announce(InventoryFactory.updateInventorySlot(type, (Item) item, fromDrop));
   }
 }
 private static final void dropItem(MapleClient c, IItem target, Point dropPos) {
   if (MapleItemInformationProvider.getInstance().isDropRestricted(target.getId())
       || c.getPlayer().gmLevel() == 1
       || c.getPlayer().gmLevel() == 2) {
     c.getPlayer()
         .getMap()
         .disappearingItemDrop(
             c.getPlayer().getObjectId(),
             c.getPlayer().getPosition(),
             c.getPlayer(),
             target,
             dropPos);
   } else {
     c.getPlayer()
         .getMap()
         .spawnItemDrop(
             c.getPlayer().getObjectId(),
             c.getPlayer().getPosition(),
             c.getPlayer(),
             target,
             dropPos,
             true,
             !c.getPlayer().getMap().getEverlast());
   }
 }
Example #6
0
  public void saveItems(boolean shutdown) throws SQLException {
    List<ItemInventoryEntry> itemsWithType = new ArrayList<ItemInventoryEntry>();

    for (MaplePlayerShopItem pItems : items) {
      IItem newItem = pItems.getItem();
      if (shutdown) {
        newItem.setQuantity((short) (pItems.getItem().getQuantity() * pItems.getBundles()));
      } else {
        newItem.setQuantity(pItems.getItem().getQuantity());
      }
      if (pItems.getBundles() > 0) {
        itemsWithType.add(
            new ItemInventoryEntry(newItem, MapleInventoryType.getByType(newItem.getType())));
      }
    }
    ItemFactory.MERCHANT.saveItems(itemsWithType, this.ownerId);
  }
Example #7
0
 private boolean fitsInInventory() {
   MapleItemInformationProvider mii = MapleItemInformationProvider.getInstance();
   Map<MapleInventoryType, Integer> neededSlots = new LinkedHashMap<MapleInventoryType, Integer>();
   for (IItem item : exchangeItems) {
     MapleInventoryType type = mii.getInventoryType(item.getItemId());
     if (neededSlots.get(type) == null) {
       neededSlots.put(type, 1);
     } else {
       neededSlots.put(type, neededSlots.get(type) + 1);
     }
   }
   for (Map.Entry<MapleInventoryType, Integer> entry : neededSlots.entrySet()) {
     if (chr.getInventory(entry.getKey()).isFull(entry.getValue() - 1)) {
       return false;
     }
   }
   return true;
 }
 public static void drop(MapleClient c, MapleInventoryType type, short src, short quantity) {
   if (src < 0) {
     type = MapleInventoryType.EQUIPPED;
   }
   IItem source = c.getPlayer().getInventory(type).getItem(src);
   int Id = source.getId();
   if (c.getPlayer().getItemEffect() == Id && source.getQuantity() == 1) {
     c.getPlayer().setItemEffect(0);
     c.getPlayer().getMap().broadcastMessage(EffectFactory.itemEffect(c.getPlayer().getId(), 0));
   } else if (Id == 5370000 || Id == 5370001) { // not actually possible
     if (c.getPlayer().getItemQuantity(Id, false) == 1) {
       c.getPlayer().setChalkboard(null);
     }
   } else if ((Id >= 5000000 && Id <= 5000100) || Id == 4031284) {
     c.getPlayer().dropMessage("This item may not be dropped.");
     return;
   }
   if (c.getPlayer().getItemQuantity(Id, true) < quantity
       || quantity < 0
       || source == null
       || source.getFlag() == InventoryConstants.LOCK
       || (quantity == 0 && !InventoryConstants.isRechargable(Id))) {
     return;
   }
   Point dropPos = new Point(c.getPlayer().getPosition());
   if (quantity < source.getQuantity() && !InventoryConstants.isRechargable(Id)) {
     IItem target = source.copy();
     target.setQuantity(quantity);
     source.setQuantity((short) (source.getQuantity() - quantity));
     c.announce(InventoryFactory.dropInventoryItemUpdate(type, source));
     dropItem(c, target, dropPos);
   } else {
     c.getPlayer().getInventory(type).removeSlot(src);
     c.announce(
         InventoryFactory.dropInventoryItem((src < 0 ? MapleInventoryType.EQUIP : type), src));
     if (src < 0) {
       c.getPlayer().equipChanged();
     }
     dropItem(c, source, dropPos);
   }
 }
 public static void removeById(
     final MapleClient c,
     final MapleInventoryType type,
     final int Id,
     final int quantity,
     final boolean fromDrop,
     final boolean consume) {
   List<IItem> items = c.getPlayer().getInventory(type).listById(Id);
   int remremove = quantity;
   for (IItem item : items) {
     if (remremove <= item.getQuantity()) {
       removeFromSlot(c, type, item.getPosition(), (short) remremove, fromDrop, consume);
       remremove = 0;
       break;
     } else {
       remremove -= item.getQuantity();
       removeFromSlot(c, type, item.getPosition(), item.getQuantity(), fromDrop, consume);
     }
   }
   if (remremove > 0) {
     throw new RuntimeException(
         "[h4x] Not enough items available ("
             + Id
             + ", "
             + (quantity - remremove)
             + "/"
             + quantity
             + ")");
   }
 }
Example #10
0
 private void complete2() {
   items.clear();
   meso = 0;
   for (IItem item : exchangeItems) {
     if ((item.getFlag() & InventoryConstants.KARMA) == InventoryConstants.KARMA) {
       item.setFlag(
           (byte)
               (item.getFlag()
                   ^ InventoryConstants
                       .KARMA)); // items with scissors of karma used on them are reset once traded
     }
     MapleInventoryManipulator.addFromDrop(chr.getClient(), item, true);
   }
   if (exchangeMeso > 0) {
     int overflow = chr.updateMesosGetOverflow(exchangeMeso - getFee(exchangeMeso));
     partner.chr.gainMeso(overflow, true);
   }
   exchangeMeso = 0;
   if (exchangeItems != null) {
     exchangeItems.clear();
   }
   chr.getClient().getSession().write(MaplePacketCreator.getTradeCompletion(number));
 }
  public static void move(
      final MapleClient c, final MapleInventoryType type, final short src, final short dst) {
    if (src < 0 || dst < 0) {
      return;
    }
    final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    final IItem source = c.getPlayer().getInventory(type).getItem(src);
    final IItem initialTarget = c.getPlayer().getInventory(type).getItem(dst);
    if (source == null) {
      return;
    }

    short olddstQ = -1;
    if (initialTarget != null) {
      olddstQ = initialTarget.getQuantity();
    }
    final short oldsrcQ = source.getQuantity();
    final short slotMax = ii.getSlotMax(c, source.getId());

    c.getPlayer().getInventory(type).move(src, dst, slotMax);
    if (!type.equals(MapleInventoryType.EQUIP)
        && initialTarget != null
        && initialTarget.getId() == source.getId()
        && !InventoryConstants.isRechargable(source.getId())) {
      if ((olddstQ + oldsrcQ) > slotMax) {
        c.announce(
            InventoryFactory.moveAndMergeWithRestInventoryItem(
                type, src, dst, (short) ((olddstQ + oldsrcQ) - slotMax), slotMax));
      } else {
        c.announce(
            InventoryFactory.moveAndMergeInventoryItem(
                type,
                src,
                dst,
                ((Item) c.getPlayer().getInventory(type).getItem(dst)).getQuantity()));
      }
    } else {
      c.announce(InventoryFactory.moveInventoryItem(type, src, dst));
    }
  }
Example #12
0
 public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   if (!c.getPlayer().getCashShop().isOpened()) {
     return;
   }
   if (slea.available() > 0) {
     byte op = slea.readByte();
     if (op == 2) { // put item up for sale
       byte itemtype = slea.readByte();
       int itemid = slea.readInt();
       slea.readShort();
       slea.skip(7);
       short stars = 1;
       if (itemtype == 1) {
         slea.skip(32);
       } else {
         stars = slea.readShort();
       }
       slea.readMapleAsciiString(); // another useless thing (owner)
       if (itemtype == 1) {
         slea.skip(32);
       } else {
         slea.readShort();
       }
       byte slot = 1;
       short quantity = 1;
       if (itemtype != 1) {
         if (itemid / 10000 == 207 || itemid / 10000 == 233) {
           slea.skip(8);
         }
         slot = (byte) slea.readInt();
       } else {
         slot = (byte) slea.readInt();
       }
       if (itemtype != 1) {
         if (itemid / 10000 == 207 || itemid / 10000 == 233) {
           quantity = stars;
           slea.skip(4);
         } else {
           quantity = (short) slea.readInt();
         }
       } else {
         quantity = (byte) slea.readInt();
       }
       int price = slea.readInt();
       if (itemtype == 1) {
         quantity = 1;
       }
       if (quantity < 0
           || price < 110
           || c.getPlayer().getItemQuantity(itemid, false) < quantity) {
         return;
       }
       MapleInventoryType type =
           MapleItemInformationProvider.getInstance().getInventoryType(itemid);
       IItem i = c.getPlayer().getInventory(type).getItem(slot).copy();
       if (i != null && c.getPlayer().getMeso() >= 5000) {
         Connection con = DatabaseConnection.getConnection();
         try {
           PreparedStatement ps =
               con.prepareStatement("SELECT COUNT(*) FROM mts_items WHERE seller = ?");
           ps.setInt(1, c.getPlayer().getId());
           ResultSet rs = ps.executeQuery();
           if (rs.next()) {
             if (rs.getInt(1) > 10) { // They have more than 10
               // items up for sale
               // already!
               c.getPlayer().dropMessage(1, "You already have 10 items up for auction!");
               c.announce(getMTS(1, 0, 0));
               c.announce(
                   MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
               c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
               rs.close();
               ps.close();
               return;
             }
           }
           rs.close();
           ps.close();
           Calendar calendar = Calendar.getInstance();
           int year = 2008;
           int month = 6;
           int day = 17;
           int oldmax = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
           int oldday = calendar.get(Calendar.DAY_OF_MONTH) + 7;
           if (oldmax < oldday) {
             if (calendar.get(Calendar.MONTH) + 2 > 12) {
               year = calendar.get(Calendar.YEAR) + 1;
               month = 1;
               calendar.set(year, month, 1);
               day = oldday - oldmax;
             } else {
               month = calendar.get(Calendar.MONTH) + 2;
               year = calendar.get(Calendar.YEAR);
               calendar.set(year, month, 1);
               day = oldday - oldmax;
             }
           } else {
             day = calendar.get(Calendar.DAY_OF_MONTH) + 7;
             month = calendar.get(Calendar.MONTH);
             year = calendar.get(Calendar.YEAR);
           }
           String date = year + "-";
           if (month < 10) {
             date += "0" + month + "-";
           } else {
             date += month + "-";
           }
           if (day < 10) {
             date += "0" + day;
           } else {
             date += day + "";
           }
           if (i.getType() == 2) {
             Item item = (Item) i;
             ps =
                 con.prepareStatement(
                     "INSERT INTO mts_items (tab, type, itemid, quantity, seller, price, owner, sellername, sell_ends) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
             ps.setInt(1, 1);
             ps.setInt(2, (int) type.getType());
             ps.setInt(3, item.getItemId());
             ps.setInt(4, quantity);
             ps.setInt(5, c.getPlayer().getId());
             ps.setInt(6, price);
             ps.setString(7, item.getOwner());
             ps.setString(8, c.getPlayer().getName());
             ps.setString(9, date);
           } else {
             Equip equip = (Equip) i;
             ps =
                 con.prepareStatement(
                     "INSERT INTO mts_items (tab, type, itemid, quantity, seller, price, upgradeslots, level, str, dex, `int`, luk, hp, mp, watk, matk, wdef, mdef, acc, avoid, hands, speed, jump, locked, owner, sellername, sell_ends, vicious, flag) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
             ps.setInt(1, 1);
             ps.setInt(2, (int) type.getType());
             ps.setInt(3, equip.getItemId());
             ps.setInt(4, quantity);
             ps.setInt(5, c.getPlayer().getId());
             ps.setInt(6, price);
             ps.setInt(7, equip.getUpgradeSlots());
             ps.setInt(8, equip.getLevel());
             ps.setInt(9, equip.getStr());
             ps.setInt(10, equip.getDex());
             ps.setInt(11, equip.getInt());
             ps.setInt(12, equip.getLuk());
             ps.setInt(13, equip.getHp());
             ps.setInt(14, equip.getMp());
             ps.setInt(15, equip.getWatk());
             ps.setInt(16, equip.getMatk());
             ps.setInt(17, equip.getWdef());
             ps.setInt(18, equip.getMdef());
             ps.setInt(19, equip.getAcc());
             ps.setInt(20, equip.getAvoid());
             ps.setInt(21, equip.getHands());
             ps.setInt(22, equip.getSpeed());
             ps.setInt(23, equip.getJump());
             ps.setInt(24, 0);
             ps.setString(25, equip.getOwner());
             ps.setString(26, c.getPlayer().getName());
             ps.setString(27, date);
             ps.setInt(28, equip.getVicious());
             ps.setInt(29, equip.getFlag());
           }
           ps.executeUpdate();
           ps.close();
           MapleInventoryManipulator.removeFromSlot(c, type, slot, quantity, false);
         } catch (SQLException e) {
         }
         c.getPlayer().gainMeso(-5000, false);
         c.announce(MaplePacketCreator.MTSConfirmSell());
         c.announce(getMTS(1, 0, 0));
         c.announce(MaplePacketCreator.enableCSUse());
         c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
         c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
       }
     } else if (op == 3) { // send offer for wanted item
     } else if (op == 4) { // list wanted item
       slea.readInt();
       slea.readInt();
       slea.readInt();
       slea.readShort();
       slea.readMapleAsciiString();
     } else if (op == 5) { // change page
       int tab = slea.readInt();
       int type = slea.readInt();
       int page = slea.readInt();
       c.getPlayer().changePage(page);
       if (tab == 4 && type == 0) {
         c.announce(getCart(c.getPlayer().getId()));
       } else if (tab == c.getPlayer().getCurrentTab()
           && type == c.getPlayer().getCurrentType()
           && c.getPlayer().getSearch() != null) {
         c.announce(
             getMTSSearch(
                 tab, type, c.getPlayer().getCurrentCI(), c.getPlayer().getSearch(), page));
       } else {
         c.getPlayer().setSearch(null);
         c.announce(getMTS(tab, type, page));
       }
       c.getPlayer().changeTab(tab);
       c.getPlayer().changeType(type);
       c.announce(MaplePacketCreator.enableCSUse());
       c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
       c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
     } else if (op == 6) { // search
       int tab = slea.readInt();
       int type = slea.readInt();
       slea.readInt();
       int ci = slea.readInt();
       String search = slea.readMapleAsciiString();
       c.getPlayer().setSearch(search);
       c.getPlayer().changeTab(tab);
       c.getPlayer().changeType(type);
       c.getPlayer().changeCI(ci);
       c.announce(MaplePacketCreator.enableCSUse());
       c.announce(MaplePacketCreator.enableActions());
       c.announce(getMTSSearch(tab, type, ci, search, c.getPlayer().getCurrentPage()));
       c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
       c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
       c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
     } else if (op == 7) { // cancel sale
       int id = slea.readInt(); // id of the item
       Connection con = DatabaseConnection.getConnection();
       try {
         PreparedStatement ps =
             con.prepareStatement("UPDATE mts_items SET transfer = 1 WHERE id = ? AND seller = ?");
         ps.setInt(1, id);
         ps.setInt(2, c.getPlayer().getId());
         ps.executeUpdate();
         ps.close();
         ps = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ?");
         ps.setInt(1, id);
         ps.executeUpdate();
         ps.close();
       } catch (SQLException e) {
         e.printStackTrace();
       }
       c.announce(MaplePacketCreator.enableCSUse());
       c.announce(
           getMTS(
               c.getPlayer().getCurrentTab(),
               c.getPlayer().getCurrentType(),
               c.getPlayer().getCurrentPage()));
       c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
       c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
     } else if (op == 8) { // transfer item from transfer inv.
       int id = slea.readInt(); // id of the item
       Connection con = DatabaseConnection.getConnection();
       PreparedStatement ps;
       ResultSet rs;
       try {
         ps =
             con.prepareStatement(
                 "SELECT * FROM mts_items WHERE seller = ? AND transfer = 1  AND id= ? ORDER BY id DESC");
         ps.setInt(1, c.getPlayer().getId());
         ps.setInt(2, id);
         rs = ps.executeQuery();
         if (rs.next()) {
           IItem i;
           if (rs.getInt("type") != 1) {
             Item ii = new Item(rs.getInt("itemid"), (byte) 0, (short) rs.getInt("quantity"));
             ii.setOwner(rs.getString("owner"));
             ii.setPosition(
                 c.getPlayer()
                     .getInventory(
                         MapleItemInformationProvider.getInstance()
                             .getInventoryType(rs.getInt("itemid")))
                     .getNextFreeSlot());
             i = ii.copy();
           } else {
             Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
             equip.setOwner(rs.getString("owner"));
             equip.setQuantity((short) 1);
             equip.setAcc((short) rs.getInt("acc"));
             equip.setAvoid((short) rs.getInt("avoid"));
             equip.setDex((short) rs.getInt("dex"));
             equip.setHands((short) rs.getInt("hands"));
             equip.setHp((short) rs.getInt("hp"));
             equip.setInt((short) rs.getInt("int"));
             equip.setJump((short) rs.getInt("jump"));
             equip.setLuk((short) rs.getInt("luk"));
             equip.setMatk((short) rs.getInt("matk"));
             equip.setMdef((short) rs.getInt("mdef"));
             equip.setMp((short) rs.getInt("mp"));
             equip.setSpeed((short) rs.getInt("speed"));
             equip.setStr((short) rs.getInt("str"));
             equip.setWatk((short) rs.getInt("watk"));
             equip.setWdef((short) rs.getInt("wdef"));
             equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
             equip.setLevel((byte) rs.getInt("level"));
             equip.setVicious((byte) rs.getInt("vicious"));
             equip.setFlag((byte) rs.getInt("flag"));
             equip.setPosition(
                 c.getPlayer()
                     .getInventory(
                         MapleItemInformationProvider.getInstance()
                             .getInventoryType(rs.getInt("itemid")))
                     .getNextFreeSlot());
             i = equip.copy();
           }
           PreparedStatement pse =
               con.prepareStatement(
                   "DELETE FROM mts_items WHERE id = ? AND seller = ? AND transfer = 1");
           pse.setInt(1, id);
           pse.setInt(2, c.getPlayer().getId());
           pse.executeUpdate();
           pse.close();
           MapleInventoryManipulator.addFromDrop(c, i, false);
           c.announce(MaplePacketCreator.enableCSUse());
           c.announce(getCart(c.getPlayer().getId()));
           c.announce(
               getMTS(
                   c.getPlayer().getCurrentTab(),
                   c.getPlayer().getCurrentType(),
                   c.getPlayer().getCurrentPage()));
           c.announce(MaplePacketCreator.MTSConfirmTransfer(i.getQuantity(), i.getPosition()));
           c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
         }
         rs.close();
         ps.close();
       } catch (SQLException e) {
         Output.print("MTS Transfer error: " + e);
       }
     } else if (op == 9) { // add to cart
       int id = slea.readInt(); // id of the item
       Connection con = DatabaseConnection.getConnection();
       try {
         PreparedStatement ps1 =
             con.prepareStatement("SELECT * FROM mts_items WHERE id = ? AND seller <> ?");
         ps1.setInt(1, id); // Previene que agregues al cart tus
         // propios items
         ps1.setInt(2, c.getPlayer().getId());
         ResultSet rs1 = ps1.executeQuery();
         if (rs1.next()) {
           PreparedStatement ps =
               con.prepareStatement("SELECT * FROM mts_cart WHERE cid = ? AND itemid = ?");
           ps.setInt(1, c.getPlayer().getId());
           ps.setInt(2, id);
           ResultSet rs = ps.executeQuery();
           if (!rs.next()) {
             PreparedStatement pse =
                 con.prepareStatement("INSERT INTO mts_cart (cid, itemid) VALUES (?, ?)");
             pse.setInt(1, c.getPlayer().getId());
             pse.setInt(2, id);
             pse.executeUpdate();
             pse.close();
           }
           rs.close();
         }
         rs1.close();
       } catch (SQLException e) {
         e.printStackTrace();
       }
       c.announce(
           getMTS(
               c.getPlayer().getCurrentTab(),
               c.getPlayer().getCurrentType(),
               c.getPlayer().getCurrentPage()));
       c.announce(MaplePacketCreator.enableCSUse());
       c.announce(MaplePacketCreator.enableActions());
       c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
       c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
     } else if (op == 10) { // delete from cart
       int id = slea.readInt(); // id of the item
       Connection con = DatabaseConnection.getConnection();
       try {
         PreparedStatement ps =
             con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ? AND cid = ?");
         ps.setInt(1, id);
         ps.setInt(2, c.getPlayer().getId());
         ps.executeUpdate();
         ps.close();
       } catch (SQLException e) {
         e.printStackTrace();
       }
       c.announce(getCart(c.getPlayer().getId()));
       c.announce(MaplePacketCreator.enableCSUse());
       c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
       c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
     } else if (op == 12) { // put item up for auction
     } else if (op == 13) { // cancel wanted cart thing
     } else if (op == 14) { // buy auction item now
     } else if (op == 16) { // buy
       int id = slea.readInt(); // id of the item
       Connection con = DatabaseConnection.getConnection();
       PreparedStatement ps;
       ResultSet rs;
       try {
         ps = con.prepareStatement("SELECT * FROM mts_items WHERE id = ? ORDER BY id DESC");
         ps.setInt(1, id);
         rs = ps.executeQuery();
         if (rs.next()) {
           int price = rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1); // taxes
           if (c.getPlayer().getCashShop().getCash(4) >= price) { // FIX
             boolean alwaysnull = true;
             for (Channel cserv : Server.getInstance().getAllChannels()) {
               MapleCharacter victim =
                   cserv.getPlayerStorage().getCharacterById(rs.getInt("seller"));
               if (victim != null) {
                 victim.getCashShop().gainCash(4, rs.getInt("price"));
                 alwaysnull = false;
               }
             }
             if (alwaysnull) {
               PreparedStatement pse =
                   con.prepareStatement("SELECT accountid FROM characters WHERE id = ?");
               pse.setInt(1, rs.getInt("seller"));
               ResultSet rse = pse.executeQuery();
               if (rse.next()) {
                 PreparedStatement psee =
                     con.prepareStatement(
                         "UPDATE accounts SET nxPrepaid = nxPrepaid + ? WHERE id = ?");
                 psee.setInt(1, rs.getInt("price"));
                 psee.setInt(2, rse.getInt("accountid"));
                 psee.executeUpdate();
                 psee.close();
               }
               pse.close();
               rse.close();
             }
             PreparedStatement pse =
                 con.prepareStatement(
                     "UPDATE mts_items SET seller = ?, transfer = 1 WHERE id = ?");
             pse.setInt(1, c.getPlayer().getId());
             pse.setInt(2, id);
             pse.executeUpdate();
             pse.close();
             pse = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ?");
             pse.setInt(1, id);
             pse.executeUpdate();
             pse.close();
             c.getPlayer().getCashShop().gainCash(4, -price);
             c.announce(MaplePacketCreator.enableCSUse());
             c.announce(
                 getMTS(
                     c.getPlayer().getCurrentTab(),
                     c.getPlayer().getCurrentType(),
                     c.getPlayer().getCurrentPage()));
             c.announce(MaplePacketCreator.MTSConfirmBuy());
             c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
             c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
             c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
             c.announce(MaplePacketCreator.enableActions());
           } else {
             c.announce(MaplePacketCreator.MTSFailBuy());
           }
         }
         rs.close();
         ps.close();
       } catch (SQLException e) {
         c.announce(MaplePacketCreator.MTSFailBuy());
       }
     } else if (op == 17) { // buy from cart
       int id = slea.readInt(); // id of the item
       Connection con = DatabaseConnection.getConnection();
       PreparedStatement ps;
       ResultSet rs;
       try {
         ps = con.prepareStatement("SELECT * FROM mts_items WHERE id = ? ORDER BY id DESC");
         ps.setInt(1, id);
         rs = ps.executeQuery();
         if (rs.next()) {
           int price = rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1);
           if (c.getPlayer().getCashShop().getCash(4) >= price) {
             for (Channel cserv : Server.getInstance().getAllChannels()) {
               MapleCharacter victim =
                   cserv.getPlayerStorage().getCharacterById(rs.getInt("seller"));
               if (victim != null) {
                 victim.getCashShop().gainCash(4, rs.getInt("price"));
               } else {
                 PreparedStatement pse =
                     con.prepareStatement("SELECT accountid FROM characters WHERE id = ?");
                 pse.setInt(1, rs.getInt("seller"));
                 ResultSet rse = pse.executeQuery();
                 if (rse.next()) {
                   PreparedStatement psee =
                       con.prepareStatement(
                           "UPDATE accounts SET nxPrepaid = nxPrepaid + ? WHERE id = ?");
                   psee.setInt(1, rs.getInt("price"));
                   psee.setInt(2, rse.getInt("accountid"));
                   psee.executeUpdate();
                   psee.close();
                 }
                 pse.close();
                 rse.close();
               }
             }
             PreparedStatement pse =
                 con.prepareStatement(
                     "UPDATE mts_items SET seller = ?, transfer = 1 WHERE id = ?");
             pse.setInt(1, c.getPlayer().getId());
             pse.setInt(2, id);
             pse.executeUpdate();
             pse.close();
             pse = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ?");
             pse.setInt(1, id);
             pse.executeUpdate();
             pse.close();
             c.getPlayer().getCashShop().gainCash(4, -price);
             c.announce(getCart(c.getPlayer().getId()));
             c.announce(MaplePacketCreator.enableCSUse());
             c.announce(MaplePacketCreator.MTSConfirmBuy());
             c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
             c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
             c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
           } else {
             c.announce(MaplePacketCreator.MTSFailBuy());
           }
         }
         rs.close();
         ps.close();
       } catch (SQLException e) {
         c.announce(MaplePacketCreator.MTSFailBuy());
       }
     } else {
       System.out.println("Unhandled OP(MTS): " + op + " Packet: " + slea.toString());
     }
   } else {
     c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
   }
 }
 public static boolean addById(MapleClient c, int Id, short quantity, String owner, int petid) {
   final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
   final MapleInventoryType type = ii.getInventoryType(Id);
   if (!type.equals(MapleInventoryType.EQUIP)) {
     final short slotMax = ii.getSlotMax(c, Id);
     final List<IItem> existing = c.getPlayer().getInventory(type).listById(Id);
     if (!InventoryConstants.isRechargable(Id)) {
       if (existing.size() > 0) { // first update all existing slots to slotMax
         Iterator<IItem> i = existing.iterator();
         while (quantity > 0) {
           if (i.hasNext()) {
             Item eItem = (Item) i.next();
             short oldQ = eItem.getQuantity();
             if (oldQ < slotMax && (eItem.getOwner().equals(owner) || owner == null)) {
               short newQ = (short) Math.min(oldQ + quantity, slotMax);
               quantity -= (newQ - oldQ);
               eItem.setQuantity(newQ);
               c.announce(InventoryFactory.updateInventorySlot(type, eItem));
             }
           } else {
             break;
           }
         }
       }
       while (quantity > 0 || InventoryConstants.isRechargable(Id)) {
         short newQ = (short) Math.min(quantity, slotMax);
         if (newQ != 0) {
           quantity -= newQ;
           Item nItem = new Item(Id, (short) 0, newQ, petid);
           short newSlot = c.getPlayer().getInventory(type).addItem(nItem);
           if (newSlot == -1) {
             c.announce(InventoryFactory.getInventoryFull());
             c.announce(InventoryFactory.getShowInventoryFull());
             return false;
           }
           if (owner != null) {
             nItem.setOwner(owner);
           }
           c.announce(InventoryFactory.addInventorySlot(type, nItem));
           if ((InventoryConstants.isRechargable(Id)) && quantity == 0) {
             break;
           }
         } else {
           c.announce(IntraPersonalFactory.enableActions());
           return false;
         }
       }
     } else {
       final Item nItem = new Item(Id, (short) 0, quantity);
       final short newSlot = c.getPlayer().getInventory(type).addItem(nItem);
       if (newSlot == -1) {
         c.announce(InventoryFactory.getInventoryFull());
         c.announce(InventoryFactory.getShowInventoryFull());
         return false;
       }
       c.announce(InventoryFactory.addInventorySlot(type, nItem));
       c.announce(IntraPersonalFactory.enableActions());
     }
   } else if (quantity == 1) {
     IItem nEquip = ii.getEquipById(Id);
     if (owner != null) {
       nEquip.setOwner(owner);
     }
     short newSlot = c.getPlayer().getInventory(type).addItem(nEquip);
     if (newSlot == -1) {
       c.announce(InventoryFactory.getInventoryFull());
       c.announce(InventoryFactory.getShowInventoryFull());
       return false;
     }
     c.announce(InventoryFactory.addInventorySlot(type, nEquip));
   } else {
     throw new RuntimeException("Trying to create equip with non-one quantity");
   }
   return true;
 }
 public static void equip(final MapleClient c, final short src, short dst) {
   Equip source = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(src);
   Equip target = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(dst);
   if (dst == -12 && target != null) {
     if (c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -13) == null) {
       dst = (short) -13;
       target = null;
     }
     for (int i = 0; i < 2; i++) {
       if (c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) (i - 16))
           == null) {
         dst = (short) (i - 16);
         target = null;
       }
     }
     if (target != null) {
       return;
     }
   }
   if (isPE(source.getId(), dst)
       || source == null
       || (MapleItemInformationProvider.getInstance().getReqLevel(source.getId())
               > c.getPlayer().getLevel()
           && c.getPlayer().gmLevel() < 1)
       || (((source.getId() >= 1902000 && source.getId() <= 1902002) || source.getId() == 1912000)
           && c.getPlayer().getJobType() != 0)
       || (((source.getId() >= 1902005 && source.getId() <= 1902007) || source.getId() == 1912005)
           && c.getPlayer().getJobType() != 1)
       || (((source.getId() >= 1902015 && source.getId() <= 1902018) || source.getId() == 1912011)
           && !c.getPlayer().isAran())) {
     return;
   }
   if (MapleItemInformationProvider.getInstance().isUntradeableOnEquip(source.getId())) {
     source.setFlag((byte) InventoryConstants.UNTRADEABLE);
     c.announce(InventoryFactory.updateSlot(source));
   }
   if (dst == -6) { // unequip the overall
     final IItem top = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -5);
     if (top != null && isOverall(top.getId())) {
       if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
         c.announce(InventoryFactory.getInventoryFull());
         c.announce(InventoryFactory.getShowInventoryFull());
         return;
       }
       unequip(
           c, (short) -5, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
     }
   } else if (dst == -5) { // equip overall
     final IItem bottom =
         c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -6);
     if (bottom != null && isOverall(source.getId())) {
       if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
         c.announce(InventoryFactory.getInventoryFull());
         c.announce(InventoryFactory.getShowInventoryFull());
         return;
       }
       unequip(
           c, (short) -6, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
     }
   } else if (dst == -10) { // check if weapon is two-handed
     final IItem weapon =
         c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -11);
     if (weapon != null
         && MapleItemInformationProvider.getInstance().isTwoHanded(weapon.getId())) {
       if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
         c.announce(InventoryFactory.getInventoryFull());
         c.announce(InventoryFactory.getShowInventoryFull());
         return;
       }
       unequip(
           c, (short) -11, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
     }
   } else if (dst == -11) { // unequip shield
     final IItem shield =
         c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -10);
     if (shield != null
         && MapleItemInformationProvider.getInstance().isTwoHanded(source.getId())) {
       if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
         c.announce(InventoryFactory.getInventoryFull());
         c.announce(InventoryFactory.getShowInventoryFull());
         return;
       }
       unequip(
           c, (short) -10, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
     }
   }
   if (dst == -18) {
     if (c.getPlayer().getMount() != null) {
       c.getPlayer().getMount().setId(source.getId());
     }
   }
   c.getPlayer().getInventory(MapleInventoryType.EQUIP).removeSlot(src);
   if (target != null) {
     c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).removeSlot(dst);
   }
   source.setPosition(dst);
   c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).addFromDB(source);
   if (target != null) {
     target.setPosition(src);
     c.getPlayer().getInventory(MapleInventoryType.EQUIP).addFromDB(target);
   }
   if (c.getPlayer().getBuffedValue(MapleBuffStat.BOOSTER) != null && isWeapon(source.getId())) {
     c.getPlayer().cancelBuffStats(MapleBuffStat.BOOSTER);
   }
   c.announce(InventoryFactory.moveInventoryItem(MapleInventoryType.EQUIP, src, dst, (byte) 2));
   c.getPlayer().equipChanged();
   if (source.getId() >= 1112001 && source.getId() <= 1112006) {
     c.getPlayer().setMarriageRing(MapleRing.loadFromDB(c.getPlayer()));
     c.announce(IntraPersonalFactory.getCharInfo(c.getPlayer()));
     c.getPlayer().getMap().removePlayer(c.getPlayer());
     c.getPlayer().getMap().addPlayer(c.getPlayer());
   }
 }
Example #15
0
  public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    slea.readInt(); // whatever...
    byte slot = (byte) slea.readShort();
    byte dst = (byte) slea.readShort();
    byte ws = (byte) slea.readShort();
    boolean whiteScroll = false; // white scroll being used?
    boolean legendarySpirit = false; // legendary spirit skill
    if ((ws & 2) == 2) {
      whiteScroll = true;
    }
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    IEquip toScroll = (IEquip) c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(dst);
    ISkill LegendarySpirit = SkillFactory.getSkill(1003);
    if (c.getPlayer().getSkillLevel(LegendarySpirit) > 0 && dst >= 0) {
      legendarySpirit = true;
      toScroll = (IEquip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(dst);
    }
    byte oldLevel = toScroll.getLevel();
    if (((IEquip) toScroll).getUpgradeSlots() < 1) {
      c.announce(MaplePacketCreator.getInventoryFull());
      return;
    }
    MapleInventory useInventory = c.getPlayer().getInventory(MapleInventoryType.USE);
    IItem scroll = useInventory.getItem(slot);
    IItem wscroll = null;
    List<Integer> scrollReqs = ii.getScrollReqs(scroll.getItemId());
    if (scrollReqs.size() > 0 && !scrollReqs.contains(toScroll.getItemId())) {
      c.announce(MaplePacketCreator.getInventoryFull());
      return;
    }
    if (whiteScroll) {
      wscroll = useInventory.findById(2340000);
      if (wscroll == null || wscroll.getItemId() != 2340000) {
        whiteScroll = false;
      }
    }
    if (scroll.getItemId() != 2049100 && !isCleanSlate(scroll.getItemId())) {
      if (!canScroll(scroll.getItemId(), toScroll.getItemId())) {
        return;
      }
    }
    if (scroll.getQuantity() < 1) {
      return;
    }
    try {
      IEquip scrolled = null;
      ScrollResult scrollSuccess = null;
      int sExpAdd = 0;
      Enchantment enchantment =
          (Enchantment) c.getPlayer().getPowerSkill(PowerSkillType.ENCHANTMENT);
      boolean isMultiScroll = enchantment.getMultiScrollChance() > Randomizer.nextFloat();
      int scrollMulti = 1 + (isMultiScroll ? enchantment.getMultiScrollAmount() : 0);
      if (scrollMulti > 1) sExpAdd += Randomizer.rand(0, 4);
      boolean removeSlot = enchantment.getNoSlotUse() > Randomizer.nextFloat();
      if (scrollMulti > scroll.getQuantity()) {
        scrollMulti = scroll.getQuantity();
      }
      int scrollCount = 0;
      while (scroll.getQuantity() > 0 && scrollMulti > 0) {
        scrollMulti--;
        scrollCount++;
        int scrollRerolls = enchantment.getRerolls();
        sExpAdd += scrollRerolls;

        float statMultiplier = 1 + enchantment.getExtraStats();
        if (statMultiplier > 1) sExpAdd++;

        scrolled =
            (IEquip)
                ii.scrollEquipWithId(
                    toScroll,
                    scroll.getItemId(),
                    whiteScroll,
                    removeSlot,
                    scrollRerolls,
                    statMultiplier,
                    c.getPlayer().isGM());

        if (scrolled != null && enchantment.getDoubleScroll() > Randomizer.nextFloat()) {
          scrolled =
              (IEquip)
                  ii.scrollEquipWithId(
                      scrolled,
                      scroll.getItemId(),
                      whiteScroll,
                      removeSlot,
                      scrollRerolls,
                      statMultiplier,
                      c.getPlayer().isGM());
        }

        scrollSuccess = IEquip.ScrollResult.FAIL; // fail
        if (scrolled == null) {
          scrollSuccess = IEquip.ScrollResult.CURSE;
        } else if (scrolled.getLevel() > oldLevel
            || (isCleanSlate(scroll.getItemId()) && scrolled.getLevel() == oldLevel + 1)) {
          scrollSuccess = IEquip.ScrollResult.SUCCESS;
        }
        useInventory.removeItem(scroll.getPosition(), (short) 1, false);
        if (whiteScroll) {
          useInventory.removeItem(wscroll.getPosition(), (short) 1, false);
          if (wscroll.getQuantity() < 1) {
            c.announce(
                MaplePacketCreator.clearInventoryItem(
                    MapleInventoryType.USE, wscroll.getPosition(), false));
          } else {
            c.announce(
                MaplePacketCreator.updateInventorySlot(MapleInventoryType.USE, (Item) wscroll));
          }
        }
        c.getPlayer()
            .getMap()
            .broadcastMessage(
                MaplePacketCreator.getScrollEffect(
                    c.getPlayer().getId(), scrollSuccess, legendarySpirit));
        if (scrollSuccess == IEquip.ScrollResult.CURSE) {
          break;
        }
      }
      if (scrollSuccess == IEquip.ScrollResult.CURSE) {
        scrollMulti = 0;
        c.announce(MaplePacketCreator.scrolledItem(scroll, toScroll, true));
        if (dst < 0) {
          c.getPlayer()
              .getInventory(MapleInventoryType.EQUIPPED)
              .removeItem(toScroll.getPosition());
        } else {
          c.getPlayer().getInventory(MapleInventoryType.EQUIP).removeItem(toScroll.getPosition());
        }
      } else {
        c.announce(MaplePacketCreator.scrolledItem(scroll, scrolled, false));
      }
      if (dst < 0
          && (scrollSuccess == IEquip.ScrollResult.SUCCESS
              || scrollSuccess == IEquip.ScrollResult.CURSE)) {
        c.getPlayer().equipChanged();
      }
      // sExpAdd /= initMulti;
      if (scrollCount > 1)
        c.getPlayer().message("You have successfully multi-scrolled " + scrollCount + " times!");
      c.getPlayer().addPowerSkillExp(PowerSkillType.ENCHANTMENT, sExpAdd + Randomizer.nextInt(4));
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Example #16
0
 private void addItemToDB(IItem item, int quantity, int mesos, String sName, int recipientID) {
   Connection con = DatabaseConnection.getConnection();
   try {
     PreparedStatement ps =
         con.prepareStatement(
             "INSERT INTO dueypackages (RecieverId, SenderName, Mesos, TimeStamp, Checked, Type) VALUES (?, ?, ?, ?, ?, ?)");
     ps.setInt(1, recipientID);
     ps.setString(2, sName);
     ps.setInt(3, mesos);
     ps.setString(4, getCurrentDate());
     ps.setInt(5, 1);
     if (item == null) {
       ps.setInt(6, 3);
       ps.executeUpdate();
     } else {
       ps.setInt(6, item.getType());
       ps.executeUpdate();
       ResultSet rs = ps.getGeneratedKeys();
       rs.next();
       PreparedStatement ps2;
       if (item.getType() == 1) { // equips
         ps2 =
             con.prepareStatement(
                 "INSERT INTO dueyitems (PackageId, itemid, quantity, upgradeslots, level, str, dex, `int`, luk, hp, mp, watk, matk, wdef, mdef, acc, avoid, hands, speed, jump, owner) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
         Equip eq = (Equip) item;
         ps2.setInt(2, eq.getItemId());
         ps2.setInt(3, 1);
         ps2.setInt(4, eq.getUpgradeSlots());
         ps2.setInt(5, eq.getLevel());
         ps2.setInt(6, eq.getStr());
         ps2.setInt(7, eq.getDex());
         ps2.setInt(8, eq.getInt());
         ps2.setInt(9, eq.getLuk());
         ps2.setInt(10, eq.getHp());
         ps2.setInt(11, eq.getMp());
         ps2.setInt(12, eq.getWatk());
         ps2.setInt(13, eq.getMatk());
         ps2.setInt(14, eq.getWdef());
         ps2.setInt(15, eq.getMdef());
         ps2.setInt(16, eq.getAcc());
         ps2.setInt(17, eq.getAvoid());
         ps2.setInt(18, eq.getHands());
         ps2.setInt(19, eq.getSpeed());
         ps2.setInt(20, eq.getJump());
         ps2.setString(21, eq.getOwner());
       } else {
         ps2 =
             con.prepareStatement(
                 "INSERT INTO dueyitems (PackageId, itemid, quantity, owner) VALUES (?, ?, ?, ?)");
         ps2.setInt(2, item.getItemId());
         ps2.setInt(3, quantity);
         ps2.setString(4, item.getOwner());
       }
       ps2.setInt(1, rs.getInt(1));
       ps2.executeUpdate();
       ps2.close();
       rs.close();
     }
     ps.close();
   } catch (SQLException e) {
   }
 }
 public static boolean addFromDrop(
     final MapleClient c, final IItem item, final boolean show, final boolean showAnyMessage) {
   final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
   if (ii.isPickupRestricted(item.getId())
       && c.getPlayer().getItemQuantity(item.getId(), true) > 0
       && showAnyMessage) {
     c.announce(InventoryFactory.getInventoryFull());
     c.announce(InventoryFactory.showItemUnavailable());
     return false;
   }
   final MapleInventoryType type = ii.getInventoryType(item.getId());
   short quantity = item.getQuantity();
   if (!type.equals(MapleInventoryType.EQUIP)) {
     final short slotMax = ii.getSlotMax(c, item.getId());
     final List<IItem> existing = c.getPlayer().getInventory(type).listById(item.getId());
     if (!InventoryConstants.isRechargable(item.getId())) {
       if (existing.size() > 0) { // first update all existing slots to slotMax
         Iterator<IItem> i = existing.iterator();
         while (quantity > 0) {
           if (i.hasNext()) {
             final Item eItem = (Item) i.next();
             final short oldQ = eItem.getQuantity();
             if (oldQ < slotMax && item.getOwner().equals(eItem.getOwner())) {
               short newQ = (short) Math.min(oldQ + quantity, slotMax);
               quantity -= (newQ - oldQ);
               eItem.setQuantity(newQ);
               short newQi = (short) Math.min(quantity, slotMax);
               quantity -= newQi;
               Item nItem = new Item(item.getId(), (short) 0, newQi);
               nItem.setOwner(item.getOwner());
               if (c.getPlayer().getInventory(type).fakeAddItem(nItem) == -1) {
                 eItem.setQuantity(oldQ);
                 return false;
               }
               quantity += newQi;
               c.announce(InventoryFactory.updateInventorySlot(type, eItem, showAnyMessage));
             }
           } else {
             break;
           }
         }
       }
       while (quantity > 0 || InventoryConstants.isRechargable(item.getId())) {
         final short newQ = (short) Math.min(quantity, slotMax);
         quantity -= newQ;
         final Item nItem = new Item(item.getId(), (short) 0, newQ);
         nItem.setOwner(item.getOwner());
         final short newSlot = c.getPlayer().getInventory(type).addItem(nItem);
         if (newSlot == -1) {
           if (showAnyMessage) {
             c.announce(InventoryFactory.getInventoryFull());
             c.announce(InventoryFactory.getShowInventoryFull());
           }
           item.setQuantity((short) (quantity + newQ));
           return false;
         }
         c.announce(InventoryFactory.addInventorySlot(type, nItem, true));
         if ((InventoryConstants.isRechargable(item.getId())) && quantity == 0) {
           break;
         }
       }
     } else {
       final Item nItem = new Item(item.getId(), (short) 0, quantity);
       final short newSlot = c.getPlayer().getInventory(type).addItem(nItem);
       if (newSlot == -1) {
         if (showAnyMessage) {
           c.announce(InventoryFactory.getInventoryFull());
           c.announce(InventoryFactory.getShowInventoryFull());
         }
         return false;
       }
       c.announce(InventoryFactory.addInventorySlot(type, nItem));
       c.announce(IntraPersonalFactory.enableActions());
     }
   } else if (quantity == 1) {
     final short newSlot = c.getPlayer().getInventory(type).addItem(item);
     if (newSlot == -1) {
       if (showAnyMessage) {
         c.announce(InventoryFactory.getInventoryFull());
         c.announce(InventoryFactory.getShowInventoryFull());
       }
       return false;
     }
     c.announce(InventoryFactory.addInventorySlot(type, item, true));
   } else {
     return false;
   }
   if (show) {
     c.announce(EffectFactory.getShowItemGain(item.getId(), item.getQuantity()));
   }
   return true;
 }
Example #18
0
 public void buy(MapleClient c, int item, short quantity) {
   MaplePlayerShopItem pItem = items.get(item);
   synchronized (items) {
     IItem 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 (newItem.getType() == IItem.ITEM
         && (newItem.getFlag() & ItemConstants.SPIKES) == ItemConstants.SPIKES) {
       newItem.setFlag((byte) (newItem.getFlag() ^ ItemConstants.SPIKES));
     }
     if (quantity < 1
         || pItem.getBundles() < 1
         || !pItem.isExist()
         || pItem.getBundles() < quantity) {
       c.announce(MaplePacketCreator.enableActions());
       return;
     } else if (newItem.getType() == 1 && newItem.getQuantity() > 1) {
       c.announce(MaplePacketCreator.enableActions());
       return;
     } else if (!pItem.isExist()) {
       c.announce(MaplePacketCreator.enableActions());
       return;
     }
     int price = pItem.getPrice() * quantity;
     if (c.getPlayer().getMeso() >= price) {
       if (MapleInventoryManipulator.addFromDrop(c, newItem, true)) {
         c.getPlayer().gainMeso(-price, false);
         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 {
             PreparedStatement ps =
                 DatabaseConnection.getConnection()
                     .prepareStatement(
                         "UPDATE characters SET MerchantMesos = MerchantMesos + "
                             + price
                             + " WHERE id = ?",
                         Statement.RETURN_GENERATED_KEYS);
             ps.setInt(1, ownerId);
             ps.executeUpdate();
             ps.close();
           } catch (Exception e) {
           }
         }
       } 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) {
     }
   }
 }
Example #19
0
 public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   c.getPlayer().resetAfkTime();
   byte operation = slea.readByte();
   if (operation == Actions.TOSERVER_SEND_ITEM.getCode()) {
     final int fee = 5000;
     byte inventId = slea.readByte();
     short itemPos = slea.readShort();
     short amount = slea.readShort();
     int mesos = slea.readInt();
     String recipient = slea.readMapleAsciiString();
     if (amount < 0 || amount > 2000 || itemPos < 0 || inventId > 5 || inventId < 0) {
       return;
     }
     if (mesos < 0
         || (long) mesos > Integer.MAX_VALUE
         || ((long) mesos + fee + getFee(mesos)) > Integer.MAX_VALUE) {
       return;
     }
     int finalcost = mesos + fee + getFee(mesos);
     boolean send = false;
     if (c.getPlayer().getMeso() >= finalcost) {
       int accid = getAccIdFromCNAME(recipient, true);
       if (accid != -1) {
         if (accid != c.getAccID()) {
           c.getPlayer().gainMeso(-finalcost, false);
           c.getSession()
               .write(
                   MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SUCCESSFULLY_SENT.getCode()));
           send = true;
         } else {
           c.getSession()
               .write(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SAMEACC_ERROR.getCode()));
         }
       } else {
         c.getSession()
             .write(
                 MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_NAME_DOES_NOT_EXIST.getCode()));
       }
     } else {
       c.getSession()
           .write(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_NOT_ENOUGH_MESOS.getCode()));
     }
     boolean recipientOn = false;
     MapleClient rClient = null;
     try {
       int channel = c.getChannelServer().getWorldInterface().find(recipient);
       if (channel > -1) {
         recipientOn = true;
         ChannelServer rcserv = ChannelServer.getInstance(channel);
         rClient = rcserv.getPlayerStorage().getCharacterByName(recipient).getClient();
       }
     } catch (RemoteException re) {
       c.getChannelServer().reconnectWorld();
     }
     if (send) {
       if (inventId > 0) {
         MapleInventoryType inv = MapleInventoryType.getByType(inventId);
         IItem item = c.getPlayer().getInventory(inv).getItem((byte) itemPos);
         if (item != null && c.getPlayer().getItemQuantity(item.getItemId(), false) > amount) {
           if (InventoryConstants.isRechargable(item.getItemId())) {
             MapleInventoryManipulator.removeFromSlot(
                 c, inv, (byte) itemPos, item.getQuantity(), true);
           } else {
             MapleInventoryManipulator.removeFromSlot(c, inv, (byte) itemPos, amount, true, false);
           }
           addItemToDB(
               item, amount, mesos, c.getPlayer().getName(), getAccIdFromCNAME(recipient, false));
         } else {
           return;
         }
       } else {
         addMesoToDB(mesos, c.getPlayer().getName(), getAccIdFromCNAME(recipient, false));
       }
       if (recipientOn && rClient != null) {
         rClient
             .getSession()
             .write(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_PACKAGE_MSG.getCode()));
       }
       c.getPlayer().gainMeso(-fee, false);
     }
   } else if (operation == Actions.TOSERVER_REMOVE_PACKAGE.getCode()) {
     int packageid = slea.readInt();
     removeItemFromDB(packageid);
     c.getSession().write(MaplePacketCreator.removeItemFromDuey(true, packageid));
   } else if (operation == Actions.TOSERVER_CLAIM_PACKAGE.getCode()) {
     int packageid = slea.readInt();
     List<DueyPackages> packages = new LinkedList<DueyPackages>();
     DueyPackages dp = null;
     Connection con = DatabaseConnection.getConnection();
     try {
       PreparedStatement ps =
           con.prepareStatement(
               "SELECT * FROM dueypackages LEFT JOIN dueyitems USING (PackageId) WHERE PackageId = ?"); // PLEASE WORK D:
       ps.setInt(1, packageid);
       ResultSet rs = ps.executeQuery();
       DueyPackages dueypack = null;
       if (rs.next()) {
         dueypack = getItemByPID(rs);
         dueypack.setSender(rs.getString("SenderName"));
         dueypack.setMesos(rs.getInt("Mesos"));
         dueypack.setSentTime(rs.getString("TimeStamp"));
         packages.add(dueypack);
       }
       rs.close();
       ps.close();
       dp = dueypack;
     } catch (SQLException e) {
     }
     if (dp.getItem() != null) {
       if (!MapleInventoryManipulator.checkSpace(
           c, dp.getItem().getItemId(), dp.getItem().getQuantity(), dp.getItem().getOwner())) {
         c.getPlayer().dropMessage(1, "Your inventory is full");
         c.getSession().write(MaplePacketCreator.enableActions());
         return;
       } else {
         MapleInventoryManipulator.addFromDrop(c, dp.getItem(), false);
       }
     }
     int gainmesos = 0;
     long totalmesos = (long) dp.getMesos() + (long) c.getPlayer().getMeso();
     if (totalmesos >= Integer.MAX_VALUE) {
       gainmesos = 2147383647 - c.getPlayer().getMeso();
     } else if (totalmesos < 0 || dp.getMesos() < 0) {
       // do nothing
     } else {
       c.getPlayer().gainMeso(gainmesos, false);
     }
     removeItemFromDB(packageid);
     c.getSession().write(MaplePacketCreator.removeItemFromDuey(false, packageid));
   }
 }