CounterDroneBackend/src/CounterDrone.Core/DefaultScenarios.cs

141 lines
7.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.Generic;
using System.Linq;
using CounterDrone.Core.Models;
using CounterDrone.Core.Services;
namespace CounterDrone.Core
{
/// <summary>
/// 预设想定种子 — 从 DefaultData 预设组装完整想定,写入数据库供前端测试。
/// 首次运行时自动种子,同名想定跳过(幂等)。
/// </summary>
public static class DefaultScenarios
{
public static void Seed(IScenarioService scenario, DefaultData d)
{
// 检测旧格式任务(名称含 [Demo],但 SQL LIKE 中 [] 是通配符,搜索 "Demo"
var existing = scenario.SearchTasks("Demo", null, null, 1, 100);
if (existing.TotalCount > 0)
{
// 版本升级:删除旧 Demo 任务,重新创建
foreach (var t in existing.Items)
scenario.DeleteTask(t.Id);
}
SeedNoDefense(scenario, d);
SeedZoneIntrusion(scenario, d);
SeedPistonWindy(scenario, d);
SeedJetActiveMaterial(scenario, d);
SeedAirBasedWindy(scenario, d);
Seed3DronesAirBased(scenario, d);
}
private static List<Waypoint> R(string routeId, double speed, DefaultData d)
=> d.Routes.First(r => r.Id == routeId).ToWaypoints(speed);
private static void SeedNoDefense(IScenarioService s, DefaultData d)
{
var t = s.CreateTask("[Demo] 无防御-无人机抵达目标", "");
s.SaveScene(t.Id, d.Weather.First(w => w.Id == "sunny-calm").ToCombatScene());
s.SaveTarget(t.Id, d.Targets.First(p => p.Id == "shahed").ToTargetConfig());
s.SaveRoute(t.Id, "default", d.Formations.First(f => f.Id == "single").ToRoutePlan(), R("3km-h400", 600, d));
s.SaveCloudDispersal(t.Id, new CloudDispersal());
s.SaveDeployment(t.Id, new List<EquipmentDeployment>());
s.UpdateStep(t.Id, 5);
}
private static void SeedZoneIntrusion(IScenarioService s, DefaultData d)
{
var t = s.CreateTask("[Demo] 管控区域侵入", "");
s.SaveScene(t.Id, d.Weather.First(w => w.Id == "sunny-calm").ToCombatScene());
s.SaveTarget(t.Id, d.Targets.First(p => p.Id == "electric-scout").ToTargetConfig());
s.SaveRoute(t.Id, "default", d.Formations.First(f => f.Id == "single").ToRoutePlan(), R("3km-h300", 300, d));
s.SaveCloudDispersal(t.Id, new CloudDispersal());
s.SaveDeployment(t.Id, new List<EquipmentDeployment>());
s.SaveControlZones(t.Id, new List<ControlZone>
{
new ControlZone
{
Name = "禁飞区",
VerticesJson = "[{\"X\":1200,\"Y\":0,\"Z\":-200},{\"X\":1800,\"Y\":0,\"Z\":-200},{\"X\":1800,\"Y\":0,\"Z\":200},{\"X\":1200,\"Y\":0,\"Z\":200}]",
MinAltitude = 0, MaxAltitude = 1000,
},
});
s.UpdateStep(t.Id, 5);
}
private static void SeedPistonWindy(IScenarioService s, DefaultData d)
{
var t = s.CreateTask("[Demo] 活塞拦截-西风5ms", "");
var scene = d.Weather.First(w => w.Id == "sunny-calm").ToCombatScene();
scene.WindSpeed = 5;
scene.WindDirection = (int)WindDirection.W;
s.SaveScene(t.Id, scene);
s.SaveTarget(t.Id, d.Targets.First(p => p.Id == "shahed").ToTargetConfig());
s.SaveRoute(t.Id, "default", d.Formations.First(f => f.Id == "single").ToRoutePlan(),
new List<Waypoint> {
new() { PosX = 0, PosY = 500, PosZ = 0, Speed = 200 },
new() { PosX = 7000, PosY = 500, PosZ = 0, Speed = 200 },
});
s.SaveDeployment(t.Id, new List<EquipmentDeployment>
{
d.FireUnits.First(f => f.Id == "ground-light").ToEquipmentDeployment(AerosolType.InertGas, 1, 7000, 0, 50),
});
s.SaveCloudDispersal(t.Id, new CloudDispersal { AerosolType = (int)AerosolType.InertGas, DisperseHeight = 500 });
s.UpdateStep(t.Id, 5);
}
private static void SeedJetActiveMaterial(IScenarioService s, DefaultData d)
{
var t = s.CreateTask("[Demo] 喷气式拦截-活性材料", "");
s.SaveScene(t.Id, d.Weather.First(w => w.Id == "sunny-calm").ToCombatScene());
s.SaveTarget(t.Id, d.Targets.First(p => p.Id == "cruise-missile").ToTargetConfig());
s.SaveRoute(t.Id, "default", d.Formations.First(f => f.Id == "single").ToRoutePlan(),
new List<Waypoint> {
new() { PosX = 0, PosY = 500, PosZ = 0, Speed = 200 },
new() { PosX = 10000, PosY = 500, PosZ = 0, Speed = 200 },
});
s.SaveDeployment(t.Id, new List<EquipmentDeployment>
{
d.FireUnits.First(f => f.Id == "ground-standard").ToEquipmentDeployment(AerosolType.ActiveMaterial, 1, 10000, 0, 50),
});
s.SaveCloudDispersal(t.Id, new CloudDispersal { AerosolType = (int)AerosolType.ActiveMaterial, DisperseHeight = 500 });
s.UpdateStep(t.Id, 5);
}
private static void SeedAirBasedWindy(IScenarioService s, DefaultData d)
{
var t = s.CreateTask("[Demo] 空基拦截-东风5ms", "");
var scene = d.Weather.First(w => w.Id == "sunny-calm").ToCombatScene();
scene.WindSpeed = 5;
scene.WindDirection = (int)WindDirection.E;
s.SaveScene(t.Id, scene);
s.SaveTarget(t.Id, d.Targets.First(p => p.Id == "shahed").ToTargetConfig());
s.SaveRoute(t.Id, "default", d.Formations.First(f => f.Id == "single").ToRoutePlan(), R("20km-h500", 200, d));
s.SaveDeployment(t.Id, new List<EquipmentDeployment>
{
d.FireUnits.First(f => f.Id == "air-standard").ToEquipmentDeployment(AerosolType.InertGas, 3, 12000, 1000, 0),
});
s.SaveCloudDispersal(t.Id, new CloudDispersal { AerosolType = (int)AerosolType.InertGas, DisperseHeight = 500 });
s.UpdateStep(t.Id, 5);
}
private static void Seed3DronesAirBased(IScenarioService s, DefaultData d)
{
var t = s.CreateTask("[Demo] 3架空基编队拦截", "");
s.SaveScene(t.Id, d.Weather.First(w => w.Id == "sunny-calm").ToCombatScene());
var target = d.Targets.First(p => p.Id == "shahed").ToTargetConfig();
target.Quantity = 3;
target.TypicalSpeed = 150;
s.SaveTarget(t.Id, target);
s.SaveRoute(t.Id, "default", d.Formations.First(f => f.Id == "line-3").ToRoutePlan(), R("20km-h500", 200, d));
s.SaveDeployment(t.Id, new List<EquipmentDeployment>
{
d.FireUnits.First(f => f.Id == "air-standard").ToEquipmentDeployment(AerosolType.InertGas, 3, 12000, 1000, 0),
});
s.SaveCloudDispersal(t.Id, new CloudDispersal { AerosolType = (int)AerosolType.InertGas, DisperseHeight = 500 });
s.UpdateStep(t.Id, 5);
}
}
}