心灵增伤
This commit is contained in:
Binary file not shown.
@@ -54,6 +54,23 @@
|
|||||||
<aimingChargeMote>Mote_HellsphereCannon_Charge</aimingChargeMote>
|
<aimingChargeMote>Mote_HellsphereCannon_Charge</aimingChargeMote>
|
||||||
</li>
|
</li>
|
||||||
</verbs>
|
</verbs>
|
||||||
|
<comps>
|
||||||
|
<!-- 心灵敏感度伤害缩放组件 -->
|
||||||
|
<li Class="WulaFallenEmpire.CompProperties_PsychicScaling">
|
||||||
|
<!--
|
||||||
|
伤害增幅系数:
|
||||||
|
当持有者心灵敏感度 > 1 时, 每高出1点, 伤害增加 1%。
|
||||||
|
例如: 200% (2.0) 敏感度 -> 伤害增加 (2.0 - 1.0) * 1 = 100%。
|
||||||
|
-->
|
||||||
|
<damageMultiplierPerSensitivityPoint>1</damageMultiplierPerSensitivityPoint>
|
||||||
|
<!--
|
||||||
|
伤害减免系数:
|
||||||
|
当持有者心灵敏感度 < 1 时, 每低1点, 伤害降低 100%。
|
||||||
|
例如: 50% (0.5) 敏感度 -> 伤害降低 (1.0 - 0.5) * 1.0 = 50%。
|
||||||
|
-->
|
||||||
|
<damageReductionMultiplierPerSensitivityPoint>1</damageReductionMultiplierPerSensitivityPoint>
|
||||||
|
</li>
|
||||||
|
</comps>
|
||||||
<tradeability>None</tradeability>
|
<tradeability>None</tradeability>
|
||||||
</ThingDef>
|
</ThingDef>
|
||||||
<ThingDef ParentName="MoteBase">
|
<ThingDef ParentName="MoteBase">
|
||||||
|
|||||||
31
Source/WulaFallenEmpire/CompPsychicScaling.cs
Normal file
31
Source/WulaFallenEmpire/CompPsychicScaling.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using RimWorld;
|
||||||
|
using Verse;
|
||||||
|
|
||||||
|
namespace WulaFallenEmpire
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 这个组件的XML属性定义。允许在XML中配置加成系数。
|
||||||
|
/// </summary>
|
||||||
|
public class CompProperties_PsychicScaling : CompProperties
|
||||||
|
{
|
||||||
|
// 每点心灵敏感度(超出100%的部分)提供的伤害【增伤】乘数。
|
||||||
|
public float damageMultiplierPerSensitivityPoint = 0.25f;
|
||||||
|
|
||||||
|
// 每点心灵敏感度(低于100%的部分)提供的伤害【减伤】乘数。
|
||||||
|
// 例如,系数为1时,50%敏感度将造成 1 - (1 - 0.5) * 1 = 0.5倍伤害。
|
||||||
|
public float damageReductionMultiplierPerSensitivityPoint = 1f;
|
||||||
|
|
||||||
|
public CompProperties_PsychicScaling()
|
||||||
|
{
|
||||||
|
compClass = typeof(CompPsychicScaling);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 附加到武器上的实际组件。它本身只是一个标记,真正的逻辑在Harmony Patch中。
|
||||||
|
/// </summary>
|
||||||
|
public class CompPsychicScaling : ThingComp
|
||||||
|
{
|
||||||
|
public CompProperties_PsychicScaling Props => (CompProperties_PsychicScaling)props;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using RimWorld;
|
||||||
|
using Verse;
|
||||||
|
|
||||||
|
namespace WulaFallenEmpire.HarmonyPatches
|
||||||
|
{
|
||||||
|
[HarmonyPatch(typeof(Pawn_HealthTracker), "PreApplyDamage")]
|
||||||
|
public static class HealthTracker_PreApplyDamage_Patch
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 在伤害应用到Pawn之前执行的补丁。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dinfo">伤害信息,可以被修改。</param>
|
||||||
|
/// <param name="absorbed">输出参数,如果伤害被完全吸收则为true。</param>
|
||||||
|
public static void Prefix(ref DamageInfo dinfo, out bool absorbed)
|
||||||
|
{
|
||||||
|
// 必须为out参数赋默认值
|
||||||
|
absorbed = false;
|
||||||
|
|
||||||
|
// 检查伤害来源是否是一个Pawn
|
||||||
|
Pawn instigatorPawn = dinfo.Instigator as Pawn;
|
||||||
|
if (instigatorPawn == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查这个Pawn是否装备了武器
|
||||||
|
if (instigatorPawn.equipment?.Primary == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查武器上是否有我们的心灵增幅组件
|
||||||
|
var psychicComp = instigatorPawn.equipment.Primary.GetComp<CompPsychicScaling>();
|
||||||
|
if (psychicComp == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取心灵敏感度属性值
|
||||||
|
float psychicSensitivity = instigatorPawn.GetStatValue(StatDefOf.PsychicSensitivity);
|
||||||
|
|
||||||
|
// 根据心灵敏感度是否大于100%,使用不同的计算逻辑
|
||||||
|
float damageMultiplier;
|
||||||
|
if (psychicSensitivity > 1f)
|
||||||
|
{
|
||||||
|
// 增伤:伤害会根据XML中的增伤系数获得额外加成
|
||||||
|
damageMultiplier = 1 + ((psychicSensitivity - 1) * psychicComp.Props.damageMultiplierPerSensitivityPoint);
|
||||||
|
}
|
||||||
|
else if (psychicSensitivity < 1f)
|
||||||
|
{
|
||||||
|
// 减伤:伤害会根据XML中的减伤系数降低
|
||||||
|
damageMultiplier = 1 - ((1 - psychicSensitivity) * psychicComp.Props.damageReductionMultiplierPerSensitivityPoint);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 敏感度正好为100%,伤害不变
|
||||||
|
damageMultiplier = 1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取当前伤害值并应用乘数
|
||||||
|
float originalAmount = dinfo.Amount;
|
||||||
|
float newAmount = originalAmount * damageMultiplier;
|
||||||
|
|
||||||
|
// 更新伤害信息中的伤害值
|
||||||
|
dinfo.SetAmount(newAmount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -119,6 +119,8 @@
|
|||||||
<Compile Include="Verb\Projectile_ConfigurableHellsphereCannon.cs" />
|
<Compile Include="Verb\Projectile_ConfigurableHellsphereCannon.cs" />
|
||||||
<Compile Include="TimedExplosion.cs" />
|
<Compile Include="TimedExplosion.cs" />
|
||||||
<Compile Include="PsychicRitual_TechOffering.cs" />
|
<Compile Include="PsychicRitual_TechOffering.cs" />
|
||||||
|
<Compile Include="CompPsychicScaling.cs" />
|
||||||
|
<Compile Include="HarmonyPatches\HealthTracker_PreApplyDamage_Patch.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- 自定义清理任务,删除obj文件夹中的临时文件 -->
|
<!-- 自定义清理任务,删除obj文件夹中的临时文件 -->
|
||||||
|
|||||||
Reference in New Issue
Block a user