Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Neck BodyPart for melee targeting #3206

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = 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;
}

Expand Down
12 changes: 12 additions & 0 deletions Source/CombatExtended/CombatExtended/DefOfs/CE_BodyPartDefOf.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using Verse;
using RimWorld;

namespace CombatExtended
{
[DefOf]
public static class CE_BodyPartDefOf
{
public static BodyPartDef Neck;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ private void RebuildArmorCache(Dictionary<BodyPartRecord, float> 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)
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)
.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)
Expand Down
Loading