TimeReactionBase ITimeActiveListenerFull.reactToHourPassing() { //set initial out values so we can return safely. TimeReactionBase output = null; //pregnant, does not have diapause, or pregnant, has diapause, and has some hours to progess due to ingesting liquids. if (isPregnant && (!hasDiapause || diapauseHours > 0)) { if (hasDiapause) { diapauseHours--; if (doDiapauseText) { output = new GenericSimpleReaction((_, __) => DiapauseText()); doDiapauseText = false; } } hoursTilBirth -= pregnancyMultiplier; //override them if we are pregnant and giving birth. if (hoursTilBirth <= 0) { output = DoBirth(); } } return(output); }
private void DoLazies() { hitLazies = true; int hoursPassed = startTime.hoursToNow(); byte lazyHoursPassed = hoursPassed > byte.MaxValue ? byte.MaxValue : (byte)hoursPassed; IEnumerable <ITimeLazyListener> lazyItems = lazyListeners.Union(CreatureStore.activeCreatureList.SelectMany(x => x.QueryLazyListeners())); foreach (var item in lazyItems) { currentContentPage.OutputText(item.reactToTimePassing(lazyHoursPassed)); } //it may be possible for some of the previously processed events to create a new reaction, like an asshole. take care of that here. while (!reactions.isEmpty && reactions.Peek().procTime.CompareTo(GameDateTime.Now) <= 0) { TimeReactionBase scene = reactions.Pop().onProc; ParsePage(scene); } QueryPageStatus(); }
private void ParsePage(TimeReactionBase scene) { if (scene is null) { return; } DisplayWrapper eventResult = scene.RunEvent(isIdleTime, idleHours > 0); if (DisplayWrapper.IsNullOrEmpty(eventResult)) { return; } else if (eventResult.isSimpleReaction) { currentContentPage.OutputText(eventResult.simpleReaction); } else { DisplayBase display = eventResult.fullPageReaction; if (!string.IsNullOrEmpty(newHourHeader)) { display.CombineWith(newHourHeader, false); newHourHeader = null; } //enqueue the current page. create a new page, and load that. if (ReferenceEquals(display, GetCurrentPage())) { activePages.Enqueue(display); SetCurrentPage(pageMaker()); } else { GetCurrentPage().ClearOutput(); } } }
private void RunHour() { //Linq for the win! Simple version: take all reactions, full daily, multi-daily, and active listeners, and convert them into a function that returns an eventwrapper. //similarly, for all creatures currently participating in time events, take all their daily, multi-daily, and active items (collection of collections), and flatten them into one //collection for each type. we union all of these results together into one giant collection of items for this engine to parse. this giant collection is passed into the constructor //for a queue, and then we're good to go. while (!reactions.isEmpty && reactions.Peek().procTime.CompareTo(GameDateTime.Now) <= 0) { TimeReactionBase scene = reactions.Pop().onProc; ParsePage(scene); } IEnumerable <Func <TimeReactionBase> > eventsToParse = fullDailyListeners.Where(x => x.hourToTrigger == currentHour).Select <ITimeDailyListenerFull, Func <TimeReactionBase> >(x => x.reactToDailyTrigger) .Union(CreatureStore.activeCreatureList.SelectMany(x => x.QueryFullDailyListeners(currentHour).Select <ITimeDailyListenerFull, Func <TimeReactionBase> >(y => y.reactToDailyTrigger))) .Union(fullMultiTimeListeners.Where(x => x.triggerHours.Contains(currentHour)).Select <ITimeDayMultiListenerFull, Func <TimeReactionBase> >(x => () => x.reactToTrigger(currentHour))) .Union(CreatureStore.activeCreatureList.SelectMany(x => x.QueryFullDayMultiListeners(currentHour).Select <ITimeDayMultiListenerFull, Func <TimeReactionBase> >(y => () => y.reactToTrigger(currentHour)))) .Union(fullActiveListeners.Select <ITimeActiveListenerFull, Func <TimeReactionBase> >(x => x.reactToHourPassing)) .Union(CreatureStore.activeCreatureList.SelectMany(x => x.QueryFullActiveListeners().Select <ITimeActiveListenerFull, Func <TimeReactionBase> >(y => y.reactToHourPassing))); foreach (var element in eventsToParse) { TimeReactionBase result = element?.Invoke(); ParsePage(result); } if (this.activePages.Count > 0 && finalDestination != null) { this.newHourHeader = finalDestination.DoResume(idleHours, areaEngine.currentArea); } QueryPageStatus(); }