Add static "IsPowered" method (#8434)

* Add static "IsPowered" method

* Use IsPowered in more places

Co-authored-by: wrexbe <wrexbe@protonmail.com>
This commit is contained in:
metalgearsloth
2022-05-27 10:36:12 +10:00
committed by GitHub
parent 33c03fa0a0
commit 2d873a2cf2
20 changed files with 104 additions and 141 deletions

View File

@@ -1,6 +1,7 @@
using Content.Server.Botany.Components;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Shared.Interaction;
using Robust.Shared.Player;
using Robust.Shared.Random;
@@ -22,29 +23,27 @@ public sealed class SeedExtractorSystem : EntitySystem
private void OnInteractUsing(EntityUid uid, SeedExtractorComponent component, InteractUsingEvent args)
{
if (!TryComp<ApcPowerReceiverComponent>(uid, out var powerReceiverComponent) || !powerReceiverComponent.Powered)
if (!this.IsPowered(uid, EntityManager))
return;
if (TryComp(args.Used, out ProduceComponent? produce))
if (!TryComp(args.Used, out ProduceComponent? produce)) return;
if (!_botanySystem.TryGetSeed(produce, out var seed))
return;
_popupSystem.PopupCursor(Loc.GetString("seed-extractor-component-interact-message",("name", args.Used)),
Filter.Entities(args.User));
QueueDel(args.Used);
var random = _random.Next(component.MinSeeds, component.MaxSeeds);
var coords = Transform(uid).Coordinates;
if (random > 1)
seed.Unique = false;
for (var i = 0; i < random; i++)
{
if (!_botanySystem.TryGetSeed(produce, out var seed))
return;
_popupSystem.PopupCursor(Loc.GetString("seed-extractor-component-interact-message",("name", args.Used)),
Filter.Entities(args.User));
QueueDel(args.Used);
var random = _random.Next(component.MinSeeds, component.MaxSeeds);
var coords = Transform(uid).Coordinates;
if (random > 1)
seed.Unique = false;
for (var i = 0; i < random; i++)
{
_botanySystem.SpawnSeedPacket(seed, coords);
}
_botanySystem.SpawnSeedPacket(seed, coords);
}
}
}