Exemplo n.º 1
0
        public static void SendMenu(Players.Player player, JSONNode json)
        {
            NetworkMenu menu = new NetworkMenu();

            json.TryGetAsOrDefault("header", out string header, "Title");
            menu.LocalStorage.SetAs("header", header);

            if (json.HasChild("width"))
            {
                menu.Width = json.GetAs <int>("width");
            }
            else
            {
                menu.Width = SettlersConfiguration.GetorDefault("MenuWidth", 1000);
            }

            if (json.HasChild("height"))
            {
                menu.Height = json.GetAs <int>("height");
            }
            else
            {
                menu.Height = SettlersConfiguration.GetorDefault("MenuHeight", 700);
            }

            foreach (JSONNode item in (json.GetAs <JSONNode>("Items")).LoopArray())
            {
                if (LoadItem(item, ref menu, player, out var menuItem))
                {
                    menu.Items.Add(menuItem);
                }
            }

            NetworkMenuManager.SendServerPopup(player, menu);
        }
Exemplo n.º 2
0
        public static void OnPlayerConnectedLate(Players.Player p)
        {
            if (p == null || p.Colonies == null || p.Colonies.Length == 0)
            {
                return;
            }

            if (SettlersConfiguration.GetorDefault("SettlersEnabled", true) &&
                SettlersConfiguration.GetorDefault("MaxSettlersToggle", 4) > 0 &&
                p.ActiveColony != null)
            {
                var cs = ColonyState.GetColonyState(p.ActiveColony);

                if (cs.SettlersEnabled != SettlersState.Disabled && SettlersConfiguration.GetorDefault("ColonistsRecruitment", true))
                {
                    PandaChat.Send(p, _localizationHelper, "BuyingColonists", ChatColor.orange, MAX_BUYABLE.ToString(), cs.Difficulty.GetorDefault("UnhappyColonistsBought", 1).ToString());
                }

                if (cs.SettlersToggledTimes < SettlersConfiguration.GetorDefault("MaxSettlersToggle", 4))
                {
                    PandaChat.Send(p, _localizationHelper, "SettlersEnabled", ChatColor.orange, cs.SettlersEnabled.ToString());
                }
            }

            foreach (Colony c in p.Colonies)
            {
                UpdateFoodUse(ColonyState.GetColonyState(c));
                c.SendCommonData();
            }
        }
Exemplo n.º 3
0
        public static void OnPlayerConnectedLate(Players.Player p)
        {
            if (p == null || p.Colonies == null || p.Colonies.Length == 0)
            {
                return;
            }

            if (SettlersConfiguration.GetorDefault("SettlersEnabled", true) &&
                SettlersConfiguration.GetorDefault("MaxSettlersToggle", 4) > 0 &&
                p.ActiveColony != null)
            {
                var cs = ColonyState.GetColonyState(p.ActiveColony);

                if (cs.SettlersToggledTimes < SettlersConfiguration.GetorDefault("MaxSettlersToggle", 4))
                {
                    PandaChat.Send(p, _localizationHelper, "SettlersEnabled", ChatColor.orange, cs.SettlersEnabled.ToString());
                }
            }

            foreach (Colony c in p.Colonies)
            {
                UpdateFoodUse(ColonyState.GetColonyState(c));
                c.SendCommonData();
            }
        }
Exemplo n.º 4
0
        public static void OnNPCRecruited(NPCBase npc)
        {
            try
            {
                var npcInv = ColonistInventory.Get(npc);
                if (npc.CustomData == null)
                {
                    npc.CustomData = new JSONNode();
                }

                if (npc.NPCType.IsLaborer)
                {
                    npcInv.UnemployedLeaveTime = TimeCycle.TotalHours + 48;
                }

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

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

                npc.FoodHoursCarried = ServerManager.ServerSettings.NPCs.InitialFoodCarriedHours;

                if (ps.SettlersEnabled != API.Models.SettlersState.Disabled)
                {
                    if (SettlersConfiguration.GetorDefault("ColonistsRecruitment", true))
                    {
                        if (npc.Colony.FollowerCount > MAX_BUYABLE)
                        {
                            if (!ColonistsBought.BoughtCount.ContainsKey(npc.Colony))
                            {
                                ColonistsBought.BoughtCount.Add(npc.Colony, new List <double>());
                            }

                            ColonistsBought.BoughtCount[npc.Colony].Add(TimeCycle.TotalHours + 24);
                        }

                        ColonistInventory.Get(npc);
                        UpdateFoodUse(ps);
                    }
                    else
                    {
                        PandaChat.Send(npc.Colony, _localizationHelper, "AdminDisabled", ChatColor.red);
                        npc.health = 0;
                        npc.Update();
                    }
                }
            }
            catch (Exception ex)
            {
                SettlersLogger.LogError(ex);
            }
        }
