Example #1
0
  @Override
  public void handleChat(int type, L2PcInstance activeChar, String target, String text) {
    if (!FloodProtectors.performAction(activeChar.getClient(), Action.TRADE_CHAT)) return;

    final CreatureSay cs =
        new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
    final int region = MapRegionTable.getMapRegion(activeChar.getX(), activeChar.getY());

    for (L2PcInstance player : L2World.getInstance().getPlayers()) {
      if (!BlockList.isBlocked(player, activeChar)
          && region == MapRegionTable.getMapRegion(player.getX(), player.getY()))
        player.sendPacket(cs);
    }
  }
Example #2
0
  /**
   * Adda mercenary ticket.
   *
   * <ul>
   *   <li>find the npc that needs to be saved in the mercenary spawns, given this item
   *   <li>Use the passed character's location info to add the spawn
   *   <li>create a copy of the item to drop in the world returns the id of the mercenary npc that
   *       was added to the spawn returns -1 if this fails.
   * </ul>
   *
   * @param itemId
   * @param activeChar
   * @return
   */
  public int addTicket(int itemId, L2PcInstance activeChar) {
    int x = activeChar.getX();
    int y = activeChar.getY();
    int z = activeChar.getZ();
    int heading = activeChar.getHeading();

    Castle castle = CastleManager.getInstance().getCastle(activeChar);
    if (castle == null) // this should never happen at this point
    return -1;

    for (int i = 0; i < ITEM_IDS.length; i++) {
      if (ITEM_IDS[i] == itemId) // Find the index of the item used
      {
        spawnMercenary(NPC_IDS[i], x, y, z, 3000);

        // Hire merc for this castle. NpcId is at the same index as the item used.
        castle.getSiege().getSiegeGuardManager().hireMerc(x, y, z, heading, NPC_IDS[i]);

        // create the ticket in the gameworld
        ItemInstance dropticket = new ItemInstance(IdFactory.getInstance().getNextId(), itemId);
        dropticket.setLocation(ItemInstance.ItemLocation.INVENTORY);
        dropticket.setDestroyProtected(true);
        dropticket.dropMe(activeChar, x, y, z);
        L2World.getInstance().storeObject(dropticket); // add to the world
        // and keep track of this ticket in the list
        _droppedTickets.add(dropticket);

        return NPC_IDS[i];
      }
    }
    return -1;
  }
Example #3
0
  /**
   * This method is used to drop the CW from a monster.<br>
   * It drops the item on ground, and broadcast earthquake && red sky animations.
   *
   * @param attackable : The monster who dropped CW.
   * @param player : The player who killed the monster.
   */
  private void dropFromMob(L2Attackable attackable, L2PcInstance player) {
    _isActivated = false;

    // get position
    int x = attackable.getX() + Rnd.get(-70, 70);
    int y = attackable.getY() + Rnd.get(-70, 70);
    int z = GeoData.getInstance().getHeight(x, y, attackable.getZ());

    // create item and drop it
    _item = ItemTable.getInstance().createItem("CursedWeapon", _itemId, 1, player, attackable);
    _item.setDestroyProtected(true);
    _item.dropMe(attackable, x, y, z);

    // RedSky and Earthquake
    Broadcast.toAllOnlinePlayers(new ExRedSky(10));
    Broadcast.toAllOnlinePlayers(new Earthquake(x, y, z, 14, 3));

    _isDropped = true;

    SystemMessage sm =
        SystemMessage.getSystemMessage(SystemMessageId.S2_WAS_DROPPED_IN_THE_S1_REGION);
    sm.addZoneName(player.getX(), player.getY(), player.getZ());
    sm.addItemName(_itemId);

    Broadcast.toAllOnlinePlayers(sm);
  }
Example #4
0
  /**
   * This method is used to drop the CW from player.<br>
   * It drops the item on ground, and reset player stats.
   *
   * @param killer : The player who killed CW owner.
   */
  private void dropFromPlayer(L2Character killer) {
    _player.abortAttack();

    // Prevent item from being removed by ItemsAutoDestroy
    _item.setDestroyProtected(true);
    _player.dropItem("DieDrop", _item, killer, true);

    _isActivated = false;
    _isDropped = true;

    _player.setKarma(_playerKarma);
    _player.setPkKills(_playerPkKills);
    _player.setCursedWeaponEquippedId(0);
    removeDemonicSkills();

    // Cancel the daily timer. It will be reactivated when someone will pickup the weapon.
    cancelDailyTimerTask();

    // Activate the "1h dropped CW" timer.
    _dropTimerTask = ThreadPoolManager.getInstance().scheduleGeneral(new DropTimerTask(), 3600000L);

    // Reset current stage to 1.
    _currentStage = 1;

    // Drop infos from database.
    removeFromDb();

    SystemMessage sm =
        SystemMessage.getSystemMessage(SystemMessageId.S2_WAS_DROPPED_IN_THE_S1_REGION);
    sm.addZoneName(_player.getX(), _player.getY(), _player.getZ());
    sm.addItemName(_itemId);

    Broadcast.toAllOnlinePlayers(sm);
  }
