Example #1
0
        public void ReloadEvents()
        {
            events.Clear();
            int currentTick = this.game.tickManager.TicksAbs;

            Utils.LogDebug("Loading scheduled events...");
            foreach (ScheduledEvent e in ScheduledEventsSettings.events)
            {
                int nextEventTick = e.GetNextEventTick(currentTick);
                if (nextEventTick <= 0)
                {
                    Utils.LogDebug(e.incidentName + " event has invalid next tick");
                    continue;
                }
                Utils.LogDebug($"Event {e.incidentName} will happen on {GenDate.HourOfDay(nextEventTick, 0)}h, {GenDate.DateFullStringAt(nextEventTick, Vector2.zero)}");
                TickEvent.AddToList(events, nextEventTick, e);
            }
        }
Example #2
0
        public override void GameComponentTick()
        {
            int       currentTick = this.game.tickManager.TicksAbs;
            TickEvent nextEvent   = events.FirstOrDefault();

            if (nextEvent != null && nextEvent.tick <= currentTick)
            {
                Utils.LogDebug($"Firing scheduled {nextEvent.e.incidentName} event!");
                // Remove from list
                events.Remove(nextEvent);
                int nextEventTick = nextEvent.e.GetNextEventTick(currentTick);

                IncidentDef incident = nextEvent.e.GetIncident();
                if (incident != null)
                {
                    IEnumerable <IIncidentTarget> targets = nextEvent.e.incidentTarget.GetCurrentTarget(nextEvent.e);
                    if (targets.Count() > 0)
                    {
                        nextEvent.e.targetSelector.RunOn(targets, (target) => this.nextEvents.Add(new NextEvent(incident, target)));
                    }
                    else
                    {
                        Utils.LogDebugWarning($"Event found 0 targets");
                    }
                }
                else
                {
                    Utils.LogWarning($"Could not fire event, since it could not find an IncidentDef");
                }
                Utils.LogDebug($"Next event will happen on {GenDate.HourOfDay(nextEventTick, 0)}h, {GenDate.DateFullStringAt(nextEventTick, Vector2.zero)}");
                //Utils.LogDebug($"Hours until: {(nextEventTick - currentTick) / GenDate.TicksPerHour}");
                TickEvent.AddToList(events, nextEventTick, nextEvent.e);
            }
            if (nextEvents.Count > 0)
            {
                nextEvents.First().Execute();
                nextEvents.RemoveAt(0);
            }
            //Current.Game.storyteller.TryFire()
            base.GameComponentTick();
        }