Skip to content
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

Merged
merged 7 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Content.Server/Administration/Commands/SetOutfitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Content.Server.Silicon.IPC;
using Content.Shared.Radio.Components;

namespace Content.Server.Administration.Commands
{
Expand Down Expand Up @@ -127,7 +128,12 @@ public static bool SetOutfit(EntityUid target, string gear, IEntityManager entit
handsSystem.TryPickup(target, inhandEntity, checkActionBlocker: false, handsComp: handsComponent);
}
}
InternalEncryptionKeySpawner.TryInsertEncryptionKey(target, startingGear, entityManager, profile);

if (entityManager.HasComponent<EncryptionKeyHolderComponent>(target))
{
var encryption = new InternalEncryptionKeySpawner();
Copy link
Contributor

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.

encryption.TryInsertEncryptionKey(target, startingGear, entityManager);
}
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.ComponentModel.DataAnnotations;
using Robust.Shared.Audio;
using Content.Server.Sound.Components;

namespace Content.Server.Silicon;

Expand Down
57 changes: 21 additions & 36 deletions Content.Server/Power/Systems/BatteryDrinkerSystem.cs
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;
Expand All @@ -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()
Expand All @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out var drinkerBattery is not used anywhere in the code after you get it. You should either remove the check entirely or mark variable as not used (out _)


AlternativeVerb verb = new()
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sourceComp can't be null since TryComp<BatteryDrinkerSourceComponent>(args.Target.Value, out var sourceComp) already checks for it.

|| container.ContainedEntities is null)
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this checks should probably go in order from args.Target.Value checks to uid checks to increase readability.


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;
}

Expand All @@ -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
Expand Up @@ -4,7 +4,6 @@
using Content.Server.Power.EntitySystems;
using Content.Shared.Electrocution;
using Robust.Shared.Random;
using Robust.Shared.Timing;

namespace Content.Server.Power.Systems;

Expand All @@ -26,10 +25,10 @@ private void OnElectrocuted(EntityUid uid, BatteryComponent battery, Electrocute
if (args.ShockDamage == null || args.ShockDamage <= 0)
return;

var damagePerWatt = ElectrocutionSystem.ElectrifiedDamagePerWatt * 2;

var damage = args.ShockDamage.Value * args.SiemensCoefficient;
var charge = Math.Min(damage / damagePerWatt, battery.MaxCharge * 0.25f) * _random.NextFloat(0.75f, 1.25f);
var charge = Math.Min(args.ShockDamage.Value * args.SiemensCoefficient
/ ElectrocutionSystem.ElectrifiedDamagePerWatt * 2,
battery.MaxCharge * 0.25f)
* _random.NextFloat(0.75f, 1.25f);

_battery.SetCharge(uid, battery.CurrentCharge + charge);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Content.Shared.Sound.Components;
using Content.Server.Sound;
using Content.Shared.Mobs;
using Content.Shared.Silicon.Systems;

namespace Content.Server.Silicon;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
}

