using ActiveProtect.Models; namespace ActiveProtect.SimulationEnvironment { /// /// 仿真元素的抽象基类,所有仿真中的实体都继承自此类 /// public abstract class SimulationElement(string id, Vector3D position, Orientation orientation, ISimulationManager simulationManager) { /// /// 仿真元素的唯一标识符 /// public string Id { get; set; } = id; /// /// 仿真元素的当前位置 /// public Vector3D Position { get; set; } = position; /// /// 仿真元素的当前朝向 /// public Orientation Orientation { get; set; } = orientation; /// /// 仿真管理器的引用 /// public ISimulationManager SimulationManager { get; set; } = simulationManager; /// /// 仿真元素是否处于活动状态 /// public bool IsActive { get; protected set; } = true; /// /// 更新仿真元素的状态 /// /// 时间步长 public abstract void Update(double deltaTime); /// /// 获取仿真元素的状态信息 /// /// 状态信息字符串 public virtual string GetStatus() { return $"{GetType().Name} {Id} at {Position}, Orientation: {Orientation}, Active: {IsActive}"; } /// /// 发布仿真事件 /// /// 要发布的事件 protected void PublishEvent(SimulationEvent evt) { evt.SenderId = Id; evt.Timestamp = SimulationManager.CurrentTime; SimulationManager.PublishEvent(evt); } /// /// 激活仿真元素 /// protected virtual void Activate() { IsActive = true; PublishEvent(new EntityActivatedEvent { ActivatedEntityId = Id }); } /// /// 停用仿真元素 /// protected virtual void Deactivate() { IsActive = false; PublishEvent(new EntityDeactivatedEvent { DeactivatedEntityId = Id }); } } }