public static boolean checkSpace(
     final MapleClient c, final int Id, int quantity, final String owner) {
   final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
   final MapleInventoryType type = ii.getInventoryType(Id);
   if (!type.equals(MapleInventoryType.EQUIP)) {
     final short slotMax = ii.getSlotMax(c, Id);
     final List<IItem> existing = c.getPlayer().getInventory(type).listById(Id);
     if (!InventoryConstants.isRechargable(Id)) {
       if (existing.size() > 0) {
         for (IItem eItem : existing) {
           final short oldQ = eItem.getQuantity();
           if (oldQ < slotMax && owner.equals(eItem.getOwner())) {
             final short newQ = (short) Math.min(oldQ + quantity, slotMax);
             quantity -= (newQ - oldQ);
           }
           if (quantity <= 0) {
             break;
           }
         }
       }
     }
     final int numSlotsNeeded;
     if (slotMax > 0) {
       numSlotsNeeded = (int) (Math.ceil(((double) quantity) / slotMax));
     } else if (InventoryConstants.isRechargable(Id)) {
       numSlotsNeeded = 1;
     } else {
       numSlotsNeeded = 1;
       System.out.println("checkSpace error");
     }
     return !c.getPlayer().getInventory(type).isFull(numSlotsNeeded - 1);
   } else {
     return !c.getPlayer().getInventory(type).isFull();
   }
 }
 @Override
 public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   if (c.getPlayer().getEnergyBar() == 15000
       || c.getPlayer().getBuffedValue(MapleBuffStat.BODY_PRESSURE) != null) {
     applyAttack(parseDamage(slea, c.getPlayer(), false), c.getPlayer(), 1);
   }
 }
Example #3
0
 @Override
 public int execute(MapleClient c, String[] splitted) {
   c.removeClickedNPC();
   NPCScriptManager.getInstance().dispose(c);
   c.getSession().write(CWvsContext.enableActions());
   return 1;
 }
Example #4
0
 @Override
 public int execute(MapleClient c, String[] splitted) {
   StringBuilder sb = new StringBuilder();
   sb.append("\r\n@str, @dex, @int, @luk, @hp, @mp <amount to add or subtract>");
   sb.append("\r\n@mob < Information on the closest monster >");
   sb.append(
       "\r\n@check < Displays various information; also use if you are stuck or unable to talk to NPC >");
   // sb.append("\r\n@npc < Universal NPC >");
   sb.append("\r\n@callgm < Send a message to all online GameMasters.");
   sb.append("\r\n@home < Warp to Acernis base >");
   sb.append("\r\n@fm < Warp to the FreeMarket instantly. >");
   sb.append("\r\n@job < Job advancements! >");
   sb.append("\r\n@save < Fixes your experience and saves your character >");
   /*sb.append("\r\n@joinevent < Join ongoing event >");
   sb.append("\r\n@crescent < Universal Town Warp / Event NPC>");
   sb.append("\r\n@dcash < Universal Cash Item Dropper >");
   sb.append("\r\n@tsmega < Toggle super megaphone on/off >");
   sb.append("\r\n@ea < If you are unable to attack or talk to NPC >");
   sb.append("\r\n@clearslot < Cleanup that trash in your inventory >");
   sb.append("\r\n@ranking < Use @ranking for more details >");
   sb.append("\r\n@checkdrop < Use @checkdrop for more details >");
   sb.append("\r\n@style < Styler >");
   sb.append("\r\n@advance < Job Advancer >");
   sb.append("\r\n@bosswarp < Boss Warper >");
   sb.append("\r\n@fly < Makes you fly if you're in the Free Market >");*/
   if (c.canClickNPC()) {
     NPCPacket.getNPCTalk(9010000, (byte) 0, sb.toString(), "00 00", (byte) 0);
   }
   for (String command : sb.toString().split("\r\n")) {
     c.getPlayer().dropMessage(5, command);
   }
   return 1;
 }
 public void end(MapleClient c, short questid, int npc) {
   MapleQuest quest = MapleQuest.getInstance(questid);
   if (!c.getPlayer().getQuest(quest).getStatus().equals(MapleQuestStatus.Status.STARTED)
       || !c.getPlayer().getMap().containsNPC(npc)) {
     dispose(c);
     return;
   }
   try {
     QuestActionManager qm = new QuestActionManager(c, questid, npc, false);
     if (qms.containsKey(c)) {
       return;
     }
     if (c.canClickNPC()) {
       qms.put(c, qm);
       Invocable iv = getInvocable("quest/" + questid + ".js", c);
       if (iv == null) {
         qm.dispose();
         return;
       }
       engine.put("qm", qm);
       scripts.put(c, iv);
       c.setClickedNPC();
       iv.invokeFunction("end", (byte) 1, (byte) 0, 0);
     }
   } catch (final UndeclaredThrowableException ute) {
     FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
     dispose(c);
   } catch (final Throwable t) {
     FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
     dispose(c);
   }
 }
