Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix udder wooly reagent creation V2 #32905

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
20a68cf
Changed comments to be more clear and uniform.
Sirionaut Jun 21, 2024
0ce5b13
Merge branch 'space-wizards:master' into AnimalHusbandry-tweaks
Sirionaut Jun 21, 2024
c703afc
UdderComponent ReagentId can be changed now
Sirionaut Jun 21, 2024
2397d56
Merge branch 'AnimalHusbandry-tweaks' of https://github.com/Sirionaut…
Sirionaut Jun 21, 2024
f6fbfd7
Entities with udders can be examined to see a rough hunger level
Sirionaut Jun 21, 2024
24cfd2d
Moved stuff to Shared
Sirionaut Jun 22, 2024
a62e795
Cleanup moving stuff to Shared
Tayrtahn Jun 22, 2024
52e55f6
Oops. Make UdderSystem sealed instead of abstract.
Tayrtahn Jun 22, 2024
9162ac8
Switch PopupEntity for PopupClient
Tayrtahn Jun 22, 2024
5ee777c
Didn't mean to delete Access
Tayrtahn Jun 22, 2024
c061955
new() instead of default! prototype
Sirionaut Jun 25, 2024
0f5aaf2
forgot [Datafield] for NextGrowth
Sirionaut Jun 25, 2024
e10c506
forgot NetworkedComponent again...
Sirionaut Jun 27, 2024
2dc2708
Renaming Shared Animal to Shared Animals to match Server
Baa14453 Oct 19, 2024
39f4810
Merge master and resolve conflicts.
Baa14453 Oct 19, 2024
bc02487
Fix incorrect filename
Baa14453 Oct 19, 2024
9def7a5
Merge branch 'space-wizards:master' into Fix-udder-wooly-reagent-crea…
Baa14453 Nov 11, 2024
105b319
Update with requested changes
Baa14453 Nov 12, 2024
75abf08
Add some additional descriptions for cow hunger levels.
Baa14453 Nov 13, 2024
e9ee666
Add Udder and Wooly quantity to AutoNetworkedField
Baa14453 Nov 13, 2024
b569997
Account for less than starving threshold.
Baa14453 Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions Content.Server/Animals/Components/EggLayerComponent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Animals.Systems;
using Content.Shared.Storage;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
Expand All @@ -9,44 +10,47 @@ namespace Content.Server.Animals.Components;
/// 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;
}
59 changes: 0 additions & 59 deletions Content.Server/Animals/Components/UdderComponent.cs

This file was deleted.

25 changes: 15 additions & 10 deletions Content.Server/Animals/Systems/EggLayerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@
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 IRobustRandom _random = default!;
[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!;

Expand All @@ -37,21 +38,24 @@ public override void Initialize()
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;

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);
}
Expand All @@ -60,11 +64,12 @@ public override void Update(float frameTime)
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);
}

Expand All @@ -76,7 +81,7 @@ public bool TryLayEgg(EntityUid uid, EggLayerComponent? 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)
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Polymorph/Systems/PolymorphSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
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;
Expand All @@ -13,6 +12,7 @@
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;
Expand Down
57 changes: 57 additions & 0 deletions Content.Shared/Animals/UdderComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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;
}
Loading
Loading