Hunger ECS (#14939)
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
using Content.Server.Animals.Components;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Nutrition.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Nutrition.Components;
|
||||
using Content.Shared.Nutrition.EntitySystems;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Udder;
|
||||
using Content.Shared.Verbs;
|
||||
@@ -18,6 +20,7 @@ namespace Content.Server.Animals.Systems
|
||||
internal sealed class UdderSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
||||
[Dependency] private readonly HungerSystem _hunger = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
|
||||
@@ -41,10 +44,8 @@ namespace Content.Server.Animals.Systems
|
||||
// Actually there is food digestion so no problem with instant reagent generation "OnFeed"
|
||||
if (EntityManager.TryGetComponent<HungerComponent?>(udder.Owner, out var hunger))
|
||||
{
|
||||
hunger.HungerThresholds.TryGetValue(HungerThreshold.Peckish, out var targetThreshold);
|
||||
|
||||
// Is there enough nutrition to produce reagent?
|
||||
if (hunger.CurrentHunger < targetThreshold)
|
||||
if (_hunger.GetHungerThreshold(hunger) < HungerThreshold.Peckish)
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user