* Changed comments to be more clear and uniform. EggLayer uses NextGrowth instead of frame accumulation. Egglayer uses much less energy to make eggs, and lay time is randomized for player and AI chicken. * UdderComponent ReagentId can be changed now UdderSystem and WoolySystem use SharedSolutionContainerSystem now * Entities with udders can be examined to see a rough hunger level udders and wooly stop reagent generation/extra nutrient usage once the solution container is full * Moved stuff to Shared AutoPausedField now * Cleanup moving stuff to Shared * Oops. Make UdderSystem sealed instead of abstract. * Switch PopupEntity for PopupClient * Didn't mean to delete Access * new() instead of default! prototype revert egglayer balance change NextGrowth += timespan in egglayer * forgot [Datafield] for NextGrowth * forgot NetworkedComponent again... * Renaming Shared Animal to Shared Animals to match Server Hopefully also resolve merge conflicts. * Fix incorrect filename * Update with requested changes Put UdderSystem dependencies in alphabetical order. Initialise NextGrowth for Udder and Wooly components on MapInitEvent. Clean-up EggLayerSystem a little. Re-write OnExamine function for UdderSystem, improving clarity. Add full stops to end of udder examine locales. And more :) * Add some additional descriptions for cow hunger levels. * Add Udder and Wooly quantity to AutoNetworkedField * Account for less than starving threshold. --------- Co-authored-by: sirionaut <sirionaut@gmail.com> Co-authored-by: Sirionaut <148076704+Sirionaut@users.noreply.github.com> Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
75 lines
2.5 KiB
C#
75 lines
2.5 KiB
C#
using Content.Shared.Chemistry.EntitySystems;
|
|
using Content.Shared.Mobs.Systems;
|
|
using Content.Shared.Nutrition;
|
|
using Content.Shared.Nutrition.Components;
|
|
using Content.Shared.Nutrition.EntitySystems;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Shared.Animals;
|
|
|
|
/// <summary>
|
|
/// Gives ability to produce fiber reagents;
|
|
/// produces endlessly if the owner has no HungerComponent.
|
|
/// </summary>
|
|
public sealed class WoolySystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly HungerSystem _hunger = default!;
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly MobStateSystem _mobState = default!;
|
|
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<WoolyComponent, BeforeFullyEatenEvent>(OnBeforeFullyEaten);
|
|
SubscribeLocalEvent<WoolyComponent, MapInitEvent>(OnMapInit);
|
|
}
|
|
|
|
private void OnMapInit(EntityUid uid, WoolyComponent component, MapInitEvent args)
|
|
{
|
|
component.NextGrowth = _timing.CurTime + component.GrowthDelay;
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
var query = EntityQueryEnumerator<WoolyComponent>();
|
|
while (query.MoveNext(out var uid, out var wooly))
|
|
{
|
|
if (_timing.CurTime < wooly.NextGrowth)
|
|
continue;
|
|
|
|
wooly.NextGrowth += wooly.GrowthDelay;
|
|
|
|
if (_mobState.IsDead(uid))
|
|
continue;
|
|
|
|
if (!_solutionContainer.ResolveSolution(uid, wooly.SolutionName, ref wooly.Solution, out var solution))
|
|
continue;
|
|
|
|
if (solution.AvailableVolume == 0)
|
|
continue;
|
|
|
|
// Actually there is food digestion so no problem with instant reagent generation "OnFeed"
|
|
if (EntityManager.TryGetComponent(uid, out HungerComponent? hunger))
|
|
{
|
|
// Is there enough nutrition to produce reagent?
|
|
if (_hunger.GetHungerThreshold(hunger) < HungerThreshold.Okay)
|
|
continue;
|
|
|
|
_hunger.ModifyHunger(uid, -wooly.HungerUsage, hunger);
|
|
}
|
|
|
|
_solutionContainer.TryAddReagent(wooly.Solution.Value, wooly.ReagentId, wooly.Quantity, out _);
|
|
}
|
|
}
|
|
|
|
private void OnBeforeFullyEaten(Entity<WoolyComponent> ent, ref BeforeFullyEatenEvent args)
|
|
{
|
|
// don't want moths to delete goats after eating them
|
|
args.Cancel();
|
|
}
|
|
}
|