private Job TryOutfit(Pawn pawn)
        {
            if (pawn.equipment == null)
            {
                return(null);
            }

            if (pawn.RaceProps.Humanlike && pawn.story.WorkTagIsDisabled(WorkTags.Violent))
            {
                Gunfitter.Trace(pawn.ToString() + " is a wuss and cant even gunfit.");
                return(null);
            }

            if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                return(null);
            }

            List <Thing> list          = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Weapon);
            Outfit       currentOutfit = pawn.outfits.CurrentOutfit;


            Thing thing = null;

            for (int j = 0; j < list?.Count; j++)
            {
                var gun = list[j];
                if (!currentOutfit.filter.Allows(gun))
                {
                    continue;
                }
                if (!gun.IsInAnyStorage())
                {
                    continue;
                }
                if (gun.IsForbidden(pawn))
                {
                    continue;
                }
                if (!this.ShouldEquipByOutfit(gun, pawn))
                {
                    continue;
                }
                if (!pawn.CanReserveAndReach(gun, PathEndMode.OnCell, pawn.NormalMaxDanger(), 1, -1, null, false)
                    )
                {
                    continue;
                }

                Gunfitter.Trace(pawn.ToString() + "Off to be gunfitted");
                return(new Job(JobDefOf.Equip, gun));
            }


            Gunfitter.Trace("Nothing for [" + pawn + "]");

            return(null);
        }
        private Job TryOutfit(Pawn pawn)
        {
            if (!pawn.IsColonist || pawn.Drafted)
            {
                return(null);
            }

            if (pawn.equipment == null)
            {
                Gunfitter.Trace(pawn + " has no equipment settings.");
                return(null);
            }

            if (pawn.RaceProps.Humanlike && pawn.WorkTagIsDisabled(WorkTags.Violent))
            {
                Gunfitter.Trace(pawn + " is incapable of violence.");
                return(null);
            }

            if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                Gunfitter.Trace(pawn + " can not manipulate things.");
                return(null);
            }

            if (pawn.equipment?.Primary != null)
            {
                if (FindAGunDamnItMod.instance.Settings.FindingSetting == FindAGunDamnItMod.findingSettings[0] ||
                    ModLister.HasActiveModWithName("Simple sidearms"))
                {
                    Gunfitter.Trace(pawn + " has a weapon and simple sidearms is loaded or setting is " +
                                    FindAGunDamnItMod.findingSettings[0] + ", will not evaluate new guns.");
                    return(null);
                }

                var currentGun = pawn.equipment.Primary;
                if (FindAGunDamnItMod.instance.Settings.FindingSetting == FindAGunDamnItMod.findingSettings[1])
                {
                    var hunter  = pawn.workSettings.WorkIsActive(WorkTypeDefOf.Hunting);
                    var brawler = pawn.story.traits.HasTrait(TraitDefOf.Brawler);
                    if (!hunter && !brawler)
                    {
                        Gunfitter.Trace(pawn + " is not brawler or hunter and setting is " +
                                        FindAGunDamnItMod.findingSettings[1] + ", will not evaluate new guns.");
                        return(null);
                    }

                    if (brawler && currentGun.def.IsMeleeWeapon || hunter && currentGun.def.IsRangedWeapon)
                    {
                        Gunfitter.Trace(pawn + " is brawler or hunter with an appropriate weapon and setting is " +
                                        FindAGunDamnItMod.findingSettings[1] + ", will not evaluate new guns.");
                        return(null);
                    }
                }
            }

            var list        = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Weapon);
            var allowedGuns = new List <Thing>();

            for (var j = 0; j < list?.Count; j++)
            {
                var gun = list[j];
                Gunfitter.Trace(pawn + " testing weapon: " + gun.def, true);
                if (gun.IsForbidden(pawn))
                {
                    continue;
                }

                Gunfitter.Trace(gun.def + " is allowed", true);
                if (gun.def.IsMeleeWeapon && gun.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS) < whatAFistCanDo)
                {
                    continue;
                }

                Gunfitter.Trace(gun.def + " is better than a fist", true);
                if (!this.ShouldEquipByOutfit(gun, pawn))
                {
                    continue;
                }

                Gunfitter.Trace(pawn + " should be equiped by outfit " + gun.def, true);
                if (!pawn.CanReserveAndReach(gun, PathEndMode.OnCell, Danger.None))
                {
                    continue;
                }

                Gunfitter.Trace(pawn + " can equip " + gun.def, true);
                allowedGuns.Add(gun);
            }

            Gunfitter.Trace(pawn + " determining best gun from equippable.");
            var bestGun = this.bestGunForPawn(allowedGuns, pawn);

            if (bestGun == null)
            {
                return(null);
            }

            if (Prefs.DevMode)
            {
                Log.Message("FindAGunDamnIt: " + pawn + " will equip " + bestGun.def);
            }
            else
            {
                Gunfitter.Trace(pawn + " will equip " + bestGun.def);
            }

            return(new Job(JobDefOf.Equip, bestGun));
        }