Example #5
0
  public void goTo(L2PcInstance player) {
    if (player == null) return;

    // Go to player holding the weapon
    if (_isActivated) player.teleToLocation(_player.getX(), _player.getY(), _player.getZ(), 0);
    // Go to item on the ground
    else if (_isDropped) player.teleToLocation(_item.getX(), _item.getY(), _item.getZ(), 0);
    else player.sendMessage(_name + " isn't in the world.");
  }
 /**
  * @param activeChar
  * @param player
  */
 private void gatherCharacterInfo(L2PcInstance activeChar, L2PcInstance player, String filename) {
   String ip = "N/A";
   String account = "N/A";
   try {
     String clientInfo = player.getClient().toString();
     account =
         clientInfo.substring(clientInfo.indexOf("Account: ") + 9, clientInfo.indexOf(" - IP: "));
     ip = clientInfo.substring(clientInfo.indexOf(" - IP: ") + 7, clientInfo.lastIndexOf("]"));
   } catch (Exception e) {
   }
   NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
   adminReply.setFile("data/html/admin/" + filename);
   adminReply.replace("%name%", player.getName());
   adminReply.replace("%level%", String.valueOf(player.getLevel()));
   adminReply.replace(
       "%clan%", String.valueOf(ClanTable.getInstance().getClan(player.getClanId())));
   adminReply.replace("%xp%", String.valueOf(player.getExp()));
   adminReply.replace("%sp%", String.valueOf(player.getSp()));
   adminReply.replace("%class%", player.getTemplate().className);
   adminReply.replace("%ordinal%", String.valueOf(player.getClassId().ordinal()));
   adminReply.replace("%classid%", String.valueOf(player.getClassId()));
   adminReply.replace("%x%", String.valueOf(player.getX()));
   adminReply.replace("%y%", String.valueOf(player.getY()));
   adminReply.replace("%z%", String.valueOf(player.getZ()));
   adminReply.replace("%currenthp%", String.valueOf((int) player.getCurrentHp()));
   adminReply.replace("%maxhp%", String.valueOf(player.getMaxHp()));
   adminReply.replace("%karma%", String.valueOf(player.getKarma()));
   adminReply.replace("%currentmp%", String.valueOf((int) player.getCurrentMp()));
   adminReply.replace("%maxmp%", String.valueOf(player.getMaxMp()));
   adminReply.replace("%pvpflag%", String.valueOf(player.getPvpFlag()));
   adminReply.replace("%currentcp%", String.valueOf((int) player.getCurrentCp()));
   adminReply.replace("%maxcp%", String.valueOf(player.getMaxCp()));
   adminReply.replace("%pvpkills%", String.valueOf(player.getPvpKills()));
   adminReply.replace("%pkkills%", String.valueOf(player.getPkKills()));
   adminReply.replace("%currentload%", String.valueOf(player.getCurrentLoad()));
   adminReply.replace("%maxload%", String.valueOf(player.getMaxLoad()));
   adminReply.replace(
       "%percent%",
       String.valueOf(
           Util.roundTo(
               ((float) player.getCurrentLoad() / (float) player.getMaxLoad()) * 100, 2)));
   adminReply.replace("%patk%", String.valueOf(player.getPAtk(null)));
   adminReply.replace("%matk%", String.valueOf(player.getMAtk(null, null)));
   adminReply.replace("%pdef%", String.valueOf(player.getPDef(null)));
   adminReply.replace("%mdef%", String.valueOf(player.getMDef(null, null)));
   adminReply.replace("%accuracy%", String.valueOf(player.getAccuracy()));
   adminReply.replace("%evasion%", String.valueOf(player.getEvasionRate(null)));
   adminReply.replace("%critical%", String.valueOf(player.getCriticalHit(null, null)));
   adminReply.replace("%runspeed%", String.valueOf(player.getRunSpeed()));
   adminReply.replace("%patkspd%", String.valueOf(player.getPAtkSpd()));
   adminReply.replace("%matkspd%", String.valueOf(player.getMAtkSpd()));
   adminReply.replace("%access%", String.valueOf(player.getAccessLevel().getLevel()));
   adminReply.replace("%account%", account);
   adminReply.replace("%ip%", ip);
   activeChar.sendPacket(adminReply);
 }
Example #7
0
  private static void teleportToCharacter(L2PcInstance activeChar, L2PcInstance target) {
    if (target.getObjectId() == activeChar.getObjectId())
      activeChar.sendPacket(SystemMessageId.CANNOT_USE_ON_YOURSELF);
    else {
      int x = target.getX();
      int y = target.getY();
      int z = target.getZ();

      activeChar.getAI().setIntention(CtrlIntention.IDLE);
      activeChar.teleToLocation(x, y, z, 0);
      activeChar.sendMessage("You have teleported to " + target.getName() + ".");
    }
  }
