Skip to content

Commit 1ac76df

Browse files
committed
Fixing reverting issues
1 parent b160f3a commit 1ac76df

File tree

3 files changed

+68
-10
lines changed

3 files changed

+68
-10
lines changed

Content.Shared/Nutrition/EntitySystems/HungerSystem.cs

+37-8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ private void OnRejuvenate(EntityUid uid, HungerComponent component, RejuvenateEv
7272
SetHunger(uid, component.Thresholds[HungerThreshold.Okay], component);
7373
}
7474

75+
/// <summary>
76+
/// Gets the current hunger value of the given <see cref="HungerComponent"/>.
77+
/// </summary>
78+
public float GetHunger(HungerComponent component)
79+
{
80+
var dt = _timing.CurTime - component.LastAuthoritativeHungerChangeTime;
81+
var value = component.LastAuthoritativeHungerValue - (float)dt.TotalSeconds * component.ActualDecayRate;
82+
return ClampHungerWithinThresholds(component, value);
83+
}
84+
7585
/// <summary>
7686
/// Adds to the current hunger of an entity by the specified value
7787
/// </summary>
@@ -82,7 +92,7 @@ public void ModifyHunger(EntityUid uid, float amount, HungerComponent? component
8292
{
8393
if (!Resolve(uid, ref component))
8494
return;
85-
SetHunger(uid, component.CurrentHunger + amount, component);
95+
SetHunger(uid, GetHunger(component) + amount, component);
8696
}
8797

8898
/// <summary>
@@ -95,11 +105,23 @@ public void SetHunger(EntityUid uid, float amount, HungerComponent? component =
95105
{
96106
if (!Resolve(uid, ref component))
97107
return;
98-
component.CurrentHunger = Math.Clamp(amount,
99-
component.Thresholds[HungerThreshold.Dead],
100-
component.Thresholds[HungerThreshold.Overfed]);
108+
109+
SetAuthoritativeHungerValue((uid, component), amount);
101110
UpdateCurrentThreshold(uid, component);
102-
Dirty(uid, component);
111+
}
112+
113+
/// <summary>
114+
/// Sets <see cref="HungerComponent.LastAuthoritativeHungerValue"/> and
115+
/// <see cref="HungerComponent.LastAuthoritativeHungerChangeTime"/>, and dirties this entity. This "resets" the
116+
/// starting point for <see cref="GetHunger"/>'s calculation.
117+
/// </summary>
118+
/// <param name="entity">The entity whose hunger will be set.</param>
119+
/// <param name="value">The value to set the entity's hunger to.</param>
120+
private void SetAuthoritativeHungerValue(Entity<HungerComponent> entity, float value)
121+
{
122+
entity.Comp.LastAuthoritativeHungerChangeTime = _timing.CurTime;
123+
entity.Comp.LastAuthoritativeHungerValue = ClampHungerWithinThresholds(entity.Comp, value);
124+
DirtyField(entity.Owner, entity.Comp, nameof(HungerComponent.LastAuthoritativeHungerChangeTime));
103125
}
104126

105127
private void UpdateCurrentThreshold(EntityUid uid, HungerComponent? component = null)
@@ -167,7 +189,7 @@ component.StarvationDamage is { } damage &&
167189
/// <returns></returns>
168190
public HungerThreshold GetHungerThreshold(HungerComponent component, float? food = null)
169191
{
170-
food ??= component.CurrentHunger;
192+
food ??= GetHunger(component);
171193
var result = HungerThreshold.Dead;
172194
var value = component.Thresholds[HungerThreshold.Overfed];
173195
foreach (var threshold in component.Thresholds)
@@ -229,16 +251,23 @@ public bool TryGetStatusIconPrototype(HungerComponent component, [NotNullWhen(tr
229251
return prototype != null;
230252
}
231253

254+
private static float ClampHungerWithinThresholds(HungerComponent component, float hungerValue)
255+
{
256+
return Math.Clamp(hungerValue,
257+
component.Thresholds[HungerThreshold.Dead],
258+
component.Thresholds[HungerThreshold.Overfed]);
259+
}
260+
232261
public override void Update(float frameTime)
233262
{
234263
base.Update(frameTime);
235264

236265
var query = EntityQueryEnumerator<HungerComponent>();
237266
while (query.MoveNext(out var uid, out var hunger))
238267
{
239-
if (_timing.CurTime < hunger.NextUpdateTime)
268+
if (_timing.CurTime < hunger.NextThresholdUpdateTime)
240269
continue;
241-
hunger.NextUpdateTime = _timing.CurTime + hunger.UpdateRate;
270+
hunger.NextThresholdUpdateTime = _timing.CurTime + hunger.NextThresholdUpdateTime;
242271

243272
ModifyHunger(uid, -hunger.ActualDecayRate, hunger);
244273
DoContinuousHungerEffects(uid, hunger);

Content.Shared/_CorvaxNext/NextVars.cs

+30
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,39 @@ namespace Content.Shared._CorvaxNext.NextVars;
99
// ReSharper disable once InconsistentNaming
1010
public sealed class NextVars
1111
{
12+
/**
13+
* Auto cryo sleep
14+
*/
15+
16+
public static readonly CVarDef<bool> AutoCryoSleepEnabled =
17+
CVarDef.Create("auto_cryo_sleep.enabled", true, CVar.SERVER);
18+
19+
public static readonly CVarDef<int> AutoCryoSleepTime =
20+
CVarDef.Create("auto_cryo_sleep.time", 1200, CVar.SERVER);
21+
22+
public static readonly CVarDef<int> AutoCryoSleepUpdateTime =
23+
CVarDef.Create("auto_cryo_sleep.update_time", 120, CVar.SERVER);
24+
1225
/// <summary>
1326
/// Offer item.
1427
/// </summary>
1528
public static readonly CVarDef<bool> OfferModeIndicatorsPointShow =
1629
CVarDef.Create("hud.offer_mode_indicators_point_show", true, CVar.ARCHIVE | CVar.CLIENTONLY);
30+
31+
/*
32+
* _CorvaxNext Bind Standing and Laying System
33+
*/
34+
35+
public static readonly CVarDef<bool> AutoGetUp =
36+
CVarDef.Create("laying.auto_get_up", true, CVar.CLIENT | CVar.ARCHIVE | CVar.REPLICATED);
37+
38+
/// <summary>
39+
/// When true, entities that fall to the ground will be able to crawl under tables and
40+
/// plastic flaps, allowing them to take cover from gunshots.
41+
/// </summary>
42+
public static readonly CVarDef<bool> CrawlUnderTables =
43+
CVarDef.Create("laying.crawlundertables", false, CVar.REPLICATED);
44+
45+
// public static readonly CVarDef<bool> OfferModeIndicatorsPointShow =
46+
// CVarDef.Create("hud.offer_mode_indicators_point_show", true, CVar.ARCHIVE | CVar.CLIENTONLY);
1747
}

Content.Shared/_CorvaxNext/Standing/SharedLayingDownSystem.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Diagnostics.CodeAnalysis;
22
using Content.Shared._CorvaxNext.NextVars;
3-
using Content.Shared._CorvaxNext.Targeting;
43
using Content.Shared.Body.Components;
54
using Content.Shared.Buckle;
65
using Content.Shared.Buckle.Components;
@@ -322,7 +321,7 @@ standingState.CurrentState is not StandingState.Lying ||
322321
obj.Value,
323322
uid,
324323
PopupType.MediumCaution);
325-
_damageable.TryChangeDamage(uid, new DamageSpecifier() { DamageDict = { { "Blunt", 5 } } }, ignoreResistances: true, canEvade: true, targetPart: TargetBodyPart.Head);
324+
_damageable.TryChangeDamage(uid, new DamageSpecifier() { DamageDict = { { "Blunt", 5 } } }, ignoreResistances: true);
326325
_stun.TryStun(uid, TimeSpan.FromSeconds(2), true);
327326
_audioSystem.PlayPredicted(_bonkSound, uid, obj.Value);
328327
return false;

0 commit comments

Comments
 (0)