Files
wwdpublic/Content.Server/Animals/Systems/WoolySystem.cs
Spatison 1cd5b0ac0a [Fix] Massive Bug Fixes / Массовое Исправление Багов (#131)
* fix

* fix

* fix

* fix

* fix

* Fix Bug with Opening Storage Containers (#1292)

<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

# Description

<!--
Explain this PR in as much detail as applicable

Some example prompts to consider:
How might this affect the game? The codebase?
What might be some alternatives to this?
How/Who does this benefit/hurt [the game/codebase]?
-->

Fixes the bug with opening storage containers while there's already one
opened.

---

# Changelog

<!--
You can add an author after the `🆑` to change the name that appears
in the changelog (ex: `🆑 Death`)
Leaving it blank will default to your GitHub display name
This includes all available types for the changelog
-->

🆑
- fix: Fixed the bug with opening storage containers while there's
already one open.

(cherry picked from commit b0407604ced2859ccbdc417345dadc29656f71f0)

* Automatic Changelog Update (#1292)

(cherry picked from commit 9a40c3783eb0d0e622badc2febcaf0794f6f8ddd)

* possible test fix

* possible test fix

* fix

---------

Co-authored-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com>
Co-authored-by: SimpleStation Changelogs <simplestation14@users.noreply.github.com>
2024-12-01 20:41:08 +07:00

68 lines
2.3 KiB
C#

using Content.Server.Animals.Components;
using Content.Server.Chemistry.Containers.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;
/// <summary>
/// Gives ability to produce fiber reagents, produces endless 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 SolutionContainerSystem _solutionContainer = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<WoolyComponent, BeforeFullyEatenEvent>(OnBeforeFullyEaten);
}
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)
continue;
wooly.NextGrowth = now + wooly.GrowthDelay;
if (_mobState.IsDead(uid))
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);
}
if (!_solutionContainer.ResolveSolution(uid, wooly.SolutionName, ref wooly.Solution))
continue;
_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();
}
}