* 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>
+using Content.Server.Animals.Systems;
using Content.Shared.Storage;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
/// It also grants an action to players who are controlling these entities, allowing them to do it manually.
/// </summary>
-[RegisterComponent]
+[RegisterComponent, Access(typeof(EggLayerSystem)), AutoGenerateComponentPause]
public sealed partial class EggLayerComponent : Component
{
- [DataField]
- public EntProtoId EggLayAction = "ActionAnimalLayEgg";
+ /// <summary>
+ /// The item that gets laid/spawned, retrieved from animal prototype.
+ /// </summary>
+ [DataField(required: true)]
+ public List<EntitySpawnEntry> EggSpawn = new();
/// <summary>
- /// The amount of nutrient consumed on update.
+ /// Player action.
/// </summary>
- [DataField, ViewVariables(VVAccess.ReadWrite)]
- public float HungerUsage = 60f;
+ [DataField]
+ public EntProtoId EggLayAction = "ActionAnimalLayEgg";
+
+ [DataField]
+ public SoundSpecifier EggLaySound = new SoundPathSpecifier("/Audio/Effects/pop.ogg");
/// <summary>
/// Minimum cooldown used for the automatic egg laying.
/// </summary>
- [DataField, ViewVariables(VVAccess.ReadWrite)]
+ [DataField]
public float EggLayCooldownMin = 60f;
/// <summary>
/// Maximum cooldown used for the automatic egg laying.
/// </summary>
- [DataField, ViewVariables(VVAccess.ReadWrite)]
+ [DataField]
public float EggLayCooldownMax = 120f;
/// <summary>
- /// Set during component init.
+ /// The amount of nutrient consumed on update.
/// </summary>
- [ViewVariables(VVAccess.ReadWrite)]
- public float CurrentEggLayCooldown;
-
- [DataField(required: true), ViewVariables(VVAccess.ReadWrite)]
- public List<EntitySpawnEntry> EggSpawn = default!;
-
[DataField]
- public SoundSpecifier EggLaySound = new SoundPathSpecifier("/Audio/Effects/pop.ogg");
-
- [DataField]
- public float AccumulatedFrametime;
+ public float HungerUsage = 60f;
[DataField] public EntityUid? Action;
+
+ /// <summary>
+ /// When to next try to produce.
+ /// </summary>
+ [DataField, AutoPausedField]
+ public TimeSpan NextGrowth = TimeSpan.Zero;
}
+++ /dev/null
-using Content.Server.Animals.Systems;
-using Content.Shared.Chemistry.Components;
-using Content.Shared.Chemistry.Reagent;
-using Content.Shared.FixedPoint;
-using Robust.Shared.Prototypes;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
-
-namespace Content.Server.Animals.Components
-
-/// <summary>
-/// Lets an entity produce milk. Uses hunger if present.
-/// </summary>
-{
- [RegisterComponent, Access(typeof(UdderSystem))]
- internal sealed partial class UdderComponent : Component
- {
- /// <summary>
- /// The reagent to produce.
- /// </summary>
- [DataField, ViewVariables(VVAccess.ReadOnly)]
- public ProtoId<ReagentPrototype> ReagentId = "Milk";
-
- /// <summary>
- /// The name of <see cref="Solution"/>.
- /// </summary>
- [DataField, ViewVariables(VVAccess.ReadOnly)]
- public string SolutionName = "udder";
-
- /// <summary>
- /// The solution to add reagent to.
- /// </summary>
- [DataField]
- public Entity<SolutionComponent>? Solution = null;
-
- /// <summary>
- /// The amount of reagent to be generated on update.
- /// </summary>
- [DataField, ViewVariables(VVAccess.ReadOnly)]
- public FixedPoint2 QuantityPerUpdate = 25;
-
- /// <summary>
- /// The amount of nutrient consumed on update.
- /// </summary>
- [DataField, ViewVariables(VVAccess.ReadWrite)]
- public float HungerUsage = 10f;
-
- /// <summary>
- /// How long to wait before producing.
- /// </summary>
- [DataField, ViewVariables(VVAccess.ReadWrite)]
- public TimeSpan GrowthDelay = TimeSpan.FromMinutes(1);
-
- /// <summary>
- /// When to next try to produce.
- /// </summary>
- [DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
- public TimeSpan NextGrowth = TimeSpan.FromSeconds(0);
- }
-}
using Content.Shared.Nutrition.EntitySystems;
using Content.Shared.Storage;
using Robust.Server.Audio;
-using Robust.Server.GameObjects;
using Robust.Shared.Player;
using Robust.Shared.Random;
+using Robust.Shared.Timing;
namespace Content.Server.Animals.Systems;
/// <summary>
-/// Gives ability to produce eggs, produces endless if the
-/// owner has no HungerComponent
+/// Gives the ability to lay eggs/other things;
+/// produces endlessly if the owner does not have a HungerComponent.
/// </summary>
public sealed class EggLayerSystem : EntitySystem
{
[Dependency] private readonly ActionsSystem _actions = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly HungerSystem _hunger = default!;
+ [Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
public override void Update(float frameTime)
{
base.Update(frameTime);
-
var query = EntityQueryEnumerator<EggLayerComponent>();
while (query.MoveNext(out var uid, out var eggLayer))
{
if (HasComp<ActorComponent>(uid))
continue;
- eggLayer.AccumulatedFrametime += frameTime;
+ 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 (eggLayer.AccumulatedFrametime < eggLayer.CurrentEggLayCooldown)
+ if (_mobState.IsDead(uid))
continue;
- eggLayer.AccumulatedFrametime -= eggLayer.CurrentEggLayCooldown;
- eggLayer.CurrentEggLayCooldown = _random.NextFloat(eggLayer.EggLayCooldownMin, eggLayer.EggLayCooldownMax);
+ // 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.CurrentEggLayCooldown = _random.NextFloat(component.EggLayCooldownMin, component.EggLayCooldownMax);
+ 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);
}
if (_mobState.IsDead(uid))
return false;
- // Allow infinitely laying eggs if they can't get hungry
+ // Allow infinitely laying eggs if they can't get hungry.
if (TryComp<HungerComponent>(uid, out var hunger))
{
if (hunger.CurrentHunger < egglayer.HungerUsage)
using Content.Server.Humanoid;
using Content.Server.Inventory;
using Content.Server.Mind.Commands;
-using Content.Server.Nutrition;
using Content.Server.Polymorph.Components;
using Content.Shared.Actions;
using Content.Shared.Buckle;
using Content.Shared.Mind;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
+using Content.Shared.Nutrition;
using Content.Shared.Polymorph;
using Content.Shared.Popups;
using Robust.Server.Audio;
--- /dev/null
+using Content.Shared.Chemistry.Components;
+using Content.Shared.Chemistry.Reagent;
+using Content.Shared.FixedPoint;
+using Robust.Shared.GameStates;
+using Robust.Shared.Prototypes;
+
+namespace Content.Shared.Animals;
+
+/// <summary>
+/// Gives the ability to produce a solution;
+/// produces endlessly if the owner does not have a HungerComponent.
+/// </summary>
+[RegisterComponent, AutoGenerateComponentState, AutoGenerateComponentPause, NetworkedComponent]
+public sealed partial class UdderComponent : Component
+{
+ /// <summary>
+ /// The reagent to produce.
+ /// </summary>
+ [DataField, AutoNetworkedField]
+ public ProtoId<ReagentPrototype> ReagentId = new();
+
+ /// <summary>
+ /// The name of <see cref="Solution"/>.
+ /// </summary>
+ [DataField]
+ public string SolutionName = "udder";
+
+ /// <summary>
+ /// The solution to add reagent to.
+ /// </summary>
+ [DataField, ViewVariables(VVAccess.ReadOnly)]
+ public Entity<SolutionComponent>? Solution = null;
+
+ /// <summary>
+ /// The amount of reagent to be generated on update.
+ /// </summary>
+ [DataField, AutoNetworkedField]
+ public FixedPoint2 QuantityPerUpdate = 25;
+
+ /// <summary>
+ /// The amount of nutrient consumed on update.
+ /// </summary>
+ [DataField, AutoNetworkedField]
+ public float HungerUsage = 10f;
+
+ /// <summary>
+ /// How long to wait before producing.
+ /// </summary>
+ [DataField, AutoNetworkedField]
+ public TimeSpan GrowthDelay = TimeSpan.FromMinutes(1);
+
+ /// <summary>
+ /// When to next try to produce.
+ /// </summary>
+ [DataField, AutoPausedField, Access(typeof(UdderSystem))]
+ public TimeSpan NextGrowth = TimeSpan.Zero;
+}
-using Content.Server.Animals.Components;
-using Content.Server.Popups;
-using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Components;
+using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.DoAfter;
+using Content.Shared.Examine;
using Content.Shared.IdentityManagement;
using Content.Shared.Mobs.Systems;
using Content.Shared.Nutrition.Components;
using Content.Shared.Verbs;
using Robust.Shared.Timing;
-namespace Content.Server.Animals.Systems;
-
+namespace Content.Shared.Animals;
/// <summary>
-/// Gives ability to produce milkable reagents, produces endless if the
-/// owner has no HungerComponent
+/// Gives the ability to produce milkable reagents;
+/// produces endlessly if the owner does not have a HungerComponent.
/// </summary>
-internal sealed class UdderSystem : EntitySystem
+public sealed class UdderSystem : EntitySystem
{
[Dependency] private readonly HungerSystem _hunger = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
- [Dependency] private readonly PopupSystem _popupSystem = default!;
+ [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
{
base.Initialize();
+ SubscribeLocalEvent<UdderComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<UdderComponent, GetVerbsEvent<AlternativeVerb>>(AddMilkVerb);
SubscribeLocalEvent<UdderComponent, MilkingDoAfterEvent>(OnDoAfter);
+ SubscribeLocalEvent<UdderComponent, ExaminedEvent>(OnExamine);
+ }
+
+ private void OnMapInit(EntityUid uid, UdderComponent component, MapInitEvent args)
+ {
+ component.NextGrowth = _timing.CurTime + component.GrowthDelay;
}
public override void Update(float frameTime)
{
base.Update(frameTime);
-
var query = EntityQueryEnumerator<UdderComponent>();
- var now = _timing.CurTime;
while (query.MoveNext(out var uid, out var udder))
{
- if (now < udder.NextGrowth)
+ if (_timing.CurTime < udder.NextGrowth)
continue;
- udder.NextGrowth = now + udder.GrowthDelay;
+ udder.NextGrowth += udder.GrowthDelay;
if (_mobState.IsDead(uid))
continue;
+ if (!_solutionContainerSystem.ResolveSolution(uid, udder.SolutionName, ref udder.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))
{
_hunger.ModifyHunger(uid, -udder.HungerUsage, hunger);
}
- if (!_solutionContainerSystem.ResolveSolution(uid, udder.SolutionName, ref udder.Solution))
- continue;
-
//TODO: toxins from bloodstream !?
_solutionContainerSystem.TryAddReagent(udder.Solution.Value, udder.ReagentId, udder.QuantityPerUpdate, out _);
}
var quantity = solution.Volume;
if (quantity == 0)
{
- _popupSystem.PopupEntity(Loc.GetString("udder-system-dry"), entity.Owner, args.Args.User);
+ _popupSystem.PopupClient(Loc.GetString("udder-system-dry"), entity.Owner, args.Args.User);
return;
}
var split = _solutionContainerSystem.SplitSolution(entity.Comp.Solution.Value, quantity);
_solutionContainerSystem.TryAddSolution(targetSoln.Value, split);
- _popupSystem.PopupEntity(Loc.GetString("udder-system-success", ("amount", quantity), ("target", Identity.Entity(args.Args.Used.Value, EntityManager))), entity.Owner,
+ _popupSystem.PopupClient(Loc.GetString("udder-system-success", ("amount", quantity), ("target", Identity.Entity(args.Args.Used.Value, EntityManager))), entity.Owner,
args.Args.User, PopupType.Medium);
}
};
args.Verbs.Add(verb);
}
+
+ /// <summary>
+ /// Defines the text provided on examine.
+ /// Changes depending on the amount of hunger the target has.
+ /// </summary>
+ private void OnExamine(Entity<UdderComponent> entity, ref ExaminedEvent args)
+ {
+
+ var entityIdentity = Identity.Entity(args.Examined, EntityManager);
+
+ string message;
+
+ // Check if the target has hunger, otherwise return not hungry.
+ if (!TryComp<HungerComponent>(entity, out var hunger))
+ {
+ message = Loc.GetString("udder-system-examine-none", ("entity", entityIdentity));
+ args.PushMarkup(message);
+ return;
+ }
+
+ // Choose the correct examine string based on HungerThreshold.
+ switch (_hunger.GetHungerThreshold(hunger))
+ {
+ case >= HungerThreshold.Overfed:
+ message = Loc.GetString("udder-system-examine-overfed", ("entity", entityIdentity));
+ break;
+
+ case HungerThreshold.Okay:
+ message = Loc.GetString("udder-system-examine-okay", ("entity", entityIdentity));
+ break;
+
+ case HungerThreshold.Peckish:
+ message = Loc.GetString("udder-system-examine-hungry", ("entity", entityIdentity));
+ break;
+
+ // There's a final hunger threshold called "dead" but animals don't actually die so we'll re-use this.
+ case <= HungerThreshold.Starving:
+ message = Loc.GetString("udder-system-examine-starved", ("entity", entityIdentity));
+ break;
+
+ default:
+ return;
+ }
+
+ args.PushMarkup(message);
+ }
}
-using Content.Server.Animals.Systems;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
+using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
-namespace Content.Server.Animals.Components;
+namespace Content.Shared.Animals;
/// <summary>
-/// Lets an entity produce wool fibers. Uses hunger if present.
+/// Gives the ability to produce wool fibers;
+/// produces endlessly if the owner does not have a HungerComponent.
/// </summary>
-
-[RegisterComponent, Access(typeof(WoolySystem))]
+[RegisterComponent, AutoGenerateComponentState, AutoGenerateComponentPause, NetworkedComponent]
public sealed partial class WoolyComponent : Component
{
/// <summary>
/// The reagent to grow.
/// </summary>
- [DataField, ViewVariables(VVAccess.ReadOnly)]
+ [DataField, AutoNetworkedField]
public ProtoId<ReagentPrototype> ReagentId = "Fiber";
/// <summary>
/// <summary>
/// The solution to add reagent to.
/// </summary>
- [DataField]
+ [DataField, ViewVariables(VVAccess.ReadOnly)]
public Entity<SolutionComponent>? Solution;
/// <summary>
/// The amount of reagent to be generated on update.
/// </summary>
- [DataField, ViewVariables(VVAccess.ReadOnly)]
+ [DataField, AutoNetworkedField]
public FixedPoint2 Quantity = 25;
/// <summary>
/// The amount of nutrient consumed on update.
/// </summary>
- [DataField, ViewVariables(VVAccess.ReadWrite)]
+ [DataField, AutoNetworkedField]
public float HungerUsage = 10f;
/// <summary>
/// How long to wait before growing wool.
/// </summary>
- [DataField, ViewVariables(VVAccess.ReadWrite)]
+ [DataField, AutoNetworkedField]
public TimeSpan GrowthDelay = TimeSpan.FromMinutes(1);
/// <summary>
/// When to next try growing wool.
/// </summary>
- [DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
- public TimeSpan NextGrowth = TimeSpan.FromSeconds(0);
+ [DataField, AutoPausedField, Access(typeof(WoolySystem))]
+ public TimeSpan NextGrowth = TimeSpan.Zero;
}
-using Content.Server.Animals.Components;
-using Content.Server.Nutrition;
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.Server.Animals.Systems;
+namespace Content.Shared.Animals;
/// <summary>
-/// Gives ability to produce fiber reagents, produces endless if the
-/// owner has no HungerComponent
+/// Gives ability to produce fiber reagents;
+/// produces endlessly if the owner has no HungerComponent.
/// </summary>
public sealed class WoolySystem : EntitySystem
{
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>();
- var now = _timing.CurTime;
while (query.MoveNext(out var uid, out var wooly))
{
- if (now < wooly.NextGrowth)
+ if (_timing.CurTime < wooly.NextGrowth)
continue;
- wooly.NextGrowth = now + wooly.GrowthDelay;
+ 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))
{
_hunger.ModifyHunger(uid, -wooly.HungerUsage, hunger);
}
- if (!_solutionContainer.ResolveSolution(uid, wooly.SolutionName, ref wooly.Solution))
- continue;
-
_solutionContainer.TryAddReagent(wooly.Solution.Value, wooly.ReagentId, wooly.Quantity, out _);
}
}
-namespace Content.Server.Nutrition;
+namespace Content.Shared.Nutrition;
/// <summary>
/// Raised directed at the consumer when attempting to ingest something.
udder-system-dry = The udder is dry.
udder-system-verb-milk = Milk
+
+udder-system-examine-overfed = {CAPITALIZE(SUBJECT($entity))} looks stuffed!
+udder-system-examine-okay = {CAPITALIZE(SUBJECT($entity))} looks content.
+udder-system-examine-hungry = {CAPITALIZE(SUBJECT($entity))} looks hungry.
+udder-system-examine-starved = {CAPITALIZE(SUBJECT($entity))} looks starved!
+udder-system-examine-none = {CAPITALIZE(SUBJECT($entity))} seems not to get hungry.