重写寿命机制

This commit is contained in:
2025-09-25 12:02:44 +08:00
parent c6db75ddc4
commit 4034f27c14
10 changed files with 475 additions and 37 deletions

Binary file not shown.

View File

@@ -708,7 +708,6 @@
<label>巨镰器官</label>
<listOrder>126</listOrder>
</BodyPartGroupDef>
<BodyDef>
<defName>ArachnaeMyrmecocystus_Body</defName>
@@ -1053,6 +1052,7 @@
<!-- 甲片,防御作用 -->
<li>
<def>ARA_Chitin_Shell</def>
<customLabel>尾部甲片</customLabel>
<coverage>0.01</coverage>
<depth>Outside</depth>
<groups>
@@ -1313,6 +1313,16 @@
</li>
</parts>
</li>
<!-- 甲片,防御作用 -->
<li>
<def>ARA_Chitin_Shell</def>
<customLabel>肩部甲片</customLabel>
<coverage>0.02</coverage>
<depth>Outside</depth>
<groups>
<li>Shoulders</li>
</groups>
</li>
<li>
<def>Shoulder</def>
<customLabel>左肩</customLabel>
@@ -1381,6 +1391,16 @@
<li>Waist</li>
</groups>
</li>
<!-- 甲片,防御作用 -->
<li>
<def>ARA_Chitin_Shell</def>
<customLabel>下肢甲片</customLabel>
<coverage>0.02</coverage>
<depth>Outside</depth>
<groups>
<li>Legs</li>
</groups>
</li>
<li>
<def>Leg</def>
<customLabel>左腿</customLabel>
@@ -1392,15 +1412,6 @@
<woundAnchorTag>LeftLeg</woundAnchorTag>
<flipGraphic>true</flipGraphic>
<parts>
<!-- 甲片,防御作用 -->
<li>
<def>ARA_Chitin_Shell</def>
<coverage>0.12</coverage>
<depth>Outside</depth>
<groups>
<li>Legs</li>
</groups>
</li>
<li>
<def>Foot</def>
<customLabel>左足</customLabel>
@@ -1422,15 +1433,6 @@
</groups>
<woundAnchorTag>RightLeg</woundAnchorTag>
<parts>
<!-- 甲片,防御作用 -->
<li>
<def>ARA_Chitin_Shell</def>
<coverage>0.12</coverage>
<depth>Outside</depth>
<groups>
<li>Legs</li>
</groups>
</li>
<li>
<def>Foot</def>
<customLabel>右足</customLabel>

View File

@@ -106,6 +106,30 @@
</li>
</stages>
</HediffDef>
<HediffDef>
<defName>ARA_HiveStrength_Low</defName>
<label>虫群健壮</label>
<description>阿拉克涅虫族的伤势修复能力相当强大,它们能从各种致命打击中快速恢复。</description>
<hediffClass>HediffWithComps</hediffClass>
<defaultLabelColor>(0.6, 0.4, 0.8)</defaultLabelColor>
<isBad>false</isBad>
<scenarioCanAdd>false</scenarioCanAdd>
<comps>
</comps>
<stages>
<li>
<minSeverity>0</minSeverity>
<regeneration>20</regeneration>
</li>
</stages>
<comps>
<li Class="HediffCompProperties_RemoveIfOtherHediff">
<hediffs>
<li>ARA_Cycle_Suppression_Hediff</li>
</hediffs>
</li>
</comps>
</HediffDef>
<HediffDef>
<defName>ARA_TemperatureRegulation</defName>

View File