Expand Down
4 changes: 0 additions & 4 deletions Content.Server/Silicon/BlindHealing/BlindHealingComponent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using Content.Shared.Damage;
using Content.Shared.Tools;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Server.Silicon.BlindHealing
{
[RegisterComponent]
Expand Down
58 changes: 18 additions & 40 deletions Content.Server/Silicon/BlindHealing/BlindHealingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ namespace Content.Server.Silicon.BlindHealing
public sealed class BlindHealingSystem : SharedBlindHealingSystem
{
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly IAdminLogManager _adminLogger= default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly BlindableSystem _blindableSystem = default!;
[Dependency] private readonly StackSystem _stackSystem = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;

public override void Initialize()
Expand All @@ -32,27 +31,16 @@ public override void Initialize()

private void OnHealingFinished(EntityUid uid, BlindHealingComponent component, HealingDoAfterEvent args)
{
Log.Info("event started!");

if (args.Cancelled || args.Target == null)
if (args.Cancelled || args.Target == null
|| !TryComp<BlindableComponent>(args.Target, out var blindComp)
|| blindComp is { EyeDamage: 0 })
return;

EntityUid target = (EntityUid) args.Target;

if(!EntityManager.TryGetComponent(target, out BlindableComponent? blindcomp)
|| blindcomp is { EyeDamage: 0 })
return;

if(EntityManager.TryGetComponent(uid, out StackComponent? stackComponent))
{
double price = 1;
if (EntityManager.TryGetComponent(uid, out StackPriceComponent? stackPrice))
price = stackPrice.Price;
_stackSystem.SetCount(uid, (int) (_stackSystem.GetCount(uid, stackComponent) - price), stackComponent);

}
if (TryComp<StackComponent>(uid, out var stackComponent)
&& TryComp<StackPriceComponent>(uid, out var stackPrice))
_stackSystem.SetCount(uid, (int) (_stackSystem.GetCount(uid, stackComponent) - stackPrice.Price), stackComponent);

_blindableSystem.AdjustEyeDamage((target, blindcomp), -blindcomp!.EyeDamage);
_blindableSystem.AdjustEyeDamage((args.Target.Value, blindComp), -blindComp.EyeDamage);

_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target}'s vision");

Expand Down Expand Up @@ -82,40 +70,30 @@ private void OnInteract(EntityUid uid, BlindHealingComponent component, ref Afte

if (args.Handled
|| !TryComp(args.User, out DamageableComponent? damageable)
|| damageable.DamageContainerID != null
&& !component.DamageContainers.Contains(damageable.DamageContainerID)
|| damageable.DamageContainerID != null && !component.DamageContainers.Contains(damageable.DamageContainerID)
|| !TryComp(args.User, out BlindableComponent? blindcomp)
|| blindcomp is { EyeDamage: 0 })
|| blindcomp is { EyeDamage: 0 }
|| args.User == args.Target && !component.AllowSelfHeal)
return;

float delay = component.DoAfterDelay;

if (args.User == args.Target)
{
if (!component.AllowSelfHeal)
return;
delay *= component.SelfHealPenalty;
}

TryHealBlindness(uid, args.User, args.User, delay);
TryHealBlindness(uid, args.User, args.User,
args.User == args.Target
? component.DoAfterDelay * component.SelfHealPenalty
: component.DoAfterDelay);
}

private void OnUse(EntityUid uid, BlindHealingComponent component, ref UseInHandEvent args)
{
if (args.Handled
|| !TryComp(args.User, out DamageableComponent? damageable)
|| damageable.DamageContainerID != null
&& !component.DamageContainers.Contains(damageable.DamageContainerID)
|| damageable.DamageContainerID != null && !component.DamageContainers.Contains(damageable.DamageContainerID)
|| !TryComp(args.User, out BlindableComponent? blindcomp)
|| blindcomp is { EyeDamage: 0 }
|| !component.AllowSelfHeal)
return;

float delay = component.DoAfterDelay;
delay *= component.SelfHealPenalty;

TryHealBlindness(uid, args.User, args.User, delay);

TryHealBlindness(uid, args.User, args.User,
component.DoAfterDelay * component.SelfHealPenalty);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Threading;

namespace Content.Server.Silicon.Death;

/// <summary>
Expand All @@ -15,5 +13,5 @@ public sealed partial class SiliconDownOnDeadComponent : Component
/// Is this Silicon currently dead?
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
public bool Dead { get; set; } = false;
public bool Dead;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void OnSiliconChargeStateUpdate(EntityUid uid, SiliconDownOnDeadComponen
if (args.ChargePercent == 0 && !siliconDeadComp.Dead)
SiliconDead(uid, siliconDeadComp, batteryComp, uid);
else if (args.ChargePercent != 0 && siliconDeadComp.Dead)
SiliconUnDead(uid, siliconDeadComp, batteryComp, uid);
SiliconUnDead(uid, siliconDeadComp, batteryComp, uid);
}

private void SiliconDead(EntityUid uid, SiliconDownOnDeadComponent siliconDeadComp, BatteryComponent? batteryComp, EntityUid batteryUid)
Expand All @@ -54,7 +54,7 @@ private void SiliconDead(EntityUid uid, SiliconDownOnDeadComponent siliconDeadCo
EntityManager.EnsureComponent<SleepingComponent>(uid);
EntityManager.EnsureComponent<ForcedSleepingComponent>(uid);

if (TryComp(uid, out HumanoidAppearanceComponent? humanoidAppearanceComponent))
if (TryComp<HumanoidAppearanceComponent>(uid, out var humanoidAppearanceComponent))
{
var layers = HumanoidVisualLayersExtension.Sublayers(HumanoidVisualLayers.HeadSide);
_humanoidAppearanceSystem.SetLayersVisibility(uid, layers, false, true, humanoidAppearanceComponent);
Expand Down
Loading
Loading