예제 #1
0
파일: MapleGuild.java 프로젝트: opencat/Nin
  public final void createAlliance(final MapleClient c, final String name) {
    if (allianceid != 0) {
      c.getPlayer().dropMessage(1, "You are already in an Alliance!");
      return;
    }
    if (checkAllianceName(name)) {
      try {
        if (name.equals("") || id <= 0) {
          return;
        }
        Connection con = DatabaseConnection.getConnection();
        PreparedStatement ps =
            con.prepareStatement(
                "INSERT INTO `alliances` (notice, name, guild1, guild2, guild3, guild4, guild5, rank1, rank2, rank3, rank4, rank5) VALUES ('', ?, ?, 0, 0, 0, 0, 'Master', 'Jr. Master', 'Member', 'Member', 'Member')");
        ps.setString(1, name);
        ps.setInt(2, id);
        ps.executeUpdate();
        ps.close();

        ps = con.prepareStatement("SELECT id FROM alliances WHERE guild1 = ?");
        ps.setInt(1, id);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
          allianceid = rs.getInt("id");
        }
        rs.close();
        ps.close();
        writeToDB(false);
        c.getPlayer().dropMessage(1, "Alliance successfully created!");
      } catch (SQLException a) {
      }
    } else {
      c.getPlayer().dropMessage(1, "This name already exists.");
    }
  }
예제 #2
0
 public void execute(MapleClient c, MessageCallback mc, String[] splitted) throws Exception {
   if (splitted[0].equalsIgnoreCase("reloadmap")) {
     if (splitted.length < 2) {
       mc.dropMessage("If you don't know how to use it. You should't be using it.");
       return;
     }
     int mapid = Integer.parseInt(splitted[1]);
     MapleMap map = c.getChannelServer().getMapFactory().getMap(mapid);
     map.deleteAndReloadMap();
   } else if (splitted[0].equalsIgnoreCase("reloaddropspawn")) {
     try {
       TimerManager.getInstance().stop();
     } catch (Exception e) {
       mc.dropMessage("Error : " + e);
       e.printStackTrace();
     } finally {
       try {
         TimerManager tMan = TimerManager.getInstance();
         tMan.start();
         mc.dropMessage("Success");
       } catch (Exception e) {
         mc.dropMessage("Error : " + e);
         e.printStackTrace();
       }
     }
   } else if (splitted[0].equalsIgnoreCase("resetreactors")) {
     c.getPlayer().getMap().resetReactors();
   }
 }
 public static void unequip(MapleClient c, byte src, byte dst) {
   Equip source = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(src);
   Equip target = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(dst);
   if (dst < 0) {
     log.warn(
         "Unequipping to negative slot. ({}: {}->{})",
         new Object[] {c.getPlayer().getName(), src, dst});
   }
   if (source == null) {
     return;
   }
   if (target != null && src <= 0) {
     // do not allow switching with equip
     c.getSession().write(MaplePacketCreator.getInventoryFull());
     return;
   }
   c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).removeSlot(src);
   if (target != null) {
     c.getPlayer().getInventory(MapleInventoryType.EQUIP).removeSlot(dst);
   }
   source.setPosition(dst);
   c.getPlayer().getInventory(MapleInventoryType.EQUIP).addFromDB(source);
   if (target != null) {
     target.setPosition(src);
     c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).addFromDB(target);
   }
   c.getSession()
       .write(MaplePacketCreator.moveInventoryItem(MapleInventoryType.EQUIP, src, dst, (byte) 1));
   c.getPlayer().equipChanged();
 }
예제 #4
0
  public static final void DenyPartyRequest(
      final SeekableLittleEndianAccessor slea, final MapleClient c) {
    final MapleCharacter cfrom =
        c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
    final String to = slea.readMapleAsciiString();

    if (cfrom != null) {
      cfrom
          .getClient()
          .getSession()
          .write(MaplePacketCreator.partyStatusMessage(23, c.getPlayer().getName()));
    }
  }
예제 #5
0
파일: MapleGuild.java 프로젝트: opencat/Nin
 // null indicates successful invitation being sent
 // keep in mind that this will be called by a handler most of the time
 // so this will be running mostly on a channel server, unlike the rest
 // of the class
 public static final MapleGuildResponse sendInvite(final MapleClient c, final String targetName) {
   final MapleCharacter mc =
       c.getChannelServer().getPlayerStorage().getCharacterByName(targetName);
   if (mc == null) {
     return MapleGuildResponse.NOT_IN_CHANNEL;
   }
   if (mc.getGuildId() > 0) {
     return MapleGuildResponse.ALREADY_IN_GUILD;
   }
   mc.getClient()
       .getSession()
       .write(GuildPacket.guildInvite(c.getPlayer().getGuildId(), c.getPlayer().getName()));
   return null;
 }
예제 #6
0
 public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   int oid = slea.readInt();
   @SuppressWarnings("unused")
   byte mode = slea.readByte(); // specifies if backwarp or not, but currently we do not care
   for (MapleMapObject obj : c.getPlayer().getMap().getMapObjects()) {
     if (obj instanceof MapleDoor) {
       MapleDoor door = (MapleDoor) obj;
       if (door.getOwner().getId() == oid) {
         door.warp(c.getPlayer());
         return;
       }
     }
   }
 }
 public static void removeAllById(MapleClient c, int itemId, boolean checkEquipped) {
   MapleInventoryType type = MapleItemInformationProvider.getInstance().getInventoryType(itemId);
   for (IItem item : c.getPlayer().getInventory(type).listById(itemId)) {
     if (item != null) {
       removeFromSlot(c, type, item.getPosition(), item.getQuantity(), true, false);
     }
   }
   if (checkEquipped) {
     IItem ii = c.getPlayer().getInventory(type).findById(itemId);
     if (ii != null) {
       c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).removeItem(ii.getPosition());
       c.getPlayer().equipChanged();
     }
   }
 }
 public static void removeById(
     MapleClient c,
     MapleInventoryType type,
     int itemId,
     int quantity,
     boolean fromDrop,
     boolean consume) {
   List<IItem> items = c.getPlayer().getInventory(type).listById(itemId);
   int remremove = quantity;
   for (IItem item : items) {
     if (remremove <= item.getQuantity()) {
       removeFromSlot(c, type, item.getPosition(), (short) remremove, fromDrop, consume);
       remremove = 0;
       break;
     } else {
       remremove -= item.getQuantity();
       removeFromSlot(c, type, item.getPosition(), item.getQuantity(), fromDrop, consume);
     }
   }
   if (remremove > 0) {
     throw new InventoryException(
         "[h4x] Not enough cheese available ("
             + itemId
             + ", "
             + (quantity - remremove)
             + "/"
             + quantity
             + ")");
   }
 }
 public static void editBBSThread(
     MapleClient client, String title, String text, int icon, int localthreadid) {
   MapleCharacter c = client.getPlayer();
   if (c.getGuildId() <= 0) {
     return; // expelled while viewing?
   }
   try {
     Connection con = DatabaseConnection.getConnection();
     PreparedStatement ps =
         con.prepareStatement(
             "UPDATE bbs_threads SET `name` = ?, `timestamp` = ?, "
                 + "`icon` = ?, "
                 + "`startpost` = ? WHERE guildid = ? AND localthreadid = ? AND (postercid = ? OR ?)");
     ps.setString(1, title);
     ps.setLong(2, System.currentTimeMillis());
     ps.setInt(3, icon);
     ps.setString(4, text);
     ps.setInt(5, c.getGuildId());
     ps.setInt(6, localthreadid);
     ps.setInt(7, c.getId());
     ps.setBoolean(8, c.getGuildRank() <= 2);
     ps.execute();
     ps.close();
     displayThread(client, localthreadid);
   } catch (SQLException se) {
     log.error("SQLException: " + se.getLocalizedMessage(), se);
   }
 }
