This commit is contained in:
Tourswen
2025-11-18 00:36:33 +08:00
parent 5a7e53fa4c
commit 710eca55d4
70 changed files with 437 additions and 198 deletions

View File

@@ -197,28 +197,6 @@ namespace WulaFallenEmpire
return Mathf.Clamp01(currentFadeInTime / fadeInDuration);
}
}
// 修改后的淡出透明度属性
public float FadeOutAlpha
{
get
{
if (!useFadeOut || !fadeOutStarted) return 1f;
if (fadeOutCompleted) return 0f;
return Mathf.Clamp01(1f - (currentFadeOutTime / fadeOutDuration));
}
}
// 修改后的总体透明度属性
public float OverallAlpha
{
get
{
if (!useFadeEffects) return 1f;
return FadeInAlpha * FadeOutAlpha;
}
}
// 新增:计算剩余飞行时间(秒)
public float RemainingFlightTime
{
@@ -228,6 +206,151 @@ namespace WulaFallenEmpire
return remainingProgress / (flightSpeed * 0.001f) * (1f / 60f);
}
}
// 修改后的紧急销毁方法 - 急速加速版本
public void EmergencyDestroy()
{
if (Destroyed || hasCompleted) return;
// 计算剩余进度
float remainingProgress = 1f - currentProgress;
// 计算需要的速度确保在1秒内完成剩余进度
// 每帧增加 flightSpeed * 0.0011秒60帧所以需要remainingProgress = flightSpeed * 0.001 * 60
// 因此flightSpeed = remainingProgress / (0.001 * 60) = remainingProgress / 0.06
float requiredSpeed = remainingProgress / 0.06f;
// 设置新的飞行速度确保至少是当前速度的2倍
flightSpeed = Mathf.Max(requiredSpeed, flightSpeed * 2f);
// 标记为紧急销毁状态
hasCompleted = false; // 确保可以继续飞行
Log.Message($"FlyOver emergency destroy: accelerating to complete in 1 second. " +
$"Current progress: {currentProgress:F2}, Required speed: {requiredSpeed:F2}, " +
$"Actual speed: {flightSpeed:F2}");
}
// 修改后的淡出透明度属性 - 紧急销毁时强制启用淡出
public float FadeOutAlpha
{
get
{
// 如果已经开始了淡出(包括紧急销毁),就应用淡出效果
if (!fadeOutStarted) return 1f;
if (fadeOutCompleted) return 0f;
return Mathf.Clamp01(1f - (currentFadeOutTime / fadeOutDuration));
}
}
// 修改后的总体透明度属性 - 紧急销毁时强制计算淡出
public float OverallAlpha
{
get
{
if (!useFadeEffects && !fadeOutStarted) return 1f;
return FadeInAlpha * FadeOutAlpha;
}
}
// 修改后的 Tick 方法,优化紧急销毁逻辑
protected override void Tick()
{
base.Tick();
if (!hasStarted || hasCompleted)
return;
// 更新进场动画
if (useApproachAnimation && !approachCompleted)
{
currentApproachTime += 1f / 60f;
if (currentApproachTime >= approachDuration)
{
approachCompleted = true;
currentApproachTime = approachDuration;
}
}
// 更新淡入效果(仅在启用时)
if (useFadeIn && !fadeInCompleted)
{
currentFadeInTime += 1f / 60f;
if (currentFadeInTime >= fadeInDuration)
{
fadeInCompleted = true;
currentFadeInTime = fadeInDuration;
}
}
// 更新飞行进度
currentProgress += flightSpeed * 0.001f;
// 检查是否应该开始淡出(仅在启用时且未紧急销毁)
if (useFadeOut && !fadeOutStarted && currentProgress >= fadeOutStartProgress)
{
StartFadeOut();
}
// 更新淡出效果(仅在启用时)
if (useFadeOut && fadeOutStarted && !fadeOutCompleted)
{
currentFadeOutTime += 1f / 60f;
if (currentFadeOutTime >= fadeOutDuration)
{
fadeOutCompleted = true;
currentFadeOutTime = fadeOutDuration;
}
}
// 更新当前位置
UpdatePosition();
// 维持飞行音效
UpdateFlightSound();
// 检查是否到达终点
if (currentProgress >= 1f)
{
CompleteFlyOver();
return; // 立即返回,避免后续处理
}
// 生成飞行轨迹特效
CreateFlightEffects();
}
// 修改后的 CompleteFlyOver 方法,添加紧急销毁处理
private void CompleteFlyOver()
{
if (hasCompleted) return;
hasCompleted = true;
currentProgress = 1f;
// 生成内容物(如果需要)
if (spawnContentsOnImpact && innerContainer.Any)
{
SpawnContents();
}
// 播放完成音效
if (def.skyfaller?.impactSound != null)
{
def.skyfaller.impactSound.PlayOneShot(
SoundInfo.InMap(new TargetInfo(endPosition, base.Map)));
}
Log.Message($"FlyOver completed at {endPosition}");
// 立即销毁
Destroy();
}
// 修改后的 UpdatePosition 方法,添加安全检查
private void UpdatePosition()
{
if (hasCompleted) return;
Vector3 currentWorldPos = Vector3.Lerp(startPosition.ToVector3(), endPosition.ToVector3(), currentProgress);
IntVec3 newPos = currentWorldPos.ToIntVec3();
if (newPos != base.Position && newPos.InBounds(base.Map))
{
base.Position = newPos;
}
}
// 新增:计算基于剩余距离的淡出持续时间
private float CalculateDynamicFadeOutDuration()
@@ -337,63 +460,6 @@ namespace WulaFallenEmpire
}
}
}
protected override void Tick()
{
base.Tick();
if (!hasStarted || hasCompleted)
return;
// 更新进场动画
if (useApproachAnimation && !approachCompleted)
{
currentApproachTime += 1f / 60f;
if (currentApproachTime >= approachDuration)
{
approachCompleted = true;
currentApproachTime = approachDuration;
Log.Message("FlyOver approach animation completed");
}
}
// 更新淡入效果(仅在启用时)
if (useFadeIn && !fadeInCompleted)
{
currentFadeInTime += 1f / 60f;
if (currentFadeInTime >= fadeInDuration)
{
fadeInCompleted = true;
currentFadeInTime = fadeInDuration;
}
}
// 更新飞行进度
currentProgress += flightSpeed * 0.001f;
// 检查是否应该开始淡出(仅在启用时)
if (useFadeOut && !fadeOutStarted && currentProgress >= fadeOutStartProgress)
{
StartFadeOut();
}
// 更新淡出效果(仅在启用时)
if (useFadeOut && fadeOutStarted && !fadeOutCompleted)
{
currentFadeOutTime += 1f / 60f;
if (currentFadeOutTime >= fadeOutDuration)
{
fadeOutCompleted = true;
currentFadeOutTime = fadeOutDuration;
Log.Message("FlyOver fade out completed");
}
}
// 更新当前位置
UpdatePosition();
// 维持飞行音效(在淡出时逐渐降低音量)
UpdateFlightSound();
// 检查是否到达终点
if (currentProgress >= 1f)
{
CompleteFlyOver();
}
// 生成飞行轨迹特效(在淡出时减少特效)
CreateFlightEffects();
}
// 新增:开始淡出效果
private void StartFadeOut()
{
@@ -405,69 +471,21 @@ namespace WulaFallenEmpire
Log.Message($"FlyOver started fade out at progress {currentProgress:F2}, duration: {fadeOutDuration:F2}s, remaining time: {RemainingFlightTime:F2}s");
}
private void UpdatePosition()
{
Vector3 currentWorldPos = Vector3.Lerp(startPosition.ToVector3(), endPosition.ToVector3(), currentProgress);
IntVec3 newPos = currentWorldPos.ToIntVec3();
if (newPos != base.Position && newPos.InBounds(base.Map))
{
base.Position = newPos;
}
}
// 修改后的音效更新方法
// 修改后的 UpdateFlightSound 方法,添加紧急销毁时的音效处理
private void UpdateFlightSound()
{
if (flightSoundPlaying != null)
{
if (useFadeOut && fadeOutStarted)
// 紧急销毁时提高音效音量或频率
if (flightSoundPlaying != null && flightSoundPlaying.externalParams != null)
{
// 淡出时逐渐降低音效音量
flightSoundPlaying.externalParams["VolumeFactor"] = FadeOutAlpha;
// 可以根据需要调整紧急销毁时的音效参数
flightSoundPlaying.externalParams["VolumeFactor"] = 1f; // 保持最大音量
}
flightSoundPlaying?.Maintain();
}
}
private void CompleteFlyOver()
{
hasCompleted = true;
currentProgress = 1f;
// 生成内容物(如果需要)
if (spawnContentsOnImpact && innerContainer.Any)
{
SpawnContents();
}
// 播放完成音效
if (def.skyfaller?.impactSound != null)
{
def.skyfaller.impactSound.PlayOneShot(
SoundInfo.InMap(new TargetInfo(endPosition, base.Map)));
}
Log.Message($"FlyOver completed at {endPosition}");
// 销毁自身
Destroy();
}
// 修改后的紧急销毁方法
public void EmergencyDestroy()
{
if (useFadeOut && !fadeOutStarted)
{
// 如果还没有开始淡出,使用默认淡出时间
fadeOutStarted = true;
fadeOutDuration = defaultFadeOutDuration;
Log.Message($"FlyOver emergency destroy with default fade out: {defaultFadeOutDuration}s");
}
// 设置标记,下一帧会处理淡出
hasCompleted = true;
}
private void SpawnContents()
{
foreach (Thing thing in innerContainer)
@@ -480,19 +498,21 @@ namespace WulaFallenEmpire
innerContainer.Clear();
}
// 修改后的特效生成方法
// 修改后的 CreateFlightEffects 方法,添加紧急销毁时的特效增强
private void CreateFlightEffects()
{
// 在飞行轨迹上生成粒子效果
if (Rand.MTBEventOccurs(0.5f, 1f, 1f) && def.skyfaller?.motesPerCell > 0 && !fadeOutCompleted)
if (Rand.MTBEventOccurs(0.5f, 1f, 1f) && def.skyfaller?.motesPerCell > 0)
{
Vector3 effectPos = DrawPos;
effectPos.y = AltitudeLayer.MoteOverhead.AltitudeFor();
// 淡出时减少粒子效果强度
float effectIntensity = (useFadeOut && fadeOutStarted) ? FadeOutAlpha : 1f;
// 紧急销毁时增强粒子效果
float effectIntensity = 1f;
FleckMaker.ThrowSmoke(effectPos, base.Map, 1f * effectIntensity);
// 可选:根据速度生成更多效果
if (flightSpeed > 2f && !(useFadeOut && fadeOutStarted))
// 紧急销毁时生成更多效果
if (flightSpeed > 2f)
{
FleckMaker.ThrowAirPuffUp(effectPos, base.Map);
}

View File

@@ -31,7 +31,7 @@ namespace WulaFallenEmpire
if (aircraftManager == null)
{
Log.Error("AircraftManagerNotFound".Translate());
Log.Error("WULA_AircraftManagerNotFound".Translate());
return;
}
@@ -39,13 +39,13 @@ namespace WulaFallenEmpire
if (aircraftManager.TryUseAircraft(Props.requiredAircraftType, Props.aircraftsPerUse, parent.pawn.Faction, Props.aircraftCooldownTicks))
{
// 成功消耗战机,发送消息
Messages.Message("AircraftStrikeInitiated".Translate(Props.requiredAircraftType.LabelCap), MessageTypeDefOf.PositiveEvent);
Log.Message("AircraftStrikeSuccess".Translate(Props.aircraftsPerUse, Props.requiredAircraftType.LabelCap));
Messages.Message("WULA_AircraftStrikeInitiated".Translate(Props.requiredAircraftType.LabelCap), MessageTypeDefOf.PositiveEvent);
Log.Message("WULA_AircraftStrikeSuccess".Translate(Props.aircraftsPerUse, Props.requiredAircraftType.LabelCap));
}
else
{
Messages.Message("NoAvailableAircraft".Translate(Props.requiredAircraftType.LabelCap), MessageTypeDefOf.NegativeEvent);
Log.Warning("AircraftStrikeFailed".Translate(Props.requiredAircraftType.LabelCap, parent.pawn.Faction?.Name ?? "UnknownFaction".Translate()));
Messages.Message("WULA_NoAvailableAircraft".Translate(Props.requiredAircraftType.LabelCap), MessageTypeDefOf.NegativeEvent);
Log.Warning("WULA_AircraftStrikeFailed".Translate(Props.requiredAircraftType.LabelCap, parent.pawn.Faction?.Name ?? "WULA_UnknownFaction".Translate()));
}
}
@@ -59,6 +59,44 @@ namespace WulaFallenEmpire
aircraftManager.HasAvailableAircraft(Props.requiredAircraftType, Props.aircraftsPerUse, parent.pawn.Faction);
}
// 关键修改:重写 GizmoDisabled 方法,在不满足条件时禁用按钮
public override bool GizmoDisabled(out string reason)
{
// 先检查基础条件
if (base.GizmoDisabled(out reason))
return true;
// 检查战机可用性
WorldComponent_AircraftManager aircraftManager = Find.World.GetComponent<WorldComponent_AircraftManager>();
if (aircraftManager == null)
{
reason = "WULA_AircraftSystemNotReady".Translate();
return true;
}
if (!aircraftManager.HasAvailableAircraft(Props.requiredAircraftType, Props.aircraftsPerUse, parent.pawn.Faction))
{
int available = aircraftManager.GetAvailableAircraftCount(Props.requiredAircraftType, parent.pawn.Faction);
int total = aircraftManager.GetTotalAircraftCount(Props.requiredAircraftType, parent.pawn.Faction);
if (available == 0 && total == 0)
{
reason = "WULA_NoAvailableAircraftType".Translate(Props.requiredAircraftType.LabelCap);
}
else if (available < Props.aircraftsPerUse)
{
reason = "WULA_AircraftInsufficient".Translate(Props.requiredAircraftType.LabelCap, available, Props.aircraftsPerUse);
}
else
{
reason = "WULA_AircraftOnCooldown".Translate(Props.requiredAircraftType.LabelCap);
}
return true;
}
return false;
}
public override string ExtraLabelMouseAttachment(LocalTargetInfo target)
{
WorldComponent_AircraftManager aircraftManager = Find.World.GetComponent<WorldComponent_AircraftManager>();
@@ -73,9 +111,9 @@ namespace WulaFallenEmpire
string cooldownSymbols = GetAircraftSymbols(onCooldown, "◇");
StringBuilder sb = new StringBuilder();
sb.AppendLine("AvailableAircraft".Translate(Props.requiredAircraftType.LabelCap, availableSymbols));
sb.AppendLine("CooldownAircraft".Translate(cooldownSymbols));
sb.Append("CostPerUse".Translate(Props.aircraftsPerUse));
sb.AppendLine("WULA_AvailableAircraft".Translate(availableSymbols));
sb.AppendLine("WULA_CooldownAircraft".Translate(cooldownSymbols));
sb.Append("WULA_CostPerUse".Translate(Props.aircraftsPerUse));
return sb.ToString();
}
@@ -86,18 +124,16 @@ namespace WulaFallenEmpire
// 生成飞机符号表示
private string GetAircraftSymbols(int count, string symbol)
{
if (count <= 0) return "—"; // 无飞机时显示破折号
if (count <= 0) return "—";
StringBuilder sb = new StringBuilder();
int displayCount = count;
// 如果数量过多,用数字+符号表示
if (count > 10)
{
return $"{count}{symbol}";
}
// 直接显示符号
for (int i = 0; i < displayCount; i++)
{
sb.Append(symbol);
@@ -117,7 +153,7 @@ namespace WulaFallenEmpire
{
if (throwMessages)
{
Messages.Message("NoAircraftForStrike".Translate(Props.requiredAircraftType.LabelCap), MessageTypeDefOf.RejectInput);
Messages.Message("WULA_NoAircraftForStrike".Translate(), MessageTypeDefOf.RejectInput);
}
return false;
}
@@ -140,11 +176,12 @@ namespace WulaFallenEmpire
float cooldownHours = TicksToHours(Props.aircraftCooldownTicks);
StringBuilder sb = new StringBuilder();
sb.AppendLine("AircraftStatusTooltip".Translate());
sb.AppendLine("• " + "TotalAircraft".Translate(total));
sb.AppendLine("• " + "ReadyAircraft".Translate(available));
sb.AppendLine("• " + "CooldownAircraft".Translate(onCooldown));
sb.AppendLine("AircraftAbilityDescription".Translate(Props.requiredAircraftType.LabelCap, Props.aircraftsPerUse, cooldownHours.ToString("F1")));
sb.AppendLine("WULA_AircraftStatus".Translate());
sb.AppendLine("WULA_TotalAircraft".Translate(total));
sb.AppendLine("WULA_ReadyAircraft".Translate(available));
sb.AppendLine("WULA_CooldownAircraftCount".Translate(onCooldown));
sb.AppendLine("WULA_AircraftRequirement".Translate(Props.requiredAircraftType.LabelCap, Props.aircraftsPerUse));
sb.AppendLine("WULA_CooldownTime".Translate(cooldownHours.ToString("F1")));
return sb.ToString();
}
@@ -155,7 +192,6 @@ namespace WulaFallenEmpire
// 将 tick 转换为小时
private float TicksToHours(int ticks)
{
// RimWorld 中 1 小时 = 2500 tick
return ticks / 2500f;
}
}

