示例#1
0
文件: Spoil.java 项目: RostMyr/aCis
  @Override
  public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets) {
    if (!(activeChar instanceof L2PcInstance)) return;

    if (targets == null) return;

    for (L2Object tgt : targets) {
      if (!(tgt instanceof L2MonsterInstance)) continue;

      final L2MonsterInstance target = (L2MonsterInstance) tgt;
      if (target.isDead()) continue;

      if (target.getSpoilerId() != 0) {
        activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ALREADY_SPOILED));
        continue;
      }

      if (Formulas.calcMagicSuccess(activeChar, (L2Character) tgt, skill)) {
        target.setSpoilerId(activeChar.getObjectId());
        activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SPOIL_SUCCESS));
      } else
        activeChar.sendPacket(
            SystemMessage.getSystemMessage(SystemMessageId.S1_RESISTED_YOUR_S2)
                .addCharName(target)
                .addSkillName(skill.getId()));

      target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
    }
  }
示例#2
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);
  }
示例#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);
  }
示例#4
0
  @Override
  public boolean onActionTime() {
    if (_skill == null) return true;

    int mpConsume = _skill.getMpConsume();
    if (mpConsume > getEffector().getCurrentMp()) {
      getEffector()
          .sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SKILL_REMOVED_DUE_LACK_MP));
      return false;
    }
    getEffector().reduceCurrentMp(mpConsume);

    List<L2Character> targets = new ArrayList<>();
    for (L2Character cha :
        _actor
            .getKnownList()
            .getKnownTypeInRadius(L2Character.class, getSkill().getSkillRadius())) {
      if (_skill.isOffensive()
          && !L2Skill.checkForAreaOffensiveSkills(getEffector(), cha, _skill, _srcInArena))
        continue;

      // there doesn't seem to be a visible effect with MagicSkillLaunched packet...
      _actor.broadcastPacket(
          new MagicSkillUse(_actor, cha, _skill.getId(), _skill.getLevel(), 0, 0));
      targets.add(cha);
    }

    if (!targets.isEmpty())
      getEffector().callSkill(_skill, targets.toArray(new L2Character[targets.size()]));

    return true;
  }
示例#5
0
  @Override
  public final void reduceHp(
      double value, L2Character attacker, boolean awake, boolean isDOT, boolean isHpConsumption) {
    if (getActiveChar().isDead()) return;

    super.reduceHp(value, attacker, awake, isDOT, isHpConsumption);

    if (attacker != null) {
      if (!isDOT && getActiveChar().getOwner() != null) {
        SystemMessage sm =
            SystemMessage.getSystemMessage(SystemMessageId.PET_RECEIVED_S2_DAMAGE_BY_S1);
        sm.addCharName(attacker);
        sm.addNumber((int) value);
        getActiveChar().getOwner().sendPacket(sm);
      }
      getActiveChar().getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, attacker);
    }
  }
