伤害响应,乌拉受到的每点伤害增加维护需求严重性

This commit is contained in:
2025-08-14 10:51:18 +08:00
parent c1140c7743
commit b796fbe329
6 changed files with 78 additions and 8 deletions

View File

@@ -0,0 +1,37 @@
using Verse;
namespace WulaFallenEmpire
{
// 定义了在XML中可以设置的属性
public class HediffCompProperties_DamageResponse : HediffCompProperties
{
// 每点伤害值所转化的严重性数值
public float severityIncreasePerDamage = 0f;
public HediffCompProperties_DamageResponse()
{
this.compClass = typeof(HediffComp_DamageResponse);
}
}
// 组件的实际逻辑
public class HediffComp_DamageResponse : HediffComp
{
// 一个方便获取上面属性的捷径
private HediffCompProperties_DamageResponse Props => (HediffCompProperties_DamageResponse)this.props;
// 当Hediff的持有者Pawn受到伤害后这个方法会被游戏调用
public override void Notify_PawnPostApplyDamage(DamageInfo dinfo, float totalDamageDealt)
{
base.Notify_PawnPostApplyDamage(dinfo, totalDamageDealt);
// 如果伤害值大于0并且我们在XML中设置了转化率
if (totalDamageDealt > 0 && Props.severityIncreasePerDamage > 0f)
{
// 增加父Hediff的严重性
// this.parent 指向这个组件所属的Hediff实例
this.parent.Severity += totalDamageDealt * Props.severityIncreasePerDamage;
}
}
}
}

View File

@@ -136,7 +136,7 @@
<Compile Include="Verb\Trackingbullet.cs" />
<Compile Include="Verb\Verb_ShootBeamExplosive.cs" />
<Compile Include="Verb\VerbPropertiesExplosiveBeam.cs" />
<Compile Include="Verb\Verb_MeleeAttack_Cleave.cs" />
<Compile Include="Verb\Verb_MeleeAttack_Cleave.cs" />
<Compile Include="WorkGiver_FeedWulaPatient.cs" />
<Compile Include="WorkGiver_Warden_DeliverEnergy.cs" />
<Compile Include="WorkGiver_Warden_FeedWula.cs" />
@@ -146,7 +146,8 @@
<Compile Include="WulaStatDefOf.cs" />
<Compile Include="Building_MaintenancePod.cs" />
<Compile Include="HediffComp_MaintenanceNeed.cs" />
<Compile Include="JobDefOf_WULA.cs" />
<Compile Include="HediffComp_DamageResponse.cs" />
<Compile Include="JobDefOf_WULA.cs" />
<Compile Include="ThingDefOf_WULA.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />