using ActiveProtect.Simulation;
using System;
using ActiveProtect.Utility;
namespace ActiveProtect.Models
{
///
/// 表示仿真中的坦克
///
public class Tank : SimulationElement
{
///
/// 当前装甲值
///
public double CurrentArmor { get; private set; }
///
/// 坦克配置
///
public TankProperties TankProperties { get; private set; }
///
/// 构造函数
///
/// 坦克配置
/// 仿真管理器
public Tank(TankProperties properties, ISimulationManager simulationManager)
: base(properties.Id, properties.InitialPosition, properties.InitialOrientation, properties.InitialSpeed, simulationManager)
{
TankProperties = properties;
Speed = TankProperties.InitialSpeed;
CurrentArmor = TankProperties.MaxArmor;
IsActive = false;
}
///
/// 更新坦克状态
///
/// 时间步长(秒)
public override void Update(double deltaTime)
{
if (!IsActive) return;
// 辐射事件发布
PublishRadiationEvent();
UpdatePosition(deltaTime);
}
///
/// 辐射事件发布
///
private void PublishRadiationEvent()
{
SimulationManager.PublishEvent(new TankRadiationEvent
{
LaserReflectionIntensity = 100,
MillimeterWaveReflectionIntensity = 100,
MillimeterWaveRadiationTemperature = TankProperties.MillimeterWaveRadiationTemperature,
InfraredRadiationIntensity = TankProperties.InfraredRadiationIntensity,
SenderId = Id
});
}
///
/// 更新坦克位置
///
/// 时间步长(秒)
private void UpdatePosition(double deltaTime)
{
Vector3D direction = Orientation.ToVector();
Vector3D movement = direction * Speed * deltaTime;
Position += movement;
}
///
/// 坦克受到伤害
///
/// 伤害值
/// 是否为导弹造成的伤害
public void TakeDamage(double damage, bool isMissileDamage = false)
{
if (isMissileDamage)
{
damage = CurrentArmor * 0.5;
}
CurrentArmor = Math.Max(0, CurrentArmor - damage);
if (CurrentArmor <= 0)
{
Deactivate();
}
}
///
/// 获取坦克状态信息
///
/// 坦克状态字符串
public override string GetStatus()
{
return $"坦克 {Id}:\n" +
$" 位置: {Position}\n" +
$" 速度: {Speed:F2}/{TankProperties.MaxSpeed:F2}\n" +
$" 装甲: {CurrentArmor:F2}/{TankProperties.MaxArmor:F2}\n" +
$" 状态: {(IsActive ? "活动" : "已销毁")}\n";
}
}
}