( ctx: ReducerCtx<S>, agent: GameEnemyAiAgentState, agentTargetable: GameTargetableState, surroundingAgents: GameTargetableState[], currentTimeMs: bigint )
| 250 | } |
| 251 | |
| 252 | function agentLoop( |
| 253 | ctx: ReducerCtx<S>, |
| 254 | agent: GameEnemyAiAgentState, |
| 255 | agentTargetable: GameTargetableState, |
| 256 | surroundingAgents: GameTargetableState[], |
| 257 | currentTimeMs: bigint |
| 258 | ) { |
| 259 | const entityId = agent.entity_id; |
| 260 | |
| 261 | const coordinates = ctx.db.gameMobileEntityState.entity_id.find(entityId); |
| 262 | if (coordinates == null) { |
| 263 | throw new Error('GameMobileEntityState Entity ID not found'); |
| 264 | } |
| 265 | |
| 266 | const agentEntity = ctx.db.gameEnemyState.entity_id.find(entityId); |
| 267 | if (agentEntity == null) { |
| 268 | throw new Error('GameEnemyState Entity ID not found'); |
| 269 | } |
| 270 | |
| 271 | const agentHerd = ctx.db.gameHerdCache.id.find(agentEntity.herd_id); |
| 272 | if (agentHerd == null) { |
| 273 | throw new Error('GameHerdCache Entity ID not found'); |
| 274 | } |
| 275 | |
| 276 | const agentHerdCoordinates = agentHerd.location; |
| 277 | |
| 278 | moveAgent(ctx, agent, agentHerdCoordinates, currentTimeMs); |
| 279 | } |
| 280 | |
| 281 | export const gameLoopEnemyIa = spacetimedb.reducer( |
| 282 | { name: 'game_loop_enemy_ia' }, |
no test coverage detected
searching dependent graphs…