Пример #1
0
        private static void NPCLeaving(NPCBase npc)
        {
            if (Random.NextFloat() > .49f)
            {
                float cost = ColonistManager.PenalizeFood(npc.Colony, 0.05f);

                PandaChat.Send(npc.Colony, _localizationHelper, "TakenFood", ChatColor.red);
            }
            else
            {
                var numberOfItems = Random.Next(1, 10);

                for (var i = 0; i < numberOfItems; i++)
                {
                    var randItem = Random.Next(npc.Colony.Stockpile.ItemCount);
                    var item     = npc.Colony.Stockpile.GetByIndex(randItem);

                    if (item.Type != ColonyBuiltIn.ItemTypes.AIR.Id && item.Amount != 0)
                    {
                        var leaveTax = Pipliz.Math.RoundToInt(item.Amount * .10);
                        npc.Colony.Stockpile.TryRemove(item.Type, leaveTax);

                        PandaChat.Send(npc.Colony, _localizationHelper, "LeavingTakingItems", ChatColor.red, leaveTax.ToString(), ItemId.GetItemId(item.Type).Name);
                    }
                }

                PandaChat.Send(npc.Colony, _localizationHelper, "LeavingNumberOfItems", ChatColor.red, numberOfItems.ToString());
            }

            npc.health = 0;
            npc.OnDeath();
        }
Пример #2
0
        private static bool EvaluateBeds(ColonyState state)
        {
            var update = false;

            try
            {
                if (!TimeCycle.IsDay && Time.SecondsSinceStartDouble > _nextbedTime)
                {
                    if (state.ColonyRef.OwnerIsOnline())
                    {
                        // TODO Fix bed count
                        var remainingBeds = ServerManager.BlockEntityTracker.BedTracker.CalculateBedCount(state.ColonyRef) - state.ColonyRef.FollowerCount;
                        var left          = 0;

                        if (remainingBeds >= 0)
                        {
                            state.NeedsABed = 0;
                        }
                        else
                        {
                            if (state.NeedsABed == 0)
                            {
                                state.NeedsABed = Time.SecondsSinceStartDouble + LOABOROR_LEAVE_HOURS;
                                PandaChat.Send(state.ColonyRef, SettlerReasoning.GetNeedBed(), ChatColor.grey);
                            }

                            if (state.NeedsABed != 0 && state.NeedsABed < Time.SecondsSinceStartDouble)
                            {
                                foreach (var follower in state.ColonyRef.Followers)
                                {
                                    if (follower.UsedBed == null)
                                    {
                                        left++;
                                        NPCLeaving(follower);
                                    }
                                }

                                state.NeedsABed = 0;
                            }

                            if (left > 0)
                            {
                                PandaChat.Send(state.ColonyRef, string.Concat(SettlerReasoning.GetNoBed(), string.Format(" {0} colonists have left your colony.", left)), ChatColor.red);
                                update = true;
                            }
                        }

                        state.ColonyRef.SendCommonData();
                    }

                    _nextbedTime = Time.SecondsSinceStartDouble + Random.Next(5, 8) * IN_GAME_HOUR_IN_SECONDS * 24;
                }
            }
            catch (Exception ex)
            {
                PandaLogger.LogError(ex, "EvaluateBeds");
            }

            return(update);
        }
Пример #3
0
        public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData d)
        {
            if (d.CallbackState == ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled)
            {
                return;
            }

            if (d.TypeNew == Item.ItemIndex && d.TypeOld == BuiltinBlocks.Air)
            {
                if (World.TryGetTypeAt(d.Position.Add(0, -1, 0), out var itemBelow))
                {
                    if (CanMineBlock(itemBelow))
                    {
                        MachineManager.RegisterMachineState(d.RequestedByPlayer,
                                                            new MachineState(d.Position, d.RequestedByPlayer,
                                                                             nameof(Miner)));

                        return;
                    }
                }

                PandaChat.Send(d.RequestedByPlayer, "The mining machine must be placed on stone or ore.",
                               ChatColor.orange);

                d.CallbackState = ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled;
            }
        }
