Sericulture fixes (#19193)

* redone

* I FUCKING HATE SPAWNING STUFF IN SHARED

* inheritdoc

* owo

* fly broken wings

* From a server event to just an event.

* more info

* a comment and a different comment

* Partial

* Emo's requested changes.

* wuh

* head ache

* they call me mean names (laugh track)
This commit is contained in:
PixelTK
2023-10-01 21:46:09 +01:00
committed by GitHub
parent d15b7dff42
commit dfda2dbd05
7 changed files with 195 additions and 124 deletions

View File

@@ -1,89 +1,7 @@
using Content.Server.Actions;
using Content.Server.DoAfter;
using Content.Server.Popups;
using Content.Server.Stack;
using Content.Shared.DoAfter;
using Content.Shared.Nutrition.Components;
using Content.Shared.Nutrition.EntitySystems;
using Content.Shared.Sericulture;
namespace Content.Server.Sericulture;
public sealed partial class SericultureSystem : EntitySystem
public sealed partial class SericultureSystem : SharedSericultureSystem
{
[Dependency] private readonly ActionsSystem _actionsSystem = default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly HungerSystem _hungerSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly StackSystem _stackSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SericultureComponent, MapInitEvent>(OnCompMapInit);
SubscribeLocalEvent<SericultureComponent, ComponentShutdown>(OnCompRemove);
SubscribeLocalEvent<SericultureComponent, SericultureActionEvent>(OnSericultureStart);
SubscribeLocalEvent<SericultureComponent, SericultureDoAfterEvent>(OnSericultureDoAfter);
}
private void OnCompMapInit(EntityUid uid, SericultureComponent comp, MapInitEvent args)
{
_actionsSystem.AddAction(uid, ref comp.ActionEntity, comp.Action, uid);
}
private void OnCompRemove(EntityUid uid, SericultureComponent comp, ComponentShutdown args)
{
_actionsSystem.RemoveAction(uid, comp.ActionEntity);
}
private void OnSericultureStart(EntityUid uid, SericultureComponent comp, SericultureActionEvent args)
{
if (IsHungry(uid))
{
_popupSystem.PopupEntity(Loc.GetString(comp.PopupText), uid, uid);
return;
}
var doAfter = new DoAfterArgs(EntityManager, uid, comp.ProductionLength, new SericultureDoAfterEvent(), uid)
{
BreakOnUserMove = true,
BlockDuplicate = true,
BreakOnDamage = true,
CancelDuplicate = true,
};
_doAfterSystem.TryStartDoAfter(doAfter);
}
private void OnSericultureDoAfter(EntityUid uid, SericultureComponent comp, SericultureDoAfterEvent args)
{
if (args.Cancelled || args.Handled || comp.Deleted)
return;
if (IsHungry(uid))
{
_popupSystem.PopupEntity(Loc.GetString(comp.PopupText), uid, uid);
return;
}
_hungerSystem.ModifyHunger(uid, -comp.HungerCost);
var newEntity = Spawn(comp.EntityProduced, Transform(uid).Coordinates);
_stackSystem.TryMergeToHands(newEntity, uid);
args.Repeat = true;
}
private bool IsHungry(EntityUid uid, HungerComponent? comp = null)
{
if (!Resolve(uid, ref comp))
return false;
if (_hungerSystem.GetHungerThreshold(comp) <= HungerThreshold.Peckish)
return true;
return false;
}
}