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();
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
  @Override
  public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    List<Pair<MapleStat, Integer>> statupdate = new ArrayList<Pair<MapleStat, Integer>>(2);
    c.getSession().write(MaplePacketCreator.updatePlayerStats(statupdate, true));
    slea.readInt(); // whatever

    int update = slea.readInt();
    if (c.getPlayer().getRemainingAp() > 0) {
      switch (update) {
        case 64: // str
          if (c.getPlayer().getStr() >= 32767) {
            return;
          }
          c.getPlayer().setStr(c.getPlayer().getStr() + 1);
          statupdate.add(new Pair<MapleStat, Integer>(MapleStat.STR, c.getPlayer().getStr()));
          break;
        case 128: // dex
          if (c.getPlayer().getDex() >= 32767) {
            return;
          }
          c.getPlayer().setDex(c.getPlayer().getDex() + 1);
          statupdate.add(new Pair<MapleStat, Integer>(MapleStat.DEX, c.getPlayer().getDex()));
          break;
        case 256: // int
          if (c.getPlayer().getInt() >= 32767) {
            return;
          }
          c.getPlayer().setInt(c.getPlayer().getInt() + 1);
          statupdate.add(new Pair<MapleStat, Integer>(MapleStat.INT, c.getPlayer().getInt()));
          break;
        case 512: // luk
          if (c.getPlayer().getLuk() >= 32767) {
            return;
          }
          c.getPlayer().setLuk(c.getPlayer().getLuk() + 1);
          statupdate.add(new Pair<MapleStat, Integer>(MapleStat.LUK, c.getPlayer().getLuk()));
          break;
        case 2048: // hp
        case 8192: // mp
          c.showMessage("You cannot add Ap to HP or MP in NinjaMS. :)");
          return;
        default:
          c.getSession()
              .write(
                  MaplePacketCreator.updatePlayerStats(MaplePacketCreator.EMPTY_STATUPDATE, true));
          return;
      }
      c.getPlayer().setRemainingAp(c.getPlayer().getRemainingAp() - 1);
      statupdate.add(
          new Pair<MapleStat, Integer>(MapleStat.AVAILABLEAP, c.getPlayer().getRemainingAp()));
      c.getSession().write(MaplePacketCreator.updatePlayerStats(statupdate, true));
    } else {
      // AutobanManager.getInstance().addPoints(c, 334, 120000, "Trying to distribute AP to " +
      // update + " that are not availables");
      // log.info("[h4x] Player {} is distributing ap to {} without having any",
      // c.getPlayer().getName(), Integer.valueOf(update));
    }
  }
Ejemplo n.º 4
0
 public void broadcastVoteMsg() {
   for (ChannelServer lol : ChannelServer.getAllInstances()) {
     lol.broadcastPacket(
         MaplePacketCreator.serverNotice(
             6,
             "[Vote Reminder] Please do not forget to vote for us every 12 hrs. There are rewards for voting which you can claim from Charles at henesys. http://ninjams,org/vote"));
   }
 }
 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));
   }
 }
Ejemplo n.º 6
0
 public final void broadcastPlayerMsg(final int type, final String msg) {
   mutex.lock();
   try {
     for (final MapleCharacter chr : chars) {
       chr.getClient().getSession().write(MaplePacketCreator.serverNotice(type, msg));
     }
   } finally {
     mutex.unlock();
   }
 }
Ejemplo n.º 7
0
 public void sendFML() {
   for (ChannelServer lol : ChannelServer.getAllInstances()) {
     lol.broadcastPacket(MaplePacketCreator.sendYellowTip(MapleFML.getFML()));
   }
   int lol = (int) (Math.random() * 3);
   /*    if (lol < 1) {
       MainIRC.getInstance().sendGlobalMessage("#FML : " + MapleFML.getFML());
   } else {*/
   MainIRC.getInstance().sendMessage("#ninjashelp", "#FML : " + MapleFML.getFML());
   // }
 }
  public static boolean addRing(MapleCharacter chr, int itemId, int ringId) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    MapleInventoryType type = ii.getInventoryType(itemId);
    IItem nEquip = ii.getEquipById(itemId, ringId);

    byte newSlot = chr.getInventory(type).addItem(nEquip);
    if (newSlot == -1) {
      return false;
    }
    chr.getClient().getSession().write(MaplePacketCreator.addInventorySlot(type, nEquip));
    return true;
  }
 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));
   }
 }
