1
This commit is contained in:
147
Source/WulaFallenEmpire/Damage/202512031732.xml
Normal file
147
Source/WulaFallenEmpire/Damage/202512031732.xml
Normal file
@@ -0,0 +1,147 @@
|
||||
<!-- 1. 基本额外伤害配置 -->
|
||||
<DamageDef>
|
||||
<defName>Damage_WithExtraEffects</defName>
|
||||
<label>带电击伤害</label>
|
||||
<workerClass>WulaFallenEmpire.DamageWorker_ExtraDamage</workerClass>
|
||||
|
||||
<modExtensions>
|
||||
<li Class="WulaFallenEmpire.DamageDef_ExtraDamageExtension">
|
||||
<extraLabel>电击效果</extraLabel>
|
||||
<showExtraLog>true</showExtraLog>
|
||||
|
||||
<extraDamages>
|
||||
<li>
|
||||
<damageDef>EMP</damageDef>
|
||||
<amount>15</amount>
|
||||
<isPercentage>false</isPercentage>
|
||||
<armorPenetration>25</armorPenetration>
|
||||
<soundDef>EMP_Small</soundDef>
|
||||
<fleckDef>ElectricArc</fleckDef>
|
||||
<minTriggerDamage>5</minTriggerDamage>
|
||||
|
||||
<conditions>
|
||||
<li>
|
||||
<targetType>Mechanoid</targetType>
|
||||
<healthPercentRange>0,1</healthPercentRange>
|
||||
</li>
|
||||
</conditions>
|
||||
</li>
|
||||
</extraDamages>
|
||||
</li>
|
||||
</modExtensions>
|
||||
</DamageDef>
|
||||
|
||||
<!-- 2. 百分比额外伤害 -->
|
||||
<DamageDef>
|
||||
<defName>Damage_WithBurn</defName>
|
||||
<label>带燃烧伤害</label>
|
||||
<workerClass>WulaFallenEmpire.DamageWorker_ExtraDamage</workerClass>
|
||||
|
||||
<modExtensions>
|
||||
<li Class="WulaFallenEmpire.DamageDef_ExtraDamageExtension">
|
||||
<extraLabel>燃烧效果</extraLabel>
|
||||
|
||||
<extraDamages>
|
||||
<li>
|
||||
<damageDef>Burn</damageDef>
|
||||
<isPercentage>true</isPercentage>
|
||||
<percentageMultiplier>0.3</percentageMultiplier>
|
||||
<effecterDef>SparkHit</effecterDef>
|
||||
<minTriggerDamage>10</minTriggerDamage>
|
||||
|
||||
<conditions>
|
||||
<li>
|
||||
<targetType>Pawn</targetType>
|
||||
<healthPercentRange>0.3,1</healthPercentRange>
|
||||
<requiredTags>
|
||||
<li>Flammable</li>
|
||||
</requiredTags>
|
||||
</li>
|
||||
</conditions>
|
||||
</li>
|
||||
</extraDamages>
|
||||
</li>
|
||||
</modExtensions>
|
||||
</DamageDef>
|
||||
|
||||
<!-- 3. 多种额外伤害 -->
|
||||
<DamageDef>
|
||||
<defName>Damage_MultiEffect</defName>
|
||||
<label>多重效果伤害</label>
|
||||
<workerClass>WulaFallenEmpire.DamageWorker_ExtraDamage</workerClass>
|
||||
|
||||
<modExtensions>
|
||||
<li Class="WulaFallenEmpire.DamageDef_ExtraDamageExtension">
|
||||
<extraLabel>组合效果</extraLabel>
|
||||
|
||||
<extraDamages>
|
||||
<!-- 对生物造成流血 -->
|
||||
<li>
|
||||
<damageDef>Cut</damageDef>
|
||||
<amount>5</amount>
|
||||
<isPercentage>false</isPercentage>
|
||||
<targetBodyPart>Torso</targetBodyPart>
|
||||
|
||||
<conditions>
|
||||
<li>
|
||||
<targetType>Animal</targetType>
|
||||
</li>
|
||||
<li>
|
||||
<targetType>Humanlike</targetType>
|
||||
</li>
|
||||
</conditions>
|
||||
</li>
|
||||
|
||||
<!-- 对机械造成EMP -->
|
||||
<li>
|
||||
<damageDef>EMP</damageDef>
|
||||
<isPercentage>true</isPercentage>
|
||||
<percentageMultiplier>0.5</percentageMultiplier>
|
||||
<canBeBlockedByArmor>false</canBeBlockedByArmor>
|
||||
|
||||
<conditions>
|
||||
<li>
|
||||
<targetType>Mechanoid</targetType>
|
||||
</li>
|
||||
</conditions>
|
||||
</li>
|
||||
|
||||
<!-- 对建筑造成额外伤害 -->
|
||||
<li>
|
||||
<damageDef>Blunt</damageDef>
|
||||
<amount>20</amount>
|
||||
<isPercentage>false</isPercentage>
|
||||
|
||||
<conditions>
|
||||
<li>
|
||||
<targetType>Building</targetType>
|
||||
</li>
|
||||
</conditions>
|
||||
</li>
|
||||
</extraDamages>
|
||||
</li>
|
||||
</modExtensions>
|
||||
</DamageDef>
|
||||
|
||||
<!-- 4. 武器使用这个伤害类型 -->
|
||||
<ThingDef>
|
||||
<defName>Gun_AdvancedRifle</defName>
|
||||
<label>先进步枪</label>
|
||||
|
||||
<verbs>
|
||||
<li>
|
||||
<verbClass>Verb_Shoot</verbClass>
|
||||
<defaultProjectile>Bullet_Advanced</defaultProjectile>
|
||||
</li>
|
||||
</verbs>
|
||||
</ThingDef>
|
||||
|
||||
<!-- 5. 抛射体定义 -->
|
||||
<ThingDef>
|
||||
<defName>Bullet_Advanced</defName>
|
||||
<label>先进子弹</label>
|
||||
<projectile>
|
||||
<damageDef>Damage_MultiEffect</damageDef>
|
||||
<damageAmountBase>25</damageAmountBase>
|
||||
</projectile>
|
||||
</ThingDef>
|
||||
299
Source/WulaFallenEmpire/Damage/DamageDef_ExtraDamageExtension.cs
Normal file
299
Source/WulaFallenEmpire/Damage/DamageDef_ExtraDamageExtension.cs
Normal file
@@ -0,0 +1,299 @@
|
||||
using System.Collections.Generic;
|
||||
using Verse;
|
||||
using RimWorld;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class DamageDef_ExtraDamageExtension : DefModExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 额外伤害列表
|
||||
/// </summary>
|
||||
public List<ExtraDamageDef> extraDamages = new List<ExtraDamageDef>();
|
||||
|
||||
/// <summary>
|
||||
/// 条件触发器列表
|
||||
/// </summary>
|
||||
public List<DamageCondition> conditions = new List<DamageCondition>();
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示额外的战斗日志信息
|
||||
/// </summary>
|
||||
public bool showExtraLog = true;
|
||||
|
||||
/// <summary>
|
||||
/// 额外伤害标签
|
||||
/// </summary>
|
||||
public string extraLabel = "";
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有适用于特定目标的额外伤害
|
||||
/// </summary>
|
||||
public List<ExtraDamageDef> GetApplicableExtraDamages(Thing target, DamageInfo originalDinfo)
|
||||
{
|
||||
List<ExtraDamageDef> result = new List<ExtraDamageDef>();
|
||||
|
||||
foreach (var extraDamage in extraDamages)
|
||||
{
|
||||
if (IsConditionMet(extraDamage.conditions, target, originalDinfo))
|
||||
{
|
||||
result.Add(extraDamage);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查条件是否满足
|
||||
/// </summary>
|
||||
private bool IsConditionMet(List<DamageCondition> conditions, Thing target, DamageInfo originalDinfo)
|
||||
{
|
||||
if (conditions == null || conditions.Count == 0)
|
||||
return true;
|
||||
|
||||
foreach (var condition in conditions)
|
||||
{
|
||||
if (!condition.IsMet(target, originalDinfo))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 额外伤害定义
|
||||
/// </summary>
|
||||
public class ExtraDamageDef
|
||||
{
|
||||
/// <summary>
|
||||
/// 伤害类型
|
||||
/// </summary>
|
||||
public DamageDef damageDef;
|
||||
|
||||
/// <summary>
|
||||
/// 伤害数值(如果是百分比,基于原始伤害)
|
||||
/// </summary>
|
||||
public float amount = 10f;
|
||||
|
||||
/// <summary>
|
||||
/// 是否为百分比伤害(相对于原始伤害)
|
||||
/// </summary>
|
||||
public bool isPercentage = false;
|
||||
|
||||
/// <summary>
|
||||
/// 百分比倍数(当isPercentage为true时有效)
|
||||
/// </summary>
|
||||
public float percentageMultiplier = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// 护甲穿透值
|
||||
/// </summary>
|
||||
public float armorPenetration = -1f; // -1表示使用damageDef的默认值
|
||||
|
||||
/// <summary>
|
||||
/// 命中部位(可选)
|
||||
/// </summary>
|
||||
public BodyPartDef targetBodyPart;
|
||||
|
||||
/// <summary>
|
||||
/// 伤害应用条件
|
||||
/// </summary>
|
||||
public List<DamageCondition> conditions = new List<DamageCondition>();
|
||||
|
||||
/// <summary>
|
||||
/// 伤害应用后的效果器
|
||||
/// </summary>
|
||||
public EffecterDef effecterDef;
|
||||
|
||||
/// <summary>
|
||||
/// 伤害应用后的粒子
|
||||
/// </summary>
|
||||
public FleckDef fleckDef;
|
||||
|
||||
/// <summary>
|
||||
/// 伤害应用后的音效
|
||||
/// </summary>
|
||||
public SoundDef soundDef;
|
||||
|
||||
/// <summary>
|
||||
/// 最小触发伤害阈值
|
||||
/// </summary>
|
||||
public float minTriggerDamage = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以被护甲抵抗
|
||||
/// </summary>
|
||||
public bool canBeBlockedByArmor = true;
|
||||
|
||||
/// <summary>
|
||||
/// 是否为真实伤害(忽略所有抗性)
|
||||
/// </summary>
|
||||
public bool isTrueDamage = false;
|
||||
|
||||
/// <summary>
|
||||
/// 计算实际伤害值
|
||||
/// </summary>
|
||||
public float CalculateActualAmount(DamageInfo originalDinfo, Thing target)
|
||||
{
|
||||
if (isPercentage)
|
||||
{
|
||||
return originalDinfo.Amount * percentageMultiplier;
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算实际护甲穿透值
|
||||
/// </summary>
|
||||
public float CalculateActualArmorPenetration()
|
||||
{
|
||||
if (armorPenetration >= 0)
|
||||
return armorPenetration;
|
||||
return damageDef.defaultArmorPenetration;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 伤害条件
|
||||
/// </summary>
|
||||
public class DamageCondition
|
||||
{
|
||||
/// <summary>
|
||||
/// 目标类型
|
||||
/// </summary>
|
||||
public ConditionTarget targetType = ConditionTarget.Any;
|
||||
|
||||
/// <summary>
|
||||
/// 特定种族列表(当targetType为SpecificRaces时有效)
|
||||
/// </summary>
|
||||
public List<ThingDef> specificRaces = new List<ThingDef>();
|
||||
|
||||
/// <summary>
|
||||
/// 目标血量百分比阈值
|
||||
/// </summary>
|
||||
public FloatRange healthPercentRange = new FloatRange(0f, 1f);
|
||||
|
||||
/// <summary>
|
||||
/// 目标是否必须存活
|
||||
/// </summary>
|
||||
public bool targetMustBeAlive = true;
|
||||
|
||||
/// <summary>
|
||||
/// 目标是否必须有特定标签
|
||||
/// </summary>
|
||||
public List<string> requiredTags = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 原始伤害类型限制
|
||||
/// </summary>
|
||||
public List<DamageDef> requiredOriginalDamageTypes = new List<DamageDef>();
|
||||
|
||||
/// <summary>
|
||||
/// 原始伤害必须大于
|
||||
/// </summary>
|
||||
public float originalDamageMustBeGreaterThan = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// 检查条件是否满足
|
||||
/// </summary>
|
||||
public bool IsMet(Thing target, DamageInfo originalDinfo)
|
||||
{
|
||||
// 检查目标类型
|
||||
if (!CheckTargetType(target))
|
||||
return false;
|
||||
|
||||
// 检查血量百分比
|
||||
if (!CheckHealthPercentage(target))
|
||||
return false;
|
||||
|
||||
// 检查存活状态
|
||||
if (targetMustBeAlive && target is Pawn pawn && (pawn.Dead || pawn.Downed))
|
||||
return false;
|
||||
|
||||
// 检查标签
|
||||
if (!CheckTags(target))
|
||||
return false;
|
||||
|
||||
// 检查原始伤害类型
|
||||
if (!CheckOriginalDamageType(originalDinfo))
|
||||
return false;
|
||||
|
||||
// 检查原始伤害大小
|
||||
if (originalDinfo.Amount <= originalDamageMustBeGreaterThan)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool CheckTargetType(Thing target)
|
||||
{
|
||||
switch (targetType)
|
||||
{
|
||||
case ConditionTarget.Any:
|
||||
return true;
|
||||
case ConditionTarget.Pawn:
|
||||
return target is Pawn;
|
||||
case ConditionTarget.Animal:
|
||||
return target is Pawn pawn && pawn.RaceProps.Animal;
|
||||
case ConditionTarget.Humanlike:
|
||||
return target is Pawn pawn && pawn.RaceProps.Humanlike;
|
||||
case ConditionTarget.Mechanoid:
|
||||
return target is Pawn pawn && pawn.RaceProps.IsMechanoid;
|
||||
case ConditionTarget.Building:
|
||||
return target is Building;
|
||||
case ConditionTarget.SpecificRaces:
|
||||
return target is Pawn pawn && specificRaces.Contains(pawn.def);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckHealthPercentage(Thing target)
|
||||
{
|
||||
if (target is Pawn pawn)
|
||||
{
|
||||
float healthPercent = pawn.health.summaryHealth.SummaryHealthPercent;
|
||||
return healthPercentRange.Includes(healthPercent);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool CheckTags(Thing target)
|
||||
{
|
||||
if (requiredTags == null || requiredTags.Count == 0)
|
||||
return true;
|
||||
|
||||
foreach (var tag in requiredTags)
|
||||
{
|
||||
if (target.def.HasTag(tag))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool CheckOriginalDamageType(DamageInfo originalDinfo)
|
||||
{
|
||||
if (requiredOriginalDamageTypes == null || requiredOriginalDamageTypes.Count == 0)
|
||||
return true;
|
||||
|
||||
return requiredOriginalDamageTypes.Contains(originalDinfo.Def);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 条件目标类型
|
||||
/// </summary>
|
||||
public enum ConditionTarget
|
||||
{
|
||||
Any,
|
||||
Pawn,
|
||||
Animal,
|
||||
Humanlike,
|
||||
Mechanoid,
|
||||
Building,
|
||||
SpecificRaces
|
||||
}
|
||||
}
|
||||
245
Source/WulaFallenEmpire/Damage/DamageWorker_ExtraDamage.cs
Normal file
245
Source/WulaFallenEmpire/Damage/DamageWorker_ExtraDamage.cs
Normal file
@@ -0,0 +1,245 @@
|
||||
using System.Collections.Generic;
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class DamageWorker_ExtraDamage : DamageWorker
|
||||
{
|
||||
/// <summary>
|
||||
/// 重写伤害应用方法
|
||||
/// </summary>
|
||||
public override DamageResult Apply(DamageInfo dinfo, Thing victim)
|
||||
{
|
||||
// 先应用原始伤害
|
||||
DamageResult originalResult = base.Apply(dinfo, victim);
|
||||
|
||||
// 获取额外伤害扩展
|
||||
DamageDef_ExtraDamageExtension extension =
|
||||
dinfo.Def.GetModExtension<DamageDef_ExtraDamageExtension>();
|
||||
|
||||
if (extension != null && victim != null && !victim.Destroyed)
|
||||
{
|
||||
// 应用额外伤害
|
||||
var extraDamageResults = ApplyExtraDamages(extension, dinfo, victim, originalResult);
|
||||
|
||||
// 如果需要,添加战斗日志
|
||||
if (extension.showExtraLog && extraDamageResults.Count > 0)
|
||||
{
|
||||
AddCombatLog(extension, dinfo, victim, extraDamageResults);
|
||||
}
|
||||
}
|
||||
|
||||
return originalResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用额外伤害
|
||||
/// </summary>
|
||||
private List<DamageResult> ApplyExtraDamages(
|
||||
DamageDef_ExtraDamageExtension extension,
|
||||
DamageInfo originalDinfo,
|
||||
Thing victim,
|
||||
DamageResult originalResult)
|
||||
{
|
||||
List<DamageResult> results = new List<DamageResult>();
|
||||
|
||||
var applicableDamages = extension.GetApplicableExtraDamages(victim, originalDinfo);
|
||||
|
||||
foreach (var extraDamage in applicableDamages)
|
||||
{
|
||||
if (ShouldApplyExtraDamage(extraDamage, originalDinfo, victim))
|
||||
{
|
||||
DamageResult result = ApplySingleExtraDamage(extraDamage, originalDinfo, victim);
|
||||
if (result != null)
|
||||
{
|
||||
results.Add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否应该应用额外伤害
|
||||
/// </summary>
|
||||
private bool ShouldApplyExtraDamage(ExtraDamageDef extraDamage, DamageInfo originalDinfo, Thing victim)
|
||||
{
|
||||
// 检查最小触发伤害
|
||||
if (originalDinfo.Amount < extraDamage.minTriggerDamage)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用单个额外伤害
|
||||
/// </summary>
|
||||
private DamageResult ApplySingleExtraDamage(ExtraDamageDef extraDamage, DamageInfo originalDinfo, Thing victim)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 计算伤害值
|
||||
float damageAmount = extraDamage.CalculateActualAmount(originalDinfo, victim);
|
||||
if (damageAmount <= 0)
|
||||
return null;
|
||||
|
||||
// 计算护甲穿透
|
||||
float armorPenetration = extraDamage.CalculateActualArmorPenetration();
|
||||
|
||||
// 创建伤害信息
|
||||
DamageInfo extraDinfo = new DamageInfo(
|
||||
def: extraDamage.damageDef,
|
||||
amount: damageAmount,
|
||||
armorPenetration: armorPenetration,
|
||||
angle: originalDinfo.Angle,
|
||||
instigator: originalDinfo.Instigator,
|
||||
hitPart: GetTargetBodyPart(victim, extraDamage.targetBodyPart),
|
||||
weapon: originalDinfo.Weapon,
|
||||
category: DamageInfo.SourceCategory.ThingOrUnknown,
|
||||
intendedTarget: originalDinfo.IntendedTarget
|
||||
);
|
||||
|
||||
// 如果是真实伤害,设置特殊标志(如果需要特殊处理)
|
||||
if (extraDamage.isTrueDamage)
|
||||
{
|
||||
// 这里可能需要特殊的处理方式
|
||||
// 例如,可以设置伤害信息中的特殊标志
|
||||
}
|
||||
|
||||
// 应用伤害
|
||||
DamageResult result = victim.TakeDamage(extraDinfo);
|
||||
|
||||
// 播放效果
|
||||
PlayExtraDamageEffects(extraDamage, victim, damageAmount);
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Log.Warning($"应用额外伤害时出错: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取目标部位
|
||||
/// </summary>
|
||||
private BodyPartRecord GetTargetBodyPart(Thing victim, BodyPartDef bodyPartDef)
|
||||
{
|
||||
if (bodyPartDef == null || !(victim is Pawn pawn))
|
||||
return null;
|
||||
|
||||
return pawn.RaceProps.body.GetPartsWithDef(bodyPartDef).FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 播放额外伤害效果
|
||||
/// </summary>
|
||||
private void PlayExtraDamageEffects(ExtraDamageDef extraDamage, Thing victim, float damageAmount)
|
||||
{
|
||||
if (victim.Map == null)
|
||||
return;
|
||||
|
||||
// 播放音效
|
||||
if (extraDamage.soundDef != null)
|
||||
{
|
||||
extraDamage.soundDef.PlayOneShot(new TargetInfo(victim.Position, victim.Map));
|
||||
}
|
||||
|
||||
// 播放粒子效果
|
||||
if (extraDamage.fleckDef != null)
|
||||
{
|
||||
FleckMaker.Static(victim.DrawPos, victim.Map, extraDamage.fleckDef);
|
||||
}
|
||||
|
||||
// 播放效果器
|
||||
if (extraDamage.effecterDef != null)
|
||||
{
|
||||
Effecter effecter = extraDamage.effecterDef.Spawn();
|
||||
effecter.Trigger(new TargetInfo(victim.Position, victim.Map), new TargetInfo(victim.Position, victim.Map));
|
||||
effecter.Cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加战斗日志
|
||||
/// </summary>
|
||||
private void AddCombatLog(
|
||||
DamageDef_ExtraDamageExtension extension,
|
||||
DamageInfo originalDinfo,
|
||||
Thing victim,
|
||||
List<DamageResult> extraResults)
|
||||
{
|
||||
if (victim is Pawn victimPawn)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine($"{extension.extraLabel} - 额外伤害:");
|
||||
|
||||
foreach (var result in extraResults)
|
||||
{
|
||||
if (result != null && result.totalDamageDealt > 0)
|
||||
{
|
||||
sb.AppendLine($" {result.totalDamageDealt:F1} 伤害");
|
||||
}
|
||||
}
|
||||
|
||||
// 这里可以添加更详细的战斗日志逻辑
|
||||
// 例如,创建一个自定义的战斗日志条目
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写爆炸伤害处理
|
||||
/// </summary>
|
||||
protected override void ExplosionDamageThing(Explosion explosion, Thing t, List<Thing> damagedThings, List<Thing> ignoredThings, IntVec3 cell)
|
||||
{
|
||||
base.ExplosionDamageThing(explosion, t, damagedThings, ignoredThings, cell);
|
||||
|
||||
// 检查并应用额外伤害
|
||||
DamageDef_ExtraDamageExtension extension =
|
||||
explosion.damType.GetModExtension<DamageDef_ExtraDamageExtension>();
|
||||
|
||||
if (extension != null && !t.Destroyed)
|
||||
{
|
||||
// 为爆炸中的每个目标应用额外伤害
|
||||
// 注意:这里需要创建适当的DamageInfo
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取伤害描述(用于UI显示)
|
||||
/// </summary>
|
||||
public string GetExtraDamageDescription(DamageDef damageDef)
|
||||
{
|
||||
DamageDef_ExtraDamageExtension extension =
|
||||
damageDef.GetModExtension<DamageDef_ExtraDamageExtension>();
|
||||
|
||||
if (extension == null || extension.extraDamages.Count == 0)
|
||||
return "";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("额外伤害效果:");
|
||||
|
||||
foreach (var extraDamage in extension.extraDamages)
|
||||
{
|
||||
string damageType = extraDamage.damageDef.label;
|
||||
string amountStr = extraDamage.isPercentage ?
|
||||
$"{extraDamage.percentageMultiplier * 100}% 原始伤害" :
|
||||
$"{extraDamage.amount} 点";
|
||||
|
||||
sb.AppendLine($" {damageType}: {amountStr}");
|
||||
|
||||
if (extraDamage.minTriggerDamage > 0)
|
||||
{
|
||||
sb.AppendLine($" 触发条件: 原始伤害 > {extraDamage.minTriggerDamage}");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user