ItemPickupHandler.java
资源名称:src.rar [点击查看]
上传用户:gwt600
上传日期:2021-06-03
资源大小:704k
文件大小:6k
源码类别:
游戏
开发平台:
Java
- /*
- This file is part of the OdinMS Maple Story Server
- Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
- Matthias Butz <matze@odinms.de>
- Jan Christian Meyer <vimes@odinms.de>
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License version 3
- as published by the Free Software Foundation. You may not use, modify
- or distribute this program under any other version of the
- GNU Affero General Public License.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /*
- * ItemPickupHandler.java
- *
- * Created on 29. November 2007, 13:39
- */
- package net.sf.odinms.net.channel.handler;
- import net.sf.odinms.client.MapleCharacter;
- import net.sf.odinms.net.channel.ChannelServer;
- import net.sf.odinms.net.world.MaplePartyCharacter;
- import net.sf.odinms.client.MapleClient;
- import net.sf.odinms.server.AutobanManager;
- import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
- import net.sf.odinms.client.MaplePet;
- import net.sf.odinms.net.AbstractMaplePacketHandler;
- import net.sf.odinms.server.MapleInventoryManipulator;
- import net.sf.odinms.server.maps.MapleMapItem;
- import net.sf.odinms.server.maps.MapleMapObject;
- import net.sf.odinms.tools.MaplePacketCreator;
- import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
- /**
- *
- * @author Matze
- */
- public class ItemPickupHandler extends AbstractMaplePacketHandler {
- /** Creates a new instance of ItemPickupHandler */
- public ItemPickupHandler() {
- }
- public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
- c.getPlayer().resetAfkTime();
- @SuppressWarnings("unused")
- byte mode = slea.readByte(); // or something like that... but better ignore it if you want
- // mapchange to work! o.o!
- slea.readInt(); //?
- slea.readInt(); // position, but we dont need it o.o
- int oid = slea.readInt();
- MapleMapObject ob = c.getPlayer().getMap().getMapObject(oid);
- if (ob == null) {
- c.getSession().write(MaplePacketCreator.getInventoryFull());
- c.getSession().write(MaplePacketCreator.getShowInventoryFull());
- return;
- }
- if (ob instanceof MapleMapItem) {
- MapleMapItem mapitem = (MapleMapItem) ob;
- synchronized (mapitem) {
- if (mapitem.isPickedUp()) {
- c.getSession().write(MaplePacketCreator.getInventoryFull());
- c.getSession().write(MaplePacketCreator.getShowInventoryFull());
- return;
- }
- double distance = c.getPlayer().getPosition().distanceSq(mapitem.getPosition());
- // c.getPlayer().getCheatTracker().checkPickupAgain();
- if (mapitem.getMeso() > 0) {
- if (c.getPlayer().getParty() != null) {
- ChannelServer cserv = c.getChannelServer();
- int mesosamm = mapitem.getMeso();
- int partynum = 0;
- for (MaplePartyCharacter partymem : c.getPlayer().getParty().getMembers()) {
- if (partymem.isOnline() && partymem.getMapid() == c.getPlayer().getMap().getId() && partymem.getChannel() == c.getChannel()) {
- partynum++;
- }
- }
- int mesosgain = mesosamm / partynum;
- for (MaplePartyCharacter partymem : c.getPlayer().getParty().getMembers()) {
- if (partymem.isOnline() && partymem.getMapid() == c.getPlayer().getMap().getId()) {
- MapleCharacter somecharacter = cserv.getPlayerStorage().getCharacterById(partymem.getId());
- if (somecharacter != null) {
- somecharacter.gainMeso(mesosgain, true, true);
- }
- }
- }
- } else {
- c.getPlayer().gainMeso(mapitem.getMeso(), true, true);
- }
- c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 2, c.getPlayer().getId()), mapitem.getPosition());
- c.getPlayer().getCheatTracker().pickupComplete();
- c.getPlayer().getMap().removeMapObject(ob);
- } else {
- if (mapitem.getItem().getItemId() >= 5000000 && mapitem.getItem().getItemId() <= 5000100) {
- int petId = MaplePet.createPet(mapitem.getItem().getItemId());
- if (petId == -1) {
- return;
- }
- MapleInventoryManipulator.addById(c, mapitem.getItem().getItemId(), mapitem.getItem().getQuantity(), null, petId);
- c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 2, c.getPlayer().getId()), mapitem.getPosition());
- // c.getPlayer().getCheatTracker().pickupComplete();
- c.getPlayer().getMap().removeMapObject(ob);
- } else {
- if (MapleInventoryManipulator.addFromDrop(c, mapitem.getItem(), true)) {
- c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 2, c.getPlayer().getId()), mapitem.getPosition());
- // c.getPlayer().getCheatTracker().pickupComplete();
- c.getPlayer().getMap().removeMapObject(ob);
- } else {
- c.getPlayer().getCheatTracker().pickupComplete();
- return;
- }
- }
- }
- mapitem.setPickedUp(true);
- }
- }
- c.getSession().write(MaplePacketCreator.enableActions());
- }
- }