Пример #1
0
        /// <summary>
        /// Sends every modified weapon to the player.
        /// Steps:
        /// Change every weapon to default values.
        /// Stores the index of every modified weapon, and stores the index as the max index.
        /// Fill the player's inventory with a placeholder item up to the max index.
        /// Removes every item that was modified serverside with the list of indexes.
        /// Starts to drop the modified items.
        /// </summary>
        public static void SendCustomItems(PvPPlayer player)
        {
            RefreshInventory(player);
            List <int>       itemIndex = new List <int>();
            InventoryIndexer indexer   = new InventoryIndexer();

            for (byte loop = 0; loop < indexer.MaxInventoryCycle; loop++)
            {
                int index = indexer.NextIndex();

                Item item = player.TPlayer.inventory[index];

                var custwep = GetCustomWeapon(player, item.type, item.prefix, (short)item.stack);
                if (IsModifiedItem(custwep.ItemNetId))
                {
                    indexer.StoreMaxIndex(index);
                    itemIndex.Add(index);
                    player.InvTracker.AddItem(custwep);
                }
            }

            if (itemIndex.Count != 0)
            {
                SSCUtils.FillInventoryToIndex(player, Constants.EmptyItem, Constants.JunkItem, indexer.MaxIndex);
                foreach (int num in itemIndex)
                {
                    SSCUtils.SetItem(player, (byte)num, Constants.EmptyItem);
                }
                player.InvTracker.StartDroppingItems();
            }
            else
            {
                player.InvTracker.CheckFinishedModifications(0);
            }
        }
Пример #2
0
        /// <summary>
        /// Replaces every instance of an item that matches the target item id with an item
        /// that matches the replacement item id up to a certain inventory index.
        /// </summary>
        /// <param name="player">The player to change inventory from.</param>
        /// <param name="targetItemID">The numerical ID of the item to be replaced.</param>
        /// <param name="replacementItemID">The numerical ID of the item to replace.</param>
        /// <param name="maxIndex">The index to fill the inventory up to.</param>
        public static void FillInventoryToIndex(TSPlayer player, short targetItemID, short replacementItemID, int maxIndex)
        {
            InventoryIndexer indexer = new InventoryIndexer();

            indexer.StoreMaxIndex(maxIndex);

            new SSCAction(player, () => {
                for (byte loop = 0; loop < indexer.MaxIndexPos; loop++)
                {
                    if (!player.ConnectionAlive)
                    {
                        return;
                    }
                    int index = indexer.NextIndex();
                    if (player.TPlayer.inventory[index].netID == targetItemID)
                    {
                        player.TPlayer.inventory[index].SetDefaults(replacementItemID);
                        NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, null, player.Index, index, 1, 0, replacementItemID);
                    }
                }
            });
        }