-
Notifications
You must be signed in to change notification settings - Fork 165
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
IPC Refactor #771
IPC Refactor #771
Changes from 5 commits
ccdb5c3
7245e0a
d777715
8713534
4c6c2a1
2b4fa5b
e1aaecb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using Content.Server.Power.Components; | ||
using Content.Shared.Containers.ItemSlots; | ||
|
@@ -12,22 +11,18 @@ | |
using Content.Server.Popups; | ||
using Content.Server.PowerCell; | ||
using Content.Shared.Popups; | ||
using Content.Shared.Silicon.Components; | ||
using FastAccessors; | ||
using Robust.Shared.Audio.Systems; | ||
using Robust.Shared.Containers; | ||
|
||
namespace Content.Server.Power; | ||
|
||
public sealed class BatteryDrinkerSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly ItemSlotsSystem _slots = default!; | ||
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!; | ||
[Dependency] private readonly SharedAudioSystem _audio = default!; | ||
[Dependency] private readonly BatterySystem _battery = default!; | ||
[Dependency] private readonly SiliconChargeSystem _silicon = default!; | ||
[Dependency] private readonly PopupSystem _popup = default!; | ||
[Dependency] private readonly PowerCellSystem _powerCell = default!; | ||
[Dependency] private readonly SharedContainerSystem _container = default!; | ||
|
||
public override void Initialize() | ||
|
@@ -41,12 +36,10 @@ public override void Initialize() | |
|
||
private void AddAltVerb(EntityUid uid, BatteryComponent batteryComponent, GetVerbsEvent<AlternativeVerb> args) | ||
{ | ||
if (!args.CanAccess || !args.CanInteract) | ||
return; | ||
|
||
if (!TryComp<BatteryDrinkerComponent>(args.User, out var drinkerComp) || | ||
!TestDrinkableBattery(uid, drinkerComp) || | ||
!_silicon.TryGetSiliconBattery(args.User, out var drinkerBattery)) | ||
if (!args.CanAccess || !args.CanInteract | ||
|| !TryComp<BatteryDrinkerComponent>(args.User, out var drinkerComp) | ||
|| !TestDrinkableBattery(uid, drinkerComp) | ||
|| !_silicon.TryGetSiliconBattery(args.User, out var drinkerBattery)) | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
AlternativeVerb verb = new() | ||
|
@@ -80,6 +73,7 @@ private void DrinkBattery(EntityUid target, EntityUid user, BatteryDrinkerCompon | |
{ | ||
BreakOnDamage = true, | ||
BreakOnTargetMove = true, | ||
BreakOnUserMove = true, | ||
Broadcast = false, | ||
DistanceThreshold = 1.35f, | ||
RequireCanInteract = true, | ||
|
@@ -91,39 +85,29 @@ private void DrinkBattery(EntityUid target, EntityUid user, BatteryDrinkerCompon | |
|
||
private void OnDoAfter(EntityUid uid, BatteryDrinkerComponent drinkerComp, DoAfterEvent args) | ||
{ | ||
if (args.Cancelled || args.Target == null) | ||
if (args.Cancelled || args.Target == null | ||
|| !TryComp<BatteryComponent>(args.Target.Value, out var sourceBattery) | ||
|| !_silicon.TryGetSiliconBattery(uid, out var drinkerBatteryComponent) | ||
|| !TryComp(uid, out PowerCellSlotComponent? batterySlot) | ||
|| !TryComp<BatteryDrinkerSourceComponent>(args.Target.Value, out var sourceComp) | ||
|| sourceComp is null | ||
|| !_container.TryGetContainer(uid, batterySlot.CellSlotId, out var container) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|| container.ContainedEntities is null) | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also this checks should probably go in order from |
||
|
||
var source = args.Target.Value; | ||
var drinker = uid; | ||
var sourceBattery = Comp<BatteryComponent>(source); | ||
|
||
_silicon.TryGetSiliconBattery(drinker, out var drinkerBatteryComponent); | ||
|
||
if (!TryComp(uid, out PowerCellSlotComponent? batterySlot)) | ||
return; | ||
|
||
var container = _container.GetContainer(uid, batterySlot.CellSlotId); | ||
var drinkerBattery = container.ContainedEntities.First(); | ||
|
||
TryComp<BatteryDrinkerSourceComponent>(source, out var sourceComp); | ||
|
||
DebugTools.AssertNotNull(drinkerBattery); | ||
|
||
if (drinkerBattery == null) | ||
return; | ||
|
||
var amountToDrink = drinkerComp.DrinkMultiplier * 1000; | ||
|
||
amountToDrink = MathF.Min(amountToDrink, sourceBattery.CurrentCharge); | ||
amountToDrink = MathF.Min(amountToDrink, drinkerBatteryComponent!.MaxCharge - drinkerBatteryComponent.CurrentCharge); | ||
|
||
if (sourceComp != null && sourceComp.MaxAmount > 0) | ||
if (sourceComp.MaxAmount > 0) | ||
amountToDrink = MathF.Min(amountToDrink, (float) sourceComp.MaxAmount); | ||
|
||
if (amountToDrink <= 0) | ||
{ | ||
_popup.PopupEntity(Loc.GetString("battery-drinker-empty", ("target", source)), drinker, drinker); | ||
_popup.PopupEntity(Loc.GetString("battery-drinker-empty", ("target", source)), uid, uid); | ||
return; | ||
} | ||
|
||
|
@@ -135,10 +119,11 @@ private void OnDoAfter(EntityUid uid, BatteryDrinkerComponent drinkerComp, DoAft | |
_battery.SetCharge(source, 0); | ||
} | ||
|
||
if (sourceComp != null && sourceComp.DrinkSound != null){ | ||
_popup.PopupEntity(Loc.GetString("ipc-recharge-tip"), drinker, drinker, PopupType.SmallCaution); | ||
_audio.PlayPvs(sourceComp.DrinkSound, source); | ||
Spawn("EffectSparks", Transform(source).Coordinates); | ||
} | ||
if (sourceComp.DrinkSound is null) | ||
return; | ||
|
||
_popup.PopupEntity(Loc.GetString("ipc-recharge-tip"), uid, uid, PopupType.SmallCaution); | ||
_audio.PlayPvs(sourceComp.DrinkSound, source); | ||
Spawn("EffectSparks", Transform(source).Coordinates); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,27 +2,27 @@ | |
using Content.Shared.Lock; | ||
using Content.Shared.Popups; | ||
using Content.Shared.Silicon.Components; | ||
using Content.Shared.IdentityManagement; | ||
using Content.Shared.IdentityManagement; | ||
|
||
namespace Content.Server.Silicon.BatteryLocking; | ||
|
||
public sealed class BatterySlotRequiresLockSystem : EntitySystem | ||
|
||
{ | ||
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!; | ||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!; | ||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!; | ||
|
||
/// <inheritdoc/> | ||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<BatterySlotRequiresLockComponent, LockToggledEvent>(LockToggled); | ||
SubscribeLocalEvent<BatterySlotRequiresLockComponent, LockToggleAttemptEvent>(LockToggleAttempted); | ||
|
||
SubscribeLocalEvent<BatterySlotRequiresLockComponent, LockToggleAttemptEvent>(LockToggleAttempted); | ||
} | ||
|
||
private void LockToggled(EntityUid uid, BatterySlotRequiresLockComponent component, LockToggledEvent args) | ||
{ | ||
if (!TryComp<LockComponent>(uid, out var lockComp) | ||
if (!TryComp<LockComponent>(uid, out var lockComp) | ||
|| !TryComp<ItemSlotsComponent>(uid, out var itemslots) | ||
|| !_itemSlotsSystem.TryGetSlot(uid, component.ItemSlot, out var slot, itemslots)) | ||
return; | ||
|
@@ -33,9 +33,9 @@ private void LockToggled(EntityUid uid, BatterySlotRequiresLockComponent compone | |
private void LockToggleAttempted(EntityUid uid, BatterySlotRequiresLockComponent component, LockToggleAttemptEvent args) | ||
{ | ||
if (args.User == uid | ||
|| !TryComp<SiliconComponent>(uid, out var siliconComp)) | ||
|| !HasComp<SiliconComponent>(uid)) | ||
Comment on lines
34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just for the style - it should be on the same line since it's not that long. |
||
return; | ||
|
||
_popupSystem.PopupEntity(Loc.GetString("batteryslotrequireslock-component-alert-owner", ("user", Identity.Entity(args.User, EntityManager))), uid, uid, PopupType.Large); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really a good approach to make a new instance of EntitySystem? You should use
IoC
instead.