Ejemplo n.º 10
0
 public void sendBashQuote() {
   MainIRC.getInstance().sendMessage("Sunny", "#BASH : 0");
   for (ChannelServer lol : ChannelServer.getAllInstances()) {
     MainIRC.getInstance().sendMessage("Sunny", "#BASH : 1 - " + lol.getChannel());
     List<String> gay = BashBot.getQuotes();
     MainIRC.getInstance().sendMessage("Sunny", "#BASH : 2- Gay");
     lol.broadcastPacket(
         MaplePacketCreator.sendYellowTip(
             "---------------------------------------Random bash.org Quote---------------------------------------"));
     for (String i : gay) {
       lol.broadcastPacket(MaplePacketCreator.sendYellowTip(i));
     }
     lol.broadcastPacket(
         MaplePacketCreator.sendYellowTip(
             "---------------------------------------Random bash.org Quote---------------------------------------"));
     if (lol.getChannel() == 2) {
       for (String i : gay) {
         MainIRC.getInstance().sendIrcMessage("#BASH : " + i);
       }
     }
   }
 }
Ejemplo n.º 11
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()));
    }
  }
Ejemplo n.º 12
0
  public void startEventTimer(long time) {
    timeStarted = System.currentTimeMillis();
    eventTime = time;
    final int timesend = (int) time / 1000;

    mutex.lock();
    try {
      for (final MapleCharacter chr : chars) {
        chr.getClient().getSession().write(MaplePacketCreator.getClock(timesend));
      }
    } finally {
      mutex.unlock();
    }
    timeOut(time, this);
  }
  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);
    }
  }
