@Override
  public void onBypassFeedback(Player player, String command) {
    if (!canBypassCheck(player, this)) return;

    if (command.startsWith("tryenter")) {
      if (NaiaLock.isEntranceActive()) {
        // instance
        if (!player.isInParty()) {
          player.sendPacket(SystemMsg.YOU_ARE_NOT_CURRENTLY_IN_A_PARTY_SO_YOU_CANNOT_ENTER);
          return;
        }
        if (!player.getParty().isLeader(player)) {
          player.sendPacket(SystemMsg.ONLY_A_PARTY_LEADER_CAN_MAKE_THE_REQUEST_TO_ENTER);
          return;
        }
        for (Player member : player.getParty().getPartyMembers()) {
          if (member.getLevel() < 80) {
            player.sendPacket(
                new SystemMessage(
                        SystemMessage.C1S_LEVEL_REQUIREMENT_IS_NOT_SUFFICIENT_AND_CANNOT_BE_ENTERED)
                    .addName(member));
            return;
          }
          if (!member.isInRange(this, 500)) {
            player.sendPacket(
                new SystemMessage(
                        SystemMessage
                            .C1_IS_IN_A_LOCATION_WHICH_CANNOT_BE_ENTERED_THEREFORE_IT_CANNOT_BE_PROCESSED)
                    .addName(member));
            return;
          }
        }
        NaiaTowerManager.startNaiaTower(player);

        broadcastPacket(new MagicSkillUse(this, this, 5527, 1, 0, 0));
        doDie(null);
      } else {
        broadcastPacket(new MagicSkillUse(this, this, 5527, 1, 0, 0));
        doDie(null);
      }
    } else super.onBypassFeedback(player, command);
  }
Beispiel #2
0
  @Override
  protected void runImpl() {
    Player activeChar = getClient().getActiveChar();
    if (activeChar == null || _count == 0) return;

    // Проверяем, не подменили ли id
    if (activeChar.getBuyListId() != _listId)
      // TODO audit
      return;

    if (activeChar.isActionsDisabled()) {
      activeChar.sendActionFailed();
      return;
    }

    if (activeChar.isInStoreMode()) {
      activeChar.sendPacket(
          SystemMsg
              .WHILE_OPERATING_A_PRIVATE_STORE_OR_WORKSHOP_YOU_CANNOT_DISCARD_DESTROY_OR_TRADE_AN_ITEM);
      return;
    }

    if (activeChar.isInTrade()) {
      activeChar.sendActionFailed();
      return;
    }

    if (activeChar.isFishing()) {
      activeChar.sendPacket(SystemMsg.YOU_CANNOT_DO_THAT_WHILE_FISHING);
      return;
    }

    if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && activeChar.isPK() && !activeChar.isGM()) {
      activeChar.sendActionFailed();
      return;
    }

    NpcInstance merchant = activeChar.getLastNpc();
    boolean isValidMerchant = merchant != null && merchant.isMerchantNpc();
    if (!activeChar.isGM()
        && (merchant == null
            || !isValidMerchant
            || !activeChar.isInRange(merchant, Creature.INTERACTION_DISTANCE))) {
      activeChar.sendActionFailed();
      return;
    }

    NpcTradeList list = BuyListHolder.getInstance().getBuyList(_listId);
    if (list == null) {
      // TODO audit
      activeChar.sendActionFailed();
      return;
    }

    int slots = 0;
    long weight = 0;
    long totalPrice = 0;
    long tax = 0;
    double taxRate = 0;

    Castle castle = null;
    if (merchant != null) {
      castle = merchant.getCastle(activeChar);
      if (castle != null) taxRate = castle.getTaxRate();
    }

    List<TradeItem> buyList = new ArrayList<TradeItem>(_count);
    List<TradeItem> tradeList = list.getItems();
    try {
      loop:
      for (int i = 0; i < _count; i++) {
        int itemId = _items[i];
        long count = _itemQ[i];
        long price = 0;

        for (TradeItem ti : tradeList)
          if (ti.getItemId() == itemId) {
            if (ti.isCountLimited() && ti.getCurrentValue() < count) continue loop;
            price = ti.getOwnersPrice();
          }

        if (price == 0 && (!activeChar.isGM() || !activeChar.getPlayerAccess().UseGMShop)) {
          // TODO audit
          activeChar.sendActionFailed();
          return;
        }

        totalPrice = SafeMath.addAndCheck(totalPrice, SafeMath.mulAndCheck(count, price));

        TradeItem ti = new TradeItem();
        ti.setItemId(itemId);
        ti.setCount(count);
        ti.setOwnersPrice(price);

        weight =
            SafeMath.addAndCheck(weight, SafeMath.mulAndCheck(count, ti.getItem().getWeight()));
        if (!ti.getItem().isStackable()
            || activeChar.getInventory().getItemByItemId(itemId) == null) slots++;

        buyList.add(ti);
      }

      tax = (long) (totalPrice * taxRate);

      totalPrice = SafeMath.addAndCheck(totalPrice, tax);

      if (!activeChar.getInventory().validateWeight(weight)) {
        activeChar.sendPacket(SystemMsg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT);
        return;
      }

      if (!activeChar.getInventory().validateCapacity(slots)) {
        activeChar.sendPacket(SystemMsg.YOUR_INVENTORY_IS_FULL);
        return;
      }

      if (!activeChar.reduceAdena(totalPrice)) {
        activeChar.sendPacket(SystemMsg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
        return;
      }

      for (TradeItem ti : buyList) activeChar.getInventory().addItem(ti.getItemId(), ti.getCount());

      // Для магазинов с ограниченным количеством товара число продаваемых предметов уменьшаем после
      // всех проверок
      list.updateItems(buyList);

      // Add tax to castle treasury if not owned by npc clan
      if (castle != null)
        if (tax > 0
            && castle.getOwnerId() > 0
            && activeChar.getReflection() == ReflectionManager.DEFAULT)
          castle.addToTreasury(tax, true, false);
    } catch (ArithmeticException ae) {
      // TODO audit
      activeChar.sendPacket(SystemMsg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED);
      return;
    }

    sendPacket(new ExBuySellListPacket.SellRefundList(activeChar, true));
    activeChar.sendChanges();
  }