MCPcopy Create free account
hub / github.com/YGYOOO/WorldX / simulateTick

Method simulateTick

server/src/simulation/simulation-engine.ts:79–183  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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,

Callers 3

simulateDayMethod · 0.95
fetchTickMethod · 0.80
runGuardedSimulationTickFunction · 0.80

Calls 15

runCycleTransitionMethod · 0.95
finalizeTickEventsMethod · 0.95
buildTickIntentsMethod · 0.95
runDialogueSessionMethod · 0.95
shuffleFunction · 0.85

Tested by

no test coverage detected