Skip to content

Commit

Permalink
melee locked-in fix + allow non-hunting weapons
Browse files Browse the repository at this point in the history
  • Loading branch information
rheirman committed Apr 20, 2019
1 parent b3c505a commit 346376c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
Binary file modified Assemblies/RunAndGun.dll
Binary file not shown.
8 changes: 8 additions & 0 deletions Source/RunAndGun/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ namespace RunAndGun
{
public static class Extensions
{
public static bool HasRangedWeapon(this Pawn instance)
{
if(instance.equipment != null && instance.equipment.Primary != null && instance.equipment.Primary.def.IsWeaponUsingProjectiles)
{
return true;
}
return false;
}
public static bool Contains(this Rect rect, Rect otherRect)
{
if (!rect.Contains(new Vector2(otherRect.xMin, otherRect.yMin)))
Expand Down
8 changes: 6 additions & 2 deletions Source/RunAndGun/Harmony/JobDriver_Goto_SetupToils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ static void Postfix(JobDriver __instance)
Toil toil = toils.ElementAt(0);
toil.AddPreTickAction(delegate
{
if (jobDriver.pawn != null && jobDriver.pawn.IsHashIntervalTick(10) && !jobDriver.pawn.IsBurning() && (jobDriver.pawn.Drafted || !jobDriver.pawn.IsColonist) && !jobDriver.pawn.Downed)
if (jobDriver.pawn != null &&
jobDriver.pawn.IsHashIntervalTick(10) &&
!jobDriver.pawn.IsBurning() &&
(jobDriver.pawn.Drafted || !jobDriver.pawn.IsColonist) && !jobDriver.pawn.Downed)
{
checkForAutoAttack(jobDriver);
}
Expand All @@ -49,6 +52,7 @@ static void checkForAutoAttack(JobDriver_Goto __instance)
return;
}
Verb verb = __instance.pawn.TryGetAttackVerb(null);

if (verb != null)
{
TargetScanFlags targetScanFlags = TargetScanFlags.NeedLOSToPawns | TargetScanFlags.NeedLOSToNonPawns | TargetScanFlags.NeedThreat;
Expand All @@ -57,7 +61,7 @@ static void checkForAutoAttack(JobDriver_Goto __instance)
targetScanFlags |= TargetScanFlags.NeedNonBurning;
}
Thing thing = (Thing)AttackTargetFinder.BestShootTargetFromCurrentPosition(__instance.pawn, targetScanFlags, null, 0f, 9999f);
if (thing != null)
if (thing != null && !(verb.IsMeleeAttack && __instance.pawn.CanReachImmediate(thing, PathEndMode.Touch))) //Don't allow melee attacks, but take into account ranged animals or dual wield users
{
__instance.pawn.TryStartAttack(thing);
return;
Expand Down
2 changes: 1 addition & 1 deletion Source/RunAndGun/Harmony/Pawn_GetGizmos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Pawn_DraftController_GetGizmos_Patch
{
public static void Postfix(ref IEnumerable<Gizmo> __result, ref Pawn __instance)
{
if (__instance == null || !__instance.Drafted || !__instance.Faction.Equals(Faction.OfPlayer) || !WorkGiver_HunterHunt.HasHuntingWeapon(__instance))
if (__instance == null || !__instance.Drafted || !__instance.Faction.Equals(Faction.OfPlayer) || !__instance.HasRangedWeapon())
{
return;
}
Expand Down

0 comments on commit 346376c

Please sign in to comment.