Package net.sf.l2j.gameserver.model

Examples of net.sf.l2j.gameserver.model.L2TradeList


    activeChar.sendPacket(adminReply);
  }

  private void showShopList(L2PcInstance activeChar, int tradeListID, int page)
  {
    L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
    if (page > tradeList.getItems().size() / PAGE_LIMIT + 1 || page < 1)
      return;

    NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
    TextBuilder html = itemListHtml(tradeList, page);
View Full Code Here


          ResultSet rset = statement.executeQuery();
          if (rset.next())
          {
            LimitedItem = false;
            dummyItemCount++;
            L2TradeList buy1 = new L2TradeList(rset1.getInt("shop_id"));
            int itemId = rset.getInt("item_id");
            int price = rset.getInt("price");
            int count = rset.getInt("count");
            int currentCount = rset.getInt("currentCount");
            int time = rset.getInt("time");
            L2ItemInstance item = ItemTable.getInstance().createDummyItem(itemId);
            if (item == null)
            {
              rset.close();
              statement.close();
              continue;
            }
            if(count > -1){
              item.setCountDecrease(true);
              LimitedItem = true;
            }
            item.setPriceToSell(price);
            item.setTime(time);
            item.setInitCount(count);
            if(currentCount>-1)
              item.setCount(currentCount);
            else
              item.setCount(count);
            buy1.addItem(item);
            buy1.setNpcId(rset1.getString("npc_id"));
            try
            {
              while (rset.next())
              {
                dummyItemCount++;
                itemId = rset.getInt("item_id");
                price = rset.getInt("price");
                count = rset.getInt("count");
                time = rset.getInt("time");
                currentCount = rset.getInt("currentCount");
                L2ItemInstance item2 = ItemTable.getInstance().createDummyItem(itemId);
                if (item2 == null) continue;
                if(count > -1){
                  item2.setCountDecrease(true);
                  LimitedItem = true;
                }
                item2.setPriceToSell(price);
                item2.setTime(time);
                item2.setInitCount(count);
                if(currentCount>-1)
                  item2.setCount(currentCount);
                else
                  item2.setCount(count);
                buy1.addItem(item2);
              }
            } catch (Exception e)
            {
              _log.warning("TradeController: Problem with buylist " + buy1.getListId() + " item " + itemId);
            }
            if(LimitedItem)
              _listsTaskItem.put(new Integer(buy1.getListId()), buy1);
            else
              _lists.put(new Integer(buy1.getListId()), buy1);
            _nextListId = Math.max(_nextListId, buy1.getListId() + 1);
          }

          rset.close();
          statement.close();
        }
View Full Code Here

  {
    int itemCreated = 0;
    StringTokenizer st = new StringTokenizer(line, ";");

    int listId = Integer.parseInt(st.nextToken());
    L2TradeList buy1 = new L2TradeList(listId);
    while (st.hasMoreTokens())
    {
      int itemId = Integer.parseInt(st.nextToken());
      int price = Integer.parseInt(st.nextToken());
      L2ItemInstance item = ItemTable.getInstance().createDummyItem(itemId);
      item.setPriceToSell(price);
      buy1.addItem(item);
      itemCreated++;
    }

    _lists.put(new Integer(buy1.getListId()), buy1);
    return itemCreated;
  }
View Full Code Here

        {
          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(new ActionFailed());
        return;
      }
    }
        if(_count < 1)
    {
            sendPacket(new ActionFailed());
        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;
            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(new ActionFailed());
                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);
            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);
                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))
        list.decreaseCount(itemId,count);
      // Add item to Inventory and adjust update packet
      player.getInventory().addItem("Buy", itemId, count, player, merchant);
/* TODO: Disabled until Leaseholders are rewritten ;-)
      // Update Leaseholder list
      if (_listId >= 1000000)
View Full Code Here

    catch (Exception e)
    {
      _log.warning("admin buylist failed:"+command);
    }

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

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

        player.tempInvetoryDisable();

        if (Config.DEBUG)
          _log.fine("Showing buylist :"+player.getName()+" List ID :"+val);

        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);
        }
        else
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)   // Distance is too far
              )) return;

        L2TradeList list = null;

        // Get the current merchant targeted by the player
    L2MerchantInstance merchant = (target != null && target instanceof L2MerchantInstance) ? (L2MerchantInstance)target : null;

    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(new ActionFailed());
            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

TOP

Related Classes of net.sf.l2j.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.