示例#6
0
  /**
   * This method displays EnchantSkillList to the player.
   *
   * @param player The player who requested the method.
   * @param npc The L2Npc linked to the request.
   * @param classId The classId asked. Used to sort available enchant skill list.
   */
  public static void showEnchantSkillList(L2PcInstance player, L2Npc npc, ClassId classId) {
    if (((L2NpcInstance) npc).getClassesToTeach() == null) {
      NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
      final String sb =
          StringUtil.concat(
              "<html><body>I cannot teach you. My class list is empty.<br>Your admin needs to add me teachTo informations.<br>NpcId:",
              String.valueOf(npc.getTemplate().getNpcId()),
              ", your classId:",
              String.valueOf(player.getClassId().getId()),
              "</body></html>");
      html.setHtml(sb);
      player.sendPacket(html);
      return;
    }

    if (!npc.getTemplate().canTeach(classId)) {
      NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
      html.setFile("data/html/trainer/" + npc.getTemplate().getNpcId() + "-noskills.htm");
      player.sendPacket(html);
      return;
    }

    if (player.getClassId().level() < 3) {
      NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
      html.setHtml("<html><body> You must have 3rd class change quest completed.</body></html>");
      player.sendPacket(html);
      return;
    }

    ExEnchantSkillList esl = new ExEnchantSkillList();
    boolean empty = true;

    List<L2EnchantSkillLearn> esll = SkillTreeTable.getInstance().getAvailableEnchantSkills(player);
    for (L2EnchantSkillLearn skill : esll) {
      L2Skill sk = SkillTable.getInstance().getInfo(skill.getId(), skill.getLevel());
      if (sk == null) continue;

      L2EnchantSkillData data =
          SkillTreeTable.getInstance().getEnchantSkillData(skill.getEnchant());
      if (data == null) continue;

      esl.addSkill(skill.getId(), skill.getLevel(), data.getCostSp(), data.getCostExp());
      empty = false;
    }

    if (empty) {
      player.sendPacket(SystemMessageId.THERE_IS_NO_SKILL_THAT_ENABLES_ENCHANT);

      if (player.getLevel() < 74)
        player.sendPacket(
            SystemMessage.getSystemMessage(SystemMessageId.DO_NOT_HAVE_FURTHER_SKILLS_TO_LEARN_S1)
                .addNumber(74));
      else player.sendPacket(SystemMessageId.NO_MORE_SKILLS_TO_LEARN);
    } else player.sendPacket(esl);

    player.sendPacket(ActionFailed.STATIC_PACKET);
  }
示例#7
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);
  }
示例#8
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();
  }
示例#9
0
  /**
   * This method displays SkillList to the player.
   *
   * @param player The player who requested the method.
   * @param npc The L2Npc linked to the request.
   * @param classId The classId asked. Used to sort available skill list.
   */
  public static void showSkillList(L2PcInstance player, L2Npc npc, ClassId classId) {
    if (((L2NpcInstance) npc).getClassesToTeach() == null) {
      NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
      final String sb =
          StringUtil.concat(
              "<html><body>I cannot teach you. My class list is empty.<br>Your admin needs to add me teachTo informations.<br>NpcId:",
              String.valueOf(npc.getTemplate().getNpcId()),
              ", your classId:",
              String.valueOf(player.getClassId().getId()),
              "</body></html>");
      html.setHtml(sb);
      player.sendPacket(html);
      return;
    }

    if (!npc.getTemplate().canTeach(classId)) {
      NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
      html.setFile("data/html/trainer/" + npc.getTemplate().getNpcId() + "-noskills.htm");
      player.sendPacket(html);
      return;
    }

    AcquireSkillList asl = new AcquireSkillList(AcquireSkillList.SkillType.Usual);
    boolean empty = true;

    for (L2SkillLearn sl : SkillTreeTable.getInstance().getAvailableSkills(player, classId)) {
      L2Skill sk = SkillTable.getInstance().getInfo(sl.getId(), sl.getLevel());
      if (sk == null) continue;

      asl.addSkill(sl.getId(), sl.getLevel(), sl.getLevel(), sl.getSpCost(), 0);
      empty = false;
    }

    if (empty) {
      int minlevel = SkillTreeTable.getInstance().getMinLevelForNewSkill(player, classId);

      if (minlevel > 0)
        player.sendPacket(
            SystemMessage.getSystemMessage(SystemMessageId.DO_NOT_HAVE_FURTHER_SKILLS_TO_LEARN_S1)
                .addNumber(minlevel));
      else player.sendPacket(SystemMessageId.NO_MORE_SKILLS_TO_LEARN);
    } else player.sendPacket(asl);

    player.sendPacket(ActionFailed.STATIC_PACKET);
  }
