Beispiel #1
0
        public override void CompTick()
        {
            base.CompTick();
            if (summonOnce)
            {
                if (this.parent.Map != null)
                {
                    int numToSpawn = Rand.RangeInclusive(Props.groupMinMax[0], Props.groupMinMax[1]);
                    for (int i = 0; i < numToSpawn; i++)
                    {
                        PawnGenerationRequest request = new PawnGenerationRequest(PawnKindDef.Named(Props.pawnDef), Find.FactionManager.FirstFactionOfDef(FactionDefOf.AncientsHostile), PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 1f, false, true, true, false, false);
                        Pawn pawn = PawnGenerator.GeneratePawn(request);

                        GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(parent.Position, parent.Map, 3, null), parent.Map, WipeMode.Vanish);
                        pawn.mindState.mentalStateHandler.TryStartMentalState(DefDatabase <MentalStateDef> .GetNamed("ManhunterPermanent", true), null, true, false, null, false);
                    }
                    SoundDefOf.Hive_Spawn.PlayOneShot(new TargetInfo(this.parent.Position, this.parent.Map, false));


                    summonOnce = false;
                }
            }
        }
Beispiel #2
0
        private void SpawnPawns(SpawnInfo info)
        {
            var walkableAdjCells = new List <IntVec3>();

            foreach (var cell in GenAdj.CellsAdjacent8Way(new TargetInfo(Position, Map)))
            {
                if (Position.Walkable(Map))
                {
                    walkableAdjCells.Add(cell);
                }
            }
            if (walkableAdjCells.TryRandomElement(out var spawnPosition))
            {
                var pawn = PawnGenerator.GeneratePawn(info.pawnKind,
                                                      Find.FactionManager.FirstFactionOfDef(info.faction) ?? null);
                if (GenPlace.TryPlaceThing(pawn, spawnPosition, Map, ThingPlaceMode.Near, null))
                {
                    GiveMentalState(info, pawn);
                    GiveHediffs(info, pawn);
                    PostSpawnEvents(pawn);
                }
            }
        }
