public override void Resolve(ResolveParams rp)
 {
     if (rp.singlePawnToSpawn == null || !rp.singlePawnToSpawn.Spawned)
     {
         Map     map = BaseGen.globalSettings.map;
         IntVec3 loc;
         if (!SymbolResolver_SinglePawn.TryFindSpawnCell(rp, out loc))
         {
             if (rp.singlePawnToSpawn != null)
             {
                 Find.WorldPawns.PassToWorld(rp.singlePawnToSpawn, PawnDiscardDecideMode.Decide);
             }
         }
         else
         {
             Pawn pawn;
             if (rp.singlePawnToSpawn == null)
             {
                 PawnGenerationRequest value;
                 if (rp.singlePawnGenerationRequest != null)
                 {
                     value = rp.singlePawnGenerationRequest.Value;
                 }
                 else
                 {
                     PawnKindDef pawnKindDef;
                     if ((pawnKindDef = rp.singlePawnKindDef) == null)
                     {
                         pawnKindDef = (from x in DefDatabase <PawnKindDef> .AllDefsListForReading
                                        where x.defaultFactionType == null || !x.defaultFactionType.isPlayer
                                        select x).RandomElement <PawnKindDef>();
                     }
                     PawnKindDef pawnKindDef2 = pawnKindDef;
                     Faction     faction      = rp.faction;
                     if (faction == null && pawnKindDef2.RaceProps.Humanlike)
                     {
                         if (pawnKindDef2.defaultFactionType != null)
                         {
                             faction = FactionUtility.DefaultFactionFrom(pawnKindDef2.defaultFactionType);
                             if (faction == null)
                             {
                                 return;
                             }
                         }
                         else if (!(from x in Find.FactionManager.AllFactions
                                    where !x.IsPlayer
                                    select x).TryRandomElement(out faction))
                         {
                             return;
                         }
                     }
                     PawnKindDef kind     = pawnKindDef2;
                     Faction     faction2 = faction;
                     int         tile     = map.Tile;
                     value = new PawnGenerationRequest(kind, faction2, PawnGenerationContext.NonPlayer, tile, false, false, false, false, true, false, 1f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null);
                 }
                 pawn = PawnGenerator.GeneratePawn(value);
                 if (rp.postThingGenerate != null)
                 {
                     rp.postThingGenerate(pawn);
                 }
             }
             else
             {
                 pawn = rp.singlePawnToSpawn;
             }
             if (!pawn.Dead && rp.disableSinglePawn != null && rp.disableSinglePawn.Value)
             {
                 pawn.mindState.Active = false;
             }
             GenSpawn.Spawn(pawn, loc, map, WipeMode.Vanish);
             if (rp.singlePawnLord != null)
             {
                 rp.singlePawnLord.AddPawn(pawn);
             }
             if (rp.postThingSpawn != null)
             {
                 rp.postThingSpawn(pawn);
             }
         }
     }
 }
