Skip to content

Commit

Permalink
Lots of general improvements to the systems, lots of cleanup.
Browse files Browse the repository at this point in the history
Clean, Medi, and Honk bots all use battery cell slots, which SiliconSystem now supports.
To support external batteries entirely sometime.
  • Loading branch information
Pspritechologist committed Jun 24, 2023
1 parent 564258b commit f7cca4f
Show file tree
Hide file tree
Showing 31 changed files with 250 additions and 155 deletions.
2 changes: 1 addition & 1 deletion Content.Server/Electrocution/ElectrocutionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
private const string DamageType = "Shock";

// Yes, this is absurdly small for a reason.
public const float ElectrifiedDamagePerWatt = 0.0015f; // Parkstation-IPC
public const float ElectrifiedDamagePerWatt = 0.0015f; // Parkstation-IPC // This information is allowed to be public, and was needed in BatteryElectrocuteChargeSystem.cs

private const float RecursiveDamageMultiplier = 0.75f;
private const float RecursiveTimeMultiplier = 0.8f;
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Nyanotrasen/Borgs/CyborgComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ namespace Content.Server.Borgs
[RegisterComponent]
public sealed class CyborgComponent : Component
{}
}
}
6 changes: 3 additions & 3 deletions Content.Server/Nyanotrasen/Borgs/CyborgSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override void Initialize()
base.Initialize();
SubscribeLocalEvent<CyborgComponent, MobStateChangedEvent>(OnChangeState);
}