示例#10
0
  @Override
  protected void runImpl() {
    final L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null) return;

    // Noblesse can bestow a title to themselves
    if (activeChar.isNoble() && _target.matches(activeChar.getName())) {
      activeChar.setTitle(_title);
      activeChar.sendPacket(SystemMessageId.TITLE_CHANGED);
      activeChar.broadcastTitleInfo();
    } else {
      // Can the player change/give a title?
      if ((activeChar.getClanPrivileges() & L2Clan.CP_CL_GIVE_TITLE) != L2Clan.CP_CL_GIVE_TITLE) {
        activeChar.sendPacket(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT);
        return;
      }

      if (activeChar.getClan().getLevel() < 3) {
        activeChar.sendPacket(SystemMessageId.CLAN_LVL_3_NEEDED_TO_ENDOWE_TITLE);
        return;
      }

      final L2ClanMember member = activeChar.getClan().getClanMember(_target);
      if (member != null) {
        final L2PcInstance playerMember = member.getPlayerInstance();
        if (playerMember != null) {
          playerMember.setTitle(_title);

          playerMember.sendPacket(SystemMessageId.TITLE_CHANGED);
          if (activeChar != playerMember)
            activeChar.sendPacket(
                SystemMessage.getSystemMessage(SystemMessageId.CLAN_MEMBER_S1_TITLE_CHANGED_TO_S2)
                    .addPcName(playerMember)
                    .addString(_title));

          playerMember.broadcastTitleInfo();
        } else activeChar.sendPacket(SystemMessageId.TARGET_IS_NOT_FOUND_IN_THE_GAME);
      } else activeChar.sendPacket(SystemMessageId.TARGET_MUST_BE_IN_CLAN);
    }
  }
示例#11
0
    @Override
    public void run() {
      _hungryTime--;
      _timer++;

      if (_hungryTime <= 0) endOfLife();
      else if (_player != null && _player.isOnline() && _timer % 60 == 0) {
        SystemMessage 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);
      }
    }
示例#12
0
  @Override
  protected void runImpl() {
    if (_items == null) return;

    L2PcInstance player = getClient().getActiveChar();
    if (player == null) return;

    L2Object manager = player.getCurrentFolkNPC();
    if (!(manager instanceof L2ManorManagerInstance)) return;

    if (!player.isInsideRadius(manager, L2Npc.INTERACTION_DISTANCE, false, false)) return;

    int castleId = ((L2ManorManagerInstance) manager).getCastle().getCastleId();

    // Calculate summary values
    int slots = 0;
    int weight = 0;

    for (Crop i : _items) {
      if (!i.getCrop()) continue;

      Item template = ItemTable.getInstance().getTemplate(i.getReward());
      weight += i.getCount() * template.getWeight();

      if (!template.isStackable()) slots += i.getCount();
      else if (player.getInventory().getItemByItemId(i.getItemId()) == null) slots++;
    }

    if (!player.getInventory().validateWeight(weight)) {
      sendPacket(SystemMessage.getSystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
      return;
    }

    if (!player.getInventory().validateCapacity(slots)) {
      sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SLOTS_FULL));
      return;
    }

    // Proceed the purchase
    for (Crop i : _items) {
      if (i.getReward() == 0) continue;

      int fee = i.getFee(castleId); // fee for selling to other manors

      int rewardPrice = ItemTable.getInstance().getTemplate(i.getReward()).getReferencePrice();
      if (rewardPrice == 0) continue;

      int rewardItemCount = i.getPrice() / rewardPrice;
      if (rewardItemCount < 1) {
        player.sendPacket(
            SystemMessage.getSystemMessage(SystemMessageId.FAILED_IN_TRADING_S2_OF_CROP_S1)
                .addItemName(i.getItemId())
                .addItemNumber(i.getCount()));
        continue;
      }

      if (player.getAdena() < fee) {
        player.sendPacket(
            SystemMessage.getSystemMessage(SystemMessageId.FAILED_IN_TRADING_S2_OF_CROP_S1)
                .addItemName(i.getItemId())
                .addItemNumber(i.getCount()));
        player.sendPacket(SystemMessageId.YOU_NOT_ENOUGH_ADENA);
        continue;
      }

      // check if player have correct items count
      ItemInstance item = player.getInventory().getItemByObjectId(i.getObjectId());
      if (item == null || item.getCount() < i.getCount()) continue;

      // try modify castle crop
      if (!i.setCrop()) continue;

      if (fee > 0 && !player.reduceAdena("Manor", fee, manager, true)) continue;

      if (!player.destroyItem("Manor", i.getObjectId(), i.getCount(), manager, true)) continue;

      player.addItem("Manor", i.getReward(), rewardItemCount, manager, true);
    }
  }