View File

@@ -0,0 +1,57 @@
using System.Collections.Generic;
using RimWorld;
using Verse;
namespace WulaFallenEmpire
{
// CompProperties 定义
public class CompProperties_DestroyFlyOverByFacilities : CompProperties_AbilityEffect
{
public CompProperties_DestroyFlyOverByFacilities()
{
compClass = typeof(CompAbilityEffect_DestroyFlyOverByFacilities);
}
}
// Comp 实现
public class CompAbilityEffect_DestroyFlyOverByFacilities : CompAbilityEffect
{
public new CompProperties_DestroyFlyOverByFacilities Props => (CompProperties_DestroyFlyOverByFacilities)props;
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
{
base.Apply(target, dest);
if (parent.pawn?.Map == null) return;
// 销毁所有 FlyOver 物体
DestroyAllFlyOvers();
}
// 销毁所有 FlyOver
private void DestroyAllFlyOvers()
{
List<Thing> flyOvers = new List<Thing>();
// 获取地图上所有的 FlyOver
foreach (Thing thing in parent.pawn.Map.listerThings.AllThings)
{
if (thing is FlyOver flyOver)
{
flyOvers.Add(flyOver);
}
}
// 销毁找到的 FlyOver
foreach (FlyOver flyOver in flyOvers)
{
flyOver.EmergencyDestroy();
}
if (flyOvers.Count > 0)
{
Messages.Message($"WULA_DestroyFlyOver".Translate(), parent.pawn, MessageTypeDefOf.PositiveEvent);
}
}
}
}

View File

@@ -127,6 +127,7 @@
<Compile Include="Flyover\WULA_AircraftHangar\CompAircraftHangar.cs" />
<Compile Include="Flyover\WULA_AircraftHangar\WorldComponent_AircraftManager.cs" />
<Compile Include="Flyover\WULA_BlockedByFlyOverFacility\CompAbilityEffect_BlockedByFlyOverFacility.cs" />
<Compile Include="Flyover\WULA_DestroyFlyOverByFacilities\CompProperties_DestroyFlyOverByFacilities.cs" />
<Compile Include="Flyover\WULA_FlyOverDropPod\CompProperties_FlyOverDropPod.cs" />
<Compile Include="Flyover\WULA_FlyOverEscort\CompFlyOverEscort.cs" />
<Compile Include="Flyover\WULA_FlyOverEscort\CompProperties_FlyOverEscort.cs" />