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));
         }
     }
 }
Example #2
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);
                }
            }
Example #3
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);
                }
            }
Example #4
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);
 }
        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));
        }