Package l2p.gameserver.model

Examples of l2p.gameserver.model.TradeItem


          {
            NpcTradeList tradeList = new NpcTradeList(0);
            GArray<SeedProduction> seeds = castle.getSeedProduction(CastleManorManager.PERIOD_CURRENT);
            for(SeedProduction s : seeds)
            {
              TradeItem item = new TradeItem();
              item.setItemId(s.getId());
              item.setOwnersPrice(s.getPrice());
              item.setCount(s.getCanProduce());
              if(item.getCount() > 0 && item.getOwnersPrice() > 0)
              {
                tradeList.addItem(item);
              }
            }
            BuyListSeed bl = new BuyListSeed(tradeList, castleId, player.getAdena());
View Full Code Here


                          {
                            continue;
                          }
                          counterItems++;
                          final int price = i.getAttributes().getNamedItem("price") != null ? Integer.parseInt(i.getAttributes().getNamedItem("price").getNodeValue()) : Math.round(template.getReferencePrice() * markup);
                          TradeItem item = new TradeItem();
                          item.setItemId(itemId);
                          final int itemCount = i.getAttributes().getNamedItem("count") != null ? Integer.parseInt(i.getAttributes().getNamedItem("count").getNodeValue()) : 0;
                          // Время респауна задается минутах
                          final int itemRechargeTime = i.getAttributes().getNamedItem("time") != null ? Integer.parseInt(i.getAttributes().getNamedItem("time").getNodeValue()) : 0;
                          item.setOwnersPrice(price);
                          item.setCount(itemCount);
                          item.setCurrentValue(itemCount);
                          item.setLastRechargeTime((int) (System.currentTimeMillis() / 60000));
                          item.setRechargeTime(itemRechargeTime);
                          tl.addItem(item);
                        }
                      }
                      _lists.put(shop_id, tl);
                    }
View Full Code Here

        {
          L2ItemInstance item = items[i];
          item.setOwnerId(letter.senderId);
          item.setLocation(ItemLocation.LEASE);
          item.updateDatabase(true, false);
          letter.attached.add(new TradeItem(item));
          stmnt.setInt(1, letter.id);
          stmnt.setInt(2, item.getObjectId());
          stmnt.executeUpdate();
        }
        letter.attachments = letter.attached.size();
View Full Code Here

          stmt2 = con.createStatement();
          rs2 = stmt2.executeQuery("SELECT itemId FROM mail_attachments WHERE messageId=" + ret.id);
          GArray<TradeItem> items = new GArray<TradeItem>(ret.attachments);
          while(rs2.next())
          {
            TradeItem ti = TradeItem.restoreFromDb(rs2.getInt("itemId"), ItemLocation.LEASE);
            if(ti != null)
            {
              items.add(ti);
            }
          }
