diff --git a/Source/CombatExtended/CombatExtended/Comps/CompMeleeTargettingGizmo.cs b/Source/CombatExtended/CombatExtended/Comps/CompMeleeTargettingGizmo.cs index 886705d698..3d31d4b10e 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,26 +103,26 @@ public BodyPartHeight finalHeight(Pawn target) if (PawnParent.skills.GetSkill(SkillDefOf.Melee).Level >= 16) { - //TODO: 1.5 Should be neck? - targetBodyPart = BodyPartDefOf.Eye; - - var neck = target.health.hediffSet.GetNotMissingParts(BodyPartHeight.Top).Where(y => y.def == BodyPartDefOf.Eye).FirstOrFallback(); - - if (neck != null) + foreach (var bpd in priorityList) { - var neckApparel = target.apparel?.WornApparel?.Find(x => x.def.apparel.CoversBodyPart(neck)); + targetBodyPart = bpd; + var bp = target.health.hediffSet.GetNotMissingParts(BodyPartHeight.Top).Where(y => y.def == bpd).FirstOrFallback(); - if (neckApparel != null && maxWeaponPen < neckApparel.GetStatValue(StatDefOf.ArmorRating_Sharp)) - { - targetBodyPart = null; - return BodyPartHeight.Bottom; - } - else + if (bp != null) { - targetBodyPart = neck.def; + 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/DefOfs/CE_BodyPartDefOf.cs b/Source/CombatExtended/CombatExtended/DefOfs/CE_BodyPartDefOf.cs new file mode 100644 index 0000000000..41589ebd5c --- /dev/null +++ b/Source/CombatExtended/CombatExtended/DefOfs/CE_BodyPartDefOf.cs @@ -0,0 +1,12 @@ +using System; +using Verse; +using RimWorld; + +namespace CombatExtended +{ + [DefOf] + public static class CE_BodyPartDefOf + { + public static BodyPartDef Neck; + } +} diff --git a/Source/CombatExtended/CombatExtended/Loadouts/ITab_Inventory.cs b/Source/CombatExtended/CombatExtended/Loadouts/ITab_Inventory.cs index d0a2a093be..378fe1870a 100644 --- a/Source/CombatExtended/CombatExtended/Loadouts/ITab_Inventory.cs +++ b/Source/CombatExtended/CombatExtended/Loadouts/ITab_Inventory.cs @@ -520,7 +520,7 @@ private void RebuildArmorCache(Dictionary armorCache, Sta foreach (BodyPartRecord part in SelPawnForGear.RaceProps.body.AllParts) { //TODO: 1.5 should be Neck - if (part.depth == BodyPartDepth.Outside && (part.coverage >= 0.1 || (part.def == BodyPartDefOf.Eye || part.def == BodyPartDefOf.Eye))) + if (part.depth == BodyPartDepth.Outside && (part.coverage >= 0.1 || (part.def == CE_BodyPartDefOf.Neck || part.def == CE_BodyPartDefOf.Neck))) { float armorValue = part.IsInGroup(CE_BodyPartGroupDefOf.CoveredByNaturalArmor) ? naturalArmor : 0f; if (wornApparel != null) diff --git a/Source/CombatExtended/CombatExtended/Verbs/Verb_MeleeAttackCE.cs b/Source/CombatExtended/CombatExtended/Verbs/Verb_MeleeAttackCE.cs index d62ddf9dfc..1dfa44b3e9 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) - .FirstOrDefault(r => r.def == BodyPartDefOf.Eye); - damageInfo.SetHitPart(neck); + var hp = pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Top, BodyPartDepth.Outside) + .FirstOrDefault(r => r.def == CE_BodyPartDefOf.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) @@ -451,7 +456,11 @@ private IEnumerable DamageInfosToApply(LocalTargetInfo target, bool if (damageInfo.HitPart != null) { - damageInfo.SetHitPart(damageInfo.HitPart.GetDirectChildParts().RandomElementByWeight(x => x.coverage)); + var children = damageInfo.HitPart.GetDirectChildParts(); + if (children.Count() > 0) + { + damageInfo.SetHitPart(children.RandomElementByWeight(x => x.coverage)); + } } } }