Beispiel #3
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            if (!TryFindEntryCell(map, out IntVec3 cell))
            {
                return(false);
            }
            if (!TryFindFormerFaction(out Faction formerFaction))
            {
                return(false);
            }
            Pawn pawn = PawnGenerator.GeneratePawn(PawnKindDefOf.WildMan, formerFaction);

            pawn.SetFaction(null);
            GenSpawn.Spawn(pawn, cell, map);
            string title = def.letterLabel.Formatted(pawn.LabelShort, pawn.Named("PAWN"));
            string text  = def.letterText.Formatted(pawn.LabelShort, pawn.Named("PAWN")).AdjustedFor(pawn).CapitalizeFirst();

            PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref text, ref title, pawn);
            Find.LetterStack.ReceiveLetter(title, text, def.letterDef, pawn);
            return(true);
        }
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            bool isViolation = !PawnGenerator.IsBeingGenerated(pawn) && this.IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (base.CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[]
                {
                    billDoer,
                    pawn
                });
                if (isViolation)
                {
                    base.ReportViolation(pawn, billDoer, pawn.FactionOrExtraHomeFaction, -70, "GoodwillChangedReason_NeedlesslyInstalledWorseBodyPart".Translate(this.recipe.addsHediff.label));
                }
            }

            pawn.health.AddHediff(this.recipe.addsHediff, part, null, null);
        }
        public override IEnumerable <Thing> GenerateThings(int forTile, Faction faction = null)
        {
            if (respectPopulationIntent && Rand.Value > StorytellerUtilityPopulation.PopulationIntent)
            {
                yield break;
            }
            int count = countRange.RandomInRange;

            for (int i = 0; i < count; i++)
            {
                if (!Find.FactionManager.AllFactionsVisible.Where((Faction fac) => fac != Faction.OfPlayer && fac.def.humanlikeFaction).TryRandomElement(out Faction result))
                {
                    break;
                }
                PawnGenerationRequest request = PawnGenerationRequest.MakeDefault();
                request.KindDef = ((slaveKindDef != null) ? slaveKindDef : PawnKindDefOf.Slave);
                request.Faction = result;
                request.Tile    = forTile;
                request.ForceAddFreeWarmLayerIfNeeded = !trader.orbital;
                request.RedressValidator = ((Pawn x) => x.royalty == null || !x.royalty.AllTitlesForReading.Any());
                yield return(PawnGenerator.GeneratePawn(request));
            }
        }
        static void Postfix(Thing toGive, int countToGive, Pawn playerNegotiator)
        {
            if (!ZTribbleSettings.flagTradeship)
            {
                return;
            }
            if (Rand.Chance(0.9f))
            {
                return;
            }

            Map map = playerNegotiator.Map;

            IntVec3 loc = DropCellFinder.TradeDropSpot(map);

            PawnKindDef tribbleKind = PawnKindDef.Named("ZTrib_Tribble");
            Pawn        tribble     = PawnGenerator.GeneratePawn(tribbleKind);

            // spawn extra drop pod containing tribble
            TradeUtility.SpawnDropPod(loc, map, tribble);

            TribbleUtility.ResetInterval(map);
        }
 public override void MapComponentTick()
 {
     base.MapComponentTick();
     if (Find.TickManager.TicksGame % Rand.RangeInclusive(60, 100) == 0)
     {
         if (this.ActiveInfestations != null && this.ActiveInfestations.Count > 0)
         {
             foreach (var infestation in this.ActiveInfestations)
             {
                 foreach (var pawnKind in infestation.infestators)
                 {
                     if (infestation.infestationParms > 0f)
                     {
                         var pawn = PawnGenerator.GeneratePawn(pawnKind, null);
                         infestation.infestationParms -= pawnKind.combatPower;
                         GenSpawn.Spawn(pawn, infestation.infestationPlace, map);
                     }
                 }
             }
             this.ActiveInfestations.RemoveAll(x => x.infestationParms <= 0f);
         }
     }
 }
 public void MakePawnAndInitCrafting(DroneCraftingDef def)
 {
     this.orderProcessor.requestedItems.Clear();
     foreach (ThingOrderRequest cost in def.costList)
     {
         this.orderProcessor.requestedItems.Add(new ThingOrderRequest()
         {
             nutrition = cost.nutrition,
             thingDef  = cost.thingDef,
             amount    = cost.amount
         });
     }
     this.craftingTime = def.timeCost;
     if (def.useDroneCreator)
     {
         this.pawnBeingCrafted = DroidUtility.MakeDroidTemplate(def.pawnKind, this.Faction, this.Map.Tile, (List <SkillRequirement>)null, 6);
     }
     else
     {
         this.pawnBeingCrafted = PawnGenerator.GeneratePawn(def.pawnKind, this.Faction);
     }
     this.crafterStatus = CrafterStatus.Filling;
 }
Beispiel #9
0
        public void AddApparel(Pawn targetPawn, int layer)
        {
            if (acceptedApparel[layer] != null)
            {
                Apparel a;
                if (selectedApparel[layer].MadeFromStuff)
                {
                    a           = (Apparel)ThingMaker.MakeThing(selectedApparel[layer], selectedStuff[layer]);
                    a.DrawColor = colors[layer] * GetStuffColor(layer);
                }
                else
                {
                    a           = (Apparel)ThingMaker.MakeThing(selectedApparel[layer], null);
                    a.DrawColor = colors[layer];
                }

                PawnGenerator.PostProcessGeneratedGear(a, targetPawn);
                if (ApparelUtility.HasPartsToWear(targetPawn, a.def))
                {
                    targetPawn.apparel.Wear(a, false);
                }
            }
        }