Пример #4
0
        public static void OnUpdate()
        {
            if (ServerManager.ColonyTracker != null)
            {
                foreach (var c in ServerManager.ColonyTracker.ColoniesByID.Values)
                {
                    if (c.OwnerIsOnline())
                    {
                        try
                        {
                            var ps = GetColonyState(c);

                            if (ps.NextColonistBuyTime != 0 && TimeCycle.TotalTime.Value.Hours > ps.NextColonistBuyTime)
                            {
                                PandaChat.Send(c, "The compounding cost of buying colonists has been reset.", ChatColor.orange);
                                ps.NextColonistBuyTime = 0;
                                ps.ColonistsBought     = 0;
                            }
                        }
                        catch (Exception ex)
                        {
                            PandaLogger.LogError(ex);
                        }
                    }
                }
            }
        }
        public static void ChangedSetting(TupleStruct <Players.Player, JSONNode, string> data)
        {
            switch (data.item3)
            {
            case "world_settings":
                var ps = PlayerState.GetPlayerState(data.item1);

                if (ps != null && data.item2.GetAsOrDefault(_Monsters, Convert.ToInt32(ps.MonstersEnabled)) != Convert.ToInt32(ps.MonstersEnabled))
                {
                    if (!Configuration.GetorDefault("MonstersCanBeDisabled", true))
                    {
                        PandaChat.Send(data.item1, "The server administrator had disabled the changing of Monsters.", ChatColor.red);
                    }
                    else
                    {
                        ps.MonstersEnabled = data.item2.GetAsOrDefault(_Monsters, Convert.ToInt32(ps.MonstersEnabled)) != 0;
                    }

                    PandaChat.Send(data.item1, "Settlers! Mod Monsters are now " + (ps.MonstersEnabled ? "on" : "off"), ChatColor.green);

                    if (!ps.MonstersEnabled)
                    {
                        MonsterTracker.KillAllZombies(data.item1);
                    }
                }

                break;
            }
        }
Пример #6
0
        public static void OpenMenu(Players.Player player, PlayerClickedData playerClickData)
        {
            if (ItemTypes.IndexLookup.TryGetIndex(SchematicTool.NAME, out var schematicItem) &&
                playerClickData.TypeSelected == schematicItem)
            {
                if (player.ActiveColony == null)
                {
                    PandaChat.Send(player, _localizationHelper, "ErrorOpening", ChatColor.red);
                    return;
                }

                if (!_awaitingClick.ContainsKey(player))
                {
                    SendMainMenu(player);
                }
                else
                {
                    var tuple = _awaitingClick[player];
                    _awaitingClick.Remove(player);

                    switch (tuple.Item1)
                    {
                    case SchematicClickType.Build:
                        Vector3Int location = playerClickData.GetVoxelHit().BlockHit.Add(0, 1, 0);
                        var        args     = new JSONNode();
                        args.SetAs("constructionType", GameLoader.NAMESPACE + ".SchematicBuilder");
                        args.SetAs(SchematicBuilderLoader.NAME + ".SchematicName", tuple.Item2);
                        args.SetAs(SchematicBuilderLoader.NAME + ".Rotation", tuple.Item3);

                        if (SchematicReader.TryGetSchematic(tuple.Item2, player.ActiveColony.ColonyID, location, out var schematic))
                        {
                            if (tuple.Item3 >= Schematic.Rotation.Right)
                            {
                                schematic.Rotate();
                            }

                            if (tuple.Item3 >= Schematic.Rotation.Back)
                            {
                                schematic.Rotate();
                            }

                            if (tuple.Item3 >= Schematic.Rotation.Left)
                            {
                                schematic.Rotate();
                            }

                            var maxSize = location.Add(schematic.XMax - 1, schematic.YMax - 1, schematic.ZMax - 1);
                            AreaJobTracker.CreateNewAreaJob("pipliz.constructionarea", args, player.ActiveColony, location, maxSize);
                            AreaJobTracker.SendData(player);
                        }

                        break;

                    case SchematicClickType.Archetect:

                        break;
                    }
                }
            }
        }