@@ -14,7 +14,7 @@
<skillRequirements>
<Medicine>5</Medicine>
</skillRequirements>
<recipeUsers Inherit="False">
<!-- <recipeUsers Inherit="False">
<li>ArachnaeNode_Race_Myrmecocystus</li>
<li>ArachnaeNode_Race_ShieldHead</li>
<li>ArachnaeNode_Race_WeaponSmith</li>
@@ -22,7 +22,7 @@
<li>ArachnaeNode_Race_Facehugger</li>
<li>ArachnaeNode_Race_Smokepop</li>
<li>ArachnaeNode_Race_Skyraider</li>
</recipeUsers>
</recipeUsers> -->
<ingredients>
<li>
<filter><categories><li>Medicine</li></categories></filter>
@@ -108,7 +108,7 @@
</li>
</ingredients>
<appliedOnFixedBodyParts>
<li>stomach</li>
<li>Stomach</li>
</appliedOnFixedBodyParts>
<fixedIngredientFilter>
<thingDefs>
@@ -136,4 +136,45 @@
</li>
</stages>
</HediffDef>
<RecipeDef ParentName="ARA_SurgeryInstallImplantBase">
<defName>ARA_Surgery_Install_Cycle_Suppression</defName>
<label>生命周期抑制</label>
<description>诱发阿拉克涅虫族的定向变异,使其不再受到寿命的制约,得以存活更久。但是注入生命周期抑制素后,虫族将失去其自愈能力。</description>
<descriptionHyperlinks>
<HediffDef>ARA_Cycle_Suppression_Hediff</HediffDef>
</descriptionHyperlinks>
<jobString>正在实施定向变异</jobString>
<ingredients>
<li>
<filter>
<thingDefs>
<li>ARA_Activated_Bacterium</li>
</thingDefs>
</filter>
<count>6</count>
</li>
</ingredients>
<appliedOnFixedBodyParts>
<li>Brain</li>
</appliedOnFixedBodyParts>
<fixedIngredientFilter>
<thingDefs>
<li>ARA_Activated_Bacterium</li>
</thingDefs>
</fixedIngredientFilter>
<addsHediff>ARA_Cycle_Suppression_Hediff</addsHediff>
</RecipeDef>
<HediffDef ParentName="ImplantHediffBase">
<defName>ARA_Cycle_Suppression_Hediff</defName>
<label>生命周期抑制</label>
<hediffClass>Hediff_Implant</hediffClass>
<description>为阿拉克涅虫族的生命周期抑制素阻止了虫族自身的无序生长,以延长其寿命。</description>
<descriptionHyperlinks>
<RecipeDef>ARA_Surgery_Install_Cycle_Suppression</RecipeDef>
</descriptionHyperlinks>
<addedPartProps>
<betterThanNatural>true</betterThanNatural>
</addedPartProps>
</HediffDef>
</Defs>

View File