Beispiel #10
0
        private void GenerateDeadOrDownedPawns()
        {
            int burialCount = Rand.Range(10, 25);

            for (int i = 0; i < burialCount; i++)
            {
                if (Map.AllCells.Where(vec => !vec.Fogged(Map) && vec.DistanceToEdge(Map) > 5).TryRandomElement(out IntVec3 result))
                {
                    Pawn pawn = PawnGenerator.GeneratePawn(Faction.RandomPawnKind(), Rand.Chance(0.5f) ? Faction : SecondFaction);

                    GenSpawn.Spawn(pawn, result, Map);

                    if (Rand.Chance(0.65f))
                    {
                        pawn.Kill(null);
                    }
                    else
                    {
                        HealthUtility.DamageUntilDowned(pawn);
                    }
                }
            }
        }
        public MainTabWindow_Numbers()
        {
            Pawn tmpPawn;

            MethodInfo statsToDraw = typeof(StatsReportUtility).GetMethod("StatsToDraw", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.InvokeMethod, null, new Type[] { typeof(Thing) }, null);

            tmpPawn = PawnGenerator.GeneratePawn(PawnKindDefOf.SpaceSoldier, Faction.OfPlayer);

            pawnHumanlikeStatDef = (from s in ((IEnumerable <StatDrawEntry>)statsToDraw.Invoke(null, new[] { tmpPawn })) where s.ShouldDisplay && s.stat != null select s.stat).OrderBy(stat => stat.LabelCap).ToList();
            pawnHumanlikeNeedDef.AddRange(DefDatabase <NeedDef> .AllDefsListForReading);

            tmpPawn           = PawnGenerator.GeneratePawn(PawnKindDefOf.Thrumbo, null);
            pawnAnimalStatDef = (from s in ((IEnumerable <StatDrawEntry>)statsToDraw.Invoke(null, new[] { tmpPawn })) where s.ShouldDisplay && s.stat != null select s.stat).ToList();
            pawnAnimalNeedDef = tmpPawn.needs.AllNeeds.Where(x => x.def.showOnNeedList).Select(x => x.def).ToList();

            savedKLists = new Dictionary <MainTabWindow_Numbers.pawnType, List <KListObject> >(5);
            foreach (MainTabWindow_Numbers.pawnType pType in Enum.GetValues(typeof(MainTabWindow_Numbers.pawnType)))
            {
                savedKLists.Add(pType, new List <KListObject>());
            }

            MapComponent_Numbers.InitMapComponent();
        }
Beispiel #12
0
        public override void TryExecute()
        {
            PawnKindDef           pawnKind = PawnKindDefOf.Colonist;
            Faction               ofPlayer = Faction.OfPlayer;
            bool                  pawnMustBeCapableOfViolence = true;
            PawnGenerationRequest request = new PawnGenerationRequest(pawnKind, ofPlayer, PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, pawnMustBeCapableOfViolence, 20f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null);
            Pawn                  pawn    = PawnGenerator.GeneratePawn(request);
            NameTriple            old     = pawn.Name as NameTriple;

            pawn.Name = new NameTriple(old.First, viewer.username, old.Last);
            GenSpawn.Spawn(pawn, loc, map, WipeMode.Vanish);
            string label = "Viewer Joins";
            string text  = $"A new pawn has been purchased by {viewer.username}, let's welcome them to the colony.";

            PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref text, ref label, pawn);
            Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.PositiveEvent, pawn, null, null);

            Current.Game.GetComponent <GameComponentPawns>().AssignUserToPawn(viewer.username, pawn);
            viewer.TakeViewerCoins(this.storeIncident.cost);
            viewer.CalculateNewKarma(this.storeIncident.karmaType, storeIncident.cost);

            VariablesHelpers.SendPurchaseMessage($"@{viewer.username} has purchased a pawn and is joining the colony.", separateChannel);
        }
Beispiel #13
0
        static bool Prefix(ref bool __result, IntVec3 loc, Map ___map)
        {
            PawnKindDef pawnKindDef = ___map.Biome.AllWildAnimals.Where(
                (PawnKindDef a) => ___map.mapTemperature.SeasonAcceptableFor(a.race) && ___map.PawnKindCanEnter(a) && !a.UnreachableLocationCheck(___map, loc)
                ).RandomElementByWeight((PawnKindDef def) => ___map.Biome.CommonalityOfAnimal(def) / def.wildGroupSize.Average);

            if (pawnKindDef == null)
            {
                Log.Error("No spawnable animals right now.");
                __result = false;
                return(false);
            }
            int randomInRange = pawnKindDef.wildGroupSize.RandomInRange;
            int radius        = Mathf.CeilToInt(Mathf.Sqrt(pawnKindDef.wildGroupSize.max));

            for (int i = 0; i < randomInRange; i++)
            {
                IntVec3 loc2 = CellFinderExtended.RandomClosewalkCellNear(loc, ___map, pawnKindDef, radius);
                GenSpawn.Spawn(PawnGenerator.GeneratePawn(pawnKindDef), loc2, ___map);
            }
            __result = true;
            return(false);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map  map  = (Map)parms.target;
            Pawn pawn = PawnGenerator.GeneratePawn(RWBYDefOf.Grimm_Nuckelavee, 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.SetNuckelaveeTimer(Rand.RangeInclusive(30000, 60000));
            }
            GenSpawn.Spawn(pawn, loc, map, parms.spawnRotation, WipeMode.Vanish, false);
            string label = "LetterLabelNuckelavee".Translate();
            string text  = "LetterTextNuckelavee".Translate();

            Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.ThreatBig, pawn);
            return(true);
        }
 public virtual List <Pawn> SpawnThreats(IncidentParms parms)
 {
     if (parms.pawnKind != null)
     {
         List <Pawn> list = new List <Pawn>();
         for (int i = 0; i < parms.pawnCount; i++)
         {
             PawnGenerationRequest request = new PawnGenerationRequest(parms.pawnKind, parms.faction, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: false, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: true, 1f, forceAddFreeWarmLayerIfNeeded: false, allowGay: true, biocodeWeaponChance: parms.biocodeWeaponsChance, allowFood: def.pawnsCanBringFood);
             request.BiocodeApparelChance = 1f;
             Pawn pawn = PawnGenerator.GeneratePawn(request);
             if (pawn != null)
             {
                 list.Add(pawn);
             }
         }
         if (list.Any())
         {
             parms.raidArrivalMode.Worker.Arrive(list, parms);
             return(list);
         }
     }
     return(null);
 }
