public MinerJobInstance(IBlockJobSettings settings, Vector3Int position, ItemTypes.ItemType type, ByteReader reader) : base(settings, position, type, reader)
        {
            ushort belowType = reader.ReadVariableUShort();

            MiningCooldown = -1f;
            if (ItemTypes.TryGetType(belowType, out ItemTypes.ItemType foundtype))
            {
                BlockTypeBelow = foundtype;
            }
        }
        public static bool TryGetItem(this Dictionary <string, ushort> itemInedex, string itemName, out ItemTypes.ItemType itemType)
        {
            itemType = null;

            if (itemInedex.TryGetValue(itemName, out ushort itemId) && ItemTypes.TryGetType(itemId, out itemType))
            {
                return(true);
            }

            return(false);
        }
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d)
        {
            if (d.RequestOrigin.AsPlayer == null ||
                d.RequestOrigin.AsPlayer.ID.type == NetworkID.IDType.Server ||
                d.RequestOrigin.AsPlayer.ID.type == NetworkID.IDType.Invalid)
            {
                return;
            }

            var ps = PlayerState.GetPlayerState(d.RequestOrigin.AsPlayer);

            if (ps != null)
            {
                if (d.TypeNew.ItemIndex != ColonyBuiltIn.ItemTypes.AIR.Id && ItemTypes.TryGetType(d.TypeNew.ItemIndex, out var item))
                {
                    ushort itemId = GetParentId(d.TypeNew.ItemIndex, item);

                    if (!ps.ItemsPlaced.ContainsKey(itemId))
                    {
                        ps.ItemsPlaced.Add(itemId, 0);
                    }

                    if (!ps.ItemsInWorld.ContainsKey(itemId))
                    {
                        ps.ItemsInWorld.Add(itemId, 0);
                    }

                    ps.ItemsPlaced[itemId]++;
                    ps.ItemsInWorld[itemId]++;
                }

                if (d.TypeNew.ItemIndex == ColonyBuiltIn.ItemTypes.AIR.Id && d.TypeOld.ItemIndex != ColonyBuiltIn.ItemTypes.AIR.Id && ItemTypes.TryGetType(d.TypeOld.ItemIndex, out var itemOld))
                {
                    ushort itemId = GetParentId(d.TypeOld.ItemIndex, itemOld);

                    if (!ps.ItemsRemoved.ContainsKey(itemId))
                    {
                        ps.ItemsRemoved.Add(itemId, 0);
                    }

                    if (!ps.ItemsInWorld.ContainsKey(itemId))
                    {
                        ps.ItemsInWorld.Add(itemId, 0);
                    }
                    else
                    {
                        ps.ItemsInWorld[itemId]--;
                    }

                    ps.ItemsRemoved[itemId]++;
                }
            }
        }
Beispiel #4
0
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData userData)
        {
            if (userData.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled)
            {
                return;
            }

            if (userData.TypeNew == BuiltinBlocks.Dirt)
            {
                if (ItemTypes.TryGetType(userData.TypeOld, out ItemTypes.ItemType itemtype))
                {
                    if (itemtype.IsFertile && itemtype.CustomDataNode.TryGetAs <float>("fertilizervalue", out float result))
                    {
                        userData.TypeNew = userData.TypeOld;
                    }
                }
            }

            if (userData.CallbackOrigin == ModLoader.OnTryChangeBlockData.ECallbackOrigin.ClientPlayerManual)
            {
                VoxelSide side    = userData.PlayerClickedData.VoxelSideHit;
                ushort    newType = userData.TypeNew;
                string    suffix  = "bottom";

                switch (side)
                {
                case VoxelSide.yPlus:
                    suffix = "bottom";
                    break;

                case VoxelSide.yMin:
                    suffix = "top";
                    break;
                }

                if (newType != userData.TypeOld && ItemTypes.IndexLookup.TryGetName(newType, out string typename))
                {
                    string otherTypename = typename + suffix;

                    if (ItemTypes.IndexLookup.TryGetIndex(otherTypename, out ushort otherIndex))
                    {
                        Vector3Int position = userData.Position;
                        ThreadManager.InvokeOnMainThread(delegate()
                        {
                            ServerManager.TryChangeBlock(position, otherIndex);
                        }, 0.1f);
                    }
                }
            }
        }
Beispiel #5
0
 public RestResponse GetItemByName(string name)
 {
     if (ItemTypes.TryGetType(name, out ItemTypes.ItemType itemType))
     {
         return(new RestResponse()
         {
             Content = itemType.ToUTF8SerializedJson()
         });
     }
     else
     {
         return(RestResponse.BlankJsonObject);
     }
 }
Beispiel #6
0
 public RestResponse GetItemById(ushort itemId)
 {
     if (ItemTypes.TryGetType(itemId, out ItemTypes.ItemType itemType))
     {
         return(new RestResponse()
         {
             Content = itemType.ToUTF8SerializedJson()
         });
     }
     else
     {
         return(RestResponse.BlankJsonObject);
     }
 }
        public static void OnNPCGathered(IJob job, Vector3Int location, List <ItemTypes.ItemTypeDrops> results)
        {
            if (job != null && job.NPC != null && results != null && results.Count > 0)
            {
                var inv = SettlerInventory.GetSettlerInventory(job.NPC);

                foreach (var item in results)
                {
                    if (ItemTypes.TryGetType(item.Type, out var itemType))
                    {
                        inv.IncrimentStat(itemType.Name, item.Amount);
                    }
                }
            }
        }
