Esempio n. 1
0
        public virtual void Tick()
        {
            ageTicks++;
            if (def.hediffGivers != null && pawn.IsHashIntervalTick(60))
            {
                for (int i = 0; i < def.hediffGivers.Count; i++)
                {
                    def.hediffGivers[i].OnIntervalPassed(pawn, this);
                }
            }
            if (Visible && !visible)
            {
                visible = true;
                if (def.taleOnVisible != null)
                {
                    TaleRecorder.RecordTale(def.taleOnVisible, pawn, def);
                }
            }
            HediffStage curStage = CurStage;

            if (curStage == null)
            {
                return;
            }
            if (curStage.hediffGivers != null && pawn.IsHashIntervalTick(60))
            {
                for (int j = 0; j < curStage.hediffGivers.Count; j++)
                {
                    curStage.hediffGivers[j].OnIntervalPassed(pawn, this);
                }
            }
            if (curStage.mentalStateGivers != null && pawn.IsHashIntervalTick(60) && !pawn.InMentalState)
            {
                for (int k = 0; k < curStage.mentalStateGivers.Count; k++)
                {
                    MentalStateGiver mentalStateGiver = curStage.mentalStateGivers[k];
                    if (Rand.MTBEventOccurs(mentalStateGiver.mtbDays, 60000f, 60f))
                    {
                        pawn.mindState.mentalStateHandler.TryStartMentalState(mentalStateGiver.mentalState, "MentalStateReason_Hediff".Translate(Label));
                    }
                }
            }
            if (curStage.mentalBreakMtbDays > 0f && pawn.IsHashIntervalTick(60) && !pawn.InMentalState && !pawn.Downed && Rand.MTBEventOccurs(curStage.mentalBreakMtbDays, 60000f, 60f))
            {
                TryDoRandomMentalBreak();
            }
            if (curStage.vomitMtbDays > 0f && pawn.IsHashIntervalTick(600) && Rand.MTBEventOccurs(curStage.vomitMtbDays, 60000f, 600f) && pawn.Spawned && pawn.Awake() && pawn.RaceProps.IsFlesh)
            {
                pawn.jobs.StartJob(JobMaker.MakeJob(JobDefOf.Vomit), JobCondition.InterruptForced, null, resumeCurJobAfterwards: true);
            }
            if (curStage.forgetMemoryThoughtMtbDays > 0f && pawn.needs != null && pawn.needs.mood != null && pawn.IsHashIntervalTick(400) && Rand.MTBEventOccurs(curStage.forgetMemoryThoughtMtbDays, 60000f, 400f) && pawn.needs.mood.thoughts.memories.Memories.TryRandomElement(out var result))
            {
                pawn.needs.mood.thoughts.memories.RemoveMemory(result);
            }
            if (!recordedTale && curStage.tale != null)
            {
                TaleRecorder.RecordTale(curStage.tale, pawn);
                recordedTale = true;
            }
            if (curStage.destroyPart && Part != null && Part != pawn.RaceProps.body.corePart)
            {
                pawn.health.AddHediff(HediffDefOf.MissingBodyPart, Part);
            }
            if (curStage.deathMtbDays > 0f && pawn.IsHashIntervalTick(200) && Rand.MTBEventOccurs(curStage.deathMtbDays, 60000f, 200f))
            {
                bool    num     = PawnUtility.ShouldSendNotificationAbout(pawn);
                Caravan caravan = pawn.GetCaravan();
                pawn.Kill(null, null);
                if (num)
                {
                    pawn.health.NotifyPlayerOfKilled(null, this, caravan);
                }
            }
        }