Example #8
0
  /**
   * Method used to send messages.<br>
   *
   * <ul>
   *   <li>one is broadcasted to warn ppl CW is online.
   *   <li>the other shows left timer for for CW owner (either in hours or minutes).
   * </ul>
   */
  public void cursedOnLogin() {
    SystemMessage msg =
        SystemMessage.getSystemMessage(SystemMessageId.S2_OWNER_HAS_LOGGED_INTO_THE_S1_REGION);
    msg.addZoneName(_player.getX(), _player.getY(), _player.getZ());
    msg.addItemName(_player.getCursedWeaponEquippedId());
    Broadcast.toAllOnlinePlayers(msg);

    int timeLeft = (int) (getTimeLeft() / 60000);
    if (timeLeft > 60) {
      msg = SystemMessage.getSystemMessage(SystemMessageId.S2_HOUR_OF_USAGE_TIME_ARE_LEFT_FOR_S1);
      msg.addItemName(_player.getCursedWeaponEquippedId());
      msg.addNumber(Math.round(timeLeft / 60));
    } else {
      msg = SystemMessage.getSystemMessage(SystemMessageId.S2_MINUTE_OF_USAGE_TIME_ARE_LEFT_FOR_S1);
      msg.addItemName(_player.getCursedWeaponEquippedId());
      msg.addNumber(timeLeft);
    }
    _player.sendPacket(msg);
  }