Example #6
0
  public static final void CharlistRequest(final LittleEndianAccessor slea, final MapleClient c) {
    if (!c.isLoggedIn()) {
      c.getSession().close();
      return;
    }
    if (GameConstants.GMS) {
      slea.readByte(); // 2?
    }
    final int server = slea.readByte();
    final int channel = slea.readByte() + 1;
    if (!World.isChannelAvailable(channel) || server != 0) { // TODOO: MULTI WORLDS
      c.getSession().write(LoginPacket.getLoginFailed(10)); // cannot process so many
      return;
    }

    // System.out.println("Client " + c.getSession().getRemoteAddress().toString().split(":")[0] + "
    // is connecting to server " + server + " channel " + channel + "");

    final List<MapleCharacter> chars = c.loadCharacters(server);
    if (chars != null && ChannelServer.getInstance(channel) != null) {
      c.setWorld(server);
      c.setChannel(channel);
      c.getSession().write(LoginPacket.getSecondAuthSuccess(c));
      c.getSession()
          .write(LoginPacket.getCharList(c.getSecondPassword(), chars, c.getCharacterSlots()));
    } else {
      c.getSession().close();
    }
  }
  public static final void CharlistRequest(LittleEndianAccessor slea, MapleClient c) {
    if (!c.isLoggedIn()) {
      c.getSession().close(true);
      return;
    }
    if (GameConstants.GMS) {
      slea.readByte();
    }
    int server = slea.readByte();
    int channel = slea.readByte() + 1;
    if ((!World.isChannelAvailable(channel)) || (server != 0)) {
      c.getSession().write(LoginPacket.getLoginFailed(10));
      return;
    }

    List chars = c.loadCharacters(server);
    if ((chars != null) && (ChannelServer.getInstance(channel) != null)) {
      c.setWorld(server);
      c.setChannel(channel);

      c.getSession()
          .write(LoginPacket.getCharList(c.getSecondPassword(), chars, c.getCharacterSlots()));
    } else {
      c.getSession().close(true);
    }
  }
 @Override
 public void execute(MapleClient c, MessageCallback mc, String[] splitted)
     throws Exception, IllegalCommandSyntaxException {
   if (splitted[0].equals("!whosthere")) {
     MessageCallback callback = new ServernoticeMapleClientMessageCallback(c);
     StringBuilder builder = new StringBuilder("Players on Map: ");
     for (MapleCharacter chr : c.getPlayer().getMap().getCharacters()) {
       if (builder.length() > 150) { // wild guess :o
         builder.setLength(builder.length() - 2);
         callback.dropMessage(builder.toString());
         builder = new StringBuilder();
       }
       builder.append(MapleCharacter.makeMapleReadable(chr.getName()));
       builder.append(", ");
     }
     builder.setLength(builder.length() - 2);
     c.getSession().write(MaplePacketCreator.serverNotice(6, builder.toString()));
   } else if (splitted[0].equals("!cheaters")) {
     try {
       List<CheaterData> cheaters =
           c.getChannelServer().getWorldInterface().getCheaters(c.getWorld());
       for (int x = cheaters.size() - 1; x >= 0; x--) {
         CheaterData cheater = cheaters.get(x);
         mc.dropMessage(cheater.getInfo());
       }
     } catch (RemoteException e) {
       c.getChannelServer().reconnectWorld();
     }
   }
 }
  public static void CreateChar(LittleEndianAccessor slea, MapleClient c) {
    String name = slea.readMapleAsciiString();
    slea.skip(4);
    final JobType jobType =
        JobType.getByType(
            slea
                .readInt()); // BIGBANG: 0 = Resistance, 1 = Adventurer, 2 = Cygnus, 3 = Aran, 4 =
                             // Evan, 5 = Mercedes
    final short subCategory = slea.readShort(); // whether dual blade = 1 or adventurer = 0
    final byte gender = slea.readByte();
    byte skinColor = slea.readByte(); // 01
    int hairColor = 0;
    slea.skip(1);
    boolean mercedes = (jobType == JobType.Mercedes);
    boolean demon = (jobType == JobType.Demon);
    boolean adventurer = (jobType == JobType.Adventurer);
    int face = slea.readInt();
    int hair = slea.readInt();

    final int demonMark = demon ? slea.readInt() : 0;
    int top = slea.readInt();
    int bottom = (mercedes || demon || adventurer) ? 0 : slea.readInt();
    int shoes = slea.readInt();
    int weapon = slea.readInt();
    int shield = demon ? slea.readInt() : (mercedes ? 1352000 : 0);

    MapleCharacter newchar = MapleCharacter.getDefault(c);
    newchar.setWorld((byte) c.getWorld());
    newchar.setFace(face);
    newchar.setHair(hair + hairColor);
    newchar.setGender(gender);
    newchar.setName(name);
    newchar.setSkinColor(skinColor);
    newchar.setDemonMarking(demonMark);
    newchar.setSubcategory(subCategory);

    MapleInventory equip = newchar.getInventory(MapleInventoryType.EQUIPPED);
    Item eq_top = MapleItemInformationProvider.getInstance().getEquipById(top);
    eq_top.setPosition((byte) -5);
    equip.addFromDB(eq_top);
    Item eq_bottom = MapleItemInformationProvider.getInstance().getEquipById(bottom);
    eq_bottom.setPosition((byte) -6);
    Item eq_shoes = MapleItemInformationProvider.getInstance().getEquipById(shoes);
    eq_shoes.setPosition((byte) -7);
    equip.addFromDB(eq_shoes);
    Item eq_weapon = MapleItemInformationProvider.getInstance().getEquipById(weapon);
    eq_weapon.setPosition((byte) -11);
    equip.addFromDB(eq_weapon);

    if (MapleCharacterUtil.canCreateChar(name, false)
        && !LoginInformationProvider.getInstance().isForbiddenName(name)) {
      MapleCharacter.saveNewCharToDB(newchar, (short) 0);
      c.getSession().write(LoginPacket.addNewCharEntry(newchar, true));
      c.createdChar(newchar.getId());
    } else {
      c.getSession().write(LoginPacket.addNewCharEntry(newchar, false));
    }
    newchar = null;
  }