Exemplo n.º 5
0
        public static void OnPlayerConnectedLate(Players.Player p)
        {
            if (p == null || p.Colonies == null || p.Colonies.Length == 0)
            {
                return;
            }

            if (SettlersConfiguration.GetorDefault("SettlersEnabled", true) &&
                SettlersConfiguration.GetorDefault("MaxSettlersToggle", 4) > 0 &&
                p.ActiveColony != null)
            {
                var cs = ColonyState.GetColonyState(p.ActiveColony);

                if (cs.SettlersEnabled && SettlersConfiguration.GetorDefault("ColonistsRecruitment", true))
                {
                    PandaChat.Send(p,
                                   string
                                   .Format("Recruiting over {0} colonists will cost the base food cost plus a compounding {1} food. This compounding value resets once per in game day. If you build it... they will come.",
                                           MAX_BUYABLE,
                                           SettlersConfiguration.GetorDefault("CompoundingFoodRecruitmentCost", 2)),
                                   ChatColor.orange);
                }

                if (cs.SettlersToggledTimes < SettlersConfiguration.GetorDefault("MaxSettlersToggle", 4))
                {
                    var settlers = cs.SettlersEnabled ? "on" : "off";

                    if (SettlersConfiguration.GetorDefault("MaxSettlersToggle", 4) > 0)
                    {
                        PandaChat.Send(p,
                                       $"To disable/enable gaining random settlers type '/settlers off' Note: this can only be used {SettlersConfiguration.GetorDefault("MaxSettlersToggle", 4)} times.",
                                       ChatColor.orange);
                    }
                    else
                    {
                        PandaChat.Send(p, $"To disable/enable gaining random settlers type '/settlers off'",
                                       ChatColor.orange);
                    }

                    PandaChat.Send(p, $"Random Settlers are currently {settlers}!", ChatColor.orange);
                }
            }

            foreach (Colony c in p.Colonies)
            {
                UpdateFoodUse(ColonyState.GetColonyState(c));
                c.SendCommonData();
            }
        }
Exemplo n.º 6
0
        public bool TryDoCommand(Players.Player player, string chat, List <string> split)
        {
            if (!chat.StartsWith("/settlersconfig", StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }


            if (PermissionsManager.CheckAndWarnPermission(player, new PermissionsManager.Permission(GameLoader.NAMESPACE + ".Permissions.Config")))
            {
                var array = new List <string>();
                CommandManager.SplitCommand(chat, array);

                if (array.Count == 3)
                {
                    if (SettlersConfiguration.HasSetting(array[1]))
                    {
                        if (int.TryParse(array[2], out var set))
                        {
                            SettlersConfiguration.SetValue(array[1], set);
                        }
                        else if (float.TryParse(array[2], out var fset))
                        {
                            SettlersConfiguration.SetValue(array[1], fset);
                        }
                        else if (bool.TryParse(array[2], out var bset))
                        {
                            SettlersConfiguration.SetValue(array[1], bset);
                        }
                        else
                        {
                            SettlersConfiguration.SetValue(array[1], array[2]);
                        }
                    }
                    else
                    {
                        PandaChat.Send(player, _localizationHelper, "UnknownConfiguration", ChatColor.red, array[1]);
                    }
                }
                else
                {
                    SettlersConfiguration.Configuration.Reload();
                }
            }

            return(true);
        }
Exemplo n.º 7
0
 public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData userData)
 {
     if (SettlersConfiguration.GetorDefault("AntigriefEnabled", true) &&
         ServerManager.BlockEntityTracker.BannerTracker.TryGetClosest(userData.Position, out BannerTracker.Banner existingBanner, ServerManager.ServerSettings.Colony.ExclusiveRadius))
     {
         if (userData.RequestOrigin.Type == BlockChangeRequestOrigin.EType.Player &&
             userData.RequestOrigin.AsPlayer.ID.type == NetworkID.IDType.Steam &&
             !PermissionsManager.HasPermission(userData.RequestOrigin.AsPlayer, new PermissionsManager.Permission(GameLoader.NAMESPACE + ".Permissions.Antigrief")) &&
             !PermissionsManager.HasPermission(userData.RequestOrigin.AsPlayer, new PermissionsManager.Permission("god")) &&
             !existingBanner.Colony.Owners.Contains(userData.RequestOrigin.AsPlayer))
         {
             PandaChat.SendThrottle(userData.RequestOrigin.AsPlayer, _LocalizationHelper, _LocalizationHelper.LocalizeOrDefault("NotYourColony", userData.RequestOrigin.AsPlayer) + string.Join(", ", existingBanner.Colony.Owners.Select(o => o.Name)), ChatColor.red);
             userData.InventoryItemResults.Clear();
             userData.CallbackState          = ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled;
             userData.CallbackConsumedResult = EServerChangeBlockResult.CancelledByCallback;
         }
     }
 }
