protected override bool Satisfied(Pawn pawn)
 {
     i++;
     i %= 2579 + 579 + 7;
     return(pawn.IsColonist && !pawn.Drafted &&
            ((AmHunter(pawn) && !WorkGiver_HunterHunt.HasHuntingWeapon(pawn)) || //alert!!!
             i % (2579 + pawn.Name.GetHashCode() % 579) != 0));
     //range for normal optimize clothing is 3000-6000 this gives an offset of about that without storing another
     //value but using the names hash as salt which is effectively constant cost.
     //O(n), st n E [10,70] = O(70) = O(1)
 }
Beispiel #2
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn.Map == null)
            {
                return(null);
            }
            if (!WorkGiver_HunterHunt.HasHuntingWeapon(pawn))
            {
                IEnumerable <Thing> huntingWeapons = (from t in pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Weapon)
                                                      where t.def.IsRangedWeapon && t.TryGetComp <CompEquippable>().PrimaryVerb.HarmsHealth() && !t.TryGetComp <CompEquippable>().PrimaryVerb.UsesExplosiveProjectiles() && pawn.CanReserveAndReach(t, PathEndMode.Touch, Danger.None)
                                                      orderby t.GetStatValue(StatDefOf.AccuracyLong) descending
                                                      select t);
                if (huntingWeapons.Count() > 0)
                {
                    Thing bestWeapon = huntingWeapons.First();
                    if (pawn.equipment.Primary == null || !pawn.equipment.Primary.def.IsRangedWeapon || !pawn.equipment.PrimaryEq.PrimaryVerb.HarmsHealth() || pawn.equipment.PrimaryEq.PrimaryVerb.UsesExplosiveProjectiles() || pawn.equipment.Primary.GetStatValue(StatDefOf.AccuracyLong) < bestWeapon.GetStatValue(StatDefOf.AccuracyLong))
                    {
                        return(new Job(JobDefOf.Equip, bestWeapon));
                    }
                }
            }
            if (WorkGiver_HunterHunt.HasShieldAndRangedWeapon(pawn))
            {
                List <Apparel> wornApparel = pawn.apparel.WornApparel;
                for (int i = 0; i < wornApparel.Count; i++)
                {
                    if (wornApparel[i] is ShieldBelt)
                    {
                        return(new Job(JobDefOf.DropEquipment, wornApparel[i]));
                    }
                }
            }
            if (!(pawn.MentalState is MentalState_HuntingTrip))
            {
                return(null);
            }
            Pawn assignedPrey = (pawn.MentalState as MentalState_HuntingTrip).prey;

            if (assignedPrey != null && !assignedPrey.Dead)
            {
                return(new Job(JobDefOfPsychology.BreakHunt, assignedPrey));
            }
            IEnumerable <Pawn> wildlife = from p in Find.CurrentMap.mapPawns.AllPawns
                                          where p.Spawned && p.Faction == null && p.AnimalOrWildMan() && !p.Position.Fogged(p.Map) && pawn.CanReserve(p, 1, -1, null, true)
                                          select p;

            if (wildlife.Count() > 0)
            {
                Pawn prey = wildlife.RandomElement();
                (pawn.MentalState as MentalState_HuntingTrip).prey = prey;
                return(new Job(JobDefOfPsychology.BreakHunt, prey));
            }
            return(null);
        }
Beispiel #3
0
        private Priority considerHunting()
        {
            if (this.workTypeDef.defName != hunting)
            {
                return(this);
            }
            bool isBrawler = this.pawn.story.traits.HasTrait(DefDatabase <TraitDef> .GetNamed("Brawler")) && !YouDoYou_Settings.BrawlersCanHunt;

            return(this
                   .neverDoIf(isBrawler, "YouDoYouPriorityBrawler".Translate())
                   .neverDoIf(!WorkGiver_HunterHunt.HasHuntingWeapon(pawn), "YouDoYouPriorityNoHuntingWeapon".Translate()));
        }
        protected override bool Satisfied(Pawn pawn)
        {
            if (!pawn.IsColonist)
            {
                return(true);
            }

            if (pawn.Drafted)
            {
                return(true);
            }

            if (pawn.workSettings.WorkIsActive(WorkTypeDefOf.Hunting) && WorkGiver_HunterHunt.HasHuntingWeapon(pawn))
            {
                return(true);
            }

            i++;
            i %= 2579 + 579 + 7;
            return(i % (2579 + (pawn.Name.GetHashCode() % 579)) != 0);
            //range for normal optimize clothing is 3000-6000 this gives an offset of about that without storing another
            //value but using the names hash as salt which is effectively constant cost.
            //O(n), st n E [10,70] = O(70) = O(1)
        }
        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))
            {
                return;
            }
            if (__result == null || !__result.Any())
            {
                return;
            }

            CompRunAndGun data = __instance.TryGetComp <CompRunAndGun>();

            if (data == null)
            {
                return;
            }
            if (__instance.equipment != null && __instance.equipment.Primary != null)
            {
                bool found = Settings.weaponForbidder.Value.InnerList.TryGetValue(__instance.equipment.Primary.def.defName, out WeaponRecord value);
                if (found && value.isSelected)
                {
                    return;
                }
            }

            String uiElement   = "enable_RG";
            String label       = "RG_Action_Enable_Label".Translate();
            String description = data.isEnabled ? "RG_Action_Disable_Description".Translate() : "RG_Action_Enable_Description".Translate();


            var gizmoList = __result.ToList();
            var ourGizmo  = new Command_Toggle
            {
                defaultLabel = label,
                defaultDesc  = description,
                icon         = ContentFinder <Texture2D> .Get(("UI/Buttons/" + uiElement), true),
                isActive     = () => data.isEnabled,
                toggleAction = () => { data.isEnabled = !data.isEnabled; }
            };


            gizmoList.Add(ourGizmo);
            __result = gizmoList;
        }
 protected override bool Satisfied(Pawn pawn)
 {
     return(!WorkGiver_HunterHunt.HasHuntingWeapon(pawn));
 }
Beispiel #7
0
 public override bool ShouldSkip(Pawn pawn)
 {
     return(!WorkGiver_HunterHunt.HasHuntingWeapon(pawn) || pawn.equipment.Primary.def.defName.Contains("TFJ_Tool") || WorkGiver_HunterHunt.HasShieldAndRangedWeapon(pawn));
 }