Пример #7
0
        private static void AddNewSettlers(double addCount, int numbSkilled, ColonyState state)
        {
            var reason = string.Format(SettlerReasoning.GetSettleReason(), addCount);

            if (numbSkilled > 0)
            {
                if (numbSkilled == 1)
                {
                    reason += string.Format(" {0} of them is skilled!", numbSkilled);
                }
                else
                {
                    reason += string.Format(" {0} of them are skilled!", numbSkilled);
                }
            }

            PandaChat.Send(state.ColonyRef, reason, ChatColor.magenta);

            for (var i = 0; i < addCount; i++)
            {
                var newGuy = new NPCBase(state.ColonyRef, state.ColonyRef.GetRandomBanner().Position);

                NPCTracker.Add(newGuy);
                state.ColonyRef.RegisterNPC(newGuy);
                SettlerInventory.GetSettlerInventory(newGuy);
                newGuy.CustomData.SetAs(ISSETTLER, true);

                if (i <= numbSkilled)
                {
                    newGuy.CustomData.SetAs(GameLoader.ALL_SKILLS, Random.Next(1, 10) * 0.002f);
                }

                ModLoader.Callbacks.OnNPCRecruited.Invoke(newGuy);
            }
        }
Пример #8
0
        private static void NPCLeaving(NPCBase npc)
        {
            if (Random.NextFloat() > .49f)
            {
                float cost = PenalizeFood(npc.Colony, 0.05f);
                PandaChat.Send(npc.Colony, $"A colonist has left your colony taking {cost} food.", ChatColor.red);
            }
            else
            {
                var numberOfItems = Random.Next(1, 10);

                for (var i = 0; i < numberOfItems; i++)
                {
                    var randItem = Random.Next(npc.Colony.Stockpile.ItemCount);
                    var item     = npc.Colony.Stockpile.GetByIndex(randItem);

                    if (item.Type != ColonyBuiltIn.ItemTypes.AIR.Id && item.Amount != 0)
                    {
                        var leaveTax = Pipliz.Math.RoundToInt(item.Amount * .10);
                        npc.Colony.Stockpile.TryRemove(item.Type, leaveTax);

                        PandaChat.Send(npc.Colony, $"A leaving colonist has taken {leaveTax} {Models.ItemId.GetItemId(item.Type).Name}", ChatColor.red);
                    }
                }

                PandaChat.Send(npc.Colony, $"A colonist has left your colony taking 10% of {numberOfItems} items from your stockpile.", ChatColor.red);
            }

            npc.health = 0;
            npc.OnDeath();
        }
Пример #9
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();
            }
        }
Пример #10
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();
            }
        }
Пример #11
0
        private static void DeductArmor(ModLoader.OnHitData box, Dictionary <ArmorSlot, ArmorState> entityArmor,
                                        Players.Player player, string name)
        {
            if (box.ResultDamage > 0)
            {
                float armor = 0;

                foreach (ArmorSlot armorSlot in ArmorSlotEnum)
                {
                    if (!entityArmor.ContainsKey(armorSlot))
                    {
                        entityArmor.Add(armorSlot, new ArmorState());
                    }

                    if (!entityArmor[armorSlot].IsEmpty())
                    {
                        armor += ArmorLookup[entityArmor[armorSlot].Id].ArmorRating;
                    }
                }

                if (armor != 0)
                {
                    box.ResultDamage = box.ResultDamage - box.ResultDamage * armor;

                    var hitLocation = _rand.Next(1, 100);

                    var dic = _hitChance;

                    if (!entityArmor[ArmorSlot.Shield].IsEmpty())
                    {
                        dic = _hitChanceShield;
                    }

                    foreach (var loc in dic)
                    {
                        if (!entityArmor[loc.Key].IsEmpty() && loc.Value >= hitLocation)
                        {
                            entityArmor[loc.Key].Durability--;

                            if (entityArmor[loc.Key].Durability <= 0)
                            {
                                entityArmor[loc.Key].Durability = 0;
                                entityArmor[loc.Key].Id         = default(ushort);

                                PandaChat.Send(player,
                                               $"{name} {loc.Key} broke! If you have a spare one it will be automatically equipt within 30 seconds.",
                                               ChatColor.white);
                            }

                            break;
                        }
                    }
                }
            }
        }
