static bool Prefix(ref bool __result, float points, int tile, out PawnKindDef animalKind)
        {
            MapExtensions.TileLookup.TryGetValue(tile, out Map map);
            bool flag = DefDatabase <PawnKindDef> .AllDefs.Where(
                (PawnKindDef k) =>
                k.RaceProps.Animal && k.canArriveManhunter &&
                (tile == -1 || Find.World.tileTemperatures.SeasonAndOutdoorTemperatureAcceptableFor(tile, k.race)) &&
                (map == null || map.PawnKindCanEnter(k))

                ).TryRandomElementByWeight(
                (PawnKindDef k) => ManhunterPackIncidentUtility.ManhunterAnimalWeight(k, points), out animalKind);

            if (!flag)
            {
                List <PawnKindDef> tmpAnimalKinds = new List <PawnKindDef>();
                tmpAnimalKinds.AddRange(DefDatabase <PawnKindDef> .AllDefs.Where((PawnKindDef k) => k.RaceProps.Animal && k.canArriveManhunter && map.PawnKindCanEnter(k)));
                tmpAnimalKinds.Sort((PawnKindDef a, PawnKindDef b) => b.combatPower.CompareTo(a.combatPower));
                animalKind = tmpAnimalKinds.Take(Math.Max(2, Mathf.FloorToInt(0.15f * (float)tmpAnimalKinds.Count))).RandomElement();
                __result   = animalKind != null;
            }
            else
            {
                __result = flag;
            }
            return(false);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            float totalPoints = parms.points / 2;

            HashSet <PawnKindDef> hybridsList;

            if (StaticCollectionsClass.AnyMechAntennas())
            {
                hybridsList = DefDatabase <PawnKindDef> .AllDefsListForReading.Where(x => (x.race.tradeTags?.Contains("AnimalGenetic") == true) && (x.race.tradeTags?.Contains("AnimalGeneticFailure") == false) && (x.race.tradeTags?.Contains("AnimalGeneticCentipede") == false)).ToHashSet();
            }
            else
            {
                hybridsList = DefDatabase <PawnKindDef> .AllDefsListForReading.Where(x => (x.race.tradeTags?.Contains("AnimalGenetic") == true) && (x.race.tradeTags?.Contains("AnimalGeneticFailure") == false) && (x.race.tradeTags?.Contains("AnimalGeneticMechanoid") == false)).ToHashSet();
            }

            List <Pawn> list = new List <Pawn>();

            PawnKindDef firstPawn;

            hybridsList.TryRandomElementByWeight((PawnKindDef a) => ManhunterPackIncidentUtility.ManhunterAnimalWeight(a, parms.points), out firstPawn);
            IntVec3 result = parms.spawnCenter;

            if (firstPawn != null)
            {
                if (!result.IsValid && !RCellFinder.TryFindRandomPawnEntryCell(out result, map, CellFinder.EdgeRoadChance_Animal))
                {
                    return(false);
                }
                Pawn item = PawnGenerator.GeneratePawn(new PawnGenerationRequest(firstPawn, null, PawnGenerationContext.NonPlayer, map.Tile));
                list.Add(item);
                totalPoints -= item.kindDef.combatPower;
                while (totalPoints > 0)
                {
                    PawnKindDef nextPawn;
                    hybridsList.TryRandomElementByWeight((PawnKindDef a) => ManhunterPackIncidentUtility.ManhunterAnimalWeight(a, totalPoints), out nextPawn);
                    Pawn nextitem = PawnGenerator.GeneratePawn(new PawnGenerationRequest(nextPawn, null, PawnGenerationContext.NonPlayer, map.Tile));
                    list.Add(nextitem);
                    totalPoints -= nextitem.kindDef.combatPower;
                }
            }


            Rot4 rot = Rot4.FromAngleFlat((map.Center - result).AngleFlat);

            for (int i = 0; i < list.Count; i++)
            {
                Pawn    pawn = list[i];
                IntVec3 loc  = CellFinder.RandomClosewalkCellNear(result, map, 10);
                QuestUtility.AddQuestTag(GenSpawn.Spawn(pawn, loc, map, rot), parms.questTag);
                pawn.health.AddHediff(InternalDefOf.GR_GreaterScaria);
                pawn.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.ManhunterPermanent);
                CompHybrid compHybrid = pawn.TryGetComp <CompHybrid>();

                if (compHybrid != null)
                {
                    compHybrid.quality = QualityUtility.GenerateQualityRandomEqualChance();
                }
            }
            SendStandardLetter("GR_LetterLabelMonstrositiesArrived".Translate(), "GR_LetterMonstrositiesArrived".Translate(), LetterDefOf.ThreatBig, parms, list[0]);
            Find.TickManager.slower.SignalForceNormalSpeedShort();

            return(true);
        }