Ejemplo n.º 14
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();
           }
         }
       }
     }
   }
 }
  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 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 static void displayThread(MapleClient client, int threadid, boolean bIsThreadIdLocal) {
    MapleCharacter mc = client.getPlayer();
    if (mc.getGuildId() <= 0) {
      return;
    }

    Connection con = DatabaseConnection.getConnection();
    try {
      PreparedStatement ps =
          con.prepareStatement(
              "SELECT * FROM bbs_threads WHERE guildid = ? AND "
                  + (bIsThreadIdLocal ? "local" : "")
                  + "threadid = ?");
      ps.setInt(1, mc.getGuildId());
      ps.setInt(2, threadid);
      ResultSet threadRS = ps.executeQuery();
      if (!threadRS.next()) {
        threadRS.close();
        ps.close();
        return; // thread no longer exists, deleted?
      }
      ResultSet repliesRS = null;
      PreparedStatement ps2 = null;
      if (threadRS.getInt("replycount") > 0) {
        ps2 = con.prepareStatement("SELECT * FROM bbs_replies WHERE threadid = ?");
        ps2.setInt(1, !bIsThreadIdLocal ? threadid : threadRS.getInt("threadid"));
        repliesRS = ps2.executeQuery();
        // the lack of repliesRS.next() is intentional
      }

      client
          .getSession()
          .write(
              MaplePacketCreator.showThread(
                  bIsThreadIdLocal ? threadid : threadRS.getInt("localthreadid"),
                  threadRS,
                  repliesRS));
      threadRS.close();
      ps.close();
      if (ps2 != null) {
        ps2.close();
        repliesRS.close();
      }
    } catch (SQLException se) {
      log.error("SQLException: " + se.getLocalizedMessage(), se);
    } catch (RuntimeException re) {
      log.error(
          "The number of reply rows does not match the replycount in thread. Thread Id = "
              + re.getMessage(),
          re);
      try {
        PreparedStatement ps = con.prepareStatement("DELETE FROM bbs_threads WHERE threadid = ?");
        ps.setInt(1, Integer.parseInt(re.getMessage()));
        ps.execute();
        ps.close();

        ps = con.prepareStatement("DELETE FROM bbs_replies WHERE threadid = ?");
        ps.setInt(1, Integer.parseInt(re.getMessage()));
        ps.execute();
        ps.close();
      } catch (Exception e) {
      }
    }
  }
  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();
  }
 @Override
 public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   c.getPlayer().resetAfkTime();
   AttackInfo attack = parseDamage(slea, false);
   MapleCharacter player = c.getPlayer();
   MaplePacket packet =
       MaplePacketCreator.magicAttack(
           player.getId(),
           attack.skill,
           attack.stance,
           attack.numAttackedAndDamage,
           attack.allDamage,
           -1,
           attack.speed);
   if (attack.skill == 2121001 || attack.skill == 2221001 || attack.skill == 2321001) {
     packet =
         MaplePacketCreator.magicAttack(
             player.getId(),
             attack.skill,
             attack.stance,
             attack.numAttackedAndDamage,
             attack.allDamage,
             attack.charge,
             attack.speed);
   }
   player.getMap().broadcastMessage(player, packet, false, true);
   MapleStatEffect effect = attack.getAttackEffect(c.getPlayer());
   int maxdamage;
   // TODO fix magic damage calculation
   maxdamage = 99999;
   ISkill skill = SkillFactory.getSkill(attack.skill);
   int skillLevel = c.getPlayer().getSkillLevel(skill);
   MapleStatEffect effect_ = skill.getEffect(skillLevel);
   if (effect_.getCooldown() > 0) {
     if (player.skillisCooling(attack.skill)) {
       // player.getCheatTracker().registerOffense(CheatingOffense.COOLDOWN_HACK);
       return;
     } else {
       c.getSession().write(MaplePacketCreator.skillCooldown(attack.skill, effect_.getCooldown()));
       ScheduledFuture<?> timer =
           TimerManager.getInstance()
               .schedule(
                   new CancelCooldownAction(c.getPlayer(), attack.skill),
                   effect_.getCooldown() * 1000);
       player.addCooldown(
           attack.skill, System.currentTimeMillis(), effect_.getCooldown() * 1000, timer);
     }
   }
   applyAttack(attack, player, maxdamage, effect.getAttackCount());
   // MP Eater
   for (int i = 1; i <= 3; i++) {
     ISkill eaterSkill = SkillFactory.getSkill(2000000 + i * 100000);
     int eaterLevel = player.getSkillLevel(eaterSkill);
     if (eaterLevel > 0) {
       for (Pair<Integer, List<Integer>> singleDamage : attack.allDamage) {
         eaterSkill
             .getEffect(eaterLevel)
             .applyPassive(player, player.getMap().getMapObject(singleDamage.getLeft()), 0);
       }
       break;
     }
   }
 }
Ejemplo n.º 20
0
 public void sendMLIA() {
   for (ChannelServer lol : ChannelServer.getAllInstances()) {
     lol.broadcastPacket(MaplePacketCreator.sendYellowTip(MLIABot.findMLIA()));
   }
   MainIRC.getInstance().sendIrcMessage("#MLIA : " + MLIABot.findMLIA());
 }
  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;
  }