View Full Code Here

    if(_items == null || _count <= 0 || !activeChar.checksForShop(false))
    {
      L2TradeList.cancelStore(activeChar);
      return;
    }
    TradeItem temp;
    ConcurrentLinkedQueue<TradeItem> listsell = new ConcurrentLinkedQueue<TradeItem>();
    int maxSlots = activeChar.getTradeLimit();
    if(_count > maxSlots)
    {
      activeChar.sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED);
      L2TradeList.cancelStore(activeChar);
      activeChar.sendPacket(new PrivateStoreManageList(activeChar, _package));
      return;
    }
    int count = _count;
    for(int x = 0; x < _count; x++)
    {
      int objectId = (int) _items[x * 3 + 0];
      long cnt = _items[x * 3 + 1];
      long price = _items[x * 3 + 2];
      L2ItemInstance itemToSell = activeChar.getInventory().getItemByObjectId(objectId);
      if(cnt < 1 || itemToSell == null || !itemToSell.canBeTraded(activeChar) || itemToSell.getItemId() == L2Item.ITEM_ID_ADENA)
      {
        count--;
        continue;
      }
      // If player sells the enchant scroll he is using, deactivate it
      if(activeChar.getEnchantScroll() != null && itemToSell.getObjectId() == activeChar.getEnchantScroll().getObjectId())
      {
        activeChar.setEnchantScroll(null);
      }
      if(cnt > itemToSell.getCount())
      {
        cnt = itemToSell.getCount();
      }
      temp = new TradeItem();
      temp.setObjectId(objectId);
      temp.setCount(cnt);
      temp.setOwnersPrice(price);
      temp.setItemId(itemToSell.getItemId());
      temp.setEnchantLevel(itemToSell.getEnchantLevel());
      temp.setAttackElement(itemToSell.getAttackElement());
      temp.setDefenceFire(itemToSell.getDefenceFire());
      temp.setDefenceWater(itemToSell.getDefenceWater());
      temp.setDefenceWind(itemToSell.getDefenceWind());
      temp.setDefenceEarth(itemToSell.getDefenceEarth());
      temp.setDefenceHoly(itemToSell.getDefenceHoly());
      temp.setDefenceUnholy(itemToSell.getDefenceUnholy());
      listsell.add(temp);
    }
    if(count != 0)
    {
      activeChar.setSellList(listsell);
View Full Code Here

    {
      activeChar.sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED);
      L2TradeList.cancelStore(activeChar);
      return;
    }
    TradeItem temp;
    ConcurrentLinkedQueue<TradeItem> listbuy = new ConcurrentLinkedQueue<TradeItem>();
    long totalCost = 0;
    int count = 0;
    outer: for (int x = 0; x < _count; x++)
    {
      int itemId = (int) _items[x * 3 + 0];
      long itemCount = _items[x * 3 + 1];
      long itemPrice = _items[x * 3 + 2];
      if (!ItemTable.getInstance().isExists(itemId) || itemCount < 1 || itemPrice < 0 || itemId == L2Item.ITEM_ID_ADENA)
      {
        continue;
      }
      L2Item item = ItemTable.getInstance().getTemplate(itemId);
      if (item.getReferencePrice() / 2 > itemPrice)
      {
        activeChar.sendMessage(new CustomMessage("l2p.gameserver.clientpackets.SetPrivateStoreBuyList.TooLowPrice", activeChar).addItemName(item).addNumber(item.getReferencePrice() / 2));
        continue;
      }
     
      // char wants to buy item that he doesn't have
      if (activeChar.getInventory().getItemByItemId(itemId) == null)
        continue;
     
      if (item.isStackable())
      {
        for (TradeItem ti : listbuy)
        {
          if (ti.getItemId() == itemId)
          {
            if (ti.getOwnersPrice() == itemPrice)
            {
              ti.setCount(ti.getCount() + itemCount);
            }
            continue outer;
          }
        }
      }
      temp = new TradeItem();
      temp.setItemId(itemId);
      temp.setCount(itemCount);
      temp.setOwnersPrice(itemPrice);
      totalCost += temp.getOwnersPrice() * temp.getCount();
      listbuy.add(temp);
      count++;
    }
    if (totalCost > activeChar.getAdena())
    {
View Full Code Here

    }
    _haveList = new ConcurrentLinkedQueue<TradeItem>();
    // Делаем список для собственно передачи с учетом количества
    for(L2ItemInstance item : _list.getItems())
    {
      TradeItem ti = new TradeItem();
      ti.setObjectId(item.getObjectId());
      ti.setItemId(item.getItemId());
      ti.setCount(item.getCount());
      ti.setEnchantLevel(item.getEnchantLevel());
      ti.setAttackElement(item.getAttackElement());
      ti.setDefenceFire(item.getDefenceFire());
      ti.setDefenceWater(item.getDefenceWater());
      ti.setDefenceWind(item.getDefenceWind());
      ti.setDefenceEarth(item.getDefenceEarth());
      ti.setDefenceHoly(item.getDefenceHoly());
      ti.setDefenceUnholy(item.getDefenceUnholy());
      _haveList.add(ti);
    }
    //Убираем совпадения между списками, в сумме оба списка должны совпадать с содержимым инвентаря
    if(_sellList.size() > 0)
    {
View Full Code Here

                                                if(sellerItem == null || sellerItem.getCount() < count)
                                                {
                                                        buyer.sendActionFailed();
                                                        return;
                                                }
                                                TradeItem temp = new TradeItem();
                                                temp.setObjectId(si.getObjectId());
                                                temp.setItemId(sellerItem.getItemId());
                                                temp.setCount(count);
                                                temp.setOwnersPrice(si.getOwnersPrice());
                                                temp.setAttackElement(sellerItem.getAttackElement());
                                                temp.setDefenceFire(sellerItem.getDefenceFire());
                                                temp.setDefenceWater(sellerItem.getDefenceWater());
                                                temp.setDefenceWind(sellerItem.getDefenceWind());
                                                temp.setDefenceEarth(sellerItem.getDefenceEarth());
                                                temp.setDefenceHoly(sellerItem.getDefenceHoly());
                                                temp.setDefenceUnholy(sellerItem.getDefenceUnholy());
                                                cost += 1d * temp.getOwnersPrice() * temp.getCount();
                                                buyerlist.add(temp);
                                        }
                                }
                        }
                }