Beispiel #16
0
        private bool TrySpawnPawn(out Pawn pawn, float limitPoint)
        {
            if (!canSpawnPawns)
            {
                pawn = null;
                return(false);
            }
            float curPoints = SpawnedPawnsPoints;
            IEnumerable <PawnKindDef> source = from x in RatkinTunnelUtility.spawnableElitePawnKinds
                                               where curPoints + x.combatPower <= limitPoint
                                               select x;
            PawnKindDef kindDef;

            if (!source.TryRandomElement(out kindDef))
            {
                pawn = null;
                return(false);
            }
            pawn = PawnGenerator.GeneratePawn(kindDef, Faction);
            spawnedPawns.Add(pawn);
            GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(Position, Map, 2, null), Map, WipeMode.Vanish);
            Lord lord = Lord;

            if (lord == null)
            {
                lord = CreateNewLord();
            }
            lord.AddPawn(pawn);
            SoundDefOf.DropPod_Open.PlayOneShot(this);
            Need rest = pawn.needs.TryGetNeed(NeedDefOf.Rest);

            rest.CurLevel = rest.MaxLevel;
            Need food = pawn.needs.TryGetNeed(NeedDefOf.Food);

            food.CurLevel = food.MaxLevel;
            return(true);
        }
        public static bool ShouldSendNotificationAbout(Pawn p)
        {
            bool result;

            if (Current.ProgramState != ProgramState.Playing)
            {
                result = false;
            }
            else if (PawnGenerator.IsBeingGenerated(p))
            {
                result = false;
            }
            else if (p.IsWorldPawn() && (!p.IsCaravanMember() || !p.GetCaravan().IsPlayerControlled) && !PawnUtility.IsTravelingInTransportPodWorldObject(p) && p.Corpse.DestroyedOrNull())
            {
                result = false;
            }
            else
            {
                if (p.Faction != Faction.OfPlayer)
                {
                    if (p.HostFaction != Faction.OfPlayer)
                    {
                        return(false);
                    }
                    if (p.RaceProps.Humanlike && p.guest.Released && !p.Downed && !p.InBed())
                    {
                        return(false);
                    }
                    if (p.CurJob != null && p.CurJob.exitMapOnArrival && !PrisonBreakUtility.IsPrisonBreaking(p))
                    {
                        return(false);
                    }
                }
                result = true;
            }
            return(result);
        }