Ejemplo n.º 2
0
        private static void PawnKindApparelCheck()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (PawnKindDef item in from kd in DefDatabase <PawnKindDef> .AllDefs
                     where kd.race == ThingDefOf.Human
                     orderby kd.defName
                     select kd)
            {
                PawnKindDef localKindDef = item;
                list.Add(new DebugMenuOption(localKindDef.defName, DebugMenuOptionMode.Action, delegate
                {
                    Faction faction = FactionUtility.DefaultFactionFrom(localKindDef.defaultFactionType);
                    bool flag       = false;
                    for (int k = 0; k < 100; k++)
                    {
                        Pawn pawn2 = PawnGenerator.GeneratePawn(localKindDef, faction);
                        if (pawn2.royalty != null)
                        {
                            RoyalTitle mostSeniorTitle2 = pawn2.royalty.MostSeniorTitle;
                            if (mostSeniorTitle2 != null && !mostSeniorTitle2.def.requiredApparel.NullOrEmpty())
                            {
                                for (int l = 0; l < mostSeniorTitle2.def.requiredApparel.Count; l++)
                                {
                                    if (!mostSeniorTitle2.def.requiredApparel[l].IsMet(pawn2))
                                    {
                                        Log.Error(localKindDef + " (" + mostSeniorTitle2.def.label + ")  does not have its title requirements met. index=" + l + logApparel(pawn2));
                                        flag = true;
                                    }
                                }
                            }
                        }
                        List <Apparel> wornApparel2 = pawn2.apparel.WornApparel;
                        for (int m = 0; m < wornApparel2.Count; m++)
                        {
                            string text = apparelOkayToWear(pawn2, wornApparel2[m]);
                            if (text != "OK")
                            {
                                Log.Error(text + " - " + wornApparel2[m].Label + logApparel(pawn2));
                                flag = true;
                            }
                        }
                        Find.WorldPawns.PassToWorld(pawn2, PawnDiscardDecideMode.Discard);
                    }
                    if (!flag)
                    {
                        Log.Message("No errors for " + localKindDef.defName);
                    }
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
            string apparelOkayToWear(Pawn pawn, Apparel apparel)
            {
                ApparelProperties app = apparel.def.apparel;

                if (!pawn.kindDef.apparelRequired.NullOrEmpty() && pawn.kindDef.apparelRequired.Contains(apparel.def))
                {
                    return("OK");
                }
                if (!app.CorrectGenderForWearing(pawn.gender))
                {
                    return("Wrong gender.");
                }
                List <SpecificApparelRequirement> specificApparelRequirements = pawn.kindDef.specificApparelRequirements;

                if (specificApparelRequirements != null)
                {
                    for (int i = 0; i < specificApparelRequirements.Count; i++)
                    {
                        if (PawnApparelGenerator.ApparelRequirementHandlesThing(specificApparelRequirements[i], apparel.def) && PawnApparelGenerator.ApparelRequirementTagsMatch(specificApparelRequirements[i], apparel.def))
                        {
                            return("OK");
                        }
                    }
                }
                if (!pawn.kindDef.apparelTags.NullOrEmpty())
                {
                    if (!app.tags.Any((string tag) => pawn.kindDef.apparelTags.Contains(tag)))
                    {
                        return("Required tag missing.");
                    }
                    if ((pawn.royalty == null || pawn.royalty.MostSeniorTitle == null) && app.tags.Contains("Royal") && !pawn.kindDef.apparelTags.Any((string tag) => app.tags.Contains(tag)))
                    {
                        return("Royal apparel on non-royal pawn.");
                    }
                }
                if (!pawn.kindDef.apparelDisallowTags.NullOrEmpty() && pawn.kindDef.apparelDisallowTags.Any((string t) => app.tags.Contains(t)))
                {
                    return("Has a disallowed tag.");
                }
                if (pawn.royalty != null && pawn.royalty.AllTitlesInEffectForReading.Any())
                {
                    RoyalTitle mostSeniorTitle = pawn.royalty.MostSeniorTitle;
                    if (apparel.TryGetQuality(out QualityCategory qc) && (int)qc < (int)mostSeniorTitle.def.requiredMinimumApparelQuality)
                    {
                        return("Quality too low.");
                    }
                }
                return("OK");
            }

            string logApparel(Pawn p)
            {
                StringBuilder stringBuilder = new StringBuilder();

                stringBuilder.AppendLine();
                stringBuilder.AppendLine($"Apparel of {p.LabelShort}:");
                List <Apparel> wornApparel = p.apparel.WornApparel;

                for (int j = 0; j < wornApparel.Count; j++)
                {
                    stringBuilder.AppendLine("  - " + wornApparel[j].Label);
                }
                return(stringBuilder.ToString());
            }
        }
Ejemplo n.º 3
0
        public static void PawnWorkDisablesSampled()
        {
            IOrderedEnumerable <PawnKindDef> orderedEnumerable = from k in DefDatabase <PawnKindDef> .AllDefs
                                                                 where k.RaceProps.Humanlike
                                                                 orderby k.combatPower
                                                                 select k;
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            foreach (PawnKindDef current in orderedEnumerable)
            {
                PawnKindDef     kind = current;
                Faction         fac  = FactionUtility.DefaultFactionFrom(kind.defaultFactionType);
                FloatMenuOption item = new FloatMenuOption(string.Concat(new object[]
                {
                    kind.defName,
                    " (",
                    kind.combatPower,
                    ")"
                }), delegate
                {
                    Dictionary <WorkTags, int> dictionary = new Dictionary <WorkTags, int>();
                    for (int i = 0; i < 1000; i++)
                    {
                        Pawn pawn = PawnGenerator.GeneratePawn(kind, fac);
                        WorkTags combinedDisabledWorkTags = pawn.story.CombinedDisabledWorkTags;
                        foreach (WorkTags workTags in Enum.GetValues(typeof(WorkTags)))
                        {
                            if (!dictionary.ContainsKey(workTags))
                            {
                                dictionary.Add(workTags, 0);
                            }
                            if ((combinedDisabledWorkTags & workTags) != WorkTags.None)
                            {
                                Dictionary <WorkTags, int> dictionary2;
                                WorkTags key;
                                (dictionary2 = dictionary)[key = workTags] = dictionary2[key] + 1;
                            }
                        }
                        pawn.Destroy(DestroyMode.Vanish);
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine(string.Concat(new object[]
                    {
                        "Sampled ",
                        1000,
                        "x ",
                        kind.defName,
                        ":"
                    }));
                    stringBuilder.AppendLine("Worktags disabled");
                    foreach (WorkTags key2 in Enum.GetValues(typeof(WorkTags)))
                    {
                        int num = dictionary[key2];
                        stringBuilder.AppendLine(string.Concat(new object[]
                        {
                            "  ",
                            key2.ToString(),
                            "    ",
                            num,
                            " (",
                            ((float)num / 1000f).ToStringPercent(),
                            ")"
                        }));
                    }
                    Log.Message(stringBuilder.ToString().TrimEndNewlines(), false);
                }, MenuOptionPriority.Default, null, null, 0f, null, null);
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
Ejemplo n.º 4
0
        public override void MapComponentTick()
        {
            base.MapComponentTick();
            if (Find.TickManager.TicksGame % 250 == 0)
            {
                var plants = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.PurpleIvy);
                //Log.Message("Checking orbital strike, " + this.OrbitalHelpActive + " - " + plants.Count);
                if (plants != null && ((this.OrbitalHelpActive == true && plants.Count > 0) ||
                                       plants.Count > 2000)) // && Rand.Chance(PurpleIvyData.getFogProgress(plants.Count)))
                {
                    if (this.OrbitalHelpActive == false)
                    {
                        this.OrbitalHelpActive = true;
                        Find.LetterStack.ReceiveLetter("OrbitalHelpFromAncients".Translate(),
                                                       "OrbitalHelpFromAncientsDesc".Translate(),
                                                       LetterDefOf.NeutralEvent, new TargetInfo(plants.RandomElement().Position, map, false));
                    }
                    PowerBeam powerBeam = (PowerBeam)GenSpawn.Spawn(PurpleIvyDefOf.PI_PowerBeam,
                                                                    plants.RandomElement().Position, this.map, 0);
                    powerBeam.duration   = 200;
                    powerBeam.instigator = null;
                    powerBeam.weaponDef  = null;
                    powerBeam.StartStrike();
                }
                if ((plants.Count <= 0 || plants == null) && this.OrbitalHelpActive == true)
                {
                    Log.Message("Orbital help");
                    this.OrbitalHelpActive = false;
                    List <Pawn> list = new List <Pawn>();

                    var alpha = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteAlpha);
                    var beta  = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteBeta);
                    var gamma = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteGamma);
                    var omega = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteOmega);
                    var guard = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteNestGuard);

                    int pawnCount = alpha.Count;
                    pawnCount += beta.Count;
                    pawnCount += gamma.Count;
                    pawnCount += omega.Count;
                    pawnCount += guard.Count;
                    Predicate <IntVec3> predicate = delegate(IntVec3 c)
                    {
                        return(!GridsUtility.Fogged(c, map) &&
                               !GridsUtility.Roofed(c, map) &&
                               GenGrid.InBounds(c, map) &&
                               GenRadial.RadialCellsAround(c, 10, true).Where(x =>
                                                                              map.thingGrid.ThingsListAt(x).Where(y => y.Faction == PurpleIvyData.AlienFaction)
                                                                              != null) != null);
                    };
                    IntVec3 position = CellFinder.RandomClosewalkCellNear(this.map.Center, this.map, 500,
                                                                          predicate);
                    foreach (var num in Enumerable.Range(1, pawnCount / 2))
                    {
                        Faction faction = FactionUtility.DefaultFactionFrom(PurpleIvyDefOf.KorsolianFaction);
                        Pawn    NewPawn = PawnGenerator.GeneratePawn(PurpleIvyDefOf.KorsolianSoldier, faction);
                        if (faction != null && faction != Faction.OfPlayer)
                        {
                            Lord lord = null;
                            if (this.map.mapPawns.SpawnedPawnsInFaction(faction).Any((Pawn p) =>
                                                                                     p != NewPawn))
                            {
                                lord = ((Pawn)GenClosest.ClosestThing_Global(NewPawn.Position,
                                                                             this.map.mapPawns.SpawnedPawnsInFaction(faction), 99999f,
                                                                             (Thing p) => p != NewPawn && ((Pawn)p).GetLord() != null, null)).GetLord();
                            }
                            if (lord == null)
                            {
                                var lordJob = new LordJob_AssistColony(Faction.OfPlayer, position);
                                //LordJob_DefendPoint lordJob = new LordJob_DefendPoint(position);
                                lord = LordMaker.MakeNewLord(faction, lordJob, this.map, null);
                            }
                            lord.AddPawn(NewPawn);
                        }
                        Log.Message(NewPawn?.Faction?.def?.defName);
                        list.Add(NewPawn);
                    }
                    DropPodUtility.DropThingsNear(position, this.map, list, 30, false, true, true, true);
                    Find.LetterStack.ReceiveLetter("AncientsLandOnTheGround".Translate(),
                                                   "AncientsLandOnTheGroundDesc".Translate(),
                                                   LetterDefOf.NeutralEvent, new TargetInfo(position, map, false));
                }
                //Log.Message("Alpha limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteAlpha.defName]);
                //Log.Message("Beta limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteBeta.defName]);
                //Log.Message("Gamma limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteGamma.defName]);
                //Log.Message("Omega limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteOmega.defName]);
                int  count = plants.Count;
                bool comeFromOuterSource;
                var  tempComp = new WorldObjectComp_InfectedTile();
                tempComp.infectedTile = map.Tile;
                if (PurpleIvyUtils.getFogProgressWithOuterSources(count, tempComp, out comeFromOuterSource) > 0f &&
                    !map.gameConditionManager.ConditionIsActive(PurpleIvyDefOf.PurpleFogGameCondition))
                {
                    GameCondition_PurpleFog gameCondition =
                        (GameCondition_PurpleFog)GameConditionMaker.MakeConditionPermanent
                            (PurpleIvyDefOf.PurpleFogGameCondition);
                    map.gameConditionManager.RegisterCondition(gameCondition);
                    if (comeFromOuterSource == false)
                    {
                        Find.LetterStack.ReceiveLetter(gameCondition.LabelCap,
                                                       gameCondition.LetterText, gameCondition.def.letterDef,
                                                       new TargetInfo(map.Center, map, false));
                    }
                    else
                    {
                        Find.LetterStack.ReceiveLetter("PurpleFogСomesFromInfectedSites".Translate(),
                                                       "PurpleFogСomesFromInfectedSitesDesc".Translate(),
                                                       LetterDefOf.ThreatBig, new TargetInfo(map.Center, map, false));
                        Log.Message("PurpleFogСomesFromInfectedSites: " + map.ToString()
                                    + " - " + Find.TickManager.TicksGame.ToString());
                    }
                    if (map.Parent.GetComponent <WorldObjectComp_InfectedTile>() == null)
                    {
                        var comp = new WorldObjectComp_InfectedTile();
                        comp.parent = map.Parent;
                        comp.StartInfection();
                        comp.gameConditionCaused = PurpleIvyDefOf.PurpleFogGameCondition;
                        comp.counter             = count;
                        comp.infectedTile        = map.Tile;
                        comp.radius = comp.GetRadius();
                        PurpleIvyData.TotalFogProgress[comp] = PurpleIvyUtils.getFogProgress(comp.counter);
                        comp.fillRadius();
                        map.Parent.AllComps.Add(comp);
                        Log.Message("Adding comp to: " + map.Parent.ToString());
                    }
                }
            }
            if (Find.TickManager.TicksGame % 60000 == 0)
            {
                int count     = 0;
                var alphaEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSac);
                var betaEggs  = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacBeta);
                var gammaEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacGamma);
                var nestsEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacNestGuard);
                var omegaEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.ParasiteEgg);

                Log.Message("Total PurpleIvy count on the map: " +
                            this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.PurpleIvy).Count.ToString(), true);

                count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteAlpha).Count;
                if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteAlpha.defName])
                {
                    foreach (var egg in alphaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = true;
                    }
                }
                else
                {
                    foreach (var egg in alphaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = false;
                    }
                }
                Log.Message("Total Genny_ParasiteAlpha count on the map: " + count.ToString(), true);
                count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteBeta).Count;
                if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteBeta.defName])
                {
                    foreach (var egg in betaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = true;
                    }
                }
                else
                {
                    foreach (var egg in betaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = false;
                    }
                }
                Log.Message("Total Genny_ParasiteBeta count on the map: " + count.ToString(), true);
                count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteGamma).Count;
                if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteGamma.defName])
                {
                    foreach (var egg in gammaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = true;
                    }
                }
                else
                {
                    foreach (var egg in gammaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = false;
                    }
                }
                Log.Message("Total Genny_ParasiteGamma count on the map: " + count.ToString(), true);
                count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteOmega).Count;
                if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteOmega.defName])
                {
                    foreach (var egg in omegaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = true;
                    }
                }
                else
                {
                    foreach (var egg in omegaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = false;
                    }
                }
                Log.Message("Total Genny_ParasiteOmega count on the map: " + count.ToString(), true);
                Log.Message("Total Genny_ParasiteNestGuard count on the map: " +
                            this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteNestGuard).Count.ToString(), true);
                Log.Message("Total EggSac count on the map: " + alphaEggs.Count.ToString(), true);
                Log.Message("Total EggSac beta count on the map: " + betaEggs.Count.ToString(), true);
                Log.Message("Total EggSac gamma count on the map: " + gammaEggs.Count.ToString(), true);
                Log.Message("Total EggSac NestGuard count on the map: " + nestsEggs.Count.ToString(), true);
                Log.Message("Total ParasiteEgg count on the map: " + omegaEggs.Count.ToString(), true);
                Log.Message("Total GasPump count on the map: " +
                            this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.GasPump).Count.ToString(), true);
                Log.Message("Total GenTurretBase count on the map: " +
                            this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.GenTurretBase).Count.ToString(), true);
                Log.Message("Total Turret_GenMortarSeed count on the map: " +
                            this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Turret_GenMortarSeed).Count.ToString(), true);
                Log.Message("Total Nest count on the map: " +
                            this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.PI_Nest).Count.ToString(), true);
            }
        }
