using System; using System.Collections; using System.Collections.Generic; using BITKit; using BITKit.Entities; using Net.BITKit.Quadtree; using Net.Project.B.Health; using Net.Project.B.Interaction; using Net.Project.B.WorldNode; using Project.B.CharacterController; using Unity.Mathematics; using UnityEngine; namespace Net.Project.B.AI { public class AIOpenDoorService:IDisposable { private readonly IWorldInteractionService _interactionService; private readonly QuadTreeService _quadTreeService; private readonly IEntitiesService _entitiesService; private readonly ITicker _ticker; public AIOpenDoorService(QuadTreeService quadTreeService, IEntitiesService entitiesService, ITicker ticker, IWorldInteractionService interactionService) { _quadTreeService = quadTreeService; _entitiesService = entitiesService; _ticker = ticker; _interactionService = interactionService; _ticker.Add(OnTick); } private void OnTick(float obj) { foreach (var (entity,healthComponent,aiBlackBoard,characterController) in _entitiesService.QueryComponents()) { if(healthComponent.HealthPoint<0)continue; foreach (var id in _quadTreeService.Quadtree.Query(characterController.ViewPosition.xz,1)) { if (_entitiesService.Entities[id].ServiceProvider.QueryComponents(out UnityDoorNode doorNode, out IWorldInteractable interactable)) { ; if(doorNode.InteractionType is not WorldInteractionProcess.None)continue; if(doorNode.State is UnityDoorState.Opened)continue; _interactionService.Interaction(entity, interactable); } break; } } } public void Dispose() { _ticker.Remove(OnTick); } } }