Skip to content

Commit

Permalink
Fall back to targeting the head for creatures without necks
Browse files Browse the repository at this point in the history
  • Loading branch information
perkinslr committed Jun 23, 2024
1 parent 4ca8694 commit b746214
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ static MeleeTargettingAdd()
}
}
}

[StaticConstructorOnStartup]
public class CompMeleeTargettingGizmo : ThingComp
{
static CompMeleeTargettingGizmo()
{
priorityList = new List<BodyPartDef>() {
CE_BodyPartDefOf.Neck,
BodyPartDefOf.Eye,
BodyPartDefOf.Head
};
}
private static List<BodyPartDef> priorityList = null;
#region Fields
public Pawn PawnParent => (Pawn)this.parent;

Expand Down Expand Up @@ -92,26 +103,26 @@ 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)
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,14 @@ private IEnumerable<DamageInfo> 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)
Expand Down

0 comments on commit b746214

Please sign in to comment.