Package l2p.gameserver.model.items

Examples of l2p.gameserver.model.items.Inventory$ItemOrderComparator


      }
      if(first && _itemConsume[0] > 0)
      {
        for(int i = 0; i < _itemConsume.length; i++)
        {
          Inventory inv = ((L2Playable) activeChar).getInventory();
          if(inv == null)
          {
            inv = player.getInventory();
          }
          L2ItemInstance requiredItems = inv.getItemByItemId(_itemConsumeId[i]);
          if(requiredItems == null || requiredItems.getCount() < _itemConsume[i])
          {
            if(activeChar == player)
            {
              player.sendPacket(Msg.INCORRECT_ITEM_COUNT);
View Full Code Here


  /**
   * Проверяет, есть ли у игрока player в наличии необходимое количество вещей
   */
  public static boolean validateTrade(L2Player player, Collection<TradeItem> items)
  {
    Inventory playersInv = player.getInventory();
    L2ItemInstance playerItem;
    synchronized(items)
    {
      for(TradeItem item : items)
      {
        playerItem = playersInv.getItemByObjectId(item.getObjectId());
        if(playerItem == null || playerItem.getCount() < item.getCount() || playerItem.getEnchantLevel() < item.getEnchantLevel() || !playerItem.canBeTraded(player))
        {
          return false;
        }
      }
View Full Code Here

    return true;
  }

  public void updateSellList(L2Player player, ConcurrentLinkedQueue<TradeItem> list)
  {
    Inventory playersInv = player.getInventory();
    L2ItemInstance item;
    for(L2ItemInstance temp : _items)
    {
      item = playersInv.getItemByObjectId(temp.getObjectId());
      if(item == null || item.getCount() <= 0)
      {
        for(TradeItem i : list)
        {
          if(i.getObjectId() == temp.getItemId())
View Full Code Here

    }
  }

  public synchronized boolean buySellItems(L2Player buyer, ConcurrentLinkedQueue<TradeItem> listToBuy, L2Player seller, ConcurrentLinkedQueue<TradeItem> listToSell)
  {
    Inventory sellerInv = seller.getInventory();
    Inventory buyerInv = buyer.getInventory();
    TradeItem sellerTradeItem = null;
    L2ItemInstance sellerInventoryItem = null;
    L2ItemInstance TransferItem = null;
    L2ItemInstance temp;
    ConcurrentLinkedQueue<TradeItem> unsold = new ConcurrentLinkedQueue<TradeItem>();
    unsold.addAll(listToSell);
    long cost = 0, amount = 0;
    for(TradeItem buyerTradeItem : listToBuy)
    {
      sellerTradeItem = null;
      for(TradeItem unsoldItem : unsold)
      {
        if(unsoldItem.getItemId() == buyerTradeItem.getItemId() && unsoldItem.getOwnersPrice() == buyerTradeItem.getOwnersPrice())
        {
          sellerTradeItem = unsoldItem;
          break;
        }
      }
      if(sellerTradeItem == null)
      {
        continue;
      }
      sellerInventoryItem = sellerInv.getItemByObjectId(sellerTradeItem.getObjectId());
      unsold.remove(sellerTradeItem);
      if(sellerInventoryItem == null)
      {
        continue;
      }
      long buyerItemCount = buyerTradeItem.getCount();
      long sellerItemCount = sellerTradeItem.getCount();
      if(sellerItemCount > sellerInventoryItem.getCount())
      {
        sellerItemCount = sellerInventoryItem.getCount();
      }
      if(seller.getPrivateStoreType() == L2Player.STORE_PRIVATE_SELL || seller.getPrivateStoreType() == L2Player.STORE_PRIVATE_SELL_PACKAGE)
      {
        if(buyerItemCount > sellerItemCount)
        {
          buyerTradeItem.setCount(sellerItemCount);
        }
        if(buyerItemCount > sellerInventoryItem.getCount())
        {
          buyerTradeItem.setCount(sellerInventoryItem.getCount());
        }
        buyerItemCount = buyerTradeItem.getCount();
        amount = buyerItemCount;
        cost = amount * sellerTradeItem.getOwnersPrice();
      }
      if(buyer.getPrivateStoreType() == L2Player.STORE_PRIVATE_BUY)
      {
        if(sellerItemCount > buyerItemCount)
        {
          sellerTradeItem.setCount(buyerItemCount);
        }
        if(sellerItemCount > sellerInventoryItem.getCount())
        {
          sellerTradeItem.setCount(sellerInventoryItem.getCount());
        }
        sellerItemCount = sellerTradeItem.getCount();
        amount = sellerItemCount;
        cost = amount * buyerTradeItem.getOwnersPrice();
      }
      if(buyer.getAdena() < cost)
      {
        return false;
      }
      try
      {
        SafeMath.safeMulLong(buyerItemCount, buyerTradeItem.getOwnersPrice());
        SafeMath.safeMulLong(sellerItemCount, sellerTradeItem.getOwnersPrice());
      }
      catch(ArithmeticException e)
      {
        return false;
      }
      TransferItem = sellerInv.dropItem(sellerInventoryItem.getObjectId(), amount, false);
      Log.LogItem(seller, buyer, Log.PrivateStoreSell, TransferItem, amount);
      buyer.reduceAdena(cost, false);
      seller.addAdena(cost);
      int tax = (int) (cost * Config.SERVICES_TRADE_TAX / 100);
      if(seller.isInZone(L2Zone.ZoneType.offshore))
      {
        tax = (int) (cost * Config.SERVICES_OFFSHORE_TRADE_TAX / 100);
      }
      if(Config.SERVICES_TRADE_TAX_ONLY_OFFLINE && !seller.isInOfflineMode())
      {
        tax = 0;
      }
      if(seller.getReflection().getId() == -1) // Особая зона в Parnassus
      {
        tax = 0;
      }
      if(tax > 0)
      {
        seller.reduceAdena(tax, true);
        Stat.addTax(tax);
        seller.sendMessage(new CustomMessage("trade.HavePaidTax", seller).addNumber(tax));
      }
      temp = buyerInv.addItem(TransferItem);
      Log.LogItem(buyer, seller, Log.PrivateStoreBuy, TransferItem, amount);
      if(!temp.isStackable())
      {
        if(temp.getEnchantLevel() > 0)
        {
View Full Code Here

  }

  private void tradeItems(L2Player player, L2Player reciever)
  {
    ConcurrentLinkedQueue<TradeItem> exchangeList = getExchangeList(player);
    Inventory playersInv = player.getInventory();
    Inventory recieverInv = reciever.getInventory();
    L2ItemInstance recieverItem, TransferItem;
    for(TradeItem temp : exchangeList)
    {
      if(temp.getObjectId() == 0)
      {
        _log.warning("Warning: null object id item, player " + player);
        continue;
      }
      else if(temp.getCount() <= 0)
      {
        _log.warning("Warning: null item count, player " + player);
        continue;
      }
      // If player trades the enchant scroll he was using remove its effect
      if(player.getEnchantScroll() != null && temp.getObjectId() == player.getEnchantScroll().getObjectId())
      {
        player.setEnchantScroll(null);
      }
      TransferItem = playersInv.dropItem(temp.getObjectId(), temp.getCount(), false);
      if(TransferItem == null)
      {
        _log.warning("Warning: null trade item, player " + player);
        continue;
      }
      recieverItem = recieverInv.addItem(TransferItem);
      Log.LogItem(player, reciever, Log.TradeGive, TransferItem);
      Log.LogItem(player, reciever, Log.TradeGet, recieverItem);
    }
    player.sendChanges();
    reciever.sendChanges();
View Full Code Here

    if(listId == 9999)
    {
      list.setShowAll(false);
      list.setKeepEnchant(true);
      list.setNoTax(true);
      final Inventory inv = player.getInventory();
      _items = new GArray<L2ItemInstance>();
      for(final L2ItemInstance itm : inv.getItems())
      {
        if(itm.getItem().getAdditionalName().isEmpty() // Менять можно только обычные предметы
           && !itm.getItem().isSa() // SA менять нельзя
           && !itm.getItem().isRare() // Rare менять нельзя
           && !itm.getItem().isCommonItem() // Common менять нельзя
           && !itm.getItem().isPvP() // PvP менять нельзя
           && itm.canBeTraded(player) // универсальная проверка
           && !itm.isStackable() //
           && itm.getItem().getType2() == L2Item.TYPE2_WEAPON //
           && itm.getItem().getCrystalType() != Grade.NONE //
           && itm.getReferencePrice() <= Config.ALT_MAMMON_EXCHANGE //
           && itm.getItem().getCrystalCount() > 0 //
           && itm.getItem().isTradeable() //
           && (itm.getCustomFlags() & L2ItemInstance.FLAG_NO_TRADE) != L2ItemInstance.FLAG_NO_TRADE //
        )
        {
          _items.add(itm);
        }
      }
      for(final L2ItemInstance itm : _items)
      {
        for(L2Weapon i : ItemTable.getInstance().getAllWeapons())
        {
          if(i.getAdditionalName().isEmpty() // Менять можно только обычные предметы
             && !i.isSa() // На SA менять нельзя
             && !i.isRare() // На Rare менять нельзя
             && !i.isCommonItem() // На Common менять нельзя
             && !i.isPvP() // На PvP менять нельзя
             && !i.isShadowItem() // На Shadow менять нельзя
             && i.isTradeable() // можно использовать чтобы запретить менять специальные вещи
             && i.getItemId() != itm.getItemId() //
             && i.getType2() == L2Item.TYPE2_WEAPON //
             && itm.getItem().getCrystalType() != Grade.NONE //
             && i.getItemType() == WeaponType.DUAL == (itm.getItem().getItemType() == WeaponType.DUAL) //
             && itm.getItem().getCrystalType() == i.getCrystalType() //
             && itm.getItem().getCrystalCount() == i.getCrystalCount() //
          )
          {
            final int entry = new int[]
            {
              itm.getItemId(), i.getItemId(), itm.getEnchantLevel()
            }.hashCode();
            MultiSellEntry possibleEntry = new MultiSellEntry(entry, i.getItemId(), 1, itm.getEnchantLevel());
            possibleEntry.addIngredient(new MultiSellIngredient(itm.getItemId(), 1, itm.getEnchantLevel()));
            list.entries.add(possibleEntry);
          }
        }
      }
    }
    // Hardcoded  - обмен вещей с доплатой за AA
    else if(listId == 9998)
    {
      list.setShowAll(false);
      list.setKeepEnchant(false);
      list.setNoTax(true);
      final Inventory inv = player.getInventory();
      _items = new GArray<L2ItemInstance>();
      for(final L2ItemInstance itm : inv.getItems())
      {
        if(itm.getItem().getAdditionalName().isEmpty() // Менять можно только обычные предметы
           && !itm.getItem().isSa() // SA менять нельзя
           && !itm.getItem().isRare() // Rare менять нельзя
           && !itm.getItem().isCommonItem() // Common менять нельзя
           && !itm.getItem().isPvP() // PvP менять нельзя
           && !itm.getItem().isShadowItem() // Shadow менять нельзя
           && !itm.isTemporalItem() // Temporal менять нельзя
           && !itm.isStackable() //
           && itm.getItem().getType2() == L2Item.TYPE2_WEAPON //
           && itm.getItem().getCrystalType() != Grade.NONE //
           && itm.getReferencePrice() <= Config.ALT_MAMMON_UPGRADE //
           && itm.getItem().getCrystalCount() > 0 //
           && !itm.isEquipped() //
           && itm.getItem().isTradeable() //
           && (itm.getCustomFlags() & L2ItemInstance.FLAG_NO_TRADE) != L2ItemInstance.FLAG_NO_TRADE //
        )
        {
          _items.add(itm);
        }
      }
      for(final L2ItemInstance itemtosell : _items)
      {
        for(final L2Weapon itemtobuy : ItemTable.getInstance().getAllWeapons())
        {
          if(itemtobuy.getAdditionalName().isEmpty() // Менять можно только обычные предметы
             && !itemtobuy.isSa() // На SA менять нельзя
             && !itemtobuy.isRare() // На Rare менять нельзя
             && !itemtobuy.isCommonItem() // На Common менять нельзя
             && !itemtobuy.isPvP() // На PvP менять нельзя
             && !itemtobuy.isShadowItem() // На Shadow менять нельзя
             && itemtobuy.isTradeable() //
             && itemtobuy.getType2() == L2Item.TYPE2_WEAPON //
             && itemtobuy.getItemType() == WeaponType.DUAL == (itemtosell.getItem().getItemType() == WeaponType.DUAL) //
             && itemtobuy.getCrystalType().ordinal() >= itemtosell.getItem().getCrystalType().ordinal() //
             && itemtobuy.getReferencePrice() <= Config.ALT_MAMMON_UPGRADE //
             && itemtosell.getItem().getReferencePrice() < itemtobuy.getReferencePrice() //
             && itemtosell.getReferencePrice() * 1.7 > itemtobuy.getReferencePrice() //
          )
          {
            final int entry = new int[]
            {
              itemtosell.getItemId(), itemtobuy.getItemId(), itemtosell.getEnchantLevel()
            }.hashCode();
            MultiSellEntry possibleEntry = new MultiSellEntry(entry, itemtobuy.getItemId(), 1, 0);
            possibleEntry.addIngredient(new MultiSellIngredient(itemtosell.getItemId(), 1, itemtosell.getEnchantLevel()));
            possibleEntry.addIngredient(new MultiSellIngredient((short) 5575, (int) ((itemtobuy.getReferencePrice() - itemtosell.getReferencePrice()) * 1.2), 0));
            list.entries.add(possibleEntry);
          }
        }
      }
    }
    // Hardcoded  - обмен вещей на кристаллы
    else if(listId == 9997)
    {
      list.setShowAll(false);
      list.setKeepEnchant(true);
      list.setNoTax(false);
      final Inventory inv = player.getInventory();
      for(final L2ItemInstance itm : inv.getItems())
      {
        if(!itm.isStackable() && itm.getItem().isCrystallizable() && itm.getItem().getCrystalType() != Grade.NONE && itm.getItem().getCrystalCount() > 0 && !itm.isShadowItem() && !itm.isTemporalItem() && !itm.isEquipped() && (itm.getCustomFlags() & L2ItemInstance.FLAG_NO_CRYSTALLIZE) != L2ItemInstance.FLAG_NO_CRYSTALLIZE)
        {
          final L2Item crystal = ItemTable.getInstance().getTemplate(itm.getItem().getCrystalType().cry);
          final int entry = new int[]
          {
            itm.getItemId(), itm.getEnchantLevel()
          }.hashCode();
          MultiSellEntry possibleEntry = new MultiSellEntry(entry, crystal.getItemId(), itm.getItem().getCrystalCount(), 0);
          possibleEntry.addIngredient(new MultiSellIngredient(itm.getItemId(), 1, itm.getEnchantLevel()));
          possibleEntry.addIngredient(new MultiSellIngredient((short) 57, (int) (itm.getItem().getCrystalCount() * crystal.getReferencePrice() * 0.05), 0));
          list.entries.add(possibleEntry);
        }
      }
    }
    // Все мультиселлы из датапака
    else
    {
      MultiSellListContainer container = L2Multisell.getInstance().getList(listId);
      if(container == null)
      {
        _log.warning("Not found myltisell " + listId);
        return null;
      }
      else if(container.isEmpty())
      {
        player.sendMessage(new CustomMessage("common.Disabled", player));
        return null;
      }
      boolean enchant = container.isKeepEnchant();
      boolean notax = container.isNoTax();
      boolean showall = container.isShowAll();
      boolean nokey = container.isNoKey();
      list.setShowAll(showall);
      list.setKeepEnchant(enchant);
      list.setNoTax(notax);
      list.setNoKey(nokey);
      final Inventory inv = player.getInventory();
      for(MultiSellEntry origEntry : container.getEntries())
      {
        MultiSellEntry ent = origEntry.clone();
        // Обработка налога, если лист не безналоговый
        // Адены добавляются в лист если отсутствуют или прибавляются к существующим
        GArray<MultiSellIngredient> ingridients;
        if(!notax && taxRate > 0.)
        {
          double tax = 0, adena = 0;
          ingridients = new GArray<MultiSellIngredient>(ent.getIngredients().size() + 1);
          for(MultiSellIngredient i : ent.getIngredients())
          {
            if(i.getItemId() == 57)
            {
              adena += i.getItemCount();
              tax += i.getItemCount() * (taxRate);
              continue;
            }
            ingridients.add(i);
            if(i.getItemId() == L2Item.ITEM_ID_CLAN_REPUTATION_SCORE)
            // hardcoded. Налог на клановую репутацию. Формула проверена на с6 и соответсвует на 100%.
            //TODO: Проверить на корейском(?) оффе налог на банг поинты и fame
            {
              tax += i.getItemCount() / 120 * 1000 * taxRate * 100;
            }
            if(i.getItemId() < 1)
            {
              continue;
            }
            final L2Item item = ItemTable.getInstance().getTemplate(i.getItemId());
            if(item == null)
            {
              System.out.println("Not found template for itemId: " + i.getItemId());
            }
            else if(item.isStackable())
            {
              tax += item.getReferencePrice() * i.getItemCount() * taxRate;
            }
          }
          adena = Math.round(adena + tax);
          if(adena >= 1)
          {
            ingridients.add(new MultiSellIngredient(57, (long) adena));
          }
          tax = Math.round(tax);
          if(tax >= 1)
          {
            ent.setTax((long) tax);
          }
          ent.getIngredients().clear();
          ent.getIngredients().addAll(ingridients);
        }
        else
        {
          ingridients = ent.getIngredients();
        }
        // Если стоит флаг "показывать все" не проверять наличие ингридиентов
        if(showall)
        {
          list.entries.add(ent);
        }
        else
        {
          GArray<Integer> _itm = new GArray<Integer>();
          // Проверка наличия у игрока ингридиентов
          for(MultiSellIngredient i : ingridients)
          {
            L2Item template = i.getItemId() <= 0 ? null : ItemTable.getInstance().getTemplate(i.getItemId());
            if(i.getItemId() <= 0 || template.getType2() <= L2Item.TYPE2_ACCESSORY || template.getType2() >= (nokey ? L2Item.TYPE2_OTHER : L2Item.TYPE2_PET_WOLF)) // Экипировка
            {
              if(i.getItemId() == 12374) // Mammon's Varnish Enhancer
              {
                continue;
              }
              //TODO: а мы должны тут сверять count?
              if(i.getItemId() == L2Item.ITEM_ID_CLAN_REPUTATION_SCORE)
              {
                if(!_itm.contains(i.getItemId()) && player.getClan() != null && player.getClan().getReputationScore() >= i.getItemCount())
                {
                  _itm.add(i.getItemId());
                }
                continue;
              }
              else if(i.getItemId() == L2Item.ITEM_ID_PC_BANG_POINTS)
              {
                if(!_itm.contains(i.getItemId()) && player.getPcBangPoints() >= i.getItemCount())
                {
                  _itm.add(i.getItemId());
                }
                continue;
              }
              else if(i.getItemId() == L2Item.ITEM_ID_FAME)
              {
                if(!_itm.contains(i.getItemId()) && player.getFame() >= i.getItemCount())
                {
                  _itm.add(i.getItemId());
                }
                continue;
              }
              for(final L2ItemInstance item : inv.getItems())
              {
                if(item.getItemId() == i.getItemId() && !item.isEquipped() && (item.getCustomFlags() & L2ItemInstance.FLAG_NO_TRADE) != L2ItemInstance.FLAG_NO_TRADE)
                {
                  if(_itm.contains(enchant ? i.getItemId() + i.getItemEnchant() * 100000 : i.getItemId())) // Не проверять одинаковые вещи
                  {
View Full Code Here

  {
    for(L2Character target : targets)
    {
      if(target != null)
      {
        Inventory inventory;
        if(target.isPlayer())
        {
          inventory = ((L2Player) target).getInventory();
        }
        else if(target.isPet())
        {
          inventory = ((L2PetInstance) target).getInventory();
        }
        else
        {
          continue;
        }
        L2ItemInstance item = ItemTable.getInstance().createItem(_minId > 0 ? Rnd.get(_minId, _maxId) : _itemId);
        final int count = Rnd.get(_minCount, _maxCount);
        item.setCount(count);
        activeChar.sendPacket(SystemMessage.obtainItems(item));
        item = inventory.addItem(item);
        activeChar.sendChanges();
        getEffects(activeChar, target, getActivateRate() > 0, false);
      }
    }
  }
View Full Code Here

  {
    if(!env.character.isPlayer())
    {
      return false;
    }
    Inventory inv = ((L2Player) env.character).getInventory();
    L2ItemInstance item = inv.getPaperdollItem(_slot);
    if(item == null)
    {
      return _itemId == 0;
    }
    return item.getItemId() == _itemId && item.getEnchantLevel() >= _enchantLevel;
View Full Code Here

  {
    if(!env.character.isPlayer())
    {
      return false;
    }
    Inventory inv = ((L2Player) env.character).getInventory();
    return (_mask & inv.getWearedMask()) != 0;
  }
View Full Code Here

    }
    else
    {
      player = playable;
    }
    Inventory inv = player.getInventory();
    if(inv == null)
    {
      return;
    }
    L2ItemInstance[] items = inv.getItems();
    for(L2ItemInstance item : items)
    {
      if(item.getObjectId() == item_obj_id && count > 0)
      {
        long item_count = item.getCount();
View Full Code Here

TOP

Related Classes of l2p.gameserver.model.items.Inventory$ItemOrderComparator

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.