Package com.l2jfrozen.gameserver.model

Examples of com.l2jfrozen.gameserver.model.L2TradeList


    {
      player.sendMessage("Invalid Target: Seller must be targetted");
      return;
    }

    L2TradeList list = null;

    if(merchant != null)
    {
      List<L2TradeList> lists = TradeController.getInstance().getBuyListByNpcId(merchant.getNpcId());

      if(!player.isGM())
      {
        if(lists == null)
        {
          Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id.", Config.DEFAULT_PUNISH);
          return;
        }
        for(L2TradeList tradeList : lists)
        {
          if(tradeList.getListId() == _listId)
          {
            list = tradeList;
          }
        }
      }
      else
      {
        list = TradeController.getInstance().getBuyList(_listId);
      }
    }
    else
    {
      list = TradeController.getInstance().getBuyList(_listId);
    }

    if(list == null)
    {
      Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id.", Config.DEFAULT_PUNISH);
      return;
    }

    _listId = list.getListId();

    if(_listId > 1000000) // lease
    {
      if(merchant != null && merchant.getTemplate().npcId != _listId - 1000000)
      {
        sendPacket(ActionFailed.STATIC_PACKET);
        return;
      }
    }

    if(_count < 1)
    {
      sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    double taxRate = 0;

    if(merchant != null && merchant.getIsInTown())
    {
      taxRate = merchant.getCastle().getTaxRate();
    }

    long subTotal = 0;
    int tax = 0;

    // Check for buylist validity and calculates summary values
    long slots = 0;
    long weight = 0;
    for(int i = 0; i < _count; i++)
    {
      int itemId = _items[i * 2 + 0];
      int count = _items[i * 2 + 1];
      int price = -1;

      if(!list.containsItemId(itemId))
      {
        Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id.", Config.DEFAULT_PUNISH);
        return;
      }

      L2Item template = ItemTable.getInstance().getTemplate(itemId);

      if(template == null)
      {
        continue;
      }

      // Check count
      if(count > Integer.MAX_VALUE || !template.isStackable() && count > 1)
      {
        //Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase invalid quantity of items at the same time.", Config.DEFAULT_PUNISH);
        SystemMessage sm = new SystemMessage(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED);
        sendPacket(sm);
        sm = null;
        return;
      }

      if(_listId < 1000000)
      {
        //list = TradeController.getInstance().getBuyList(_listId);
        price = list.getPriceForItemId(itemId);

        if(itemId >= 3960 && itemId <= 4026)
        {
          price *= Config.RATE_SIEGE_GUARDS_PRICE;
        }

      }
      /* TODO: Disabled until Leaseholders are rewritten ;-)
            }
            else
            {
              L2ItemInstance li = merchant.findLeaseItem(itemId, 0);
              if (li == null || li.getCount() < cnt)
              {
                cnt = li.getCount();
                if (cnt <= 0)
                {
                  items.remove(i);
                  continue;
                }
                items.get(i).setCount((int)cnt);
              }
              price = li.getPriceToSell(); // lease holder sells the item
              weight = li.getItem().getWeight();
            }

      */
      if(price < 0)
      {
        _log.warning("ERROR, no price found .. wrong buylist ??");
        sendPacket(ActionFailed.STATIC_PACKET);
        return;
      }

      if(price == 0 && !player.isGM() && Config.ONLY_GM_ITEMS_FREE)
      {
        player.sendMessage("Ohh Cheat dont work? You have a problem now!");
        Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried buy item for 0 adena.", Config.DEFAULT_PUNISH);
        return;
      }

      subTotal += (long) count * price; // Before tax
      tax = (int) (subTotal * taxRate);

      // Check subTotal + tax
      if(subTotal + tax > Integer.MAX_VALUE)
      {
        //Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase over " + Integer.MAX_VALUE + " adena worth of goods.", Config.DEFAULT_PUNISH);
        SystemMessage sm = new SystemMessage(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED);
        sendPacket(sm);
        sm = null;
        return;
      }

      weight += (long) count * template.getWeight();
      if(!template.isStackable())
      {
        slots += count;
      }
      else if(player.getInventory().getItemByItemId(itemId) == null)
      {
        slots++;
      }
    }

    if(weight > Integer.MAX_VALUE || weight < 0 || !player.getInventory().validateWeight((int) weight))
    {
      sendPacket(new SystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
      return;
    }

    if(slots > Integer.MAX_VALUE || slots < 0 || !player.getInventory().validateCapacity((int) slots))
    {
      sendPacket(new SystemMessage(SystemMessageId.SLOTS_FULL));
      return;
    }

    // Charge buyer and add tax to castle treasury if not owned by npc clan
    if(subTotal < 0 || !player.reduceAdena("Buy", (int) (subTotal + tax), player.getLastFolkNPC(), false))
    {
      sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
      return;
    }

    if(merchant != null && merchant.getIsInTown() && merchant.getCastle().getOwnerId() > 0)
    {
      merchant.getCastle().addToTreasury(tax);
    }

    // Proceed the purchase
    for(int i = 0; i < _count; i++)
    {
      int itemId = _items[i * 2 + 0];
      int count = _items[i * 2 + 1];

      if(count < 0)
      {
        count = 0;
      }

      if(!list.containsItemId(itemId))
      {
        Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id.", Config.DEFAULT_PUNISH);
        return;
      }

      if(list.countDecrease(itemId))
      {
        if(!list.decreaseCount(itemId, count)) {
          SystemMessage sm = new SystemMessage(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED);
          sendPacket(sm);
          sm = null;
          return;
        }
View Full Code Here


        e.printStackTrace();
     
      _log.warning("admin buylist failed:" + command);
    }

    L2TradeList list = TradeController.getInstance().getBuyList(val);

    if(list != null)
    {
      activeChar.sendPacket(new BuyList(list, activeChar.getAdena()));
View Full Code Here

    if(!player.isGM() && (target == null // No target (ie GM Shop)
        || !(target instanceof L2MerchantInstance || target instanceof L2MercManagerInstance) // Target not a merchant and not mercmanager
    || !player.isInsideRadius(target, L2NpcInstance.INTERACTION_DISTANCE, false, false)))
      return; // Distance is too far

    L2TradeList list = null;

    // Get the current merchant targeted by the player
    final L2MerchantInstance merchant = target != null && target instanceof L2MerchantInstance ? (L2MerchantInstance) target : null;
    if (merchant == null)
    {
      _log.warning("Null merchant!");
      return;
    }
   
    final List<L2TradeList> lists = TradeController.getInstance().getBuyListByNpcId(merchant.getNpcId());
    if(lists == null)
    {
      Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id.", Config.DEFAULT_PUNISH);
      return;
    }

    for(L2TradeList tradeList : lists)
    {
      if(tradeList.getListId() == _listId)
      {
        list = tradeList;
      }
    }

    if(list == null)
    {
      Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id.", Config.DEFAULT_PUNISH);
      return;
    }

    _listId = list.getListId();

    // Check if the quantity of Item to Wear
    if(_count < 1 || _listId >= 1000000)
    {
      sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    // Total Price of the Try On
    long totalPrice = 0;

    // Check for buylist validity and calculates summary values
    int slots = 0;
    int weight = 0;

    for(int i = 0; i < _count; i++)
    {
      int itemId = _items[i];

      if(!list.containsItemId(itemId))
      {
        Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id.", Config.DEFAULT_PUNISH);
        return;
      }

      L2Item template = ItemTable.getInstance().getTemplate(itemId);
      weight += template.getWeight();
      slots++;

      totalPrice += Config.WEAR_PRICE;
      if(totalPrice > Integer.MAX_VALUE)
      {
        Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase over " + Integer.MAX_VALUE + " adena worth of goods.", Config.DEFAULT_PUNISH);
        return;
      }
    }

    // Check the weight
    if(!player.getInventory().validateWeight(weight))
    {
      sendPacket(new SystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
      return;
    }

    // Check the inventory capacity
    if(!player.getInventory().validateCapacity(slots))
    {
      sendPacket(new SystemMessage(SystemMessageId.SLOTS_FULL));
      return;
    }

    // Charge buyer and add tax to castle treasury if not owned by npc clan because a Try On is not Free
    if(totalPrice < 0 || !player.reduceAdena("Wear", (int) totalPrice, player.getLastFolkNPC(), false))
    {
      sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
      return;
    }

    // Proceed the wear
    InventoryUpdate playerIU = new InventoryUpdate();
    for(int i = 0; i < _count; i++)
    {
      int itemId = _items[i];

      if(!list.containsItemId(itemId))
      {
        Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id.", Config.DEFAULT_PUNISH);
        return;
      }
View Full Code Here

  private void showBuyWindow(L2PcInstance player, String val)
  {
    double taxRate = 0;
    player.tempInvetoryDisable();

    L2TradeList list = TradeController.getInstance().getBuyList(Integer.parseInt(val));

    if(list != null)
    {
      list.getItems().get(0).setCount(1);
      BuyList bl = new BuyList(list, player.getAdena(), taxRate);
      player.sendPacket(bl);
    }
    else
    {
View Full Code Here

          {
            player.sendPacket(new SystemMessage(SystemMessageId.HERE_YOU_CAN_BUY_ONLY_SEEDS_OF_S1_MANOR));
          }
          else
          {
            L2TradeList tradeList = new L2TradeList(0);
            FastList<SeedProduction> seeds = getCastle().getSeedProduction(CastleManorManager.PERIOD_CURRENT);

            for(SeedProduction s : seeds)
            {
              L2ItemInstance item = ItemTable.getInstance().createDummyItem(s.getId());
              item.setPriceToSell(s.getPrice());
              item.setCount(s.getCanProduce());
              if(item.getCount() > 0 && item.getPriceToSell() > 0)
              {
                tradeList.addItem(item);
              }
            }

            BuyListSeed bl = new BuyListSeed(tradeList, castleId, player.getAdena());
            player.sendPacket(bl);
View Full Code Here

    if(Config.DEBUG)
    {
      _log.fine("Showing wearlist");
    }

    L2TradeList list = TradeController.getInstance().getBuyList(val);

    if(list != null)
    {
      WearList bl = new WearList(list, player.getAdena(), player.getExpertiseIndex());
      player.sendPacket(bl);
View Full Code Here

    if(Config.DEBUG)
    {
      _log.fine("Showing buylist");
    }

    L2TradeList list = TradeController.getInstance().getBuyList(val);

    if(list != null && list.getNpcId().equals(String.valueOf(getNpcId())))
    {
      BuyList bl = new BuyList(list, player.getAdena(), taxRate);
      player.sendPacket(bl);
      list = null;
      bl = null;
View Full Code Here

  private void editShopItem(L2PcInstance activeChar, String[] args)
  {
    int tradeListID = Integer.parseInt(args[1]);
    int itemID = Integer.parseInt(args[2]);

    L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
    L2Item item = ItemTable.getInstance().getTemplate(itemID);

    if(tradeList.getPriceForItemId(itemID) < 0)
      return;

    if(args.length > 3)
    {
      int price = Integer.parseInt(args[3]);
      int order = findOrderTradeList(itemID, tradeList.getPriceForItemId(itemID), tradeListID);

      tradeList.replaceItem(itemID, Integer.parseInt(args[3]));
      updateTradeList(itemID, price, tradeListID, order);

      activeChar.sendMessage("Updated price for " + item.getName() + " in Trade List " + tradeListID);
      showShopList(activeChar, tradeListID, 1);
      return;
    }

    NpcHtmlMessage adminReply = new NpcHtmlMessage(5);

    TextBuilder replyMSG = new TextBuilder();
    replyMSG.append("<html><title>Merchant Shop Item Edit</title>");
    replyMSG.append("<body>");
    replyMSG.append("<br>Edit an entry in merchantList.");
    replyMSG.append("<br>Editing Item: " + item.getName());
    replyMSG.append("<table>");
    replyMSG.append("<tr><td width=100>Property</td><td width=100>Edit Field</td><td width=100>Old Value</td></tr>");
    replyMSG.append("<tr><td><br></td><td></td></tr>");
    replyMSG.append("<tr><td>Price</td><td><edit var=\"price\" width=80></td><td>" + tradeList.getPriceForItemId(itemID) + "</td></tr>");
    replyMSG.append("</table>");
    replyMSG.append("<center><br><br><br>");
    replyMSG.append("<button value=\"Save\" action=\"bypass -h admin_editShopItem " + tradeListID + " " + itemID + " $price\"  width=100 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
    replyMSG.append("<br><button value=\"Back\" action=\"bypass -h admin_showShopList " + tradeListID + " 1\"  width=100 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
    replyMSG.append("</center>");
View Full Code Here

  private void delShopItem(L2PcInstance activeChar, String[] args)
  {
    int tradeListID = Integer.parseInt(args[1]);
    int itemID = Integer.parseInt(args[2]);

    L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);

    if(tradeList.getPriceForItemId(itemID) < 0)
      return;

    if(args.length > 3)
    {
      int order = findOrderTradeList(itemID, tradeList.getPriceForItemId(itemID), tradeListID);

      tradeList.removeItem(itemID);
      deleteTradeList(tradeListID, order);

      activeChar.sendMessage("Deleted " + ItemTable.getInstance().getTemplate(itemID).getName() + " from Trade List " + tradeListID);
      showShopList(activeChar, tradeListID, 1);
      return;
    }

    NpcHtmlMessage adminReply = new NpcHtmlMessage(5);

    TextBuilder replyMSG = new TextBuilder();
    replyMSG.append("<html><title>Merchant Shop Item Delete</title>");
    replyMSG.append("<body>");
    replyMSG.append("<br>Delete entry in merchantList.");
    replyMSG.append("<br>Item to Delete: " + ItemTable.getInstance().getTemplate(itemID).getName());
    replyMSG.append("<table>");
    replyMSG.append("<tr><td width=100>Property</td><td width=100>Value</td></tr>");
    replyMSG.append("<tr><td><br></td><td></td></tr>");
    replyMSG.append("<tr><td>Price</td><td>" + tradeList.getPriceForItemId(itemID) + "</td></tr>");
    replyMSG.append("</table>");
    replyMSG.append("<center><br><br><br>");
    replyMSG.append("<button value=\"Confirm\" action=\"bypass -h admin_delShopItem " + tradeListID + " " + itemID + " 1\"  width=100 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
    replyMSG.append("<br><button value=\"Back\" action=\"bypass -h admin_showShopList " + tradeListID + " 1\"  width=100 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
    replyMSG.append("</center>");
View Full Code Here

  private void addShopItem(L2PcInstance activeChar, String[] args)
  {
    int tradeListID = Integer.parseInt(args[1]);

    L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);

    if(tradeList == null)
    {
      activeChar.sendMessage("TradeList not found!");
      return;
    }

    if(args.length > 3)
    {
      int order = tradeList.getItems().size() + 1; // last item order + 1
      int itemID = Integer.parseInt(args[2]);
      int price = Integer.parseInt(args[3]);

      L2ItemInstance newItem = ItemTable.getInstance().createDummyItem(itemID);
      newItem.setPriceToSell(price);
      newItem.setCount(-1);
      tradeList.addItem(newItem);
      storeTradeList(itemID, price, tradeListID, order);

      activeChar.sendMessage("Added " + newItem.getItem().getName() + " to Trade List " + tradeList.getListId());
      showShopList(activeChar, tradeListID, 1);

      newItem = null;

      return;
View Full Code Here

TOP

Related Classes of com.l2jfrozen.gameserver.model.L2TradeList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.