This commit is contained in:
2026-02-24 12:02:38 +08:00
parent 1af5f0c1d8
commit 96bc1d4c5a
57 changed files with 6595 additions and 1170 deletions

View File

@@ -41,10 +41,10 @@ namespace WulaFallenEmpire
}
// Patch 2: Specifically for Verb_ShootWithOffset.
[HarmonyPatch(typeof(Verb_ShootWithOffset), "TryCastShot")]
public static class Patch_Verb_ShootWithOffset_TryCastShot
[HarmonyPatch(typeof(Verb_Shoot), "TryCastShot")]
public static class Patch_Verb_Shoot_TryCastShot
{
public static void Postfix(Verb_ShootWithOffset __instance, bool __result)
public static void Postfix(Verb_Shoot __instance, bool __result)
{
if (!__result) return;
if (__instance.CasterPawn == null || __instance.EquipmentSource == null) return;
@@ -58,45 +58,26 @@ namespace WulaFallenEmpire
var disappearsComp = hediff.TryGetComp<HediffComp_Disappears>();
disappearsComp?.ResetElapsedTicks();
}
}
// Patch 3: Specifically for our new Verb_ShootShotgunWithOffset.
[HarmonyPatch(typeof(Verb_ShootShotgunWithOffset), "TryCastShot")]
public static class Patch_Verb_ShootShotgunWithOffset_TryCastShot
{
public static void Postfix(Verb_ShootShotgunWithOffset __instance, bool __result)
// Patch 2: Specifically for Verb_ShootWithOffset.
[HarmonyPatch(typeof(Verb_ShootWithOffset), "TryCastShot")]
public static class Patch_ShootWithOffset_TryCastShot
{
if (!__result) return;
if (__instance.CasterPawn == null || __instance.EquipmentSource == null) return;
public static void Postfix(Verb_ShootWithOffset __instance, bool __result)
{
if (!__result) return;
if (__instance.CasterPawn == null || __instance.EquipmentSource == null) return;
CompGiveHediffOnShot comp = __instance.EquipmentSource.GetComp<CompGiveHediffOnShot>();
if (comp == null || comp.Props.hediffDef == null) return;
CompGiveHediffOnShot comp = __instance.EquipmentSource.GetComp<CompGiveHediffOnShot>();
if (comp == null || comp.Props.hediffDef == null) return;
Hediff hediff = __instance.CasterPawn.health.GetOrAddHediff(comp.Props.hediffDef);
hediff.Severity += comp.Props.severityToAdd;
Hediff hediff = __instance.CasterPawn.health.GetOrAddHediff(comp.Props.hediffDef);
hediff.Severity += comp.Props.severityToAdd;
var disappearsComp = hediff.TryGetComp<HediffComp_Disappears>();
disappearsComp?.ResetElapsedTicks();
var disappearsComp = hediff.TryGetComp<HediffComp_Disappears>();
disappearsComp?.ResetElapsedTicks();
}
}
}
// 新增补丁:为 Verb_ShootBeamExplosive 添加支持
[HarmonyPatch(typeof(Verb_ShootBeamExplosive), "TryCastShot")]
public static class Patch_Verb_ShootBeamExplosive_TryCastShot
{
public static void Postfix(Verb_ShootBeamExplosive __instance, bool __result)
{
if (!__result) return;
if (__instance.CasterPawn == null || __instance.EquipmentSource == null) return;
CompGiveHediffOnShot comp = __instance.EquipmentSource.GetComp<CompGiveHediffOnShot>();
if (comp == null || comp.Props.hediffDef == null) return;
Hediff hediff = __instance.CasterPawn.health.GetOrAddHediff(comp.Props.hediffDef);
hediff.Severity += comp.Props.severityToAdd;
var disappearsComp = hediff.TryGetComp<HediffComp_Disappears>();
disappearsComp?.ResetElapsedTicks();
}
}
}
}

View File

@@ -0,0 +1,39 @@
// File: CompMechOnlyWeapon.cs
using System.Collections.Generic;
using Verse;
namespace WulaFallenEmpire
{
/// <summary>
/// 简单的机甲专用武器组件
/// </summary>
public class CompMechOnlyWeapon : ThingComp
{
public List<ThingDef> allowedMechRaces;
public override void Initialize(CompProperties props)
{
base.Initialize(props);
allowedMechRaces = ((CompProperties_MechOnlyWeapon)props).allowedMechRaces;
}
/// <summary>
/// 检查机甲是否可以装备此武器
/// </summary>
public bool CanBeEquippedByMech(Pawn mech)
{
if (mech == null || mech.def == null) return false;
return allowedMechRaces != null && allowedMechRaces.Contains(mech.def);
}
}
public class CompProperties_MechOnlyWeapon : CompProperties
{
public List<ThingDef> allowedMechRaces = new List<ThingDef>();
public CompProperties_MechOnlyWeapon()
{
compClass = typeof(CompMechOnlyWeapon);
}
}
}

View File

@@ -127,16 +127,10 @@ namespace WulaFallenEmpire
// 播放声音
Props.sound.PlayOneShot(soundInfo);
soundPlayed = true;
// 调试日志
if (Prefs.DevMode)
{
WulaLog.Debug($"Played spawn sound: {Props.sound.defName} for {parent.Label} at {parent.Position}");
}
}
catch (System.Exception ex)
{
WulaLog.Debug($"Error playing spawn sound for {parent.Label}: {ex}");
Log.Error($"Error playing spawn sound for {parent.Label}: {ex}");
}
}
@@ -162,10 +156,6 @@ namespace WulaFallenEmpire
{
PlaySound();
}
else
{
WulaLog.Debug("No sound defined for CompPlaySoundOnSpawn");
}
}
};