示例#13
0
  @Override
  protected void runImpl() {
    if (_items == null || _items.isEmpty() || !Config.ALLOW_FREIGHT) return;

    final L2PcInstance player = getClient().getActiveChar();
    if (player == null) return;

    // player attempts to send freight to the different account
    if (!player.getAccountChars().containsKey(_objectID)) return;

    final PcFreight freight = player.getDepositedFreight(_objectID);
    player.setActiveWarehouse(freight);

    final ItemContainer warehouse = player.getActiveWarehouse();
    if (warehouse == null) return;

    final L2Npc manager = player.getCurrentFolkNPC();
    if ((manager == null
            || !player.isInsideRadius(manager, L2Npc.INTERACTION_DISTANCE, false, false))
        && !player.isGM()) return;

    if (warehouse instanceof PcFreight && !player.getAccessLevel().allowTransaction()) {
      player.sendMessage("Transactions are disabled for your Access Level.");
      return;
    }

    // Alt game - Karma punishment
    if (!Config.KARMA_PLAYER_CAN_USE_WH && player.getKarma() > 0) return;

    // Freight price from config or normal price per item slot (30)
    int fee = _items.size() * Config.ALT_GAME_FREIGHT_PRICE;
    int currentAdena = player.getAdena();
    int slots = 0;

    for (Item i : _items) {
      int objectId = i.id;
      int count = i.count;

      // Check validity of requested item
      ItemInstance item = player.checkItemManipulation(objectId, count);
      if (item == null) {
        _log.warning(
            "Error depositing a warehouse object for char "
                + player.getName()
                + " (validity check)");
        i.id = 0;
        i.count = 0;
        continue;
      }

      if (!item.isTradable() || item.isQuestItem()) return;

      // Calculate needed adena and slots
      if (item.getItemId() == 57) currentAdena -= count;

      if (!item.isStackable()) slots += count;
      else if (warehouse.getItemByItemId(item.getItemId()) == null) slots++;
    }

    // Item Max Limit Check
    if (!warehouse.validateCapacity(slots)) {
      sendPacket(
          SystemMessage.getSystemMessage(
              SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED));
      return;
    }

    // Check if enough adena and charge the fee
    if (currentAdena < fee
        || !player.reduceAdena("Warehouse", fee, player.getCurrentFolkNPC(), false)) {
      sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
      return;
    }

    // Proceed to the transfer
    InventoryUpdate playerIU = new InventoryUpdate();
    for (Item i : _items) {
      int objectId = i.id;
      int count = i.count;

      // check for an invalid item
      if (objectId == 0 && count == 0) continue;

      ItemInstance oldItem = player.getInventory().getItemByObjectId(objectId);
      if (oldItem == null) {
        _log.warning(
            "Error depositing a warehouse object for char "
                + player.getName()
                + " (olditem == null)");
        continue;
      }

      if (oldItem.isHeroItem()) continue;

      ItemInstance newItem =
          player
              .getInventory()
              .transferItem(
                  "Warehouse", objectId, count, warehouse, player, player.getCurrentFolkNPC());
      if (newItem == null) {
        _log.warning(
            "Error depositing a warehouse object for char "
                + player.getName()
                + " (newitem == null)");
        continue;
      }

      if (oldItem.getCount() > 0 && oldItem != newItem) playerIU.addModifiedItem(oldItem);
      else playerIU.addRemovedItem(oldItem);
    }

    // Send updated item list to the player
    player.sendPacket(playerIU);

    // Update current load status on player
    StatusUpdate su = new StatusUpdate(player);
    su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
    player.sendPacket(su);
  }