예제 #10
0
 @Override
 public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   int emote = slea.readInt();
   if (emote < 0) {
     return;
   }
   if (emote > 7) {
     int emoteid = 5159992 + emote;
     if (c.getPlayer()
             .getInventory(MapleItemInformationProvider.getInstance().getInventoryType(emoteid))
             .findById(emoteid)
         == null) {
       return;
     }
   }
   if (c.getPlayer().getAndroid() != null) {
     c.getPlayer()
         .getMap()
         .broadcastMessage(MaplePacketCreator.showAndroidEmotion(c.getPlayer().getId(), emote));
   }
   c.getPlayer()
       .getMap()
       .broadcastMessage(
           c.getPlayer(), MaplePacketCreator.facialExpression(c.getPlayer(), emote), false);
 }
  public static void listBBSThreads(MapleClient c, int start) {
    int gid = c.getPlayer().getGuildId();
    try {
      Connection con = DatabaseConnection.getConnection();
      PreparedStatement ps =
          con.prepareStatement(
              "SELECT * FROM bbs_threads WHERE guildid = ? ORDER BY localthreadid DESC");
      ps.setInt(1, gid);

      ResultSet rs = ps.executeQuery();

      c.getSession().write(MaplePacketCreator.BBSThreadList(rs, start));

      rs.close();
      ps.close();
    } catch (SQLException se) {
      log.error("SQLException: " + se.getLocalizedMessage(), se);
    }
  }
 public static void removeFromSlot(
     MapleClient c,
     MapleInventoryType type,
     byte slot,
     short quantity,
     boolean fromDrop,
     boolean consume) {
   IItem item = c.getPlayer().getInventory(type).getItem(slot);
   MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
   boolean allowZero =
       consume && (ii.isThrowingStar(item.getItemId()) || ii.isBullet(item.getItemId()));
   c.getPlayer().getInventory(type).removeItem(slot, quantity, allowZero);
   if (item.getQuantity() == 0 && !allowZero) {
     c.getSession()
         .write(MaplePacketCreator.clearInventoryItem(type, item.getPosition(), fromDrop));
   } else {
     c.getSession().write(MaplePacketCreator.updateInventorySlot(type, (Item) item, fromDrop));
   }
 }
 public void clearslot(MapleClient c, int x) {
   MapleInventoryType type = MapleInventoryType.getByType((byte) x);
   for (byte i = 0; i < 101; i++) {
     IItem tempItem = c.getPlayer().getInventory(type).getItem(i);
     if (tempItem == null) {
       continue;
     }
     MapleInventoryManipulator.removeFromSlot(c, type, i);
   }
 }
