Add egg laying + chicken/duck improvements (#9518)
This commit is contained in:
55
Content.Server/Animals/Components/EggLayerComponent.cs
Normal file
55
Content.Server/Animals/Components/EggLayerComponent.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using Content.Shared.Actions;
|
||||||
|
using Content.Shared.Actions.ActionTypes;
|
||||||
|
using Content.Shared.Sound;
|
||||||
|
using Content.Shared.Storage;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||||
|
|
||||||
|
namespace Content.Server.Animals.Components;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This component handles animals which lay eggs (or some other item) on a timer, using up hunger to do so.
|
||||||
|
/// It also grants an action to players who are controlling these entities, allowing them to do it manually.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent]
|
||||||
|
public sealed class EggLayerComponent : Component
|
||||||
|
{
|
||||||
|
[DataField("eggLayAction", customTypeSerializer: typeof(PrototypeIdSerializer<InstantActionPrototype>))]
|
||||||
|
public string EggLayAction = "AnimalLayEgg";
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
[DataField("hungerUsage")]
|
||||||
|
public float HungerUsage = 60f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Minimum cooldown used for the automatic egg laying.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
[DataField("eggLayCooldownMin")]
|
||||||
|
public float EggLayCooldownMin = 60f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Maximum cooldown used for the automatic egg laying.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
[DataField("eggLayCooldownMax")]
|
||||||
|
public float EggLayCooldownMax = 120f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set during component init.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public float CurrentEggLayCooldown;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
[DataField("eggSpawn", required: true)]
|
||||||
|
public List<EntitySpawnEntry> EggSpawn = default!;
|
||||||
|
|
||||||
|
[DataField("eggLaySound")]
|
||||||
|
public SoundSpecifier EggLaySound = new SoundPathSpecifier("/Audio/Effects/pop.ogg");
|
||||||
|
|
||||||
|
[DataField("accumulatedFrametime")]
|
||||||
|
public float AccumulatedFrametime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class EggLayInstantActionEvent : InstantActionEvent {}
|
||||||
95
Content.Server/Animals/Systems/EggLayerSystem.cs
Normal file
95
Content.Server/Animals/Systems/EggLayerSystem.cs
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
using Content.Server.Actions;
|
||||||
|
using Content.Server.Animals.Components;
|
||||||
|
using Content.Server.Nutrition.Components;
|
||||||
|
using Content.Server.Popups;
|
||||||
|
using Content.Shared.Actions.ActionTypes;
|
||||||
|
using Content.Shared.Storage;
|
||||||
|
using Robust.Server.GameObjects;
|
||||||
|
using Robust.Shared.Audio;
|
||||||
|
using Robust.Shared.Player;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
|
namespace Content.Server.Animals.Systems;
|
||||||
|
|
||||||
|
public sealed class EggLayerSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||||
|
[Dependency] private readonly ActionsSystem _actions = default!;
|
||||||
|
[Dependency] private readonly PopupSystem _popup = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<EggLayerComponent, ComponentInit>(OnComponentInit);
|
||||||
|
SubscribeLocalEvent<EggLayerComponent, EggLayInstantActionEvent>(OnEggLayAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(float frameTime)
|
||||||
|
{
|
||||||
|
base.Update(frameTime);
|
||||||
|
|
||||||
|
foreach (var eggLayer in EntityQuery<EggLayerComponent>())
|
||||||
|
{
|
||||||
|
// Players should be using the action.
|
||||||
|
if (HasComp<ActorComponent>(eggLayer.Owner))
|
||||||
|
return;
|
||||||
|
|
||||||
|
eggLayer.AccumulatedFrametime += frameTime;
|
||||||
|
|
||||||
|
if (eggLayer.AccumulatedFrametime < eggLayer.CurrentEggLayCooldown)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
eggLayer.AccumulatedFrametime -= eggLayer.CurrentEggLayCooldown;
|
||||||
|
eggLayer.CurrentEggLayCooldown = _random.NextFloat(eggLayer.EggLayCooldownMin, eggLayer.EggLayCooldownMax);
|
||||||
|
|
||||||
|
TryLayEgg(eggLayer.Owner, eggLayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnComponentInit(EntityUid uid, EggLayerComponent component, ComponentInit args)
|
||||||
|
{
|
||||||
|
if (!_prototype.TryIndex<InstantActionPrototype>(component.EggLayAction, out var action))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_actions.AddAction(uid, new InstantAction(action), uid);
|
||||||
|
component.CurrentEggLayCooldown = _random.NextFloat(component.EggLayCooldownMin, component.EggLayCooldownMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEggLayAction(EntityUid uid, EggLayerComponent component, EggLayInstantActionEvent args)
|
||||||
|
{
|
||||||
|
args.Handled = TryLayEgg(uid, component);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryLayEgg(EntityUid uid, EggLayerComponent? component)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref component))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Allow infinitely laying eggs if they can't get hungry
|
||||||
|
if (TryComp<HungerComponent>(uid, out var hunger))
|
||||||
|
{
|
||||||
|
if (hunger.CurrentHunger < component.HungerUsage)
|
||||||
|
{
|
||||||
|
_popup.PopupEntity(Loc.GetString("action-popup-lay-egg-too-hungry"), uid, Filter.Entities(uid));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
hunger.CurrentHunger -= component.HungerUsage;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var ent in EntitySpawnCollection.GetSpawns(component.EggSpawn, _random))
|
||||||
|
{
|
||||||
|
Spawn(ent, Transform(uid).Coordinates);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sound + popups
|
||||||
|
SoundSystem.Play(component.EggLaySound.GetSound(), Filter.Pvs(uid), uid, component.EggLaySound.Params);
|
||||||
|
_popup.PopupEntity(Loc.GetString("action-popup-lay-egg-user"), uid, Filter.Entities(uid));
|
||||||
|
_popup.PopupEntity(Loc.GetString("action-popup-lay-egg-others", ("entity", uid)), uid, Filter.PvsExcept(uid));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,12 +12,14 @@ namespace Content.Shared.Storage;
|
|||||||
[DataDefinition]
|
[DataDefinition]
|
||||||
public struct EntitySpawnEntry : IPopulateDefaultValues
|
public struct EntitySpawnEntry : IPopulateDefaultValues
|
||||||
{
|
{
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
[DataField("id", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
[DataField("id", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||||
public string PrototypeId;
|
public string PrototypeId;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The probability that an item will spawn. Takes decimal form so 0.05 is 5%, 0.50 is 50% etc.
|
/// The probability that an item will spawn. Takes decimal form so 0.05 is 5%, 0.50 is 50% etc.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
[DataField("prob")] public float SpawnProbability;
|
[DataField("prob")] public float SpawnProbability;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -41,8 +43,10 @@ public struct EntitySpawnEntry : IPopulateDefaultValues
|
|||||||
/// </code>
|
/// </code>
|
||||||
/// </example>
|
/// </example>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
[DataField("orGroup")] public string? GroupId;
|
[DataField("orGroup")] public string? GroupId;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
[DataField("amount")] public int Amount;
|
[DataField("amount")] public int Amount;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -50,6 +54,7 @@ public struct EntitySpawnEntry : IPopulateDefaultValues
|
|||||||
/// If this is lesser or equal to <see cref="Amount"/>, it will spawn <see cref="Amount"/> exactly.
|
/// If this is lesser or equal to <see cref="Amount"/>, it will spawn <see cref="Amount"/> exactly.
|
||||||
/// Otherwise, it chooses a random value between <see cref="Amount"/> and <see cref="MaxAmount"/> on spawn.
|
/// Otherwise, it chooses a random value between <see cref="Amount"/> and <see cref="MaxAmount"/> on spawn.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
[DataField("maxAmount")] public int MaxAmount;
|
[DataField("maxAmount")] public int MaxAmount;
|
||||||
|
|
||||||
public void PopulateDefaultValues()
|
public void PopulateDefaultValues()
|
||||||
|
|||||||
@@ -37,3 +37,5 @@ The following sounds are taken from TGstation github (licensed under CC by 3.0):
|
|||||||
demon_consume.ogg: taken at https://github.com/tgstation/tgstation/commit/d4f678a1772007ff8d7eddd21cf7218c8e07bfc0
|
demon_consume.ogg: taken at https://github.com/tgstation/tgstation/commit/d4f678a1772007ff8d7eddd21cf7218c8e07bfc0
|
||||||
|
|
||||||
demon_dies.ogg: taken at https://github.com/tgstation/tgstation/commit/d4f678a1772007ff8d7eddd21cf7218c8e07bfc0
|
demon_dies.ogg: taken at https://github.com/tgstation/tgstation/commit/d4f678a1772007ff8d7eddd21cf7218c8e07bfc0
|
||||||
|
|
||||||
|
pop.ogg licensed under CC0 1.0 by mirrorcult
|
||||||
BIN
Resources/Audio/Effects/pop.ogg
Normal file
BIN
Resources/Audio/Effects/pop.ogg
Normal file
Binary file not shown.
@@ -46,3 +46,15 @@ accent-words-generic-aggressive-1 = Grr!
|
|||||||
accent-words-generic-aggressive-2 = Rrrr!
|
accent-words-generic-aggressive-2 = Rrrr!
|
||||||
accent-words-generic-aggressive-3 = Grr...
|
accent-words-generic-aggressive-3 = Grr...
|
||||||
accent-words-generic-aggressive-4 = Grrow!!
|
accent-words-generic-aggressive-4 = Grrow!!
|
||||||
|
|
||||||
|
# Duck
|
||||||
|
accent-words-duck-1 = Quack!
|
||||||
|
accent-words-duck-2 = Quack.
|
||||||
|
accent-words-duck-3 = Quack?
|
||||||
|
accent-words-duck-4 = Quack quack!
|
||||||
|
|
||||||
|
# Chicken
|
||||||
|
accent-words-chicken-1 = Cluck!
|
||||||
|
accent-words-chicken-2 = Cluck.
|
||||||
|
accent-words-chicken-3 = Cluck?
|
||||||
|
accent-words-chicken-4 = Cluck cluck!
|
||||||
|
|||||||
6
Resources/Locale/en-US/actions/actions/egg-lay.ftl
Normal file
6
Resources/Locale/en-US/actions/actions/egg-lay.ftl
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
action-name-lay-egg = Lay egg
|
||||||
|
action-description-lay-egg = Uses hunger to lay an egg.
|
||||||
|
|
||||||
|
action-popup-lay-egg-user = You lay an egg.
|
||||||
|
action-popup-lay-egg-others = {CAPITALIZE(THE($entity))} lays an egg.
|
||||||
|
action-popup-lay-egg-too-hungry = You need more food before you can lay another egg!
|
||||||
@@ -69,3 +69,11 @@
|
|||||||
icon: Objects/Weapons/Melee/shields.rsi/teleriot-icon.png
|
icon: Objects/Weapons/Melee/shields.rsi/teleriot-icon.png
|
||||||
iconOn: Objects/Weapons/Melee/shields.rsi/teleriot-on.png
|
iconOn: Objects/Weapons/Melee/shields.rsi/teleriot-on.png
|
||||||
event: !type:ToggleActionEvent
|
event: !type:ToggleActionEvent
|
||||||
|
|
||||||
|
- type: instantAction
|
||||||
|
id: AnimalLayEgg
|
||||||
|
name: action-name-lay-egg
|
||||||
|
description: action-description-lay-egg
|
||||||
|
icon: Objects/Consumable/Food/egg.rsi/icon.png
|
||||||
|
useDelay: 60
|
||||||
|
serverEvent: !type:EggLayInstantActionEvent
|
||||||
|
|||||||
@@ -193,6 +193,13 @@
|
|||||||
path: /Audio/Animals/chicken_cluck_happy.ogg
|
path: /Audio/Animals/chicken_cluck_happy.ogg
|
||||||
- type: Bloodstream
|
- type: Bloodstream
|
||||||
bloodMaxVolume: 100
|
bloodMaxVolume: 100
|
||||||
|
- type: EggLayer
|
||||||
|
eggSpawn:
|
||||||
|
- id: FoodEgg
|
||||||
|
- type: ReplacementAccent
|
||||||
|
accent: chicken
|
||||||
|
- type: SentienceTarget
|
||||||
|
flavorKind: organic
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
name: mallard duck #Quack
|
name: mallard duck #Quack
|
||||||
@@ -237,6 +244,13 @@
|
|||||||
path: /Audio/Animals/duck_quack_happy.ogg
|
path: /Audio/Animals/duck_quack_happy.ogg
|
||||||
- type: Bloodstream
|
- type: Bloodstream
|
||||||
bloodMaxVolume: 100
|
bloodMaxVolume: 100
|
||||||
|
- type: EggLayer
|
||||||
|
eggSpawn:
|
||||||
|
- id: FoodEgg
|
||||||
|
- type: ReplacementAccent
|
||||||
|
accent: duck
|
||||||
|
- type: SentienceTarget
|
||||||
|
flavorKind: organic
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
name: white duck #Quack
|
name: white duck #Quack
|
||||||
|
|||||||
@@ -62,3 +62,19 @@
|
|||||||
- accent-words-generic-aggressive-2
|
- accent-words-generic-aggressive-2
|
||||||
- accent-words-generic-aggressive-3
|
- accent-words-generic-aggressive-3
|
||||||
- accent-words-generic-aggressive-4
|
- accent-words-generic-aggressive-4
|
||||||
|
|
||||||
|
- type: accent
|
||||||
|
id: duck
|
||||||
|
words:
|
||||||
|
- accent-words-duck-1
|
||||||
|
- accent-words-duck-2
|
||||||
|
- accent-words-duck-3
|
||||||
|
- accent-words-duck-4
|
||||||
|
|
||||||
|
- type: accent
|
||||||
|
id: chicken
|
||||||
|
words:
|
||||||
|
- accent-words-chicken-1
|
||||||
|
- accent-words-chicken-2
|
||||||
|
- accent-words-chicken-3
|
||||||
|
- accent-words-chicken-4
|
||||||
|
|||||||
Reference in New Issue
Block a user