Example #9
0
  private static void showHtml(L2PcInstance activeChar) {
    int worldX = activeChar.getX();
    int worldY = activeChar.getY();
    int geoX = ((((worldX - (-327680)) >> 4) >> 11) + 10);
    int geoY = ((((worldY - (-262144)) >> 4) >> 11) + 10);

    NpcHtmlMessage adminReply = new NpcHtmlMessage(0);
    adminReply.setFile("data/html/admin/zone.htm");

    adminReply.replace(
        "%MAPREGION%",
        "[x:"
            + MapRegionTable.getMapRegionX(activeChar.getX())
            + " y:"
            + MapRegionTable.getMapRegionX(activeChar.getY())
            + "]");
    adminReply.replace("%GEOREGION%", "" + geoX + "_" + geoY);
    adminReply.replace(
        "%CLOSESTTOWN%", MapRegionTable.getInstance().getClosestTownName(activeChar));
    adminReply.replace(
        "%CURRENTLOC%",
        "" + activeChar.getX() + ", " + activeChar.getY() + ", " + activeChar.getZ());

    adminReply.replace(
        "%PVP%", (activeChar.isInsideZone(ZoneId.PVP) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%PEACE%",
        (activeChar.isInsideZone(ZoneId.PEACE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%SIEGE%",
        (activeChar.isInsideZone(ZoneId.SIEGE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%MOTHERTREE%",
        (activeChar.isInsideZone(ZoneId.MOTHER_TREE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%CLANHALL%",
        (activeChar.isInsideZone(ZoneId.CLAN_HALL) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%NOLANDING%",
        (activeChar.isInsideZone(ZoneId.NO_LANDING) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%WATER%",
        (activeChar.isInsideZone(ZoneId.WATER) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%JAIL%",
        (activeChar.isInsideZone(ZoneId.JAIL) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%MONSTERTRACK%",
        (activeChar.isInsideZone(ZoneId.MONSTER_TRACK)
            ? "<font color=\"LEVEL\">YES</font>"
            : "NO"));
    adminReply.replace(
        "%CASTLE%",
        (activeChar.isInsideZone(ZoneId.CASTLE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%SWAMP%",
        (activeChar.isInsideZone(ZoneId.SWAMP) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%NOSUMMONFRIEND%",
        (activeChar.isInsideZone(ZoneId.NO_SUMMON_FRIEND)
            ? "<font color=\"LEVEL\">YES</font>"
            : "NO"));
    adminReply.replace(
        "%NOSTORE%",
        (activeChar.isInsideZone(ZoneId.NO_STORE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%TOWN%",
        (activeChar.isInsideZone(ZoneId.TOWN) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%HQ%", (activeChar.isInsideZone(ZoneId.HQ) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%DANGERAREA%",
        (activeChar.isInsideZone(ZoneId.DANGER_AREA) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%CASTONARTIFACT%",
        (activeChar.isInsideZone(ZoneId.CAST_ON_ARTIFACT)
            ? "<font color=\"LEVEL\">YES</font>"
            : "NO"));
    adminReply.replace(
        "%NORESTART%",
        (activeChar.isInsideZone(ZoneId.NO_RESTART) ? "<font color=\"LEVEL\">YES</font>" : "NO"));

    StringBuilder zones = new StringBuilder(100);
    L2WorldRegion region = L2World.getInstance().getRegion(activeChar.getX(), activeChar.getY());
    for (L2ZoneType zone : region.getZones()) {
      if (zone.isCharacterInZone(activeChar)) {
        StringUtil.append(zones, String.valueOf(zone.getId()));
        StringUtil.append(zones, " ");
      }
    }
    adminReply.replace("%ZLIST%", zones.toString());
    activeChar.sendPacket(adminReply);
  }
Example #10
0
  @Override
  public boolean useAdminCommand(String command, L2PcInstance activeChar) {
    // runmod
    if (command.equals("admin_runmod") || command.equals("admin_instant_move"))
      activeChar.setTeleMode(1);
    if (command.equals("admin_runmod tele")) activeChar.setTeleMode(2);
    if (command.equals("admin_runmod norm")) activeChar.setTeleMode(0);

    // teleport via panels
    if (command.equals("admin_tele")) AdminHelpPage.showHelpPage(activeChar, "teleports.htm");
    if (command.equals("admin_tele_areas"))
      AdminHelpPage.showHelpPage(activeChar, "tele/other.htm");

    // recalls / goto types
    if (command.startsWith("admin_goto") || command.startsWith("admin_teleportto")) {
      StringTokenizer st = new StringTokenizer(command);
      if (st.countTokens() > 1) {
        st.nextToken();
        String plyr = st.nextToken();
        L2PcInstance player = L2World.getInstance().getPlayer(plyr);
        if (player == null) {
          activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
          return false;
        }

        teleportToCharacter(activeChar, player);
      }
    } else if (command.startsWith("admin_recall ")) {
      try {
        String targetName = command.substring(13);
        L2PcInstance player = L2World.getInstance().getPlayer(targetName);
        if (player == null) {
          activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
          return false;
        }

        teleportCharacter(player, activeChar.getX(), activeChar.getY(), activeChar.getZ());
      } catch (StringIndexOutOfBoundsException e) {
      }
    } else if (command.startsWith("admin_recall_party")) {
      try {
        String targetName = command.substring(19);
        L2PcInstance player = L2World.getInstance().getPlayer(targetName);
        if (player == null) {
          activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
          return false;
        }

        if (player.isInParty()) {
          for (L2PcInstance pm : player.getParty().getPartyMembers())
            teleportCharacter(pm, activeChar.getX(), activeChar.getY(), activeChar.getZ());

          activeChar.sendMessage("You recall " + player.getName() + "'s party.");
        } else {
          activeChar.sendMessage("You recall " + player.getName() + ", but he isn't in a party.");
          teleportCharacter(player, activeChar.getX(), activeChar.getY(), activeChar.getZ());
        }
      } catch (StringIndexOutOfBoundsException e) {
      }
    } else if (command.startsWith("admin_recall_clan")) {
      try {
        String targetName = command.substring(18);
        L2PcInstance player = L2World.getInstance().getPlayer(targetName);
        if (player == null) {
          activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
          return false;
        }

        L2Clan clan = player.getClan();
        if (clan != null) {
          for (L2PcInstance member : clan.getOnlineMembers())
            teleportCharacter(member, activeChar.getX(), activeChar.getY(), activeChar.getZ());

          activeChar.sendMessage("You recall " + player.getName() + "'s clan.");
        } else {
          activeChar.sendMessage(
              "You recall " + player.getName() + ", but he isn't a clan member.");
          teleportCharacter(player, activeChar.getX(), activeChar.getY(), activeChar.getZ());
        }
      } catch (StringIndexOutOfBoundsException e) {
      }
    } else if (command.startsWith("admin_move_to")) {
      try {
        String val = command.substring(14);
        teleportTo(activeChar, val);
      } catch (Exception e) {
        // Case of empty or missing coordinates
        AdminHelpPage.showHelpPage(activeChar, "teleports.htm");
      }
    } else if (command.startsWith("admin_sendhome")) {
      StringTokenizer st = new StringTokenizer(command);
      if (st.countTokens() > 1) {
        st.nextToken();
        String plyr = st.nextToken();
        L2PcInstance player = L2World.getInstance().getPlayer(plyr);
        if (player == null) {
          activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
          return false;
        }

        sendHome(player);
      } else {
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;

        // if target isn't a player, select yourself as target
        if (target instanceof L2PcInstance) player = (L2PcInstance) target;
        else player = activeChar;

        sendHome(player);
      }
    }
    return true;
  }
  public boolean useAdminCommand(String command, L2PcInstance activeChar) {
    if (command.equals("admin_current_player")) {
      showCharacterInfo(activeChar, null);
    } else if ((command.startsWith("admin_character_list"))
        || (command.startsWith("admin_character_info"))) {
      try {
        String val = command.substring(21);
        L2PcInstance target = L2World.getInstance().getPlayer(val);
        if (target != null) showCharacterInfo(activeChar, target);
        else activeChar.sendPacket(new SystemMessage(SystemMessageId.CHARACTER_DOES_NOT_EXIST));
      } catch (StringIndexOutOfBoundsException e) {
        activeChar.sendMessage(385);
      }
    } else if (command.startsWith("admin_show_characters")) {
      try {
        String val = command.substring(22);
        int page = Integer.parseInt(val);
        listCharacters(activeChar, page);
      } catch (StringIndexOutOfBoundsException e) {
        // Case of empty page number
        activeChar.sendMessage(421);
      }
    } else if (command.startsWith("admin_find_character")) {
      try {
        String val = command.substring(21);
        findCharacter(activeChar, val);
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character name
        activeChar.sendMessage(392);
        listCharacters(activeChar, 0);
      }
    } else if (command.startsWith("admin_find_ip")) {
      try {
        String val = command.substring(14);
        findCharactersPerIp(activeChar, val);
      } catch (Exception e) { // Case of empty or malformed IP number
        activeChar.sendMessage(393);
        listCharacters(activeChar, 0);
      }
    } else if (command.startsWith("admin_find_account")) {
      try {
        String val = command.substring(19);
        findCharactersPerAccount(activeChar, val);
      } catch (Exception e) { // Case of empty or malformed player name
        activeChar.sendMessage(391);
        listCharacters(activeChar, 0);
      }
    } else if (command.equals("admin_edit_character")) editCharacter(activeChar);
    // Karma control commands
    else if (command.equals("admin_nokarma")) setTargetKarma(activeChar, 0);
    else if (command.startsWith("admin_setkarma")) {
      try {
        String val = command.substring(15);
        int karma = Integer.parseInt(val);
        setTargetKarma(activeChar, karma);
      } catch (Exception e) {
        if (Config.DEVELOPER) _log.warning("Set karma error: " + e);
        activeChar.sendMessage(419);
      }
    } else if (command.startsWith("admin_setfame")) {
      try {
        String val = command.substring(14);
        int fame = Integer.parseInt(val);
        L2Object target = activeChar.getTarget();
        if (target instanceof L2PcInstance) {
          L2PcInstance player = (L2PcInstance) target;
          player.setFame(fame);
          player.sendPacket(new UserInfo(player));
          player.sendPacket(new ExBrExtraUserInfo(player));
          L2CoreMessage cm = new L2CoreMessage(MessageTable.Messages[261]);
          cm.addNumber(fame);
          cm.sendMessage(player);
        } else {
          activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
        }
      } catch (Exception e) {
        if (Config.DEVELOPER) _log.warning("Set Fame error: " + e);
        activeChar.sendMessage(316);
      }
    } else if (command.startsWith("admin_save_modifications")) {
      try {
        String val = command.substring(24);
        adminModifyCharacter(activeChar, val);
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character name
        activeChar.sendMessage(113);
        listCharacters(activeChar, 0);
      }
    } else if (command.startsWith("admin_rec")) {
      try {
        String val = command.substring(10);
        int recVal = Integer.parseInt(val);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        player.setRecomHave(recVal);
        player.sendMessage(528);
        player.broadcastUserInfo();
      } catch (Exception e) {
        activeChar.sendMessage(414);
      }
    } else if (command.startsWith("admin_setclass")) {
      try {
        String val = command.substring(15);
        int classidval = Integer.parseInt(val);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) player = (L2PcInstance) target;
        else return false;
        boolean valid = false;
        for (ClassId classid : ClassId.values()) if (classidval == classid.getId()) valid = true;
        if (valid && (player.getClassId().getId() != classidval)) {
          player.setClassId(classidval);
          if (!player.isSubClassActive()) player.setBaseClass(classidval);
          String newclass = player.getTemplate().className;
          player.store();
          L2CoreMessage cm = new L2CoreMessage(MessageTable.Messages[14]);
          cm.addString(newclass);
          cm.sendMessage(player);
          player.broadcastUserInfo();
          cm = new L2CoreMessage(MessageTable.Messages[670]);
          cm.addString(player.getName());
          cm.addString(newclass);
          cm.sendMessage(activeChar);
        }
        activeChar.sendMessage(418);
      } catch (StringIndexOutOfBoundsException e) {
        AdminHelpPage.showHelpPage(activeChar, "charclasses.htm");
      }
    } else if (command.startsWith("admin_settitle")) {
      try {
        String val = command.substring(15);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        player.setTitle(val);
        player.sendMessage(644);
        player.broadcastTitleInfo();
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character title
        activeChar.sendMessage(584);
      }
    } else if (command.startsWith("admin_changename")) {
      try {
        String val = command.substring(17);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        L2World.getInstance().removeFromAllPlayers(player);
        player.setName(val);
        player.store();
        L2World.getInstance().addToAllPlayers(player);

        player.sendMessage(623);
        player.broadcastUserInfo();

        if (player.isInParty()) {
          // Delete party window for other party members
          player.getParty().broadcastToPartyMembers(player, new PartySmallWindowDeleteAll());
          for (L2PcInstance member : player.getParty().getPartyMembers()) {
            // And re-add
            if (member != player)
              member.sendPacket(new PartySmallWindowAll(member, player.getParty()));
          }
        }
        if (player.getClan() != null) {
          player.getClan().broadcastClanStatus();
        }

        RegionBBSManager.getInstance().changeCommunityBoard();
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character name
        activeChar.sendMessage(420);
      }
    } else if (command.startsWith("admin_setsex")) {
      L2Object target = activeChar.getTarget();
      L2PcInstance player = null;
      if (target instanceof L2PcInstance) {
        player = (L2PcInstance) target;
      } else {
        return false;
      }
      player.getAppearance().setSex(player.getAppearance().getSex() ? false : true);
      player.sendMessage(621);
      player.broadcastUserInfo();
      player.decayMe();
      player.spawnMe(player.getX(), player.getY(), player.getZ());
    } else if (command.startsWith("admin_setcolor")) {
      try {
        String val = command.substring(15);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        player.getAppearance().setNameColor(Integer.decode("0x" + val));
        player.sendMessage(622);
        player.broadcastUserInfo();
      } catch (Exception e) { // Case of empty color or invalid hex string
        activeChar.sendMessage(583);
      }
    } else if (command.startsWith("admin_fullfood")) {
      L2Object target = activeChar.getTarget();
      if (target instanceof L2PetInstance) {
        L2PetInstance targetPet = (L2PetInstance) target;
        targetPet.setCurrentFed(targetPet.getMaxFed());
        targetPet
            .getOwner()
            .sendPacket(new SetSummonRemainTime(targetPet.getMaxFed(), targetPet.getCurrentFed()));
      } else activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
    } else if (command.startsWith("admin_unpenalty")) {
      try {
        StringTokenizer st = new StringTokenizer(command, " ");
        if (st.countTokens() != 3) {
          activeChar.sendMessage(364);
          return false;
        }

        st.nextToken();

        boolean changeCreateExpiryTime = st.nextToken().equalsIgnoreCase("create");

        String playerName = st.nextToken();
        L2PcInstance player = null;
        player = L2World.getInstance().getPlayer(playerName);

        if (player == null) {
          Connection con = L2DatabaseFactory.getInstance().getConnection();
          PreparedStatement ps =
              con.prepareStatement(
                  "UPDATE characters SET "
                      + (changeCreateExpiryTime
                          ? "clan_create_expiry_time"
                          : "clan_join_expiry_time")
                      + " WHERE char_name=? LIMIT 1");

          ps.setString(1, playerName);
          ps.execute();
        } else {
          // removing penalty
          if (changeCreateExpiryTime) player.setClanCreateExpiryTime(0);
          else player.setClanJoinExpiryTime(0);
        }

        L2CoreMessage cm = new L2CoreMessage(MessageTable.Messages[470]);
        cm.addString(playerName);
        cm.sendMessage(activeChar);
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else if (command.startsWith("admin_find_dualbox")) {
      int multibox = 2;
      try {
        String val = command.substring(19);
        multibox = Integer.parseInt(val);
        if (multibox < 1) {
          activeChar.sendMessage(97);
          return false;
        }
      } catch (Exception e) {
      }
      findDualbox(activeChar, multibox);
    }

    return true;
  }
  private void adminModifyCharacter(L2PcInstance activeChar, String modifications) {
    L2Object target = activeChar.getTarget();

    if (!(target instanceof L2PcInstance)) return;

    L2PcInstance player = (L2PcInstance) target;
    StringTokenizer st = new StringTokenizer(modifications);

    if (st.countTokens() != 6) {
      editCharacter(player);
      return;
    }

    String hp = st.nextToken();
    String mp = st.nextToken();
    String cp = st.nextToken();
    String pvpflag = st.nextToken();
    String pvpkills = st.nextToken();
    String pkkills = st.nextToken();

    int hpval = Integer.parseInt(hp);
    int mpval = Integer.parseInt(mp);
    int cpval = Integer.parseInt(cp);
    int pvpflagval = Integer.parseInt(pvpflag);
    int pvpkillsval = Integer.parseInt(pvpkills);
    int pkkillsval = Integer.parseInt(pkkills);

    // Common character information
    L2CoreMessage cm = new L2CoreMessage(MessageTable.Messages[30]);
    cm.addNumber(hpval);
    cm.addNumber(mpval);
    cm.addNumber(cpval);
    cm.addNumber(pvpflagval);
    cm.addNumber(pvpkillsval);
    cm.addNumber(pkkillsval);
    cm.sendMessage(player);
    player.setCurrentHp(hpval);
    player.setCurrentMp(mpval);
    player.setCurrentCp(cpval);
    player.setPvpFlag(pvpflagval);
    player.setPvpKills(pvpkillsval);
    player.setPkKills(pkkillsval);

    // Save the changed parameters to the database.
    player.store();

    StatusUpdate su = new StatusUpdate(player.getObjectId());
    su.addAttribute(StatusUpdate.CUR_HP, hpval);
    su.addAttribute(StatusUpdate.MAX_HP, player.getMaxHp());
    su.addAttribute(StatusUpdate.CUR_MP, mpval);
    su.addAttribute(StatusUpdate.MAX_MP, player.getMaxMp());
    su.addAttribute(StatusUpdate.CUR_CP, cpval);
    su.addAttribute(StatusUpdate.MAX_CP, player.getMaxCp());
    player.sendPacket(su);

    // Admin information
    cm = new L2CoreMessage(MessageTable.Messages[70]);
    cm.addString(player.getName());
    cm.addNumber(hpval);
    cm.addNumber(mpval);
    cm.addNumber(cpval);
    cm.addNumber(pvpflagval);
    cm.addNumber(pvpkillsval);
    cm.addNumber(pkkillsval);
    cm.sendMessage(activeChar);

    if (Config.DEBUG)
      _log.fine(
          "[GM]"
              + activeChar.getName()
              + " changed stats of "
              + player.getName()
              + ". "
              + " HP: "
              + hpval
              + " MP: "
              + mpval
              + " CP: "
              + cpval
              + " PvP: "
              + pvpflagval
              + " / "
              + pvpkillsval);

    showCharacterInfo(activeChar, null); // Back to start

    player.broadcastPacket(new CharInfo(player));
    player.sendPacket(new UserInfo(player));
    player.broadcastPacket(new ExBrExtraUserInfo(player));
    player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
    player.decayMe();
    player.spawnMe(activeChar.getX(), activeChar.getY(), activeChar.getZ());
  }
Example #13
0
  @Override
  public boolean useAdminCommand(String command, L2PcInstance activeChar) {
    if (command.equals("admin_forge")) showMainPage(activeChar);
    else if (command.startsWith("admin_forge2")) {
      try {
        StringTokenizer st = new StringTokenizer(command);
        st.nextToken();
        String format = st.nextToken();
        showPage2(activeChar, format);
      } catch (Exception ex) {
        activeChar.sendMessage("Usage: //forge2 format");
      }
    } else if (command.startsWith("admin_forge3")) {
      try {
        StringTokenizer st = new StringTokenizer(command);
        st.nextToken();
        String format = st.nextToken();
        boolean broadcast = false;

        if (format.toLowerCase().equals("broadcast")) {
          format = st.nextToken();
          broadcast = true;
        }

        AdminForgePacket sp = new AdminForgePacket();
        for (int i = 0; i < format.length(); i++) {
          String val = st.nextToken();
          if (val.toLowerCase().equals("$objid")) {
            val = String.valueOf(activeChar.getObjectId());
          } else if (val.toLowerCase().equals("$tobjid")) {
            val = String.valueOf(activeChar.getTarget().getObjectId());
          } else if (val.toLowerCase().equals("$bobjid")) {
            if (activeChar.getBoat() != null) {
              val = String.valueOf(activeChar.getBoat().getObjectId());
            }
          } else if (val.toLowerCase().equals("$clanid")) {
            val = String.valueOf(activeChar.getCharId());
          } else if (val.toLowerCase().equals("$allyid")) {
            val = String.valueOf(activeChar.getAllyId());
          } else if (val.toLowerCase().equals("$tclanid")) {
            val = String.valueOf(((L2PcInstance) activeChar.getTarget()).getCharId());
          } else if (val.toLowerCase().equals("$tallyid")) {
            val = String.valueOf(((L2PcInstance) activeChar.getTarget()).getAllyId());
          } else if (val.toLowerCase().equals("$x")) {
            val = String.valueOf(activeChar.getX());
          } else if (val.toLowerCase().equals("$y")) {
            val = String.valueOf(activeChar.getY());
          } else if (val.toLowerCase().equals("$z")) {
            val = String.valueOf(activeChar.getZ());
          } else if (val.toLowerCase().equals("$heading")) {
            val = String.valueOf(activeChar.getHeading());
          } else if (val.toLowerCase().equals("$tx")) {
            val = String.valueOf(activeChar.getTarget().getX());
          } else if (val.toLowerCase().equals("$ty")) {
            val = String.valueOf(activeChar.getTarget().getY());
          } else if (val.toLowerCase().equals("$tz")) {
            val = String.valueOf(activeChar.getTarget().getZ());
          } else if (val.toLowerCase().equals("$theading")) {
            val = String.valueOf(((L2PcInstance) activeChar.getTarget()).getHeading());
          }

          sp.addPart(format.getBytes()[i], val);
        }

        if (broadcast) activeChar.broadcastPacket(sp);
        else activeChar.sendPacket(sp);

        showPage3(activeChar, format, command);
      } catch (Exception ex) {
        activeChar.sendMessage("Usage: //forge or //forge2 format");
      }
    }
    return true;
  }
Example #14
0
  public void activate(L2PcInstance player, ItemInstance item) {
    // if the player is mounted, attempt to unmount first and pick it if successful.
    if (player.isMounted() && !player.dismount()) {
      player.sendPacket(
          SystemMessage.getSystemMessage(SystemMessageId.FAILED_TO_PICKUP_S1)
              .addItemName(item.getItemId()));
      item.setDestroyProtected(true);
      player.dropItem("InvDrop", item, null, true);
      return;
    }

    _isActivated = true;

    // Hold player data.
    _player = player;
    _playerId = _player.getObjectId();
    _playerKarma = _player.getKarma();
    _playerPkKills = _player.getPkKills();

    _item = item;

    // Generate a random number for next stage.
    _numberBeforeNextStage =
        Rnd.get((int) Math.round(_stageKills * 0.5), (int) Math.round(_stageKills * 1.5));

    // Renew hungry time.
    _hungryTime = _durationLost * 60;

    // Activate the daily timer.
    _dailyTimerTask =
        ThreadPoolManager.getInstance()
            .scheduleGeneralAtFixedRate(new DailyTimerTask(), 60000L, 60000L);

    // Cancel the "1h dropped CW" timer.
    cancelDropTimerTask();

    insertData();

    // Change player stats
    _player.setCursedWeaponEquippedId(_itemId);
    _player.setKarma(9999999);
    _player.setPkKills(0);

    if (_player.isInParty()) _player.getParty().removePartyMember(_player, MessageType.Expelled);

    // Disable active toggles
    for (L2Effect effect : _player.getAllEffects()) {
      if (effect.getSkill().isToggle()) effect.exit();
    }

    // Add CW skills
    giveDemonicSkills();

    // Equip the weapon
    _player.useEquippableItem(_item, true);

    // Fully heal player
    _player.setCurrentHpMp(_player.getMaxHp(), _player.getMaxMp());
    _player.setCurrentCp(_player.getMaxCp());

    // Refresh player stats
    _player.broadcastUserInfo();

    // _player.broadcastPacket(new SocialAction(_player, 17));
    Broadcast.toAllOnlinePlayers(
        SystemMessage.getSystemMessage(
                SystemMessageId.THE_OWNER_OF_S2_HAS_APPEARED_IN_THE_S1_REGION)
            .addZoneName(_player.getX(), _player.getY(), _player.getZ())
            .addItemName(_item.getItemId()));
  }
Example #15
0
  @Override
  protected void runImpl() {
    final L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null || activeChar.isTeleporting() || activeChar.inObserverMode()) return;

    final int realX = activeChar.getX();
    final int realY = activeChar.getY();
    int realZ = activeChar.getZ();

    if (Config.DEVELOPER)
      _log.fine(
          "C(S) pos: "
              + _x
              + "("
              + realX
              + ") "
              + _y
              + "("
              + realY
              + ") "
              + _z
              + "("
              + realZ
              + ") / "
              + _heading
              + "("
              + activeChar.getHeading()
              + ")");

    if (_x == 0 && _y == 0) {
      if (realX != 0) // in this case this seems like a client error
      return;
    }

    int dx, dy, dz;
    double diffSq;

    if (activeChar.isInBoat()) {
      if (Config.COORD_SYNCHRONIZE == 2) {
        dx = _x - activeChar.getInVehiclePosition().getX();
        dy = _y - activeChar.getInVehiclePosition().getY();
        dz = _z - activeChar.getInVehiclePosition().getZ();
        diffSq = (dx * dx + dy * dy);
        if (diffSq > 250000)
          sendPacket(
              new GetOnVehicle(activeChar.getObjectId(), _data, activeChar.getInVehiclePosition()));
      }
      return;
    }

    if (activeChar.isFalling(_z)) return; // disable validations during fall to avoid "jumping"

    dx = _x - realX;
    dy = _y - realY;
    dz = _z - realZ;
    diffSq = (dx * dx + dy * dy);

    if (activeChar.isFlying() || activeChar.isInsideZone(ZoneId.WATER)) {
      activeChar.setXYZ(realX, realY, _z);
      if (diffSq > 90000) // validate packet, may also cause z bounce if close to land
      activeChar.sendPacket(new ValidateLocation(activeChar));
    } else if (diffSq < 360000) // if too large, messes observation
    {
      if (Config.COORD_SYNCHRONIZE == -1) // Only Z coordinate synched to server,
      // mainly used when no geodata but can be used also with geodata
      {
        activeChar.setXYZ(realX, realY, _z);
        return;
      }
      if (Config.COORD_SYNCHRONIZE
          == 1) // Trusting also client x,y coordinates (should not be used with geodata)
      {
        // Heading changed on client = possible obstacle
        if (!activeChar.isMoving() || !activeChar.validateMovementHeading(_heading)) {
          // character is not moving, take coordinates from client
          if (diffSq
              < 2500) // 50*50 - attack won't work fluently if even small differences are corrected
          activeChar.setXYZ(realX, realY, _z);
          else activeChar.setXYZ(_x, _y, _z);
        } else activeChar.setXYZ(realX, realY, _z);

        activeChar.setHeading(_heading);
        return;
      }
      // Sync 2 (or other),
      // intended for geodata. Sends a validation packet to client
      // when too far from server calculated true coordinate.
      // Due to geodata/zone errors, some Z axis checks are made. (maybe a temporary solution)
      // Important: this code part must work together with L2Character.updatePosition
      if (Config.GEODATA > 0 && (diffSq > 250000 || Math.abs(dz) > 200)) {
        if (Math.abs(dz) > 200
            && Math.abs(dz) < 1500
            && Math.abs(_z - activeChar.getClientZ()) < 800) {
          activeChar.setXYZ(realX, realY, _z);
          realZ = _z;
        } else {
          if (Config.DEVELOPER)
            _log.info(activeChar.getName() + ": Synchronizing position Server --> Client");

          activeChar.sendPacket(new ValidateLocation(activeChar));
        }
      }
    }

    activeChar.setClientX(_x);
    activeChar.setClientY(_y);
    activeChar.setClientZ(_z);
    activeChar.setClientHeading(_heading); // No real need to validate heading.
    activeChar.setLastServerPosition(realX, realY, realZ);
  }