Beispiel #8
0
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d)
        {
            if (d.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled)
            {
                return;
            }

            IRoamingJobObjective roamingJobObjective = null;
            Colony colony = null;

            if (d.RequestOrigin.AsPlayer != null &&
                d.RequestOrigin.AsPlayer.ID.type != NetworkID.IDType.Server &&
                d.RequestOrigin.AsPlayer.ID.type != NetworkID.IDType.Invalid &&
                d.RequestOrigin.AsPlayer.ActiveColony != null)
            {
                colony = d.RequestOrigin.AsPlayer.ActiveColony;
            }

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

            if (colony != null)
            {
                if (d.TypeNew.ItemIndex == ColonyBuiltIn.ItemTypes.AIR.Id)
                {
                    RemoveObjective(colony, d.Position);
                }
                else if (ItemTypes.TryGetType(d.TypeNew.ItemIndex, out ItemTypes.ItemType item))
                {
                    if (ObjectiveCallbacks.TryGetValue(item.Name, out roamingJobObjective))
                    {
                        RegisterRoamingJobState(colony, new RoamingJobState(d.Position, colony, roamingJobObjective.ItemIndex, roamingJobObjective));
                    }
                    else if (!string.IsNullOrEmpty(item.ParentType) && ObjectiveCallbacks.TryGetValue(item.ParentType, out roamingJobObjective))
                    {
                        RegisterRoamingJobState(colony, new RoamingJobState(d.Position, colony, roamingJobObjective.ItemIndex, roamingJobObjective));
                    }
                }
            }
        }
        // construct from JSON
        public TrackedItem(JSONNode json)
        {
            ushort type = json.GetAs <ushort>("itemType");

            ItemTypes.TryGetType(type, out this.item);
            this.interval = json.GetAs <ushort>("interval");

            JSONNode jsonAmounts;

            if (json.TryGetAs("values", out jsonAmounts) && jsonAmounts.NodeType == NodeType.Array)
            {
                int i = 0;
                foreach (JSONNode jsonAmount in jsonAmounts.LoopArray())
                {
                    int val = jsonAmount.GetAs <int>();
                    this.itemAmount[i] = val;
                    i++;
                }
            }
        }
Beispiel #10
0
        public static void MonsterDied(IMonster monster)
        {
            var rewardMonster = monster as IKillReward;

            if (rewardMonster != null && rewardMonster.OriginalGoal.IsConnected)
            {
                var stockpile = Stockpile.GetStockPile(rewardMonster.OriginalGoal);

                foreach (var reward in rewardMonster.KillRewards)
                {
                    stockpile.Add(reward.Key, reward.Value);

                    if (ItemTypes.TryGetType(reward.Key, out var item))
                    {
                        PandaChat.Send(rewardMonster.OriginalGoal,
                                       $"You have been awarded {reward.Value}x {item.Name}!", ChatColor.orange);
                    }
                }
            }
        }
Beispiel #11
0
        private static void AddToCount(ModLoader.OnTryChangeBlockData d, Dictionary <ushort, int> ItemsPlaced, Dictionary <ushort, int> ItemsInWorld, Dictionary <ushort, int> ItemsRemoved)
        {
            if (d.TypeNew.ItemIndex != ColonyBuiltIn.ItemTypes.AIR.Id && ItemTypes.TryGetType(d.TypeNew.ItemIndex, out var item))
            {
                ushort itemId = GetParentId(d.TypeNew.ItemIndex, item);

                if (!ItemsPlaced.ContainsKey(itemId))
                {
                    ItemsPlaced.Add(itemId, 0);
                }

                if (!ItemsInWorld.ContainsKey(itemId))
                {
                    ItemsInWorld.Add(itemId, 0);
                }

                ItemsPlaced[itemId]++;
                ItemsInWorld[itemId]++;
            }

            if (d.TypeNew.ItemIndex == ColonyBuiltIn.ItemTypes.AIR.Id && d.TypeOld.ItemIndex != ColonyBuiltIn.ItemTypes.AIR.Id && ItemTypes.TryGetType(d.TypeOld.ItemIndex, out var itemOld))
            {
                ushort itemId = GetParentId(d.TypeOld.ItemIndex, itemOld);

                if (!ItemsRemoved.ContainsKey(itemId))
                {
                    ItemsRemoved.Add(itemId, 0);
                }

                if (!ItemsInWorld.ContainsKey(itemId))
                {
                    ItemsInWorld.Add(itemId, 0);
                }
                else
                {
                    ItemsInWorld[itemId]--;
                }

                ItemsRemoved[itemId]++;
            }
        }
Beispiel #12
0
        //player != null
        private static bool CheckBlock(Players.Player player, ushort block)
        {
            if (0 == block)  //Air block
            {
                return(true);
            }

            if (!ItemTypes.TryGetType(block, out ItemTypes.ItemType type))
            {
                Chatting.Chat.Send(player, "<color=orange>Block not found</color>");
                return(false);
            }

            if (!type.IsPlaceable || type.NeedsBase)
            {
                Chatting.Chat.Send(player, "<color=orange>You can't place this block</color>");
                return(false);
            }

            return(true);
        }
