public override void InitializeStates(out BaseState default_state) { default_state = infected; base.serializable = true; infected.Enter("Infect", delegate(StatesInstance smi) { smi.Infect(); }).DoNotification((StatesInstance smi) => smi.master.notification).Update("UpdateProgress", delegate(StatesInstance smi, float dt) { smi.UpdateProgress(dt); }, UpdateRate.SIM_200ms, false) .ToggleStatusItem((StatesInstance smi) => smi.master.GetStatusItem(), (StatesInstance smi) => smi) .ParamTransition(percentRecovered, cured, GameStateMachine <States, StatesInstance, SicknessInstance, object> .IsGTOne) .ParamTransition(percentDied, fatality_pre, GameStateMachine <States, StatesInstance, SicknessInstance, object> .IsGTOne); cured.Enter("Cure", delegate(StatesInstance smi) { smi.master.Cure(); }); fatality_pre.Update("DeathByDisease", delegate(StatesInstance smi, float dt) { DeathMonitor.Instance sMI = smi.master.gameObject.GetSMI <DeathMonitor.Instance>(); if (sMI != null) { sMI.Kill(Db.Get().Deaths.FatalDisease); smi.GoTo(fatality); } }, UpdateRate.SIM_200ms, false); fatality.DoNothing(); }
private void OnNewDay(object data) { if (lifeCyclesDone) { return; } if (currentStage == null || currentStage.ID == "") { DebugUtil.LogWarningArgs($"[DuplicantLifeExpectancy]: Life Stage for Duplicant {gameObject.GetProperName()} was null during OnNewDay callback. Should have already been set."); currentStage = new LifeStage(LifeStagePreset.FirstState); } float currCycle = GameClock.Instance.GetCycle(); if (!currentStage.Started) { if (currentStage.BeginsOn >= currCycle) { Effect e = currentStage.GetEffect(); EffectInstance instance = effects.Add(e, true); currentStage.Started = true; } } else { if (currCycle >= currentStage.EndsAfter) { string nextStage = currentStage.NextStage; if (nextStage != "") { currentStage = new LifeStage(currentStage.NextStage); if (currentStage.BeginsOn == currCycle) { effects.Add(currentStage.GetEffect(), true); currentStage.Started = true; } } else { if (currentStage.IsDying()) { DeathMonitor.Instance smi = gameObject.GetSMI <DeathMonitor.Instance>(); if (smi != null) { Death OldAge = new Death("OldAge", Db.Get().Deaths, "Old Age", "{Target} has died of old age", "dead_on_back", "dead_on_back"); smi.Kill(OldAge); } } else { //There is no next stage. The current stage will be re-applied Effect e = currentStage.GetEffect(); effects.Add(e, true); currentStage.BeginsOn = currCycle; } } } } }
private void CheckDrowning(object data = null) { if (drowned) { return; } int cell = Grid.PosToCell(gameObject.transform.GetPosition()); if (!IsCellSafe(cell)) { if (!drowning) { drowning = true; Trigger((int)GameHashes.Drowning); GetComponent <KPrefabID>().AddTag(GameTags.Creatures.Drowning, false); } if (timeToDrown <= 0f && canDrownToDeath) { DeathMonitor.Instance smi = this.GetSMI <DeathMonitor.Instance>(); if (smi != null) { smi.Kill(Db.Get().Deaths.Drowned); } Trigger((int)GameHashes.Drowned); drowned = true; } } else if (drowning) { drowning = false; GetComponent <KPrefabID>().RemoveTag(GameTags.Creatures.Drowning); Trigger((int)GameHashes.EnteredBreathableArea); } drowningStatusGuid = selectable.ToggleStatusItem(NeedLiquid, drowningStatusGuid, drowning, this); if (effects != null) { if (drowning) { effects.Add(drowningEffect, false); return; } else { effects.Remove(drowningEffect); } } }
private void CheckDryingOut() { if (this.suffocated || this.GetComponent <KPrefabID>().HasTag(GameTags.Trapped)) { return; } if (!IsInWater(Grid.PosToCell(this.gameObject.transform.GetPosition()))) { if (!this.suffocating) { this.suffocating = true; this.Trigger((int)GameHashes.DryingOut); } if ((double)this.timeToSuffocate > 0.0) { return; } DeathMonitor.Instance smi = this.GetSMI <DeathMonitor.Instance>(); if (smi != null) { smi.Kill(Db.Get().Deaths.Suffocation); } this.Trigger((int)GameHashes.DriedOut); this.suffocated = true; } else { if (!this.suffocating) { return; } this.suffocating = false; this.Trigger((int)GameHashes.EnteredWetArea, (object)null); } }