예제 #14
0
 public static final void partySearchRegister(SeekableLittleEndianAccessor slea, MapleClient c) {
   MapleCharacter chr = c.getPlayer();
   int min = slea.readInt();
   int max = slea.readInt();
   if (chr.getLevel() < min
       || chr.getLevel() > max
       || (max - min) > 30
       || min > max) { // Client editing
     return;
   }
 }
  public static boolean checkSpace(MapleClient c, int itemid, int quantity, String owner) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    MapleInventoryType type = ii.getInventoryType(itemid);

    if (!type.equals(MapleInventoryType.EQUIP)) {
      short slotMax = ii.getSlotMax(c, itemid);
      List<IItem> existing = c.getPlayer().getInventory(type).listById(itemid);
      if (!ii.isThrowingStar(itemid) && !ii.isBullet(itemid)) {
        if (existing.size() > 0) { // first update all existing slots to slotMax

          for (IItem eItem : existing) {
            short oldQ = eItem.getQuantity();
            if (oldQ < slotMax && owner.equals(eItem.getOwner())) {
              short newQ = (short) Math.min(oldQ + quantity, slotMax);
              quantity -= (newQ - oldQ);
            }
            if (quantity <= 0) {
              break;
            }
          }
        }
      }
      // add new slots if there is still something left
      final int numSlotsNeeded;
      if (slotMax > 0) {
        numSlotsNeeded = (int) (Math.ceil(((double) quantity) / slotMax));
      } else if (ii.isThrowingStar(itemid) || ii.isBullet(itemid)) {
        numSlotsNeeded = 1;
      } else {
        numSlotsNeeded = 1;
        log.error("SUCK ERROR - FIX ME! - 0 slotMax");
      }
      return !c.getPlayer().getInventory(type).isFull(numSlotsNeeded - 1);
    } else {
      return !c.getPlayer().getInventory(type).isFull();
    }
  }
  public static void newBBSThread(
      MapleClient client, String title, String text, int icon, boolean bNotice) {
    MapleCharacter c = client.getPlayer();
    if (c.getGuildId() <= 0) {
      return; // expelled while viewing?
    }
    int nextId = 0;
    try {
      Connection con = DatabaseConnection.getConnection();
      PreparedStatement ps;

      if (!bNotice) // notice's local id is always 0, so we don't need to fetch it
      {
        ps =
            con.prepareStatement(
                "SELECT MAX(localthreadid) AS lastLocalId FROM bbs_threads WHERE guildid = ?");
        ps.setInt(1, c.getGuildId());
        ResultSet rs = ps.executeQuery();

        rs.next();
        nextId = rs.getInt("lastLocalId") + 1;
        rs.close();
        ps.close();
      }

      ps =
          con.prepareStatement(
              "INSERT INTO bbs_threads "
                  + "(`postercid`, `name`, `timestamp`, `icon`, `startpost`, "
                  + "`guildid`, `localthreadid`) "
                  + "VALUES(?, ?, ?, ?, ?, ?, ?)");
      ps.setInt(1, c.getId());
      ps.setString(2, title);
      ps.setLong(3, System.currentTimeMillis());
      ps.setInt(4, icon);
      ps.setString(5, text);
      ps.setInt(6, c.getGuildId());
      ps.setInt(7, nextId);
      ps.execute();

      ps.close();
      displayThread(client, nextId);
    } catch (SQLException se) {
      log.error("SQLException: " + se.getLocalizedMessage(), se);
    }
  }
  public static void newBBSReply(MapleClient client, int localthreadid, String text) {
    MapleCharacter mc = client.getPlayer();
    if (mc.getGuildId() <= 0) {
      return;
    }

    Connection con = DatabaseConnection.getConnection();
    try {
      PreparedStatement ps =
          con.prepareStatement(
              "SELECT threadid FROM bbs_threads WHERE guildid = ? AND localthreadid = ?");
      ps.setInt(1, mc.getGuildId());
      ps.setInt(2, localthreadid);
      ResultSet threadRS = ps.executeQuery();
      if (!threadRS.next()) {
        threadRS.close();
        ps.close();
        return; // thread no longer exists, deleted?
      }
      int threadid = threadRS.getInt("threadid");
      threadRS.close();
      ps.close();

      ps =
          con.prepareStatement(
              "INSERT INTO bbs_replies "
                  + "(`threadid`, `postercid`, `timestamp`, `content`) VALUES "
                  + "(?, ?, ?, ?)");
      ps.setInt(1, threadid);
      ps.setInt(2, mc.getId());
      ps.setLong(3, System.currentTimeMillis());
      ps.setString(4, text);
      ps.execute();
      ps.close();

      ps =
          con.prepareStatement(
              "UPDATE bbs_threads SET replycount = replycount + 1 WHERE threadid = ?");
      ps.setInt(1, threadid);
      ps.execute();
      ps.close();
      displayThread(client, localthreadid);
    } catch (SQLException se) {
      log.error("SQLException: " + se.getLocalizedMessage(), se);
    }
  }
  public static void deleteBBSThread(MapleClient client, int localthreadid) {
    MapleCharacter mc = client.getPlayer();
    if (mc.getGuildId() <= 0) {
      return;
    }

    Connection con = DatabaseConnection.getConnection();
    try {
      PreparedStatement ps =
          con.prepareStatement(
              "SELECT threadid, postercid FROM bbs_threads WHERE guildid = ? AND localthreadid = ?");
      ps.setInt(1, mc.getGuildId());
      ps.setInt(2, localthreadid);
      ResultSet threadRS = ps.executeQuery();
      if (!threadRS.next()) {
        threadRS.close();
        ps.close();
        return; // thread no longer exists, deleted?
      }
      if (mc.getId() != threadRS.getInt("postercid")
          && mc.getGuildRank() > 2) { // but let all master/jrs delete
        threadRS.close();
        ps.close();
        return; // [hax] deleting a thread that he didn't make
      }
      int threadid = threadRS.getInt("threadid");

      threadRS.close();
      ps.close();

      ps = con.prepareStatement("DELETE FROM bbs_replies WHERE threadid = ?");
      ps.setInt(1, threadid);
      ps.execute();
      ps.close();

      ps = con.prepareStatement("DELETE FROM bbs_threads WHERE threadid = ?");
      ps.setInt(1, threadid);
      ps.execute();
      ps.close();
    } catch (SQLException se) {
      log.error("SQLException: " + se.getLocalizedMessage(), se);
    }
  }
  public static void deleteBBSReply(MapleClient client, int replyid) {
    MapleCharacter mc = client.getPlayer();
    if (mc.getGuildId() <= 0) {
      return;
    }

    int threadid;
    Connection con = DatabaseConnection.getConnection();
    try {
      PreparedStatement ps =
          con.prepareStatement("SELECT postercid, threadid FROM bbs_replies WHERE replyid = ?");
      ps.setInt(1, replyid);
      ResultSet rs = ps.executeQuery();
      if (!rs.next()) {
        rs.close();
        ps.close();
        return; // reply no longer exists, deleted already?
      }
      if (mc.getId() != rs.getInt("postercid") && mc.getGuildRank() > 2) {
        rs.close();
        ps.close();
        return; // [hax] deleting a reply that he didn't make
      }
      threadid = rs.getInt("threadid");
      rs.close();
      ps.close();

      ps = con.prepareStatement("DELETE FROM bbs_replies WHERE replyid = ?");
      ps.setInt(1, replyid);
      ps.execute();
      ps.close();

      ps =
          con.prepareStatement(
              "UPDATE bbs_threads SET replycount = replycount - 1 WHERE threadid = ?");
      ps.setInt(1, threadid);
      ps.execute();
      ps.close();
      displayThread(client, threadid, false);
    } catch (SQLException se) {
      log.error("SQLException: " + se.getLocalizedMessage(), se);
    }
  }
 public static void move(MapleClient c, MapleInventoryType type, byte src, byte dst) {
   if (src < 0 || dst < 0) {
     return;
   }
   MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
   IItem source = c.getPlayer().getInventory(type).getItem(src);
   IItem initialTarget = c.getPlayer().getInventory(type).getItem(dst);
   if (source == null) {
     return;
   }
   short olddstQ = -1;
   if (initialTarget != null) {
     olddstQ = initialTarget.getQuantity();
   }
   short oldsrcQ = source.getQuantity();
   short slotMax = ii.getSlotMax(c, source.getItemId());
   c.getPlayer().getInventory(type).move(src, dst, slotMax);
   if (!type.equals(MapleInventoryType.EQUIP)
       && initialTarget != null
       && initialTarget.getItemId() == source.getItemId()
       && !ii.isThrowingStar(source.getItemId())
       && !ii.isBullet(source.getItemId())) {
     if ((olddstQ + oldsrcQ) > slotMax) {
       c.getSession()
           .write(
               MaplePacketCreator.moveAndMergeWithRestInventoryItem(
                   type, src, dst, (short) ((olddstQ + oldsrcQ) - slotMax), slotMax));
     } else {
       c.getSession()
           .write(
               MaplePacketCreator.moveAndMergeInventoryItem(
                   type,
                   src,
                   dst,
                   ((Item) c.getPlayer().getInventory(type).getItem(dst)).getQuantity()));
     }
   } else {
     c.getSession().write(MaplePacketCreator.moveInventoryItem(type, src, dst));
   }
 }
