예제 #1
0
  private static void giveReward(QuestState st, int item, int count) {
    final Item template = ItemTable.getInstance().getTemplate(item);

    if (template.isStackable()) st.giveItems(item, count);
    else {
      for (int i = 0; i < count; i++) st.giveItems(item, 1);
    }
  }
예제 #2
0
 public ConfirmDlg addItemName(Item item) {
   return addItemName(item.getItemId());
 }
예제 #3
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);
    }
  }