Beispiel #18
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            if (!TryFindEntryCell(map, out IntVec3 cell))
            {
                return(false);
            }
            PawnKindDef thrumbo = PawnKindDefOf.Thrumbo;
            float       num     = StorytellerUtility.DefaultThreatPointsNow(map);
            int         value   = GenMath.RoundRandom(num / thrumbo.combatPower);
            int         max     = Rand.RangeInclusive(2, 4);

            value = Mathf.Clamp(value, 1, max);
            int     num2   = Rand.RangeInclusive(90000, 150000);
            IntVec3 result = IntVec3.Invalid;

            if (!RCellFinder.TryFindRandomCellOutsideColonyNearTheCenterOfTheMap(cell, map, 10f, out result))
            {
                result = IntVec3.Invalid;
            }
            Pawn pawn = null;

            for (int i = 0; i < value; i++)
            {
                IntVec3 loc = CellFinder.RandomClosewalkCellNear(cell, map, 10);
                pawn = PawnGenerator.GeneratePawn(thrumbo);
                GenSpawn.Spawn(pawn, loc, map, Rot4.Random);
                pawn.mindState.exitMapAfterTick = Find.TickManager.TicksGame + num2;
                if (result.IsValid)
                {
                    pawn.mindState.forcedGotoPosition = CellFinder.RandomClosewalkCellNear(result, map, 10);
                }
            }
            Find.LetterStack.ReceiveLetter("LetterLabelThrumboPasses".Translate(thrumbo.label).CapitalizeFirst(), "LetterThrumboPasses".Translate(thrumbo.label), LetterDefOf.PositiveEvent, pawn);
            return(true);
        }
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            bool flag  = MedicalRecipesUtility.IsClean(pawn, part);
            bool flag2 = !PawnGenerator.IsBeingGenerated(pawn) && IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn);
                MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, billDoer.Position, billDoer.Map);
            }
            else if (pawn.Map != null)
            {
                MedicalRecipesUtility.RestorePartAndSpawnAllPreviousParts(pawn, part, pawn.Position, pawn.Map);
            }
            else
            {
                pawn.health.RestorePart(part);
            }
            pawn.health.AddHediff(recipe.addsHediff, part);
            if (flag && flag2 && part.def.spawnThingOnRemoved != null)
            {
                ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
            }
            if (flag2 && pawn.Faction != null && billDoer != null && billDoer.Faction != null)
            {
                Faction          faction        = pawn.Faction;
                Faction          faction2       = billDoer.Faction;
                int              goodwillChange = -15;
                string           reason         = "GoodwillChangedReason_NeedlesslyInstalledWorseBodyPart".Translate(recipe.addsHediff.label);
                GlobalTargetInfo?lookTarget     = pawn;
                faction.TryAffectGoodwillWith(faction2, goodwillChange, canSendMessage: true, canSendHostilityLetter: true, reason, lookTarget);
            }
        }
 public static void TryGiveThoughts(Pawn victim, DamageInfo?dinfo, PawnDiedOrDownedThoughtsKind thoughtsKind)
 {
     try
     {
         if (!PawnGenerator.IsBeingGenerated(victim))
         {
             if (Current.ProgramState == ProgramState.Playing)
             {
                 PawnDiedOrDownedThoughtsUtility.GetThoughts(victim, dinfo, thoughtsKind, PawnDiedOrDownedThoughtsUtility.tmpIndividualThoughtsToAdd, PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts);
                 for (int i = 0; i < PawnDiedOrDownedThoughtsUtility.tmpIndividualThoughtsToAdd.Count; i++)
                 {
                     PawnDiedOrDownedThoughtsUtility.tmpIndividualThoughtsToAdd[i].Add();
                 }
                 if (PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts.Any <ThoughtDef>())
                 {
                     foreach (Pawn pawn in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_Colonists)
                     {
                         if (pawn != victim)
                         {
                             for (int j = 0; j < PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts.Count; j++)
                             {
                                 ThoughtDef def = PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts[j];
                                 pawn.needs.mood.thoughts.memories.TryGainMemory(def, null);
                             }
                         }
                     }
                 }
                 PawnDiedOrDownedThoughtsUtility.tmpIndividualThoughtsToAdd.Clear();
                 PawnDiedOrDownedThoughtsUtility.tmpAllColonistsThoughts.Clear();
             }
         }
     }
     catch (Exception arg)
     {
         Log.Error("Could not give thoughts: " + arg, false);
     }
 }
        public void Spawn()
        {
            try {
                Utils.forceGeneratedAndroidToBeDefaultPainted = true;

                PawnGenerationRequest request = new PawnGenerationRequest(Spawnprops.Pawnkind, Faction.OfPlayer, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, true, 1f, false, true, false, false, false, false, false, false, 0f, null, 0f, null, null, null, null);
                Pawn blankAndroid             = PawnGenerator.GeneratePawn(request);
                GenSpawn.Spawn(blankAndroid, this.parent.Position, this.parent.Map, WipeMode.Vanish);

                blankAndroid.health.AddHediff(Utils.hediffBlankAndroid);

                CompAndroidState cas = blankAndroid.ATCompState;
                cas.isBlankAndroid = true;


                Utils.initBodyAsSurrogate(blankAndroid, false);

                string sn = "";
                if (blankAndroid.def.defName == Utils.T3)
                {
                    sn = "T3";
                }
                else if (blankAndroid.def.defName == Utils.T4)
                {
                    sn = "T4";
                }

                blankAndroid.Name = new NameTriple("", sn, "");


                Utils.forceGeneratedAndroidToBeDefaultPainted = false;
                //Utils.GCATPP.pushSurrogateAndroid(surrogate);
            }
            catch (Exception e) {
                Log.Message("Blank Android Spawn Error : " + e.Message + " " + e.StackTrace);
            }
        }