Esempio n. 2
0
        public virtual void Tick()
        {
            this.ageTicks++;
            if (this.def.hediffGivers != null && this.pawn.IsHashIntervalTick(60))
            {
                for (int i = 0; i < this.def.hediffGivers.Count; i++)
                {
                    this.def.hediffGivers[i].OnIntervalPassed(this.pawn, this);
                }
            }
            if (this.Visible && !this.visible)
            {
                this.visible = true;
                if (this.def.taleOnVisible != null)
                {
                    TaleRecorder.RecordTale(this.def.taleOnVisible, new object[]
                    {
                        this.pawn,
                        this.def
                    });
                }
            }
            HediffStage curStage = this.CurStage;

            if (curStage != null)
            {
                if (curStage.hediffGivers != null && this.pawn.IsHashIntervalTick(60))
                {
                    for (int j = 0; j < curStage.hediffGivers.Count; j++)
                    {
                        curStage.hediffGivers[j].OnIntervalPassed(this.pawn, this);
                    }
                }
                if (curStage.mentalStateGivers != null && this.pawn.IsHashIntervalTick(60) && !this.pawn.InMentalState)
                {
                    for (int k = 0; k < curStage.mentalStateGivers.Count; k++)
                    {
                        MentalStateGiver mentalStateGiver = curStage.mentalStateGivers[k];
                        if (Rand.MTBEventOccurs(mentalStateGiver.mtbDays, 60000f, 60f))
                        {
                            this.pawn.mindState.mentalStateHandler.TryStartMentalState(mentalStateGiver.mentalState, "MentalStateReason_Hediff".Translate(this.Label), false, false, null, false);
                        }
                    }
                }
                MentalBreakDef mentalBreakDef;
                if (curStage.mentalBreakMtbDays > 0f && this.pawn.IsHashIntervalTick(60) && !this.pawn.InMentalState && Rand.MTBEventOccurs(curStage.mentalBreakMtbDays, 60000f, 60f) && (from x in DefDatabase <MentalBreakDef> .AllDefsListForReading
                                                                                                                                                                                          where x.Worker.BreakCanOccur(this.pawn)
                                                                                                                                                                                          select x).TryRandomElementByWeight((MentalBreakDef x) => x.Worker.CommonalityFor(this.pawn), out mentalBreakDef))
                {
                    mentalBreakDef.Worker.TryStart(this.pawn, "MentalStateReason_Hediff".Translate(this.Label), false);
                }
                if (curStage.vomitMtbDays > 0f && this.pawn.IsHashIntervalTick(600) && Rand.MTBEventOccurs(curStage.vomitMtbDays, 60000f, 600f) && this.pawn.Spawned && this.pawn.Awake())
                {
                    this.pawn.jobs.StartJob(new Job(JobDefOf.Vomit), JobCondition.InterruptForced, null, true, true, null, null, false);
                }
                Thought_Memory th;
                if (curStage.forgetMemoryThoughtMtbDays > 0f && this.pawn.needs.mood != null && this.pawn.IsHashIntervalTick(400) && Rand.MTBEventOccurs(curStage.forgetMemoryThoughtMtbDays, 60000f, 400f) && this.pawn.needs.mood.thoughts.memories.Memories.TryRandomElement(out th))
                {
                    this.pawn.needs.mood.thoughts.memories.RemoveMemory(th);
                }
                if (!this.recordedTale && curStage.tale != null)
                {
                    TaleRecorder.RecordTale(curStage.tale, new object[]
                    {
                        this.pawn
                    });
                    this.recordedTale = true;
                }
                if (curStage.destroyPart && this.Part != null && this.Part != this.pawn.RaceProps.body.corePart)
                {
                    this.pawn.health.AddHediff(HediffDefOf.MissingBodyPart, this.Part, null, null);
                }
                if (curStage.deathMtbDays > 0f && this.pawn.IsHashIntervalTick(200) && Rand.MTBEventOccurs(curStage.deathMtbDays, 60000f, 200f))
                {
                    bool    flag    = PawnUtility.ShouldSendNotificationAbout(this.pawn);
                    Caravan caravan = this.pawn.GetCaravan();
                    this.pawn.Kill(null, null);
                    if (flag)
                    {
                        this.pawn.health.NotifyPlayerOfKilled(null, this, caravan);
                    }
                    return;
                }
            }
        }