-
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 6 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,28 @@ 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) | ||
|| !_container.TryGetContainer(uid, batterySlot.CellSlotId, out var container) | ||
|| container.ContainedEntities is null) | ||
return; | ||
|
||
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 +118,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,26 @@ | |
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 +32,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); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,23 @@ | ||
using Content.Shared.Damage; | ||
using Content.Shared.Tools; | ||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; | ||
namespace Content.Server.Silicon.BlindHealing; | ||
|
||
namespace Content.Server.Silicon.BlindHealing | ||
[RegisterComponent] | ||
public sealed partial class BlindHealingComponent : Component | ||
{ | ||
[RegisterComponent] | ||
public sealed partial class BlindHealingComponent : Component | ||
{ | ||
[DataField] | ||
public int DoAfterDelay = 3; | ||
[DataField] | ||
public int DoAfterDelay = 3; | ||
|
||
/// <summary> | ||
/// A multiplier that will be applied to the above if an entity is repairing themselves. | ||
/// </summary> | ||
[DataField] | ||
public float SelfHealPenalty = 3f; | ||
/// <summary> | ||
/// A multiplier that will be applied to the above if an entity is repairing themselves. | ||
/// </summary> | ||
[DataField] | ||
public float SelfHealPenalty = 3f; | ||
|
||
/// <summary> | ||
/// Whether or not an entity is allowed to repair itself. | ||
/// </summary> | ||
[DataField] | ||
public bool AllowSelfHeal = true; | ||
/// <summary> | ||
/// Whether or not an entity is allowed to repair itself. | ||
/// </summary> | ||
[DataField] | ||
public bool AllowSelfHeal = true; | ||
|
||
[DataField(required: true)] | ||
public List<string> DamageContainers; | ||
} | ||
[DataField(required: true)] | ||
public List<string> DamageContainers; | ||
} |
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.