Files
OldThink/Content.Shared/Nutrition/EntitySystems/ThirstSystem.cs
Jabak b385386ab4 Upstream gp (#149)
* fix borg (#719)

* Automatic changelog update

* Переводы снаряжения и прочей мелочи в стартовом меню (#720)

* Сумки, мешки и прочее

* Перевод снаряжения

* перевод черт персонажа

* Добавлено ничего

* Automatic changelog update

* Фикс отображения потери мастера для импланта подчинения (#721)

* фикс отображения

* brain damage is real

* я блять запустил райдер ради рефактора одного ифа

* а лучше даже так

* Automatic changelog update

* add coderabbitai config (#722)

* fix (#723)

* Шприц теперь является оружием массового поражения (#724)

* Automatic changelog update

* Пиздец (#725)

Я на это потратил 2 недели

* Automatic changelog update

* Honk FM (#136) (#726)

* Fix Cosmic Temperance и новые песенки в jukebox

* Новая музыка в jucebox x2

Co-authored-by: Vorge7 <vorge228@gmail.com>

* Automatic changelog update

* Флаф (fluff) мне (big_zi_348) (#727)

* Заработал

* brain damage

* fuck (#729)

* Automatic changelog update

* FUCKERS (#732)

* Удаление ненужных суффиксов (#731)

* Перевод захардкукоженной строки (#728)

* Пластырь поможет

* очапятка

* Перевод ревенанта

* Карповый перекат

* Create shakeable-component.ftl

* Криогеника

* Хранилища скафандров

* Update autotranslate-14.ftl

* Update Cyborgs.xml

* Комоды

* Кредиты

* Удалил дубликат

* Информация

* Пластырь миму и клоуну

* Переводы всего

* Перевод аплинка

* Удалил ненужные суффиксы

* Revert "Удалил ненужные суффиксы"

This reverts commit d82f05f30c37ec2c11e5736b91239fe9dd1a4d17.

* Удаление ненужных суффиксов

* Перевод реагентовых слизней

* Перевод аномалий

* Перевод маяков

* Перевод различной мелочи

* Automatic changelog update

* Переводы и правки Гайдов (#730)

* Automatic changelog update

* aaaaa (#733)

* Правка локализации (#737)

* Update ThirstSystem.cs (#736)

* AccessConfiguratorForBorgs (#735)

* Automatic changelog update

* Починил бесконечную сварку (#734)

* Automatic changelog update

* ShowManifestFeature (#738)

* Automatic changelog update

* I LOVE OPENSOURCE

* Изменение размеров милишек (#739)

* Фикс размеров

* Заготовку биты тоже

* Правка

* Automatic changelog update

* Время после взрыва нюки (#740)

* More Fun

* Автоформатирование

* Подкрутка

* Automatic changelog update

* Скальпель в армейские ботинки (#741)

* Automatic changelog update

* DoHeavyAttack stamina check (#742)

* Automatic changelog update

* aaaaaaaaaaaaaaaaaaaaaaaaaaaaa (#743)

* fix retarded code (#744)

* Automatic changelog update

---------

Co-authored-by: RavmorganButOnCocaine <valtos@nextmail.ru>
Co-authored-by: BIGZi0348 <118811750+BIGZi0348@users.noreply.github.com>
Co-authored-by: ThereDrD <88589686+ThereDrD0@users.noreply.github.com>
Co-authored-by: Vorge7 <vorge228@gmail.com>
Co-authored-by: Valtos <valtos@spaces.ru>
Co-authored-by: haiwwkes <49613070+rhailrake@users.noreply.github.com>
2024-10-24 21:36:52 +03:00

237 lines
8.8 KiB
C#

using Content.Shared.Alert;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Systems;
using Content.Shared.Nutrition.Components;
using Content.Shared.Rejuvenate;
using Content.Shared.StatusIcon;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Content.Shared._White.Mood;
using Robust.Shared.Utility;
namespace Content.Shared.Nutrition.EntitySystems;
[UsedImplicitly]
public sealed class ThirstSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
[Dependency] private readonly SharedJetpackSystem _jetpack = default!;
[ValidatePrototypeId<StatusIconPrototype>]
private const string ThirstIconOverhydratedId = "ThirstIconOverhydrated";
[ValidatePrototypeId<StatusIconPrototype>]
private const string ThirstIconThirstyId = "ThirstIconThirsty";
[ValidatePrototypeId<StatusIconPrototype>]
private const string ThirstIconParchedId = "ThirstIconParched";
private StatusIconPrototype? _thirstIconOverhydrated = null;
private StatusIconPrototype? _thirstIconThirsty = null;
private StatusIconPrototype? _thirstIconParched = null;
public override void Initialize()
{
base.Initialize();
DebugTools.Assert(_prototype.TryIndex(ThirstIconOverhydratedId, out _thirstIconOverhydrated) &&
_prototype.TryIndex(ThirstIconThirstyId, out _thirstIconThirsty) &&
_prototype.TryIndex(ThirstIconParchedId, out _thirstIconParched));
SubscribeLocalEvent<ThirstComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
SubscribeLocalEvent<ThirstComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<ThirstComponent, RejuvenateEvent>(OnRejuvenate);
}
private void OnMapInit(EntityUid uid, ThirstComponent component, MapInitEvent args)
{
// Do not change behavior unless starting value is explicitly defined
if (component.CurrentThirst < 0)
{
component.CurrentThirst = _random.Next(
(int) component.ThirstThresholds[ThirstThreshold.Thirsty] + 10,
(int) component.ThirstThresholds[ThirstThreshold.Okay] - 1);
}
component.NextUpdateTime = _timing.CurTime;
component.CurrentThirstThreshold = GetThirstThreshold(component, component.CurrentThirst);
component.LastThirstThreshold = ThirstThreshold.Okay; // TODO: Potentially change this -> Used Okay because no effects.
// TODO: Check all thresholds make sense and throw if they don't.
UpdateEffects(uid, component);
TryComp(uid, out MovementSpeedModifierComponent? moveMod);
_movement.RefreshMovementSpeedModifiers(uid, moveMod);
}
private void OnRefreshMovespeed(EntityUid uid, ThirstComponent component, RefreshMovementSpeedModifiersEvent args)
{
// TODO: This should really be taken care of somewhere else
if (_jetpack.IsUserFlying(uid))
return;
var mod = component.CurrentThirstThreshold <= ThirstThreshold.Parched ? 0.75f : 1.0f;
args.ModifySpeed(mod, mod);
}
private void OnRejuvenate(EntityUid uid, ThirstComponent component, RejuvenateEvent args)
{
SetThirst(uid, component, component.ThirstThresholds[ThirstThreshold.Okay]);
}
private ThirstThreshold GetThirstThreshold(ThirstComponent component, float amount)
{
var result = ThirstThreshold.Dead;
var value = component.ThirstThresholds[ThirstThreshold.OverHydrated];
foreach (var threshold in component.ThirstThresholds)
{
if (threshold.Value <= value && threshold.Value >= amount)
{
result = threshold.Key;
value = threshold.Value;
}
}
return result;
}
public void ModifyThirst(EntityUid uid, ThirstComponent component, float amount)
{
SetThirst(uid, component, component.CurrentThirst + amount);
}
public void SetThirst(EntityUid uid, ThirstComponent component, float amount)
{
component.CurrentThirst = Math.Clamp(amount,
component.ThirstThresholds[ThirstThreshold.Dead],
component.ThirstThresholds[ThirstThreshold.OverHydrated]
);
Dirty(uid, component);
}
private bool IsMovementThreshold(ThirstThreshold threshold)
{
switch (threshold)
{
case ThirstThreshold.Dead:
case ThirstThreshold.Parched:
return true;
case ThirstThreshold.Thirsty:
case ThirstThreshold.Okay:
case ThirstThreshold.OverHydrated:
return false;
default:
throw new ArgumentOutOfRangeException(nameof(threshold), threshold, null);
}
}
public bool TryGetStatusIconPrototype(ThirstComponent component, out StatusIconPrototype? prototype)
{
switch (component.CurrentThirstThreshold)
{
case ThirstThreshold.OverHydrated:
prototype = _thirstIconOverhydrated;
return true;
case ThirstThreshold.Thirsty:
prototype = _thirstIconThirsty;
return true;
case ThirstThreshold.Parched:
prototype = _thirstIconParched;
return true;
default:
prototype = null;
return false;
}
}
private void UpdateEffects(EntityUid uid, ThirstComponent component)
{
//WD start
/*if (IsMovementThreshold(component.LastThirstThreshold) != IsMovementThreshold(component.CurrentThirstThreshold) &&
TryComp(uid, out MovementSpeedModifierComponent? movementSlowdownComponent))
{
_movement.RefreshMovementSpeedModifiers(uid, movementSlowdownComponent);
}*/
//WD end
// Update UI
if (ThirstComponent.ThirstThresholdAlertTypes.TryGetValue(component.CurrentThirstThreshold, out var alertId))
{
_alerts.ShowAlert(uid, alertId);
}
else
{
_alerts.ClearAlertCategory(uid, AlertCategory.Thirst);
}
// WD start
if (component.CurrentThirstThreshold != ThirstThreshold.OverHydrated)
{
var ev = new MoodEffectEvent("Thirst" + component.CurrentThirstThreshold);
RaiseLocalEvent(uid, ev);
}
// WD end
switch (component.CurrentThirstThreshold)
{
case ThirstThreshold.OverHydrated:
component.LastThirstThreshold = component.CurrentThirstThreshold;
component.ActualDecayRate = component.BaseDecayRate * 1.2f;
return;
case ThirstThreshold.Okay:
component.LastThirstThreshold = component.CurrentThirstThreshold;
component.ActualDecayRate = component.BaseDecayRate;
return;
case ThirstThreshold.Thirsty:
// Same as okay except with UI icon saying drink soon.
component.LastThirstThreshold = component.CurrentThirstThreshold;
component.ActualDecayRate = component.BaseDecayRate * 0.8f;
return;
case ThirstThreshold.Parched:
//_movement.RefreshMovementSpeedModifiers(uid); WD REMOVED
component.LastThirstThreshold = component.CurrentThirstThreshold;
component.ActualDecayRate = component.BaseDecayRate * 0.6f;
return;
case ThirstThreshold.Dead:
return;
default:
Log.Error($"No thirst threshold found for {component.CurrentThirstThreshold}");
throw new ArgumentOutOfRangeException($"No thirst threshold found for {component.CurrentThirstThreshold}");
}
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<ThirstComponent>();
while (query.MoveNext(out var uid, out var thirst))
{
if (_timing.CurTime < thirst.NextUpdateTime)
continue;
thirst.NextUpdateTime += thirst.UpdateRate;
ModifyThirst(uid, thirst, -thirst.ActualDecayRate);
var calculatedThirstThreshold = GetThirstThreshold(thirst, thirst.CurrentThirst);
if (calculatedThirstThreshold == thirst.CurrentThirstThreshold)
continue;
thirst.CurrentThirstThreshold = calculatedThirstThreshold;
UpdateEffects(uid, thirst);
}
}
}