Ejemplo n.º 5
0
        public override void Tick()
        {
            base.Tick();
            if (Downed)
            {
                if (lastTakenDamageFrom is Pawn killer && killer.RaceProps.Humanlike && killer.story.traits.HasTrait(RWBYDefOf.Semblance_Weiss) && killer.TryGetComp <CompAbilityUserAura>() is CompAbilityUserAura compAbilityUserAura && compAbilityUserAura.IsInitialized)
                {
                    if (this.RaceProps.AnyPawnKind == RWBYDefOf.Grimm_Boarbatusk)
                    {
                        if (!compAbilityUserAura.AbilityData.AllPowers.Any(p => p.Def == RWBYDefOf.Weiss_SummonBoar))
                        {
                            compAbilityUserAura.AddPawnAbility(RWBYDefOf.Weiss_SummonBoar);
                        }
                    }
                    else if (this.RaceProps.AnyPawnKind == RWBYDefOf.Grimm_Beowolf)
                    {
                        if (!compAbilityUserAura.AbilityData.AllPowers.Any(p => p.Def == RWBYDefOf.Weiss_SummonBeowolf))
                        {
                            compAbilityUserAura.AddPawnAbility(RWBYDefOf.Weiss_SummonBeowolf);
                        }
                    }
                    else if (this.RaceProps.AnyPawnKind == RWBYDefOf.Grimm_Ursa)
                    {
                        if (!compAbilityUserAura.AbilityData.AllPowers.Any(p => p.Def == RWBYDefOf.Weiss_SummonUrsa))
                        {
                            compAbilityUserAura.AddPawnAbility(RWBYDefOf.Weiss_SummonUrsa);
                        }
                    }
                    else if (this.RaceProps.AnyPawnKind == RWBYDefOf.Grimm_Griffon)
                    {
                        if (!compAbilityUserAura.AbilityData.AllPowers.Any(p => p.Def == RWBYDefOf.Weiss_SummonGriffon))
                        {
                            compAbilityUserAura.AddPawnAbility(RWBYDefOf.Weiss_SummonGriffon);
                        }
                    }
                    else if (this.RaceProps.AnyPawnKind == RWBYDefOf.Grimm_Nevermore)
                    {
                        if (!compAbilityUserAura.AbilityData.AllPowers.Any(p => p.Def == RWBYDefOf.Weiss_SummonNevermore))
                        {
                            compAbilityUserAura.AddPawnAbility(RWBYDefOf.Weiss_SummonNevermore);
                        }
                    }
                    else if (this.RaceProps.AnyPawnKind == RWBYDefOf.Grimm_Lancer)
                    {
                        if (!compAbilityUserAura.AbilityData.AllPowers.Any(p => p.Def == RWBYDefOf.Weiss_SummonLancer))
                        {
                            compAbilityUserAura.AddPawnAbility(RWBYDefOf.Weiss_SummonLancer);
                        }
                    }
                    else if (this.RaceProps.AnyPawnKind == RWBYDefOf.Grimm_LancerQueen)
                    {
                        if (!compAbilityUserAura.AbilityData.AllPowers.Any(p => p.Def == RWBYDefOf.Weiss_SummonLancerQueen))
                        {
                            compAbilityUserAura.AddPawnAbility(RWBYDefOf.Weiss_SummonLancerQueen);
                        }
                    }
                    else if (this.RaceProps.AnyPawnKind == RWBYDefOf.Grimm_DeathStalker)
                    {
                        if (!compAbilityUserAura.AbilityData.AllPowers.Any(p => p.Def == RWBYDefOf.Weiss_SummonDeathStalker))
                        {
                            compAbilityUserAura.AddPawnAbility(RWBYDefOf.Weiss_SummonDeathStalker);
                        }
                    }
                    else if (this.RaceProps.AnyPawnKind == RWBYDefOf.Grimm_Nuckelavee)
                    {
                        if (!compAbilityUserAura.AbilityData.AllPowers.Any(p => p.Def == RWBYDefOf.Weiss_SummonNuckelavee))
                        {
                            compAbilityUserAura.AddPawnAbility(RWBYDefOf.Weiss_SummonNuckelavee);
                        }
                    }
                    else if (this.RaceProps.AnyPawnKind == RWBYDefOf.Grimm_Apathy)
                    {
                        if (!compAbilityUserAura.AbilityData.AllPowers.Any(p => p.Def == RWBYDefOf.Weiss_SummonApathy))
                        {
                            compAbilityUserAura.AddPawnAbility(RWBYDefOf.Weiss_SummonApathy);
                        }
                    }
                }
                Kill(null);
            }
            attractGrimmTimer--;
            nuckelaveeTimer--;

            if (this.Map != null && this.RaceProps.AnyPawnKind == RWBYDefOf.Grimm_Nuckelavee && nuckelaveeTimer > 0 && nuckelaveeTimer % 2500 == 0 && !this.InMentalState) // Nuckelavee spawn more Grimm
            {
                Pawn    pawn = PawnGenerator.GeneratePawn(GrimmUtility.GetRandomGrimmBalanced(), FactionUtility.DefaultFactionFrom(RWBYDefOf.Creatures_of_Grimm));
                IntVec3 loc  = CellFinder.RandomClosewalkCellNear(this.Position, this.Map, 8, null);
                if (pawn is Pawn_Grimm pawn_Grimm)
                {
                    pawn_Grimm.SetNuckelaveeTimer(nuckelaveeTimer);
                }
                GenSpawn.Spawn(pawn, loc, this.Map, this.Rotation, WipeMode.Vanish, false);
            }

            if (this.Map != null && this.IsHashIntervalTick(30000) && this.RaceProps.AnyPawnKind == RWBYDefOf.Grimm_Apathy && !this.InMentalState && this.Map.mapPawns.AllPawnsSpawned.FindAll(p => p.RaceProps.AnyPawnKind == RWBYDefOf.Grimm_Apathy).Count() < this.Map.mapPawns.ColonistCount * 10) // Apathy spawn more Apathy
            {
                Pawn    pawn = PawnGenerator.GeneratePawn(RWBYDefOf.Grimm_Apathy, FactionUtility.DefaultFactionFrom(RWBYDefOf.Creatures_of_Grimm));
                IntVec3 loc  = CellFinder.RandomClosewalkCellNear(this.Position, this.Map, 8, null);
                if (pawn is Pawn_Grimm pawn_Grimm)
                {
                    pawn_Grimm.SetNuckelaveeTimer(nuckelaveeTimer);
                }
                GenSpawn.Spawn(pawn, loc, this.Map, this.Rotation, WipeMode.Vanish, false);
            }

            if (nuckelaveeTimer == 0)
            {
                if (this.RaceProps.AnyPawnKind == RWBYDefOf.Grimm_Nuckelavee && !this.InMentalState)
                {
                    Messages.Message("MessageTextNuckelaveeTriggered".Translate().CapitalizeFirst(), this, MessageTypeDefOf.NegativeEvent);
                }
                TriggerAggro();
            }

            if (attractGrimmTimer == 0)
            {
                IncidentDef     localDef        = IncidentDefOf.RaidEnemy;
                IncidentParms   parms           = StorytellerUtility.DefaultParmsNow(localDef.category, Map);
                StorytellerComp storytellerComp = Find.Storyteller.storytellerComps.First((StorytellerComp x) => x is StorytellerComp_OnOffCycle || x is StorytellerComp_RandomMain);
                parms              = storytellerComp.GenerateParms(localDef.category, parms.target);
                parms.faction      = FactionUtility.DefaultFactionFrom(RWBYDefOf.Creatures_of_Grimm);
                parms.raidStrategy = RaidStrategyDefOf.ImmediateAttack;
                localDef.Worker.TryExecute(parms);
                TriggerAggro();
            }
        }