Exemplo n.º 8
0
        public static void OnPlayerMoved(Players.Player p, UnityEngine.Vector3 oldPosition)
        {
            try
            {
                var posBelow = new Vector3Int(p.Position);

                if (GetPadAt(posBelow, out var machineState) &&
                    _paired.ContainsKey(machineState.Position) &&
                    GetPadAt(_paired[machineState.Position], out var paired))
                {
                    var startInt = Time.SecondsSinceStartInt;

                    if (!_cooldown.ContainsKey(p))
                    {
                        _cooldown.Add(p, 0);
                    }

                    if (_cooldown[p] <= startInt)
                    {
                        if (machineState.GetActionEnergy(MachineConstants.REPAIR) <= 0)
                        {
                            PandaChat.Send(p, _localizationHelper, "NeedsRepair", ChatColor.red);
                            return;
                        }

                        if (machineState.GetActionEnergy(MachineConstants.REFUEL) <= 0)
                        {
                            PandaChat.Send(p, _localizationHelper, "", ChatColor.red);
                            return;
                        }

                        Teleport.TeleportTo(p, paired.Position.Vector);
                        AudioManager.SendAudio(machineState.Position.Vector, GameLoader.NAMESPACE + ".TeleportPadMachineAudio");
                        AudioManager.SendAudio(paired.Position.Vector, GameLoader.NAMESPACE + ".TeleportPadMachineAudio");
                        _cooldown[p] = SettlersConfiguration.GetorDefault("TeleportPadCooldown", 15) + startInt;
                    }
                }
            }
            catch (Exception ex)
            {
                SettlersLogger.LogError(ex);
            }
        }
Exemplo n.º 9
0
        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);

                npc.FoodHoursCarried = ServerManager.ServerSettings.NPCs.InitialFoodCarriedHours;

                if (ps.SettlersEnabled)
                {
                    if (SettlersConfiguration.GetorDefault("ColonistsRecruitment", true))
                    {
                        //if (ps.SettlersEnabled && npc.Colony.FollowerCount > MAX_BUYABLE)
                        //{
                        //    var cost = SettlersConfiguration.GetorDefault("CompoundingFoodRecruitmentCost", .25) * 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.");
                        npc.health = 0;
                        npc.Update();
                    }
                }
            }
            catch (Exception ex)
            {
                PandaLogger.LogError(ex);
            }
        }
