internal static bool TryStartAttack(this Pawn_EquipmentTracker _this, LocalTargetInfo targ) { Pawn pawn = (Pawn)pawnFieldInfo.GetValue(_this); if (pawn.stances.FullBodyBusy) { return(false); } if (pawn.story != null && pawn.story.DisabledWorkTags.Contains(WorkTags.Violent)) { return(false); } bool allowManualCastWeapons = !pawn.IsColonist; Verb verb = pawn.TryGetAttackVerb(allowManualCastWeapons); // Check for reload before attacking if (_this.PrimaryEq != null && verb != null && verb == _this.PrimaryEq.PrimaryVerb) { if (_this.Primary != null) { CompAmmoUser compAmmo = _this.Primary.TryGetComp <CompAmmoUser>(); if (compAmmo != null) { if (!compAmmo.hasMagazine) { if (compAmmo.useAmmo && !compAmmo.hasAmmo) { return(false); } } else if (compAmmo.curMagCount <= 0) { compAmmo.TryStartReload(); return(false); } } } } return(verb != null && verb.TryStartCastOn(targ, false, true)); }
static bool ReloadCheck(Verb verb, LocalTargetInfo targ, bool surpriseAttack, bool canFreeIntercept, Pawn_EquipmentTracker __instance) { // this is no longer valid: ThingWithComps primaryInt = Traverse.Create(__instance).Field("primaryInt").GetValue() as ThingWithComps; ThingOwner <ThingWithComps> equipment = Traverse.Create(__instance).Field("equipment").GetValue <ThingOwner <ThingWithComps> >(); if (equipment != null && __instance.PrimaryEq != null && verb != null && verb == __instance.PrimaryEq.PrimaryVerb) { if (__instance.Primary != null) { CompAmmoUser compAmmo = __instance.Primary.TryGetComp <CompAmmoUser>(); if (compAmmo != null && !compAmmo.CanBeFiredNow) { if (compAmmo.HasAmmo) { compAmmo.TryStartReload(); } return(false); } } } return(verb != null && verb.TryStartCastOn(targ, surpriseAttack, canFreeIntercept)); }