| 253 | private const int MAX_MOVE_TIMESTAMPS = 20; |
| 254 | |
| 255 | public static void MoveAgent( |
| 256 | ReducerContext ctx, |
| 257 | ref GameEnemyAiAgentState agent, |
| 258 | SmallHexTile agent_coord, |
| 259 | ulong current_time_ms |
| 260 | ) |
| 261 | { |
| 262 | ulong entity_id = agent.entity_id; |
| 263 | |
| 264 | GameEnemyState enemy = |
| 265 | ctx.Db.game_enemy_state.entity_id.Find(entity_id) |
| 266 | ?? throw new Exception("GameEnemyState Entity ID not found"); |
| 267 | ctx.Db.game_enemy_state.entity_id.Update(enemy); |
| 268 | |
| 269 | agent.next_action_timestamp = current_time_ms + 2000; |
| 270 | |
| 271 | agent.last_move_timestamps.Add(current_time_ms); |
| 272 | if (agent.last_move_timestamps.Count > MAX_MOVE_TIMESTAMPS) |
| 273 | { |
| 274 | agent.last_move_timestamps.RemoveAt(0); |
| 275 | } |
| 276 | |
| 277 | GameTargetableState targetable = |
| 278 | ctx.Db.game_targetable_state.entity_id.Find(entity_id) |
| 279 | ?? throw new Exception("GameTargetableState Entity ID not found"); |
| 280 | int new_hash = targetable.quad.GetHashCode(); |
| 281 | targetable.quad = new_hash; |
| 282 | ctx.Db.game_targetable_state.entity_id.Update(targetable); |
| 283 | |
| 284 | if (ctx.Db.game_live_targetable_state.entity_id.Delete(entity_id)) |
| 285 | { |
| 286 | ctx.Db.game_live_targetable_state.Insert(new(entity_id, new_hash)); |
| 287 | } |
| 288 | |
| 289 | GameMobileEntityState mobile_entity = |
| 290 | ctx.Db.game_mobile_entity_state.entity_id.Find(entity_id) |
| 291 | ?? throw new Exception("GameMobileEntityState Entity ID not found"); |
| 292 | mobile_entity.location_x += 1; |
| 293 | mobile_entity.location_y += 1; |
| 294 | mobile_entity.timestamp = agent.next_action_timestamp; |
| 295 | |
| 296 | ctx.Db.game_enemy_ai_agent_state.entity_id.Update(agent); |
| 297 | |
| 298 | ctx.Db.game_mobile_entity_state.entity_id.Update(mobile_entity); |
| 299 | } |
| 300 | |
| 301 | public static void AgentLoop( |
| 302 | ReducerContext ctx, |