Esempio n. 1
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();
   }
 }
Esempio n. 2
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));
   }
 }
Esempio n. 3
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;
 }
Esempio n. 4
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));
   }
 }
Esempio n. 5
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) {
   }
 }
Esempio n. 6
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();
    }
  }