Пример #12
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);
            }
        }
Пример #13
0
        private static void CantSpawnBoss(PlayerState ps, Colony colony)
        {
            ps.FaiedBossSpawns++;

            if (ps.FaiedBossSpawns > 10)
            {
                PandaChat.SendThrottle(ps.Player, $"WARNING: Unable to spawn boss. Please ensure you have a path to your banner. You will be penalized {SettlerManager.PenalizeFood(colony, 0.15f)} food.", ChatColor.red);
            }

            colony.OnZombieSpawn(false);
        }
Пример #14
0
        private static void CantSpawnBoss(ColonyState cs)
        {
            cs.FaiedBossSpawns++;

            if (cs.FaiedBossSpawns > 10)
            {
                PandaChat.SendThrottle(cs, _localizationHelper, "NoBanner", ChatColor.red, ColonistManager.PenalizeFood(cs.ColonyRef, 0.15f) * 100 + "%");
            }

            cs.ColonyRef.OnZombieSpawn(false);
        }
Пример #15
0
        public static void OnPlayerConnectedSuperLate(Players.Player p)
        {
            GetPlayerState(p);

            _playerStates[p].Connected = true;
            _playerStates[p].RecaclculateMagicItems();

            if (GameLoader.FileWasCopied)
            {
                PandaChat.Send(p, "For settlers mod to fully be installed the Colony Survival surver needs to be restarted.", ChatColor.red);
            }
        }
Пример #16
0
        public static void OnNPCRecruited(NPCBase npc)
        {
            if (npc.GetTempValues().TryGet(ISSETTLER, out bool settler) && settler)
            {
                return;
            }

            var ps = PlayerState.GetPlayerState(npc.Colony.Owner);

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

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

                        if (npc.Colony.UsedStockpile.TotalFood < cost ||
                            !npc.Colony.UsedStockpile.TryRemoveFood(ref num, cost))
                        {
                            Chat.Send(npc.Colony.Owner,
                                      $"<color=red>Could not recruit a new colonist; not enough food in stockpile. {cost + ServerManager.ServerVariables.LaborerCost} food required.</color>",
                                      ChatSenderType.Server);

                            npc.Colony.UsedStockpile.Add(BuiltinBlocks.Bread,
                                                         (int)Math.Floor(ServerManager.ServerVariables.LaborerCost /
                                                                         3));

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

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

                    SettlerInventory.GetSettlerInventory(npc);
                    UpdateFoodUse(npc.Colony.Owner);
                }
                else
                {
                    PandaChat.Send(npc.Colony.Owner,
                                   "The server administrator has disabled recruitment of colonists while settlers are enabled.");
                }
            }
        }
Пример #17
0
 public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData userData)
 {
     if (ServerManager.BlockEntityTracker.BannerTracker.TryGetClosest(userData.Position, out BannerTracker.Banner existingBanner, ServerManager.ServerSettings.Colony.ExclusiveRadius * 2))
     {
         if (userData.RequestOrigin.Type == BlockChangeRequestOrigin.EType.Player && !existingBanner.Colony.Owners.Contains(userData.RequestOrigin.AsPlayer))
         {
             PandaChat.SendThrottle(userData.RequestOrigin.AsPlayer, _LocalizationHelper.LocalizeOrDefault("NotYourColony", userData.RequestOrigin.AsPlayer) + string.Join(", ", existingBanner.Colony.Owners.Select(o => o.Name)), ChatColor.red);
             userData.CallbackState          = ModLoader.OnTryChangeBlockData.ECallbackState.Cancelled;
             userData.CallbackConsumedResult = EServerChangeBlockResult.CancelledByCallback;
         }
     }
 }
