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