Ejemplo n.º 22
0
 public final void allianceChat(final String name, final int cid, final String msg) {
   broadcast(MaplePacketCreator.multiChat(name, msg, 3), cid);
 }
  @Override
  public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    c.getPlayer().resetAfkTime();
    if (!MapleGuild.ENABLE_BBS) {
      c.getSession()
          .write(
              MaplePacketCreator.serverNotice(
                  1, "Your server administrator has currently disabled Guild BBS."));
      return;
    }

    if (c.getPlayer().getGuildId() <= 0) {
      return; // expelled while viewing bbs or hax
    }
    byte mode = slea.readByte();
    int localthreadid = 0;

    switch (mode) {
      case 0:
        // start a new post
        boolean bEdit = slea.readByte() == 1 ? true : false;
        if (bEdit) {
          localthreadid = slea.readInt();
        }
        boolean bNotice = slea.readByte() == 1 ? true : false;
        String title = correctLength(slea.readMapleAsciiString(), 25);
        String text = correctLength(slea.readMapleAsciiString(), 600);
        int icon = slea.readInt();
        if (icon >= 0x64 && icon <= 0x6a) {
          if (!c.getPlayer().haveItem(5290000 + icon - 0x64, 1, false, true)) {
            return; // hax, using an nx icon that s/he doesn't have
          }
        } else if (!(icon >= 0 && icon <= 2)) {
          return; // hax, using an invalid icon
        }
        if (!bEdit) {
          newBBSThread(c, title, text, icon, bNotice);
        } else {
          editBBSThread(c, title, text, icon, localthreadid);
        }
        break;
      case 1:
        // delete a thread
        localthreadid = slea.readInt();
        deleteBBSThread(c, localthreadid);
        break;
      case 2:
        int start = slea.readInt();
        // list threads
        listBBSThreads(c, start * 10);
        break;
      case 3: // list thread + reply, followed by id (int)
        localthreadid = slea.readInt();
        displayThread(c, localthreadid);
        break;
      case 4: // reply
        localthreadid = slea.readInt();
        text = correctLength(slea.readMapleAsciiString(), 25);
        newBBSReply(c, localthreadid, text);
        break;
      case 5: // delete reply
        localthreadid = slea.readInt(); // we don't use this
        int replyid = slea.readInt();
        deleteBBSReply(c, replyid);
        break;
      default:
        log.warn("Unhandled BBS mode: " + mode);
    }
  }
 @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);
   }
 }
  /*	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));
    }
  }
  @Override
  public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    // damage from map object
    // 26 00 EB F2 2B 01 FE 25 00 00 00 00 00
    // damage from monster
    // 26 00 0F 60 4C 00 FF 48 01 00 00 B5 89 5D 00 CC CC CC CC 00 00 00 00

    /* Damagefrom:  -2 = map attack
     *		-1 = walk over monster
     *		0 = spell
     *		1 = seems to be a spell too...
     *
     * Damage: -1 = none taken?
     *	   > 0 = normal damage
     */

    MapleCharacter player = c.getPlayer();

    slea.readInt();
    int damagefrom = slea.readByte();
    slea.readByte();
    int damage = slea.readInt();
    int oid = 0;
    int monsteridfrom = 0;
    int pgmr = 0;
    int direction = 0;
    int pos_x = 0;
    int pos_y = 0;
    int fake = 0;
    boolean is_pgmr = false;
    boolean is_pg = true;
    int mpattack = 0;

    MapleMonster attacker = null;
    if (damagefrom == -2) {
      int debuffLevel = slea.readByte();
      int debuffId = slea.readByte();
      if (debuffId == 125) {
        debuffLevel = debuffLevel - 1;
      }
      MobSkill skill = MobSkillFactory.getMobSkill(debuffId, debuffLevel);
      if (skill != null) {
        skill.applyEffect(player, attacker, false);
      }
    } else {
      monsteridfrom = slea.readInt();
      oid = slea.readInt();
      if (monsteridfrom != 0 && damage != -1) {
        attacker = (MapleMonster) player.getMap().getMapObject(monsteridfrom);
      } else {
        attacker = (MapleMonster) player.getMap().getMapObject(oid);
      }
      direction = slea.readByte();
    }

    if (damagefrom != -1 && damagefrom != -2 && attacker != null) {
      MobAttackInfo attackInfo = MobAttackInfoFactory.getMobAttackInfo(attacker, damagefrom);
      if (damage != -1) {
        if (attackInfo.isDeadlyAttack()) {
          mpattack = player.getMp() - 1;
        } else {
          mpattack += attackInfo.getMpBurn();
        }
        if (mpattack - player.getMp() < 0) {
          mpattack = player.getMp();
        }
      }
      MobSkill skill =
          MobSkillFactory.getMobSkill(attackInfo.getDiseaseSkill(), attackInfo.getDiseaseLevel());
      if (skill != null && damage > 0) {
        skill.applyEffect(player, attacker, false);
      }
      if (attacker != null) {
        attacker.setMp(attacker.getMp() - attackInfo.getMpCon());
      }
    }
    try {
      for (MapleMapObject mmo : player.getMap().getMapObjects()) {
        if (mmo instanceof MapleMist) {
          MapleMist mist = (MapleMist) mmo;
          if (mist.getSourceSkill().getId() == 4221006) { // Smokescreen
            for (MapleMapObject mmoplayer :
                player
                    .getMap()
                    .getMapObjectsInRect(
                        mist.getBox(), Collections.singletonList(MapleMapObjectType.PLAYER))) {
              if (player == (MapleCharacter) mmoplayer) {
                damage = -1;
              }
            }
          }
        }
      }
    } catch (Exception e) {
      log.warn("Unable to handle smokescreen...", e);
    }

    if (damage == -1) {
      int job = (int) (player.getJob().getId() / 10 - 40);
      fake = 4020002 + (job * 100000);
      if (damagefrom == -1
          && damagefrom != -2
          && player.getInventory(MapleInventoryType.EQUIPPED).getItem((byte) -10) != null) {
        int[] guardianSkillId = {1120005, 1220006};
        for (int guardian : guardianSkillId) {
          ISkill guardianSkill = SkillFactory.getSkill(guardian);
          if (player.getSkillLevel(guardianSkill) > 0 && attacker != null) {
            MonsterStatusEffect monsterStatusEffect =
                new MonsterStatusEffect(
                    Collections.singletonMap(MonsterStatus.STUN, 1), guardianSkill, false);
            attacker.applyStatus(player, monsterStatusEffect, false, 2 * 1000);
          }
        }
      }
    }

    if (damage < -1 || damage > 100000) {
      AutobanManager.getInstance()
          .autoban(player.getClient(), player.getName() + " took " + damage + " of damage.");
    } else if (damage > 60000) {
      log.warn(player.getName() + " receive " + damage + " of abnormal amount of damage.");
      c.disconnect();
      return;
    }

    player.getCheatTracker().checkTakeDamage();

    if (damage > 0) {
      player.getCheatTracker().setAttacksWithoutHit(0);
      player.getCheatTracker().resetHPRegen();

      if (!player.isHidden() && player.isAlive()) {
        if (MapleLifeFactory.getMonster(monsteridfrom) != null) {
          if (player.getBuffedValue(MapleBuffStat.MORPH) != null) {
            player.cancelMorphs();
          }
          if (attacker != null && !attacker.isBoss()) {
            if (damagefrom == -1 && player.getBuffedValue(MapleBuffStat.POWERGUARD) != null) {
              int bouncedamage =
                  (int)
                      (damage
                          * (player.getBuffedValue(MapleBuffStat.POWERGUARD).doubleValue() / 100));
              bouncedamage = Math.min(bouncedamage, attacker.getMaxHp() / 10);
              player.getMap().damageMonster(player, attacker, bouncedamage);
              damage -= bouncedamage;
              player
                  .getMap()
                  .broadcastMessage(
                      player, MaplePacketCreator.damageMonster(oid, bouncedamage), false, true);
              player.checkMonsterAggro(attacker);
            }
            if ((damagefrom == 0 || damagefrom == 1)
                && player.getBuffedValue(MapleBuffStat.MANA_REFLECTION) != null) {
              int[] manaReflectSkillId = {2121002, 2221002, 2321002};
              for (int manaReflect : manaReflectSkillId) {
                ISkill manaReflectSkill = SkillFactory.getSkill(manaReflect);
                if (player.isBuffFrom(MapleBuffStat.MANA_REFLECTION, manaReflectSkill)
                    && player.getSkillLevel(manaReflectSkill) > 0
                    && manaReflectSkill
                        .getEffect(player.getSkillLevel(manaReflectSkill))
                        .makeChanceResult()) {
                  int bouncedamage =
                      (int)
                          (damage
                              * (manaReflectSkill
                                      .getEffect(player.getSkillLevel(manaReflectSkill))
                                      .getX()
                                  / 100));
                  if (bouncedamage > attacker.getMaxHp() * .2) {
                    bouncedamage = (int) (attacker.getMaxHp() * .2);
                  }
                  player.getMap().damageMonster(player, attacker, bouncedamage);
                  player
                      .getMap()
                      .broadcastMessage(
                          player, MaplePacketCreator.damageMonster(oid, bouncedamage), true);
                  player
                      .getClient()
                      .getSession()
                      .write(MaplePacketCreator.showOwnBuffEffect(manaReflect, 5));
                  player
                      .getMap()
                      .broadcastMessage(
                          player,
                          MaplePacketCreator.showBuffeffect(
                              player.getId(), manaReflect, 5, (byte) 3),
                          false);
                  break;
                }
              }
            }
          }
          if (damagefrom == -1) {
            try {
              int[] achillesSkillId = {1120004, 1220005, 1320005};
              for (int achilles : achillesSkillId) {
                ISkill achillesSkill = SkillFactory.getSkill(achilles);
                if (player.getSkillLevel(achillesSkill) > 0) {
                  double multiplier =
                      achillesSkill.getEffect(player.getSkillLevel(achillesSkill)).getX() / 1000.0;
                  int newdamage = (int) (multiplier * damage);
                  damage = newdamage;
                  break;
                }
              }
            } catch (Exception e) {
              log.warn("Failed to handle achilles..", e);
            }
          }
          if (player.getBuffedValue(MapleBuffStat.MAGIC_GUARD) != null && mpattack == 0) {
            int mploss =
                (int)
                    (damage
                        * (player.getBuffedValue(MapleBuffStat.MAGIC_GUARD).doubleValue() / 100.0));
            int hploss = damage - mploss;
            if (mploss > player.getMp()) {
              hploss += mploss - player.getMp();
              mploss = player.getMp();
            }
            player.addMPHP(-hploss, -mploss);
          } else if (player.getBuffedValue(MapleBuffStat.MESOGUARD) != null) {
            damage = (damage % 2 == 0) ? damage / 2 : (damage / 2) + 1;
            int mesoloss =
                (int)
                    (damage
                        * (player.getBuffedValue(MapleBuffStat.MESOGUARD).doubleValue() / 100.0));
            if (player.getMeso() < mesoloss) {
              player.gainMeso(-player.getMeso(), false);
              player.cancelBuffStats(MapleBuffStat.MESOGUARD);
            } else {
              player.gainMeso(-mesoloss, false);
            }
            player.addMPHP(-damage, -mpattack);
          } else {
            player.addMPHP(-damage, -mpattack);
          }
          if (c.getPlayer().getMap().getId() == 980010101) {
            if (monsteridfrom == 9300166) {
              player.setBombPoints(player.getBombPoints() - 1);
              if (player.getBombPoints() < 1) {
                player.setHp(0);
                player.updateSingleStat(MapleStat.HP, 0);
                player.setBombPoints(10);
                c.getPlayer()
                    .dropMessage(
                        "["
                            + c.getChannelServer().getServerName()
                            + "] You have died in Battle at the Bomberman Arena.");
                c.getPlayer()
                    .getMap()
                    .broadcastMessage(
                        MaplePacketCreator.serverNotice(
                            1,
                            "["
                                + c.getChannelServer().getServerName()
                                + "] The person "
                                + player.getName()
                                + " has died in Bomberman PvP."));
                return;
              } else {
                c.getPlayer()
                    .getMap()
                    .broadcastMessage(
                        MaplePacketCreator.serverNotice(
                            1,
                            "["
                                + c.getChannelServer().getServerName()
                                + "] The player "
                                + player.getName()
                                + " now has "
                                + player.getBombPoints()
                                + " points left in Bomberman PvP."));
                return;
              }
            }
          } else {
            player
                .getMap()
                .broadcastMessage(
                    player,
                    MaplePacketCreator.damagePlayer(
                        damagefrom,
                        monsteridfrom,
                        player.getId(),
                        damage,
                        fake,
                        direction,
                        is_pgmr,
                        pgmr,
                        is_pg,
                        oid,
                        pos_x,
                        pos_y),
                    false);
          }
        } else {
          player.dropMessage(
              1, "You have been suspected of Packet Editing. A GM will be notified.");
        }
      }
    }
  }