private void OnChangeState(EntityUid uid, CyborgComponent component, MobStateChangedEvent args)
{
if (args.NewMobState == MobState.Dead){
Expand All @@ -28,7 +28,7 @@ private void OnChangeState(EntityUid uid, CyborgComponent component, MobStateCha

// Stop dead borg from being movable AA cards by removing their ability to bump doors.
_tagSystem.RemoveTag(uid, "DoorBumpOpener");

}
else if(args.NewMobState == MobState.Alive && args.OldMobState == MobState.Dead)
{
Expand All @@ -39,4 +39,4 @@ private void OnChangeState(EntityUid uid, CyborgComponent component, MobStateCha
return;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Robust.Shared.Audio;

namespace Content.Server.SimpleStation14.Power;

[RegisterComponent]
public class BatteryDrinkerComponent : Component
public sealed class BatteryDrinkerComponent : Component
{
/// <summary>
/// Is this drinker allowed to drink batteries not tagged as <see cref="BatteryDrinkSource"/>?
Expand All @@ -26,16 +24,8 @@ public class BatteryDrinkerComponent : Component
public float DrinkMultiplier = 5f;

/// <summary>
/// The sound to override the standard drink sound with.
/// Uses per source sound if null.
/// </summary>
[DataField("drinkSoundOverride")]
public SoundSpecifier? DrinkSound = new SoundPathSpecifier("/Audio/Items/drink.ogg");

/// <summary>
/// The localised string to display when drinking from a battery.
/// Doesn't _need_ to be localised, but come on, man.
/// The multiplier for how long it takes to drink a non-source battery, if <see cref="DrinkAll"/> is true.
/// </summary>
[DataField("drinkText")]
public string DrinkText = "aaaaaaaaaa";
[DataField("drinkAllMultiplier"), ViewVariables(VVAccess.ReadWrite)]
public float DrinkAllMultiplier = 2.5f;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Content.Server.SimpleStation14.Power.Components;

[RegisterComponent]
public class RandomBatteryChargeComponent : Component
public sealed class RandomBatteryChargeComponent : Component
{
/// <summary>
/// The minimum and maximum max charge the battery can have.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
using Content.Server.Power.Components;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.DoAfter;
using Content.Shared.Interaction.Helpers;
using Content.Shared.PowerCell.Components;
using Content.Shared.SimpleStation14.Silicon;
using Content.Shared.Verbs;
using Robust.Shared.Audio;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Content.Server.SimpleStation14.Silicon.Charge;
using Content.Server.Power.EntitySystems;
using Content.Server.Popups;

namespace Content.Server.SimpleStation14.Power;

Expand All @@ -21,31 +19,32 @@ public sealed class BatteryDrinkerSystem : EntitySystem
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly BatterySystem _battery = default!;
[Dependency] private readonly SiliconChargeSystem _silicon = default!;
[Dependency] private readonly PopupSystem _popup = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<BatteryComponent, GetVerbsEvent<AlternativeVerb>>(AddAltVerb);

SubscribeLocalEvent<BatteryDrinkerComponent, BatteryDrinkerEvent>(OnDoAfter);
SubscribeLocalEvent<BatteryDrinkerComponent, BatteryDrinkerDoAfterEvent>(OnDoAfter);
}

private void AddAltVerb(EntityUid uid, BatteryComponent batteryComponent, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanAccess || !args.CanInteract)
return;

if (!EntityManager.TryGetComponent<BatteryDrinkerComponent>(args.User, out var drinkerComp) ||
if (!TryComp<BatteryDrinkerComponent>(args.User, out var drinkerComp) ||
!TestDrinkableBattery(uid, drinkerComp) ||
!TryGetFillableBattery(args.User, out var drinkerBattery))
!TryGetFillableBattery(args.User, out var drinkerBattery, out _))
return;

AlternativeVerb verb = new()
{
Act = () => DrinkBattery(uid, args.User, drinkerComp),
Text = "system-battery-drinker-verb-drink",
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/VerbIcons/drink.svg.192dpi.png")),
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/VerbIcons/smite.svg.192dpi.png")),
};

args.Verbs.Add(verb);
Expand All @@ -59,19 +58,22 @@ private bool TestDrinkableBattery(EntityUid target, BatteryDrinkerComponent drin
return true;
}

private bool TryGetFillableBattery(EntityUid uid, [NotNullWhen(true)] out BatteryComponent? battery)
private bool TryGetFillableBattery(EntityUid uid, [NotNullWhen(true)] out BatteryComponent? battery, [NotNullWhen(true)] out EntityUid batteryUid)
{
if (_silicon.TryGetSiliconBattery(uid, out battery))
if (_silicon.TryGetSiliconBattery(uid, out battery, out batteryUid))
return true;

if (EntityManager.TryGetComponent(uid, out battery))
if (TryComp(uid, out battery))
return true;

if (EntityManager.TryGetComponent<PowerCellSlotComponent>(uid, out var powerCellSlot) &&
if (TryComp<PowerCellSlotComponent>(uid, out var powerCellSlot) &&
_slots.TryGetSlot(uid, powerCellSlot.CellSlotId, out var slot) &&
slot.Item != null &&
EntityManager.TryGetComponent(slot.Item.Value, out battery))
TryComp(slot.Item.Value, out battery))
{
batteryUid = slot.Item.Value;
return true;
}

return false;
}
Expand All @@ -80,12 +82,12 @@ private void DrinkBattery(EntityUid target, EntityUid user, BatteryDrinkerCompon
{
var doAfterTime = drinkerComp.DrinkSpeed;

if (EntityManager.TryGetComponent<BatteryDrinkerSourceComponent>(target, out var sourceComp))
if (TryComp<BatteryDrinkerSourceComponent>(target, out var sourceComp))
doAfterTime *= sourceComp.DrinkSpeedMulti;
else
doAfterTime *= 2.5f;
doAfterTime *= drinkerComp.DrinkAllMultiplier;

var args = new DoAfterArgs(user, doAfterTime, new BatteryDrinkerEvent(), user, target)
var args = new DoAfterArgs(user, doAfterTime, new BatteryDrinkerDoAfterEvent(), user, target) // TODO: Make this doafter loop, once we merge Upstream.
{
BreakOnDamage = true,
BreakOnTargetMove = true,
Expand All @@ -105,11 +107,11 @@ private void OnDoAfter(EntityUid uid, BatteryDrinkerComponent drinkerComp, DoAft

var source = args.Target.Value;
var drinker = uid;
var sourceBattery = EntityManager.GetComponent<BatteryComponent>(source);
var sourceBattery = Comp<BatteryComponent>(source);

TryGetFillableBattery(drinker, out var drinkerBattery);
TryGetFillableBattery(drinker, out var drinkerBattery, out var drinkerBatteryUid);

EntityManager.TryGetComponent<BatteryDrinkerSourceComponent>(source, out var sourceComp);
TryComp<BatteryDrinkerSourceComponent>(source, out var sourceComp);

DebugTools.AssertNotNull(drinkerBattery);

Expand All @@ -126,26 +128,19 @@ private void OnDoAfter(EntityUid uid, BatteryDrinkerComponent drinkerComp, DoAft

if (amountToDrink <= 0)
{
// Do empty stuff
_popup.PopupEntity(Loc.GetString("battery-drinker-empty", ("target", source)), drinker, drinker);
return;
}

if (_battery.TryUseCharge(source, amountToDrink, sourceBattery))
{
_battery.SetCharge(source, drinkerBattery.Charge + amountToDrink, sourceBattery);
}
_battery.SetCharge(drinkerBatteryUid, drinkerBattery.Charge + amountToDrink, drinkerBattery);
else
{
_battery.SetCharge(drinker, sourceBattery.Charge, drinkerBattery);
_battery.SetCharge(drinker, sourceBattery.Charge + drinkerBattery.Charge, drinkerBattery);
_battery.SetCharge(source, 0, sourceBattery);
}

var sound = drinkerComp.DrinkSound ?? sourceComp?.DrinkSound;

if (sound != null)
_audio.PlayPvs(sound, source);

// if (sourceBattery.CurrentCharge > 0) // Make use proper looping doafters when we merge Upstream.
// DrinkBattery(source, drinker, sourceBattery, drinkerBattery, drinkerComp);
if (sourceComp != null && sourceComp.DrinkSound != null)
_audio.PlayPvs(sourceComp.DrinkSound, source);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Server.Electrocution;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Shared.Electrocution;
using Robust.Shared.Random;
using Robust.Shared.Timing;
Expand All @@ -11,7 +12,7 @@ public sealed class BatteryElectrocuteChargeSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly BatterySystem _battery = default!;

public override void Initialize()
{
Expand All @@ -30,7 +31,7 @@ private void OnElectrocuted(EntityUid uid, BatteryComponent battery, Electrocute
var damage = args.ShockDamage.Value * args.SiemensCoefficient;
var charge = Math.Min(damage / damagePerWatt, battery.MaxCharge * 0.25f) * _random.NextFloat(0.75f, 1.25f);

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

_popup.PopupEntity(Loc.GetString("battery-electrocute-charge"), uid, uid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private void OnReceiverChannelsChanged(EntityUid uid, ActiveRadioComponent compo
UpdateChannels(uid, args.Component, ref component.Channels);
}

private void UpdateChannels(EntityUid uid, EncryptionKeyHolderComponent keyHolderComp, ref HashSet<string> channels)
private void UpdateChannels(EntityUid _, EncryptionKeyHolderComponent keyHolderComp, ref HashSet<string> channels)
{
channels.Clear();
channels.UnionWith(keyHolderComp.Channels);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Content.Server.SimpleStation14.Silicon.Charge;

[RegisterComponent]
public class BatteryDrinkerSourceComponent : Component
public sealed class BatteryDrinkerSourceComponent : Component
{
/// <summary>
/// The max amount of power to give when drunk from.
/// The max amount of power this source can provide in one sip.
/// No limit if null.
/// </summary>
[DataField("maxAmount"), ViewVariables(VVAccess.ReadWrite)]
public int? MaxAmount = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
namespace Content.Server.SimpleStation14.Silicon.Death;

/// <summary>
/// Marks a Silicon as becoming incapacitated when they run out of battery charge.
/// </summary>
/// <remarks>
/// Uses the Silicon System's charge states to do so, so make sure they're a battery powered Silicon.
/// </remarks>
[RegisterComponent]
public sealed class SiliconDownOnDeadComponent : Component
{
/// <summary>
/// Is this Silicon currently dead?
/// </summary>
public bool Dead { get; set; } = false;
}
Loading

0 comments on commit f7cca4f

Please sign in to comment.