Ejemplo n.º 6
0
 public override void TryExecute()
 {
     RaidHelpers.Raid(points, arrival, strategy, FactionUtility.DefaultFactionFrom(FactionDef.Named("OutlanderRough")));
 }
        public static void PawnKindGearSampled()
        {
            IOrderedEnumerable <PawnKindDef> orderedEnumerable = from k in DefDatabase <PawnKindDef> .AllDefs
                                                                 where k.RaceProps.ToolUser
                                                                 orderby k.combatPower
                                                                 select k;
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            foreach (PawnKindDef item2 in orderedEnumerable)
            {
                Faction         fac  = FactionUtility.DefaultFactionFrom(item2.defaultFactionType);
                PawnKindDef     kind = item2;
                FloatMenuOption item = new FloatMenuOption(kind.defName + " (" + kind.combatPower + ")", delegate
                {
                    DefMap <ThingDef, int> weapons  = new DefMap <ThingDef, int>();
                    DefMap <ThingDef, int> apparel  = new DefMap <ThingDef, int>();
                    DefMap <HediffDef, int> hediffs = new DefMap <HediffDef, int>();
                    for (int i = 0; i < 400; i++)
                    {
                        Pawn pawn = PawnGenerator.GeneratePawn(kind, fac);
                        if (pawn.equipment.Primary != null)
                        {
                            weapons[pawn.equipment.Primary.def]++;
                        }
                        foreach (Hediff hediff in pawn.health.hediffSet.hediffs)
                        {
                            hediffs[hediff.def]++;
                        }
                        foreach (Apparel item3 in pawn.apparel.WornApparel)
                        {
                            apparel[item3.def]++;
                        }
                        pawn.Destroy();
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("Sampled " + 400 + "x " + kind.defName + ":");
                    stringBuilder.AppendLine("Weapons");
                    foreach (ThingDef item4 in DefDatabase <ThingDef> .AllDefs.OrderByDescending((ThingDef t) => weapons[t]))
                    {
                        int num = weapons[item4];
                        if (num > 0)
                        {
                            stringBuilder.AppendLine("  " + item4.defName + "    " + ((float)num / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Apparel");
                    foreach (ThingDef item5 in DefDatabase <ThingDef> .AllDefs.OrderByDescending((ThingDef t) => apparel[t]))
                    {
                        int num2 = apparel[item5];
                        if (num2 > 0)
                        {
                            stringBuilder.AppendLine("  " + item5.defName + "    " + ((float)num2 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Tech hediffs");
                    foreach (HediffDef item6 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.spawnThingOnRemoved != null
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num3 = hediffs[item6];
                        if (num3 > 0)
                        {
                            stringBuilder.AppendLine("  " + item6.defName + "    " + ((float)num3 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Addiction hediffs");
                    foreach (HediffDef item7 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.IsAddiction
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num4 = hediffs[item7];
                        if (num4 > 0)
                        {
                            stringBuilder.AppendLine("  " + item7.defName + "    " + ((float)num4 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Other hediffs");
                    foreach (HediffDef item8 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.spawnThingOnRemoved == null && !h.IsAddiction
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num5 = hediffs[item8];
                        if (num5 > 0)
                        {
                            stringBuilder.AppendLine("  " + item8.defName + "    " + ((float)num5 / 400f).ToStringPercent());
                        }
                    }
                    Log.Message(stringBuilder.ToString().TrimEndNewlines());
                });
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
        public override void Resolve(ResolveParams rp)
        {
            if (rp.singlePawnToSpawn != null && rp.singlePawnToSpawn.Spawned)
            {
                return;
            }
            Map map = BaseGen.globalSettings.map;

            if (!TryFindSpawnCell(rp, out var cell))
            {
                if (rp.singlePawnToSpawn != null)
                {
                    Find.WorldPawns.PassToWorld(rp.singlePawnToSpawn);
                }
                return;
            }
            Pawn pawn;

            if (rp.singlePawnToSpawn == null)
            {
                PawnGenerationRequest request;
                if (rp.singlePawnGenerationRequest.HasValue)
                {
                    request = rp.singlePawnGenerationRequest.Value;
                }
                else
                {
                    PawnKindDef pawnKindDef = rp.singlePawnKindDef ?? DefDatabase <PawnKindDef> .AllDefsListForReading.Where((PawnKindDef x) => x.defaultFactionType == null || !x.defaultFactionType.isPlayer).RandomElement();

                    Faction result = rp.faction;
                    if (result == null && pawnKindDef.RaceProps.Humanlike)
                    {
                        if (pawnKindDef.defaultFactionType != null)
                        {
                            result = FactionUtility.DefaultFactionFrom(pawnKindDef.defaultFactionType);
                            if (result == null)
                            {
                                return;
                            }
                        }
                        else if (!Find.FactionManager.AllFactions.Where((Faction x) => !x.IsPlayer).TryRandomElement(out result))
                        {
                            return;
                        }
                    }
                    request = new PawnGenerationRequest(pawnKindDef, result, PawnGenerationContext.NonPlayer, map.Tile);
                }
                pawn = PawnGenerator.GeneratePawn(request);
                if (rp.postThingGenerate != null)
                {
                    rp.postThingGenerate(pawn);
                }
            }
            else
            {
                pawn = rp.singlePawnToSpawn;
            }
            if (!pawn.Dead && rp.disableSinglePawn.HasValue && rp.disableSinglePawn.Value)
            {
                pawn.mindState.Active = false;
            }
            GenSpawn.Spawn(pawn, cell, map);
            if (rp.singlePawnLord != null)
            {
                rp.singlePawnLord.AddPawn(pawn);
            }
            if (rp.postThingSpawn != null)
            {
                rp.postThingSpawn(pawn);
            }
        }
Ejemplo n.º 9
0
        public static Zombie GeneratePawn(ZombieType overwriteType)
        {
            var thing  = ThingMaker.MakeThing(ZombieDefOf.Zombie.race, null);
            var zombie = thing as Zombie;

            if (zombie == null)
            {
                Log.Error("ThingMaker.MakeThing(ZombieDefOf.Zombie.race, null) unexpectedly returned " + thing);
                return(null);
            }

            var bodyType = PrepareZombieType(zombie, overwriteType);

            zombie.kindDef = ZombieDefOf.Zombie;
            zombie.SetFactionDirect(FactionUtility.DefaultFactionFrom(ZombieDefOf.Zombies));

            PawnComponentsUtility.CreateInitialComponents(zombie);
            zombie.health.hediffSet.Clear();

            var ageInYears = (long)Rand.Range(14, 130);

            zombie.ageTracker.AgeBiologicalTicks    = (ageInYears * 3600000);
            zombie.ageTracker.AgeChronologicalTicks = zombie.ageTracker.AgeBiologicalTicks;
            zombie.ageTracker.BirthAbsTicks         = GenTicks.TicksAbs - zombie.ageTracker.AgeBiologicalTicks;
            var idx = zombie.ageTracker.CurLifeStageIndex;             // trigger calculations

            zombie.needs.SetInitialLevels();
            zombie.needs.mood = new Need_Mood(zombie);

            var name = PawnNameDatabaseSolid.GetListForGender((zombie.gender == Gender.Female) ? GenderPossibility.Female : GenderPossibility.Male).RandomElement();
            var n1   = name.First.Replace('s', 'z').Replace('S', 'Z');
            var n2   = name.Last.Replace('s', 'z').Replace('S', 'Z');
            var n3   = name.Nick.Replace('s', 'z').Replace('S', 'Z');

            zombie.Name = new NameTriple(n1, n3, n2);

            zombie.story.childhood = BackstoryDatabase.allBackstories
                                     .Where(kvp => kvp.Value.slot == BackstorySlot.Childhood)
                                     .RandomElement().Value;
            if (zombie.ageTracker.AgeBiologicalYearsFloat >= 20f)
            {
                zombie.story.adulthood = BackstoryDatabase.allBackstories
                                         .Where(kvp => kvp.Value.slot == BackstorySlot.Adulthood)
                                         .RandomElement().Value;
            }

            zombie.story.melanin   = 0.01f * Rand.Range(10, 91);
            zombie.story.bodyType  = bodyType;
            zombie.story.crownType = Rand.Bool ? CrownType.Average : CrownType.Narrow;

            zombie.story.hairColor = HairColor();
            zombie.story.hairDef   = PawnHairChooser.RandomHairDefFor(zombie, ZombieDefOf.Zombies);

            if (ZombieSettings.Values.useCustomTextures)
            {
                var it = AssignNewGraphics(zombie);
                while (it.MoveNext())
                {
                    ;
                }
            }

            zombie.Drawer.leaner = new ZombieLeaner(zombie);

            if (zombie.pather == null)
            {
                zombie.pather = new Pawn_PathFollower(zombie);
            }
            GetterSetters.destinationByRef(zombie.pather) = IntVec3.Invalid;

            return(zombie);
        }
Ejemplo n.º 10
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map  map  = (Map)parms.target;
            Pawn pawn = PawnGenerator.GeneratePawn(GrimmUtility.GetRandomGrimmBalanced(), FactionUtility.DefaultFactionFrom(RWBYDefOf.Creatures_of_Grimm));

            if (!parms.spawnCenter.IsValid && !RCellFinder.TryFindRandomPawnEntryCell(out parms.spawnCenter, map, CellFinder.EdgeRoadChance_Hostile, false, null))
            {
                return(false);
            }
            parms.spawnRotation = Rot4.FromAngleFlat((map.Center - parms.spawnCenter).AngleFlat);
            IntVec3 loc = CellFinder.RandomClosewalkCellNear(parms.spawnCenter, map, 8, null);

            if (pawn is Pawn_Grimm pawn_Grimm)
            {
                pawn_Grimm.SetAttractGrimmTimer();
            }
            GenSpawn.Spawn(pawn, loc, map, parms.spawnRotation, WipeMode.Vanish, false);
            string label = "LetterLabelGrimmWandersIn".Translate();
            string text  = "LetterTextGrimmWandersIn".Translate();

            Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.ThreatSmall, pawn);
            return(true);
        }
Ejemplo n.º 11
0
        public static IEnumerator SpawnZombieIterativ(IntVec3 cell, Map map, ZombieType zombieType, Action <Zombie> callback)
        {
            ZombiesSpawning++;
            var thing = ThingMaker.MakeThing(ZombieDefOf.Zombie.race, null);

            yield return(null);

            var zombie   = thing as Zombie;
            var bodyType = PrepareZombieType(zombie, zombieType);

            zombie.kindDef = ZombieDefOf.Zombie;
            zombie.SetFactionDirect(FactionUtility.DefaultFactionFrom(ZombieDefOf.Zombies));
            yield return(null);

            PawnComponentsUtility.CreateInitialComponents(zombie);
            yield return(null);

            zombie.health.hediffSet.Clear();
            var ageInYears = (long)Rand.Range(14, 130);

            zombie.ageTracker.AgeBiologicalTicks    = (ageInYears * 3600000);
            zombie.ageTracker.AgeChronologicalTicks = zombie.ageTracker.AgeBiologicalTicks;
            zombie.ageTracker.BirthAbsTicks         = GenTicks.TicksAbs - zombie.ageTracker.AgeBiologicalTicks;
            var idx = zombie.ageTracker.CurLifeStageIndex;             // trigger calculations

            yield return(null);

            zombie.needs.SetInitialLevels();
            yield return(null);

            zombie.needs.mood = new Need_Mood(zombie);
            yield return(null);

            var name = PawnNameDatabaseSolid.GetListForGender((zombie.gender == Gender.Female) ? GenderPossibility.Female : GenderPossibility.Male).RandomElement();

            yield return(null);

            var n1 = name.First.Replace('s', 'z').Replace('S', 'Z');
            var n2 = name.Last.Replace('s', 'z').Replace('S', 'Z');
            var n3 = name.Nick.Replace('s', 'z').Replace('S', 'Z');

            zombie.Name = new NameTriple(n1, n3, n2);
            yield return(null);

            zombie.story.childhood = BackstoryDatabase.allBackstories
                                     .Where(kvp => kvp.Value.slot == BackstorySlot.Childhood)
                                     .RandomElement().Value;
            yield return(null);

            if (zombie.ageTracker.AgeBiologicalYearsFloat >= 20f)
            {
                zombie.story.adulthood = BackstoryDatabase.allBackstories
                                         .Where(kvp => kvp.Value.slot == BackstorySlot.Adulthood)
                                         .RandomElement().Value;
            }
            yield return(null);

            zombie.story.melanin   = 0.01f * Rand.Range(10, 91);
            zombie.story.bodyType  = bodyType;
            zombie.story.crownType = Rand.Bool ? CrownType.Average : CrownType.Narrow;
            zombie.story.hairColor = HairColor();
            zombie.story.hairDef   = PawnHairChooser.RandomHairDefFor(zombie, ZombieDefOf.Zombies);
            yield return(null);

            var it = AssignNewGraphics(zombie);

            while (it.MoveNext())
            {
                yield return(null);
            }
            zombie.Drawer.leaner = new ZombieLeaner(zombie);
            if (zombie.pather == null)
            {
                zombie.pather = new Pawn_PathFollower(zombie);
            }
            GetterSetters.destinationByRef(zombie.pather) = IntVec3.Invalid;
            yield return(null);

            if (zombie.IsTanky == false)
            {
                var it2 = GenerateStartingApparelFor(zombie);
                while (it2.MoveNext())
                {
                    yield return(null);
                }
            }
            if (zombie.IsSuicideBomber)
            {
                zombie.lastBombTick = Find.TickManager.TicksAbs + Rand.Range(0, (int)zombie.bombTickingInterval);
            }
            GenPlace.TryPlaceThing(zombie, cell, map, ThingPlaceMode.Direct);
            yield return(null);

            if (callback != null)
            {
                callback(zombie);
            }
            ZombiesSpawning--;
            switch (Find.TickManager.CurTimeSpeed)
            {
            case TimeSpeed.Paused:
                break;

            case TimeSpeed.Normal:
                yield return(new WaitForSeconds(0.1f));

                break;

            case TimeSpeed.Fast:
                yield return(new WaitForSeconds(0.25f));

                break;

            case TimeSpeed.Superfast:
                yield return(new WaitForSeconds(0.5f));

                break;

            case TimeSpeed.Ultrafast:
                yield return(new WaitForSeconds(1f));

                break;
            }
        }
        public override void PostStart(string reason)
        {
            base.PostStart(reason);

            Logger.MessageFormat(this, "Meeseeks attempting to incite other Meeseeks to join in killing the creator.");

            Faction meeseeksFaction = FactionUtility.DefaultFactionFrom(MeeseeksDefOf.CM_Meeseeks_Box_Faction_Hostile_Meeseeks);

            if (meeseeksFaction == null)
            {
                meeseeksFaction = Faction.OfAncientsHostile;
            }

            Lord lord = LordMaker.MakeNewLord(meeseeksFaction, new LordJob_MeeseeksKillCreator(target), pawn.MapHeld);

            // Now add all the meeseeks in this tree to the list
            List <Pawn> foundMeeseeks = new List <Pawn> {
                grandCreatorMeeseeks
            };
            List <Pawn> accumulatedMeeseeks = new List <Pawn>();

            while (foundMeeseeks.Count > 0)
            {
                foreach (Pawn meeseeks in foundMeeseeks)
                {
                    meeseeks.SetFaction(meeseeksFaction);

                    CompMeeseeksMemory meeseeksMemory = meeseeks.GetComp <CompMeeseeksMemory>();

                    // Set job memory, wont be using it in this lord, but set it anyway for debugging purposes
                    Job newJob = JobMaker.MakeJob(MeeseeksDefOf.CM_Meeseeks_Box_Job_Kill, target);
                    newJob.workGiverDef = MeeseeksDefOf.CM_Meeseeks_Box_WorkGiver_Kill;
                    meeseeksMemory.ForceNewJob(newJob, target);

                    // Put in new lrd
                    meeseeks.GetLord()?.Notify_PawnLost(meeseeks, PawnLostCondition.ChangedFaction);
                    lord.AddPawn(meeseeks);

                    accumulatedMeeseeks.AddRange(meeseeks.GetComp <CompMeeseeksMemory>().CreatedMeeseeks);
                }

                foundMeeseeks = new List <Pawn>(accumulatedMeeseeks);
                accumulatedMeeseeks.Clear();
            }

            CompMeeseeksMemory grandCreatorMeeseeksMemory = grandCreatorMeeseeks.GetComp <CompMeeseeksMemory>();

            MeeseeksUtility.PlayCriticalBreakSound(grandCreatorMeeseeks, grandCreatorMeeseeksMemory.Voice);

            // Since we changed the Meeseeks' faction, we need to make our own letter
            string letterText = this.GetBeginLetterText();

            if (!letterText.NullOrEmpty())
            {
                string letterLabel = (def.beginLetterLabel ?? ((string)def.LabelCap)).CapitalizeFirst();
                if (!reason.NullOrEmpty())
                {
                    letterText = letterText + "\n\n" + reason;
                }
                Find.LetterStack.ReceiveLetter(letterLabel, letterText, def.beginLetterDef, grandCreatorMeeseeks);
            }
        }
Ejemplo n.º 13
0
        public static void RecruitDifficultiesSampled()
        {
            IOrderedEnumerable <PawnKindDef> orderedEnumerable = from k in DefDatabase <PawnKindDef> .AllDefs
                                                                 where k.RaceProps.Humanlike
                                                                 orderby k.combatPower
                                                                 select k;
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            foreach (PawnKindDef current in orderedEnumerable)
            {
                PawnKindDef kind = current;
                Faction     fac  = FactionUtility.DefaultFactionFrom(kind.defaultFactionType);
                if (kind == PawnKindDefOf.WildMan)
                {
                    fac = null;
                }
                FloatMenuOption item = new FloatMenuOption(kind.defName + " (" + kind.baseRecruitDifficulty.ToStringPercent() + ")", delegate
                {
                    Dictionary <int, int> dictionary = new Dictionary <int, int>();
                    for (int i = 0; i < 21; i++)
                    {
                        dictionary.Add(i, 0);
                    }
                    for (int j = 0; j < 300; j++)
                    {
                        Pawn pawn = PawnGenerator.GeneratePawn(kind, fac);
                        float num = pawn.RecruitDifficulty(Faction.OfPlayer);
                        int num2  = Mathf.RoundToInt(num * 20f);
                        Dictionary <int, int> dictionary2;
                        int key;
                        (dictionary2 = dictionary)[key = num2] = dictionary2[key] + 1;
                        pawn.Destroy(DestroyMode.Vanish);
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine(string.Concat(new object[]
                    {
                        "Sampled ",
                        300,
                        "x ",
                        kind.defName,
                        ":"
                    }));
                    for (int k = 0; k < 21; k++)
                    {
                        int num3 = dictionary[k];
                        stringBuilder.AppendLine(string.Concat(new object[]
                        {
                            "  ",
                            (k * 5).ToString(),
                            "    ",
                            num3,
                            " (",
                            ((float)num3 / 300f).ToStringPercent(),
                            ")"
                        }));
                    }
                    Log.Message(stringBuilder.ToString().TrimEndNewlines(), false);
                }, MenuOptionPriority.Default, null, null, 0f, null, null);
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
Ejemplo n.º 14
0
        private static void PawnKindAbilityCheck()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();
            StringBuilder          sb   = new StringBuilder();

            foreach (PawnKindDef item in from kd in DefDatabase <PawnKindDef> .AllDefs
                     where kd.titleRequired != null || !kd.titleSelectOne.NullOrEmpty()
                     orderby kd.defName
                     select kd)
            {
                PawnKindDef localKindDef = item;
                list.Add(new DebugMenuOption(localKindDef.defName, DebugMenuOptionMode.Action, delegate
                {
                    Faction faction = FactionUtility.DefaultFactionFrom(localKindDef.defaultFactionType);
                    for (int i = 0; i < 100; i++)
                    {
                        RoyalTitleDef fixedTitle = null;
                        if (localKindDef.titleRequired != null)
                        {
                            fixedTitle = localKindDef.titleRequired;
                        }
                        else if (!localKindDef.titleSelectOne.NullOrEmpty() && Rand.Chance(localKindDef.royalTitleChance))
                        {
                            fixedTitle = localKindDef.titleSelectOne.RandomElementByWeight((RoyalTitleDef t) => t.commonality);
                        }
                        Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(localKindDef, faction, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: false, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: false, 1f, forceAddFreeWarmLayerIfNeeded: false, allowGay: true, allowFood: true, allowAddictions: true, inhabitant: false, certainlyBeenInCryptosleep: false, forceRedressWorldPawnIfFormerColonist: false, worldPawnFactionDoesntMatter: false, 0f, null, 1f, null, null, null, null, null, null, null, null, null, null, null, fixedTitle));
                        RoyalTitle mostSeniorTitle = pawn.royalty.MostSeniorTitle;
                        if (mostSeniorTitle != null)
                        {
                            Hediff_Psylink mainPsylinkSource = pawn.GetMainPsylinkSource();
                            if (mainPsylinkSource == null)
                            {
                                if (mostSeniorTitle.def.MaxAllowedPsylinkLevel(faction.def) > 0)
                                {
                                    string text = mostSeniorTitle.def.LabelCap + " - No psylink.";
                                    if (pawn.abilities.abilities.Any((Ability x) => x.def.level > 0))
                                    {
                                        text += " Has psycasts without psylink.";
                                    }
                                    sb.AppendLine(text);
                                }
                            }
                            else if (mainPsylinkSource.level < mostSeniorTitle.def.MaxAllowedPsylinkLevel(faction.def))
                            {
                                sb.AppendLine("Psylink at level " + mainPsylinkSource.level + ", but requires " + mostSeniorTitle.def.MaxAllowedPsylinkLevel(faction.def));
                            }
                            else if (mainPsylinkSource.level > mostSeniorTitle.def.MaxAllowedPsylinkLevel(faction.def))
                            {
                                sb.AppendLine("Psylink at level " + mainPsylinkSource.level + ". Max is " + mostSeniorTitle.def.MaxAllowedPsylinkLevel(faction.def));
                            }
                        }
                        Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                    }
                    if (sb.Length == 0)
                    {
                        Log.Message("No errors for " + localKindDef.defName);
                    }
                    else
                    {
                        Log.Error("Errors:\n" + sb.ToString());
                    }
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
Ejemplo n.º 15
0
        public override void PostMapGenerate(Map map)
        {
            IncidentParms incidentParms = StorytellerUtility.DefaultParmsNow(Find.Storyteller.def, (IncidentCategory)3, map);

            incidentParms.forced = true;
            IntVec3 spawnCenter;

            if (RCellFinder.TryFindRandomPawnEntryCell(out spawnCenter, map, 0f, (IntVec3 v) => GenGrid.Standable(v, map)))
            {
                incidentParms.spawnCenter = spawnCenter;
            }
            Faction faction;

            if (GenCollection.TryRandomElement <Faction>(from f in Find.FactionManager.AllFactions
                                                         where !f.def.hidden && FactionUtility.HostileTo(f, Faction.OfPlayer)
                                                         select f, out faction))
            {
                IntVec3 spawnCenter2;
                if (CellFinder.TryFindRandomEdgeCellWith((IntVec3 c) => map.reachability.CanReachColony(c), map, 0f, out spawnCenter2))
                {
                    incidentParms.faction                 = Faction.OfMechanoids;
                    incidentParms.raidStrategy            = RaidStrategyDefOf.ImmediateAttack;
                    incidentParms.generateFightersOnly    = true;
                    incidentParms.raidNeverFleeIndividual = true;
                    incidentParms.raidArrivalMode         = PawnsArriveMode.CenterDrop;
                    incidentParms.spawnCenter             = spawnCenter2;
                    incidentParms.points *= 20f;
                    incidentParms.points  = Math.Max(incidentParms.points, 250f);
                    QueuedIncident queuedIncident = new QueuedIncident(new FiringIncident(TorannMagicDefOf.ArcaneEnemyRaid, null, incidentParms), Find.TickManager.TicksGame + Rand.RangeInclusive(500, 5000));
                    Find.Storyteller.incidentQueue.Add(queuedIncident);
                    System.Random random = new System.Random();
                    int           rnd    = GenMath.RoundRandom(random.Next(0, 10));
                    if (rnd < 5)
                    {
                        incidentParms.points = Math.Max(incidentParms.points * 2, 500f);
                        queuedIncident       = new QueuedIncident(new FiringIncident(TorannMagicDefOf.ArcaneEnemyRaid, null, incidentParms), Find.TickManager.TicksGame + Rand.RangeInclusive(2000, 3000));
                        Find.Storyteller.incidentQueue.Add(queuedIncident);
                    }
                    if (rnd < 3)
                    {
                        if (GenCollection.TryRandomElement <Faction>(from f in Find.FactionManager.AllFactions
                                                                     where !f.def.hidden && FactionUtility.HostileTo(f, Faction.OfPlayer)
                                                                     select f, out faction))
                        {
                            incidentParms.faction = faction;
                            incidentParms.points  = Math.Max(250f, 500f);
                            queuedIncident        = new QueuedIncident(new FiringIncident(TorannMagicDefOf.ArcaneEnemyRaid, null, incidentParms), Find.TickManager.TicksGame + Rand.RangeInclusive(5000, 10000));
                            Find.Storyteller.incidentQueue.Add(queuedIncident);
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
0
        public static Zombie GeneratePawn()
        {
            var zombie = (Zombie)ThingMaker.MakeThing(ZombieDefOf.Zombie.race, null);

            zombie.gender  = Rand.Bool ? Gender.Male : Gender.Female;
            zombie.kindDef = ZombieDefOf.Zombie;
            zombie.SetFactionDirect(FactionUtility.DefaultFactionFrom(ZombieDefOf.Zombies));

            PawnComponentsUtility.CreateInitialComponents(zombie);
            zombie.health.hediffSet.Clear();

            zombie.ageTracker.AgeBiologicalTicks    = ((long)(Rand.Range(0, 0x9c4 + 1) * 3600000f)) + Rand.Range(0, 0x36ee80);
            zombie.ageTracker.AgeChronologicalTicks = zombie.ageTracker.AgeBiologicalTicks;
            zombie.ageTracker.BirthAbsTicks         = GenTicks.TicksAbs - zombie.ageTracker.AgeBiologicalTicks;
            var idx = zombie.ageTracker.CurLifeStageIndex;             // trigger calculations

            zombie.needs.SetInitialLevels();
            zombie.needs.mood = new Need_Mood(zombie);

            var name = PawnNameDatabaseSolid.GetListForGender((zombie.gender == Gender.Female) ? GenderPossibility.Female : GenderPossibility.Male).RandomElement();
            var n1   = name.First.Replace('s', 'z').Replace('S', 'Z');
            var n2   = name.Last.Replace('s', 'z').Replace('S', 'Z');
            var n3   = name.Nick.Replace('s', 'z').Replace('S', 'Z');

            zombie.Name = new NameTriple(n1, n3, n2);

            // faster: use MinimalBackstory()
            zombie.story.childhood = BackstoryDatabase.allBackstories
                                     .Where(kvp => kvp.Value.slot == BackstorySlot.Childhood)
                                     .RandomElement().Value;
            if (zombie.ageTracker.AgeBiologicalYearsFloat >= 20f)
            {
                zombie.story.adulthood = BackstoryDatabase.allBackstories
                                         .Where(kvp => kvp.Value.slot == BackstorySlot.Adulthood)
                                         .RandomElement().Value;
            }

            zombie.story.melanin   = 0.01f * Rand.Range(10, 91);
            zombie.story.crownType = Rand.Bool ? CrownType.Average : CrownType.Narrow;

            zombie.story.hairColor = HairColor();
            zombie.story.hairDef   = PawnHairChooser.RandomHairDefFor(zombie, ZombieDefOf.Zombies);
            zombie.story.bodyType  = (zombie.gender == Gender.Female) ? BodyType.Female : BodyType.Male;
            if (zombie.story.bodyType == BodyType.Male)
            {
                switch (Rand.Range(1, 6))
                {
                case 1:
                    zombie.story.bodyType = BodyType.Thin;
                    break;

                case 2:
                    zombie.story.bodyType = BodyType.Fat;
                    break;

                case 3:
                    zombie.story.bodyType = BodyType.Hulk;
                    break;
                }
            }

            if (ZombieSettings.Values.useCustomTextures)
            {
                AssignNewCustomGraphics(zombie);
            }

            zombie.Drawer.leaner = new ZombieLeaner(zombie);
            Traverse.Create(zombie.pather).Field("destination").SetValue(IntVec3.Invalid);

            return(zombie);
        }
Ejemplo n.º 17
0
        public override void Notify_PawnDied()
        {
            base.Notify_PawnDied();
            Corpse corpse  = pawn.Corpse;
            Pawn   newBorg = PawnGenerator.GeneratePawn(PawnKindDef.Named("BorgDrone"), FactionUtility.DefaultFactionFrom(FactionDef.Named("BorgFaction")));

            newBorg.SpawnSetup(corpse.Map);
            newBorg.Position = corpse.Position;
            if (corpse != null)
            {
                corpse.Destroy();
            }
        }
 private static IEnumerable <Pawn> DangerInPosRadius(Pawn pawn, IntVec3 position, Map map, float distance)
 {
     return(Enumerable.Where <Pawn>(map.mapPawns.AllPawns, (p => p.Position.InHorDistOf(position, distance) && !p.RaceProps.Animal && !p.Downed && !p.Dead && FactionUtility.HostileTo(p.Faction, pawn.Faction))));
 }
Ejemplo n.º 19
0
        private static bool isFriendly(Pawn hunter, Pawn prey)
        {
            bool flag  = hunter.Faction == Faction.OfPlayer;
            bool flag2 = flag;
            bool result;

            if (flag2)
            {
                bool flag3 = prey == null;
                bool flag4 = flag3;
                if (flag4)
                {
                    result = (prey.Faction == Faction.OfPlayer || prey.def == hunter.def || prey.IsPrisonerOfColony || FactionUtility.HostileTo(prey.Faction, Faction.OfPlayer));
                }
                else
                {
                    result = (prey.Faction == Faction.OfPlayer || prey.Faction == Faction.OfPlayer || prey.IsPrisonerOfColony || FactionUtility.HostileTo(prey.Faction, Faction.OfPlayer));
                }
            }
            else
            {
                result = (prey.def == hunter.def);
            }
            return(result);
        }
Ejemplo n.º 20
0
        public override void Notify_PawnDied()
        {
            base.Notify_PawnDied();

            if (pawn.def.race.Animal == false)
            {
                Corpse corpse   = pawn.Corpse;
                Pawn   newBorg1 = PawnGenerator.GeneratePawn(PawnKindDef.Named("PlayerBorgDrone"), FactionUtility.DefaultFactionFrom(FactionDef.Named("BorgCollective")));
                newBorg1.SetFaction(Faction.OfPlayer);
                newBorg1.Position = corpse.Position;
                newBorg1.SpawnSetup(corpse.Map, false);

                if (corpse != null)
                {
                    corpse.Destroy();
                }
            }
            else if (pawn.def.race.Animal == true)
            {
                Messages.Message("an animal has succumbed to the nanite infection, and have been deemed inappropriate for assimilation. The nanites have consumed and destroyed the corpse.", MessageTypeDefOf.NeutralEvent);
                pawn.Corpse.Destroy();
            }
        }
Ejemplo n.º 21
0
    private static Pawn GenerateNewTenant()
    {
        var  generation   = true;
        Pawn newTenant    = null;
        var  currentRaces = SettingsHelper.LatestVersion.AvailableRaces;

        if (currentRaces == null || currentRaces.Count == 0)
        {
            currentRaces = DefDatabase <PawnKindDef> .AllDefsListForReading
                           .Where(x => x.race != null && x.RaceProps.Humanlike && x.RaceProps.IsFlesh &&
                                  x.RaceProps.ResolvedDietCategory != DietCategory.NeverEats).Select(s => s.race.defName)
                           .Distinct().ToList();
        }

        while (generation)
        {
            var race   = currentRaces.RandomElement();
            var random = DefDatabase <PawnKindDef> .AllDefsListForReading.Where(x => x.race.defName == race)
                         .RandomElement();

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

            var faction = FactionUtility.DefaultFactionFrom(random.defaultFactionType);
            if (faction == null)
            {
                continue;
            }

            if (faction.def.pawnGroupMakers.NullOrEmpty())
            {
                continue;
            }

            newTenant = PawnGenerator.GeneratePawn(random, faction);
            if (newTenant == null || newTenant.Dead || newTenant.IsDessicated() || newTenant.AnimalOrWildMan())
            {
                continue;
            }

            if (newTenant.royalty != null && !SettingsHelper.LatestVersion.RoyaltyTenants &&
                (newTenant.royalty.CanRequireBedroom() || newTenant.royalty.CanRequireThroneroom()))
            {
                continue;
            }

            if (SettingsHelper.LatestVersion.SimpleClothing)
            {
                var range = newTenant.kindDef.apparelMoney;
                newTenant.kindDef.apparelMoney = new FloatRange(SettingsHelper.LatestVersion.SimpleClothingMin,
                                                                SettingsHelper.LatestVersion.SimpleClothingMax);
                PawnApparelGenerator.GenerateStartingApparelFor(newTenant, new PawnGenerationRequest(random));
                newTenant.kindDef.apparelMoney = range;
            }

            RemoveExpensiveItems(newTenant);
            newTenant.GetTenantComponent().IsTenant      = true;
            newTenant.GetTenantComponent().HiddenFaction = faction;
            newTenant.SetFaction(null);
            if (SettingsHelper.LatestVersion.Weapons)
            {
                var ammo = newTenant.inventory.innerContainer.Where(x => x.def.defName.Contains("Ammunition"))
                           .ToList();
                foreach (var thing in ammo)
                {
                    newTenant.inventory.innerContainer.Remove(thing);
                }
            }

            newTenant.DestroyOrPassToWorld();
            generation = false;
        }

        return(newTenant);
    }
Ejemplo n.º 22
0
        private void ImpactSomething()
        {
            if (this.def.projectile.flyOverhead)
            {
                RoofDef roofDef = base.Map.roofGrid.RoofAt(base.Position);
                if (roofDef != null)
                {
                    if (roofDef.isThickRoof)
                    {
                        SoundStarter.PlayOneShot(this.def.projectile.soundHitThickRoof, new TargetInfo(base.Position, base.Map, false));
                        this.Destroy(0);
                        return;
                    }
                    if (GridsUtility.GetEdifice(base.Position, base.Map) == null || GridsUtility.GetEdifice(base.Position, base.Map).def.Fillage != FillCategory.Full)
                    {
                        RoofCollapserImmediate.DropRoofInCells(base.Position, base.Map, null);
                    }
                }
            }
            if (!this.usedTarget.HasThing || !base.CanHit(this.usedTarget.Thing))
            {
                List <Thing> list = new List <Thing>();
                list.Clear();
                List <Thing> thingList = GridsUtility.GetThingList(base.Position, base.Map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    Thing thing = thingList[i];
                    if ((thing.def.category == ThingCategory.Building || thing.def.category == ThingCategory.Pawn || thing.def.category == ThingCategory.Item || thing.def.category == ThingCategory.Plant) && base.CanHit(thing))
                    {
                        list.Add(thing);
                    }
                }
                GenList.Shuffle <Thing>(list);
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing2 = list[j];
                    Pawn  pawn   = thing2 as Pawn;
                    float num;
                    if (pawn != null)
                    {
                        num = 0.5f * Mathf.Clamp(pawn.BodySize, 0.1f, 2f);
                        if (PawnUtility.GetPosture(pawn) != null && GenGeo.MagnitudeHorizontalSquared(this.origin - this.destination) >= 20.25f)
                        {
                            num *= 0.2f;
                        }
                        if (this.launcher != null && pawn.Faction != null && this.launcher.Faction != null && !FactionUtility.HostileTo(pawn.Faction, this.launcher.Faction))
                        {
                            num *= VerbUtility.InterceptChanceFactorFromDistance(this.origin, base.Position);
                        }
                    }
                    else
                    {
                        num = 1.5f * thing2.def.fillPercent;
                    }
                    if (Rand.Chance(num))
                    {
                        this.Impact(GenCollection.RandomElement <Thing>(list));
                        return;
                    }
                }
                this.Impact(null);
                return;
            }
            Pawn pawn2 = this.usedTarget.Thing as Pawn;

            if (pawn2 != null && PawnUtility.GetPosture(pawn2) != null && GenGeo.MagnitudeHorizontalSquared(this.origin - this.destination) >= 20.25f && !Rand.Chance(0.2f))
            {
                this.Impact(null);
                return;
            }
            this.Impact(this.usedTarget.Thing);
        }
Ejemplo n.º 23
0
        public static void PawnKindGearSampled()
        {
            IOrderedEnumerable <PawnKindDef> orderedEnumerable = from k in DefDatabase <PawnKindDef> .AllDefs
                                                                 where k.RaceProps.ToolUser
                                                                 orderby k.combatPower
                                                                 select k;
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            foreach (PawnKindDef current in orderedEnumerable)
            {
                Faction         fac  = FactionUtility.DefaultFactionFrom(current.defaultFactionType);
                PawnKindDef     kind = current;
                FloatMenuOption item = new FloatMenuOption(string.Concat(new object[]
                {
                    kind.defName,
                    " (",
                    kind.combatPower,
                    ")"
                }), delegate
                {
                    DefMap <ThingDef, int> weapons  = new DefMap <ThingDef, int>();
                    DefMap <ThingDef, int> apparel  = new DefMap <ThingDef, int>();
                    DefMap <HediffDef, int> hediffs = new DefMap <HediffDef, int>();
                    for (int i = 0; i < 400; i++)
                    {
                        Pawn pawn = PawnGenerator.GeneratePawn(kind, fac);
                        if (pawn.equipment.Primary != null)
                        {
                            DefMap <ThingDef, int> defMap;
                            ThingDef def;
                            (defMap = weapons)[def = pawn.equipment.Primary.def] = defMap[def] + 1;
                        }
                        foreach (Hediff current2 in pawn.health.hediffSet.hediffs)
                        {
                            DefMap <HediffDef, int> hediffs2;
                            HediffDef def2;
                            (hediffs2 = hediffs)[def2 = current2.def] = hediffs2[def2] + 1;
                        }
                        foreach (Apparel current3 in pawn.apparel.WornApparel)
                        {
                            DefMap <ThingDef, int> defMap;
                            ThingDef def3;
                            (defMap = apparel)[def3 = current3.def] = defMap[def3] + 1;
                        }
                        pawn.Destroy(DestroyMode.Vanish);
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine(string.Concat(new object[]
                    {
                        "Sampled ",
                        400,
                        "x ",
                        kind.defName,
                        ":"
                    }));
                    stringBuilder.AppendLine("Weapons");
                    foreach (ThingDef current4 in from t in DefDatabase <ThingDef> .AllDefs
                             orderby weapons[t] descending
                             select t)
                    {
                        int num = weapons[current4];
                        if (num > 0)
                        {
                            stringBuilder.AppendLine("  " + current4.defName + "    " + ((float)num / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Apparel");
                    foreach (ThingDef current5 in from t in DefDatabase <ThingDef> .AllDefs
                             orderby apparel[t] descending
                             select t)
                    {
                        int num2 = apparel[current5];
                        if (num2 > 0)
                        {
                            stringBuilder.AppendLine("  " + current5.defName + "    " + ((float)num2 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Tech hediffs");
                    foreach (HediffDef current6 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.spawnThingOnRemoved != null
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num3 = hediffs[current6];
                        if (num3 > 0)
                        {
                            stringBuilder.AppendLine("  " + current6.defName + "    " + ((float)num3 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Addiction hediffs");
                    foreach (HediffDef current7 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.IsAddiction
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num4 = hediffs[current7];
                        if (num4 > 0)
                        {
                            stringBuilder.AppendLine("  " + current7.defName + "    " + ((float)num4 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Other hediffs");
                    foreach (HediffDef current8 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.spawnThingOnRemoved == null && !h.IsAddiction
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num5 = hediffs[current8];
                        if (num5 > 0)
                        {
                            stringBuilder.AppendLine("  " + current8.defName + "    " + ((float)num5 / 400f).ToStringPercent());
                        }
                    }
                    Log.Message(stringBuilder.ToString().TrimEndNewlines(), false);
                }, MenuOptionPriority.Default, null, null, 0f, null, null);
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }