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 6 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
56 changes: 20 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,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;
}

Expand All @@ -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
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 Expand Up @@ -35,7 +34,9 @@ private void OnAlive(EntityUid uid, SiliconEmitSoundOnDrainedComponent component

public void OnStateChange(EntityUid uid, SiliconEmitSoundOnDrainedComponent component, MobStateChangedEvent args)
{
if (args.NewMobState == MobState.Dead)
RemComp<SpamEmitSoundComponent>(uid);
if (args.NewMobState != MobState.Dead)
return;

RemComp<SpamEmitSoundComponent>(uid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
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
39 changes: 17 additions & 22 deletions Content.Server/Silicon/BlindHealing/BlindHealingComponent.cs
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;
}
Loading
Loading