Beispiel #22
0
 public void Notify_MemberDied(Pawn member, DamageInfo?dinfo, bool wasWorldPawn, Map map)
 {
     if (this.IsPlayer)
     {
         return;
     }
     if (!wasWorldPawn && !PawnGenerator.IsBeingGenerated(member) && Current.ProgramState == ProgramState.Playing && map != null && map.IsPlayerHome && !this.HostileTo(Faction.OfPlayer))
     {
         if (dinfo.HasValue && dinfo.Value.Category == DamageInfo.SourceCategory.Collapse)
         {
             bool    flag           = MessagesRepeatAvoider.MessageShowAllowed("FactionRelationAdjustmentCrushed-" + this.Name, 5f);
             Faction ofPlayer       = Faction.OfPlayer;
             int     goodwillChange = (!member.RaceProps.Humanlike) ? -15 : -25;
             bool    canSendMessage = flag;
             string  reason         = "GoodwillChangedReason_PawnCrushed".Translate(new object[]
             {
                 member.LabelShort
             });
             this.TryAffectGoodwillWith(ofPlayer, goodwillChange, canSendMessage, true, reason, new GlobalTargetInfo?(new TargetInfo(member.Position, map, false)));
         }
         else if (dinfo.HasValue && (dinfo.Value.Instigator == null || dinfo.Value.Instigator.Faction == null))
         {
             Faction ofPlayer       = Faction.OfPlayer;
             int     goodwillChange = (!member.RaceProps.Humanlike) ? -3 : -5;
             string  reason         = "GoodwillChangedReason_PawnDied".Translate(new object[]
             {
                 member.LabelShort
             });
             GlobalTargetInfo?lookTarget = new GlobalTargetInfo?(member);
             this.TryAffectGoodwillWith(ofPlayer, goodwillChange, true, true, reason, lookTarget);
         }
     }
     if (member == this.leader)
     {
         this.Notify_LeaderDied();
     }
 }
        public override void DoEffect(Pawn usedBy)
        {
            base.DoEffect(usedBy);

            var automataDataComp = parent.GetComp <CompAutomataDataHolder>();
            var automataData     = automataDataComp?.automataData;

            QualityCategory qualityCategory = parent.TryGetComp <CompQuality>()?.Quality ?? QualityCategory.Normal;
            var             qualityProperty = AutomataQualityProperty.GetQualityProperty(qualityCategory);

            if (qualityProperty == null)
            {
                Log.Error($"There is no AutomataQualityProperty for quality '{qualityCategory}'");
                return;
            }

            PawnKindDef pawnKindDef = qualityProperty.pawnKindDefs.TryGetValue(automataData.specializationDef, null);

            if (pawnKindDef != null)
            {
                PawnGenerationRequest pawnGenReq = new PawnGenerationRequest(
                    pawnKindDef,
                    faction: Faction.OfPlayer,
                    context: PawnGenerationContext.NonPlayer,
                    tile: -1,
                    forceGenerateNewPawn: true);

                Pawn generated = PawnGenerator.GeneratePawn(pawnGenReq);
                generated.GetComp <CompAutomataDataHolder>().CopyFrom(automataDataComp);

                generated.story.hairDef   = automataData.appearance?.hairDef;
                generated.story.hairColor = Color.white;

                GenSpawn.Spawn(generated, parent.Position, parent.Map);
                generated.SetFaceBodyAddonVariant(automataData.appearance.faceVariantIndex);
            }
        }
        // Token: 0x06005740 RID: 22336 RVA: 0x001D33C0 File Offset: 0x001D15C0
        private bool TrySpawnPawn(out Pawn pawn)
        {
            if (!this.canSpawnPawns)
            {
                pawn = null;
                return(false);
            }
            if (!this.Props.chooseSingleTypeToSpawn)
            {
                this.chosenKind = this.RandomPawnKindDef();
            }
            if (this.chosenKind == null)
            {
                pawn = null;
                return(false);
            }
            pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(this.chosenKind, this.parent.Faction, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 1f, false, true, true, true, false, false, false, false, 0f, null, 1f, null, null, null, null, null, new float?(this.chosenKind.race.race.lifeStageAges.Last().minAge), null, null, null, null, null, null));
            this.spawnedPawns.Add(pawn);
            GenSpawn.Spawn(pawn, this.parent.OccupiedRect().AdjacentCells.RandomElement() /*CellFinder.RandomClosewalkCellNear(this.parent.Position, this.parent.Map, this.Props.pawnSpawnRadius, null) */, this.parent.Map, WipeMode.Vanish);
            Lord lord = this.Lord;

            if (lord == null)
            {
                lord = CompSpawnerPawn.CreateNewLord(this.parent, this.aggressive, this.Props.defendRadius, this.Props.lordJob);
            }
            lord.AddPawn(pawn);
            if (this.Props.spawnSound != null)
            {
                this.Props.spawnSound.PlayOneShot(this.parent);
            }
            if (this.pawnsLeftToSpawn > 0)
            {
                this.pawnsLeftToSpawn--;
            }
            this.SendMessage();
            return(true);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map     map = (Map)parms.target;
            IntVec3 loc;

            if (!this.TryFindEntryCell(map, out loc))
            {
                return(false);
            }
            Gender?gender = null;

            if (this.def.pawnFixedGender != Gender.None)
            {
                gender = new Gender?(this.def.pawnFixedGender);
            }
            PawnKindDef           pawnKind = this.def.pawnKind;
            Faction               ofPlayer = Faction.OfPlayer;
            bool                  pawnMustBeCapableOfViolence = this.def.pawnMustBeCapableOfViolence;
            Gender?               fixedGender = gender;
            PawnGenerationRequest request     = new PawnGenerationRequest(pawnKind, ofPlayer, PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, pawnMustBeCapableOfViolence, 20f, false, true, true, false, false, false, false, null, null, null, null, null, fixedGender, null, null);
            Pawn                  pawn        = PawnGenerator.GeneratePawn(request);

            GenSpawn.Spawn(pawn, loc, map, WipeMode.Vanish);
            string text  = this.def.letterText.Formatted(pawn.Named("PAWN")).AdjustedFor(pawn, "PAWN");
            string label = this.def.letterLabel.Formatted(pawn.Named("PAWN")).AdjustedFor(pawn, "PAWN");

            PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref text, ref label, pawn);

            if (Quote != null)
            {
                text += "\n\n";
                text += Quote;
            }

            Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.PositiveEvent, pawn, null, null);
            return(true);
        }