Beispiel #13
0
        public static void OnPlayerClicked(Players.Player player, PlayerClickedData playerClickData)
        {
            if (playerClickData.ClickType == PlayerClickedData.EClickType.Right &&
                playerClickData.HitType == PlayerClickedData.EHitType.Block &&
                ItemTypes.TryGetType(playerClickData.GetVoxelHit().TypeHit, out ItemTypes.ItemType itemHit))
            {
                var baseType = itemHit.GetRootParentType();

                if (baseType.Categories != null &&
                    baseType.Categories.Count != 0 &&
                    baseType.Categories.Contains("door", StringComparer.CurrentCultureIgnoreCase))
                {
                    ushort replacement = ColonyBuiltIn.ItemTypes.AIR;

                    if (itemHit.Name == baseType.RotatedXMinus)
                    {
                        replacement = ItemId.GetItemId(baseType.RotatedZMinus);
                    }
                    else if (itemHit.Name == baseType.RotatedZMinus)
                    {
                        replacement = ItemId.GetItemId(baseType.RotatedXMinus);
                    }
                    else if (itemHit.Name == baseType.RotatedXPlus)
                    {
                        replacement = ItemId.GetItemId(baseType.RotatedZPlus);
                    }
                    else if (itemHit.Name == baseType.RotatedZPlus)
                    {
                        replacement = ItemId.GetItemId(baseType.RotatedXPlus);
                    }

                    if (replacement != ColonyBuiltIn.ItemTypes.AIR)
                    {
                        ServerManager.TryChangeBlock(playerClickData.GetVoxelHit().BlockHit, replacement, new BlockChangeRequestOrigin(player));
                    }
                }
            }
        }
Beispiel #14
0
        static void ConstructTooltip(ConstructTooltipUIData data)
        {
            if (data.hoverType != Shared.ETooltipHoverType.Item ||
                data.player.ID.type == NetworkID.IDType.Server ||
                data.player.ID.type == NetworkID.IDType.Invalid ||
                !ItemTypes.TryGetType(data.hoverItem, out var item))
            {
                return;
            }

            var ps = PlayerState.GetPlayerState(data.player);
            var cs = ColonyState.GetColonyState(ps.Player.ActiveColony);

            if (ps != null)
            {
                if (item.IsPlaceable)
                {
                    ushort itemId = GetParentId(data.hoverItem, item);

                    BuildPlaceableMenu(data, itemId, ps.ItemsPlaced, "PlayerNumberPlaced");
                    BuildPlaceableMenu(data, itemId, ps.ItemsRemoved, "PlayerNumberRemoved");
                    BuildPlaceableMenu(data, itemId, ps.ItemsInWorld, "PlayerNumberInWorld");
                }
            }

            if (cs != null)
            {
                if (item.IsPlaceable)
                {
                    ushort itemId = GetParentId(data.hoverItem, item);

                    BuildPlaceableMenu(data, itemId, cs.ItemsPlaced, "ColonyNumberPlaced");
                    BuildPlaceableMenu(data, itemId, cs.ItemsRemoved, "ColonyNumberRemoved");
                    BuildPlaceableMenu(data, itemId, cs.ItemsInWorld, "ColonyNumberInWorld");
                }
            }
        }
Beispiel #15
0
        private static void ScrubColony(Colony c)
        {
            List <ushort> notFound = new List <ushort>();

            foreach (var item in c.Stockpile.Items)
            {
                if (ItemTypes.TryGetType(item.Key, out var itemType))
                {
                    if (!string.IsNullOrEmpty(itemType.ParentType) && itemType.ParentType == "missingerror")
                    {
                        notFound.Add(item.Key);
                    }
                }
                else
                {
                    notFound.Add(item.Key);
                }
            }

            foreach (var i in notFound)
            {
                c.Stockpile.Items.Remove(i);
            }
        }
        public static void OnNPCRecruited(NPCBase npc)
        {
            try
            {
                if (npc.CustomData == null)
                {
                    npc.CustomData = new JSONNode();
                }

                if (npc.CustomData.TryGetAs(ISSETTLER, out bool settler) && settler)
                {
                    return;
                }

                var ps = ColonyState.GetColonyState(npc.Colony);

                if (ps.SettlersEnabled)
                {
                    if (Configuration.GetorDefault("ColonistsRecruitment", true))
                    {
                        if (ps.SettlersEnabled && npc.Colony.FollowerCount > MAX_BUYABLE)
                        {
                            var cost = Configuration.GetorDefault("CompoundingFoodRecruitmentCost", 2) * ps.ColonistsBought;
                            var num  = 0f;

                            if (cost < 1)
                            {
                                cost = 1;
                            }

                            if (npc.Colony.Stockpile.TotalFood < cost ||
                                !npc.Colony.Stockpile.TryRemoveFood(ref num, cost))
                            {
                                PandaChat.Send(npc.Colony, $"Could not recruit a new colonist; not enough food in stockpile. {cost + ServerManager.ServerSettings.NPCs.RecruitmentCost} food required.", ChatColor.red);
                                npc.Colony.HappinessData.RecruitmentCostCalculator.GetCost(npc.Colony.HappinessData.CachedHappiness, npc.Colony, out float foodCost);

                                if (ItemTypes.TryGetType(ColonyBuiltIn.ItemTypes.BREAD.Name, out var bread))
                                {
                                    npc.Colony.Stockpile.Add(ColonyBuiltIn.ItemTypes.BREAD, (int)Math.Floor(foodCost / bread.FoodValue));
                                }

                                npc.health = 0;
                                npc.Update();
                                return;
                            }

                            ps.ColonistsBought++;
                            ps.NextColonistBuyTime = TimeCycle.TotalTime.Value.Hours + 24;
                        }

                        SettlerInventory.GetSettlerInventory(npc);
                        UpdateFoodUse(ps);
                    }
                    else
                    {
                        PandaChat.Send(npc.Colony, "The server administrator has disabled recruitment of colonists while settlers are enabled.");
                    }
                }
            }
            catch (Exception ex)
            {
                PandaLogger.LogError(ex);
            }
        }
