예제 #1
0
        public static void RecalcStockpileMaxSize(Colony colony)
        {
            var pos = GetStockpilePosition(colony);
            var blocksAroundStockpile = WorldHelper.GetBlocksInArea(pos.Min, pos.Max);
            int total = 0;
            Dictionary <string, int> byCategory = new Dictionary <string, int>();
            Dictionary <string, int> byType     = new Dictionary <string, int>();

            foreach (var blockType in blocksAroundStockpile.Values)
            {
                if (StorageBlockTypes.TryGetValue(blockType.Name, out var storageUpgradeBlock))
                {
                    total += storageUpgradeBlock.GlobalStorageUpgrade;

                    if (storageUpgradeBlock.CategoryStorageUpgrades != null)
                    {
                        foreach (var kvp in storageUpgradeBlock.CategoryStorageUpgrades)
                        {
                            if (!byCategory.ContainsKey(kvp.Key))
                            {
                                byCategory.Add(kvp.Key, 0);
                            }

                            byCategory[kvp.Key] = byCategory[kvp.Key] + kvp.Value;
                        }
                    }

                    if (storageUpgradeBlock.ItemStorageUpgrades != null)
                    {
                        foreach (var kvp in storageUpgradeBlock.ItemStorageUpgrades)
                        {
                            if (!byType.ContainsKey(kvp.Key))
                            {
                                byType.Add(kvp.Key, 0);
                            }

                            byType[kvp.Key] = byType[kvp.Key] + kvp.Value;
                        }
                    }
                }
            }

            if (!StockpileMaxStackSize.ContainsKey(colony))
            {
                StockpileMaxStackSize[colony] = new Dictionary <ushort, int>();
            }

            if (total == 0)
            {
                total = StorageBlockTypes[StockpileBlock.Name].GlobalStorageUpgrade;
            }

            float stacksTotal = 0;

            foreach (var item in ItemTypes._TypeByUShort.Values)
            {
                var totalStack = total;
                DefaultMax[colony] = total;

                if (item.Categories != null)
                {
                    foreach (var cat in item.Categories)
                    {
                        if (byCategory.TryGetValue(cat, out int catTotal))
                        {
                            totalStack += catTotal;
                        }
                    }
                }

                if (byType.TryGetValue(item.Name, out int itemTotal))
                {
                    totalStack += itemTotal;
                }

                StockpileMaxStackSize[colony][item.ItemIndex] = totalStack;

                var count = colony.Stockpile.AmountContained(item.ItemIndex);

                if (count > 0)
                {
                    stacksTotal += count;
                }
            }

            var maxItems = colony.Stockpile.ItemCount * total;
            var fillPct  = System.Math.Round(stacksTotal / maxItems, 2) * 100;

            foreach (var player in colony.Owners)
            {
                if (player.ActiveColony == colony)
                {
                    UIManager.AddorUpdateUIImage("ColonyStockpile" + colony.ColonyID, colonyshared.NetworkUI.UIGeneration.UIElementDisplayType.Colony, "StockpileBackground", new Vector3Int(135, -119, 0), colonyshared.NetworkUI.AnchorPresets.TopLeft, player);
                    UIManager.AddorUpdateUILabel("ColonyStockpile" + colony.ColonyID, colonyshared.NetworkUI.UIGeneration.UIElementDisplayType.Colony, LocalizationHelper.LocalizeOrDefault("StockpileSize", player, total.ToKMB(), fillPct.ToString()), new Vector3Int(137, -119, 0), colonyshared.NetworkUI.AnchorPresets.TopLeft, 270, player, 14);
                }
            }
        }
예제 #2
0
        private static void RecalcMax(Colony colony)
        {
            var pos = GetStockpilePosition(colony);
            var blocksAroundStockpile = WorldHelper.GetBlocksInArea(pos.Min, pos.Max);
            int total = 0;
            Dictionary <string, int> byCategory = new Dictionary <string, int>();
            Dictionary <string, int> byType     = new Dictionary <string, int>();

            foreach (var blockType in blocksAroundStockpile.Values)
            {
                if (StorageBlockTypes.TryGetValue(blockType.Name, out var storageUpgradeBlock))
                {
                    total += storageUpgradeBlock.GlobalStorageUpgrade;

                    if (storageUpgradeBlock.CategoryStorageUpgrades != null)
                    {
                        foreach (var kvp in storageUpgradeBlock.CategoryStorageUpgrades)
                        {
                            if (!byCategory.ContainsKey(kvp.Key))
                            {
                                byCategory.Add(kvp.Key, 0);
                            }

                            byCategory[kvp.Key] = byCategory[kvp.Key] + kvp.Value;
                        }
                    }

                    if (storageUpgradeBlock.ItemStorageUpgrades != null)
                    {
                        foreach (var kvp in storageUpgradeBlock.ItemStorageUpgrades)
                        {
                            if (!byType.ContainsKey(kvp.Key))
                            {
                                byType.Add(kvp.Key, 0);
                            }

                            byType[kvp.Key] = byType[kvp.Key] + kvp.Value;
                        }
                    }
                }
            }

            if (!StockpileMaxStackSize.ContainsKey(colony))
            {
                StockpileMaxStackSize[colony] = new Dictionary <ushort, int>();
            }

            foreach (var item in ItemTypes._TypeByUShort.Values)
            {
                var totalStack = total;
                DefaultMax[colony] = total;

                if (item.Categories != null)
                {
                    foreach (var cat in item.Categories)
                    {
                        if (byCategory.TryGetValue(cat, out int catTotal))
                        {
                            totalStack += catTotal;
                        }
                    }
                }

                if (byType.TryGetValue(item.Name, out int itemTotal))
                {
                    totalStack += itemTotal;
                }

                StockpileMaxStackSize[colony][item.ItemIndex] = totalStack;
            }
        }