Пример #18
0
        private static bool EvaluateLaborers(ColonyState state)
        {
            var update = false;

            if (TimeCycle.TotalHours > state.NextLaborerTime)
            {
                var            unTrack     = new List <NPCBase>();
                var            left        = 0;
                var            leaving     = 0;
                List <NPCBase> leavingNPCs = new List <NPCBase>();

                foreach (var npc in state.ColonyRef.Followers)
                {
                    if (npc.NPCType.IsLaborer)
                    {
                        leaving++;

                        if (leaving > 10)
                        {
                            var inv = ColonistInventory.Get(npc);

                            if (inv.UnemployedLeaveTime == 0)
                            {
                                inv.UnemployedLeaveTime = TimeCycle.TotalHours + 48;
                            }
                            else if (inv.UnemployedLeaveTime < TimeCycle.TotalHours)
                            {
                                left++;
                                leavingNPCs.Add(npc);
                            }
                        }
                    }
                }

                foreach (var npc in leavingNPCs)
                {
                    NPCLeaving(npc);
                }

                if (left > 0)
                {
                    PandaChat.Send(state.ColonyRef, _localizationHelper, "ColonistsLeft", ChatColor.red);
                }

                update = unTrack.Count != 0;
                state.ColonyRef.SendCommonData();

                state.NextLaborerTime = TimeCycle.TotalHours + 1;
            }

            return(update);
        }
Пример #19
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();
            }
        }
Пример #20
0
        public bool TryDoCommand(Players.Player player, string chat, List <string> split)
        {
            if (!chat.StartsWith("/bosses", StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            if (player == null || player.ID == NetworkID.Server)
            {
                return(true);
            }


            if (player.ActiveColony == null)
            {
                PandaChat.Send(player, _localizationHelper, "NoColony", ChatColor.red);
            }

            var array = new List <string>();

            CommandManager.SplitCommand(chat, array);
            var state = ColonyState.GetColonyState(player.ActiveColony);

            if (array.Count == 1)
            {
                PandaChat.Send(player, _localizationHelper, "BossesToggled", ChatColor.green, state.BossesEnabled ? _localizationHelper.LocalizeOrDefault("on", player) : _localizationHelper.LocalizeOrDefault("off", player));
                return(true);
            }

            if (array.Count == 2)
            {
                if (array[1].ToLower().Trim() == "on" || array[1].ToLower().Trim() == "true")
                {
                    state.BossesEnabled = true;
                }
                else
                {
                    state.BossesEnabled = false;
                }

                PandaChat.Send(player, _localizationHelper, "BossesToggled", ChatColor.green, state.BossesEnabled ? _localizationHelper.LocalizeOrDefault("on", player) : _localizationHelper.LocalizeOrDefault("off", player));
            }

            NetworkUI.NetworkMenuManager.SendColonySettingsUI(player);
            PandaChat.Send(player, _localizationHelper, "AdminDisabledBosses", ChatColor.red);


            return(true);
        }
Пример #21
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);
        }
Пример #22
0
        public static void OnPlayerConnectedLate(Players.Player p)
        {
            if (Configuration.DifficutlyCanBeChanged)
            {
                GameDifficultyChatCommand.PossibleCommands(p, ChatColor.grey);
            }

            if (Configuration.GetorDefault("SettlersEnabled", true) &&
                Configuration.GetorDefault("MaxSettlersToggle", 4) > 0)
            {
                var ps = PlayerState.GetPlayerState(p);

                if (ps.SettlersEnabled && Configuration.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,
                                           Configuration.GetorDefault("CompoundingFoodRecruitmentCost", 5)),
                                   ChatColor.orange);
                }

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

                    if (Configuration.GetorDefault("MaxSettlersToggle", 4) > 0)
                    {
                        PandaChat.Send(p,
                                       $"To disable/enable gaining random settlers type '/settlers off' Note: this can only be used {Configuration.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);
                }
            }

            UpdateFoodUse(p);

            Colony.Get(p).SendUpdate();
            Colony.SendColonistCount(p);
        }
