Beispiel #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);
                }
            }
        }
Beispiel #2
0
        static void ConstructTooltip(Players.Player player, ConstructTooltipUIData data)
        {
            ItemTypes.ItemType item = BuiltinBlocks.Types.air;

            if (data.hoverType == Shared.ETooltipHoverType.Item && !ItemTypes.TryGetType(data.hoverItem, out item))
            {
                return;
            }
            else if (data.hoverType == Shared.ETooltipHoverType.PlayerRecipe && !ItemTypes.TryGetType(data.hoverItem, out item))
            {
                return;
            }
            else if (data.hoverType == Shared.ETooltipHoverType.NPCRecipe && !ItemTypes.TryGetType(data.hoverItem, out item))
            {
                return;
            }
            else if (data.hoverType == Shared.ETooltipHoverType.Science && !ItemTypes.TryGetType(data.hoverKey, out item))
            {
                return;
            }
            else if (data.hoverType == Shared.ETooltipHoverType.ScienceCondition && !ItemTypes.TryGetType(data.hoverKey, out item))
            {
                return;
            }
            else if (data.hoverType == Shared.ETooltipHoverType.ScienceUnlock && !ItemTypes.TryGetType(data.hoverKey, out item))
            {
                return;
            }

            if (item == BuiltinBlocks.Types.air)
            {
                return;
            }

            if (player.ActiveColony != null && StockpileMaxStackSize.TryGetValue(player.ActiveColony, out var itemDic) && itemDic.TryGetValue(item.ItemIndex, out var maxSize))
            {
                data.menu.Items.Add(new HorizontalRow(new List <(IItem, int)>()
                {
                    (new Label(new LabelData(GameSetup.GetNamespace("Storage.MaxStackSize"))), 200),
                    (new Label(new LabelData(maxSize.ToString())), 60)
                }));
            }

            if (CrateTypes.TryGetValue(item.Name, out var crate))
            {
                data.menu.Items.Add(new HorizontalRow(new List <(IItem, int)>()
                {
                    (new Label(new LabelData(GameSetup.GetNamespace("Storage.MaxCrateStackSize"))), 200),
                    (new Label(new LabelData(crate.MaxCrateStackSize.ToString())), 60)
                }));
                data.menu.Items.Add(new HorizontalRow(new List <(IItem, int)>()
                {
                    (new Label(new LabelData(GameSetup.GetNamespace("Storage.MaxNumberOfStacks"))), 200),
                    (new Label(new LabelData(crate.MaxNumberOfStacks.ToString())), 60)
                }));
            }

            if (StorageBlockTypes.TryGetValue(item.Name, out var upgrade))
            {
                data.menu.Items.Add(new HorizontalRow(new List <(IItem, int)>()
                {
                    (new Label(new LabelData(GameSetup.GetNamespace("Storage.GlobalStorageUpgrade"))), 200),
                    (new Label(new LabelData(upgrade.GlobalStorageUpgrade.ToString())), 60)
                }));


                if (upgrade.CategoryStorageUpgrades.Count > 0)
                {
                    data.menu.Items.Add(new EmptySpace(5));
                    data.menu.Items.Add(new Label(new LabelData(GameSetup.GetNamespace("Storage.CategoryStoreUpgrades"), ELabelAlignment.MiddleCenter, 18)));
                    data.menu.Items.Add(new Line(UnityEngine.Color.white, 3));
                    foreach (var csu in upgrade.CategoryStorageUpgrades)
                    {
                        data.menu.Items.Add(new HorizontalRow(new List <(IItem, int)>()
                        {
                            (new Label(new LabelData(csu.Key)), 200),
                            (new Label(new LabelData(csu.Value.ToString())), 60)
                        }));
                    }
                }

                if (upgrade.ItemStorageUpgrades.Count > 0)
                {
                    data.menu.Items.Add(new EmptySpace(5));
                    data.menu.Items.Add(new Label(new LabelData(GameSetup.GetNamespace("Storage.ItemStoreUpgrades"), ELabelAlignment.MiddleCenter, 18)));
                    data.menu.Items.Add(new Line(UnityEngine.Color.white, 3));
                    foreach (var csu in upgrade.ItemStorageUpgrades)
                    {
                        data.menu.Items.Add(new HorizontalRow(new List <(IItem, int)>()
                        {
                            (new Label(new LabelData(csu.Key, ELabelAlignment.Default, 16, LabelData.ELocalizationType.Type)), 200),
                            (new Label(new LabelData(csu.Value.ToString())), 60)
                        }));
                    }
                }
            }
        }
        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;
            }
        }