Beispiel #1
0
        public static void Ressurrect(Pawn pawn, Thing thing)
        {
            if (thing is HoloEmitter)
            {
                if (pawn.Corpse.holdingOwner != null)
                {
                    pawn.Corpse.GetDirectlyHeldThings().TryTransferToContainer(pawn, pawn.Corpse.holdingOwner, true);
                }
                else if (pawn.Corpse.Spawned)
                {
                    ResurrectionUtility.Resurrect(pawn);
                    PawnDiedOrDownedThoughtsUtility.RemoveDiedThoughts(pawn);
                    PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, false);
                    CompOsiris.FixPawnRelationships(pawn);
                    pawn.health.Reset();
                    if (pawn.Corpse != null && pawn.Corpse.Spawned)
                    {
                        pawn.Corpse.DeSpawn();
                    }
                    GenSpawn.Spawn(pawn, pawn.Corpse.Position, pawn.Corpse.Map);
                    GiveSideEffects(pawn);
                }
                if (pawn.Corpse != null)
                {
                    pawn.Corpse.Destroy(DestroyMode.Vanish);
                }
            }
            else
            {
                ResurrectionUtility.Resurrect(pawn);
                PawnDiedOrDownedThoughtsUtility.RemoveDiedThoughts(pawn);
                CompOsiris.FixPawnRelationships(pawn);
                pawn.health.Reset();
                if (pawn.Corpse != null && pawn.Corpse.Spawned)
                {
                    pawn.Corpse.DeSpawn();
                }
                GenSpawn.Spawn(pawn, thing.Position, thing.Map);
                GiveSideEffects(pawn);

                Building_Casket building_Casket = thing as Building_Casket;
                if (building_Casket != null)
                {
                    building_Casket.GetDirectlyHeldThings().Clear();
                }
            }
        }
        public static void TryAbandonViaInterface(MapParent settlement)
        {
            Map map = settlement.Map;

            if (map == null)
            {
                SettlementAbandonUtility.Abandon(settlement);
                SoundDefOf.Tick_High.PlayOneShotOnCamera(null);
            }
            else
            {
                StringBuilder      stringBuilder = new StringBuilder();
                IEnumerable <Pawn> source        = map.mapPawns.PawnsInFaction(Faction.OfPlayer);
                if (source.Count <Pawn>() != 0)
                {
                    StringBuilder stringBuilder2 = new StringBuilder();
                    foreach (Pawn current in from x in source
                             orderby x.IsColonist descending
                             select x)
                    {
                        if (stringBuilder2.Length > 0)
                        {
                            stringBuilder2.AppendLine();
                        }
                        stringBuilder2.Append("    " + current.LabelCap);
                    }
                    stringBuilder.Append("ConfirmAbandonHomeWithColonyPawns".Translate(new object[]
                    {
                        stringBuilder2
                    }));
                }
                PawnDiedOrDownedThoughtsUtility.BuildMoodThoughtsListString(map.mapPawns.AllPawns, PawnDiedOrDownedThoughtsKind.Banished, stringBuilder, null, "\n\n" + "ConfirmAbandonHomeNegativeThoughts_Everyone".Translate(), "ConfirmAbandonHomeNegativeThoughts");
                if (stringBuilder.Length == 0)
                {
                    SettlementAbandonUtility.Abandon(settlement);
                    SoundDefOf.Tick_High.PlayOneShotOnCamera(null);
                }
                else
                {
                    Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(stringBuilder.ToString(), delegate
                    {
                        SettlementAbandonUtility.Abandon(settlement);
                    }, false, null));
                }
            }
        }