Пример #23
0
        public static void OnUpdate()
        {
            Players.PlayerDatabase.ForeachValue(p =>
            {
                if (p.IsConnected)
                {
                    var ps = GetPlayerState(p);

                    if (ps.NextColonistBuyTime != 0 && TimeCycle.TotalTime > ps.NextColonistBuyTime)
                    {
                        PandaChat.Send(p, "The compounding cost of buying colonists has been reset.", ChatColor.orange);
                        ps.NextColonistBuyTime = 0;
                        ps.ColonistsBought     = 0;
                    }
                }
            });
        }
Пример #24
0
        private static bool EvaluateLaborers(Players.Player p)
        {
            var update = false;

            if (TimeCycle.IsDay && Time.SecondsSinceStartDouble > _nextLaborerTime)
            {
                if (p.IsConnected)
                {
                    var unTrack = new List <NPCBase>();
                    var colony  = Colony.Get(p);
                    var state   = PlayerState.GetPlayerState(p);
                    var left    = 0;

                    for (var i = 0; i < colony.LaborerCount; i++)
                    {
                        var npc     = colony.FindLaborer(i);
                        var tmpVals = npc.GetTempValues();

                        if (!tmpVals.Contains(LEAVETIME_JOB))
                        {
                            tmpVals.Set(LEAVETIME_JOB, Time.SecondsSinceStartDouble + LOABOROR_LEAVE_HOURS);
                        }
                        else if (tmpVals.Get <double>(LEAVETIME_JOB) < TimeCycle.TotalTime)
                        {
                            left++;
                            NPCLeaving(npc);
                        }
                    }

                    if (left > 0)
                    {
                        PandaChat.Send(p,
                                       string.Concat(SettlerReasoning.GetNoJobReason(),
                                                     string.Format(" {0} colonists have left your colony.", left)),
                                       ChatColor.red);
                    }

                    update = unTrack.Count != 0;
                    colony.SendUpdate();
                }

                _nextLaborerTime = Time.SecondsSinceStartDouble + Random.Next(4, 6) * TimeCycle.SecondsPerHour;
            }

            return(update);
        }
Пример #25
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;
         }
     }
 }
Пример #26
0
        public bool TryDoCommand(Players.Player player, string chat)
        {
            if (player == null || player.ID == NetworkID.Server)
            {
                return(true);
            }

            var array  = CommandManager.SplitCommand(chat);
            var colony = Colony.Get(player);
            var state  = PlayerState.GetPlayerState(player);

            if (array.Length == 1)
            {
                PandaChat.Send(player, "Settlers! Bosses are {0}.", ChatColor.green,
                               state.BossesEnabled ? "on" : "off");

                return(true);
            }

            if (array.Length == 2 && Configuration.GetorDefault("BossesCanBeDisabled", true))
            {
                if (array[1].ToLower().Trim() == "on" || array[1].ToLower().Trim() == "true")
                {
                    state.BossesEnabled = true;
                    PandaChat.Send(player, "Settlers! Mod Bosses are now on.", ChatColor.green);
                }
                else
                {
                    state.BossesEnabled = false;
                    PandaChat.Send(player, "Settlers! Mod Bosses are now off.", ChatColor.green);
                }
            }

            NetworkUI.NetworkMenuManager.SendWorldSettingsUI(player);
            if (!Configuration.GetorDefault("BossesCanBeDisabled", true))
            {
                PandaChat.Send(player, "The server administrator had disabled the changing of bosses.",
                               ChatColor.red);
            }


            return(true);
        }