Beispiel #26
0
        private bool ResolveTransformations()
        {
            if (!hadTransformationChance)
            {
                hadTransformationChance = true;
                if (Rand.Value <= RESettings.MUTATION_CHANCE)
                {
                    var curLoc   = this.PositionHeld;
                    var curMap   = this.MapHeld;
                    var zFaction = Find.FactionManager.FirstFactionOfDef(FactionDef.Named("RE_Zombies"));

                    HediffDef   zHDef;
                    PawnKindDef zKind = ResolveTransformationKind(out zHDef);

                    Pawn newThing;
                    if (zKind.defName != "RE_CrimsonHeadKind")
                    {
                        this.Destroy();
                        FilthMaker.TryMakeFilth(curLoc, curMap, ThingDefOf.Filth_Blood, Rand.Range(5, 8));
                        newThing = PawnGenerator.GeneratePawn(zKind, zFaction);
                    }
                    else
                    {
                        //The function here actually destroys the zombie
                        var facName = this?.Faction?.def?.defName ?? "RE_Zombies";
                        newThing = ZombieUtility.CreateZombieAtSourcePawnLocation(this, "RE_CrimsonHeadKind", facName);
                    }

                    HealthUtility.AdjustSeverity(newThing, zHDef, 1.0f);
                    GenSpawn.Spawn(newThing, curLoc, curMap);

                    ((Zombie)newThing).hadTransformationChance = true;
                    return(true);
                }
            }
            return(false);
        }