Beispiel #17
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)
                        }));
                    }
                }
            }
        }
        public static void PressButton(ButtonPressCallbackData data)
        {
            if (data.ButtonIdentifier.Contains(GameLoader.NAMESPACE + ".PlayerDetails"))
            {
                BuildPlayerDetailsMenu(data);
                return;
            }
            else if (data.ButtonIdentifier.Contains(".AddPlayerEquiptmentButton"))
            {
                NetworkMenu menu = new NetworkMenu();
                menu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault("PlayerEquiptment", data.Player));
                menu.Width  = 1000;
                menu.Height = 600;

                if (data.ButtonIdentifier.Contains("MagicItem."))
                {
                    var id = data.ButtonIdentifier.Replace("AddPlayerEquiptmentButton", "");

                    foreach (var kvp in data.Player.ActiveColony.Stockpile.Items)
                    {
                        if (kvp.Value > 0 &&
                            ItemTypes.TryGetType(kvp.Key, out var itemType) &&
                            MagicItemsCache.PlayerMagicItems.TryGetValue(itemType.Name, out var magicItem) &&
                            !Armor.ArmorFactory.ArmorLookup.ContainsKey(kvp.Key) &&
                            !Weapons.WeaponFactory.WeaponLookup.ContainsKey(kvp.Key))
                        {
                            List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                            items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(kvp.Key), 250));
                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(magicItem.name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 250));
                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Stockpile", data.Player) + ": " + kvp.Value.ToString(), UnityEngine.Color.black)), 250));
                            items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(id + kvp.Key + ".AddPlayerSelectedEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Select"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 250));
                            menu.Items.Add(new HorizontalRow(items));
                        }
                    }
                }
                else
                {
                    foreach (var kvp in data.Player.ActiveColony.Stockpile.Items)
                    {
                        if (kvp.Value > 0 && Armor.ArmorFactory.ArmorLookup.TryGetValue(kvp.Key, out var armItem) && data.ButtonIdentifier.Contains(armItem.Slot + "."))
                        {
                            List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                            items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(kvp.Key), 250));
                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(armItem.name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 250));
                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Stockpile", data.Player) + ": " + kvp.Value.ToString(), UnityEngine.Color.black)), 250));
                            items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(kvp.Key + ".AddPlayerSelectedEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Select"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 250));
                            menu.Items.Add(new HorizontalRow(items));
                        }
                    }
                }

                NetworkMenuManager.SendServerPopup(data.Player, menu);
            }
            else if (data.ButtonIdentifier.Contains(".AddPlayerSelectedEquiptmentButton"))
            {
                if (data.ButtonIdentifier.Contains("MagicItem."))
                {
                    var startPos = data.ButtonIdentifier.Replace("MagicItem.", "");

                    if (int.TryParse(startPos.Substring(0, startPos.IndexOf('.')), out var slot))
                    {
                        var itemId = startPos.Substring(startPos.IndexOf('.') + 1, startPos.LastIndexOf(".") - 2);

                        if (ushort.TryParse(itemId, out var id))
                        {
                            var item = ItemId.GetItemId(id);

                            if (MagicItemsCache.PlayerMagicItems.TryGetValue(item.Name, out var magicItem) && data.Player.ActiveColony.Stockpile.TryRemove(id))
                            {
                                var ps = PlayerState.GetPlayerState(data.Player);
                                ps.MagicItems[slot] = magicItem;
                                ps.RecaclculateMagicItems();
                            }
                        }
                    }

                    BuildPlayerDetailsMenu(data);
                    return;
                }
                else
                {
                    foreach (var kvp in data.Player.ActiveColony.Stockpile.Items)
                    {
                        if (Armor.ArmorFactory.ArmorLookup.TryGetValue(kvp.Key, out var armItem) &&
                            data.ButtonIdentifier.Contains(kvp.Key + ".") &&
                            data.Player.ActiveColony.Stockpile.TryRemove(kvp.Key))
                        {
                            var ps = PlayerState.GetPlayerState(data.Player);

                            if (ps.Armor[armItem.Slot].Id != default(ushort))
                            {
                                data.Player.ActiveColony.Stockpile.Add(ps.Armor[armItem.Slot].Id);
                            }

                            ps.Armor[armItem.Slot].Id         = kvp.Key;
                            ps.Armor[armItem.Slot].Durability = armItem.Durability;
                            ps.RecaclculateMagicItems();
                            BuildPlayerDetailsMenu(data);
                            return;
                        }
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".RemovePlayerEquiptmentButton"))
            {
                var ps = PlayerState.GetPlayerState(data.Player);

                if (data.ButtonIdentifier.Contains("MagicItem."))
                {
                    if (int.TryParse(data.ButtonIdentifier.Replace("MagicItem.", "").Replace(".RemovePlayerEquiptmentButton", ""), out var id))
                    {
                        data.Player.ActiveColony.Stockpile.Add(ItemId.GetItemId(ps.MagicItems[id].name));
                        ps.MagicItems[id] = null;
                    }
                }
                else
                {
                    foreach (var armor in ps.Armor)
                    {
                        if (data.ButtonIdentifier.Contains(armor.Key + "."))
                        {
                            if (armor.Value.Id != default(ushort))
                            {
                                data.Player.ActiveColony.Stockpile.Add(armor.Value.Id);
                            }

                            armor.Value.Id         = default(ushort);
                            armor.Value.Durability = default(int);
                            break;
                        }
                    }
                }

                ps.RecaclculateMagicItems();
                BuildPlayerDetailsMenu(data);
            }
            else if (data.ButtonIdentifier.Contains(".JobDetailsButton"))
            {
                Dictionary <string, JobCounts> jobCounts = ColonyTool.GetJobCounts(data.Player.ActiveColony);

                foreach (var jobKvp in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(jobKvp.Key))
                    {
                        NetworkMenu menu = new NetworkMenu();
                        menu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault(jobKvp.Key.Replace(" ", ""), data.Player) + " " + _localizationHelper.LocalizeOrDefault("JobDetails", data.Player));
                        menu.Width  = 1000;
                        menu.Height = 600;

                        var firstGuy = jobKvp.Value.TakenJobs.FirstOrDefault();
                        var firstInv = Entities.SettlerInventory.GetSettlerInventory(firstGuy.NPC);
                        List <ValueTuple <IItem, int> > headerItems = new List <ValueTuple <IItem, int> >();

                        headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Name"), UnityEngine.Color.black)), 100));
                        headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Weapon"), UnityEngine.Color.black)), 100));

                        foreach (var a in firstInv.Armor)
                        {
                            headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey(a.Key.ToString()), UnityEngine.Color.black)), 100));
                        }

                        menu.Items.Add(new HorizontalRow(headerItems));

                        foreach (var job in jobKvp.Value.TakenJobs)
                        {
                            var inv = Entities.SettlerInventory.GetSettlerInventory(job.NPC);
                            List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(inv.SettlerName, UnityEngine.Color.black)), 100));
                            items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(inv.Weapon.Id), 100));

                            foreach (var armor in inv.Armor)
                            {
                                items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(armor.Value.Id), 100));
                            }

                            items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + "." + job.NPC.ID + ".EquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Details"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 100));
                            menu.Items.Add(new HorizontalRow(items));
                        }

                        menu.Items.Add(new Line());
                        menu.Items.Add(new ButtonCallback(GameLoader.NAMESPACE + ".ColonyToolMainMenu", new LabelData(_localizationHelper.GetLocalizationKey("Back"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)));

                        NetworkMenuManager.SendServerPopup(data.Player, menu);
                        return;
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".EquiptmentButton"))
            {
                Dictionary <string, JobCounts> jobCounts = ColonyTool.GetJobCounts(data.Player.ActiveColony);

                foreach (var jobKvp in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(jobKvp.Key))
                    {
                        foreach (var job in jobKvp.Value.TakenJobs)
                        {
                            if (data.ButtonIdentifier.Contains("." + job.NPC.ID.ToString() + ".EquiptmentButton"))
                            {
                                BuildSettlerDetailMenu(data, jobKvp, job);
                                return;
                            }
                        }
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".AddEquiptmentButton"))
            {
                Dictionary <string, JobCounts> jobCounts = ColonyTool.GetJobCounts(data.Player.ActiveColony);

                foreach (var jobKvp in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(jobKvp.Key))
                    {
                        foreach (var job in jobKvp.Value.TakenJobs)
                        {
                            if (data.ButtonIdentifier.Contains("." + job.NPC.ID.ToString() + "."))
                            {
                                var         inv  = Entities.SettlerInventory.GetSettlerInventory(job.NPC);
                                NetworkMenu menu = new NetworkMenu();
                                menu.LocalStorage.SetAs("header", inv.SettlerName + " " + _localizationHelper.LocalizeOrDefault("Equiptment", data.Player));
                                menu.Width  = 1000;
                                menu.Height = 600;
                                var newButtonID = data.ButtonIdentifier.Replace(".AddEquiptmentButton", "");

                                if (data.ButtonIdentifier.Contains(".wep."))
                                {
                                    foreach (var kvp in data.Player.ActiveColony.Stockpile.Items)
                                    {
                                        if (kvp.Value > 0 && Weapons.WeaponFactory.WeaponLookup.TryGetValue(kvp.Key, out var wepItem))
                                        {
                                            List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                                            items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(kvp.Key), 250));
                                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(wepItem.name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 250));
                                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Stockpile", data.Player) + ": " + kvp.Value.ToString(), UnityEngine.Color.black)), 250));
                                            items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(newButtonID + "." + kvp.Key + ".AddSelectedEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Select"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 250));
                                            menu.Items.Add(new HorizontalRow(items));
                                        }
                                    }
                                }
                                else if (data.ButtonIdentifier.Contains(".arm."))
                                {
                                    foreach (var kvp in data.Player.ActiveColony.Stockpile.Items)
                                    {
                                        if (kvp.Value > 0 && Armor.ArmorFactory.ArmorLookup.TryGetValue(kvp.Key, out var armItem) && data.ButtonIdentifier.Contains("." + armItem.Slot + "."))
                                        {
                                            List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                                            items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(kvp.Key), 250));
                                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(armItem.name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 250));
                                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Stockpile", data.Player) + ": " + kvp.Value.ToString(), UnityEngine.Color.black)), 250));
                                            items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(newButtonID + "." + kvp.Key + ".AddSelectedEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Select"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 250));
                                            menu.Items.Add(new HorizontalRow(items));
                                        }
                                    }
                                }

                                NetworkMenuManager.SendServerPopup(data.Player, menu);
                                return;
                            }
                        }
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".AddSelectedEquiptmentButton"))
            {
                Dictionary <string, JobCounts> jobCounts = ColonyTool.GetJobCounts(data.Player.ActiveColony);

                foreach (var jobKvp in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(jobKvp.Key))
                    {
                        foreach (var job in jobKvp.Value.TakenJobs)
                        {
                            if (data.ButtonIdentifier.Contains("." + job.NPC.ID.ToString() + "."))
                            {
                                if (data.ButtonIdentifier.Contains(".wep."))
                                {
                                    foreach (var kvp in data.Player.ActiveColony.Stockpile.Items)
                                    {
                                        if (Weapons.WeaponFactory.WeaponLookup.TryGetValue(kvp.Key, out var wepItem) &&
                                            data.ButtonIdentifier.Contains("." + kvp.Key + ".") &&
                                            job.NPC.Colony.Stockpile.TryRemove(kvp.Key))
                                        {
                                            var inv = Entities.SettlerInventory.GetSettlerInventory(job.NPC);

                                            if (inv.Weapon.Id != default(ushort))
                                            {
                                                job.NPC.Colony.Stockpile.Add(inv.Weapon.Id);
                                            }

                                            inv.Weapon.Id         = kvp.Key;
                                            inv.Weapon.Durability = wepItem.WepDurability;
                                            BuildSettlerDetailMenu(data, jobKvp, job);
                                            return;
                                        }
                                    }
                                }
                                else if (data.ButtonIdentifier.Contains(".arm."))
                                {
                                    foreach (var kvp in data.Player.ActiveColony.Stockpile.Items)
                                    {
                                        if (Armor.ArmorFactory.ArmorLookup.TryGetValue(kvp.Key, out var armItem) &&
                                            data.ButtonIdentifier.Contains("." + kvp.Key + ".") &&
                                            job.NPC.Colony.Stockpile.TryRemove(kvp.Key))
                                        {
                                            var inv = Entities.SettlerInventory.GetSettlerInventory(job.NPC);

                                            if (inv.Armor[armItem.Slot].Id != default(ushort))
                                            {
                                                job.NPC.Colony.Stockpile.Add(inv.Armor[armItem.Slot].Id);
                                            }

                                            inv.Armor[armItem.Slot].Id         = kvp.Key;
                                            inv.Armor[armItem.Slot].Durability = armItem.Durability;
                                            BuildSettlerDetailMenu(data, jobKvp, job);
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".RemoveEquiptmentButton"))
            {
                Dictionary <string, JobCounts> jobCounts = ColonyTool.GetJobCounts(data.Player.ActiveColony);

                foreach (var jobKvp in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(jobKvp.Key))
                    {
                        foreach (var job in jobKvp.Value.TakenJobs)
                        {
                            if (data.ButtonIdentifier.Contains("." + job.NPC.ID.ToString() + ".EquiptmentButton"))
                            {
                                var inv = Entities.SettlerInventory.GetSettlerInventory(job.NPC);

                                if (data.ButtonIdentifier.Contains(".wep."))
                                {
                                    if (inv.Weapon.Id != default(ushort))
                                    {
                                        job.NPC.Colony.Stockpile.Add(inv.Weapon.Id);
                                    }

                                    inv.Weapon.Id         = default(ushort);
                                    inv.Weapon.Durability = default(int);
                                }
                                else if (data.ButtonIdentifier.Contains(".arm."))
                                {
                                    foreach (var armor in inv.Armor)
                                    {
                                        if (data.ButtonIdentifier.Contains("." + armor.Key + "."))
                                        {
                                            if (armor.Value.Id != default(ushort))
                                            {
                                                job.NPC.Colony.Stockpile.Add(armor.Value.Id);
                                            }

                                            armor.Value.Id         = default(ushort);
                                            armor.Value.Durability = default(int);
                                            break;
                                        }
                                    }
                                }

                                BuildSettlerDetailMenu(data, jobKvp, job);
                                return;
                            }
                        }
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".ColonyToolMainMenu"))
            {
                Dictionary <string, JobCounts> jobCounts = ColonyTool.GetJobCounts(data.Player.ActiveColony);
                NetworkMenuManager.SendServerPopup(data.Player, ColonyTool.BuildMenu(data.Player, jobCounts, false, string.Empty, 0));
            }
        }
 public static void OnNPCGathered(IJob job, Vector3Int location, List <ItemTypes.ItemTypeDrops> results)
 {
     //try
     //{
     if (job.NPCType.Equals(Server.NPCs.NPCType.GetByKeyNameOrDefault("pipliz.wheatfarmer")))
     {
         Vector3Int position = location.Add(0, -1, 0);
         if (World.TryGetTypeAt(position, out ushort index) &&
             ItemTypes.TryGetType(index, out ItemTypes.ItemType itemtype) &&
             itemtype.CustomDataNode != null &&
             itemtype.CustomDataNode.TryGetAs <float>("fertilizervalue", out float result))
         {
             results.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.Wheat, 1, result));
         }
         return;
     }
     if (job.NPCType.Equals(Server.NPCs.NPCType.GetByKeyNameOrDefault("pipliz.alkanetfarmer")))
     {
         Vector3Int position = location.Add(0, -1, 0);
         if (World.TryGetTypeAt(position, out ushort index) &&
             ItemTypes.TryGetType(index, out ItemTypes.ItemType itemtype) &&
             itemtype.CustomDataNode != null &&
             itemtype.CustomDataNode.TryGetAs <float>("fertilizervalue", out float result))
         {
             results.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.Alkanet, 1, result));
         }
         return;
     }
     if (job.NPCType.Equals(Server.NPCs.NPCType.GetByKeyNameOrDefault("pipliz.hollyhockfarmer")))
     {
         Vector3Int position = location.Add(0, -1, 0);
         if (World.TryGetTypeAt(position, out ushort index) &&
             ItemTypes.TryGetType(index, out ItemTypes.ItemType itemtype) &&
             itemtype.CustomDataNode != null &&
             itemtype.CustomDataNode.TryGetAs <float>("fertilizervalue", out float result))
         {
             results.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.Hollyhock, 1, result));
         }
         return;
     }
     if (job.NPCType.Equals(Server.NPCs.NPCType.GetByKeyNameOrDefault("pipliz.flaxfarmer")))
     {
         Vector3Int position = location.Add(0, -1, 0);
         if (World.TryGetTypeAt(position, out ushort index) &&
             ItemTypes.TryGetType(index, out ItemTypes.ItemType itemtype) &&
             itemtype.CustomDataNode != null &&
             itemtype.CustomDataNode.TryGetAs <float>("fertilizervalue", out float result))
         {
             results.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.Flax, 1, result));
         }
         return;
     }
     if (job.NPCType.Equals(Server.NPCs.NPCType.GetByKeyNameOrDefault("pipliz.wolfsbanefarm")))
     {
         Vector3Int position = location.Add(0, -1, 0);
         if (World.TryGetTypeAt(position, out ushort index) &&
             ItemTypes.TryGetType(index, out ItemTypes.ItemType itemtype) &&
             itemtype.CustomDataNode != null &&
             itemtype.CustomDataNode.TryGetAs <float>("fertilizervalue", out float result))
         {
             results.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.Wolfsbane, 1, result));
         }
         return;
     }
     //}
     //catch (System.Exception e)
     //{
     //    Logger.Log("{0}.OnNPCGathered had an error : {1}", Fertilizer.MOD_NAMESPACE, e.StackTrace);
     //}
 }