Пример #27
0
        private static bool EvaluateLaborers(ColonyState state)
        {
            var update = false;

            if (TimeCycle.IsDay && Time.SecondsSinceStartDouble > _nextLaborerTime)
            {
                if (state.ColonyRef.OwnerIsOnline())
                {
                    var unTrack = new List <NPCBase>();
                    var left    = 0;

                    for (var i = 0; i < state.ColonyRef.LaborerCount; i++)
                    {
                        var npc = state.ColonyRef.FindLaborer(i);

                        if (!npc.CustomData.TryGetAs(LEAVETIME_JOB, out double leaveTime))
                        {
                            npc.CustomData.SetAs(LEAVETIME_JOB, Time.SecondsSinceStartDouble + LOABOROR_LEAVE_HOURS);
                        }
                        else if (leaveTime < Time.SecondsSinceStartDouble)
                        {
                            left++;
                            NPCLeaving(npc);
                        }
                    }

                    if (left > 0)
                    {
                        PandaChat.Send(state.ColonyRef,
                                       string.Concat(SettlerReasoning.GetNoJobReason(),
                                                     string.Format(" {0} colonists have left your colony.", left)),
                                       ChatColor.red);
                    }

                    update = unTrack.Count != 0;
                    state.ColonyRef.SendCommonData();
                }

                _nextLaborerTime = Time.SecondsSinceStartDouble + Random.Next(4, 6) * IN_GAME_HOUR_IN_SECONDS * 24;
            }

            return(update);
        }
        public static void ConnectedBlockInfo(Players.Player player, PlayerClickedData playerClickData)
        {
            //Only launch on RIGHT click
            if (player == null || playerClickData.ClickType != PlayerClickedData.EClickType.Right || player.ActiveColony == null)
            {
                return;
            }

            if (playerClickData.HitType == PlayerClickedData.EHitType.Block &&
                ItemTypes.IndexLookup.TryGetIndex(GameLoader.NAMESPACE + ".ConnectedBlockTool", out var toolItem) &&
                playerClickData.TypeSelected == toolItem &&
                ConnectedBlockSystem.BlockLookup.TryGetValue(ItemId.GetItemId(playerClickData.GetVoxelHit().TypeHit), out var cSType))
            {
                PandaChat.Send(player, "Side Hit: " + playerClickData.GetVoxelHit().SideHit);
                PandaChat.Send(player, "Connected Sides: " + string.Join(", ", cSType.ConnectedBlock.Connections.Select(c => c.ToString()).ToArray()));
                PandaChat.Send(player, "Origin Sides: " + string.Join(", ", cSType.ConnectedBlock.Origin.Select(c => c.ToString()).ToArray()));                PandaChat.Send(player, "BlockRotationDegrees: " + cSType.ConnectedBlock.BlockRotationDegrees.ToString());
                PandaChat.Send(player, "RotationAxis: " + cSType.ConnectedBlock.RotationAxis.ToString());
            }
        }
Пример #29
0
        public static void ChangedSetting(ValueTuple <Players.Player, JSONNode, string> data)
        {
            if (data.Item1.ActiveColony != null)
            {
                switch (data.Item3)
                {
                case "server_popup":
                    var ps = ColonyState.GetColonyState(data.Item1.ActiveColony);

                    if (ps != null && data.Item2.GetAsOrDefault(_Bosses, Convert.ToInt32(ps.BossesEnabled)) != Convert.ToInt32(ps.BossesEnabled))
                    {
                        ps.BossesEnabled = data.Item2.GetAsOrDefault(_Bosses, Convert.ToInt32(ps.BossesEnabled)) != 0;
                        PandaChat.Send(data.Item1, _localizationHelper, "BossesToggled", ChatColor.green, ps.BossesEnabled ? _localizationHelper.LocalizeOrDefault("on", data.Item1) : _localizationHelper.LocalizeOrDefault("off", data.Item1));
                    }

                    break;
                }
            }
        }
Пример #30
0
        public static bool OnTryChangeBlockUser(ModLoader.OnTryChangeBlockUserData d)
        {
            if (d.TypeNew == Item.ItemIndex && d.typeTillNow == BuiltinBlocks.Air)
            {
                if (World.TryGetTypeAt(d.VoxelToChange.Add(0, -1, 0), out ushort itemBelow))
                {
                    if (CanMineBlock(itemBelow))
                    {
                        MachineManager.RegisterMachineState(d.requestedBy, new MachineState(d.VoxelToChange, d.requestedBy, nameof(Miner)));
                        return(true);
                    }
                }

                PandaChat.Send(d.requestedBy, "The mining machine must be placed on stone or ore.", ChatColor.orange);
                return(false);
            }

            return(true);
        }