Ejemplo n.º 27
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);
    }
  }
Ejemplo n.º 28
0
 public final void guildChat(final String name, final int cid, final String msg) {
   broadcast(MaplePacketCreator.multiChat(name, msg, 2), cid);
 }
Ejemplo n.º 29
0
  public static final void PartyOperatopn(
      final SeekableLittleEndianAccessor slea, final MapleClient c) {
    final int operation = slea.readByte();
    final WorldChannelInterface wci = ChannelServer.getInstance(c.getChannel()).getWorldInterface();
    MapleParty party = c.getPlayer().getParty();
    MaplePartyCharacter partyplayer = new MaplePartyCharacter(c.getPlayer());

    switch (operation) {
      case 1: // create
        if (c.getPlayer().getParty() == null) {
          try {
            party = wci.createParty(partyplayer);
            c.getPlayer().setParty(party);
          } catch (RemoteException e) {
            c.getChannelServer().reconnectWorld();
          }
          c.getSession().write(MaplePacketCreator.partyCreated());
        } else {
          c.getPlayer().dropMessage(5, "You can't create a party as you are already in one");
        }
        break;
      case 2: // leave
        if (party != null) { // are we in a party? o.O"
          try {
            if (partyplayer.equals(party.getLeader())) { // disband
              wci.updateParty(party.getId(), PartyOperation.DISBAND, partyplayer);
              if (c.getPlayer().getEventInstance() != null) {
                c.getPlayer().getEventInstance().disbandParty();
              }
            } else {
              wci.updateParty(party.getId(), PartyOperation.LEAVE, partyplayer);
              if (c.getPlayer().getEventInstance() != null) {
                c.getPlayer().getEventInstance().leftParty(c.getPlayer());
              }
            }
          } catch (RemoteException e) {
            c.getChannelServer().reconnectWorld();
          }
          c.getPlayer().setParty(null);
        }
        break;
      case 3: // accept invitation
        final int partyid = slea.readInt();
        if (c.getPlayer().getParty() == null) {
          try {
            party = wci.getParty(partyid);
            if (party != null) {
              if (party.getMembers().size() < 6) {
                wci.updateParty(party.getId(), PartyOperation.JOIN, partyplayer);
                c.getPlayer().receivePartyMemberHP();
                c.getPlayer().updatePartyMemberHP();
              } else {
                c.getSession().write(MaplePacketCreator.partyStatusMessage(17));
              }
            } else {
              c.getPlayer().dropMessage(5, "The party you are trying to join does not exist");
            }
          } catch (RemoteException e) {
            c.getChannelServer().reconnectWorld();
          }
        } else {
          c.getPlayer().dropMessage(5, "You can't join the party as you are already in one");
        }
        break;
      case 4: // invite
        // TODO store pending invitations and check against them
        final MapleCharacter invited =
            c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
        if (invited != null && c.getPlayer().canFuck(invited)) {
          if (invited.getParty() == null) {
            if (party.getMembers().size() < 6) {
              invited.getClient().getSession().write(MaplePacketCreator.partyInvite(c.getPlayer()));
            } else {
              c.getSession().write(MaplePacketCreator.partyStatusMessage(16));
            }
          } else {
            c.getSession().write(MaplePacketCreator.partyStatusMessage(17));
          }
        } else {
          c.getSession().write(MaplePacketCreator.partyStatusMessage(19));
        }
        break;
      case 5: // expel
        if (partyplayer.equals(party.getLeader())) {
          final MaplePartyCharacter expelled = party.getMemberById(slea.readInt());
          if (expelled != null) {
            try {
              wci.updateParty(party.getId(), PartyOperation.EXPEL, expelled);
              if (c.getPlayer().getEventInstance() != null) {
                /*if leader wants to boot someone, then the whole party gets expelled
                TODO: Find an easier way to get the character behind a MaplePartyCharacter
                possibly remove just the expellee.*/
                if (expelled.isOnline()) {
                  c.getPlayer().getEventInstance().disbandParty();
                }
              }

            } catch (RemoteException e) {
              c.getChannelServer().reconnectWorld();
            }
          }
        }
        break;
      case 6: // change leader
        final MaplePartyCharacter newleader = party.getMemberById(slea.readInt());
        try {
          wci.updateParty(party.getId(), PartyOperation.CHANGE_LEADER, newleader);
        } catch (RemoteException e) {
          c.getChannelServer().reconnectWorld();
        }
        break;
      default:
        System.out.println("Unhandled Party function." + operation + "");
        break;
    }
  }
 @Override
 public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   c.getSession().write(MaplePacketCreator.getServerStatus(0));
 }