74 lines
2.5 KiB
C#
74 lines
2.5 KiB
C#
using System;
|
|
using ActiveProtect.SimulationEnvironment;
|
|
|
|
namespace ActiveProtect.Models
|
|
{
|
|
public class LaserJammer
|
|
{
|
|
private readonly Tank tank;
|
|
public bool IsJamming { get; private set; }
|
|
public double JammingPower { get; private set; }
|
|
private double jammingCooldown = 0;
|
|
private const double MaxJammingCooldown = 5.0;
|
|
private const double MaxJammingPower = 10000.0; // 降低最大干扰功率
|
|
private const double InitialJammingPower = 4000.0; // 设置初始干扰功率
|
|
private const double PowerIncreaseRate = 2000.0; // 每秒增加的功率
|
|
|
|
public LaserJammer(Tank tank)
|
|
{
|
|
this.tank = tank;
|
|
IsJamming = false;
|
|
JammingPower = 0;
|
|
tank.SimulationManager.SubscribeToEvent<LaserIlluminationStopEvent>(OnLaserIlluminationStop);
|
|
}
|
|
|
|
public void Update(double deltaTime)
|
|
{
|
|
if (IsJamming)
|
|
{
|
|
// 逐渐增加干扰功率
|
|
JammingPower = Math.Min(JammingPower + PowerIncreaseRate * deltaTime, MaxJammingPower);
|
|
|
|
jammingCooldown += deltaTime;
|
|
if (jammingCooldown >= MaxJammingCooldown)
|
|
{
|
|
StopJamming();
|
|
}
|
|
|
|
Console.WriteLine($"坦克 {tank.Id} 的激光干扰器正在工作,当前功率: {JammingPower:F2}");
|
|
}
|
|
else if (tank.LaserWarner.IsAlarming)
|
|
{
|
|
StartJamming();
|
|
}
|
|
}
|
|
|
|
private void StartJamming()
|
|
{
|
|
IsJamming = true;
|
|
JammingPower = InitialJammingPower; // 从初始功率开始
|
|
jammingCooldown = 0;
|
|
Console.WriteLine($"坦克 {tank.Id} 的激光干扰器开始工作,初始功率: {JammingPower:F2}");
|
|
}
|
|
|
|
private void StopJamming()
|
|
{
|
|
if (IsJamming)
|
|
{
|
|
IsJamming = false;
|
|
JammingPower = 0;
|
|
jammingCooldown = 0;
|
|
Console.WriteLine($"坦克 {tank.Id} 的激光干扰器停止工作");
|
|
}
|
|
}
|
|
|
|
private void OnLaserIlluminationStop(LaserIlluminationStopEvent evt)
|
|
{
|
|
if (evt.TargetId == tank.Id)
|
|
{
|
|
Console.WriteLine($"坦克 {tank.Id} 接收到激光照射停止事件,停止干扰");
|
|
StopJamming();
|
|
}
|
|
}
|
|
}
|
|
} |