Package l2p.gameserver.model.items

Examples of l2p.gameserver.model.items.L2ItemInstance


  }

  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())
          {
            list.remove(i);
            break;
          }
        }
      }
      else if(item.getCount() < temp.getCount())
      {
        temp.setCount(item.getCount());
      }
    }
  }
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)
        {
          seller.sendPacket(new SystemMessage(SystemMessage._S2S3_HAS_BEEN_SOLD_TO_S1_AT_THE_PRICE_OF_S4_ADENA).addString(buyer.getName()).addNumber(temp.getEnchantLevel()).addItemName(sellerInventoryItem.getItemId()).addNumber(cost));
          buyer.sendPacket(new SystemMessage(SystemMessage._S2S3_HAS_BEEN_PURCHASED_FROM_S1_AT_THE_PRICE_OF_S4_ADENA).addString(seller.getName()).addNumber(temp.getEnchantLevel()).addItemName(sellerInventoryItem.getItemId()).addNumber(cost));
        }
        else
        {
          seller.sendPacket(new SystemMessage(SystemMessage.S2_IS_SOLD_TO_S1_AT_THE_PRICE_OF_S3_ADENA).addString(buyer.getName()).addItemName(sellerInventoryItem.getItemId()).addNumber(cost));
          buyer.sendPacket(new SystemMessage(SystemMessage.S2_HAS_BEEN_PURCHASED_FROM_S1_AT_THE_PRICE_OF_S3_ADENA).addString(seller.getName()).addItemName(sellerInventoryItem.getItemId()).addNumber(cost));
View Full Code Here

      {
        for(TradeItem bl : listToBuy)
        {
          if(sl.getItemId() == bl.getItemId() && sl.getOwnersPrice() == bl.getOwnersPrice())
          {
            L2ItemInstance inst = seller.getInventory().getItemByObjectId(sl.getObjectId());
            if(inst == null || inst.getCount() <= 0)
            {
              tmp.remove(sl);
              continue;
            }
            if(inst.isStackable())
            {
              sl.setCount(sl.getCount() - bl.getCount());
              if(sl.getCount() <= 0)
              {
                tmp.remove(sl);
                continue;
              }
              if(inst.getCount() < sl.getCount())
              {
                sl.setCount(inst.getCount());
              }
            }
          }
        }
      }
View Full Code Here

    if(player.getPrivateStoreType() == L2Player.STORE_PRIVATE_SELL || player.getPrivateStoreType() == L2Player.STORE_PRIVATE_SELL_PACKAGE)
    {
      ConcurrentLinkedQueue<TradeItem> selllist = player.getSellList();
      for(TradeItem tl : selllist)
      {
        L2ItemInstance inst = player.getInventory().getItemByObjectId(tl.getObjectId());
        if(inst == null || inst.getCount() <= 0)
        {
          if(player.getPrivateStoreType() == L2Player.STORE_PRIVATE_SELL_PACKAGE)
          {
            cancelStore(player);
            return false;
          }
          selllist.remove(tl);
          continue;
        }
        if(inst.isStackable() && inst.getCount() < tl.getCount())
        {
          if(player.getPrivateStoreType() == L2Player.STORE_PRIVATE_SELL_PACKAGE)
          {
            cancelStore(player);
            return false;
          }
          tl.setCount(inst.getCount());
        }
      }
    }
    else if(player.getPrivateStoreType() == L2Player.STORE_PRIVATE_BUY)
    {
View Full Code Here

    {
      activeChar.sendPacket(Msg.THE_SYMBOL_CANNOT_BE_DRAWN);
      return;
    }
    PcInventory inventory = activeChar.getInventory();
    L2ItemInstance item = inventory.getItemByItemId(temp.getItemIdDye());
    if(item != null && item.getCount() >= temp.getAmountDyeRequire() && activeChar.getAdena() >= temp.getPrice() && activeChar.addHenna(temp))
    {
      activeChar.sendPacket(new SystemMessage(SystemMessage.S1_HAS_DISAPPEARED).addString(temp.getName()), Msg.THE_SYMBOL_HAS_BEEN_ADDED);
      inventory.reduceAdena(temp.getPrice());
      if(inventory.destroyItemByItemId(temp.getItemIdDye(), temp.getAmountDyeRequire(), true) == null)
      {
View Full Code Here

    }
    // Создаем новый список передаваемых предметов, на основе полученных данных
    GArray<L2ItemInstance> itemsToStoreList = new GArray<L2ItemInstance>(_items.size() + 1);
    for(Integer itemObjectId : _items.keySet())
    {
      L2ItemInstance item = inventory.getItemByObjectId(itemObjectId);
      if(item == null || !item.canBeStored(activeChar, privatewh)) // а его вообще положить можно?
      {
        continue;
      }
      if(!item.isStackable() || !stackableList.contains(item.getItemId())) // вещь требует слота
      {
        if(slotsleft <= 0) // если слоты кончились нестекуемые вещи и отсутствующие стекуемые пропускаем
        {
          continue;
        }
        slotsleft--; // если слот есть то его уже нет
      }
      if(item.getItemId() == 57)
      {
        adenaDeposit = _items.get(itemObjectId);
      }
      itemsToStoreList.add(item);
    }
View Full Code Here

    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

    L2VehicleTrajet t = _cycle == 1 ? _t1 : _t2;
    for(L2Player player : L2ObjectsStorage.getAllPlayersForIterate())
    {
      if(player != null && player.getVehicle() == this)
      {
        L2ItemInstance it = player.getInventory().getItemByItemId(t._ticketId);
        if(it != null && it.getCount() >= 1)
        {
          player.getInventory().destroyItem(it.getObjectId(), 1, false);
          player.sendPacket(new VehicleStart(this, 1));
        }
        else if(it == null && t._ticketId == 0 || player.isGM())
        {
          player.sendPacket(new VehicleStart(this, 1));
View Full Code Here

            break;
          default:
            activeChar.sendMessage("There is no skills for your class.");
            return;
        }
        L2ItemInstance spb = activeChar.getInventory().getItemByItemId(item_id);
        if(spb == null || spb.getCount() < 1)
        {
          activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ITEMS_TO_LEARN_SKILLS);
          return;
        }
        L2ItemInstance ri = activeChar.getInventory().destroyItem(spb, 1, true);
        activeChar.sendPacket(SystemMessage.removeItems(ri.getItemId(), 1));
        String var = activeChar.getVar("TransferSkills" + item_id);
        if(var == null)
        {
          var = "";
        }
        if(!var.isEmpty())
        {
          var += ";";
        }
        var += skill.getId();
        activeChar.setVar("TransferSkills" + item_id, var);
      }
      activeChar.addSkill(skill, true);
      activeChar.updateStats();
      activeChar.sendUserInfo(true);
    }
    else
    {
      int _requiredSp = SkillTreeTable.getInstance().getSkillCost(activeChar, skill);
      if(activeChar.getSp() >= _requiredSp || SkillLearn.common || SkillLearn.transformation)
      {
        Integer spb_id = SkillSpellbookTable.getSkillSpellbooks().get(SkillSpellbookTable.hashCode(new int[]
        {
          skill.getId(), skill.getLevel()
        }));
        if(spb_id != null)
        {
          L2ItemInstance spb = activeChar.getInventory().getItemByItemId(spb_id);
          if(spb == null || spb.getCount() < itemCount)
          {
            activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ITEMS_TO_LEARN_SKILLS);
            return;
          }
          L2ItemInstance ri = activeChar.getInventory().destroyItem(spb, itemCount, true);
          activeChar.sendPacket(SystemMessage.removeItems(ri.getItemId(), itemCount));
        }
        activeChar.addSkill(skill, true);
        if(!SkillLearn.common && !SkillLearn.transformation)
        {
          activeChar.setSp(activeChar.getSp() - _requiredSp);
View Full Code Here

      {
        return false;
      }
      player = owner;
    }
    L2ItemInstance oldItem = player.getInventory().getItemByItemId(_itemId);
    if(oldItem == null)
    {
      return false;
    }
    long oldCount = oldItem.getCount();
    player.validateLocation(0);
    if((oldItem = player.getInventory().dropItem(oldItem, oldCount, true)) == null)
    {
      return false;
    }
    player.setKarma(_playerKarma);
    player.setPkKills(_playerPkKills);
    player.setCursedWeaponEquippedId(0);
    player.setTransformation(0);
    player.setTransformationName(null);
    L2Skill skill = SkillTable.getInstance().getInfo(_skillId, player.getSkillLevel(_skillId));
    if(skill != null)
    {
      for(AddedSkill s : skill.getAddedSkills())
      {
        player.removeSkillById(s.id);
      }
    }
    player.removeSkillById(_skillId);
    player.abortAttack(true, false);
    zeroOwner();
    setState(CursedWeaponState.DROPPED);
    oldItem.dropToTheGround(player, (L2NpcInstance) null);
    _loc = oldItem.getLoc();
    oldItem.setDropTime(0);
    _item = oldItem;
    player.sendPacket(new SystemMessage(SystemMessage.YOU_HAVE_DROPPED_S1).addItemName(oldItem.getItemId()));
    player.refreshExpertisePenalty();
    player.broadcastUserInfo(true);
    player.broadcastPacket(new Earthquake(player.getLoc(), 30, 12));
    return true;
  }
View Full Code Here

TOP

Related Classes of l2p.gameserver.model.items.L2ItemInstance

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.