示例#14
0
  @Override
  public boolean useAdminCommand(String command, L2PcInstance activeChar) {
    StringTokenizer st = new StringTokenizer(command, " ");
    command = st.nextToken(); // Get actual command

    // Get castle
    Castle castle = null;
    ClanHall clanhall = null;

    if (command.startsWith("admin_clanhall"))
      clanhall = ClanHallManager.getInstance().getClanHallById(Integer.parseInt(st.nextToken()));
    else if (st.hasMoreTokens()) castle = CastleManager.getInstance().getCastle(st.nextToken());

    if (clanhall == null && (castle == null || castle.getCastleId() < 0)) {
      showCastleSelectPage(activeChar);
      return true;
    }

    L2Object target = activeChar.getTarget();
    L2PcInstance player = null;
    if (target instanceof L2PcInstance) player = (L2PcInstance) target;

    if (castle != null) {
      if (command.equalsIgnoreCase("admin_add_attacker")) {
        if (player == null) activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
        else castle.getSiege().registerAttacker(player);
      } else if (command.equalsIgnoreCase("admin_add_defender")) {
        if (player == null) activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
        else castle.getSiege().registerDefender(player);
      } else if (command.equalsIgnoreCase("admin_add_guard")) {
        try {
          int npcId = Integer.parseInt(st.nextToken());
          castle.getSiege().getSiegeGuardManager().addSiegeGuard(activeChar, npcId);
        } catch (Exception e) {
          activeChar.sendMessage("Usage: //add_guard npcId");
        }
      } else if (command.equalsIgnoreCase("admin_clear_siege_list")) {
        castle.getSiege().clearSiegeClan();
      } else if (command.equalsIgnoreCase("admin_endsiege")) {
        castle.getSiege().endSiege();
      } else if (command.equalsIgnoreCase("admin_list_siege_clans")) {
        castle.getSiege().listRegisterClan(activeChar);
        return true;
      } else if (command.equalsIgnoreCase("admin_move_defenders")) {
        activeChar.sendPacket(SystemMessage.sendString("Not implemented yet."));
      } else if (command.equalsIgnoreCase("admin_setcastle")) {
        if (player == null || player.getClan() == null)
          activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
        else if (player.getClan().hasCastle())
          activeChar.sendMessage(player.getName() + "'s clan already owns a castle.");
        else castle.setOwner(player.getClan());
      } else if (command.equalsIgnoreCase("admin_removecastle")) {
        L2Clan clan = ClanTable.getInstance().getClan(castle.getOwnerId());
        if (clan != null) castle.removeOwner(clan);
        else activeChar.sendMessage("Unable to remove castle for this clan.");
      } else if (command.equalsIgnoreCase("admin_spawn_doors")) {
        castle.spawnDoors(false);
      } else if (command.equalsIgnoreCase("admin_startsiege")) {
        castle.getSiege().startSiege();
      }
      showSiegePage(activeChar, castle.getName());
    } else if (clanhall != null) {
      if (command.equalsIgnoreCase("admin_clanhallset")) {
        if (player == null || player.getClan() == null)
          activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
        else if (!ClanHallManager.getInstance().isFree(clanhall.getId()))
          activeChar.sendMessage("This ClanHall isn't free!");
        else if (!player.getClan().hasHideout()) {
          ClanHallManager.getInstance().setOwner(clanhall.getId(), player.getClan());
          if (AuctionManager.getInstance().getAuction(clanhall.getId()) != null)
            AuctionManager.getInstance().getAuction(clanhall.getId()).deleteAuctionFromDB();
        } else activeChar.sendMessage("You have already a ClanHall!");
      } else if (command.equalsIgnoreCase("admin_clanhalldel")) {
        if (!ClanHallManager.getInstance().isFree(clanhall.getId())) {
          ClanHallManager.getInstance().setFree(clanhall.getId());
          AuctionManager.getInstance().initNPC(clanhall.getId());
        } else activeChar.sendMessage("This ClanHall is already Free!");
      } else if (command.equalsIgnoreCase("admin_clanhallopendoors")) {
        clanhall.openCloseDoors(true);
      } else if (command.equalsIgnoreCase("admin_clanhallclosedoors")) {
        clanhall.openCloseDoors(false);
      } else if (command.equalsIgnoreCase("admin_clanhallteleportself")) {
        L2ClanHallZone zone = clanhall.getZone();
        if (zone != null) activeChar.teleToLocation(zone.getSpawnLoc(), 0);
      }
      showClanHallPage(activeChar, clanhall);
    }
    return true;
  }
