mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* ready * oop forgot the HUD stuff * woooo examinable generalized tooooo * oop I forgot to rename the files * bungled the merge, I guess * this is called hubris * Verin's comments * PR comments how did I use `ProtoId<> Hunger` in more than a few spots but then just say "thirst can stay a literal :^)"? also changed a few spots to my beloved ``` functionInvocation( one param per line ) ``` ``` * Satiation effect condition now with ADDED FUNCTIONALITY?? :o * tfw you trust the markov chain recommendation because long generic type names are tough q-q * TFW YOU TRUST THE MARKOV CHAIN BUT IT DOESN'T UNDERSTAND THE DIFFERING SEMANTICS OF MAX AND MIN AHHHHH * tfw you think to yourself "i need to fix the effects", but then forget to and the code doesn't even compile. * centralize satiation constants * other small comments * The enum is dead. But at what cost? * oop * like 12 more ooperses * green checks are mine by right; I have performed the rites; I have done my part; you will not deny me this succor * oops I changed the semantics from `<=` to just `<` and didn't update the tests :) * serialization has bested me :agony: also PR comments * never trust the auto merge :agony: * literally just this * force engine back to master because idk why it's different * fix randomness and update master * submodule fuckery * fall before my might * okay I ran the linter, ARE YOU HAPPY?? * cursed ovis, trouble me no more * protoman stuff * inb4 linter bonks me * break non-critical stuff from the main satiation proto *  inb4 this breaks something somewhere lmao * my two greatest PRs COLLIDE I wonder why robust says it's changed :hmmclueless * sanity is at an all-time low * serialization, I guess * I don't believe you * field deltas on class \w*satiation\w*components * PR comments * 我做泥團子 😔 * doc + kill one property that's trivially accessible after the threshold caching changes * fixes --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com> Co-authored-by: AJCM-git <ajcm_mail@disroot.org>
114 lines
4 KiB
C#
114 lines
4 KiB
C#
using Content.Server.Actions;
|
|
using Content.Server.Animals.Components;
|
|
using Content.Server.Popups;
|
|
using Content.Shared.Actions.Events;
|
|
using Content.Shared.IdentityManagement;
|
|
using Content.Shared.Mobs.Systems;
|
|
using Content.Shared.Nutrition.Components;
|
|
using Content.Shared.Nutrition.EntitySystems;
|
|
using Content.Shared.Nutrition.Prototypes;
|
|
using Content.Shared.Storage;
|
|
using Robust.Server.Audio;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Server.Animals.Systems;
|
|
|
|
/// <summary>
|
|
/// Gives the ability to lay eggs/other things;
|
|
/// produces endlessly if the owner does not have a HungerComponent.
|
|
/// </summary>
|
|
public sealed partial class EggLayerSystem : EntitySystem
|
|
{
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
[Dependency] private ActionsSystem _actions = default!;
|
|
[Dependency] private AudioSystem _audio = default!;
|
|
[Dependency] private SatiationSystem _satiation = default!;
|
|
[Dependency] private IGameTiming _timing = default!;
|
|
[Dependency] private PopupSystem _popup = default!;
|
|
[Dependency] private MobStateSystem _mobState = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<EggLayerComponent, MapInitEvent>(OnMapInit);
|
|
SubscribeLocalEvent<EggLayerComponent, EggLayInstantActionEvent>(OnEggLayAction);
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
var query = EntityQueryEnumerator<EggLayerComponent>();
|
|
while (query.MoveNext(out var uid, out var eggLayer))
|
|
{
|
|
// Players should be using the action.
|
|
if (HasComp<ActorComponent>(uid))
|
|
continue;
|
|
|
|
if (_timing.CurTime < eggLayer.NextGrowth)
|
|
continue;
|
|
|
|
// Randomize next growth time for more organic egglaying.
|
|
eggLayer.NextGrowth += TimeSpan.FromSeconds(_random.NextFloat(eggLayer.EggLayCooldownMin, eggLayer.EggLayCooldownMax));
|
|
|
|
if (_mobState.IsDead(uid))
|
|
continue;
|
|
|
|
// Hungerlevel check/modification is done in TryLayEgg()
|
|
// so it's used for player controlled chickens as well.
|
|
|
|
TryLayEgg(uid, eggLayer);
|
|
}
|
|
}
|
|
|
|
private void OnMapInit(EntityUid uid, EggLayerComponent component, MapInitEvent args)
|
|
{
|
|
_actions.AddAction(uid, ref component.Action, component.EggLayAction);
|
|
component.NextGrowth = _timing.CurTime + TimeSpan.FromSeconds(_random.NextFloat(component.EggLayCooldownMin, component.EggLayCooldownMax));
|
|
}
|
|
|
|
private void OnEggLayAction(EntityUid uid, EggLayerComponent egglayer, EggLayInstantActionEvent args)
|
|
{
|
|
// Cooldown is handeled by ActionAnimalLayEgg in types.yml.
|
|
args.Handled = TryLayEgg(uid, egglayer);
|
|
}
|
|
|
|
public bool TryLayEgg(EntityUid uid, EggLayerComponent? egglayer)
|
|
{
|
|
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<SatiationComponent>(uid, out var satiation))
|
|
{
|
|
if (_satiation.GetValueOrNull((uid, satiation), SatiationSystem.Hunger) < egglayer.HungerUsage)
|
|
{
|
|
_popup.PopupEntity(Loc.GetString("action-popup-lay-egg-too-hungry"), uid, uid);
|
|
return false;
|
|
}
|
|
|
|
_satiation.ModifyValue((uid, satiation), SatiationSystem.Hunger, -egglayer.HungerUsage);
|
|
}
|
|
|
|
foreach (var ent in EntitySpawnCollection.GetSpawns(egglayer.EggSpawn, _random))
|
|
{
|
|
SpawnNextToOrDrop(ent, uid);
|
|
}
|
|
|
|
// Sound + popups
|
|
_audio.PlayPvs(egglayer.EggLaySound, uid);
|
|
_popup.PopupEntity(
|
|
Loc.GetString("action-popup-lay-egg-user"),
|
|
Loc.GetString("action-popup-lay-egg-others", ("entity", Identity.Entity(uid, EntityManager))),
|
|
uid,
|
|
uid);
|
|
|
|
return true;
|
|
}
|
|
}
|