@@ -617,6 +617,7 @@
<recipes Inherit="False">
<li>ARA_Surgery_Install_Plasteel</li>
<li>ARA_Surgery_Install_Huge_Stomach</li>
<li>ARA_Surgery_Install_Cycle_Suppression</li>
</recipes>
<comps>
@@ -781,8 +782,9 @@
</productionQueue>
<spawnEffecter>CocoonDestroyed</spawnEffecter>
</li>
<li Class="CompProperties_MechPowerCell">
<totalPowerTicks>14400000</totalPowerTicks>
<li Class="ArachnaeSwarm.CompProperties_NodeSwarmLifetime">
<immuteHediff>ARA_Cycle_Suppression_Hediff</immuteHediff>
<lifetimeDays>120</lifetimeDays>
<labelOverride>寿命</labelOverride>
<tooltipOverride>阿拉克涅的督虫们生命如精密的发条般运转着。</tooltipOverride>
<showGizmoOnNonPlayerControlled>true</showGizmoOnNonPlayerControlled>
@@ -917,8 +919,9 @@
</productionQueue>
<spawnEffecter>CocoonDestroyed</spawnEffecter>
</li>
<li Class="CompProperties_MechPowerCell">
<totalPowerTicks>7200000</totalPowerTicks>
<li Class="ArachnaeSwarm.CompProperties_NodeSwarmLifetime">
<immuteHediff>ARA_Cycle_Suppression_Hediff</immuteHediff>
<lifetimeDays>60</lifetimeDays>
<labelOverride>寿命</labelOverride>
<tooltipOverride>阿拉克涅的督虫们生命如精密的发条般运转着。</tooltipOverride>
<showGizmoOnNonPlayerControlled>true</showGizmoOnNonPlayerControlled>
@@ -1016,8 +1019,9 @@
</productionQueue>
<spawnEffecter>CocoonDestroyed</spawnEffecter>
</li>
<li Class="CompProperties_MechPowerCell">
<totalPowerTicks>7200000</totalPowerTicks>
<li Class="ArachnaeSwarm.CompProperties_NodeSwarmLifetime">
<immuteHediff>ARA_Cycle_Suppression_Hediff</immuteHediff>
<lifetimeDays>60</lifetimeDays>
<labelOverride>寿命</labelOverride>
<tooltipOverride>阿拉克涅的督虫们生命如精密的发条般运转着。</tooltipOverride>
<showGizmoOnNonPlayerControlled>true</showGizmoOnNonPlayerControlled>
@@ -1109,8 +1113,9 @@
</race>
<comps>
<li Class="CompProperties_MechPowerCell">
<totalPowerTicks>7200000</totalPowerTicks>
<li Class="ArachnaeSwarm.CompProperties_NodeSwarmLifetime">
<immuteHediff>ARA_Cycle_Suppression_Hediff</immuteHediff>
<lifetimeDays>60</lifetimeDays>
<labelOverride>寿命</labelOverride>
<tooltipOverride>阿拉克涅的督虫们生命如精密的发条般运转着。</tooltipOverride>
<showGizmoOnNonPlayerControlled>true</showGizmoOnNonPlayerControlled>
@@ -1278,8 +1283,9 @@
</productionQueue>
<spawnEffecter>CocoonDestroyed</spawnEffecter>
</li>
<li Class="CompProperties_MechPowerCell">
<totalPowerTicks>14400000</totalPowerTicks>
<li Class="ArachnaeSwarm.CompProperties_NodeSwarmLifetime">
<immuteHediff>ARA_Cycle_Suppression_Hediff</immuteHediff>
<lifetimeDays>120</lifetimeDays>
<labelOverride>寿命</labelOverride>
<tooltipOverride>阿拉克涅的督虫们生命如精密的发条般运转着。</tooltipOverride>
<showGizmoOnNonPlayerControlled>true</showGizmoOnNonPlayerControlled>
@@ -1366,8 +1372,9 @@
<flyingAnimationEast>ARA_FlyEast</flyingAnimationEast>
<flyingAnimationSouth>ARA_FlySouth</flyingAnimationSouth>
</li>
<li Class="CompProperties_MechPowerCell">
<totalPowerTicks>7200000</totalPowerTicks>
<li Class="ArachnaeSwarm.CompProperties_NodeSwarmLifetime">
<immuteHediff>ARA_Cycle_Suppression_Hediff</immuteHediff>
<lifetimeDays>60</lifetimeDays>
<labelOverride>寿命</labelOverride>
<tooltipOverride>阿拉克涅的督虫们生命如精密的发条般运转着。</tooltipOverride>
<showGizmoOnNonPlayerControlled>true</showGizmoOnNonPlayerControlled>

View File