View Full Code Here

      {
        Log.add("tried to buy from non-exist list " + _listId, "errors", activeChar);
        activeChar.sendActionFailed();
        return;
      }
      TradeItem ti = getItemByItemId(itemId, list);
      price = ti == null ? 0 : ti.getOwnersPrice();
      if(itemId >= 3960 && itemId <= 4921)
      {
        price *= Config.RATE_SIEGE_GUARDS_PRICE;
      }
      if(price == 0 && !activeChar.getPlayerAccess().UseGMShop)
      {
        Util.handleIllegalPlayerAction(activeChar, "RequestBuyItem[191]", "Tried to buy zero price item, list " + _listId + " item " + itemId, 0);
        for(L2ItemInstance item : items)
        {
          item.deleteMe();
        }
        activeChar.sendMessage("Error: zero-price item! Please notify GM.");
        activeChar.sendActionFailed();
        return;
      }
      weight = items.get(i).getItem().getWeight();
      if(price < 0)
      {
        _log.warning("ERROR, no price found. Wrong buylist?");
        for(L2ItemInstance item : items)
        {
          item.deleteMe();
        }
        activeChar.sendActionFailed();
        return;
      }
      try
      {
        if(cnt < 0)
        {
          throw new ArithmeticException("cnt < 0");
        }
        subTotal = SafeMath.safeAddLong(subTotal, SafeMath.safeMulLong(cnt, price)); // Before tax
        tax = SafeMath.safeMulLong(subTotal, taxRate);
        totalCost = SafeMath.safeAddLong(subTotal, tax);
        if(totalCost < 0)
        {
          throw new ArithmeticException("213: Tried to purchase negative " + totalCost + " adena worth of goods.");
        }
        finalLoad = SafeMath.safeAddLong(finalLoad, SafeMath.safeMulLong(cnt, weight));
        if(finalLoad < 0)
        {
          throw new ArithmeticException("254: Tried to purchase negative " + finalLoad + " adena worth of goods.");
        }
      }
      catch(ArithmeticException e)
      {
        Util.handleIllegalPlayerAction(activeChar, "RequestBuyItem[157]", "merchant: " + merchant + ": " + e.getMessage(), 1);
        for(L2ItemInstance item : items)
        {
          item.deleteMe();
        }
        sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED, Msg.ActionFail);
        return;
      }
      if(needsSpace == 2)
      {
        finalCount += cnt;
      }
      else if(needsSpace == 1)
      {
        finalCount += 1;
      }
    }
    if(totalCost > currentMoney || subTotal < 0 || currentMoney <= 0)
    {
      for(L2ItemInstance item : items)
      {
        item.deleteMe();
      }
      sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA, Msg.ActionFail);
      return;
    }
    if(!activeChar.getInventory().validateWeight(finalLoad))
    {
      for(L2ItemInstance item : items)
      {
        item.deleteMe();
      }
      sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT, Msg.ActionFail);
      return;
    }
    if(!activeChar.getInventory().validateCapacity(finalCount))
    {
      for(L2ItemInstance item : items)
      {
        item.deleteMe();
      }
      sendPacket(Msg.YOUR_INVENTORY_IS_FULL, Msg.ActionFail);
      return;
    }
    // Для магазинов с ограниченным количеством товара число продаваемых предметов уменьшаем после всех проверок
    NpcTradeList list = TradeController.getInstance().getBuyList(_listId);
    for(int i = 0; i < items.size(); i++)
    {
      itemId = items.get(i).getItemId();
      cnt = items.get(i).getCount();
      TradeItem ic = getItemByItemId(itemId, list);
      if(ic != null && ic.isCountLimited())
      {
        if(cnt > ic.getCurrentValue())
        {
          int t = (int) (System.currentTimeMillis() / 60000);
          if(ic.getLastRechargeTime() + ic.getRechargeTime() <= t)
          {
            ic.setLastRechargeTime(t);
            ic.setCurrentValue(ic.getCount());
          }
          else
          {
            continue;
          }
        }
        else
        {
          ic.setCurrentValue(ic.getCurrentValue() - cnt);
        }
      }
    }
    activeChar.reduceAdena(totalCost, true);
    for(L2ItemInstance item : items)
