Advertisement
Guest User

kapuk99

a guest
Dec 31st, 2009
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.68 KB | None | 0 0
  1. package net.sf.odinms.net.channel.handler;
  2.  
  3. import net.sf.odinms.client.MapleClient;
  4. import net.sf.odinms.client.MaplePet;
  5. import net.sf.odinms.net.AbstractMaplePacketHandler;
  6. import net.sf.odinms.server.MapleInventoryManipulator;
  7. import net.sf.odinms.tools.MaplePacketCreator;
  8. import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
  9. import net.sf.odinms.server.CashItemFactory;
  10. import net.sf.odinms.server.CashItemInfo;
  11.  
  12. public final class BuyCSItemHandler extends AbstractMaplePacketHandler {
  13.     public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
  14.         final int action = slea.readByte();
  15.         slea.readByte();
  16.         if (action == 3) {
  17.             final int useNX = slea.readInt();
  18.             final int snCS = slea.readInt();
  19.             final CashItemInfo item = CashItemFactory.getInstance().getItem(snCS);
  20.             if (c.getPlayer().getCSPoints(useNX) >= item.getPrice())
  21.                 c.getPlayer().addCSPoints(useNX, -item.getPrice());
  22.             else {
  23.                 c.getSession().write(MaplePacketCreator.enableActions());
  24.                 return;
  25.             }
  26.             if (item.getId() >= 5000000 && item.getId() <= 5000100) {
  27.                 final int petId = MaplePet.createPet(item.getId());
  28.                 if (petId == -1)
  29.                     return;
  30.                 MapleInventoryManipulator.addById(c, item.getId(), (short) 1, "Cash Item was purchased.", null, petId);
  31.             } else
  32.                 MapleInventoryManipulator.addById(c, item.getId(), (short) item.getCount(), "Cash Item was purchased.");
  33.             c.getSession().write(MaplePacketCreator.showBoughtCSItem(c, item));
  34.             showCS(c);
  35.         } else if (action == 31) {
  36.             CashItemInfo item = CashItemFactory.getInstance().getItem(slea.readInt());
  37.             if (c.getPlayer().getMeso() >= item.getPrice() && (item.getId() == 4031180 || item.getId() == 4031192)) {
  38.                 c.getPlayer().gainMeso(-item.getPrice(), false);
  39.                 MapleInventoryManipulator.addById(c, item.getId(), (short) item.getCount(), null);
  40.                 c.getSession().write(MaplePacketCreator.showBoughtCSQuestItem(item.getId()));
  41.             }
  42.         }
  43.     }
  44.  
  45.     private static final void showCS(MapleClient c) {
  46.         c.getSession().write(MaplePacketCreator.showNXMapleTokens(c.getPlayer()));
  47.         c.getSession().write(MaplePacketCreator.enableCSUse0());
  48.         c.getSession().write(MaplePacketCreator.enableCSUse1());
  49.         c.getSession().write(MaplePacketCreator.enableCSUse2());
  50.         c.getSession().write(MaplePacketCreator.enableCSUse3());
  51.         c.getSession().write(MaplePacketCreator.enableActions());
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement