@Override
  public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
    String htmltext = getNoQuestMsg();
    QuestState st = player.getQuestState(getName());
    if (st == null) return htmltext;

    if (Util.isDigit(event)) {
      final int eventId = Integer.parseInt(event);
      if (eventId >= 0 && eventId <= 7) {
        if (st.getQuestItemsCount(HORN) >= BUFF[eventId - 1][2]) {
          st.takeItems(HORN, BUFF[eventId - 1][2]);
          npc.setTarget(player);
          npc.doCast(SkillTable.getInstance().getInfo(BUFF[eventId - 1][0], BUFF[eventId - 1][1]));
          npc.setCurrentHpMp(npc.getMaxHp(), npc.getMaxMp());
          htmltext = "31372-4.htm";
        }
      }
    } else if (event.equals("Withdraw")) {
      if (player.getWarehouse().getSize() == 0) htmltext = "31374-0.htm";
      else {
        player.sendPacket(ActionFailed.STATIC_PACKET);
        player.setActiveWarehouse(player.getWarehouse());
        player.sendPacket(new WareHouseWithdrawalList(player, 1));
      }
    } else if (event.equals("Teleport")) {
      switch (player.getAllianceWithVarkaKetra()) {
        case 4:
          htmltext = "31376-4.htm";
          break;
        case 5:
          htmltext = "31376-5.htm";
          break;
      }
    }

    return htmltext;
  }
Exemple #2
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);
  }