예제 #21
0
 public static final void partySearchStart(SeekableLittleEndianAccessor slea, MapleClient c) {
   int min = slea.readInt();
   int max = slea.readInt();
   slea.readInt(); // members
   int jobs = slea.readInt();
   MapleCharacter chr = c.getPlayer();
   MapleMap map = chr.getMap();
   Collection<MapleMapObject> mapobjs = map.getAllPlayer();
   for (MapleMapObject mapobj : mapobjs) {
     if (chr.getParty().getMembers().size() > 5) {
       break;
     }
     if (mapobj instanceof MapleCharacter) {
       MapleCharacter tchar = (MapleCharacter) mapobj;
       int charlvl = tchar.getLevel();
       if (charlvl >= min && charlvl <= max && isValidJob(tchar.getJob(), jobs)) {
         if (c.getPlayer().getParty() == null) {
           try {
             WorldChannelInterface wci = c.getChannelServer().getWorldInterface();
             MapleParty party = c.getPlayer().getParty();
             int partyid = party.getId();
             party = wci.getParty(partyid);
             if (party != null) {
               if (party.getMembers().size() < 6) {
                 MaplePartyCharacter partyplayer = new MaplePartyCharacter(tchar);
                 wci.updateParty(party.getId(), PartyOperation.JOIN, partyplayer);
                 c.getPlayer().receivePartyMemberHP();
                 c.getPlayer().updatePartyMemberHP();
               } else {
                 c.getSession().write(MaplePacketCreator.partyStatusMessage(17));
               }
             }
           } catch (Exception e) {
             c.getChannelServer().reconnectWorld();
           }
         }
       }
     }
   }
 }
 @Override
 public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   c.getPlayer().resetAfkTime();
   if (c.getPlayer().getNoPets() == 0) {
     return;
   }
   int slot = 0;
   MaplePet[] pets = c.getPlayer().getPets();
   for (int i = 0; i < 3; i++) {
     if (pets[i] != null) {
       if (pets[i].getFullness() < 100) {
         slot = i;
       }
     } else {
       break;
     }
   }
   MaplePet pet = c.getPlayer().getPet(slot);
   slea.readInt();
   slea.readShort();
   int itemId = slea.readInt();
   if (c.getPlayer().haveItem(itemId, 1, false, true)) {
     boolean gainCloseness = new Random().nextInt(101) <= 50;
     int newFullness = pet.getFullness() + 30;
     if (pet.getFullness() < 100) {
       if (newFullness > 100) {
         newFullness = 100;
       }
       pet.setFullness(newFullness);
       if (gainCloseness && pet.getCloseness() < 30000) {
         int newCloseness = pet.getCloseness() + (1 * c.getChannelServer().getPetExpRate());
         if (newCloseness > 30000) {
           newCloseness = 30000;
         }
         pet.setCloseness(newCloseness);
         if (newCloseness >= ExpTable.getClosenessNeededForLevel(pet.getLevel() + 1)) {
           pet.setLevel(pet.getLevel() + 1);
           c.getSession()
               .write(MaplePacketCreator.showOwnPetLevelUp(c.getPlayer().getPetIndex(pet)));
           c.getPlayer()
               .getMap()
               .broadcastMessage(
                   MaplePacketCreator.showPetLevelUp(
                       c.getPlayer(), c.getPlayer().getPetIndex(pet)));
         }
       }
     } else {
       if (gainCloseness) {
         int newCloseness = pet.getCloseness() - (1 * c.getChannelServer().getPetExpRate());
         if (newCloseness < 0) {
           newCloseness = 0;
         }
         pet.setCloseness(newCloseness);
         if (newCloseness < ExpTable.getClosenessNeededForLevel(pet.getLevel())) {
           pet.setLevel(pet.getLevel() - 1);
         }
       }
     }
     c.getSession().write(MaplePacketCreator.updatePet(pet, true));
     c.getPlayer()
         .getMap()
         .broadcastMessage(
             c.getPlayer(),
             MaplePacketCreator.commandResponse(c.getPlayer().getId(), (byte) 1, slot, true, true),
             true);
     MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, true, false);
   }
 }
