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