Beispiel #1
0
 public void SetDead()
 {
     if (Dead)
     {
         Log.Error(pawn + " set dead while already dead.");
     }
     healthState = PawnHealthState.Dead;
 }
 public void SetDead()
 {
     if (Dead)
     {
         Log.Error(string.Concat(pawn, " set dead while already dead."));
     }
     healthState = PawnHealthState.Dead;
 }
Beispiel #3
0
 public void SetDead()
 {
     if (this.Dead)
     {
         Log.Error(this.pawn + " set dead while already dead.", false);
     }
     this.healthState = PawnHealthState.Dead;
 }
        // It would be nice if we could just do this to deep copy a pawn, but there are references to world objects in a saved pawn that can cause
        // problems, i.e. relationship references to other pawns.  So we follow the more explicit technique below to copy the pawn.
        // Leaving this here to remind us to not bother trying to do this again.
        //public static Pawn IdealCopy(this Pawn source) {
        //    try {
        //        Pawn copy = UtilityCopy.CopyExposable<Pawn>(source);
        //        copy.ClearCaches();
        //        return copy;
        //    }
        //    catch (Exception e) {
        //        Logger.Warning("Failed to copy pawn with preferred method.  Using backup method instead.\n" + e);
        //        return CopyBackup(source);
        //    }
        //}

        public static Pawn Copy(this Pawn source)
        {
            PawnHealthState savedHealthState = source.health.State;

            Pawn result = (Pawn)ThingMaker.MakeThing(source.kindDef.race, null);

            result.kindDef = source.kindDef;
            result.SetFactionDirect(source.Faction);
            PawnComponentsUtility.CreateInitialComponents(result);

            // Copy gender.
            result.gender = source.gender;

            // Copy name;
            NameTriple nameTriple = source.Name as NameTriple;
            NameSingle nameSingle = source.Name as NameSingle;

            if (nameTriple != null)
            {
                result.Name = new NameTriple(nameTriple.First, nameTriple.Nick, nameTriple.Last);
            }
            else if (nameSingle != null)
            {
                result.Name = new NameSingle(nameSingle.Name, nameSingle.Numerical);
            }

            // Copy trackers.
            object[] constructorArgs = new object[] { result };
            result.ageTracker = UtilityCopy.CopyExposable(source.ageTracker, constructorArgs);
            result.story      = UtilityCopy.CopyExposable(source.story, constructorArgs);
            result.skills     = UtilityCopy.CopyExposable(source.skills, constructorArgs);
            result.health     = UtilityCopy.CopyExposable(source.health, constructorArgs);
            result.apparel    = UtilityCopy.CopyExposable(source.apparel, constructorArgs);

            // Copy comps
            //List<ThingComp> validComps = new List<ThingComp>();
            //foreach (var c in source.AllComps) {
            //    PawnCompsSaver saver = new PawnCompsSaver(new List<ThingComp>() { c }, null);
            //    string xml = UtilityCopy.SerializeExposableToString(saver);
            //    XmlDocument doc = new XmlDocument();
            //    doc.LoadXml(xml);
            //    if (doc.DocumentElement.HasChildNodes) {
            //        validComps.Add(c);
            //        Logger.Debug(c.GetType().FullName + ": \n  " + xml);
            //    }
            //    else {
            //        Logger.Debug(c.GetType().FullName + " is empty");
            //    }
            //}

            CopyPawnComps(source, result);

            // Clear all of the pawn caches.
            source.ClearCaches();
            result.ClearCaches();

            return(result);
        }
 public void Reset()
 {
     this.healthState = PawnHealthState.Mobile;
     this.hediffSet.Clear();
     this.capacities.Clear();
     this.summaryHealth.Notify_HealthChanged();
     this.surgeryBills.Clear();
     this.immunity = new ImmunityHandler(this.pawn);
 }
        public static void ClearCachedHealth(this Pawn pawn)
        {
            PawnHealthState savedHealthState = pawn.health.State;

            pawn.health.summaryHealth.Notify_HealthChanged();
            pawn.health.capacities.Clear();
            if (pawn.health.State != savedHealthState)
            {
                Log.Warning("Pawn healthState mismatched: " + savedHealthState + " != " + pawn.health.State + ";  Resetting value to match.");
                pawn.SetHealthState(savedHealthState);
            }
        }
 public void Notify_Resurrected()
 {
     this.healthState = PawnHealthState.Mobile;
     this.hediffSet.hediffs.RemoveAll((Hediff x) => x.def.everCurableByItem && x.TryGetComp <HediffComp_Immunizable>() != null);
     this.hediffSet.hediffs.RemoveAll((Hediff x) => x.def.everCurableByItem && x is Hediff_Injury && !x.IsPermanent());
     this.hediffSet.hediffs.RemoveAll(delegate(Hediff x)
     {
         bool result;
         if (x.def.everCurableByItem)
         {
             if (x.def.lethalSeverity < 0f)
             {
                 if (x.def.stages != null)
                 {
                     result = x.def.stages.Any((HediffStage y) => y.lifeThreatening);
                 }
                 else
                 {
                     result = false;
                 }
             }
             else
             {
                 result = true;
             }
         }
         else
         {
             result = false;
         }
         return(result);
     });
     this.hediffSet.hediffs.RemoveAll((Hediff x) => x.def.everCurableByItem && x is Hediff_Injury && x.IsPermanent() && this.hediffSet.GetPartHealth(x.Part) <= 0f);
     for (;;)
     {
         Hediff_MissingPart hediff_MissingPart = (from x in this.hediffSet.GetMissingPartsCommonAncestors()
                                                  where !this.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(x.Part)
                                                  select x).FirstOrDefault <Hediff_MissingPart>();
         if (hediff_MissingPart == null)
         {
             break;
         }
         this.RestorePart(hediff_MissingPart.Part, null, false);
     }
     this.hediffSet.DirtyCache();
     if (this.ShouldBeDead())
     {
         this.hediffSet.hediffs.Clear();
     }
     this.Notify_HediffChanged(null);
 }