예제 #23
0
  @Override
  public void handlePacket(SeekableLittleEndianAccessor slea, final MapleClient c) {
    int skillId = slea.readInt(); // 技能ID
    int level = slea.readByte(); // 等级
    byte flags = slea.readByte(); // 80
    int speed = slea.readByte(); // 武器攻击速度 && skillId != 23121000
    int op = slea.readByte();
    ISkill skill = SkillFactory.getSkill(skillId);
    /*
     * if (skill != null && skill.hasCharge()) {
     * c.getPlayer().getMap().broadcastMessage(c.getPlayer(),
     * MaplePacketCreator.skillEffect(c.getPlayer(), skillId, level, flags,
     * speed, op), false); }
     */

    if (skillId == 33101005) {
      c.getPlayer().设置吞噬的怪id(slea.readInt());
    }
    // 暴风箭雨 金属风暴 磁石
    if ((skillId == 3121004
            || skillId == 5221004
            || skillId == 1121001
            || skillId == 1221001
            || skillId == 1321001
            || skillId == 2121001
            || skillId == 2221001
            || skillId == 2321001
            || skillId == 2111002
            || skillId == 4211001
            || skillId == 3221001
            || skillId == 5101004
            || skillId == 15101003
            || skillId == 5201002
            || skillId == 14111006
            || skillId == 13111002
            || skillId == 22121000 // 冰点寒气
            || skillId == 22151001 // 火焰喷射
            || skillId == 4341002 // 终极斩
            || skillId == 4341003 // 怪物炸弹
            || skillId == 33101005 // 弩骑 吞噬
            || skillId == 33121009 // 弩骑 狂野射击
            || skillId == 35001001 // 火焰喷射器
            || skillId == 35101009 // 强化火焰喷射器
            || skillId == 23121000 // 伊师塔之环
            || skillId == 31101000 // 灵魂吞噬
            || skillId == 31001000
            || skillId == 31101002
            || skillId == 31111005
            || skillId == 5311002
            || skillId == 5721001
            || skillId == 24121000
            || skillId == 24121005
            || skillId == 60011216
            || skillId == 65121003
            || skillId == 27101202
            || skillId == 36121000
            || skillId == 36101001)
        && level >= 1) {
      c.getPlayer()
          .getMap()
          .broadcastMessage(
              c.getPlayer(),
              MaplePacketCreator.skillEffect(c.getPlayer(), skillId, level, flags, speed, op),
              false);
    } else {
      log.info("未登记技能效果挂断连接:" + skillId);
    }
  }
  /*	TODO:
   *	1. Move the equpping into a function.
   */
  @Override
  public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    c.getPlayer().resetAfkTime();
    slea.readInt();
    byte slot = slea.readByte();
    slea.readByte();
    boolean lead = slea.readByte() == 1;
    MapleCharacter player = c.getPlayer();
    IItem item = player.getInventory(MapleInventoryType.CASH).getItem(slot);

    if (item.getItemId() == 5000028 || item.getItemId() == 5000047) {
      boolean done = false;
      int petno;
      int[] pet;
      int[] dragon = {5000029, 5000030, 5000031, 5000032, 5000033};
      int[] robot = {5000048, 5000049, 5000050, 5000051, 5000052, 5000053};

      pet = item.getItemId() == 5000028 ? dragon : robot;
      Random egg = new Random();
      for (int i = 0; i < pet.length && !done; i++) {
        petno = egg.nextInt(pet.length);
        if (!player.haveItem(pet[petno], 1, true, true)) {
          MapleInventoryManipulator.removeFromSlot(
              c, MapleInventoryType.CASH, item.getPosition(), (short) 1, true, false);
          MapleInventoryManipulator.addById(
              c, pet[petno], (short) 1, null, MaplePet.createPet(pet[petno]));
          done = true;
        }
      }
      if (!done) {
        player.dropMessage(1, "You currently have all the dragons or robots.");
        return;
      }
    }
    // New instance of MaplePet - using the item ID and unique pet ID
    MaplePet pet =
        MaplePet.loadFromDb(
            player.getInventory(MapleInventoryType.CASH).getItem(slot).getItemId(),
            slot,
            player.getInventory(MapleInventoryType.CASH).getItem(slot).getPetId());

    if (pet == null) {
      MapleInventoryManipulator.removeById(
          c, MapleInventoryType.CASH, item.getItemId(), (short) item.getQuantity(), false, false);
      c.getSession().write(MaplePacketCreator.enableActions());
      return;
    }
    // Assign the pet to the player, set stats
    if (player.getPetIndex(pet) != -1) {
      player.unequipPet(pet, true);
    } else {
      if (player.getSkillLevel(SkillFactory.getSkill(8)) == 0 && player.getPet(0) != null) {
        player.unequipPet(player.getPet(0), false);
      }
      if (lead) {
        player.shiftPetsRight();
      }
      Point pos = player.getPosition();
      pos.y -= 12;
      pet.setPos(pos);
      pet.setFh(player.getMap().getFootholds().findBelow(pet.getPos()).getId());
      pet.setStance(0);

      player.addPet(pet);
      // Broadcast packet to the map...
      player
          .getMap()
          .broadcastMessage(player, MaplePacketCreator.showPet(player, pet, false), true);
      // Find the pet's unique ID
      int uniqueid = pet.getUniqueId();
      // Make a new List for the stat update
      List<Pair<MapleStat, Integer>> stats = new ArrayList<Pair<MapleStat, Integer>>();
      stats.add(new Pair<MapleStat, Integer>(MapleStat.PET, Integer.valueOf(uniqueid)));
      // Write the stat update to the player...
      c.getSession().write(MaplePacketCreator.petStatUpdate(player));
      c.getSession().write(MaplePacketCreator.enableActions());
      // Get the data
      int hunger = PetDataFactory.getHunger(pet.getItemId());
      // Start the fullness schedule
      player.startFullnessSchedule(hunger, pet, player.getPetIndex(pet));
    }
  }
  public static boolean addById(
      MapleClient c, int itemId, short quantity, String owner, int petid) {
    if (quantity >= 4000 || quantity < 0) {
      AutobanManager.getInstance()
          .autoban(c.getPlayer().getClient(), "PE Item: " + quantity + "x " + itemId);
      return false;
    }
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    MapleInventoryType type = ii.getInventoryType(itemId);
    if (!type.equals(MapleInventoryType.EQUIP)) {
      short slotMax = ii.getSlotMax(c, itemId);
      List<IItem> existing = c.getPlayer().getInventory(type).listById(itemId);
      if (!ii.isThrowingStar(itemId) && !ii.isBullet(itemId)) {
        if (existing.size() > 0) { // first update all existing slots to slotMax

          Iterator<IItem> i = existing.iterator();
          while (quantity > 0) {
            if (i.hasNext()) {
              Item eItem = (Item) i.next();
              short oldQ = eItem.getQuantity();
              if (oldQ < slotMax && (eItem.getOwner().equals(owner) || owner == null)) {
                short newQ = (short) Math.min(oldQ + quantity, slotMax);
                quantity -= (newQ - oldQ);
                eItem.setQuantity(newQ);
                c.getSession().write(MaplePacketCreator.updateInventorySlot(type, eItem));
              }
            } else {
              break;
            }
          }
        }
        // add new slots if there is still something left
        while (quantity > 0 || ii.isThrowingStar(itemId) || ii.isBullet(itemId)) {
          short newQ = (short) Math.min(quantity, slotMax);
          if (newQ != 0) {
            quantity -= newQ;
            Item nItem = new Item(itemId, (byte) 0, newQ, petid);
            byte newSlot = c.getPlayer().getInventory(type).addItem(nItem);
            if (newSlot == -1) {
              c.getSession().write(MaplePacketCreator.getInventoryFull());
              c.getSession().write(MaplePacketCreator.getShowInventoryFull());
              return false;
            }
            if (owner != null) {
              nItem.setOwner(owner);
            }
            c.getSession().write(MaplePacketCreator.addInventorySlot(type, nItem));
            if ((ii.isThrowingStar(itemId) || ii.isBullet(itemId)) && quantity == 0) {
              break;
            }
          } else {
            c.getSession().write(MaplePacketCreator.enableActions());
            return false;
          }
        }
      } else {
        // Throwing Stars and Bullets - Add all into one slot regardless of quantity.
        Item nItem = new Item(itemId, (byte) 0, quantity);
        byte newSlot = c.getPlayer().getInventory(type).addItem(nItem);

        if (newSlot == -1) {
          c.getSession().write(MaplePacketCreator.getInventoryFull());
          c.getSession().write(MaplePacketCreator.getShowInventoryFull());
          return false;
        }
        c.getSession().write(MaplePacketCreator.addInventorySlot(type, nItem));
        c.getSession().write(MaplePacketCreator.enableActions());
      }
    } else {
      if (quantity == 1) {
        IItem nEquip = ii.getEquipById(itemId);
        if (owner != null) {
          nEquip.setOwner(owner);
        }

        byte newSlot = c.getPlayer().getInventory(type).addItem(nEquip);
        if (newSlot == -1) {
          c.getSession().write(MaplePacketCreator.getInventoryFull());
          c.getSession().write(MaplePacketCreator.getShowInventoryFull());
          return false;
        }
        c.getSession().write(MaplePacketCreator.addInventorySlot(type, nEquip));
      } else {
        throw new InventoryException("Trying to create equip with non-one quantity");
      }
    }
    return true;
  }
  public static boolean addFromDrop(MapleClient c, IItem item, boolean show, String owner) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    MapleInventoryType type = ii.getInventoryType(item.getItemId());

    if (!c.getChannelServer().allowMoreThanOne()
        && ii.isPickupRestricted(item.getItemId())
        && c.getPlayer().haveItem(item.getItemId(), 1, true, false)) {
      c.getSession().write(MaplePacketCreator.getInventoryFull());
      c.getSession().write(MaplePacketCreator.showItemUnavailable());
      return false;
    }
    short quantity = item.getQuantity();
    if (quantity >= 4000 || quantity < 0) {
      AutobanManager.getInstance()
          .autoban(c.getPlayer().getClient(), "PE Item: " + quantity + "x " + item.getItemId());
      return false;
    }

    if (!type.equals(MapleInventoryType.EQUIP)) {
      short slotMax = ii.getSlotMax(c, item.getItemId());
      List<IItem> existing = c.getPlayer().getInventory(type).listById(item.getItemId());
      if (!ii.isThrowingStar(item.getItemId()) && !ii.isBullet(item.getItemId())) {
        if (existing.size() > 0) { // first update all existing slots to slotMax

          Iterator<IItem> i = existing.iterator();
          while (quantity > 0) {
            if (i.hasNext()) {
              Item eItem = (Item) i.next();
              short oldQ = eItem.getQuantity();
              if (oldQ < slotMax && item.getOwner().equals(eItem.getOwner())) {
                short newQ = (short) Math.min(oldQ + quantity, slotMax);
                quantity -= (newQ - oldQ);
                eItem.setQuantity(newQ);
                c.getSession().write(MaplePacketCreator.updateInventorySlot(type, eItem, true));
              }
            } else {
              break;
            }
          }
        }
        // add new slots if there is still something left
        while (quantity > 0
            || ii.isThrowingStar(item.getItemId())
            || ii.isBullet(item.getItemId())) {
          short newQ = (short) Math.min(quantity, slotMax);
          quantity -= newQ;
          Item nItem = new Item(item.getItemId(), (byte) 0, newQ);
          nItem.setOwner(item.getOwner());
          byte newSlot = c.getPlayer().getInventory(type).addItem(nItem);
          if (newSlot == -1) {
            c.getSession().write(MaplePacketCreator.getInventoryFull());
            c.getSession().write(MaplePacketCreator.getShowInventoryFull());
            item.setQuantity((short) (quantity + newQ));
            return false;
          }
          c.getSession().write(MaplePacketCreator.addInventorySlot(type, nItem, true));
        }
      } else {
        // Throwing Stars and Bullets - Add all into one slot regardless of quantity.
        Item nItem = new Item(item.getItemId(), (byte) 0, quantity);
        byte newSlot = c.getPlayer().getInventory(type).addItem(nItem);
        if (newSlot == -1) {
          c.getSession().write(MaplePacketCreator.getInventoryFull());
          c.getSession().write(MaplePacketCreator.getShowInventoryFull());
          return false;
        }
        c.getSession().write(MaplePacketCreator.addInventorySlot(type, nItem));
        c.getSession().write(MaplePacketCreator.enableActions());
      }
    } else {
      if (quantity == 1) {
        byte newSlot = c.getPlayer().getInventory(type).addItem(item);

        if (newSlot == -1) {
          c.getSession().write(MaplePacketCreator.getInventoryFull());
          c.getSession().write(MaplePacketCreator.getShowInventoryFull());
          return false;
        }
        c.getSession().write(MaplePacketCreator.addInventorySlot(type, item, true));
      } else {
        throw new RuntimeException("Trying to create equip with non-one quantity");
      }
    }
    if (owner != null) {
      item.setOwner(owner);
    }
    if (show) {
      c.getSession()
          .write(MaplePacketCreator.getShowItemGain(item.getItemId(), item.getQuantity()));
    }
    return true;
  }
  public static void equip(MapleClient c, byte src, byte dst) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    Equip source = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(src);
    Equip target = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(dst);
    if (source == null) {
      return;
    }
    if (!c.getPlayer().isGM() && !c.getChannelServer().CanGMItem()) {
      switch (source.getItemId()) {
        case 1002140: // Wizet Invincible Hat
        case 1042003: // Wizet Plain Suit
        case 1062007: // Wizet Plain Suit Pants
        case 1322013: // Wizet Secret Agent Suitcase
          removeAllById(c, source.getItemId(), false);
          c.getPlayer().dropMessage(1, "You're not a GM");
          return;
      }
    }

    if (source.getItemId() == 1302065 || source.getItemId() == 1302033) {
      c.getPlayer().dropMessage(6, "You cannot equip the Capture the Flag items.");
      return;
    }

    if (source.getItemId() == 1812006) {
      removeAllById(c, source.getItemId(), false);
      c.getPlayer().dropMessage(1, "Magic Scale Has Been Blocked");
      return;
    }

    if (source.getItemId() == 1002425 && c.getPlayer().getLevel() == 200) {
      c.getPlayer().setLevel(2);
      c.getPlayer().setJob(0);
      c.getPlayer().setReborns(1);
      c.getPlayer().doReborn();
      c.getPlayer().setRebirthPoints(c.getPlayer().getRebirthPoints() + 1);
      c.getPlayer()
          .dropMessage("Congratulations on your rebirth! I have given you one rebrth point.");
    }

    if (source.getItemId() == 1002083 && c.getPlayer().getLevel() >= 120) {
      c.getPlayer().saveToDB(true, true);
      c.getPlayer().changeJob(MapleJob.getById(412)); // Night Lord
      removeAllById(c, source.getItemId(), false);
    }
    if (source.getItemId() == 1002082 && c.getPlayer().getLevel() >= 120) {
      c.getPlayer().saveToDB(true, true);
      c.getPlayer().changeJob(MapleJob.getById(422)); // Bandit
      removeAllById(c, source.getItemId(), false);
    }
    if (source.getItemId() == 1002081 && c.getPlayer().getLevel() >= 120) {
      c.getPlayer().saveToDB(true, true);
      c.getPlayer().changeJob(MapleJob.getById(112)); // hero
      removeAllById(c, source.getItemId(), false);
    }
    if (source.getItemId() == 1002080 && c.getPlayer().getLevel() >= 120) {
      c.getPlayer().saveToDB(true, true);
      c.getPlayer().changeJob(MapleJob.getById(122)); // paladin
      removeAllById(c, source.getItemId(), false);
    }
    if (source.getItemId() == 1002393 && c.getPlayer().getLevel() >= 120) {
      c.getPlayer().saveToDB(true, true);
      c.getPlayer().changeJob(MapleJob.getById(132)); // DK
      removeAllById(c, source.getItemId(), false);
    }
    if (source.getItemId() == 1002394 && c.getPlayer().getLevel() >= 120) {
      c.getPlayer().saveToDB(true, true);
      c.getPlayer().changeJob(MapleJob.getById(212)); // Bishop
      removeAllById(c, source.getItemId(), false);
    }
    if (source.getItemId() == 1002392 && c.getPlayer().getLevel() >= 120) {
      c.getPlayer().saveToDB(true, true);
      c.getPlayer().changeJob(MapleJob.getById(222)); // FP mage
      removeAllById(c, source.getItemId(), false);
    }
    if (source.getItemId() == 1002391 && c.getPlayer().getLevel() >= 120) {
      c.getPlayer().saveToDB(true, true);
      c.getPlayer().changeJob(MapleJob.getById(232)); // IL mage
      removeAllById(c, source.getItemId(), false);
    }
    if (source.getItemId() == 1002395 && c.getPlayer().getLevel() >= 120) {
      c.getPlayer().saveToDB(true, true);
      c.getPlayer().changeJob(MapleJob.getById(512)); // brawler
      removeAllById(c, source.getItemId(), false);
    }
    if (source.getItemId() == 1002515 && c.getPlayer().getLevel() >= 120) {
      c.getPlayer().saveToDB(true, true);
      c.getPlayer().changeJob(MapleJob.getById(312)); // bowman
      removeAllById(c, source.getItemId(), false);
    }
    if (source.getItemId() == 1002397 && c.getPlayer().getLevel() >= 120) {
      c.getPlayer().saveToDB(true, true);
      c.getPlayer().changeJob(MapleJob.getById(322)); // xbow
      removeAllById(c, source.getItemId(), false);
    }

    if (dst == -6) {
      // unequip the overall
      IItem top = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((byte) -5);
      if (top != null && ii.isOverall(top.getItemId())) {
        if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
          c.getSession().write(MaplePacketCreator.getInventoryFull());
          c.getSession().write(MaplePacketCreator.getShowInventoryFull());
          return;
        }
        unequip(
            c, (byte) -5, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
      }
    } else if (dst == -5) {
      // unequip the bottom and top
      IItem top = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((byte) -5);
      IItem bottom = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((byte) -6);
      if (top != null && ii.isOverall(source.getItemId())) {
        if (c.getPlayer()
            .getInventory(MapleInventoryType.EQUIP)
            .isFull(bottom != null && ii.isOverall(source.getItemId()) ? 1 : 0)) {
          c.getSession().write(MaplePacketCreator.getInventoryFull());
          c.getSession().write(MaplePacketCreator.getShowInventoryFull());
          return;
        }
        unequip(
            c, (byte) -5, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
      }
      if (bottom != null && ii.isOverall(source.getItemId())) {
        if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
          c.getSession().write(MaplePacketCreator.getInventoryFull());
          c.getSession().write(MaplePacketCreator.getShowInventoryFull());
          return;
        }
        unequip(
            c, (byte) -6, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
      }
    } else if (dst == -10) {
      // check if weapon is two-handed
      IItem weapon = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((byte) -11);
      if (weapon != null && ii.isTwoHanded(weapon.getItemId())) {
        if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
          c.getSession().write(MaplePacketCreator.getInventoryFull());
          c.getSession().write(MaplePacketCreator.getShowInventoryFull());
          return;
        }
        unequip(
            c, (byte) -11, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
      }
    } else if (dst == -11) {
      IItem shield = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((byte) -10);
      if (shield != null && ii.isTwoHanded(source.getItemId())) {
        if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
          c.getSession().write(MaplePacketCreator.getInventoryFull());
          c.getSession().write(MaplePacketCreator.getShowInventoryFull());
          return;
        }
        unequip(
            c, (byte) -10, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
      }
    } else if (dst == -18) {
      c.getPlayer().getMount().setItemId(source.getItemId());
    }
    source = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(src);
    target = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(dst);
    c.getPlayer().getInventory(MapleInventoryType.EQUIP).removeSlot(src);
    if (target != null) {
      c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).removeSlot(dst);
    }
    source.setPosition(dst);
    c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).addFromDB(source);
    if (target != null) {
      target.setPosition(src);
      c.getPlayer().getInventory(MapleInventoryType.EQUIP).addFromDB(target);
    }
    if (c.getPlayer().getBuffedValue(MapleBuffStat.BOOSTER) != null
        && ii.isWeapon(source.getItemId())) {
      c.getPlayer().cancelBuffStats(MapleBuffStat.BOOSTER);
    }
    c.getSession()
        .write(MaplePacketCreator.moveInventoryItem(MapleInventoryType.EQUIP, src, dst, (byte) 2));
    c.getPlayer().equipChanged();
  }
  public static void drop(MapleClient c, MapleInventoryType type, byte src, short quantity) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    if (src < 0) {
      type = MapleInventoryType.EQUIPPED;
    }
    IItem source = c.getPlayer().getInventory(type).getItem(src);
    int itemId = source.getItemId();
    if (itemId == 1302065 || itemId == 1302033) {
      c.getPlayer().hasflag = false;
      c.getPlayer().setCanPickup(true);
    }

    if (itemId == 1112000) {
      c.getPlayer().dropMessage("Super Rebirth rings cannot be dropped or traded.");
      return;
    }

    if (itemId == 1012076) {
      c.getPlayer().dropMessage("The Beta Mask cannot be traded or dropped.");
      return;
    }

    if (c.getPlayer().getItemEffect() == itemId && source.getQuantity() == 1) {
      c.getPlayer().setItemEffect(0);
      c.getPlayer()
          .getMap()
          .broadcastMessage(MaplePacketCreator.itemEffect(c.getPlayer().getId(), 0));
    } else if (itemId == 5370000 || itemId == 5370001) {
      if (c.getPlayer().getItemQuantity(itemId, false) == 1) {
        c.getPlayer().setChalkboard(null);
      }
    }

    if (itemId == 4000076) {
      c.getPlayer().mapCheck();
    }

    if (quantity < 0
        || source == null
        || quantity == 0 && !ii.isThrowingStar(itemId) && !ii.isBullet(itemId)) {
      String message =
          "Dropping "
              + quantity
              + " "
              + (source == null ? "?" : itemId)
              + " ("
              + type.name()
              + "/"
              + src
              + ")";
      // AutobanManager.getInstance().addPoints(c, 1000, 0, message);
      log.info(MapleClient.getLogMessage(c, message));
      c.getSession()
          .close(); // disconnect the client as is inventory is inconsistent with the serverside
                    // inventory -> f**k

      return;
    }
    Point dropPos = new Point(c.getPlayer().getPosition());
    // dropPos.y -= 99;
    if (quantity < source.getQuantity() && !ii.isThrowingStar(itemId) && !ii.isBullet(itemId)) {
      IItem target = source.copy();
      target.setQuantity(quantity);
      source.setQuantity((short) (source.getQuantity() - quantity));
      c.getSession().write(MaplePacketCreator.dropInventoryItemUpdate(type, source));
      boolean weddingRing =
          source.getItemId() == 1112803
              || source.getItemId() == 1112806
              || source.getItemId() == 1112807
              || source.getItemId() == 1112809;
      if (weddingRing) {
        c.getPlayer().getMap().disappearingItemDrop(c.getPlayer(), c.getPlayer(), target, dropPos);
      } else if (c.getPlayer().getMap().getEverlast()) {
        if (!c.getChannelServer().allowUndroppablesDrop()
            && ii.isDropRestricted(target.getItemId())) {
          c.getPlayer()
              .getMap()
              .disappearingItemDrop(c.getPlayer(), c.getPlayer(), target, dropPos);
        } else {
          c.getPlayer()
              .getMap()
              .spawnItemDrop(c.getPlayer(), c.getPlayer(), target, dropPos, true, false);
        }
      } else {
        if (!c.getChannelServer().allowUndroppablesDrop()
            && ii.isDropRestricted(target.getItemId())) {
          c.getPlayer()
              .getMap()
              .disappearingItemDrop(c.getPlayer(), c.getPlayer(), target, dropPos);
        } else {
          c.getPlayer()
              .getMap()
              .spawnItemDrop(c.getPlayer(), c.getPlayer(), target, dropPos, true, true);
        }
      }
    } else {
      c.getPlayer().getInventory(type).removeSlot(src);
      c.getSession()
          .write(
              MaplePacketCreator.dropInventoryItem(
                  (src < 0 ? MapleInventoryType.EQUIP : type), src));
      if (src < 0) {
        c.getPlayer().equipChanged();
      }
      if (c.getPlayer().getMap().getEverlast()) {
        if (!c.getChannelServer().allowUndroppablesDrop() && ii.isDropRestricted(itemId)) {
          c.getPlayer()
              .getMap()
              .disappearingItemDrop(c.getPlayer(), c.getPlayer(), source, dropPos);
        } else {
          c.getPlayer()
              .getMap()
              .spawnItemDrop(c.getPlayer(), c.getPlayer(), source, dropPos, true, false);
        }
      } else {
        if (!c.getChannelServer().allowUndroppablesDrop() && ii.isDropRestricted(itemId)) {
          c.getPlayer()
              .getMap()
              .disappearingItemDrop(c.getPlayer(), c.getPlayer(), source, dropPos);
        } else {
          c.getPlayer()
              .getMap()
              .spawnItemDrop(c.getPlayer(), c.getPlayer(), source, dropPos, true, true);
        }
      }
    }
  }
 public void execute(MapleClient c, MessageCallback mc, String[] splitted)
     throws Exception, IllegalCommandSyntaxException {
   MapleCharacter player = c.getPlayer();
   if (splitted[0].equals("shop")) {
     MapleShopFactory sfact = MapleShopFactory.getInstance();
     MapleShop shop = sfact.getShop(getOptionalIntArg(splitted, 1, 1));
     shop.sendShop(c);
   } else if (splitted[0].equals("item")) {
     short quantity = (short) getOptionalIntArg(splitted, 2, 1);
     int itemId = Integer.parseInt(splitted[1]);
     if (ii.getSlotMax(itemId) > 0) {
       if (itemId >= 5000000 && itemId <= 5000100) {
         if (quantity > 1) {
           quantity = 1;
         }
         int petId = MaplePet.createPet(itemId);
         MapleInventoryManipulator.addById(
             c,
             itemId,
             quantity,
             c.getPlayer().getName() + "used !item with quantity " + quantity,
             player.getName(),
             petId);
         return;
       }
       MapleInventoryManipulator.addById(
           c,
           itemId,
           quantity,
           c.getPlayer().getName() + "used !item with quantity " + quantity,
           player.getName());
     } else {
       mc.dropMessage("Item " + itemId + " not found.");
     }
   } else if (splitted[0].equals("drop")) {
     int itemId = Integer.parseInt(splitted[1]);
     if (ii.getSlotMax(itemId) > 0) {
       if (SpecialStuff.getInstance().isGMBlocked(itemId) && !player.isHokage()) {
         mc.dropMessage("Sunny says you cannot drop this item");
         return;
       }
       short quantity = (short) (short) getOptionalIntArg(splitted, 2, 1);
       IItem toDrop;
       if (ii.getInventoryType(itemId) == MapleInventoryType.EQUIP) {
         toDrop = ii.getEquipById(itemId);
       } else {
         toDrop = new Item(itemId, (byte) 0, (short) quantity);
       }
       toDrop.setOwner(player.getName());
       c.getPlayer()
           .getMap()
           .spawnItemDrop(
               c.getPlayer(), c.getPlayer(), toDrop, c.getPlayer().getPosition(), true, true);
     } else {
       mc.dropMessage("The Item " + itemId + " does not exist");
     }
   } else if (splitted[0].equalsIgnoreCase("clearslot")) {
     if (splitted[1].equalsIgnoreCase("all")) {
       clearslot(c, 1);
       clearslot(c, 2);
       clearslot(c, 3);
       clearslot(c, 4);
       clearslot(c, 5);
       mc.dropMessage("All inventory slots cleared.");
     } else if (splitted[1].equalsIgnoreCase("eq")) {
       clearslot(c, 1);
       mc.dropMessage("Eq inventory slots cleared.");
     } else if (splitted[1].equalsIgnoreCase("use")) {
       clearslot(c, 2);
       mc.dropMessage("Use inventory slots cleared.");
     } else if (splitted[1].equalsIgnoreCase("etc")) {
       clearslot(c, 4);
       mc.dropMessage("Etc inventory slots cleared.");
     } else if (splitted[1].equalsIgnoreCase("setup")) {
       clearslot(c, 3);
       mc.dropMessage("Setup inventory slots cleared.");
     } else if (splitted[1].equalsIgnoreCase("cash")) {
       clearslot(c, 5);
       mc.dropMessage("Cash inventory slots cleared.");
     } else {
       mc.dropMessage("!clearslot " + splitted[1] + " does not exist!");
     }
   } else if (splitted[0].equalsIgnoreCase("omghax")) {
     short stat = 1;
     short wa = 1;
     int itemid = 1302000;
     if (splitted.length == 4) {
       try {
         itemid = Integer.parseInt(splitted[1]);
         stat = Short.parseShort(splitted[2]);
         wa = Short.parseShort(splitted[3]);
       } catch (NumberFormatException numberFormatException) {
       }
     } else if (splitted.length == 3) {
       try {
         itemid = Integer.parseInt(splitted[1]);
         stat = Short.parseShort(splitted[2]);
       } catch (NumberFormatException numberFormatException) {
       }
     } else if (splitted.length == 2) {
       try {
         itemid = Integer.parseInt(splitted[1]);
       } catch (NumberFormatException numberFormatException) {
       }
       stat = 32767;
     }
     if (itemid > 1000000 && itemid > 2000000 || ii.getSlotMax(itemid) > 0) {
       MapleInventoryManipulator.addStatItemById(c, itemid, c.getPlayer().getName(), stat, wa, wa);
     } else {
       mc.dropMessage("You have entered invalid Item ID : " + itemid);
     }
   }
 }
예제 #30
0
파일: MapleGuild.java 프로젝트: opencat/Nin
 public final MapleCharacter getLeader(final MapleClient c) {
   return c.getChannelServer().getPlayerStorage().getCharacterById(leader);
 }