Exemplo n.º 10
0
        public static NetworkMenu BuildMenu(Players.Player player, Dictionary <string, JobCounts> jobCounts, bool fired, string firedName, int firedCount)
        {
            NetworkMenu menu = new NetworkMenu();

            menu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault("ColonyManagement", player));
            menu.Width  = 1000;
            menu.Height = 600;

            if (fired)
            {
                var count = firedCount.ToString();

                if (firedCount == int.MaxValue)
                {
                    count = "all";
                }

                menu.Items.Add(new ButtonCallback(GameLoader.NAMESPACE + ".KillFired", new LabelData($"{_localizationHelper.LocalizeOrDefault("Kill", player)} {count} {_localizationHelper.LocalizeOrDefault("Fired", player)} {firedName}", UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)));
            }
            else
            {
                menu.Items.Add(new ButtonCallback(GameLoader.NAMESPACE + ".PlayerDetails", new LabelData(_localizationHelper.GetLocalizationKey("PlayerDetails"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)));
            }

            menu.Items.Add(new Line());

            if (!fired)
            {
                ColonyState ps = ColonyState.GetColonyState(player.ActiveColony);

                if (SettlersConfiguration.GetorDefault("ColonistsRecruitment", true))
                {
                    player.ActiveColony.HappinessData.RecruitmentCostCalculator.GetCost(player.ActiveColony.HappinessData.CachedHappiness, player.ActiveColony, out float num);
                    var cost = SettlersConfiguration.GetorDefault("CompoundingFoodRecruitmentCost", 2) * ps.ColonistsBought;

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

                    menu.Items.Add(new HorizontalSplit(new Label(new LabelData(_localizationHelper.GetLocalizationKey("RecruitmentCost"), UnityEngine.Color.black)),
                                                       new Label(new LabelData((cost + num).ToString(), UnityEngine.Color.black))));
                }

                if (ps.CallToArmsEnabled)
                {
                    menu.Items.Add(new ButtonCallback(GameLoader.NAMESPACE + ".CallToArms", new LabelData(_localizationHelper.GetLocalizationKey("DeactivateCallToArms"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)));
                }
                else
                {
                    menu.Items.Add(new ButtonCallback(GameLoader.NAMESPACE + ".CallToArms", new LabelData(_localizationHelper.GetLocalizationKey("ActivateCallToArms"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)));
                }
            }


            List <ValueTuple <IItem, int> > header = new List <ValueTuple <IItem, int> >();

            header.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Job"), UnityEngine.Color.black)), 140));

            if (!fired)
            {
                header.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("", UnityEngine.Color.black)), 140));
            }

            header.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Working"), UnityEngine.Color.black)), 140));
            header.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("NotWorking"), UnityEngine.Color.black)), 140));
            header.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("", UnityEngine.Color.black)), 140));
            header.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("", UnityEngine.Color.black)), 140));

            menu.Items.Add(new HorizontalRow(header));
            int jobCount = 0;

            foreach (var jobKvp in jobCounts)
            {
                if (fired && jobKvp.Value.AvailableCount == 0)
                {
                    continue;
                }

                jobCount++;
                List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();

                items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault(jobKvp.Key.Replace(" ", ""), player), UnityEngine.Color.black)), 140));

                if (!fired)
                {
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + ".JobDetailsButton", new LabelData(_localizationHelper.GetLocalizationKey("Details"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 140));
                }

                items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(jobKvp.Value.TakenCount.ToString(), UnityEngine.Color.black)), 140));
                items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(jobKvp.Value.AvailableCount.ToString(), UnityEngine.Color.black)), 140));

                if (fired)
                {
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + ".MoveFired", new LabelData(_localizationHelper.GetLocalizationKey("MoveFired"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft)), 140));
                }
                else
                {
                    items.Add(ValueTuple.Create <IItem, int>(new DropDown(new LabelData(_localizationHelper.GetLocalizationKey("Amount"), UnityEngine.Color.black), jobKvp.Key + ".Recruit", _recruitCount), 140));
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + ".RecruitButton", new LabelData(_localizationHelper.GetLocalizationKey("Recruit"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 140));
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + ".FireButton", new LabelData(_localizationHelper.GetLocalizationKey("Fire"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 140));
                }

                menu.LocalStorage.SetAs(jobKvp.Key + ".Recruit", 0);

                menu.Items.Add(new HorizontalRow(items));
            }

            if (jobCount == 0)
            {
                menu.Items.Add(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("NoJobs", player), UnityEngine.Color.black)));
            }

            return(menu);
        }