ItemPickupHandler.java
上传用户:gwt600
上传日期:2021-06-03
资源大小:704k
文件大小:6k
源码类别:

游戏

开发平台:

Java

  1. /*
  2. This file is part of the OdinMS Maple Story Server
  3. Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc> 
  4. Matthias Butz <matze@odinms.de>
  5. Jan Christian Meyer <vimes@odinms.de>
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Affero General Public License version 3
  8. as published by the Free Software Foundation. You may not use, modify
  9. or distribute this program under any other version of the
  10. GNU Affero General Public License.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU Affero General Public License for more details.
  15. You should have received a copy of the GNU Affero General Public License
  16. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18. /*
  19.  * ItemPickupHandler.java
  20.  *
  21.  * Created on 29. November 2007, 13:39
  22.  */
  23. package net.sf.odinms.net.channel.handler;
  24. import net.sf.odinms.client.MapleCharacter;
  25. import net.sf.odinms.net.channel.ChannelServer;
  26. import net.sf.odinms.net.world.MaplePartyCharacter;
  27. import net.sf.odinms.client.MapleClient;
  28. import net.sf.odinms.server.AutobanManager;
  29. import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
  30. import net.sf.odinms.client.MaplePet;
  31. import net.sf.odinms.net.AbstractMaplePacketHandler;
  32. import net.sf.odinms.server.MapleInventoryManipulator;
  33. import net.sf.odinms.server.maps.MapleMapItem;
  34. import net.sf.odinms.server.maps.MapleMapObject;
  35. import net.sf.odinms.tools.MaplePacketCreator;
  36. import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
  37. /**
  38.  *
  39.  * @author Matze
  40.  */
  41. public class ItemPickupHandler extends AbstractMaplePacketHandler {
  42.     /** Creates a new instance of ItemPickupHandler */
  43.     public ItemPickupHandler() {
  44.     }
  45.     public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
  46.         c.getPlayer().resetAfkTime();
  47.         @SuppressWarnings("unused")
  48.         byte mode = slea.readByte(); // or something like that... but better ignore it if you want
  49.         // mapchange to work! o.o!
  50.         slea.readInt(); //?
  51.         slea.readInt(); // position, but we dont need it o.o
  52.         int oid = slea.readInt();
  53.         MapleMapObject ob = c.getPlayer().getMap().getMapObject(oid);
  54.         if (ob == null) {
  55.             c.getSession().write(MaplePacketCreator.getInventoryFull());
  56.             c.getSession().write(MaplePacketCreator.getShowInventoryFull());
  57.             return;
  58.         }
  59.         if (ob instanceof MapleMapItem) {
  60.             MapleMapItem mapitem = (MapleMapItem) ob;
  61.             synchronized (mapitem) {
  62.                 if (mapitem.isPickedUp()) {
  63.                     c.getSession().write(MaplePacketCreator.getInventoryFull());
  64.                     c.getSession().write(MaplePacketCreator.getShowInventoryFull());
  65.                     return;
  66.                 }
  67.                 double distance = c.getPlayer().getPosition().distanceSq(mapitem.getPosition());
  68.                 // c.getPlayer().getCheatTracker().checkPickupAgain();
  69.                 if (mapitem.getMeso() > 0) {
  70.                     if (c.getPlayer().getParty() != null) {
  71.                         ChannelServer cserv = c.getChannelServer();
  72.                         int mesosamm = mapitem.getMeso();
  73.                         int partynum = 0;
  74.                         for (MaplePartyCharacter partymem : c.getPlayer().getParty().getMembers()) {
  75.                             if (partymem.isOnline() && partymem.getMapid() == c.getPlayer().getMap().getId() && partymem.getChannel() == c.getChannel()) {
  76.                                 partynum++;
  77.                             }
  78.                         }
  79.                         int mesosgain = mesosamm / partynum;
  80.                         for (MaplePartyCharacter partymem : c.getPlayer().getParty().getMembers()) {
  81.                             if (partymem.isOnline() && partymem.getMapid() == c.getPlayer().getMap().getId()) {
  82.                                 MapleCharacter somecharacter = cserv.getPlayerStorage().getCharacterById(partymem.getId());
  83.                                 if (somecharacter != null) {
  84.                                     somecharacter.gainMeso(mesosgain, true, true);
  85.                                 }
  86.                             }
  87.                         }
  88.                     } else {
  89.                         c.getPlayer().gainMeso(mapitem.getMeso(), true, true);
  90.                     }
  91.                     c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 2, c.getPlayer().getId()), mapitem.getPosition());
  92.                     c.getPlayer().getCheatTracker().pickupComplete();
  93.                     c.getPlayer().getMap().removeMapObject(ob);
  94.                 } else {
  95.                     if (mapitem.getItem().getItemId() >= 5000000 && mapitem.getItem().getItemId() <= 5000100) {
  96.                         int petId = MaplePet.createPet(mapitem.getItem().getItemId());
  97.                         if (petId == -1) {
  98.                             return;
  99.                         }
  100.                         MapleInventoryManipulator.addById(c, mapitem.getItem().getItemId(), mapitem.getItem().getQuantity(), null, petId);
  101.                         c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 2, c.getPlayer().getId()), mapitem.getPosition());
  102.                         // c.getPlayer().getCheatTracker().pickupComplete();
  103.                         c.getPlayer().getMap().removeMapObject(ob);
  104.                     } else {
  105.                         if (MapleInventoryManipulator.addFromDrop(c, mapitem.getItem(), true)) {
  106.                             c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 2, c.getPlayer().getId()), mapitem.getPosition());
  107.                             //  c.getPlayer().getCheatTracker().pickupComplete();
  108.                             c.getPlayer().getMap().removeMapObject(ob);
  109.                         } else {
  110.                             c.getPlayer().getCheatTracker().pickupComplete();
  111.                             return;
  112.                         }
  113.                     }
  114.                 }
  115.                 mapitem.setPickedUp(true);
  116.             }
  117.         }
  118.         c.getSession().write(MaplePacketCreator.enableActions());
  119.     }
  120. }