protected override bool Satisfied(Pawn pawn)
        {
            MentalState mentalState = pawn.MentalState;

            if (mentalState != null)
            {
                return(stateClass.IsAssignableFrom(mentalState.GetType()));
            }
            return(false);
        }
예제 #2
0
 internal void ClearMentalStateDirect()
 {
     if (this.curStateInt != null)
     {
         this.curStateInt = null;
         if (this.pawn.Spawned)
         {
             this.pawn.Map.attackTargetsCache.UpdateTarget(this.pawn);
         }
     }
 }
예제 #3
0
 internal void ClearMentalStateDirect()
 {
     if (curStateInt != null)
     {
         curStateInt = null;
         QuestUtility.SendQuestTargetSignals(pawn.questTags, "ExitMentalState", pawn.Named("SUBJECT"));
         if (pawn.Spawned)
         {
             pawn.Map.attackTargetsCache.UpdateTarget(pawn);
         }
     }
 }
예제 #4
0
        public bool TryStartMentalState(MentalStateDef stateDef, string reason = null, bool forceWake = false, bool causedByMood = false, Pawn otherPawn = null, bool transitionSilently = false)
        {
            if ((!this.pawn.Spawned && !this.pawn.IsCaravanMember()) || this.CurStateDef == stateDef || this.pawn.Downed || (!forceWake && !this.pawn.Awake()))
            {
                return(false);
            }
            if (TutorSystem.TutorialMode && this.pawn.Faction == Faction.OfPlayer)
            {
                return(false);
            }
            if (!stateDef.Worker.StateCanOccur(this.pawn))
            {
                return(false);
            }
            MentalState mentalState = (MentalState)Activator.CreateInstance(stateDef.stateClass);

            mentalState.pawn         = this.pawn;
            mentalState.def          = stateDef;
            mentalState.causedByMood = causedByMood;
            if (otherPawn != null)
            {
                ((MentalState_SocialFighting)mentalState).otherPawn = otherPawn;
            }
            mentalState.PreStart();
            if (!transitionSilently)
            {
                if ((this.pawn.IsColonist || this.pawn.HostFaction == Faction.OfPlayer) && stateDef.tale != null)
                {
                    TaleRecorder.RecordTale(stateDef.tale, new object[]
                    {
                        this.pawn
                    });
                }
                if (stateDef.IsExtreme && this.pawn.IsPlayerControlledCaravanMember())
                {
                    Messages.Message("MessageCaravanMemberHasExtremeMentalBreak".Translate(), this.pawn.GetCaravan(), MessageTypeDefOf.ThreatSmall, true);
                }
                this.pawn.records.Increment(RecordDefOf.TimesInMentalState);
            }
            if (this.pawn.Drafted)
            {
                this.pawn.drafter.Drafted = false;
            }
            this.curStateInt = mentalState;
            if (this.pawn.needs.mood != null)
            {
                this.pawn.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty();
            }
            if (stateDef != null && stateDef.IsAggro && this.pawn.caller != null)
            {
                this.pawn.caller.Notify_InAggroMentalState();
            }
            if (this.curStateInt != null)
            {
                this.curStateInt.PostStart(reason);
            }
            if (this.pawn.CurJob != null)
            {
                this.pawn.jobs.StopAll(false);
            }
            if (this.pawn.Spawned)
            {
                this.pawn.Map.attackTargetsCache.UpdateTarget(this.pawn);
            }
            if (this.pawn.Spawned && forceWake && !this.pawn.Awake())
            {
                this.pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, true);
            }
            if (!transitionSilently && PawnUtility.ShouldSendNotificationAbout(this.pawn))
            {
                string text = mentalState.GetBeginLetterText();
                if (!text.NullOrEmpty())
                {
                    string label = (stateDef.beginLetterLabel ?? stateDef.LabelCap).CapitalizeFirst() + ": " + this.pawn.LabelShortCap;
                    if (!reason.NullOrEmpty())
                    {
                        text = text + "\n\n" + reason;
                    }
                    Find.LetterStack.ReceiveLetter(label, text, stateDef.beginLetterDef, this.pawn, null, null);
                }
            }
            return(true);
        }
예제 #5
0
        protected override bool Satisfied(Pawn pawn)
        {
            MentalState mentalState = pawn.MentalState;

            return(mentalState != null && this.stateClass.IsAssignableFrom(mentalState.GetType()));
        }