Пример #1
0
 public static void startTrade(MapleCharacter c) {
   if (c.getTrade() == null) {
     c.setTrade(new MapleTrade((byte) 0, c));
     c.getClient()
         .getSession()
         .write(MaplePacketCreator.getTradeStart(c.getClient(), c.getTrade(), (byte) 0));
   } else {
     c.message("You are already in a trade.");
   }
 }
Пример #2
0
 public static void inviteTrade(MapleCharacter c1, MapleCharacter c2) {
   if (c2.getTrade() == null) {
     c2.setTrade(new MapleTrade((byte) 1, c2));
     c2.getTrade().setPartner(c1.getTrade());
     c1.getTrade().setPartner(c2.getTrade());
     c2.getClient().getSession().write(MaplePacketCreator.getTradeInvite(c1));
   } else {
     c1.message("The other player is already trading with someone else.");
     cancelTrade(c1);
   }
 }
Пример #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));
   }
 }
Пример #4
0
 public static void declineTrade(MapleCharacter c) {
   MapleTrade trade = c.getTrade();
   if (trade != null) {
     if (trade.getPartner() != null) {
       MapleCharacter other = trade.getPartner().getChr();
       other.getTrade().cancel();
       other.setTrade(null);
       other.message(c.getName() + " has declined your trade request.");
     }
     trade.cancel();
     c.setTrade(null);
   }
 }
Пример #5
0
 public static void visitTrade(MapleCharacter c1, MapleCharacter c2) {
   if (c1.getTrade() != null
       && c1.getTrade().getPartner() == c2.getTrade()
       && c2.getTrade() != null
       && c2.getTrade().getPartner() == c1.getTrade()) {
     c2.getClient().getSession().write(MaplePacketCreator.getTradePartnerAdd(c1));
     c1.getClient()
         .getSession()
         .write(MaplePacketCreator.getTradeStart(c1.getClient(), c1.getTrade(), (byte) 1));
   } else {
     c1.message("The other player has already closed the trade.");
   }
 }
Пример #6
0
 public static void completeTrade(MapleCharacter c) {
   c.getTrade().lock();
   MapleTrade local = c.getTrade();
   MapleTrade partner = local.getPartner();
   if (partner.isLocked()) {
     local.complete1();
     partner.complete1();
     if (!local.fitsInInventory() || !partner.fitsInInventory()) {
       cancelTrade(c);
       c.message("There is not enough inventory space to complete the trade.");
       partner.getChr().message("There is not enough inventory space to complete the trade.");
       return;
     }
     if (local.getChr().getLevel() < 15) {
       if (local.getChr().getMesosTraded() + local.exchangeMeso > 1000000) {
         cancelTrade(c);
         local.getChr().getClient().getSession().write(MaplePacketCreator.sendMesoLimit());
         return;
       } else {
         local.getChr().addMesosTraded(local.exchangeMeso);
       }
     } else if (c.getTrade().getChr().getLevel() < 15) {
       if (c.getMesosTraded() + c.getTrade().exchangeMeso > 1000000) {
         cancelTrade(c);
         c.getClient().getSession().write(MaplePacketCreator.sendMesoLimit());
         return;
       } else {
         c.addMesosTraded(local.exchangeMeso);
       }
     }
     local.complete2();
     partner.complete2();
     partner.getChr().setTrade(null);
     c.setTrade(null);
   }
 }