()
| 77 | } |
| 78 | |
| 79 | async simulateTick(): Promise<SimulationEvent[]> { |
| 80 | const events: SimulationEvent[] = []; |
| 81 | const tickAdvance = this.worldManager.advanceTick(); |
| 82 | const { previousTime, currentTime: gameTime, didAdvanceDay } = tickAdvance; |
| 83 | const absNow = absoluteTick(gameTime); |
| 84 | |
| 85 | if (didAdvanceDay) { |
| 86 | events.push(...await this.runCycleTransition(previousTime)); |
| 87 | return this.finalizeTickEvents(events); |
| 88 | } |
| 89 | |
| 90 | const allChars = shuffle(this.characterManager.getAllProfiles()); |
| 91 | |
| 92 | for (const char of allChars) { |
| 93 | events.push( |
| 94 | ...this.characterManager.tickPassiveUpdate(char.id, gameTime), |
| 95 | ); |
| 96 | } |
| 97 | |
| 98 | const activeSessions = this.reconcileDialogueSessions(); |
| 99 | const decisionEligible: string[] = []; |
| 100 | |
| 101 | for (const char of allChars) { |
| 102 | try { |
| 103 | const shouldDecide = this.prepareCharacterForTick( |
| 104 | char.id, |
| 105 | gameTime, |
| 106 | absNow, |
| 107 | events, |
| 108 | ); |
| 109 | if (shouldDecide) { |
| 110 | decisionEligible.push(char.id); |
| 111 | } |
| 112 | } catch (err) { |
| 113 | console.error(`[SimEngine] Error preparing ${char.id}:`, err); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | const intents = await this.buildTickIntents(decisionEligible, gameTime, events); |
| 118 | const dialogueIntentByInitiator = new Map<string, ActionDecision>(); |
| 119 | |
| 120 | for (const charId of decisionEligible) { |
| 121 | const intent = intents.get(charId); |
| 122 | if (intent?.decision.actionType === "talk_to") { |
| 123 | const movementDecision = this.buildMoveTowardDialogueTargetDecision( |
| 124 | charId, |
| 125 | intent.decision, |
| 126 | ); |
| 127 | if (movementDecision) { |
| 128 | intent.decision = movementDecision; |
| 129 | } else { |
| 130 | dialogueIntentByInitiator.set(charId, intent.decision); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | const selectedSessions = this.selectDialogueSessions({ |
| 136 | allChars, |
no test coverage detected