各种更新
This commit is contained in:
@@ -11,6 +11,12 @@ namespace WulaFallenEmpire
|
||||
public int aircraftCount = 1; // 起飞后提供的战机数量
|
||||
public ThingDef skyfallerLeaving; // 起飞时的天空坠落者效果
|
||||
|
||||
// 新增:自动发射配置
|
||||
public bool autoLaunchEnabled = false; // 是否启用自动发射
|
||||
public int autoLaunchDelayTicks = 600; // 自动发射延迟(ticks,默认10秒)
|
||||
public bool autoLaunchOnConstruction = true; // 建造完成后自动发射
|
||||
public bool autoLaunchOnPowerOn = false; // 通电时自动发射
|
||||
|
||||
public CompProperties_AircraftHangar()
|
||||
{
|
||||
compClass = typeof(CompAircraftHangar);
|
||||
@@ -21,6 +27,86 @@ namespace WulaFallenEmpire
|
||||
{
|
||||
public CompProperties_AircraftHangar Props => (CompProperties_AircraftHangar)props;
|
||||
|
||||
// 新增:自动发射状态
|
||||
private bool autoLaunchScheduled = false;
|
||||
private int autoLaunchTick = -1;
|
||||
private bool hasLaunched = false;
|
||||
|
||||
public override void PostSpawnSetup(bool respawningAfterLoad)
|
||||
{
|
||||
base.PostSpawnSetup(respawningAfterLoad);
|
||||
|
||||
if (!respawningAfterLoad && Props.autoLaunchEnabled && Props.autoLaunchOnConstruction)
|
||||
{
|
||||
ScheduleAutoLaunch();
|
||||
}
|
||||
}
|
||||
|
||||
public override void PostExposeData()
|
||||
{
|
||||
base.PostExposeData();
|
||||
Scribe_Values.Look(ref autoLaunchScheduled, "autoLaunchScheduled", false);
|
||||
Scribe_Values.Look(ref autoLaunchTick, "autoLaunchTick", -1);
|
||||
Scribe_Values.Look(ref hasLaunched, "hasLaunched", false);
|
||||
}
|
||||
|
||||
public override void CompTick()
|
||||
{
|
||||
base.CompTick();
|
||||
|
||||
// 处理自动发射
|
||||
if (Props.autoLaunchEnabled && !hasLaunched)
|
||||
{
|
||||
HandleAutoLaunch();
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:自动发射处理
|
||||
private void HandleAutoLaunch()
|
||||
{
|
||||
// 检查预定发射
|
||||
if (autoLaunchScheduled && Find.TickManager.TicksGame >= autoLaunchTick)
|
||||
{
|
||||
LaunchAircraft();
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查通电自动发射
|
||||
if (Props.autoLaunchOnPowerOn && IsPoweredOn() && !autoLaunchScheduled)
|
||||
{
|
||||
ScheduleAutoLaunch();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:检查电力状态
|
||||
private bool IsPoweredOn()
|
||||
{
|
||||
var powerComp = parent.GetComp<CompPowerTrader>();
|
||||
return powerComp != null && powerComp.PowerOn;
|
||||
}
|
||||
|
||||
// 新增:预定自动发射
|
||||
private void ScheduleAutoLaunch()
|
||||
{
|
||||
if (hasLaunched || autoLaunchScheduled)
|
||||
return;
|
||||
|
||||
autoLaunchScheduled = true;
|
||||
autoLaunchTick = Find.TickManager.TicksGame + Props.autoLaunchDelayTicks;
|
||||
|
||||
Messages.Message("AircraftAutoLaunchScheduled".Translate(Props.aircraftDef.LabelCap, (Props.autoLaunchDelayTicks / 60f).ToString("F1")), parent, MessageTypeDefOf.NeutralEvent);
|
||||
}
|
||||
|
||||
// 新增:强制立即发射(用于调试或其他系统调用)
|
||||
public void ForceLaunch()
|
||||
{
|
||||
if (!hasLaunched)
|
||||
{
|
||||
LaunchAircraft();
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerable<Gizmo> CompGetGizmosExtra()
|
||||
{
|
||||
foreach (Gizmo gizmo in base.CompGetGizmosExtra())
|
||||
@@ -28,7 +114,11 @@ namespace WulaFallenEmpire
|
||||
yield return gizmo;
|
||||
}
|
||||
|
||||
// 起飞命令
|
||||
// 如果已经发射,不显示任何按钮
|
||||
if (hasLaunched)
|
||||
yield break;
|
||||
|
||||
// 手动发射命令
|
||||
Command_Action launchCommand = new Command_Action
|
||||
{
|
||||
defaultLabel = "LaunchAircraft".Translate(),
|
||||
@@ -46,8 +136,28 @@ namespace WulaFallenEmpire
|
||||
yield return launchCommand;
|
||||
}
|
||||
|
||||
// 新增:切换自动发射状态
|
||||
private void ToggleAutoLaunch()
|
||||
{
|
||||
if (autoLaunchScheduled)
|
||||
{
|
||||
// 取消预定发射
|
||||
autoLaunchScheduled = false;
|
||||
autoLaunchTick = -1;
|
||||
Messages.Message("AutoLaunchCancelled".Translate(), parent, MessageTypeDefOf.NeutralEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 预定发射
|
||||
ScheduleAutoLaunch();
|
||||
}
|
||||
}
|
||||
|
||||
private void LaunchAircraft()
|
||||
{
|
||||
if (hasLaunched)
|
||||
return;
|
||||
|
||||
// 获取全局战机管理器
|
||||
WorldComponent_AircraftManager aircraftManager = Find.World.GetComponent<WorldComponent_AircraftManager>();
|
||||
|
||||
@@ -61,7 +171,7 @@ namespace WulaFallenEmpire
|
||||
aircraftManager.AddAircraft(Props.aircraftDef, Props.aircraftCount, parent.Faction);
|
||||
|
||||
// 显示消息
|
||||
Messages.Message("AircraftLaunched".Translate(Props.aircraftCount, Props.aircraftDef.LabelCap), MessageTypeDefOf.PositiveEvent);
|
||||
Messages.Message("AircraftLaunched".Translate(Props.aircraftCount, Props.aircraftDef.LabelCap), parent, MessageTypeDefOf.PositiveEvent);
|
||||
|
||||
// 创建起飞效果(仅视觉效果)
|
||||
if (Props.skyfallerLeaving != null)
|
||||
@@ -73,6 +183,9 @@ namespace WulaFallenEmpire
|
||||
// 如果没有定义 Skyfaller,直接销毁建筑
|
||||
parent.Destroy();
|
||||
}
|
||||
|
||||
hasLaunched = true;
|
||||
autoLaunchScheduled = false;
|
||||
}
|
||||
|
||||
private void CreateTakeoffEffect()
|
||||
@@ -112,10 +225,30 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
}
|
||||
|
||||
public override void PostExposeData()
|
||||
// 新增:检查是否已经发射
|
||||
public bool HasLaunched => hasLaunched;
|
||||
|
||||
// 新增:获取自动发射状态信息(用于检查字符串)
|
||||
public override string CompInspectStringExtra()
|
||||
{
|
||||
base.PostExposeData();
|
||||
// 不需要保存状态,因为建筑起飞后就销毁了
|
||||
if (hasLaunched)
|
||||
return "AircraftStatusLaunched".Translate();
|
||||
|
||||
if (Props.autoLaunchEnabled)
|
||||
{
|
||||
if (autoLaunchScheduled)
|
||||
{
|
||||
int ticksRemaining = autoLaunchTick - Find.TickManager.TicksGame;
|
||||
float secondsRemaining = ticksRemaining / 60f;
|
||||
return "AutoLaunchScheduled".Translate(secondsRemaining.ToString("F1"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return "AutoLaunchReady".Translate();
|
||||
}
|
||||
}
|
||||
|
||||
return base.CompInspectStringExtra();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user