From 43bc0951f748a4d0048de94618feb123dec0edef Mon Sep 17 00:00:00 2001 From: Logan Perkins Date: Sun, 23 Jun 2024 15:26:32 -0700 Subject: [PATCH] Fall back to targeting the head for creatures without necks --- .../Comps/CompMeleeTargettingGizmo.cs | 48 ++++++++++++------- .../Verbs/Verb_MeleeAttackCE.cs | 9 +++- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/Comps/CompMeleeTargettingGizmo.cs b/Source/CombatExtended/CombatExtended/Comps/CompMeleeTargettingGizmo.cs index 2185daf5e7..008f111338 100644 --- a/Source/CombatExtended/CombatExtended/Comps/CompMeleeTargettingGizmo.cs +++ b/Source/CombatExtended/CombatExtended/Comps/CompMeleeTargettingGizmo.cs @@ -25,8 +25,19 @@ static MeleeTargettingAdd() } } } + + [StaticConstructorOnStartup] public class CompMeleeTargettingGizmo : ThingComp { + static CompMeleeTargettingGizmo() + { + priorityList = new List() { + CE_BodyPartDefOf.Neck, + BodyPartDefOf.Eye, + BodyPartDefOf.Head + }; + } + private static List priorityList = null; #region Fields public Pawn PawnParent => (Pawn)this.parent; @@ -92,24 +103,25 @@ public BodyPartHeight finalHeight(Pawn target) if (PawnParent.skills.GetSkill(SkillDefOf.Melee).Level >= 16) { - //TODO: 1.5 Should be neck? - targetBodyPart = CE_BodyPartDefOf.Neck; - - var neck = target.health.hediffSet.GetNotMissingParts(BodyPartHeight.Top).Where(y => y.def == CE_BodyPartDefOf.Neck).FirstOrFallback(); - - if (neck != null) - { - var neckApparel = target.apparel?.WornApparel?.Find(x => x.def.apparel.CoversBodyPart(neck)); - - if (neckApparel != null && maxWeaponPen < neckApparel.GetStatValue(StatDefOf.ArmorRating_Sharp)) - { - targetBodyPart = null; - return BodyPartHeight.Bottom; - } - else - { - targetBodyPart = neck.def; - } + foreach (var bpd in priorityList) + { + targetBodyPart = bpd; + var bp = target.health.hediffSet.GetNotMissingParts(BodyPartHeight.Top).Where(y => y.def == bpd).FirstOrFallback(); + + if (bp != null) + { + var bpApparel = target.apparel?.WornApparel?.Find(x => x.def.apparel.CoversBodyPart(bp)); + + if (bpApparel != null && maxWeaponPen < bpApparel.GetStatValue(StatDefOf.ArmorRating_Sharp)) + { + targetBodyPart = null; + return BodyPartHeight.Bottom; + } + else + { + targetBodyPart = bp.def; + } + } } return BodyPartHeight.Top; diff --git a/Source/CombatExtended/CombatExtended/Verbs/Verb_MeleeAttackCE.cs b/Source/CombatExtended/CombatExtended/Verbs/Verb_MeleeAttackCE.cs index efc6f53b58..b5cb687ea8 100644 --- a/Source/CombatExtended/CombatExtended/Verbs/Verb_MeleeAttackCE.cs +++ b/Source/CombatExtended/CombatExtended/Verbs/Verb_MeleeAttackCE.cs @@ -400,9 +400,14 @@ private IEnumerable DamageInfosToApply(LocalTargetInfo target, bool if (caster.def.race.predator && IsTargetImmobile(target)) { //TODO: 1.5 Should be neck? - var neck = pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Top, BodyPartDepth.Outside) + var hp = pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Top, BodyPartDepth.Outside) .FirstOrDefault(r => r.def == CE_BodyPartDefOf.Neck); - damageInfo.SetHitPart(neck); + if (hp == null) + { + hp = pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Top, BodyPartDepth.Outside) + .FirstOrDefault(r => r.def == BodyPartDefOf.Head); + } + damageInfo.SetHitPart(hp); } //for some reason, when all parts of height are missing their incode count is 3 if (pawn.health.hediffSet.GetNotMissingParts(bodyRegion).Count() <= 3)