Animals obey conservation of matter unless they are undead (#21922)
This commit is contained in:
@@ -2,6 +2,7 @@ using Content.Server.Actions;
|
||||
using Content.Server.Animals.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Actions.Events;
|
||||
using Content.Shared.Mobs.Systems;
|
||||
using Content.Shared.Nutrition.Components;
|
||||
using Content.Shared.Nutrition.EntitySystems;
|
||||
using Content.Shared.Storage;
|
||||
@@ -12,6 +13,10 @@ using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Animals.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// Gives ability to produce eggs, produces endless if the
|
||||
/// owner has no HungerComponent
|
||||
/// </summary>
|
||||
public sealed class EggLayerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
@@ -19,6 +24,7 @@ public sealed class EggLayerSystem : EntitySystem
|
||||
[Dependency] private readonly AudioSystem _audio = default!;
|
||||
[Dependency] private readonly HungerSystem _hunger = default!;
|
||||
[Dependency] private readonly PopupSystem _popup = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobState = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -57,35 +63,38 @@ public sealed class EggLayerSystem : EntitySystem
|
||||
component.CurrentEggLayCooldown = _random.NextFloat(component.EggLayCooldownMin, component.EggLayCooldownMax);
|
||||
}
|
||||
|
||||
private void OnEggLayAction(EntityUid uid, EggLayerComponent component, EggLayInstantActionEvent args)
|
||||
private void OnEggLayAction(EntityUid uid, EggLayerComponent egglayer, EggLayInstantActionEvent args)
|
||||
{
|
||||
args.Handled = TryLayEgg(uid, component);
|
||||
args.Handled = TryLayEgg(uid, egglayer);
|
||||
}
|
||||
|
||||
public bool TryLayEgg(EntityUid uid, EggLayerComponent? component)
|
||||
public bool TryLayEgg(EntityUid uid, EggLayerComponent? egglayer)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
if (!Resolve(uid, ref egglayer))
|
||||
return false;
|
||||
|
||||
if (_mobState.IsDead(uid))
|
||||
return false;
|
||||
|
||||
// Allow infinitely laying eggs if they can't get hungry
|
||||
if (TryComp<HungerComponent>(uid, out var hunger))
|
||||
{
|
||||
if (hunger.CurrentHunger < component.HungerUsage)
|
||||
if (hunger.CurrentHunger < egglayer.HungerUsage)
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("action-popup-lay-egg-too-hungry"), uid, uid);
|
||||
return false;
|
||||
}
|
||||
|
||||
_hunger.ModifyHunger(uid, -component.HungerUsage, hunger);
|
||||
_hunger.ModifyHunger(uid, -egglayer.HungerUsage, hunger);
|
||||
}
|
||||
|
||||
foreach (var ent in EntitySpawnCollection.GetSpawns(component.EggSpawn, _random))
|
||||
foreach (var ent in EntitySpawnCollection.GetSpawns(egglayer.EggSpawn, _random))
|
||||
{
|
||||
Spawn(ent, Transform(uid).Coordinates);
|
||||
}
|
||||
|
||||
// Sound + popups
|
||||
_audio.PlayPvs(component.EggLaySound, uid);
|
||||
_audio.PlayPvs(egglayer.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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user