View Full Code Here

      _seller.sendPacket(Msg.THIS_ACCOUNT_CANOT_USE_PRIVATE_STORES);
      _fail = 1;
      return;
    }
    _buyerlist = _buyer.getBuyList();
    TradeItem temp;
    long sum = 0;
    for(int i = 0; i < _count; i++)
    {
      temp = new TradeItem();
      readD(); // ObjectId, не работает, поскольку используется id вещи-образца скупщика
      temp.setItemId(readD());
      readH();
      readH();
      temp.setCount(readQ());
      temp.setOwnersPrice(readQ());
      if(temp.getItemId() < 1 || temp.getCount() < 1 || temp.getOwnersPrice() < 1)
      {
        _seller.sendPacket(Msg.ActionFail, Msg.THE_ATTEMPT_TO_SELL_HAS_FAILED);
        _fail = 1;
        return;
      }
      sum += temp.getCount() * temp.getOwnersPrice();
      L2ItemInstance SIItem = _seller.getInventory().getItemByItemId(temp.getItemId());
      if(SIItem == null)
      {
        _seller.sendActionFailed();
        _log.warning("Player " + _seller.getName() + " tries to sell to PSB:" + _buyer.getName() + " item not in inventory");
        return;
      }
      if(SIItem.isEquipped())
      {
        _seller.sendPacket(Msg.ActionFail, Msg.THE_ATTEMPT_TO_SELL_HAS_FAILED);
        _fail = 1;
        return;
      }
      temp.setObjectId(SIItem.getObjectId());
      if(temp.getCount() > SIItem.getCount())
      {
        temp.setCount(SIItem.getCount());
      }
      temp.setEnchantLevel(SIItem.getEnchantLevel());
      temp.setAttackElement(SIItem.getAttackElement());
      temp.setDefenceFire(SIItem.getDefenceFire());
      temp.setDefenceWater(SIItem.getDefenceWater());
      temp.setDefenceWind(SIItem.getDefenceWind());
      temp.setDefenceEarth(SIItem.getDefenceEarth());
      temp.setDefenceHoly(SIItem.getDefenceHoly());
      temp.setDefenceUnholy(SIItem.getDefenceUnholy());
      _sellerlist.add(temp);
    }
    if(sum > _buyer.getAdena()) // если у продавца не хватает денег - снимать с трейда, ибо нефиг
    {
      _seller.sendPacket(Msg.ActionFail, Msg.THE_ATTEMPT_TO_SELL_HAS_FAILED);
View Full Code Here

TOP

Related Classes of l2p.gameserver.model.TradeItem

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.