Example #10
0
 private static void sendMTSPackets(
     final MTSCart cart, final MapleClient c, final boolean changed) {
   c.getSession().write(MTSStorage.getInstance().getCurrentMTS(cart));
   c.getSession().write(MTSStorage.getInstance().getCurrentNotYetSold(cart));
   c.getSession().write(MTSStorage.getInstance().getCurrentTransfer(cart, changed));
   c.getSession().write(MTSCSPacket.showMTSCash(c.getPlayer()));
   c.getSession().write(MTSCSPacket.enableCSUse());
   MTSStorage.getInstance().checkExpirations();
 }
Example #11
0
 @Override
 public int execute(MapleClient c, String[] splitted) {
   if (c.getPlayer().卡图 == c.getPlayer().getMapId() && c.getPlayer().getMapId() / 1000000 != 4) {
     c.getPlayer().changeMap(100000000, 0);
   } else {
     c.getPlayer().dropMessage(1, "你没有卡图啊。");
   }
   return 1;
 }
Example #12
0
 @Override
 public int execute(MapleClient c, String[] splitted) {
   if (splitted.length < 2) {
     c.getPlayer().dropMessage(6, splitted[0] + " <金额>");
     return 0;
   }
   c.getPlayer().gainMeso(Long.parseLong(splitted[1]), true);
   return 1;
 }
 @Override
 public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   int server = slea.readByte();
   int channel = slea.readByte() + 1;
   c.setWorld(server);
   // log.info("Client is connecting to server {} channel {}", server, channel);
   c.setChannel(channel);
   c.sendCharList(server);
 }
Example #14
0
 @Override
 public void sendSpawnData(final MapleClient client) {
   if (questid <= 0
       || (client.getPlayer().getQuestStatus(questid) == 1
           && client.getPlayer().needQuestItem(questid, item.getItemId()))) {
     client.announce(
         MaplePacketCreator.dropItemFromMapObject(this, null, getPosition(), (byte) 2));
   }
 }
Example #15
0
 @Override
 public int execute(MapleClient c, String[] splitted) {
   if (c.getPlayer().isInBlockedMap() || c.getPlayer().hasBlockedInventory()) {
     c.getPlayer().dropMessage(5, "You may not use this command here.");
     return 0;
   }
   NPCScriptManager.getInstance().start(c, 9000000, null);
   return 1;
 }
 public static final void CheckCharName(String name, MapleClient c) {
   c.getSession()
       .write(
           LoginPacket.charNameResponse(
               name,
               (!MapleCharacterUtil.canCreateChar(name, c.isGm()))
                   || ((LoginInformationProvider.getInstance().isForbiddenName(name))
                       && (!c.isGm()))));
 }
