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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        private static bool EvaluateBeds(ColonyState state)
        {
            var update = false;

            try
            {
                if (!TimeCycle.IsDay && TimeCycle.TotalHours > state.NextBedTime)
                {
                    var remainingBeds = state.ColonyRef.BedTracker.CalculateTotalBedCount() - state.ColonyRef.FollowerCount;
                    var left          = 0;

                    if (remainingBeds >= 0)
                    {
                        state.NeedsABed = 0;
                    }
                    else
                    {
                        if (state.NeedsABed == 0)
                        {
                            state.NeedsABed = TimeCycle.TotalHours + 24;
                            PandaChat.Send(state.ColonyRef, _localizationHelper, SettlerReasoning.GetNeedBed(), ChatColor.grey);
                        }
                        else if (state.NeedsABed <= TimeCycle.TotalHours)
                        {
                            List <NPCBase> leaving = new List <NPCBase>();

                            foreach (var follower in state.ColonyRef.Followers)
                            {
                                if (follower.UsedBed == null)
                                {
                                    left++;
                                    leaving.Add(follower);
                                }
                            }

                            state.NeedsABed = 0;

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

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


                        state.ColonyRef.SendCommonData();
                    }

                    state.NextBedTime = TimeCycle.TotalHours + Random.Next(5, 8);
                }
            }
            catch (Exception ex)
            {
                SettlersLogger.LogError(ex, "EvaluateBeds");
            }

            return(update);
        }