@@ -1,7 +1,28 @@
{
"Version": 1,
"WorkspaceRootPath": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\",
"Documents": [],
"WorkspaceRootPath": "D:\\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\\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|d:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\pawn_comps\\ara_nodeswarmlifetime\\compproperties_nodeswarmlifetime.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:pawn_comps\\ara_nodeswarmlifetime\\compproperties_nodeswarmlifetime.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\\pawn_comps\\ara_givehediffsinrangetorace\\hediffcomp_givehediffsinrangetorace.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:pawn_comps\\ara_givehediffsinrangetorace\\hediffcomp_givehediffsinrangetorace.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\\pawn_comps\\ara_fighter_invisible\\compfighterinvisible.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:pawn_comps\\ara_fighter_invisible\\compfighterinvisible.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\\pawn_comps\\ara_fighter_invisible\\compproperties_fighterinvisible.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:pawn_comps\\ara_fighter_invisible\\compproperties_fighterinvisible.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
}
],
"DocumentGroupContainers": [
{
"Orientation": 0,
@@ -9,11 +30,76 @@
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": -1,
"SelectedChildIndex": 5,
"Children": [
{
"$type": "Document",
"DocumentIndex": 2,
"Title": "HediffComp_GiveHediffsInRangeToRace.cs",
"DocumentMoniker": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Pawn_Comps\\ARA_GiveHediffsInRangeToRace\\HediffComp_GiveHediffsInRangeToRace.cs",
"RelativeDocumentMoniker": "Pawn_Comps\\ARA_GiveHediffsInRangeToRace\\HediffComp_GiveHediffsInRangeToRace.cs",
"ToolTip": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Pawn_Comps\\ARA_GiveHediffsInRangeToRace\\HediffComp_GiveHediffsInRangeToRace.cs",
"RelativeToolTip": "Pawn_Comps\\ARA_GiveHediffsInRangeToRace\\HediffComp_GiveHediffsInRangeToRace.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAABEAAAAXAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-09-25T03:08:41.128Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 3,
"Title": "CompFighterInvisible.cs",
"DocumentMoniker": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Pawn_Comps\\ARA_Fighter_Invisible\\CompFighterInvisible.cs",
"RelativeDocumentMoniker": "Pawn_Comps\\ARA_Fighter_Invisible\\CompFighterInvisible.cs",
"ToolTip": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Pawn_Comps\\ARA_Fighter_Invisible\\CompFighterInvisible.cs",
"RelativeToolTip": "Pawn_Comps\\ARA_Fighter_Invisible\\CompFighterInvisible.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-09-25T03:08:39.152Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 4,
"Title": "CompProperties_FighterInvisible.cs",
"DocumentMoniker": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Pawn_Comps\\ARA_Fighter_Invisible\\CompProperties_FighterInvisible.cs",
"RelativeDocumentMoniker": "Pawn_Comps\\ARA_Fighter_Invisible\\CompProperties_FighterInvisible.cs",
"ToolTip": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Pawn_Comps\\ARA_Fighter_Invisible\\CompProperties_FighterInvisible.cs",
"RelativeToolTip": "Pawn_Comps\\ARA_Fighter_Invisible\\CompProperties_FighterInvisible.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-09-25T03:06:36.76Z",
"EditorCaption": ""
},
{
"$type": "Bookmark",
"Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}"
},
{
"$type": "Document",
"DocumentIndex": 1,
"Title": "CompProperties_NodeSwarmLifetime.cs",
"DocumentMoniker": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Pawn_Comps\\ARA_NodeSwarmLifetime\\CompProperties_NodeSwarmLifetime.cs",
"RelativeDocumentMoniker": "Pawn_Comps\\ARA_NodeSwarmLifetime\\CompProperties_NodeSwarmLifetime.cs",
"ToolTip": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Pawn_Comps\\ARA_NodeSwarmLifetime\\CompProperties_NodeSwarmLifetime.cs",
"RelativeToolTip": "Pawn_Comps\\ARA_NodeSwarmLifetime\\CompProperties_NodeSwarmLifetime.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAB8AAAABAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-09-25T02:13:12.615Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "CompNodeSwarmLifetime.cs",
"DocumentMoniker": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Pawn_Comps\\ARA_NodeSwarmLifetime\\CompNodeSwarmLifetime.cs",
"RelativeDocumentMoniker": "Pawn_Comps\\ARA_NodeSwarmLifetime\\CompNodeSwarmLifetime.cs",
"ToolTip": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Pawn_Comps\\ARA_NodeSwarmLifetime\\CompNodeSwarmLifetime.cs",
"RelativeToolTip": "Pawn_Comps\\ARA_NodeSwarmLifetime\\CompNodeSwarmLifetime.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-09-25T02:13:09.974Z",
"EditorCaption": ""
}
]
}

View File

@@ -174,6 +174,8 @@
<Compile Include="Pawn_Comps\ARA_Flight\PawnRenderNodeWorker_AttachmentBody_NoFlight.cs" />
<Compile Include="Pawn_Comps\ARA_GiveHediffsInRangeToRace\HediffComp_GiveHediffsInRangeToRace.cs" />
<Compile Include="Pawn_Comps\ARA_GiveHediffsInRangeToRace\HediffCompProperties_GiveHediffsInRangeToRace.cs" />
<Compile Include="Pawn_Comps\ARA_NodeSwarmLifetime\CompNodeSwarmLifetime.cs" />
<Compile Include="Pawn_Comps\ARA_NodeSwarmLifetime\CompProperties_NodeSwarmLifetime.cs" />
<Compile Include="Pawn_Comps\ARA_TrainingWork\CompAdvancedTraining.cs" />
<Compile Include="Pawn_Comps\ARA_TrainingWork\JobClean\ARA_TrainableDefOf_Cleaning.cs" />
<Compile Include="Pawn_Comps\ARA_TrainingWork\JobClean\JobGiver_Cleaner.cs" />

View File

@@ -0,0 +1,244 @@
// Assembly-CSharp, Version=1.6.9371.18214, Culture=neutral, PublicKeyToken=null
// RimWorld.CompNodeSwarmLifetime
using RimWorld;
using System.Collections.Generic;
using UnityEngine;
using Verse;
namespace ArachnaeSwarm
{
public class CompNodeSwarmLifetime : ThingComp
{
private int powerTicksLeft;
public bool depleted;
private NodeSwarmLifetimeGizmo gizmo;
// 添加:检查是否有特定 Hediff 的缓存字段
private bool? hasShutdownHediffCached;
private int lastHediffCheckTick;
public CompProperties_NodeSwarmLifetime Props => (CompProperties_NodeSwarmLifetime)props;
// 修改:将 ticks 转换为天数计算
public float PercentFull => (float)powerTicksLeft / (float)(Props.lifetimeDays * 60000);
public int PowerTicksLeft => powerTicksLeft;
// 添加:获取剩余天数
public float DaysLeft => (float)powerTicksLeft / 60000f;
// 添加:获取总天数
public float TotalDays => Props.lifetimeDays;
// 添加:检查是否有关闭系统的 Hediff
public bool HasShutdownHediff
{
get
{
// 每 300 tick 检查一次,避免性能问题
if (hasShutdownHediffCached == null || Find.TickManager.TicksGame > lastHediffCheckTick + 300)
{
hasShutdownHediffCached = CheckForShutdownHediff();
lastHediffCheckTick = Find.TickManager.TicksGame;
}
return hasShutdownHediffCached.Value;
}
}
// 添加:实际的 Hediff 检查逻辑
private bool CheckForShutdownHediff()
{
Pawn pawn = parent as Pawn;
if (pawn == null) return false;
// 使用 Props 中定义的 immuteHediff
if (Props.immuteHediff == null) return false;
return pawn.health.hediffSet.HasHediff(Props.immuteHediff);
}
public override void PostSpawnSetup(bool respawningAfterLoad)
{
if (!ModLister.CheckBiotechOrAnomalyOrOdyssey("Node swarm lifetime"))
{
parent.Destroy();
return;
}
base.PostSpawnSetup(respawningAfterLoad);
if (!respawningAfterLoad && !parent.BeingTransportedOnGravship)
{
// 修改:使用天数转换为 ticks
powerTicksLeft = (int)(Props.lifetimeDays * 60000);
}
// 初始化 Hediff 检查缓存
hasShutdownHediffCached = null;
lastHediffCheckTick = Find.TickManager.TicksGame;
}
public override IEnumerable<Gizmo> CompGetGizmosExtra()
{
// 添加:如果有关闭 Hediff不显示任何 Gizmo
if (HasShutdownHediff)
{
yield break;
}
if (parent.Faction != Faction.OfPlayer && !Props.showGizmoOnNonPlayerControlled)
{
yield break;
}
if (Find.Selector.SingleSelectedThing == parent)
{
if (gizmo == null)
{
gizmo = new NodeSwarmLifetimeGizmo(this)
{
Order = -100f
};
}
yield return gizmo;
}
if (DebugSettings.ShowDevGizmos)
{
yield return new Command_Action
{
defaultLabel = "DEV: Power left 0%",
action = delegate
{
powerTicksLeft = 0;
}
};
yield return new Command_Action
{
defaultLabel = "DEV: Power left 100%",
action = delegate
{
powerTicksLeft = (int)(Props.lifetimeDays * 60000);
}
};
}
}
public override void CompTick()
{
base.CompTick();
// 添加:如果有关闭 Hediff停止所有 Tick 逻辑
if (HasShutdownHediff)
{
return;
}
if (depleted)
{
return;
}
powerTicksLeft--;
if (powerTicksLeft <= 0)
{
if (Props.killWhenDepleted)
{
KillPowerProcessor();
return;
}
powerTicksLeft = 0;
depleted = true;
}
}
private void KillPowerProcessor()
{
Pawn pawn = (Pawn)parent;
List<BodyPartRecord> allParts = pawn.def.race.body.AllParts;
for (int i = 0; i < allParts.Count; i++)
{
BodyPartRecord bodyPartRecord = allParts[i];
if (bodyPartRecord.def.tags.Contains(BodyPartTagDefOf.BloodPumpingSource))
{
pawn.health.AddHediff(HediffDefOf.MissingBodyPart, bodyPartRecord);
}
}
if (!pawn.Dead)
{
pawn.Kill(null, null);
}
}
public override void PostExposeData()
{
base.PostExposeData();
Scribe_Values.Look(ref powerTicksLeft, "powerTicksLeft", 0);
Scribe_Values.Look(ref depleted, "depleted", defaultValue: false);
// 添加:保存时重置缓存
if (Scribe.mode == LoadSaveMode.PostLoadInit)
{
hasShutdownHediffCached = null;
lastHediffCheckTick = Find.TickManager.TicksGame;
// 添加:额外的安全检查
// 如果读档后 powerTicksLeft 异常,重置为满值
if (powerTicksLeft <= 0 && !depleted)
{
powerTicksLeft = (int)(Props.lifetimeDays * 60000);
}
}
}
}
[StaticConstructorOnStartup]
public class NodeSwarmLifetimeGizmo : Gizmo
{
private CompNodeSwarmLifetime powerCell;
private const float Width = 160f;
private static readonly Texture2D BarTex = SolidColorMaterials.NewSolidColorTexture(new Color32(12, 45, 45, byte.MaxValue));
private static readonly Texture2D EmptyBarTex = SolidColorMaterials.NewSolidColorTexture(GenUI.FillableBar_Empty);
public NodeSwarmLifetimeGizmo(CompNodeSwarmLifetime carrier)
{
powerCell = carrier;
}
public override float GetWidth(float maxWidth)
{
return 160f;
}
public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth, GizmoRenderParms parms)
{
Rect rect = new Rect(topLeft.x, topLeft.y, GetWidth(maxWidth), 75f);
Rect rect2 = rect.ContractedBy(10f);
Widgets.DrawWindowBackground(rect);
string text = (powerCell.Props.labelOverride.NullOrEmpty() ? ((string)"NodeSwarmLifetime".Translate()) : powerCell.Props.labelOverride);
Rect rect3 = new Rect(rect2.x, rect2.y, rect2.width, Text.CalcHeight(text, rect2.width) + 8f);
Text.Font = GameFont.Small;
Widgets.Label(rect3, text);
Rect barRect = new Rect(rect2.x, rect3.yMax, rect2.width, rect2.height - rect3.height);
Widgets.FillableBar(barRect, powerCell.PercentFull, BarTex, EmptyBarTex, doBorder: true);
// 移除了刻度线绘制代码
Text.Anchor = TextAnchor.MiddleCenter;
// 修改:显示天数而不是小时
Widgets.Label(barRect, powerCell.DaysLeft.ToString("F1") + "LetterDay".Translate());
Text.Anchor = TextAnchor.UpperLeft;
string tooltip;
if (!powerCell.Props.tooltipOverride.NullOrEmpty())
{
tooltip = powerCell.Props.tooltipOverride;
}
else
{
tooltip = "NodeSwarmLifetimeTip".Translate();
}
TooltipHandler.TipRegion(rect2, () => tooltip, Gen.HashCombineInt(powerCell.GetHashCode(), 34242369));
return new GizmoResult(GizmoState.Clear);
}
}
}

View File

@@ -0,0 +1,32 @@
// Assembly-CSharp, Version=1.6.9371.18214, Culture=neutral, PublicKeyToken=null
// RimWorld.CompProperties_NodeSwarmLifetime
using ArachnaeSwarm;
using RimWorld;
using Verse;
namespace ArachnaeSwarm
{
public class CompProperties_NodeSwarmLifetime : CompProperties
{
// 修改:使用天数而不是 ticks
public float lifetimeDays = 10f;
//结束计时后杀死
public bool killWhenDepleted = true;
//关闭系统的hediff
public HediffDef immuteHediff;
//是否在非玩家控制的pawn身上显示相关控件
public bool showGizmoOnNonPlayerControlled;
[MustTranslate]
public string labelOverride;
[MustTranslate]
public string tooltipOverride;
public CompProperties_NodeSwarmLifetime()
{
compClass = typeof(CompNodeSwarmLifetime);
}
}
}