Beispiel #27
0
        public void SingleSpawnLoop(SpawnThings spawnables, IntVec3 position, Map map)
        {
            bool flag = spawnables.def != null;

            if (flag)
            {
                Faction faction = pawn.Faction;
                bool    flag2   = spawnables.def.race != null;
                if (flag2)
                {
                    bool flag3 = spawnables.kindDef == null;
                    if (flag3)
                    {
                        Log.Error("Missing kinddef");
                    }
                    else
                    {
                        newPawn                = (TMPawnSummoned)PawnGenerator.GeneratePawn(spawnables.kindDef, faction);
                        newPawn.Spawner        = this.launcher as Pawn;
                        newPawn.Temporary      = true;
                        newPawn.TicksToDestroy = 180;

                        try
                        {
                            GenSpawn.Spawn(newPawn, position, this.Map);
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    Log.Message("Missing race");
                }
            }
        }
Beispiel #28
0
        public void GenerateNewLeader()
        {
            leader = null;
            if (def.pawnGroupMakers == null)
            {
                return;
            }
            List <PawnKindDef> list = new List <PawnKindDef>();

            foreach (PawnGroupMaker item in def.pawnGroupMakers.Where((PawnGroupMaker x) => x.kindDef == PawnGroupKindDefOf.Combat))
            {
                foreach (PawnGenOption option in item.options)
                {
                    if (option.kind.factionLeader)
                    {
                        list.Add(option.kind);
                    }
                }
            }
            if (def.fixedLeaderKinds != null)
            {
                list.AddRange(def.fixedLeaderKinds);
            }
            if (list.TryRandomElement(out PawnKindDef result))
            {
                PawnGenerationRequest request = new PawnGenerationRequest(result, this, PawnGenerationContext.NonPlayer, -1, def.leaderForceGenerateNewPawn);
                leader = PawnGenerator.GeneratePawn(request);
                if (leader.RaceProps.IsFlesh)
                {
                    leader.relations.everSeenByPlayer = true;
                }
                if (!Find.WorldPawns.Contains(leader))
                {
                    Find.WorldPawns.PassToWorld(leader, PawnDiscardDecideMode.KeepForever);
                }
            }
        }
Beispiel #29
0
            public static bool Prefix(IncidentParms parms)
            {
                if (Find.StoryWatcher.statsRecord.numRaidsEnemy != 1)
                {
                    return(true);
                }

                var map = (Map)parms.target;

                if (!RCellFinder.TryFindRandomPawnEntryCell(out var result, map, CellFinder.EdgeRoadChance_Animal))
                {
                    return(true);
                }

                foreach (var p in PawnsFinder.AllMaps_SpawnedPawnsInFaction(Faction.OfPlayer))
                {
                    if (p.kindDef == DefDatabase <PawnKindDef> .GetNamed("HenThirteen"))
                    {
                        return(true);
                    }
                }

                var loc  = CellFinder.RandomClosewalkCellNear(result, map, 12);
                var kind = DefDatabase <PawnKindDef> .GetNamed("HenThirteen");

                var pawn = PawnGenerator.GeneratePawn(kind);

                GenSpawn.Spawn(pawn, loc, map, Rot4.Random);
                //PawnBioAndNameGenerator.GeneratePawnName(pawn, NameStyle.Full, "Hen 13");
                pawn.Name = new NameTriple("Hen", "Hero Chicken", "13");
                pawn.SetFaction(Faction.OfPlayer);
                Find.LetterStack.ReceiveLetter("Hen 13 Joins",
                                               "A mythical hero of wide renown has sensed your danger and has decided to join your cause.  Hen Thirteen is on the scene",
                                               LetterDefOf.PositiveEvent, new TargetInfo(result, map));

                return(false);
            }
        public Pawn CreatePawn(ThingDef def, ThingDef stuffDef, Gender gender)
        {
            PawnKindDef kindDef = (from td in DefDatabase <PawnKindDef> .AllDefs where td.race == def select td).FirstOrDefault();

            RulePackDef nameGenerator = kindDef.RaceProps.GetNameGenerator(gender);

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

            if (kindDef != null)
            {
                int     messageCount;
                Faction faction = Faction.OfPlayer;
                PawnGenerationRequest request = new PawnGenerationRequestWrapper()
                {
                    KindDef = kindDef,
                    Faction = faction,
                    MustBeCapableOfViolence = true
                }.Request;
                messageCount = ReflectionUtil.GetNonPublicStatic <int>(typeof(Log), "messageCount");
                Pawn pawn = PawnGenerator.GeneratePawn(request);
                if (pawn.Dead || pawn.Downed)
                {
                    return(null);
                }
                pawn.gender  = gender;
                messageCount = ReflectionUtil.GetNonPublicStatic <int>(typeof(Log), "messageCount");
                pawn.Drawer.renderer.graphics.ResolveAllGraphics();
                return(pawn);
            }
            else
            {
                return(null);
            }
        }