修复寿命问题,写完虫巢袭击系统,去除菌毯减速和原始恐惧
This commit is contained in:
Binary file not shown.
@@ -1,13 +1,33 @@
|
||||
{
|
||||
"Version": 1,
|
||||
"WorkspaceRootPath": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\",
|
||||
"WorkspaceRootPath": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\",
|
||||
"Documents": [
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|d:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\storyteller\\incidentworker_customraid.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|e:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\pawn_comps\\ara_nodeswarmlifetime\\compnodeswarmlifetime.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:pawn_comps\\ara_nodeswarmlifetime\\compnodeswarmlifetime.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|e:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\hediffs\\hediffcomp_lifespandisplay.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:hediffs\\hediffcomp_lifespandisplay.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|e:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\hediffs\\hediffcomp_temperature.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:hediffs\\hediffcomp_temperature.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|e:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\hediffs\\hediffcomp_spawnpawnonremoved.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:hediffs\\hediffcomp_spawnpawnonremoved.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|e:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\hediffgiver\\hediffgiver_nonplayerfaction.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:hediffgiver\\hediffgiver_nonplayerfaction.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\storyteller\\incidentworker_customraid.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:storyteller\\incidentworker_customraid.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|d:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\storyteller\\raidwavedef.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\storyteller\\raidwavedef.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
||||
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:storyteller\\raidwavedef.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
||||
}
|
||||
],
|
||||
@@ -18,7 +38,7 @@
|
||||
"DocumentGroups": [
|
||||
{
|
||||
"DockedWidth": 200,
|
||||
"SelectedChildIndex": 2,
|
||||
"SelectedChildIndex": 1,
|
||||
"Children": [
|
||||
{
|
||||
"$type": "Bookmark",
|
||||
@@ -26,29 +46,91 @@
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 1,
|
||||
"Title": "RaidWaveDef.cs",
|
||||
"DocumentMoniker": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Storyteller\\RaidWaveDef.cs",
|
||||
"RelativeDocumentMoniker": "Storyteller\\RaidWaveDef.cs",
|
||||
"ToolTip": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Storyteller\\RaidWaveDef.cs*",
|
||||
"RelativeToolTip": "Storyteller\\RaidWaveDef.cs*",
|
||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAkAAAA9AAAAAAAAAA==",
|
||||
"DocumentIndex": 0,
|
||||
"Title": "CompNodeSwarmLifetime.cs",
|
||||
"DocumentMoniker": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Pawn_Comps\\ARA_NodeSwarmLifetime\\CompNodeSwarmLifetime.cs",
|
||||
"RelativeDocumentMoniker": "Pawn_Comps\\ARA_NodeSwarmLifetime\\CompNodeSwarmLifetime.cs",
|
||||
"ToolTip": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Pawn_Comps\\ARA_NodeSwarmLifetime\\CompNodeSwarmLifetime.cs",
|
||||
"RelativeToolTip": "Pawn_Comps\\ARA_NodeSwarmLifetime\\CompNodeSwarmLifetime.cs",
|
||||
"ViewState": "AgIAAPwAAAAAAAAAAAAYwBYBAABIAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||
"WhenOpened": "2025-10-16T09:14:26.956Z",
|
||||
"WhenOpened": "2025-10-16T15:17:15.994Z",
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 0,
|
||||
"Title": "IncidentWorker_CustomRaid.cs",
|
||||
"DocumentMoniker": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Storyteller\\IncidentWorker_CustomRaid.cs",
|
||||
"RelativeDocumentMoniker": "Storyteller\\IncidentWorker_CustomRaid.cs",
|
||||
"ToolTip": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Storyteller\\IncidentWorker_CustomRaid.cs*",
|
||||
"RelativeToolTip": "Storyteller\\IncidentWorker_CustomRaid.cs*",
|
||||
"ViewState": "AgIAAHgBAAAAAAAAAAA1wJIBAAAfAAAAAAAAAA==",
|
||||
"DocumentIndex": 2,
|
||||
"Title": "HediffComp_Temperature.cs",
|
||||
"DocumentMoniker": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Hediffs\\HediffComp_Temperature.cs",
|
||||
"RelativeDocumentMoniker": "Hediffs\\HediffComp_Temperature.cs",
|
||||
"ToolTip": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Hediffs\\HediffComp_Temperature.cs",
|
||||
"RelativeToolTip": "Hediffs\\HediffComp_Temperature.cs",
|
||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAwAAAAYAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||
"WhenOpened": "2025-10-16T07:14:58.682Z",
|
||||
"WhenOpened": "2025-10-16T15:13:58.773Z",
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 3,
|
||||
"Title": "HediffComp_SpawnPawnOnRemoved.cs",
|
||||
"DocumentMoniker": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Hediffs\\HediffComp_SpawnPawnOnRemoved.cs",
|
||||
"RelativeDocumentMoniker": "Hediffs\\HediffComp_SpawnPawnOnRemoved.cs",
|
||||
"ToolTip": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Hediffs\\HediffComp_SpawnPawnOnRemoved.cs",
|
||||
"RelativeToolTip": "Hediffs\\HediffComp_SpawnPawnOnRemoved.cs",
|
||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||
"WhenOpened": "2025-10-16T15:13:49.858Z",
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 1,
|
||||
"Title": "HediffComp_LifespanDisplay.cs",
|
||||
"DocumentMoniker": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Hediffs\\HediffComp_LifespanDisplay.cs",
|
||||
"RelativeDocumentMoniker": "Hediffs\\HediffComp_LifespanDisplay.cs",
|
||||
"ToolTip": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Hediffs\\HediffComp_LifespanDisplay.cs",
|
||||
"RelativeToolTip": "Hediffs\\HediffComp_LifespanDisplay.cs",
|
||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAABMAAAANAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||
"WhenOpened": "2025-10-16T15:13:38.519Z",
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 4,
|
||||
"Title": "HediffGiver_NonPlayerFaction.cs",
|
||||
"DocumentMoniker": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\HediffGiver\\HediffGiver_NonPlayerFaction.cs",
|
||||
"RelativeDocumentMoniker": "HediffGiver\\HediffGiver_NonPlayerFaction.cs",
|
||||
"ToolTip": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\HediffGiver\\HediffGiver_NonPlayerFaction.cs",
|
||||
"RelativeToolTip": "HediffGiver\\HediffGiver_NonPlayerFaction.cs",
|
||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAACoAAAAFAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||
"WhenOpened": "2025-10-16T12:07:58.018Z",
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 6,
|
||||
"Title": "RaidWaveDef.cs",
|
||||
"DocumentMoniker": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Storyteller\\RaidWaveDef.cs",
|
||||
"RelativeDocumentMoniker": "Storyteller\\RaidWaveDef.cs",
|
||||
"ToolTip": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Storyteller\\RaidWaveDef.cs*",
|
||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAkAAAA9AAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||
"WhenOpened": "2025-10-16T09:14:26.956Z"
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 5,
|
||||
"Title": "IncidentWorker_CustomRaid.cs",
|
||||
"DocumentMoniker": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Storyteller\\IncidentWorker_CustomRaid.cs",
|
||||
"RelativeDocumentMoniker": "Storyteller\\IncidentWorker_CustomRaid.cs",
|
||||
"ToolTip": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Storyteller\\IncidentWorker_CustomRaid.cs",
|
||||
"RelativeToolTip": "Storyteller\\IncidentWorker_CustomRaid.cs",
|
||||
"ViewState": "AgIAAHkBAAAAAAAAAAAUwJIBAAAfAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||
"WhenOpened": "2025-10-16T07:14:58.682Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -119,6 +119,8 @@
|
||||
<Compile Include="EventSystem\EventVariableManager.cs" />
|
||||
<Compile Include="EventSystem\Letter_EventChoice.cs" />
|
||||
<Compile Include="EventSystem\QuestNode_Root_EventLetter.cs" />
|
||||
<Compile Include="HediffGiver\HediffGiver_NonPlayerFaction.cs" />
|
||||
<Compile Include="Hediffs\HediffComp_LifespanDisplay.cs" />
|
||||
<Compile Include="Jobs\JobDriver_CarryPrisonerToRefuelingVat.cs" />
|
||||
<Compile Include="Storyteller\CustomRaidDef.cs" />
|
||||
<Compile Include="Storyteller\CustomRaidTracker.cs" />
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
|
||||
namespace ArachnaeSwarm
|
||||
{
|
||||
public class HediffGiver_NonPlayerFaction : HediffGiver
|
||||
{
|
||||
// 显式重新定义这些字段,确保 XML 解析器能找到它们
|
||||
public float mtbDays;
|
||||
public new HediffDef hediff;
|
||||
|
||||
public override void OnIntervalPassed(Pawn pawn, Hediff cause)
|
||||
{
|
||||
// 检查派系条件
|
||||
if (ShouldHaveHediff(pawn))
|
||||
{
|
||||
// 给予 hediff
|
||||
HealthUtility.AdjustSeverity(pawn, this.hediff, 1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 移除 hediff
|
||||
RemoveHediffIfExists(pawn);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShouldHaveHediff(Pawn pawn)
|
||||
{
|
||||
// 非玩家派系且不是殖民地囚犯
|
||||
return pawn.Faction != null &&
|
||||
pawn.Faction != Faction.OfPlayer &&
|
||||
!pawn.IsPrisonerOfColony;
|
||||
}
|
||||
|
||||
private void RemoveHediffIfExists(Pawn pawn)
|
||||
{
|
||||
Hediff existing = pawn.health?.hediffSet?.GetFirstHediffOfDef(this.hediff);
|
||||
if (existing != null)
|
||||
{
|
||||
pawn.health.RemoveHediff(existing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
44
Source/ArachnaeSwarm/Hediffs/HediffComp_LifespanDisplay.cs
Normal file
44
Source/ArachnaeSwarm/Hediffs/HediffComp_LifespanDisplay.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
|
||||
namespace ArachnaeSwarm
|
||||
{
|
||||
// 新的 HediffComp,用于显示寿命信息
|
||||
public class HediffComp_LifespanDisplay : HediffComp
|
||||
{
|
||||
public CompNodeSwarmLifetime LifespanComp => parent.pawn.GetComp<CompNodeSwarmLifetime>();
|
||||
|
||||
public override string CompTipStringExtra
|
||||
{
|
||||
get
|
||||
{
|
||||
if (LifespanComp != null && !LifespanComp.HasShutdownHediff)
|
||||
{
|
||||
return $"剩余寿命: {LifespanComp.DaysLeft:F1} 天";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override string CompLabelInBracketsExtra
|
||||
{
|
||||
get
|
||||
{
|
||||
if (LifespanComp != null && !LifespanComp.HasShutdownHediff)
|
||||
{
|
||||
return $"{LifespanComp.DaysLeft:F1}d";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HediffComp 属性类
|
||||
public class HediffCompProperties_LifespanDisplay : HediffCompProperties
|
||||
{
|
||||
public HediffCompProperties_LifespanDisplay()
|
||||
{
|
||||
compClass = typeof(HediffComp_LifespanDisplay);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,10 @@ namespace ArachnaeSwarm
|
||||
private int lastHediffSyncTick;
|
||||
private const int HEDIFF_SYNC_INTERVAL = 250; // 每250ticks同步一次
|
||||
|
||||
// 新增:hediff消失检查相关
|
||||
private int lastHediffMissingCheckTick = -1;
|
||||
private const int HEDIFF_MISSING_CHECK_INTERVAL = 60; // 每60ticks检查一次hediff是否存在
|
||||
|
||||
public CompProperties_NodeSwarmLifetime Props => (CompProperties_NodeSwarmLifetime)props;
|
||||
|
||||
// 修改:将 ticks 转换为天数计算
|
||||
@@ -60,6 +64,41 @@ namespace ArachnaeSwarm
|
||||
return pawn.health.hediffSet.HasHediff(Props.immuteHediff);
|
||||
}
|
||||
|
||||
// 新增:检查寿命Hediff是否存在
|
||||
private bool CheckLifespanHediffExists()
|
||||
{
|
||||
Pawn pawn = parent as Pawn;
|
||||
if (pawn == null) return false;
|
||||
|
||||
// 直接检查hediff是否存在,不使用缓存
|
||||
return pawn.health.hediffSet.GetFirstHediffOfDef(Props.lifespanHediff) != null;
|
||||
}
|
||||
|
||||
// 新增:当hediff消失时执行的处理
|
||||
private void HandleMissingHediff()
|
||||
{
|
||||
Pawn pawn = parent as Pawn;
|
||||
if (pawn == null) return;
|
||||
|
||||
Log.Warning($"Lifespan hediff missing for {pawn.Label}. This should not happen. Forcing death.");
|
||||
|
||||
// 立即处死pawn
|
||||
if (!pawn.Dead)
|
||||
{
|
||||
// 可以选择不同的处死方式
|
||||
if (Props.killWhenDepleted)
|
||||
{
|
||||
// 使用原有的处死逻辑
|
||||
KillPowerProcessor();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 直接杀死
|
||||
pawn.Kill(null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:获取或创建寿命Hediff
|
||||
private Hediff GetOrCreateLifespanHediff()
|
||||
{
|
||||
@@ -122,6 +161,24 @@ namespace ArachnaeSwarm
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:将Comp的数据写入Hediff(用于调试命令)
|
||||
private void WriteCompDataToHediff()
|
||||
{
|
||||
Pawn pawn = parent as Pawn;
|
||||
if (pawn == null) return;
|
||||
|
||||
var hediff = GetOrCreateLifespanHediff();
|
||||
if (hediff == null)
|
||||
{
|
||||
Log.Warning($"Failed to get or create lifespan hediff for {pawn.Label}");
|
||||
return;
|
||||
}
|
||||
|
||||
// 直接将Comp的数据写入Hediff
|
||||
hediff.Severity = PercentFull;
|
||||
Log.Message($"Debug: Wrote comp data to hediff - Severity: {hediff.Severity:P4}, TicksLeft: {powerTicksLeft}");
|
||||
}
|
||||
|
||||
// 新增:定期校验Hediff状态
|
||||
private void ValidateHediffState()
|
||||
{
|
||||
@@ -133,10 +190,9 @@ namespace ArachnaeSwarm
|
||||
|
||||
if (currentHediff == null)
|
||||
{
|
||||
// Hediff消失了,重新创建
|
||||
Log.Message($"Lifespan hediff was missing for {pawn.Label}, recreating with component data");
|
||||
lifespanHediff = null; // 重置缓存
|
||||
GetOrCreateLifespanHediff();
|
||||
// Hediff消失了,触发处理逻辑
|
||||
HandleMissingHediff();
|
||||
return;
|
||||
}
|
||||
else if (currentHediff != lifespanHediff)
|
||||
{
|
||||
@@ -164,6 +220,7 @@ namespace ArachnaeSwarm
|
||||
hasShutdownHediffCached = null;
|
||||
lastHediffCheckTick = Find.TickManager.TicksGame;
|
||||
lastHediffSyncTick = Find.TickManager.TicksGame;
|
||||
lastHediffMissingCheckTick = Find.TickManager.TicksGame;
|
||||
|
||||
// 确保寿命Hediff存在
|
||||
GetOrCreateLifespanHediff();
|
||||
@@ -197,39 +254,123 @@ namespace ArachnaeSwarm
|
||||
}
|
||||
if (DebugSettings.ShowDevGizmos)
|
||||
{
|
||||
// 新增:补满寿命调试命令
|
||||
yield return new Command_Action
|
||||
{
|
||||
defaultLabel = "DEV: Power left 0%",
|
||||
action = delegate
|
||||
{
|
||||
powerTicksLeft = 0;
|
||||
SyncLifespanWithHediff(); // 同步到Hediff
|
||||
}
|
||||
};
|
||||
yield return new Command_Action
|
||||
{
|
||||
defaultLabel = "DEV: Power left 100%",
|
||||
defaultLabel = "DEV: 补满寿命",
|
||||
action = delegate
|
||||
{
|
||||
powerTicksLeft = (int)(Props.lifetimeDays * 60000);
|
||||
SyncLifespanWithHediff(); // 同步到Hediff
|
||||
WriteCompDataToHediff(); // 使用新的写入方法
|
||||
Log.Message($"已补满寿命: {parent.Label} 剩余 {DaysLeft:F1} 天");
|
||||
Messages.Message($"已补满寿命: {Props.lifetimeDays} 天", MessageTypeDefOf.SilentInput);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// 新增:剩余0.01%寿命调试命令
|
||||
yield return new Command_Action
|
||||
{
|
||||
defaultLabel = "DEV: 剩余0.01%寿命",
|
||||
action = delegate
|
||||
{
|
||||
int totalTicks = (int)(Props.lifetimeDays * 60000);
|
||||
powerTicksLeft = (int)(totalTicks * 0.0001f); // 0.01%
|
||||
WriteCompDataToHediff(); // 使用新的写入方法
|
||||
float daysLeft = (float)powerTicksLeft / 60000f;
|
||||
Log.Message($"已设置剩余0.01%寿命: {parent.Label} 剩余 {daysLeft:F4} 天 ({PercentFull:P2})");
|
||||
Messages.Message($"设置剩余寿命为0.01%: {daysLeft:F4} 天", MessageTypeDefOf.SilentInput);
|
||||
}
|
||||
};
|
||||
|
||||
// 新增:归零寿命调试命令
|
||||
yield return new Command_Action
|
||||
{
|
||||
defaultLabel = "DEV: 归零寿命",
|
||||
action = delegate
|
||||
{
|
||||
powerTicksLeft = 0;
|
||||
WriteCompDataToHediff(); // 使用新的写入方法
|
||||
Log.Message($"已归零寿命: {parent.Label} 将立即死亡");
|
||||
Messages.Message("寿命已归零,即将死亡", MessageTypeDefOf.SilentInput);
|
||||
|
||||
// 立即触发死亡逻辑
|
||||
if (Props.killWhenDepleted)
|
||||
{
|
||||
KillPowerProcessor();
|
||||
}
|
||||
else
|
||||
{
|
||||
depleted = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 新增:调试命令显示Hediff状态
|
||||
yield return new Command_Action
|
||||
{
|
||||
defaultLabel = "DEV: Show Hediff Info",
|
||||
defaultLabel = "DEV: 显示Hediff信息",
|
||||
action = delegate
|
||||
{
|
||||
var hediff = GetOrCreateLifespanHediff();
|
||||
if (hediff != null)
|
||||
{
|
||||
Messages.Message($"Lifespan Hediff: Severity={hediff.Severity:P2}, TicksLeft={powerTicksLeft}", MessageTypeDefOf.SilentInput);
|
||||
string message = $"寿命Hediff信息:\n" +
|
||||
$"严重程度: {hediff.Severity:P4}\n" +
|
||||
$"剩余ticks: {powerTicksLeft}\n" +
|
||||
$"剩余天数: {DaysLeft:F4}\n" +
|
||||
$"总天数: {TotalDays:F1}\n" +
|
||||
$"百分比: {PercentFull:P4}\n" +
|
||||
$"已耗尽: {depleted}";
|
||||
Messages.Message(message, MessageTypeDefOf.SilentInput);
|
||||
Log.Message(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Messages.Message("No lifespan hediff found", MessageTypeDefOf.SilentInput);
|
||||
Messages.Message("未找到寿命hediff", MessageTypeDefOf.SilentInput);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 新增:调试命令手动移除hediff(测试hediff消失逻辑)
|
||||
yield return new Command_Action
|
||||
{
|
||||
defaultLabel = "DEV: 移除寿命Hediff",
|
||||
action = delegate
|
||||
{
|
||||
Pawn pawn = parent as Pawn;
|
||||
if (pawn != null)
|
||||
{
|
||||
var hediff = pawn.health.hediffSet.GetFirstHediffOfDef(Props.lifespanHediff);
|
||||
if (hediff != null)
|
||||
{
|
||||
pawn.health.RemoveHediff(hediff);
|
||||
lifespanHediff = null;
|
||||
Log.Message($"已手动移除 {pawn.Label} 的寿命Hediff");
|
||||
Messages.Message("已手动移除寿命hediff,pawn将立即死亡", MessageTypeDefOf.SilentInput);
|
||||
}
|
||||
else
|
||||
{
|
||||
Messages.Message("没有找到寿命hediff", MessageTypeDefOf.SilentInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 新增:强制同步命令(用于测试同步逻辑)
|
||||
yield return new Command_Action
|
||||
{
|
||||
defaultLabel = "DEV: 强制同步",
|
||||
action = delegate
|
||||
{
|
||||
SyncLifespanWithHediff();
|
||||
var hediff = GetOrCreateLifespanHediff();
|
||||
if (hediff != null)
|
||||
{
|
||||
string message = $"强制同步后:\n" +
|
||||
$"Comp剩余ticks: {powerTicksLeft}\n" +
|
||||
$"Hediff严重程度: {hediff.Severity:P4}\n" +
|
||||
$"剩余天数: {DaysLeft:F4}";
|
||||
Messages.Message(message, MessageTypeDefOf.SilentInput);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -251,11 +392,17 @@ namespace ArachnaeSwarm
|
||||
return;
|
||||
}
|
||||
|
||||
// 定期检查hediff是否存在(比同步更频繁)
|
||||
if (Find.TickManager.TicksGame > lastHediffMissingCheckTick + HEDIFF_MISSING_CHECK_INTERVAL)
|
||||
{
|
||||
ValidateHediffState();
|
||||
lastHediffMissingCheckTick = Find.TickManager.TicksGame;
|
||||
}
|
||||
|
||||
// 定期同步Hediff状态
|
||||
if (Find.TickManager.TicksGame > lastHediffSyncTick + HEDIFF_SYNC_INTERVAL)
|
||||
{
|
||||
SyncLifespanWithHediff();
|
||||
ValidateHediffState();
|
||||
lastHediffSyncTick = Find.TickManager.TicksGame;
|
||||
}
|
||||
|
||||
@@ -283,6 +430,11 @@ namespace ArachnaeSwarm
|
||||
private void KillPowerProcessor()
|
||||
{
|
||||
Pawn pawn = (Pawn)parent;
|
||||
|
||||
// 记录日志
|
||||
Log.Message($"Killing pawn {pawn.Label} due to lifespan depletion");
|
||||
|
||||
// 原有的处死逻辑
|
||||
List<BodyPartRecord> allParts = pawn.def.race.body.AllParts;
|
||||
for (int i = 0; i < allParts.Count; i++)
|
||||
{
|
||||
@@ -311,6 +463,7 @@ namespace ArachnaeSwarm
|
||||
Scribe_Values.Look(ref powerTicksLeft, "powerTicksLeft", 0);
|
||||
Scribe_Values.Look(ref depleted, "depleted", defaultValue: false);
|
||||
Scribe_Values.Look(ref lastHediffSyncTick, "lastHediffSyncTick", 0);
|
||||
Scribe_Values.Look(ref lastHediffMissingCheckTick, "lastHediffMissingCheckTick", 0);
|
||||
|
||||
// 添加:保存时重置缓存
|
||||
if (Scribe.mode == LoadSaveMode.PostLoadInit)
|
||||
@@ -326,6 +479,9 @@ namespace ArachnaeSwarm
|
||||
powerTicksLeft = (int)(Props.lifetimeDays * 60000);
|
||||
}
|
||||
|
||||
// 立即检查hediff是否存在
|
||||
ValidateHediffState();
|
||||
|
||||
// 确保寿命Hediff存在并同步
|
||||
GetOrCreateLifespanHediff();
|
||||
SyncLifespanWithHediff();
|
||||
@@ -333,6 +489,7 @@ namespace ArachnaeSwarm
|
||||
}
|
||||
}
|
||||
|
||||
// Gizmo 类保持不变
|
||||
[StaticConstructorOnStartup]
|
||||
public class NodeSwarmLifetimeGizmo : Gizmo
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user