Esempio n. 1
0
        void CheckFollower(Players.Player player, Colony colony)
        {
            int maxFollower = Math.Min(Size, BedBlockTracker.GetCount(player));

            for (int c = colony.FollowerCount; c < maxFollower; c++)
            {
                SpawnNpc(colony);
            }
        }
        public static float SpawnChance(Players.Player p, Colony c, PlayerState state)
        {
            var chance        = .3f;
            var remainingBeds = BedBlockTracker.GetCount(p) - c.FollowerCount;

            if (remainingBeds < 1)
            {
                chance -= 0.1f;
            }

            if (remainingBeds >= state.MaxPerSpawn)
            {
                chance += 0.3f;
            }
            else if (remainingBeds > SettlerManager.MIN_PERSPAWN)
            {
                chance += 0.15f;
            }

            var hoursofFood = Stockpile.GetStockPile(p).TotalFood / c.FoodUsePerHour;

            if (hoursofFood > _minFoodHours)
            {
                chance += 0.2f;
            }

            var jobCount = JobTracker.GetOpenJobCount(p);

            if (jobCount > state.MaxPerSpawn)
            {
                chance += 0.4f;
            }
            else if (jobCount > SettlerManager.MIN_PERSPAWN)
            {
                chance += 0.1f;
            }
            else
            {
                chance -= 0.2f;
            }

            if (state.Difficulty != GameDifficulty.Easy)
            {
                if (c.InSiegeMode ||
                    c.LastSiegeModeSpawn != 0 &&
                    Time.SecondsSinceStartDouble - c.LastSiegeModeSpawn > TimeSpan.FromMinutes(5).TotalSeconds)
                {
                    chance -= 0.4f;
                }
            }

            return(chance);
        }
Esempio n. 3
0
 protected override void Update(Players.Player player)
 {
     if (Build)
     {
         Build = false;
         var builder = new NpcFarmBuilder(player, Origin, Size);
         builder.Build();
         LootSpawner.SetPossibleLootSpots(builder.LootSpots);
     }
     else if (BedBlockTracker.GetCount(player) < 1)
     {
         KingdomsTracker.SendKingdomNotification($"Farm at {Origin} is dead! Lost all beds");
         Kill();
     }
     else
     {
         var stockpile = Stockpile.GetStockPile(player);
         var colony    = Colony.Get(player);
         CheckItemAmount(stockpile, BuiltinBlocks.Bread, 5000);
         CheckFollower(player, colony);
         CheckItemAmount(stockpile, BuiltinBlocks.WheatStage1, 100);
     }
 }
Esempio n. 4
0
        private static bool EvaluateBeds(Players.Player p)
        {
            var update = false;

            try
            {
                if (!TimeCycle.IsDay && Time.SecondsSinceStartDouble > _nextbedTime)
                {
                    if (p.IsConnected)
                    {
                        var colony        = Colony.Get(p);
                        var state         = PlayerState.GetPlayerState(p);
                        var remainingBeds = BedBlockTracker.GetCount(p) - colony.FollowerCount;
                        var left          = 0;

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

                            if (state.NeedsABed != 0 && state.NeedsABed < TimeCycle.TotalTime)
                            {
                                foreach (var follower in colony.Followers)
                                {
                                    if (follower.GetFieldValue <BedBlock, NPCBase>("bed") == null)
                                    {
                                        left++;
                                        NPCLeaving(follower);
                                    }
                                }

                                state.NeedsABed = 0;
                            }

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

                                update = true;
                            }
                        }

                        colony.SendUpdate();
                    }

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

            return(update);
        }