Beispiel #20
0
 public static bool CanMineBlock(ushort itemMined)
 {
     return(ItemTypes.TryGetType(itemMined, out var item) &&
            item.CustomDataNode.TryGetAs("minerIsMineable", out bool minable) &&
            minable);
 }
        public bool PositionIsValid()
        {
            if (Position != null && Position != Vector3Int.invalidPos && World.TryGetTypeAt(Position, out ushort objType) && ItemTypes.TryGetType(objType, out ItemTypes.ItemType item))
            {
                if (objType != RoamingJobSettings.ItemIndex)
                {
                    if (!string.IsNullOrEmpty(item.ParentType))
                    {
                        return(item.ParentItemType.ItemIndex == RoamingJobSettings.ItemIndex);
                    }
                }
                else
                {
                    return(true);
                }
            }


            return(Position != null && Position != Vector3Int.invalidPos);
        }
Beispiel #22
0
        public static void PressButton(ButtonPressCallbackData data)
        {
            switch (data.ButtonIdentifier)
            {
            case GameLoader.NAMESPACE + ".SetScemanticName":
                NetworkMenu saveMenu = new NetworkMenu();
                saveMenu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault("SaveSchematic", data.Player));
                saveMenu.Width            = 600;
                saveMenu.Height           = 300;
                saveMenu.ForceClosePopups = true;
                saveMenu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("SaveInstructions"), UnityEngine.Color.black)));
                saveMenu.Items.Add(new InputField("Construction.SetArchitectArea"));
                saveMenu.Items.Add(new ButtonCallback(GameLoader.NAMESPACE + ".SetArchitectArea", new LabelData(_localizationHelper.GetLocalizationKey("Start"), UnityEngine.Color.black)));

                NetworkMenuManager.SendServerPopup(data.Player, saveMenu);
                break;

            case GameLoader.NAMESPACE + ".SetArchitectArea":
                NetworkMenuManager.CloseServerPopup(data.Player);
                if (data.Storage.TryGetAs("Construction.SetArchitectArea", out string schematicName))
                {
                    var colonySaves = GameLoader.Schematic_SAVE_LOC + $"\\{data.Player.ActiveColony.ColonyID}\\";

                    if (!Directory.Exists(colonySaves))
                    {
                        Directory.CreateDirectory(colonySaves);
                    }

                    var schematicFile = Path.Combine(colonySaves, schematicName + ".schematic");

                    if (File.Exists(schematicFile))
                    {
                        File.Delete(schematicFile);
                    }

                    var metaDataSave = Path.Combine(GameLoader.Schematic_SAVE_LOC, schematicName + ".schematic.metadata.json");

                    if (File.Exists(metaDataSave))
                    {
                        File.Delete(metaDataSave);
                    }

                    AreaJobTracker.StartCommandToolSelection(data.Player, new GenericCommandToolSettings()
                    {
                        Key                 = "pipliz.constructionarea",
                        TranslationKey      = _localizationHelper.LocalizeOrDefault("Architect", data.Player),
                        JSONData            = new JSONNode().SetAs(ArchitectLoader.NAME + ".ArchitectSchematicName", schematicName).SetAs("constructionType", GameLoader.NAMESPACE + ".Architect"),
                        OneAreaOnly         = true,
                        Maximum3DBlockCount = int.MaxValue,
                        Maximum2DBlockCount = int.MaxValue,
                        MaximumHeight       = int.MaxValue,
                        MinimumHeight       = 1,
                        Minimum2DBlockCount = 1,
                        Minimum3DBlockCount = 1
                    });
                }

                break;

            case GameLoader.NAMESPACE + ".ShowMainMenu":
                SendMainMenu(data.Player);
                break;

            case GameLoader.NAMESPACE + ".ShowBuildDetails":
                List <FileInfo> options = SchematicReader.GetSchematics(data.Player);
                var             index   = data.Storage.GetAs <int>(Selected_Schematic);

                if (options.Count > index)
                {
                    var selectedSchematic = options[index];

                    if (SchematicReader.TryGetSchematicMetadata(selectedSchematic.Name, data.Player.ActiveColony.ColonyID, out SchematicMetadata schematicMetadata))
                    {
                        if (schematicMetadata.Blocks.Count == 1 && schematicMetadata.Blocks.ContainsKey(ColonyBuiltIn.ItemTypes.AIR.Id))
                        {
                            PandaChat.Send(data.Player, _localizationHelper, "invlaidSchematic", ChatColor.red);
                        }
                        {
                            NetworkMenu menu = new NetworkMenu();
                            menu.Width  = 800;
                            menu.Height = 600;
                            menu.LocalStorage.SetAs("header", selectedSchematic.Name.Replace(".schematic", "") + " " + _localizationHelper.LocalizeOrDefault("Details", data.Player));

                            menu.Items.Add(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Height", data.Player) + ": " + schematicMetadata.MaxY, UnityEngine.Color.black)));
                            menu.Items.Add(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Width", data.Player) + ": " + schematicMetadata.MaxZ, UnityEngine.Color.black)));
                            menu.Items.Add(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Length", data.Player) + ": " + schematicMetadata.MaxX, UnityEngine.Color.black)));
                            menu.LocalStorage.SetAs(Selected_Schematic, selectedSchematic.Name);

                            List <ValueTuple <IItem, int> > headerItems = new List <ValueTuple <IItem, int> >();
                            headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("  ", UnityEngine.Color.black)), 200));
                            headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Item", data.Player), UnityEngine.Color.black)), 200));
                            headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Required", data.Player), UnityEngine.Color.black)), 200));
                            headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("InStockpile", data.Player), UnityEngine.Color.black)), 200));
                            menu.Items.Add(new HorizontalRow(headerItems));

                            foreach (var kvp in schematicMetadata.Blocks)
                            {
                                try
                                {
                                    if (ItemTypes.TryGetType(kvp.Key, out ItemTypes.ItemType item))
                                    {
                                        var stockpileCount = 0;
                                        data.Player.ActiveColony.Stockpile.Items.TryGetValue(item.ItemIndex, out stockpileCount);

                                        List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                                        items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(kvp.Key), 200));
                                        items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(item.Name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 200));
                                        items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(" x " + kvp.Value.Count, UnityEngine.Color.black)), 200));
                                        items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(" x " + stockpileCount, UnityEngine.Color.black)), 200));
                                        menu.Items.Add(new HorizontalRow(items));
                                    }
                                    else
                                    {
                                        SettlersLogger.Log(ChatColor.orange, "Unknown item for schematic: {0}", kvp.Key);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    SettlersLogger.LogError(ex);
                                }
                            }

                            menu.Items.Add(new DropDown(new LabelData(_localizationHelper.GetLocalizationKey("Rotation"), UnityEngine.Color.black), Selected_Schematic + ".Rotation", _rotation.Select(r => r.ToString()).ToList()));
                            menu.Items.Add(new HorizontalSplit(new ButtonCallback(GameLoader.NAMESPACE + ".ShowMainMenu", new LabelData("Back", UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)),
                                                               new ButtonCallback(GameLoader.NAMESPACE + ".SetBuildArea", new LabelData("Build", UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter))));
                            menu.LocalStorage.SetAs(Selected_Schematic + ".Rotation", 0);

                            NetworkMenuManager.SendServerPopup(data.Player, menu);
                        }
                    }
                }

                break;

            case GameLoader.NAMESPACE + ".SetBuildArea":
                var scem     = data.Storage.GetAs <string>(Selected_Schematic);
                var rotation = data.Storage.GetAs <int>(Selected_Schematic + ".Rotation");

                SettlersLogger.Log("Schematic: {0}", scem);

                if (SchematicReader.TryGetSchematicMetadata(scem, data.Player.ActiveColony.ColonyID, out SchematicMetadata metadata))
                {
                    if (metadata.Blocks.Count == 1 && metadata.Blocks.ContainsKey(ColonyBuiltIn.ItemTypes.AIR.Id))
                    {
                        PandaChat.Send(data.Player, _localizationHelper, "invlaidSchematic", ChatColor.red);
                    }
                    {
                        _awaitingClick[data.Player] = Tuple.Create(SchematicClickType.Build, scem, _rotation[rotation]);
                        PandaChat.Send(data.Player, _localizationHelper, "instructions");
                        NetworkMenuManager.CloseServerPopup(data.Player);
                    }
                }

                break;
            }
        }