示例#15
0
  @Override
  protected void runImpl() {
    if (_items == null) return;

    final L2PcInstance player = getClient().getActiveChar();
    if (player == null) return;

    if (player.isProcessingTransaction()) {
      player.sendPacket(SystemMessageId.ALREADY_TRADING);
      return;
    }

    if (player.getActiveEnchantItem() != null) {
      player.setActiveEnchantItem(null);
      player.sendPacket(EnchantResult.CANCELLED);
      player.sendPacket(SystemMessageId.ENCHANT_SCROLL_CANCELLED);
    }

    final ItemContainer warehouse = player.getActiveWarehouse();
    if (warehouse == null) return;

    final boolean isPrivate = warehouse instanceof PcWarehouse;

    final L2Npc manager = player.getCurrentFolkNPC();
    if ((manager == null || !manager.isWarehouse() || !manager.canInteract(player))
        && !player.isGM()) return;

    if (!isPrivate && !player.getAccessLevel().allowTransaction()) {
      player.sendMessage("Transactions are disabled for your Access Level.");
      return;
    }

    // Alt game - Karma punishment
    if (!Config.KARMA_PLAYER_CAN_USE_WH && player.getKarma() > 0) return;

    // Freight price from config or normal price per item slot (30)
    final int fee = _items.length * 30;
    int currentAdena = player.getAdena();
    int slots = 0;

    for (WarehouseItem i : _items) {
      ItemInstance item = player.checkItemManipulation(i.getObjectId(), i.getCount());
      if (item == null) {
        _log.warning(
            "Error depositing a warehouse object for char "
                + player.getName()
                + " (validity check)");
        return;
      }

      // Calculate needed adena and slots
      if (item.getItemId() == ADENA_ID) currentAdena -= i.getCount();
      if (!item.isStackable()) slots += i.getCount();
      else if (warehouse.getItemByItemId(item.getItemId()) == null) slots++;
    }

    // Item Max Limit Check
    if (!warehouse.validateCapacity(slots)) {
      sendPacket(
          SystemMessage.getSystemMessage(
              SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED));
      return;
    }

    // Check if enough adena and charge the fee
    if (currentAdena < fee || !player.reduceAdena(warehouse.getName(), fee, manager, false)) {
      sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
      return;
    }

    // get current tradelist if any
    if (player.getActiveTradeList() != null) return;

    // Proceed to the transfer
    InventoryUpdate playerIU = new InventoryUpdate();
    for (WarehouseItem i : _items) {
      // Check validity of requested item
      ItemInstance oldItem = player.checkItemManipulation(i.getObjectId(), i.getCount());
      if (oldItem == null) {
        _log.warning(
            "Error depositing a warehouse object for char "
                + player.getName()
                + " (olditem == null)");
        return;
      }

      if (!oldItem.isDepositable(isPrivate) || !oldItem.isAvailable(player, true, isPrivate))
        continue;

      final ItemInstance newItem =
          player
              .getInventory()
              .transferItem(
                  warehouse.getName(), i.getObjectId(), i.getCount(), warehouse, player, manager);
      if (newItem == null) {
        _log.warning(
            "Error depositing a warehouse object for char "
                + player.getName()
                + " (newitem == null)");
        continue;
      }

      if (oldItem.getCount() > 0 && oldItem != newItem) playerIU.addModifiedItem(oldItem);
      else playerIU.addRemovedItem(oldItem);
    }

    // Send updated item list to the player
    player.sendPacket(playerIU);

    // Update current load status on player
    StatusUpdate su = new StatusUpdate(player);
    su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
    player.sendPacket(su);
  }
示例#16
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;
  }
示例#17
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()));
  }