/// <summary> /// Only runs the rot handlers on food if it has a minimum threshold mass to rot. /// Prevents tiny microgram chunks caused by rounding errors from generating unwanted /// polluted dirt. /// </summary> private static void ReplaceRotHandler(Rottable sm) { var spoiledActions = sm.Spoiled.enterActions; if (spoiledActions != null) { var targets = new List <RotCallback>(spoiledActions.Count); foreach (var action in spoiledActions) { if (action.callback is RotCallback originalCode) { targets.Add(originalCode); } } spoiledActions.Clear(); sm.Spoiled.Enter((smi) => { var go = smi.master.gameObject; var rotted = go.GetComponentSafe <PrimaryElement>(); if (rotted == null || rotted.Mass > MASS_TO_ROT) { foreach (var action in targets) { action.Invoke(smi); } } else if (go != null) { Util.KDestroyGameObject(go); } }); } }
public void UpdateDecomposition(float dt) { // todo: протестить при наличии нескольких трупов // скорость гниения в зависимости от температуры и окружения float rate = Mathf.InverseLerp(FOOD.DEFAULT_PRESERVE_TEMPERATURE, FOOD.DEFAULT_ROT_TEMPERATURE, temperature) + Mathf.InverseLerp(FOOD.HIGH_PRESERVE_TEMPERATURE, FOOD.HIGH_ROT_TEMPERATURE, temperature); switch (Rottable.AtmosphereQuality(gameObject)) { case Rottable.RotAtmosphereQuality.Contaminating: rate += 1; break; case Rottable.RotAtmosphereQuality.Normal: break; case Rottable.RotAtmosphereQuality.Sterilizing: rate *= 0.5f; break; } master.decomposition += (rate * dt); }
/// <summary> /// Applied after InitializeStates runs. /// </summary> internal static void Postfix(Rottable __instance) { ReplaceRotHandler(__instance); }
public void Render1000ms(float dt) { Rottable.SetStatusItems(GetComponent <KSelectable>(), Rottable.IsRefrigerated(base.gameObject), Rottable.AtmosphereQuality(base.gameObject)); }