暂存拟线虫药物

This commit is contained in:
2025-09-10 19:08:42 +08:00
parent d31f5c616a
commit f531d0a136
5 changed files with 233 additions and 2 deletions

View File

@@ -191,6 +191,7 @@
<Compile Include="ProphecyGearEffect.cs" />
<Compile Include="Hediff_ConfigurableMutant.cs" />
<Compile Include="HediffComp_Symbiosis.cs" />
<Compile Include="HediffGiver_RandomWithSeverity.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 自定义清理任务删除obj文件夹中的临时文件 -->

View File

@@ -0,0 +1,54 @@
using Verse;
namespace ArachnaeSwarm
{
/// <summary>
/// A custom HediffGiver that is similar to HediffGiver_Random,
/// but allows specifying a random severity range for the given hediff.
/// </summary>
public class HediffGiver_RandomWithSeverity : HediffGiver
{
// XML configurable fields
public float mtbDays;
public FloatRange severityRange = new FloatRange(0.01f, 1f);
public override void OnIntervalPassed(Pawn pawn, Hediff cause)
{
// Calculate the chance based on Mean Time Between (MTB) days and pawn-specific factors
float mtb = this.mtbDays;
float chanceFactor = ChanceFactor(pawn);
if (chanceFactor != 0f && Rand.MTBEventOccurs(mtb / chanceFactor, 60000f, 60f))
{
// Try to apply the hediff with our custom logic
if (TryApplyWithCustomSeverity(pawn))
{
// If successful, send a letter to the player
SendLetter(pawn, cause);
}
}
}
/// <summary>
/// Applies the hediff and then sets its severity to a random value within the specified range.
/// </summary>
/// <param name="pawn">The pawn to apply the hediff to.</param>
/// <returns>True if the hediff was successfully applied, false otherwise.</returns>
private bool TryApplyWithCustomSeverity(Pawn pawn)
{
// First, apply the hediff using the base class logic.
// This will add the hediff with its default initial severity.
if (base.TryApply(pawn))
{
// If the hediff was successfully added, find it.
Hediff hediff = pawn.health.hediffSet.GetFirstHediffOfDef(this.hediff);
if (hediff != null)
{
// Set its severity to a random value from our configured range.
hediff.Severity = this.severityRange.RandomInRange;
return true;
}
}
return false;
}
}
}