Examples of PcInventory


Examples of com.l2jfrozen.gameserver.model.PcInventory

      ActionFailed af = ActionFailed.STATIC_PACKET;
      activeChar.sendPacket(af);
      return;
    }

    PcInventory inventory = activeChar.getInventory();
    if(inventory != null)
    {
      L2ItemInstance item = inventory.getItemByObjectId(_objectId);
      if(item == null || item.isWear())
      {
        ActionFailed af = ActionFailed.STATIC_PACKET;
        activeChar.sendPacket(af);
        return;
View Full Code Here

Examples of com.l2jfrozen.gameserver.model.PcInventory

          }
          int buy;
          {
            int castleId = getCastle().getCastleId();
            int circlet = CastleManager.getInstance().getCircletByCastleId(castleId);
            PcInventory s = player.getInventory();
            if(s.getItemByItemId(circlet) == null)
            {
              buy = Integer.parseInt(val + "1");
            }
            else
            {
View Full Code Here

Examples of com.l2jfrozen.gameserver.model.PcInventory

                }
        }

        private void doExchange(L2PcInstance player, MultiSellEntry templateEntry, boolean applyTaxes, boolean maintainEnchantment, int enchantment)
        {
                PcInventory inv = player.getInventory();
                boolean maintainItemFound = false;

                // given the template entry and information about maintaining enchantment and applying taxes re-create the instance of
                // the entry that will be used for this exchange i.e. change the enchantment level of select ingredient/products and adena amount appropriately.
                L2NpcInstance merchant = player.getTarget() instanceof L2NpcInstance ? (L2NpcInstance) player.getTarget() : null;

//              if(merchant == null) TODO: Check this
//                      return;

                MultiSellEntry entry = prepareEntry(merchant, templateEntry, applyTaxes, maintainEnchantment, enchantment);

                // Generate a list of distinct ingredients and counts in order to check if the correct item-counts
                // are possessed by the player
                FastList<MultiSellIngredient> _ingredientsList = new FastList<MultiSellIngredient>();
                boolean newIng = true;

                for (MultiSellIngredient e : entry.getIngredients())
                {
                        newIng = true;

                        // at this point, the template has already been modified so that enchantments are properly included
                        // whenever they need to be applied.  Uniqueness of items is thus judged by item id AND enchantment level
                        for (MultiSellIngredient ex : _ingredientsList)
                        {
                                // if the item was already added in the list, merely increment the count
                                // this happens if 1 list entry has the same ingredient twice (example 2 swords = 1 dual)
                                if (ex.getItemId() == e.getItemId() && ex.getEnchantmentLevel() == e.getEnchantmentLevel())
                                {
                                        if ((double) ex.getItemCount() + e.getItemCount() > Integer.MAX_VALUE)
                                        {
                                                player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED));
                                                _ingredientsList.clear();
                                                _ingredientsList = null;
                                                return;
                                        }
                                        ex.setItemCount(ex.getItemCount() + e.getItemCount());
                                        newIng = false;
                                }
                        }
                        if (newIng)
                        {
                                // If there is a maintainIngredient, then we do not need to check the enchantment parameter as the enchant level will be checked elsewhere
                                if (maintainEnchantment)
                                {
                                        maintainItemFound = true;
                                }

                                // if it's a new ingredient, just store its info directly (item id, count, enchantment)
                                _ingredientsList.add(new MultiSellIngredient(e));
                        }
                }

                // If there is no maintainIngredient, then we must make sure that the enchantment is not kept from the client packet, as it may have been forged
                if (!maintainItemFound)
                {
                        for (MultiSellIngredient product : entry.getProducts())
                        {
                                product.setEnchantmentLevel(0);
                        }
                }

                // now check if the player has sufficient items in the inventory to cover the ingredients' expences
                for (MultiSellIngredient e : _ingredientsList)
                {
                    if ((double) e.getItemCount() * _amount > Integer.MAX_VALUE)
                    {
                            player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED));
                            _ingredientsList.clear();
                            _ingredientsList = null;
                            return;
                    }

                    if (e.getItemId() != 65336 && e.getItemId() != 65436)
                    {
                        // if this is not a list that maintains enchantment, check the count of all items that have the given id.
                    // otherwise, check only the count of items with exactly the needed enchantment level
                        if (inv.getInventoryItemCount(e.getItemId(), maintainEnchantment ? e.getEnchantmentLevel() : -1) < (Config.ALT_BLACKSMITH_USE_RECIPES || !e.getMantainIngredient() ? e.getItemCount() * _amount : e.getItemCount()))
                        {
                            player.sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ITEMS));
                            _ingredientsList.clear();
                            _ingredientsList = null;
                            return;
                        }
                    }
                    else
                    {
                        if (e.getItemId() == 65336)
                        {
                            if (player.getClan() == null)
                            {
                                player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_A_CLAN_MEMBER));
                                return;
                            }

                            if (!player.isClanLeader())
                            {
                                player.sendPacket(new SystemMessage(SystemMessageId.ONLY_THE_CLAN_LEADER_IS_ENABLED));
                                return;
                            }

                            if (player.getClan().getReputationScore() < e.getItemCount() * _amount)
                            {
                                player.sendPacket(new SystemMessage(SystemMessageId.THE_CLAN_REPUTATION_SCORE_IS_TOO_LOW));
                                return;
                            }
                        }
                        if (e.getItemId() == 65436 && e.getItemCount() * _amount > player.getPcBangScore())
                        {
                                player.sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ITEMS));
                                return;
                        }
                    }
                }

                _ingredientsList.clear();
                _ingredientsList = null;
                FastList<L2Augmentation> augmentation = new FastList<L2Augmentation>();
                /** All ok, remove items and add final product */

                for (MultiSellIngredient e : entry.getIngredients())
                {
                        if (e.getItemId() != 65336 && e.getItemId() != 65436)
                        {
                                for (MultiSellIngredient a : entry.getProducts())
                                {
                                        if (player.getInventoryLimit() < inv.getSize() + _amount && !ItemTable.getInstance().createDummyItem(a.getItemId()).isStackable())
                                        {
                                                player.sendPacket(new SystemMessage(SystemMessageId.SLOTS_FULL));
                                                return;
                                        }
                                        if (player.getInventoryLimit() < inv.getSize() && ItemTable.getInstance().createDummyItem(a.getItemId()).isStackable())
                                        {
                                                player.sendPacket(new SystemMessage(SystemMessageId.SLOTS_FULL));
                                                return;
                                        }
                                }
                                L2ItemInstance itemToTake = inv.getItemByItemId(e.getItemId()); // initialize and initial guess for the item to take.

                                //this is a cheat, transaction will be aborted and if any items already tanken will not be returned back to inventory!
                                if (itemToTake == null)
                                {
                                        _log.severe("Character: " + player.getName() + " is trying to cheat in multisell, merchatnt id:" + (merchant!=null?merchant.getNpcId():0));
                                        return;
                                }
                                if (itemToTake.fireEvent("MULTISELL", (Object[]) null) != null)
                                        return;

                                if (itemToTake.isWear())
                                {
                                        _log.severe("Character: " + player.getName() + " is trying to cheat in multisell with weared item");
                                        return;
                                }

                                if (Config.ALT_BLACKSMITH_USE_RECIPES || !e.getMantainIngredient())
                                {
                                        // if it's a stackable item, just reduce the amount from the first (only) instance that is found in the inventory
                                        if (itemToTake.isStackable())
                                        {
                                                if (!player.destroyItem("Multisell", itemToTake.getObjectId(), (e.getItemCount() * _amount), player.getTarget(), true))
                                                        return;
                                        }
                                        else
                                        {
                                                // for non-stackable items, one of two scenaria are possible:
                                                // a) list maintains enchantment: get the instances that exactly match the requested enchantment level
                                                // b) list does not maintain enchantment: get the instances with the LOWEST enchantment level

                                                // a) if enchantment is maintained, then get a list of items that exactly match this enchantment
                                                if (maintainEnchantment)
                                                {
                                                    // loop through this list and remove (one by one) each item until the required amount is taken.
                                                    L2ItemInstance[] inventoryContents = inv.getAllItemsByItemId(e.getItemId(), e.getEnchantmentLevel());
                                                    for (int i = 0; i < e.getItemCount() * _amount; i++)
                                                    {
                                                        if (inventoryContents[i].isAugmented())
                                                        {
                                                            augmentation.add(inventoryContents[i].getAugmentation());
                                                        }

                                                        if (inventoryContents[i].isEquipped())
                                                        {
                                                            if (inventoryContents[i].isAugmented())
                                                            {
                                                                inventoryContents[i].getAugmentation().removeBoni(player);
                                                            }
                                                        }

                                                        if (!player.destroyItem("Multisell", inventoryContents[i].getObjectId(), 1, player.getTarget(), true))
                                                            return;
                                                    }
                                                }
                                                else
                                                // b) enchantment is not maintained.  Get the instances with the LOWEST enchantment level
                                                {
                                                        /* NOTE: There are 2 ways to achieve the above goal.
                                                         * 1) Get all items that have the correct itemId, loop through them until the lowest enchantment
                                                         *              level is found.  Repeat all this for the next item until proper count of items is reached.
                                                         * 2) Get all items that have the correct itemId, sort them once based on enchantment level,
                                                         *              and get the range of items that is necessary.
                                                         * Method 1 is faster for a small number of items to be exchanged.
                                                         * Method 2 is faster for large amounts.
                                                         *
                                                         * EXPLANATION:
                                                         *   Worst case scenario for algorithm 1 will make it run in a number of cycles given by:
                                                         * m*(2n-m+1)/2 where m is the number of items to be exchanged and n is the total
                                                         * number of inventory items that have a matching id.
                                                         *   With algorithm 2 (sort), sorting takes n*log(n) time and the choice is done in a single cycle
                                                         * for case b (just grab the m first items) or in linear time for case a (find the beginning of items
                                                         * with correct enchantment, index x, and take all items from x to x+m).
                                                         * Basically, whenever m > log(n) we have: m*(2n-m+1)/2 = (2nm-m*m+m)/2 >
                                                         * (2nlogn-logn*logn+logn)/2 = nlog(n) - log(n*n) + log(n) = nlog(n) + log(n/n*n) =
                                                         * nlog(n) + log(1/n) = nlog(n) - log(n) = (n-1)log(n)
                                                         * So for m < log(n) then m*(2n-m+1)/2 > (n-1)log(n) and m*(2n-m+1)/2 > nlog(n)
                                                         *
                                                         * IDEALLY:
                                                         * In order to best optimize the performance, choose which algorithm to run, based on whether 2^m > n
                                                         * if ( (2<<(e.getItemCount() * _amount)) < inventoryContents.length )
                                                         *   // do Algorithm 1, no sorting
                                                         * else
                                                         *   // do Algorithm 2, sorting
                                                         *
                                                         * CURRENT IMPLEMENTATION:
                                                         * In general, it is going to be very rare for a person to do a massive exchange of non-stackable items
                                                         * For this reason, we assume that algorithm 1 will always suffice and we keep things simple.
                                                         * If, in the future, it becomes necessary that we optimize, the above discussion should make it clear
                                                         * what optimization exactly is necessary (based on the comments under "IDEALLY").
                                                         */

                                                        // choice 1.  Small number of items exchanged.  No sorting.
                                                        for (int i = 1; i <= e.getItemCount() * _amount; i++)
                                                        {
                                                                L2ItemInstance[] inventoryContents = inv.getAllItemsByItemId(e.getItemId());

                                                                itemToTake = inventoryContents[0];
                                                                // get item with the LOWEST enchantment level  from the inventory...
                                                                // +0 is lowest by default...
                                                                if (itemToTake.getEnchantLevel() > 0)
                                                                {
                                                                        for (L2ItemInstance inventoryContent : inventoryContents)
                                                                        {
                                                                                if (inventoryContent.getEnchantLevel() < itemToTake.getEnchantLevel())
                                                                                {
                                                                                        itemToTake = inventoryContent;
                                                                                        // nothing will have enchantment less than 0. If a zero-enchanted
                                                                                        // item is found, just take it
                                                                                        if (itemToTake.getEnchantLevel() == 0)
                                                                                        {
                                                                                                break;
                                                                                        }
                                                                                }
                                                                        }
                                                                }

                                                                if (itemToTake.isEquipped())
                                                                {
                                                                        if (itemToTake.isAugmented())
                                                                        {
                                                                                itemToTake.getAugmentation().removeBoni(player);
                                                                        }
                                                                }

                                                                if (!player.destroyItem("Multisell", itemToTake.getObjectId(), 1, player.getTarget(), true))
                                                                        return;

                                                        }
                                                }
                                        }
                                }
                        }
                        else
                        {
                                if (e.getItemId() == 65336)
                                {
                                        int repCost = player.getClan().getReputationScore() - e.getItemCount();
                                        player.getClan().setReputationScore(repCost, true);
                                        player.sendPacket(new SystemMessage(SystemMessageId.S1_DEDUCTED_FROM_CLAN_REP).addNumber(e.getItemCount()));
                                        player.getClan().broadcastToOnlineMembers(new PledgeShowInfoUpdate(player.getClan()));
                                }
                                else
                                {
                                        player.reducePcBangScore(e.getItemCount() * _amount);
                                        player.sendPacket(new SystemMessage(SystemMessageId.USING_S1_PCPOINT).addNumber(e.getItemCount()));
                                }
                        }
                }
                // Generate the appropriate items
                for (MultiSellIngredient e : entry.getProducts())
                {
                        if (ItemTable.getInstance().createDummyItem(e.getItemId()).isStackable())
                        {
                                inv.addItem("Multisell["+_listId+"]" , e.getItemId(), (e.getItemCount() * _amount), player, player.getTarget());
                        }
                        else
                        {
                                L2ItemInstance product = null;
                                for (int i = 0; i < e.getItemCount() * _amount; i++)
                                {
                                        product = inv.addItem("Multisell["+_listId+"]", e.getItemId(), 1, player, player.getTarget());
                                        if (maintainEnchantment && (product != null))
                                        {
                                                if (i < augmentation.size())
                                                {
                                                        product.setAugmentation(new L2Augmentation(product, augmentation.get(i).getAugmentationId(), augmentation.get(i).getSkill(), true));
View Full Code Here

Examples of com.l2jfrozen.gameserver.model.PcInventory

  {
    for(L2PcInstance player : _playersNotVIP)
    {
      if(player != null)
      {
        PcInventory inv = player.getInventory();
       
        if(ItemTable.getInstance().createDummyItem(_notVipReward).isStackable())
          inv.addItem("VIP Event: ", _notVipReward, _notVipRewardAmount, player, null);
        else
        {
          for(int i=0;i<=_notVipRewardAmount-1;i++)
            inv.addItem("VIP Event: ", _notVipReward, 1, player, null);
        }

        SystemMessage sm;

        if(_notVipRewardAmount > 1)
View Full Code Here

Examples of com.l2jfrozen.gameserver.model.PcInventory

  {
    for(L2PcInstance player : _playersVIP)
    {
      if(player != null && !player._isTheVIP)
      {
        PcInventory inv = player.getInventory();

        if(ItemTable.getInstance().createDummyItem(_vipReward).isStackable())
          inv.addItem("VIP Event: ", _vipReward, _vipRewardAmount, player, null);
        else
        {
          for(int i=0;i<=_vipRewardAmount-1;i++)
            inv.addItem("VIP Event: ", _vipReward, 1, player, null);
        }

        SystemMessage sm;

        if(_vipRewardAmount > 1)
        {
          sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
          sm.addItemName(_vipReward);
          sm.addNumber(_vipRewardAmount);
          player.sendPacket(sm);
        }
        else
        {
          sm = new SystemMessage(SystemMessageId.EARNED_ITEM);
          sm.addItemName(_vipReward);
          player.sendPacket(sm);
        }

        StatusUpdate su = new StatusUpdate(player.getObjectId());
        su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
        player.sendPacket(su);

        NpcHtmlMessage nhm = new NpcHtmlMessage(5);
        TextBuilder replyMSG = new TextBuilder("");

        replyMSG.append("<html><head><body>Your team has won the event. Your inventory now contains your reward.</body></html>");

        nhm.setHtml(replyMSG.toString());
        player.sendPacket(nhm);
      }
      else if(player != null && player._isTheVIP)
      {
        PcInventory inv = player.getInventory();

        if(ItemTable.getInstance().createDummyItem(_theVipReward).isStackable())
          inv.addItem("VIP Event: ", _theVipReward, _theVipRewardAmount, player, null);
        else
        {
          for(int i=0;i<=_theVipRewardAmount-1;i++)
            inv.addItem("VIP Event: ", _theVipReward, 1, player, null);
        }

        SystemMessage sm;

        if(_theVipRewardAmount > 1)
View Full Code Here

Examples of l2p.gameserver.model.items.PcInventory

    if(cheater)
    {
      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)
      {
        _log.info("RequestHennaEquip[50]: Item not found!!!");
      }
    }
    else
View Full Code Here

Examples of l2p.gameserver.model.items.PcInventory

    {
      activeChar.sendPacket(Msg.WHILE_OPERATING_A_PRIVATE_STORE_OR_WORKSHOP_YOU_CANNOT_DISCARD_DESTROY_OR_TRADE_AN_ITEM);
      return;
    }
    Warehouse warehouse;
    PcInventory inventory = activeChar.getInventory();
    boolean privatewh = activeChar.getUsingWarehouseType() != WarehouseType.CLAN;
    int slotsleft;
    long adenaDeposit = 0;
    // Список предметов, уже находящихся на складе
    L2ItemInstance[] itemsOnWarehouse;
    if(privatewh)
    {
      warehouse = activeChar.getWarehouse();
      itemsOnWarehouse = warehouse.listItems(ItemClass.ALL);
      slotsleft = activeChar.getWarehouseLimit() - itemsOnWarehouse.length;
    }
    else
    {
      warehouse = activeChar.getClan().getWarehouse();
      itemsOnWarehouse = warehouse.listItems(ItemClass.ALL);
      slotsleft = activeChar.getClan().getWhBonus() + Config.WAREHOUSE_SLOTS_CLAN - itemsOnWarehouse.length;
    }
    // Список стекуемых предметов, уже находящихся на складе
    GArray<Integer> stackableList = new GArray<Integer>();
    for(L2ItemInstance i : itemsOnWarehouse)
    {
      if(i.isStackable())
      {
        stackableList.add(i.getItemId());
      }
    }
    // Создаем новый список передаваемых предметов, на основе полученных данных
    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);
    }
    // Проверяем, хватит ли у нас денег на уплату налога
    int fee = itemsToStoreList.size() * _WAREHOUSE_FEE;
    if(fee + adenaDeposit > activeChar.getAdena())
    {
      activeChar.sendPacket(Msg.YOU_LACK_THE_FUNDS_NEEDED_TO_PAY_FOR_THIS_TRANSACTION);
      return;
    }
    // Сообщаем о том, что слоты кончились
    if(slotsleft <= 0)
    {
      activeChar.sendPacket(Msg.YOUR_WAREHOUSE_IS_FULL);
    }
    // Перекидываем
    for(L2ItemInstance itemToStore : itemsToStoreList)
    {
      warehouse.addItem(inventory.dropItem(itemToStore, _items.get(itemToStore.getObjectId()), false), activeChar.getName());
    }
    // Платим налог
    activeChar.reduceAdena(fee, true);
    // Обновляем параметры персонажа
    activeChar.updateStats();
View Full Code Here

Examples of l2p.gameserver.model.items.PcInventory

    {
      activeChar.sendActionFailed();
      return;
    }
    PetInventory petInventory = pet.getInventory();
    PcInventory playerInventory = activeChar.getInventory();
    L2ItemInstance petItem = petInventory.getItemByObjectId(_objectId);
    if(petItem == null)
    {
      _log.warning(activeChar.getName() + " requested item obj_id: " + _objectId + " from pet, but its not there.");
      return;
    }
    if(petItem.isEquipped())
    {
      activeChar.sendActionFailed();
      return;
    }
    long finalLoad = petItem.getItem().getWeight() * _amount;
    if(!activeChar.getInventory().validateWeight(finalLoad))
    {
      sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT);
      return;
    }
    L2ItemInstance item = petInventory.dropItem(_objectId, _amount, false);
    item.setCustomFlags(item.getCustomFlags() & ~L2ItemInstance.FLAG_PET_EQUIPPED, true);
    playerInventory.addItem(item);
    pet.sendItemList();
    pet.broadcastPetInfo();
    Log.LogItem(activeChar, activeChar.getPet(), Log.GetItemFromPet, petItem);
  }
View Full Code Here

Examples of l2p.gameserver.model.items.PcInventory

    L2Player activeChar = getClient().getActiveChar();
    if(activeChar == null)
    {
      return;
    }
    PcInventory inventory = activeChar.getInventory();
    L2ItemInstance itemToEnchant = inventory.getItemByObjectId(_itemId);
    L2ItemInstance catalyst = inventory.getItemByObjectId(_catalystId);
    if(checkCatalyst(itemToEnchant, catalyst))
    {
      activeChar.sendPacket(new ExPutEnchantSupportItemResult(1));
    }
    else
View Full Code Here

Examples of l2p.gameserver.model.items.PcInventory

    }
  }

  private void doExchange(L2Player activeChar, MultiSellEntry entry)
  {
    PcInventory inv = activeChar.getInventory();
    int totalAdenaCost = 0;
    long tax;
    try
    {
      tax = SafeMath.safeMulLong(entry.getTax(), _amount);
    }
    catch(ArithmeticException e)
    {
      return;
    }
    L2NpcInstance merchant = activeChar.getLastNpc();
    Castle castle = merchant != null ? merchant.getCastle(activeChar) : null;
    GArray<MultiSellIngredient> productId = entry.getProduction();
    if(_keepenchant)
    {
      for(MultiSellIngredient p : productId)
      {
        _enchant = Math.max(_enchant, p.getItemEnchant());
      }
    }
    boolean logExchange = Config.LOG_MULTISELL_ID_LIST.contains(_listId);
    StringBuffer msgb = new StringBuffer();
    if(logExchange)
    {
      msgb.append("<multisell id=").append(_listId).append(" player=\"").append(activeChar.getName()).append("\" oid=").append(activeChar.getObjectId()).append(">\n");
    }
    synchronized(inv)
    {
      int slots = inv.slotsLeft();
      if(slots == 0)
      {
        activeChar.sendPacket(Msg.THE_WEIGHT_AND_VOLUME_LIMIT_OF_INVENTORY_MUST_NOT_BE_EXCEEDED);
        return;
      }
      int req = 0;
      long totalLoad = 0;
      for(MultiSellIngredient i : productId)
      {
        if(i.getItemId() <= 0)
        {
          continue;
        }
        totalLoad += ItemTable.getInstance().getTemplate(i.getItemId()).getWeight() * _amount;
        if(!ItemTable.getInstance().getTemplate(i.getItemId()).isStackable())
        {
          req += _amount;
        }
        else
        {
          req++;
        }
      }
      if(req > slots || !inv.validateWeight(totalLoad))
      {
        activeChar.sendPacket(Msg.THE_WEIGHT_AND_VOLUME_LIMIT_OF_INVENTORY_MUST_NOT_BE_EXCEEDED);
        return;
      }
      if(entry.getIngredients().size() == 0)
      {
        System.out.println("WARNING Ingredients list = 0 multisell id=:" + _listId + " player:" + activeChar.getName());
        activeChar.sendActionFailed();
        return;
      }
      L2Augmentation augmentation = null;
      // Перебор всех ингридиентов, проверка наличия и создание списка забираемого
      for(MultiSellIngredient ingridient : entry.getIngredients())
      {
        int ingridientItemId = ingridient.getItemId();
        long ingridientItemCount = ingridient.getItemCount();
        long total_amount;
        try
        {
          total_amount = SafeMath.safeMulLong(ingridientItemCount, _amount);
        }
        catch(ArithmeticException e)
        {
          activeChar.sendActionFailed();
          return;
        }
        if(ingridientItemId > 0 && !ItemTable.getInstance().getTemplate(ingridientItemId).isStackable())
        {
          for(int i = 0; i < ingridientItemCount * _amount; i++)
          {
            L2ItemInstance[] list = inv.getAllItemsById(ingridientItemId);
            // Если энчант имеет значение - то ищем вещи с точно таким энчантом
            if(_keepenchant)
            {
              L2ItemInstance itemToTake = null;
              for(L2ItemInstance itm : list)
              {
                if((itm.getEnchantLevel() == _enchant || itm.getItem().getType2() > 2) && !_items.contains(new ItemData(itm.getItemId(), itm.getCount(), itm)) && !itm.isShadowItem() && !itm.isTemporalItem() && (itm.getCustomFlags() & L2ItemInstance.FLAG_NO_TRADE) != L2ItemInstance.FLAG_NO_TRADE)
                {
                  itemToTake = itm;
                  if(itm.getAttributeElement() != L2Item.ATTRIBUTE_NONE)
                  {
                    _enchantAttr = itm.getAttributeElement();
                    _enchantAttrVal = itm.getAttributeElementValue();
                  }
                  break;
                }
              }
              if(itemToTake == null)
              {
                activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_REQUIRED_ITEMS);
                return;
              }
              if(!checkItem(itemToTake, activeChar))
              {
                activeChar.sendActionFailed();
                return;
              }
              if(itemToTake.getAugmentation() != null)
              {
                augmentation = itemToTake.getAugmentation();
              }
              _items.add(new ItemData(itemToTake.getItemId(), 1, itemToTake));
            }
            // Если энчант не обрабатывается берется вещь с наименьшим энчантом
            else
            {
              L2ItemInstance itemToTake = null;
              for(L2ItemInstance itm : list)
              {
                if(!_items.contains(new ItemData(itm.getItemId(), itm.getCount(), itm)) && (itemToTake == null || itm.getEnchantLevel() < itemToTake.getEnchantLevel()) && !itm.isShadowItem() && !itm.isTemporalItem() && (itm.getCustomFlags() & L2ItemInstance.FLAG_NO_TRADE) != L2ItemInstance.FLAG_NO_TRADE && checkItem(itm, activeChar))
                {
                  itemToTake = itm;
                  if(itemToTake.getEnchantLevel() == 0)
                  {
                    break;
                  }
                }
              }
              if(itemToTake == null)
              {
                activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_REQUIRED_ITEMS);
                return;
              }
              if(itemToTake.getAugmentation() != null)
              {
                augmentation = itemToTake.getAugmentation();
              }
              _items.add(new ItemData(itemToTake.getItemId(), 1, itemToTake));
            }
          }
        }
        else if(ingridientItemId == L2Item.ITEM_ID_CLAN_REPUTATION_SCORE)
        {
          if(activeChar.getClan() == null)
          {
            activeChar.sendPacket(Msg.YOU_ARE_NOT_A_CLAN_MEMBER);
            return;
          }
          if(activeChar.getClan().getReputationScore() < total_amount)
          {
            activeChar.sendPacket(Msg.THE_CLAN_REPUTATION_SCORE_IS_TOO_LOW);
            return;
          }
          if(activeChar.getClan().getLeaderId() != activeChar.getObjectId())
          {
            activeChar.sendPacket(new SystemMessage(SystemMessage.S1_IS_NOT_A_CLAN_LEADER).addString(activeChar.getName()));
            return;
          }
          _items.add(new ItemData(ingridientItemId, total_amount, null));
        }
        else if(ingridientItemId == L2Item.ITEM_ID_PC_BANG_POINTS)
        {
          if(activeChar.getPcBangPoints() < total_amount)
          {
            activeChar.sendPacket(Msg.YOU_ARE_SHORT_OF_ACCUMULATED_POINTS);
            return;
          }
          _items.add(new ItemData(ingridientItemId, total_amount, null));
        }
        else if(ingridientItemId == L2Item.ITEM_ID_FAME)
        {
          if(activeChar.getFame() < total_amount)
          {
            activeChar.sendPacket(Msg.NOT_ENOUGH_FAME_POINTS);
            return;
          }
          _items.add(new ItemData(ingridientItemId, total_amount, null));
        }
        else
        {
          if(ingridientItemId == 57)
          {
            totalAdenaCost += ingridientItemCount * _amount;
          }
          L2ItemInstance item = inv.getItemByItemId(ingridientItemId);
          if(item == null || item.getCount() < total_amount)
          {
            activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_REQUIRED_ITEMS);
            return;
          }
          _items.add(new ItemData(item.getItemId(), total_amount, item));
        }
        if(activeChar.getAdena() < totalAdenaCost)
        {
          activeChar.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
          return;
        }
      }
      for(ItemData id : _items)
      {
        long count = id.getCount();
        if(count > 0)
        {
          L2ItemInstance item = id.getItem();
          if(item != null)
          {
            activeChar.sendPacket(SystemMessage.removeItems(item.getItemId(), count));
            if(logExchange)
            {
              msgb.append("\t<destroy id=").append(item.getItemId()).append(" oid=").append(item.getObjectId()).append(" count=").append(count).append(">\n");
            }
            if(item.isEquipped())
            {
              inv.unEquipItemInSlot(item.getEquipSlot());
            }
            inv.destroyItem(item, count, true);
          }
          else if(id.getId() == L2Item.ITEM_ID_CLAN_REPUTATION_SCORE)
          {
            activeChar.getClan().incReputation((int) -count, false, "MultiSell" + _listId);
            activeChar.sendPacket(new SystemMessage(SystemMessage.S1_POINTS_HAVE_BEEN_DEDUCTED_FROM_THE_CLAN_REPUTATION_SCORE).addNumber(count));
          }
          else if(id.getId() == L2Item.ITEM_ID_PC_BANG_POINTS)
          {
            activeChar.setPcBangPoints(activeChar.getPcBangPoints() - (int) count);
            activeChar.sendPacket(new SystemMessage(SystemMessage.YOU_ARE_USING_S1_POINT).addNumber(count), new ExPCCafePointInfo(activeChar));
          }
          else if(id.getId() == L2Item.ITEM_ID_FAME)
          {
            activeChar.setFame(activeChar.getFame() - (int) count, "MultiSell" + _listId);
            activeChar.sendPacket(new SystemMessage(SystemMessage.S2_S1_HAS_DISAPPEARED).addNumber(count).addString("Fame"));
          }
        }
      }
      if(tax > 0 && !_notax)
      {
        if(castle != null)
        {
          activeChar.sendMessage("Tax: " + tax);
          if(merchant != null && merchant.getReflection().getId() == 0)
          {
            castle.addToTreasury(tax, true, false);
            Log.add(castle.getName() + "|" + tax + "|Multisell", "treasury");
          }
        }
      }
      for(MultiSellIngredient in : productId)
      {
        if(in.getItemId() <= 0)
        {
          if(in.getItemId() == L2Item.ITEM_ID_CLAN_REPUTATION_SCORE)
          {
            activeChar.getClan().incReputation((int) (in.getItemCount() * _amount), false, "MultiSell" + _listId);
            activeChar.sendPacket(new SystemMessage(SystemMessage.YOUR_CLAN_HAS_ADDED_1S_POINTS_TO_ITS_CLAN_REPUTATION_SCORE).addNumber(in.getItemCount() * _amount));
          }
          else if(in.getItemId() == L2Item.ITEM_ID_PC_BANG_POINTS)
          {
            activeChar.setPcBangPoints(activeChar.getPcBangPoints() + (int) (in.getItemCount() * _amount));
            activeChar.sendPacket(new SystemMessage(SystemMessage.YOU_ACQUIRED_S1_PC_BANG_POINT).addNumber(in.getItemCount() * _amount), new ExPCCafePointInfo(activeChar));
          }
          else if(in.getItemId() == L2Item.ITEM_ID_FAME)
          {
            activeChar.setFame(activeChar.getFame() + (int) (in.getItemCount() * _amount), "MultiSell" + _listId);
          }
        }
        else if(ItemTable.getInstance().getTemplate(in.getItemId()).isStackable())
        {
          L2ItemInstance product = ItemTable.getInstance().createItem(in.getItemId());
          double total = in.getItemCount() * _amount;
          if(total < 0 || total > Long.MAX_VALUE)
          {
            activeChar.sendActionFailed();
            return;
          }
          product.setCount((long) total);
          activeChar.sendPacket(SystemMessage.obtainItems(product));
          if(logExchange)
          {
            msgb.append("\t<add id=").append(product.getItemId()).append(" count=").append(product.getCount()).append(">\n");
          }
          inv.addItem(product);
        }
        else
        {
          for(int i = 0; i < _amount; i++)
          {
            L2ItemInstance product = inv.addItem(ItemTable.getInstance().createItem(in.getItemId()));
            if(_keepenchant)
            {
              product.setEnchantLevel(_enchant);
              if(_enchantAttr != L2Item.ATTRIBUTE_NONE)
              {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.