Beispiel #3
0
        public static void ResurrectPawnFromVoid(Map map, IntVec3 loc, Pawn pawn)
        {
            Corpse corpse = pawn.Corpse;

            if (corpse != null)
            {
                corpse.Destroy(DestroyMode.Vanish);
            }
            if (pawn.IsWorldPawn())
            {
                Find.WorldPawns.RemovePawn(pawn);
            }
            pawn.ForceSetStateToUnspawned();
            PawnComponentsUtility.CreateInitialComponents(pawn);
            pawn.health.Notify_Resurrected();
            if (pawn.Faction != null && pawn.Faction.IsPlayer)
            {
                if (pawn.workSettings != null)
                {
                    pawn.workSettings.EnableAndInitialize();
                }
                Find.StoryWatcher.watcherPopAdaptation.Notify_PawnEvent(pawn, PopAdaptationEvent.GainedColonist);
            }
            GenSpawn.Spawn(pawn, loc, map, WipeMode.Vanish);
            for (int i = 0; i < 10; i++)
            {
                //MoteMaker.ThrowAirPuffUp(pawn.DrawPos, map);
                DebugActionsUtility.DustPuffFrom(pawn);
            }
            if (pawn.Faction != null && pawn.Faction != Faction.OfPlayer && pawn.HostileTo(Faction.OfPlayer))
            {
                LordMaker.MakeNewLord(pawn.Faction, new LordJob_AssaultColony(pawn.Faction, true, true, false, false, true), pawn.Map, Gen.YieldSingle <Pawn>(pawn));
            }
            if (pawn.apparel != null)
            {
                List <Apparel> wornApparel = pawn.apparel.WornApparel;
                for (int j = 0; j < wornApparel.Count; j++)
                {
                    wornApparel[j].Notify_PawnResurrected();
                }
            }
            PawnDiedOrDownedThoughtsUtility.RemoveDiedThoughts(pawn);
        }
Beispiel #4
0
        public static void TryAbandonViaInterface(MapParent settlement)
        {
            Map map = settlement.Map;

            if (map == null)
            {
                Abandon(settlement);
                SoundDefOf.Tick_High.PlayOneShotOnCamera();
                return;
            }
            StringBuilder stringBuilder = new StringBuilder();
            List <Pawn>   source        = map.mapPawns.PawnsInFaction(Faction.OfPlayer);

            if (source.Count() != 0)
            {
                StringBuilder stringBuilder2 = new StringBuilder();
                foreach (Pawn item in source.OrderByDescending((Pawn x) => x.IsColonist))
                {
                    if (stringBuilder2.Length > 0)
                    {
                        stringBuilder2.AppendLine();
                    }
                    stringBuilder2.Append("    " + item.LabelCap);
                }
                stringBuilder.Append("ConfirmAbandonHomeWithColonyPawns".Translate(stringBuilder2));
            }
            PawnDiedOrDownedThoughtsUtility.BuildMoodThoughtsListString(map.mapPawns.AllPawns, PawnDiedOrDownedThoughtsKind.Banished, stringBuilder, null, "\n\n" + "ConfirmAbandonHomeNegativeThoughts_Everyone".Translate(), "ConfirmAbandonHomeNegativeThoughts");
            if (stringBuilder.Length == 0)
            {
                Abandon(settlement);
                SoundDefOf.Tick_High.PlayOneShotOnCamera();
            }
            else
            {
                Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(stringBuilder.ToString(), delegate
                {
                    Abandon(settlement);
                }));
            }
        }
