Exemple #1
0
        public void OnChangedBlock(ModLoader.OnTryChangeBlockData tryChangeBlockData)
        {
            var colony = tryChangeBlockData?.RequestOrigin.AsPlayer?.ActiveColony;

            if (colony == null)
            {
                colony = tryChangeBlockData.RequestOrigin.AsColony;
            }

            if (colony != null &&
                (StorageBlockTypes.ContainsKey(tryChangeBlockData.TypeNew.Name) ||
                 StorageBlockTypes.ContainsKey(tryChangeBlockData.TypeOld.Name)))
            {
                RecalcStockpileMaxSize(colony);
                return;
            }

            if (colony != null && CrateTypes.TryGetValue(tryChangeBlockData.TypeOld.Name, out var oldCrate))
            {
                /// empty the crate. TODO may want to do something other than magically teleporting.
                if (CrateLocations[colony].TryGetValue(tryChangeBlockData.Position, out var inv))
                {
                    StoreItems(colony, inv.GetAllItems().Values);
                }

                CrateLocations[colony].Remove(tryChangeBlockData.Position);

                foreach (var item in ItemCrateLocations[colony])
                {
                    item.Value.Remove(tryChangeBlockData.Position);
                }
            }
            else if (CrateTypes.TryGetValue(tryChangeBlockData.TypeNew.Name, out var newCrate))
            {
                if (!CrateLocations.ContainsKey(colony))
                {
                    CrateLocations.Add(colony, new Dictionary <Vector3Int, CrateInventory>());
                }

                CrateLocations[colony][tryChangeBlockData.Position] = new CrateInventory(newCrate, tryChangeBlockData.Position, colony);
            }
        }
Exemple #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)
                        }));
                    }
                }
            }
        }
Exemple #3
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);
                }
            }
        }
        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;
            }
        }