Beispiel #23
0
 public static float ItemHydrateValue(ushort itemToCheck)
 {
     ItemTypes.TryGetType(itemToCheck, out var item);
     item.CustomDataNode.TryGetAs("hydrationvalue", out float hydratevalue);
     return(hydratevalue);
 }
Beispiel #24
0
 public static void OnPlayerClicked(Players.Player player, Shared.PlayerClickedData playerClickedData)
 {
     if (player.ActiveColony != null && playerClickedData.HitType == Shared.PlayerClickedData.EHitType.Block && playerClickedData.ConsumedType == Shared.PlayerClickedData.EConsumedType.ChangedBlock && playerClickedData.IsConsumed && ItemTypes.TryGetType(playerClickedData.TypeSelected, out ItemTypes.ItemType block))
     {
         while (block.ParentItemType != null)
         {
             block = block.ParentItemType;
         }
         int blockCount = player.Inventory.GetAmount(block.ItemIndex);
         int looted     = Mathf.Clamp(block.MaxStackSize - blockCount, 0, player.ActiveColony.Stockpile.AmountContained(block.ItemIndex));
         if (blockCount == 1 && looted > 0 && player.ActiveColony.Stockpile.TryRemove(block.ItemIndex, looted))
         {
             player.Inventory.TryAdd(block.ItemIndex, looted);
         }
     }
 }