Beispiel #8
0
        private static string GetHealthStateFriendly(PawnHealthState state)
        {
            switch (state)
            {
            case PawnHealthState.Down:
                return("💫");

            case PawnHealthState.Dead:
                return("👻");

            default:
                return(string.Empty);
            }
        }
Beispiel #9
0
        private static string GetHealthStateFriendly(PawnHealthState state)
        {
            switch (state)
            {
            case PawnHealthState.Down:
                return(ResponseHelper.DazedGlyph.AltText("DownedLower".Localize().CapitalizeFirst()));

            case PawnHealthState.Dead:
                return(ResponseHelper.GhostGlyph.AltText("Dead".Localize()));

            default:
                return(string.Empty);
            }
        }
        public static Pawn Copy(this Pawn source)
        {
            PawnHealthState savedHealthState = source.health.State;

            Pawn result = (Pawn)ThingMaker.MakeThing(source.kindDef.race, null);

            result.kindDef = source.kindDef;
            result.SetFactionDirect(source.Faction);
            PawnComponentsUtility.CreateInitialComponents(result);

            // Copy gender.
            result.gender = source.gender;

            // Copy name;
            NameTriple nameTriple = source.Name as NameTriple;
            NameSingle nameSingle = source.Name as NameSingle;

            if (nameTriple != null)
            {
                result.Name = new NameTriple(nameTriple.First, nameTriple.Nick, nameTriple.Last);
            }
            else if (nameSingle != null)
            {
                result.Name = new NameSingle(nameSingle.Name, nameSingle.Numerical);
            }

            // Copy trackers.
            object[] constructorArgs = new object[] { result };
            result.ageTracker = UtilityCopy.CopyExposable(source.ageTracker, constructorArgs);
            result.story      = UtilityCopy.CopyExposable(source.story, constructorArgs);
            result.skills     = UtilityCopy.CopyExposable(source.skills, constructorArgs);
            result.health     = UtilityCopy.CopyExposable(source.health, constructorArgs);
            result.apparel    = UtilityCopy.CopyExposable(source.apparel, constructorArgs);

            // Copy properties added to pawns by mods.
            CopyModdedProperties(source, result);

            // Verify the pawn health state.
            if (result.health.State != savedHealthState)
            {
                Log.Warning("Mismatched health state on copied pawn: " + savedHealthState + " != " + result.health.State + ";  Resetting value to match.");
                result.SetHealthState(savedHealthState);
            }

            // Clear all of the pawn caches.
            source.ClearCaches();

            return(result);
        }
Beispiel #11
0
        public AttackThingState(Thing mp)
        {
            //А применяется созданый здесь контейнер в GameUtils.ApplyState
            HostThingID = mp.thingIDNumber;
            StackCount  = mp.stackCount;
            Position    = new IntVec3S(mp.Position);
            HitPoints   = mp.HitPoints;
            var pawn = mp as Pawn;

            if (pawn != null)
            {
                //Loger.Log("Client AttackThingState " + pawn.health.State.ToString() + " thing=" + pawn.Label + " ID=" + pawn.thingIDNumber);
                DownState = (AttackThingState.PawnHealthState)(int) pawn.health.State;
            }
            else
            {
                DownState = PawnHealthState.Mobile;
            }
        }
 private void MakeUndowned()
 {
     if (!Downed)
     {
         Log.Error(string.Concat(pawn, " tried to do MakeUndowned when already undowned."));
         return;
     }
     healthState = PawnHealthState.Mobile;
     if (PawnUtility.ShouldSendNotificationAbout(pawn))
     {
         Messages.Message("MessageNoLongerDowned".Translate(pawn.LabelCap, pawn), pawn, MessageTypeDefOf.PositiveEvent);
     }
     if (pawn.Spawned && !pawn.InBed())
     {
         pawn.jobs.EndCurrentJob(JobCondition.Incompletable);
     }
     PortraitsCache.SetDirty(pawn);
     if (pawn.guest != null)
     {
         pawn.guest.Notify_PawnUndowned();
     }
 }
 private void MakeUndowned()
 {
     if (!this.Downed)
     {
         Log.Error(this.pawn + " tried to do MakeUndowned when already undowned.");
     }
     else
     {
         this.healthState = PawnHealthState.Mobile;
         if (PawnUtility.ShouldSendNotificationAbout(this.pawn))
         {
             Messages.Message("MessageNoLongerDowned".Translate(this.pawn.LabelCap), this.pawn, MessageTypeDefOf.PositiveEvent);
         }
         if (this.pawn.Spawned && !this.pawn.InBed())
         {
             this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true);
         }
         PortraitsCache.SetDirty(this.pawn);
         if (this.pawn.guest != null)
         {
             this.pawn.guest.Notify_PawnUndowned();
         }
     }
 }
 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));
         }
     }
 }
 public static void SetHealthState(this Pawn pawn, PawnHealthState state)
 {
     typeof(Pawn_HealthTracker).GetField("healthState", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(pawn, state);
 }
 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);
 }