Beispiel #5
0
        static bool Prefix(MapParent settlement)
        {
            Settlement factionBase = settlement as Settlement;

            if (WorldObjectRemnantColony.CanCreateRemnantColony(factionBase))
            {
                //custom text for remnant colony
                Map                map           = settlement.Map;
                StringBuilder      stringBuilder = new StringBuilder();
                IEnumerable <Pawn> source        = map.mapPawns.PawnsInFaction(Faction.OfPlayer);
                if (source.Any())
                {
                    StringBuilder stringBuilder2 = new StringBuilder();
                    foreach (Pawn current in from x in source
                             orderby x.IsColonist descending
                             select x)
                    {
                        if (stringBuilder2.Length > 0)
                        {
                            stringBuilder2.AppendLine();
                        }
                        stringBuilder2.Append("    " + current.LabelCap);
                    }
                    stringBuilder.Append("ConfirmAbandonHomeWithColonyPawns".Translate(stringBuilder2.ToString()));
                }

                //any pawns we wont use in the remnant colony will be banished(e.g. animals and prisoner)
                PawnDiedOrDownedThoughtsUtility.BuildMoodThoughtsListString(
                    map.mapPawns.AllPawns.Except(WorldObjectRemnantColony.GetPawnsFromSettlementForRemnantColony(factionBase)),
                    PawnDiedOrDownedThoughtsKind.Banished, stringBuilder, null, "\n\n" + "ConfirmAbandonHomeNegativeThoughts_Everyone".Translate(), "ConfirmAbandonHomeNegativeThoughts");

                Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(stringBuilder.ToString(), delegate {
                    typeof(SettlementAbandonUtility).GetMethod("Abandon", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new Object[] { settlement });
                }, false, null));
                return(false);
            }
            return(true);
        }
 private void MakeDowned(DamageInfo?dinfo, Hediff hediff)
 {
     if (this.Downed)
     {
         Log.Error(this.pawn + " tried to do MakeDowned while already downed.", false);
     }
     else
     {
         if (this.pawn.guilt != null && this.pawn.GetLord() != null && this.pawn.GetLord().LordJob != null && this.pawn.GetLord().LordJob.GuiltyOnDowned)
         {
             this.pawn.guilt.Notify_Guilty();
         }
         this.healthState = PawnHealthState.Down;
         PawnDiedOrDownedThoughtsUtility.TryGiveThoughts(this.pawn, dinfo, PawnDiedOrDownedThoughtsKind.Downed);
         if (this.pawn.InMentalState)
         {
             this.pawn.mindState.mentalStateHandler.CurState.RecoverFromState();
         }
         if (this.pawn.Spawned)
         {
             if (this.pawn.IsColonist && dinfo != null && dinfo.Value.Def.externalViolence)
             {
                 Find.StoryWatcher.watcherRampUp.Notify_ColonistViolentlyDownedOrKilled(this.pawn);
             }
             this.pawn.DropAndForbidEverything(true);
             this.pawn.stances.CancelBusyStanceSoft();
         }
         this.pawn.ClearMind(true);
         if (Current.ProgramState == ProgramState.Playing)
         {
             Lord lord = this.pawn.GetLord();
             if (lord != null)
             {
                 lord.Notify_PawnLost(this.pawn, PawnLostCondition.IncappedOrKilled);
             }
         }
         if (this.pawn.Drafted)
         {
             this.pawn.drafter.Drafted = false;
         }
         PortraitsCache.SetDirty(this.pawn);
         if (this.pawn.SpawnedOrAnyParentSpawned)
         {
             GenHostility.Notify_PawnLostForTutor(this.pawn, this.pawn.MapHeld);
         }
         if (this.pawn.RaceProps.Humanlike && Current.ProgramState == ProgramState.Playing && this.pawn.SpawnedOrAnyParentSpawned)
         {
             if (this.pawn.HostileTo(Faction.OfPlayer))
             {
                 LessonAutoActivator.TeachOpportunity(ConceptDefOf.Capturing, this.pawn, OpportunityType.Important);
             }
             if (this.pawn.Faction == Faction.OfPlayer)
             {
                 LessonAutoActivator.TeachOpportunity(ConceptDefOf.Rescuing, this.pawn, OpportunityType.Critical);
             }
         }
         if (dinfo != null && dinfo.Value.Instigator != null)
         {
             Pawn pawn = dinfo.Value.Instigator as Pawn;
             if (pawn != null)
             {
                 RecordsUtility.Notify_PawnDowned(this.pawn, pawn);
             }
         }
         if (this.pawn.Spawned)
         {
             TaleRecorder.RecordTale(TaleDefOf.Downed, new object[]
             {
                 this.pawn,
                 (dinfo == null) ? null : (dinfo.Value.Instigator as Pawn),
                 (dinfo == null) ? null : dinfo.Value.Weapon
             });
             Find.BattleLog.Add(new BattleLogEntry_StateTransition(this.pawn, RulePackDefOf.Transition_Downed, (dinfo == null) ? null : (dinfo.Value.Instigator as Pawn), hediff, (dinfo == null) ? null : dinfo.Value.HitPart));
         }
     }
 }