Example #17
0
 @Override
 public int execute(MapleClient c, String[] splitted) {
   c.getPlayer()
       .setExp(
           c.getPlayer().getExp() - GameConstants.getExpNeededForLevel(c.getPlayer().getLevel())
                   >= 0
               ? GameConstants.getExpNeededForLevel(c.getPlayer().getLevel())
               : 0);
   return 1;
 }
Example #18
0
 @Override
 public int execute(MapleClient c, String[] splitted) {
   c.removeClickedNPC();
   NPCScriptManager.getInstance().dispose(c);
   ItemScriptManager.getInstance().dispose(c);
   QuestScriptManager.getInstance().dispose(c);
   c.getSession().write(MaplePacketCreator.enableActions());
   c.getPlayer().dropMessage(6, "解卡成功。");
   return 1;
 }
Example #19
0
 @Override
 public int execute(MapleClient c, String[] splitted) {
   for (final ChannelServer cserv : ChannelServer.getAllInstances()) {
     cserv.broadcastGMMessage(
         tools.packet.CField.multiChat(
             "[GM Help] " + c.getPlayer().getName(), StringUtil.joinStringFrom(splitted, 1), 6));
   }
   c.getPlayer().dropMessage(5, "Your message had been sent successfully.");
   return 1;
 }
Example #20
0
 @Override
 public int execute(MapleClient c, String[] splitted) {
   for (final ChannelServer cserv : ChannelServer.getAllInstances()) {
     cserv.broadcastGMMessage(
         MaplePacketCreator.multiChat(
             "[管理员帮助] " + c.getPlayer().getName(), StringUtil.joinStringFrom(splitted, 1), 0));
   }
   c.getPlayer().dropMessage(5, "你的消息已经发送成功");
   return 1;
 }
Example #21
0
 public void autobanDamage(MapleClient c, String reason) {
   if (c.getPlayer() == null) {
     return;
   }
   if (c.getPlayer().isGM()) {
     c.getPlayer().dropMessage(5, new StringBuilder().append("[警告] : ").append(reason).toString());
   } else {
     c.getPlayer().sendPolice(new StringBuilder().append("[警告] : ").append(reason).toString());
   }
 }
Example #22
0
 public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   if (!c.getPlayer().isAlive()) {
     c.getSession().write(MaplePacketCreator.enableActions());
     return;
   }
   MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
   slea.readInt();
   byte slot = (byte) slea.readShort();
   int itemId = slea.readInt();
   IItem toUse = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
   if (toUse != null && toUse.getQuantity() > 0 && toUse.getItemId() == itemId) {
     if (itemId == 2022178 || itemId == 2022433 || itemId == 2050004) {
       c.getPlayer().dispelDebuffs();
       remove(c, slot);
       return;
     } else if (itemId == 2050003) {
       c.getPlayer().dispelSeal();
       remove(c, slot);
       return;
     }
     if (isTownScroll(itemId)) {
       if (ii.getItemEffect(toUse.getItemId()).applyTo(c.getPlayer())) {
         remove(c, slot);
       }
       c.getSession().write(MaplePacketCreator.enableActions());
       return;
     }
     remove(c, slot);
     ii.getItemEffect(toUse.getItemId()).applyTo(c.getPlayer());
     c.getPlayer().checkBerserk();
   }
 }
Example #23
0
 public void autoban(MapleClient c, String reason) {
   if (c.getPlayer() == null) {
     return;
   }
   if (c.getPlayer().isGM()) {
     c.getPlayer()
         .dropMessage(5, new StringBuilder().append("[警告] A/b 触发: ").append(reason).toString());
     return;
   }
   addPoints(c, AUTOBAN_POINTS, 0L, reason);
 }
 public static final void MerchantItemStore(LittleEndianAccessor slea, MapleClient c) {
   if (c.getPlayer() == null) {
     return;
   }
   byte operation = slea.readByte();
   if ((operation == 27) || (operation == 28)) {
     requestItems(c, operation == 27);
   } else if (operation == 30) {
     c.getPlayer().setConversation(0);
   }
 }
 public static final void ServerStatusRequest(MapleClient c) {
   int numPlayer = LoginServer.getUsersOn();
   int userLimit = LoginServer.getUserLimit();
   if (numPlayer >= userLimit) {
     c.getSession().write(LoginPacket.getServerStatus(2));
   } else if (numPlayer * 2 >= userLimit) {
     c.getSession().write(LoginPacket.getServerStatus(1));
   } else {
     c.getSession().write(LoginPacket.getServerStatus(0));
   }
 }
