Пример #1
0
        public void SellItems(List <SoldItem> itemsToSell)
        {
            var canAddToRemoveQueue = (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer) && Entity.Spawner != null;

            foreach (SoldItem item in itemsToSell)
            {
                var itemValue = GetSellValueAtCurrentLocation(item.ItemPrefab);

                // check if the store can afford the item and if the item hasn't been removed already
                if (location.StoreCurrentBalance < itemValue || item.Removed)
                {
                    continue;
                }

                if (!item.Removed && canAddToRemoveQueue && Entity.FindEntityByID(item.ID) is Item entity)
                {
                    item.Removed = true;
                    Entity.Spawner.AddToRemoveQueue(entity);
                }
                SoldItems.Add(item);
                location.StoreCurrentBalance -= itemValue;
                campaign.Money += itemValue;
            }
            OnSoldItemsChanged?.Invoke();
        }
Пример #2
0
        public void SellItems(List <PurchasedItem> itemsToSell)
        {
            var itemsInInventory    = GetSellableItems(Character.Controlled);
            var canAddToRemoveQueue = campaign.IsSinglePlayer && Entity.Spawner != null;
            var sellerId            = GameMain.Client?.ID ?? 0;

            foreach (PurchasedItem item in itemsToSell)
            {
                var itemValue = GetSellValueAtCurrentLocation(item.ItemPrefab, quantity: item.Quantity);

                // check if the store can afford the item
                if (Location.StoreCurrentBalance < itemValue)
                {
                    continue;
                }

                var matchingItems = itemsInInventory.FindAll(i => i.Prefab == item.ItemPrefab);
                if (matchingItems.Count <= item.Quantity)
                {
                    foreach (Item i in matchingItems)
                    {
                        SoldItems.Add(new SoldItem(i.Prefab, i.ID, canAddToRemoveQueue, sellerId));
                        SoldEntities.Add(campaign.IsSinglePlayer ? SoldEntity.CreateInSinglePlayer(i) : SoldEntity.CreateInMultiPlayer(i));
                        if (canAddToRemoveQueue)
                        {
                            Entity.Spawner.AddToRemoveQueue(i);
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < item.Quantity; i++)
                    {
                        var matchingItem = matchingItems[i];
                        SoldItems.Add(new SoldItem(matchingItem.Prefab, matchingItem.ID, canAddToRemoveQueue, sellerId));
                        SoldEntities.Add(campaign.IsSinglePlayer ? SoldEntity.CreateInSinglePlayer(matchingItem) : SoldEntity.CreateInMultiPlayer(matchingItem));
                        if (canAddToRemoveQueue)
                        {
                            Entity.Spawner.AddToRemoveQueue(matchingItem);
                        }
                    }
                }

                // Exchange money
                Location.StoreCurrentBalance -= itemValue;
                campaign.Money += itemValue;

                // Remove from the sell crate
                if (ItemsInSellCrate.Find(pi => pi.ItemPrefab == item.ItemPrefab) is { } itemToSell)
                {
                    itemToSell.Quantity -= item.Quantity;
                    if (itemToSell.Quantity < 1)
                    {
                        ItemsInSellCrate.Remove(itemToSell);
                    }
                }
            }

            OnSoldItemsChanged?.Invoke();
        }
        public void SellItems(List <SoldItem> itemsToSell)
        {
            // Check all the prices before starting the transaction
            // to make sure the modifiers stay the same for the whole transaction
            Dictionary <ItemPrefab, int> sellValues = GetSellValuesAtCurrentLocation(itemsToSell.Select(i => i.ItemPrefab));
            var canAddToRemoveQueue = (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer) && Entity.Spawner != null;

            foreach (SoldItem item in itemsToSell)
            {
                var itemValue = sellValues[item.ItemPrefab];

                // check if the store can afford the item and if the item hasn't been removed already
                if (Location.StoreCurrentBalance < itemValue || item.Removed)
                {
                    continue;
                }

                if (!item.Removed && canAddToRemoveQueue && Entity.FindEntityByID(item.ID) is Item entity)
                {
                    item.Removed = true;
                    Entity.Spawner.AddToRemoveQueue(entity);
                }
                SoldItems.Add(item);
                Location.StoreCurrentBalance -= itemValue;
                campaign.Money += itemValue;
            }
            OnSoldItemsChanged?.Invoke();
        }
Пример #4
0
        public void SetSoldItems(List <SoldItem> items)
        {
            SoldItems.Clear();
            SoldItems.AddRange(items);

            foreach (SoldEntity se in SoldEntities)
            {
                if (se.Status == SoldEntity.SellStatus.Confirmed)
                {
                    continue;
                }
                if (SoldItems.Any(si => si.ID == se.Item.ID && si.ItemPrefab == se.Item.Prefab && (GameMain.Client == null || GameMain.Client.ID == si.SellerID)))
                {
                    se.Status = SoldEntity.SellStatus.Confirmed;
                }
                else
                {
                    se.Status = SoldEntity.SellStatus.Unconfirmed;
                }
            }

            OnSoldItemsChanged?.Invoke();
        }
Пример #5
0
        public void SellItems(List <PurchasedItem> itemsToSell)
        {
            var itemsInInventory    = GetSellableItems(Character.Controlled);
            var canAddToRemoveQueue = campaign.IsSinglePlayer && Entity.Spawner != null;
            var sellerId            = GameMain.Client?.ID ?? 0;

            // Check all the prices before starting the transaction
            // to make sure the modifiers stay the same for the whole transaction
            Dictionary <ItemPrefab, int> sellValues = GetSellValuesAtCurrentLocation(itemsToSell.Select(i => i.ItemPrefab));

            foreach (PurchasedItem item in itemsToSell)
            {
                var itemValue = item.Quantity * sellValues[item.ItemPrefab];

                // check if the store can afford the item
                if (Location.StoreCurrentBalance < itemValue)
                {
                    continue;
                }

                // TODO: Write logic for prioritizing certain items over others (e.g. lone Battery Cell should be preferred over one inside a Stun Baton)
                var matchingItems = itemsInInventory.Where(i => i.Prefab == item.ItemPrefab);
                if (matchingItems.Count() <= item.Quantity)
                {
                    foreach (Item i in matchingItems)
                    {
                        SoldItems.Add(new SoldItem(i.Prefab, i.ID, canAddToRemoveQueue, sellerId));
                        SoldEntities.Add(campaign.IsSinglePlayer ? SoldEntity.CreateInSinglePlayer(i) : SoldEntity.CreateInMultiPlayer(i));
                        if (canAddToRemoveQueue)
                        {
                            Entity.Spawner.AddToRemoveQueue(i);
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < item.Quantity; i++)
                    {
                        var matchingItem = matchingItems.ElementAt(i);
                        SoldItems.Add(new SoldItem(matchingItem.Prefab, matchingItem.ID, canAddToRemoveQueue, sellerId));
                        SoldEntities.Add(campaign.IsSinglePlayer ? SoldEntity.CreateInSinglePlayer(matchingItem) : SoldEntity.CreateInMultiPlayer(matchingItem));
                        if (canAddToRemoveQueue)
                        {
                            Entity.Spawner.AddToRemoveQueue(matchingItem);
                        }
                    }
                }

                // Exchange money
                Location.StoreCurrentBalance -= itemValue;
                campaign.Money += itemValue;

                // Remove from the sell crate
                if (ItemsInSellCrate.Find(pi => pi.ItemPrefab == item.ItemPrefab) is { } itemToSell)
                {
                    itemToSell.Quantity -= item.Quantity;
                    if (itemToSell.Quantity < 1)
                    {
                        ItemsInSellCrate.Remove(itemToSell);
                    }
                }
            }

            OnSoldItemsChanged?.Invoke();
        }