80 lines
2.6 KiB
C#
80 lines
2.6 KiB
C#
using Verse;
|
||
using RimWorld;
|
||
using System.Linq;
|
||
|
||
namespace ArachnaeSwarm
|
||
{
|
||
public class CompAbilityEffect_PsychicBrainburn : CompAbilityEffect
|
||
{
|
||
public new CompProperties_PsychicBrainburn Props => (CompProperties_PsychicBrainburn)props;
|
||
|
||
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
|
||
{
|
||
base.Apply(target, dest);
|
||
|
||
Pawn pawn = target.Pawn;
|
||
if (pawn == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
// 查找作为意识来源的身体部位
|
||
BodyPartRecord brain = pawn.health.hediffSet.GetNotMissingParts()
|
||
.FirstOrDefault(p => p.def.tags.Contains(BodyPartTagDefOf.ConsciousnessSource));
|
||
|
||
if (brain != null)
|
||
{
|
||
// 施加巨大伤害以摧毁大脑
|
||
float damageAmount = 99999f;
|
||
float penetration = 999f;
|
||
pawn.TakeDamage(new DamageInfo(DamageDefOf.Burn, damageAmount, penetration, -1f, parent.pawn, brain));
|
||
|
||
// 如果在XML中定义了效果,则生成它
|
||
if (Props.effecterDef != null)
|
||
{
|
||
Props.effecterDef.Spawn(pawn.Position, pawn.Map, 1f);
|
||
}
|
||
}
|
||
}
|
||
|
||
public override bool Valid(LocalTargetInfo target, bool throwMessages = false)
|
||
{
|
||
Pawn pawn = target.Pawn;
|
||
if (pawn == null)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
// 检查目标是否是血肉生物(如果XML中设置为需要)
|
||
if (Props.requiresFlesh && !pawn.RaceProps.IsFlesh)
|
||
{
|
||
if (throwMessages)
|
||
{
|
||
Messages.Message("MessageCannotUseOnMechanical".Translate(pawn.Named("PAWN")), pawn, MessageTypeDefOf.RejectInput);
|
||
}
|
||
return false;
|
||
}
|
||
|
||
// 检查目标是否有意识来源部位
|
||
BodyPartRecord brain = pawn.health.hediffSet.GetNotMissingParts()
|
||
.FirstOrDefault(p => p.def.tags.Contains(BodyPartTagDefOf.ConsciousnessSource));
|
||
|
||
if (brain == null)
|
||
{
|
||
if (throwMessages)
|
||
{
|
||
Messages.Message("MessageTargetHasNoBrain".Translate(pawn.Named("PAWN")), pawn, MessageTypeDefOf.RejectInput);
|
||
}
|
||
return false;
|
||
}
|
||
|
||
return base.Valid(target, throwMessages);
|
||
}
|
||
|
||
public override bool AICanTargetNow(LocalTargetInfo target)
|
||
{
|
||
// AI不应主动使用此技能
|
||
return false;
|
||
}
|
||
}
|
||
} |