Ejemplo n.º 1
0
  @Override
  protected void runImpl() {
    final L2PcInstance player = getClient().getActiveChar();
    if (player == null) return;

    final L2PcInstance partner = player.getActiveRequester();
    if (partner == null || L2World.getInstance().getPlayer(partner.getObjectId()) == null) {
      // Partner hasn't be found, cancel the invitation
      player.sendPacket(SystemMessageId.TARGET_IS_NOT_FOUND_IN_THE_GAME);
      player.setActiveRequester(null);
      return;
    }

    // If answer is positive, join the requester's PartyRoom.
    if (_answer == 1 && !partner.isRequestExpired()) {
      PartyMatchRoom _room = PartyMatchRoomList.getInstance().getRoom(partner.getPartyRoom());
      if (_room == null) return;

      if ((player.getLevel() >= _room.getMinLvl()) && (player.getLevel() <= _room.getMaxLvl())) {
        // Remove from waiting list
        PartyMatchWaitingList.getInstance().removePlayer(player);

        player.setPartyRoom(partner.getPartyRoom());

        player.sendPacket(new PartyMatchDetail(player, _room));
        player.sendPacket(new ExPartyRoomMember(player, _room, 0));

        for (L2PcInstance _member : _room.getPartyMembers()) {
          if (_member == null) continue;

          _member.sendPacket(new ExManagePartyRoomMember(player, _room, 0));
          _member.sendPacket(
              SystemMessage.getSystemMessage(SystemMessageId.S1_ENTERED_PARTY_ROOM)
                  .addPcName(player));
        }
        _room.addMember(player);

        // Info Broadcast
        player.broadcastUserInfo();
      } else player.sendPacket(SystemMessageId.CANT_ENTER_PARTY_ROOM);
    }
    // Else, send a message to requester.
    else partner.sendPacket(SystemMessageId.PARTY_MATCHING_REQUEST_NO_RESPONSE);

    // reset transaction timers
    player.setActiveRequester(null);
    partner.onTransactionResponse();
  }
Ejemplo n.º 2
0
  @Override
  public void useSkill(L2Character caster, L2Object[] targets) {
    try {
      for (L2Object target : targets) {
        if (target instanceof L2PcInstance) {
          L2PcInstance targetPlayer = (L2PcInstance) target;
          if (_faceId >= 0) targetPlayer.getAppearance().setFace(_faceId);
          if (_hairColorId >= 0) targetPlayer.getAppearance().setHairColor(_hairColorId);
          if (_hairStyleId >= 0) targetPlayer.getAppearance().setHairStyle(_hairStyleId);

          targetPlayer.broadcastUserInfo();
        }
      }
    } catch (Exception e) {
      _log.log(Level.SEVERE, "", e);
    }
  }
  @Override
  protected void runImpl() {
    final L2PcInstance _activeChar = getClient().getActiveChar();
    if (_activeChar == null) return;

    final PartyMatchRoom _room = PartyMatchRoomList.getInstance().getRoom(_roomid);
    if (_room == null) return;

    if ((_activeChar.isInParty() && _room.getOwner().isInParty())
        && (_activeChar.getParty().getPartyLeaderOID()
            == _room.getOwner().getParty().getPartyLeaderOID())) {
      // If user is in party with Room Owner is not removed from Room
    } else {
      _room.deleteMember(_activeChar);
      _activeChar.setPartyRoom(0);
      _activeChar.broadcastUserInfo();

      _activeChar.sendPacket(ExClosePartyRoom.STATIC_PACKET);
      _activeChar.sendPacket(SystemMessageId.PARTY_ROOM_EXITED);
    }
  }
Ejemplo n.º 4
0
  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;
  }
Ejemplo n.º 5
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()));
  }
Ejemplo n.º 6
0
  /**
   * This method is used to destroy a CW.<br>
   * It manages following states :
   *
   * <ul>
   *   <li><u>item on a online player</u> : drops the CW from inventory, and set back ancient
   *       pk/karma values.
   *   <li><u>item on a offline player</u> : make SQL operations in order to drop item from
   *       inventory.
   *   <li><u>item on ground</u> : destroys the item directly.
   * </ul>
   *
   * For all cases, a message is broadcasted, and the different states are reinitialized.
   */
  public void endOfLife() {
    if (_isActivated) {
      // Player is online ; unequip weapon && destroy it.
      if (_player != null && _player.isOnline()) {
        _log.info(_name + " being removed online.");

        _player.abortAttack();

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

        // Unequip && remove.
        _player.useEquippableItem(_item, true);
        _player.destroyItemByItemId("CW", _itemId, 1, _player, false);

        _player.broadcastUserInfo();

        _player.store();
      }
      // Player is offline ; make only SQL operations.
      else {
        _log.info(_name + " being removed offline.");

        try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
          // Delete the item
          PreparedStatement statement =
              con.prepareStatement("DELETE FROM items WHERE owner_id=? AND item_id=?");
          statement.setInt(1, _playerId);
          statement.setInt(2, _itemId);
          if (statement.executeUpdate() != 1)
            _log.warning("Error while deleting itemId " + _itemId + " from userId " + _playerId);

          statement.close();

          // Restore the karma and PK kills.
          statement =
              con.prepareStatement("UPDATE characters SET karma=?, pkkills=? WHERE obj_id=?");
          statement.setInt(1, _playerKarma);
          statement.setInt(2, _playerPkKills);
          statement.setInt(3, _playerId);
          if (statement.executeUpdate() != 1)
            _log.warning("Error while updating karma & pkkills for userId " + _playerId);

          statement.close();
        } catch (Exception e) {
          _log.log(Level.WARNING, "Could not delete : " + e.getMessage(), e);
        }
      }
    } else {
      // This CW is in the inventory of someone who has another cursed weapon equipped.
      if (_player != null && _player.getInventory().getItemByItemId(_itemId) != null) {
        _player.destroyItemByItemId("CW", _itemId, 1, _player, false);
        _log.info(_name + " item has been assimilated.");
      }
      // This CW is on the ground.
      else if (_item != null) {
        _item.decayMe();
        _log.info(_name + " item has been removed from world.");
      }
    }

    // Drop tasks.
    cancelDailyTimerTask();
    cancelOverallTimerTask();
    cancelDropTimerTask();

    // Delete infos from table, if any.
    removeFromDb();

    // Inform all ppl.
    Broadcast.toAllOnlinePlayers(
        SystemMessage.getSystemMessage(SystemMessageId.S1_HAS_DISAPPEARED).addItemName(_itemId));

    // Reset state.
    _player = null;
    _item = null;

    _isActivated = false;
    _isDropped = false;

    _nbKills = 0;
    _currentStage = 1;
    _numberBeforeNextStage = 0;

    _hungryTime = 0;
    _endTime = 0;

    _playerId = 0;
    _playerKarma = 0;
    _playerPkKills = 0;
  }