Example #26
0
 public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   int itemId = slea.readInt();
   if (c.getPlayer().getInventory(MapleInventoryType.SETUP).findById(itemId) == null) {
     return;
   }
   c.getPlayer().setChair(itemId);
   c.getPlayer()
       .getMap()
       .broadcastMessage(
           c.getPlayer(), MaplePacketCreator.showChair(c.getPlayer().getId(), itemId), false);
   c.announce(MaplePacketCreator.enableActions());
 }
Example #27
0
 public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   if (!c.getPlayer().isAlive()) {
     c.announce(MaplePacketCreator.enableActions());
     return;
   }
   slea.readInt();
   byte slot = (byte) slea.readShort();
   int itemId = slea.readInt();
   MapleCharacter player = c.getPlayer();
   IItem toUse = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
   if (toUse != null && toUse.getQuantity() == 1) {
     if (toUse.getItemId() != itemId) {
       return;
     }
     Map<String, Integer> skilldata =
         MapleItemInformationProvider.getInstance()
             .getSkillStats(toUse.getItemId(), c.getPlayer().getJob().getId());
     boolean canuse = false;
     boolean success = false;
     int skill = 0;
     int maxlevel = 0;
     if (skilldata == null) {
       return;
     }
     if (skilldata.get("skillid") == 0) {
       canuse = false;
     } else if (player.getMasterLevel(SkillFactory.getSkill(skilldata.get("skillid")))
             >= skilldata.get("reqSkillLevel")
         || skilldata.get("reqSkillLevel") == 0) {
       canuse = true;
       if (Randomizer.nextInt(101) < skilldata.get("success") && skilldata.get("success") != 0) {
         success = true;
         ISkill skill2 = SkillFactory.getSkill(skilldata.get("skillid"));
         player.changeSkillLevel(
             skill2,
             player.getSkillLevel(skill2),
             Math.max(skilldata.get("masterLevel"), player.getMasterLevel(skill2)),
             -1);
       } else {
         success = false;
         player.message(
             "The skill book lights up, but the skill winds up as if nothing happened.");
       }
       MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short) 1, false);
     } else {
       canuse = false;
     }
     player
         .getClient()
         .announce(MaplePacketCreator.skillBookSuccess(player, skill, maxlevel, canuse, success));
   }
 }
Example #28
0
 public static final void ServerListRequest(final MapleClient c) {
   // c.getSession().write(LoginPacket.getLoginWelcome());
   c.getSession().write(LoginPacket.getServerList(0, LoginServer.getLoad()));
   // c.getSession().write(CField.getServerList(1, "Scania",
   // LoginServer.getInstance().getChannels(), 1200));
   // c.getSession().write(CField.getServerList(2, "Scania",
   // LoginServer.getInstance().getChannels(), 1200));
   // c.getSession().write(CField.getServerList(3, "Scania",
   // LoginServer.getInstance().getChannels(), 1200));
   c.getSession().write(LoginPacket.getEndOfServerList());
   c.getSession().write(LoginPacket.enableRecommended());
   c.getSession().write(LoginPacket.sendRecommended(0, LoginServer.getEventMessage()));
 }
Example #29
0
 @Override
 public int execute(MapleClient c, String[] splitted) {
   if (c.getPlayer().isInBlockedMap() || c.getPlayer().hasBlockedInventory()) {
     c.getPlayer().dropMessage(5, "You may not use this command here.");
     return 0;
   } else if (c.getPlayer().getLevel() < 30) {
     c.getPlayer().dropMessage(5, "You need to be at least lvl 30 in order to advance.");
     return 0;
   } else {
     NPCScriptManager.getInstance().start(c, 2300001, null);
     return 1;
   }
 }
  public static final void DeleteChar(LittleEndianAccessor slea, MapleClient c) {
    String Secondpw_Client = GameConstants.GMS ? slea.readMapleAsciiString() : null;
    if (Secondpw_Client == null) {
      if (slea.readByte() > 0) {
        Secondpw_Client = slea.readMapleAsciiString();
      }
      slea.readMapleAsciiString();
    }

    int Character_ID = slea.readInt();

    if ((!c.login_Auth(Character_ID)) || (!c.isLoggedIn()) || (loginFailCount(c))) {
      c.getSession().close(true);
      return;
    }
    byte state = 0;

    if (c.getSecondPassword() != null) {
      if (Secondpw_Client == null) {
        c.getSession().close(true);
        return;
      }
      if (!c.CheckSecondPassword(Secondpw_Client)) {
        state = 20;
      }
    }

    if (state == 0) {
      state = (byte) c.deleteCharacter(Character_ID);
    }
    c.getSession().write(LoginPacket.deleteCharResponse(Character_ID, state));
  }