Beispiel #7
0
            public static void Listener(ref Pawn ___pawn, ref Hediff hediff, BodyPartRecord part)
            {
                try
                {
                    //Si il sagit d'une VX0 alors passation du pawn en mode surrogate
                    if (hediff.def.defName == "ATPP_HediffVX0Chip" && (___pawn.Faction == Faction.OfPlayer || ___pawn.IsPrisoner))
                    {
                        CompAndroidState cas = ___pawn.TryGetComp <CompAndroidState>();
                        if (cas == null || cas.isSurrogate)
                        {
                            return;
                        }

                        if (___pawn.Faction.IsPlayer && !Utils.preventVX0Thought)
                        {
                            //Simulation mort surrogate organic
                            PawnDiedOrDownedThoughtsUtility.TryGiveThoughts(___pawn, null, PawnDiedOrDownedThoughtsKind.Died);

                            Pawn spouse = ___pawn.GetSpouse();
                            if (spouse != null && !spouse.Dead && spouse.needs.mood != null)
                            {
                                MemoryThoughtHandler memories = spouse.needs.mood.thoughts.memories;
                                memories.RemoveMemoriesOfDef(ThoughtDefOf.GotMarried);
                                memories.RemoveMemoriesOfDef(ThoughtDefOf.HoneymoonPhase);
                            }
                            Traverse.Create(___pawn.relations).Method("AffectBondedAnimalsOnMyDeath").GetValue();

                            ___pawn.health.NotifyPlayerOfKilled(null, null, null);
                        }
                        else
                        {
                            //Si pas de la faction du player alors on va changer sa faction dans simuler de mort
                            if (!___pawn.Faction.IsPlayer)
                            {
                                ___pawn.SetFaction(Faction.OfPlayer, null);
                            }
                        }

                        cas.initAsSurrogate();

                        //SKills vierges
                        ___pawn.skills = new Pawn_SkillTracker(___pawn);
                        ___pawn.needs  = new Pawn_NeedsTracker(___pawn);

                        //Effacement des relations
                        ___pawn.relations = new Pawn_RelationsTracker(___pawn);

                        //TOuts les SX sont simple minded et ont aucuns autres traits
                        TraitDef td = DefDatabase <TraitDef> .GetNamed("SimpleMindedAndroid", false);

                        Trait t = null;
                        if (td != null)
                        {
                            t = new Trait(td);
                        }

                        ___pawn.story.traits.allTraits.Clear();
                        if (t != null)
                        {
                            ___pawn.story.traits.allTraits.Add(t);
                        }
                        Utils.notifTraitsChanged(___pawn);

                        if (!___pawn.IsAndroidTier())
                        {
                            //Reset du child et adulthood
                            if (!Settings.keepPuppetBackstory && ___pawn.story.childhood != null)
                            {
                                Backstory bs = null;

                                BackstoryDatabase.TryGetWithIdentifier("MercenaryRecruit", out bs);
                                if (bs != null)
                                {
                                    ___pawn.story.childhood = bs;
                                }
                            }

                            ___pawn.story.adulthood = null;
                        }


                        //Reset incapable of
                        Utils.ResetCachedIncapableOf(___pawn);

                        //Définition nouveau nom
                        ___pawn.Name = new NameTriple("", "S" + 0 + "-" + Utils.GCATPP.getNextSXID(0), "");
                        Utils.GCATPP.incNextSXID(0);

                        if (!Utils.preventVX0Thought)
                        {
                            //Ajout du thought de PUPPET
                            for (int i = 0; i < PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonistsAndPrisoners.Count; i++)
                            {
                                Pawn current = PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonistsAndPrisoners[i];
                                current.needs.mood.thoughts.memories.TryGainMemory(ThoughtMaker.MakeThought(Utils.thoughtDefVX0Puppet, 0), null);
                            }
                        }

                        if (___pawn.IsPrisoner)
                        {
                            if (___pawn.guest != null)
                            {
                                ___pawn.guest.SetGuestStatus(Faction.OfPlayer, false);
                            }
                        }
                        if (___pawn.workSettings == null)
                        {
                            ___pawn.workSettings = new Pawn_WorkSettings(___pawn);
                            ___pawn.workSettings.EnableAndInitializeIfNotAlreadyInitialized();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Message("[ATPP] Pawn_HealthTracker.AddHediffPostfix " + ex.Message + " " + ex.StackTrace);
                }
            }
Beispiel #8
0
            public static void Listener(ref Pawn ___pawn, ref Hediff hediff, BodyPartRecord part)
            {
                try
                {
                    if (hediff.def.defName != "ATPP_HediffVX0Chip" || ___pawn.Faction != Faction.OfPlayer && !___pawn.IsPrisoner)
                    {
                        return;
                    }

                    var cas = ___pawn.TryGetComp <CompAndroidState>();
                    if (cas == null || cas.isSurrogate)
                    {
                        return;
                    }

                    if (___pawn.Faction.IsPlayer && !Utils.preventVX0Thought)
                    {
                        PawnDiedOrDownedThoughtsUtility.TryGiveThoughts(___pawn, null, PawnDiedOrDownedThoughtsKind.Died);

                        var spouse = ___pawn.GetSpouse();
                        if (spouse != null && !spouse.Dead && spouse.needs.mood != null)
                        {
                            var memories = spouse.needs.mood.thoughts.memories;
                            memories.RemoveMemoriesOfDef(ThoughtDefOf.GotMarried);
                            memories.RemoveMemoriesOfDef(ThoughtDefOf.HoneymoonPhase);
                        }

                        Traverse.Create(___pawn.relations).Method("AffectBondedAnimalsOnMyDeath").GetValue();

                        ___pawn.health.NotifyPlayerOfKilled(null, null, null);
                    }
                    else
                    {
                        if (!___pawn.Faction.IsPlayer)
                        {
                            ___pawn.SetFaction(Faction.OfPlayer);
                        }
                    }

                    cas.initAsSurrogate();


                    ___pawn.skills = new Pawn_SkillTracker(___pawn);
                    ___pawn.needs  = new Pawn_NeedsTracker(___pawn);


                    ___pawn.relations = new Pawn_RelationsTracker(___pawn);


                    var td = DefDatabase <TraitDef> .GetNamed("SimpleMindedAndroid", false);

                    Trait t = null;
                    if (td != null)
                    {
                        t = new Trait(td);
                    }

                    ___pawn.story.traits.allTraits.Clear();
                    if (t != null)
                    {
                        ___pawn.story.traits.allTraits.Add(t);
                    }
                    Utils.notifTraitsChanged(___pawn);

                    if (!___pawn.IsAndroidTier())
                    {
                        if (!Settings.keepPuppetBackstory && ___pawn.story.childhood != null)
                        {
                            BackstoryDatabase.TryGetWithIdentifier("MercenaryRecruit", out var bs);
                            if (bs != null)
                            {
                                ___pawn.story.childhood = bs;
                            }
                        }

                        ___pawn.story.adulthood = null;
                    }


                    Utils.ResetCachedIncapableOf(___pawn);


                    ___pawn.Name = new NameTriple("", "S" + 0 + "-" + Utils.GCATPP.getNextSXID(0), "");
                    Utils.GCATPP.incNextSXID(0);

                    if (!Utils.preventVX0Thought)
                    {
                        foreach (var current in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonistsAndPrisoners)
                        {
                            current.needs.mood.thoughts.memories.TryGainMemory(ThoughtMaker.MakeThought(Utils.thoughtDefVX0Puppet, 0));
                        }
                    }

                    if (___pawn.IsPrisoner)
                    {
                        ___pawn.guest?.SetGuestStatus(Faction.OfPlayer);
                    }

                    if (___pawn.workSettings != null)
                    {
                        return;
                    }

                    ___pawn.workSettings = new Pawn_WorkSettings(___pawn);
                    ___pawn.workSettings.EnableAndInitializeIfNotAlreadyInitialized();
                }
                catch (Exception ex)
                {
                    Log.Message("[ATPP] Pawn_HealthTracker.AddHediffPostfix " + ex.Message + " " + ex.StackTrace);
                }
            }
Beispiel #9
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            if (billDoer != null)
            {
                if (CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    foreach (var i in ingredients)
                    {
                        if (i is CorticalStack c)
                        {
                            c.stackCount = 1;
                            Traverse.Create(c).Field("mapIndexOrState").SetValue((sbyte)-1);
                            GenPlace.TryPlaceThing(c, billDoer.Position, billDoer.Map, ThingPlaceMode.Near);
                        }
                    }
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn);
            }

            var thing = ingredients.Where(x => x is CorticalStack).FirstOrDefault();

            if (thing is CorticalStack corticalStack)
            {
                var hediff = HediffMaker.MakeHediff(recipe.addsHediff, pawn) as Hediff_CorticalStack;
                pawn.health.AddHediff(hediff, part);
                if (corticalStack.hasPawn)
                {
                    hediff.gender = corticalStack.gender;
                    hediff.race   = corticalStack.race;
                    if (pawn.IsColonist)
                    {
                        Find.StoryWatcher.statsRecord.Notify_ColonistKilled();
                    }
                    PawnDiedOrDownedThoughtsUtility.TryGiveThoughts(pawn, null, PawnDiedOrDownedThoughtsKind.Died);
                    pawn.health.NotifyPlayerOfKilled(null, null, null);
                    ACUtils.ACTracker.stacksIndex.Remove(corticalStack.pawnID + corticalStack.name);
                    corticalStack.OverwritePawn(pawn);
                    hediff.stackGroupID = corticalStack.stackGroupID;
                    ACUtils.ACTracker.ReplaceStackWithPawn(corticalStack, pawn);

                    var naturalMood = pawn.story.traits.GetTrait(TraitDefOf.NaturalMood);
                    var nerves      = pawn.story.traits.GetTrait(TraitDefOf.Nerves);

                    if ((naturalMood != null && naturalMood.Degree == -2) ||
                        pawn.story.traits.HasTrait(TraitDefOf.BodyPurist) ||
                        (nerves != null && nerves.Degree == -2) ||
                        pawn.story.traits.HasTrait(AlteredCarbonDefOf.AC_Sleever))
                    {
                        pawn.needs.mood.thoughts.memories.TryGainMemory(AlteredCarbonDefOf.AC_NewSleeveDouble);
                    }
                    else
                    {
                        pawn.needs.mood.thoughts.memories.TryGainMemory(AlteredCarbonDefOf.AC_NewSleeve);
                    }
                }
                else
                {
                    hediff.gender = pawn.gender;
                    hediff.race   = pawn.kindDef.race;
                    if (ACUtils.ACTracker.stacksRelationships != null)
                    {
                        hediff.stackGroupID = ACUtils.ACTracker.stacksRelationships.Count + 1;
                    }
                    else
                    {
                        hediff.stackGroupID = 0;
                    }
                    ACUtils.ACTracker.RegisterPawn(pawn);
                    ACUtils.ACTracker.TryAddRelationships(pawn);
                }

                var additionalSleeveBodyData = pawn.health.hediffSet.GetFirstHediffOfDef(AlteredCarbonDefOf.AC_SleeveBodyData) as Hediff_SleeveBodyStats;
                if (additionalSleeveBodyData != null)
                {
                    additionalSleeveBodyData.ApplyEffects();
                }
                if (ACUtils.ACTracker.emptySleeves != null && ACUtils.ACTracker.emptySleeves.Contains(pawn))
                {
                    ACUtils.ACTracker.emptySleeves.Remove(pawn);
                }
            }
        }
 private void MakeDowned(DamageInfo?dinfo, Hediff hediff)
 {
     if (Downed)
     {
         Log.Error(string.Concat(this.pawn, " tried to do MakeDowned while already downed."));
         return;
     }
     if (this.pawn.guilt != null && this.pawn.GetLord() != null && this.pawn.GetLord().LordJob != null && this.pawn.GetLord().LordJob.GuiltyOnDowned)
     {
         this.pawn.guilt.Notify_Guilty();
     }
     healthState = PawnHealthState.Down;
     PawnDiedOrDownedThoughtsUtility.TryGiveThoughts(this.pawn, dinfo, PawnDiedOrDownedThoughtsKind.Downed);
     if (this.pawn.InMentalState && this.pawn.MentalStateDef.recoverFromDowned)
     {
         this.pawn.mindState.mentalStateHandler.CurState.RecoverFromState();
     }
     if (this.pawn.Spawned)
     {
         this.pawn.DropAndForbidEverything(keepInventoryAndEquipmentIfInBed: true);
         this.pawn.stances.CancelBusyStanceSoft();
     }
     this.pawn.ClearMind(ifLayingKeepLaying: true, clearInspiration: false, clearMentalState: false);
     if (Current.ProgramState == ProgramState.Playing)
     {
         Lord lord = this.pawn.GetLord();
         if (lord != null && (lord.LordJob == null || lord.LordJob.RemoveDownedPawns))
         {
             lord.Notify_PawnLost(this.pawn, PawnLostCondition.IncappedOrKilled, dinfo);
         }
     }
     if (this.pawn.Drafted)
     {
         this.pawn.drafter.Drafted = false;
     }
     PortraitsCache.SetDirty(this.pawn);
     if (this.pawn.SpawnedOrAnyParentSpawned)
     {
         GenHostility.Notify_PawnLostForTutor(this.pawn, this.pawn.MapHeld);
     }
     if (this.pawn.RaceProps.Humanlike && Current.ProgramState == ProgramState.Playing && this.pawn.SpawnedOrAnyParentSpawned)
     {
         if (this.pawn.HostileTo(Faction.OfPlayer))
         {
             LessonAutoActivator.TeachOpportunity(ConceptDefOf.Capturing, this.pawn, OpportunityType.Important);
         }
         if (this.pawn.Faction == Faction.OfPlayer)
         {
             LessonAutoActivator.TeachOpportunity(ConceptDefOf.Rescuing, this.pawn, OpportunityType.Critical);
         }
     }
     if (dinfo.HasValue && dinfo.Value.Instigator != null)
     {
         Pawn pawn = dinfo.Value.Instigator as Pawn;
         if (pawn != null)
         {
             RecordsUtility.Notify_PawnDowned(this.pawn, pawn);
         }
     }
     if (this.pawn.Spawned)
     {
         TaleRecorder.RecordTale(TaleDefOf.Downed, this.pawn, dinfo.HasValue ? (dinfo.Value.Instigator as Pawn) : null, dinfo.HasValue ? dinfo.Value.Weapon : null);
         Find.BattleLog.Add(new BattleLogEntry_StateTransition(this.pawn, RulePackDefOf.Transition_Downed, dinfo.HasValue ? (dinfo.Value.Instigator as Pawn) : null, hediff, dinfo.HasValue ? dinfo.Value.HitPart : null));
     }
     Find.Storyteller.Notify_PawnEvent(this.pawn, AdaptationEvent.Downed, dinfo);
 }
Beispiel #11
0
        public static void Resurrect(Pawn pawn)
        {
            if (!pawn.Dead)
            {
                Log.Error("Tried to resurrect a pawn who is not dead: " + pawn.ToStringSafe <Pawn>(), false);
                return;
            }
            if (pawn.Discarded)
            {
                Log.Error("Tried to resurrect a discarded pawn: " + pawn.ToStringSafe <Pawn>(), false);
                return;
            }
            Corpse  corpse = pawn.Corpse;
            bool    flag   = false;
            IntVec3 loc    = IntVec3.Invalid;
            Map     map    = null;

            if (corpse != null)
            {
                flag             = corpse.Spawned;
                loc              = corpse.Position;
                map              = corpse.Map;
                corpse.InnerPawn = null;
                corpse.Destroy(DestroyMode.Vanish);
            }
            if (flag && pawn.IsWorldPawn())
            {
                Find.WorldPawns.RemovePawn(pawn);
            }
            pawn.ForceSetStateToUnspawned();
            PawnComponentsUtility.CreateInitialComponents(pawn);
            pawn.health.Notify_Resurrected();
            if (pawn.Faction != null && pawn.Faction.IsPlayer)
            {
                if (pawn.workSettings != null)
                {
                    pawn.workSettings.EnableAndInitialize();
                }
                Find.StoryWatcher.watcherPopAdaptation.Notify_PawnEvent(pawn, PopAdaptationEvent.GainedColonist);
            }
            if (flag)
            {
                GenSpawn.Spawn(pawn, loc, map, WipeMode.Vanish);
                for (int i = 0; i < 10; i++)
                {
                    MoteMaker.ThrowAirPuffUp(pawn.DrawPos, map);
                }
                if (pawn.Faction != null && pawn.Faction != Faction.OfPlayer && pawn.HostileTo(Faction.OfPlayer))
                {
                    LordMaker.MakeNewLord(pawn.Faction, new LordJob_AssaultColony(pawn.Faction, true, true, false, false, true), pawn.Map, Gen.YieldSingle <Pawn>(pawn));
                }
                if (pawn.apparel != null)
                {
                    List <Apparel> wornApparel = pawn.apparel.WornApparel;
                    for (int j = 0; j < wornApparel.Count; j++)
                    {
                        wornApparel[j].Notify_PawnResurrected();
                    }
                }
            }
            PawnDiedOrDownedThoughtsUtility.RemoveDiedThoughts(pawn);
        }
        private static void PassPawnsToWorld(Map map)
        {
            List <Pawn> list  = new List <Pawn>();
            List <Pawn> list2 = new List <Pawn>();
            bool        flag  = map.ParentFaction != null && map.ParentFaction.HostileTo(Faction.OfPlayer);
            List <Pawn> list3 = map.mapPawns.AllPawns.ToList();

            for (int i = 0; i < list3.Count; i++)
            {
                Find.Storyteller.Notify_PawnEvent(list3[i], AdaptationEvent.LostBecauseMapClosed);
                try
                {
                    Pawn pawn = list3[i];
                    if (pawn.Spawned)
                    {
                        pawn.DeSpawn();
                    }
                    if (pawn.IsColonist && flag)
                    {
                        list.Add(pawn);
                        map.ParentFaction.kidnapped.Kidnap(pawn, null);
                        continue;
                    }
                    if (pawn.Faction == Faction.OfPlayer || pawn.HostFaction == Faction.OfPlayer)
                    {
                        list2.Add(pawn);
                        PawnDiedOrDownedThoughtsUtility.TryGiveThoughts(pawn, null, PawnDiedOrDownedThoughtsKind.Lost);
                    }
                    CleanUpAndPassToWorld(pawn);
                }
                catch (Exception ex)
                {
                    Log.Error(string.Concat("Could not despawn and pass to world ", list3[i], ": ", ex));
                }
            }
            for (int j = 0; j < list.Count; j++)
            {
                QuestUtility.SendQuestTargetSignals(list[j].questTags, "LeftMap", list[j].Named("SUBJECT"));
            }
            for (int k = 0; k < list2.Count; k++)
            {
                QuestUtility.SendQuestTargetSignals(list2[k].questTags, "LeftMap", list2[k].Named("SUBJECT"));
            }
            if (!list.Any() && !list2.Any())
            {
                return;
            }
            StringBuilder stringBuilder = new StringBuilder();

            if (list.Any())
            {
                list.SortByDescending((Pawn x) => x.RaceProps.Humanlike);
                for (int l = 0; l < list.Count; l++)
                {
                    stringBuilder.AppendLineTagged("  - " + list[l].NameShortColored.CapitalizeFirst() + ": " + "capturedBy".Translate(map.ParentFaction.NameColored).CapitalizeFirst());
                }
            }
            if (list2.Any())
            {
                list2.SortByDescending((Pawn x) => x.RaceProps.Humanlike);
                for (int m = 0; m < list2.Count; m++)
                {
                    stringBuilder.AppendLineTagged("  - " + list2[m].NameShortColored.CapitalizeFirst());
                }
            }
            string str;
            string str2;

            if (map.IsPlayerHome)
            {
                str  = "LetterLabelPawnsLostBecauseMapClosed_Home".Translate();
                str2 = "LetterPawnsLostBecauseMapClosed_Home".Translate();
            }
            else
            {
                str  = "LetterLabelPawnsLostBecauseMapClosed_Caravan".Translate();
                str2 = "LetterPawnsLostBecauseMapClosed_Caravan".Translate();
            }
            str2 = str2 + ":\n\n" + stringBuilder.ToString().TrimEndNewlines();
            Find.LetterStack.ReceiveLetter(str, str2, LetterDefOf.NegativeEvent, new GlobalTargetInfo(map.Tile));
        }