From ee7e119deadd9d1f258c56893c4e6dc621c507c1 Mon Sep 17 00:00:00 2001 From: desuwatch Date: Sat, 18 Jan 2025 11:25:45 +0300 Subject: [PATCH] Fixing reverting issues --- .../Nutrition/EntitySystems/HungerSystem.cs | 45 +++++++++++++++---- Content.Shared/_CorvaxNext/NextVars.cs | 30 +++++++++++++ .../Standing/SharedLayingDownSystem.cs | 3 +- 3 files changed, 68 insertions(+), 10 deletions(-) diff --git a/Content.Shared/Nutrition/EntitySystems/HungerSystem.cs b/Content.Shared/Nutrition/EntitySystems/HungerSystem.cs index 6a6dd7af782..b75a1152cf6 100644 --- a/Content.Shared/Nutrition/EntitySystems/HungerSystem.cs +++ b/Content.Shared/Nutrition/EntitySystems/HungerSystem.cs @@ -72,6 +72,16 @@ private void OnRejuvenate(EntityUid uid, HungerComponent component, RejuvenateEv SetHunger(uid, component.Thresholds[HungerThreshold.Okay], component); } + /// + /// Gets the current hunger value of the given . + /// + public float GetHunger(HungerComponent component) + { + var dt = _timing.CurTime - component.LastAuthoritativeHungerChangeTime; + var value = component.LastAuthoritativeHungerValue - (float)dt.TotalSeconds * component.ActualDecayRate; + return ClampHungerWithinThresholds(component, value); + } + /// /// Adds to the current hunger of an entity by the specified value /// @@ -82,7 +92,7 @@ public void ModifyHunger(EntityUid uid, float amount, HungerComponent? component { if (!Resolve(uid, ref component)) return; - SetHunger(uid, component.CurrentHunger + amount, component); + SetHunger(uid, GetHunger(component) + amount, component); } /// @@ -95,11 +105,23 @@ public void SetHunger(EntityUid uid, float amount, HungerComponent? component = { if (!Resolve(uid, ref component)) return; - component.CurrentHunger = Math.Clamp(amount, - component.Thresholds[HungerThreshold.Dead], - component.Thresholds[HungerThreshold.Overfed]); + + SetAuthoritativeHungerValue((uid, component), amount); UpdateCurrentThreshold(uid, component); - Dirty(uid, component); + } + + /// + /// Sets and + /// , and dirties this entity. This "resets" the + /// starting point for 's calculation. + /// + /// The entity whose hunger will be set. + /// The value to set the entity's hunger to. + private void SetAuthoritativeHungerValue(Entity entity, float value) + { + entity.Comp.LastAuthoritativeHungerChangeTime = _timing.CurTime; + entity.Comp.LastAuthoritativeHungerValue = ClampHungerWithinThresholds(entity.Comp, value); + DirtyField(entity.Owner, entity.Comp, nameof(HungerComponent.LastAuthoritativeHungerChangeTime)); } private void UpdateCurrentThreshold(EntityUid uid, HungerComponent? component = null) @@ -167,7 +189,7 @@ component.StarvationDamage is { } damage && /// public HungerThreshold GetHungerThreshold(HungerComponent component, float? food = null) { - food ??= component.CurrentHunger; + food ??= GetHunger(component); var result = HungerThreshold.Dead; var value = component.Thresholds[HungerThreshold.Overfed]; foreach (var threshold in component.Thresholds) @@ -229,6 +251,13 @@ public bool TryGetStatusIconPrototype(HungerComponent component, [NotNullWhen(tr return prototype != null; } + private static float ClampHungerWithinThresholds(HungerComponent component, float hungerValue) + { + return Math.Clamp(hungerValue, + component.Thresholds[HungerThreshold.Dead], + component.Thresholds[HungerThreshold.Overfed]); + } + public override void Update(float frameTime) { base.Update(frameTime); @@ -236,9 +265,9 @@ public override void Update(float frameTime) var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var hunger)) { - if (_timing.CurTime < hunger.NextUpdateTime) + if (_timing.CurTime < hunger.NextThresholdUpdateTime) continue; - hunger.NextUpdateTime = _timing.CurTime + hunger.UpdateRate; + hunger.NextThresholdUpdateTime = _timing.CurTime + hunger.NextThresholdUpdateTime; ModifyHunger(uid, -hunger.ActualDecayRate, hunger); DoContinuousHungerEffects(uid, hunger); diff --git a/Content.Shared/_CorvaxNext/NextVars.cs b/Content.Shared/_CorvaxNext/NextVars.cs index 5d232025ae7..69fde0ef6cc 100644 --- a/Content.Shared/_CorvaxNext/NextVars.cs +++ b/Content.Shared/_CorvaxNext/NextVars.cs @@ -9,9 +9,39 @@ namespace Content.Shared._CorvaxNext.NextVars; // ReSharper disable once InconsistentNaming public sealed class NextVars { + /** + * Auto cryo sleep + */ + + public static readonly CVarDef AutoCryoSleepEnabled = + CVarDef.Create("auto_cryo_sleep.enabled", true, CVar.SERVER); + + public static readonly CVarDef AutoCryoSleepTime = + CVarDef.Create("auto_cryo_sleep.time", 1200, CVar.SERVER); + + public static readonly CVarDef AutoCryoSleepUpdateTime = + CVarDef.Create("auto_cryo_sleep.update_time", 120, CVar.SERVER); + /// /// Offer item. /// public static readonly CVarDef OfferModeIndicatorsPointShow = CVarDef.Create("hud.offer_mode_indicators_point_show", true, CVar.ARCHIVE | CVar.CLIENTONLY); + + /* + * _CorvaxNext Bind Standing and Laying System + */ + + public static readonly CVarDef AutoGetUp = + CVarDef.Create("laying.auto_get_up", true, CVar.CLIENT | CVar.ARCHIVE | CVar.REPLICATED); + + /// + /// When true, entities that fall to the ground will be able to crawl under tables and + /// plastic flaps, allowing them to take cover from gunshots. + /// + public static readonly CVarDef CrawlUnderTables = + CVarDef.Create("laying.crawlundertables", false, CVar.REPLICATED); + + // public static readonly CVarDef OfferModeIndicatorsPointShow = + // CVarDef.Create("hud.offer_mode_indicators_point_show", true, CVar.ARCHIVE | CVar.CLIENTONLY); } diff --git a/Content.Shared/_CorvaxNext/Standing/SharedLayingDownSystem.cs b/Content.Shared/_CorvaxNext/Standing/SharedLayingDownSystem.cs index 2a86d89bac3..843ee74b47a 100644 --- a/Content.Shared/_CorvaxNext/Standing/SharedLayingDownSystem.cs +++ b/Content.Shared/_CorvaxNext/Standing/SharedLayingDownSystem.cs @@ -1,6 +1,5 @@ using System.Diagnostics.CodeAnalysis; using Content.Shared._CorvaxNext.NextVars; -using Content.Shared._CorvaxNext.Targeting; using Content.Shared.Body.Components; using Content.Shared.Buckle; using Content.Shared.Buckle.Components; @@ -322,7 +321,7 @@ standingState.CurrentState is not StandingState.Lying || obj.Value, uid, PopupType.MediumCaution); - _damageable.TryChangeDamage(uid, new DamageSpecifier() { DamageDict = { { "Blunt", 5 } } }, ignoreResistances: true, canEvade: true, targetPart: TargetBodyPart.Head); + _damageable.TryChangeDamage(uid, new DamageSpecifier() { DamageDict = { { "Blunt", 5 } } }, ignoreResistances: true); _stun.TryStun(uid, TimeSpan.FromSeconds(2), true); _audioSystem.PlayPredicted(_bonkSound, uid, obj.Value); return false;