Hunger ECS (#14939)

This commit is contained in:
Nemanja
2023-04-02 22:42:30 -04:00
committed by GitHub
parent 19277a2276
commit 0f0b534239
14 changed files with 440 additions and 364 deletions

View File

@@ -1,11 +1,11 @@
using Content.Server.Actions;
using Content.Server.Animals.Components;
using Content.Server.Nutrition.Components;
using Content.Server.Popups;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Nutrition.Components;
using Content.Shared.Nutrition.EntitySystems;
using Content.Shared.Storage;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
@@ -14,9 +14,11 @@ namespace Content.Server.Animals.Systems;
public sealed class EggLayerSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ActionsSystem _actions = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly HungerSystem _hunger = default!;
[Dependency] private readonly PopupSystem _popup = default!;
public override void Initialize()
@@ -31,11 +33,12 @@ public sealed class EggLayerSystem : EntitySystem
{
base.Update(frameTime);
foreach (var eggLayer in EntityQuery<EggLayerComponent>())
var query = EntityQueryEnumerator<EggLayerComponent>();
while (query.MoveNext(out var uid, out var eggLayer))
{
// Players should be using the action.
if (HasComp<ActorComponent>(eggLayer.Owner))
return;
if (HasComp<ActorComponent>(uid))
continue;
eggLayer.AccumulatedFrametime += frameTime;
@@ -45,7 +48,7 @@ public sealed class EggLayerSystem : EntitySystem
eggLayer.AccumulatedFrametime -= eggLayer.CurrentEggLayCooldown;
eggLayer.CurrentEggLayCooldown = _random.NextFloat(eggLayer.EggLayCooldownMin, eggLayer.EggLayCooldownMax);
TryLayEgg(eggLayer.Owner, eggLayer);
TryLayEgg(uid, eggLayer);
}
}
@@ -77,7 +80,7 @@ public sealed class EggLayerSystem : EntitySystem
return false;
}
hunger.CurrentHunger -= component.HungerUsage;
_hunger.ModifyHunger(uid, -component.HungerUsage, hunger);
}
foreach (var ent in EntitySpawnCollection.GetSpawns(component.EggSpawn, _random))
@@ -86,7 +89,7 @@ public sealed class EggLayerSystem : EntitySystem
}
// Sound + popups
SoundSystem.Play(component.EggLaySound.GetSound(), Filter.Pvs(uid), uid, component.EggLaySound.Params);
_audio.PlayPvs(component.EggLaySound, uid);
_popup.PopupEntity(Loc.GetString("action-popup-lay-egg-user"), uid, uid);
_popup.PopupEntity(Loc.GetString("action-popup-lay-egg-others", ("entity", uid)), uid, Filter.PvsExcept(uid), true);