Skip to content

Commit

Permalink
Fixed the errors and cleaned up a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Pspritechologist committed Jun 19, 2023
1 parent ca94a9d commit 3a2a6c9
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Content.Server.SimpleStation14.Silicon.Charge;
using Content.Server.Power.EntitySystems;

namespace Content.Server.SimpleStation14.Power;

Expand All @@ -18,6 +19,7 @@ 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!;

public override void Initialize()
{
Expand All @@ -40,9 +42,9 @@ private void AddAltVerb(EntityUid uid, BatteryComponent batteryComponent, GetVer

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

args.Verbs.Add(verb);
Expand All @@ -59,8 +61,6 @@ private bool TestDrinkableBattery(EntityUid target, BatteryDrinkerComponent drin

private bool TryGetFillableBattery(EntityUid uid, [NotNullWhen(true)] out BatteryComponent? battery)
{
battery = null;

if (EntityManager.TryGetComponent<BatteryComponent>(uid, out battery))
return true;

Expand All @@ -73,7 +73,7 @@ private bool TryGetFillableBattery(EntityUid uid, [NotNullWhen(true)] out Batter
return false;
}

private void DrinkBattery(EntityUid target, EntityUid user, BatteryComponent batteryComp, BatteryComponent drinkerBatteryComp, BatteryDrinkerComponent drinkerComp)
private void DrinkBattery(EntityUid target, EntityUid user, BatteryDrinkerComponent drinkerComp)
{
var doAfterTime = drinkerComp.DrinkSpeed;

Expand All @@ -92,7 +92,7 @@ private void DrinkBattery(EntityUid target, EntityUid user, BatteryComponent bat
CancelDuplicate = false
};

var doAfter = _doAfter.TryStartDoAfter(args);
_doAfter.TryStartDoAfter(args);
}

private void OnDoAfter(EntityUid uid, BatteryDrinkerComponent drinkerComp, DoAfterEvent args)
Expand Down Expand Up @@ -129,14 +129,14 @@ private void OnDoAfter(EntityUid uid, BatteryDrinkerComponent drinkerComp, DoAft
return;
}

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

var sound = drinkerComp.DrinkSound ?? sourceComp?.DrinkSound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Content.Server.Body.Components;
using Robust.Shared.Utility;
using System.Linq;
using Content.Server.Power.EntitySystems;

namespace Content.Server.SimpleStation14.Silicon.Charge;

Expand All @@ -25,6 +26,7 @@ public sealed class SiliconChargeSystem : EntitySystem
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifierSystem = default!;
[Dependency] private readonly BatterySystem _battery = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -80,7 +82,7 @@ public override void Update(float frameTime)
drainRate += Math.Clamp(drainRateFinalAddi, drainRate * -0.9f, batteryComp.MaxCharge / 240);

// Drain the battery.
batteryComp.UseCharge(frameTime * drainRate);
_battery.UseCharge(silicon, frameTime * drainRate, batteryComp);

// Figure out the current state of the Silicon.
var chargePercent = batteryComp.CurrentCharge / batteryComp.MaxCharge;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
using Content.Server.Explosion.Components;
using Content.Server.Explosion.EntitySystems;
using Content.Server.Hands.Systems;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Storage.Components;
using Content.Shared.PowerCell.Components;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Damage;
using Robust.Shared.Prototypes;
using Content.Shared.Damage.Prototypes;
using Content.Server.Popups;
using Robust.Shared.Player;
using Content.Shared.Hands.Components;
using Content.Shared.Interaction.Components;
using Content.Shared.Inventory;
using Content.Shared.Popups;
using Content.Shared.Power;
using Content.Shared.PowerCell.Components;
using Content.Shared.SimpleStation14.Silicon;
using Content.Shared.SimpleStation14.Silicon.Charge;
using Content.Shared.StepTrigger.Components;
using Content.Shared.Storage.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Physics.Events;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Content.Shared.SimpleStation14.Silicon;
using Robust.Shared.Audio;
using Robust.Server.GameObjects;
using Content.Shared.Inventory;
using Content.Server.Hands.Systems;
using Content.Server.Explosion.Components;
using Content.Server.Explosion.EntitySystems;
using Content.Shared.Interaction.Components;
using Content.Shared.Power;
using Content.Shared.Storage.Components;
using Content.Shared.Hands.Components;
using Content.Shared.SimpleStation14.Silicon.Charge;

namespace Content.Server.SimpleStation14.Silicon.Charge;

public sealed class SiliconChargerSystem : EntitySystem
{
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly IPrototypeManager _prototypes = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly HandsSystem _hands = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly ExplosionSystem _explosion = default!;
[Dependency] private readonly SharedSiliconChargerSystem _sharedCharger = default!;
[Dependency] private readonly BatterySystem _battery = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -95,10 +94,10 @@ public override void Update(float frameTime)
#region Step Trigger Chargers
// Check for any chargers with the StepTriggerComponent.
var stepQuery = EntityQueryEnumerator<SiliconChargerComponent, StepTriggerComponent>();
while (stepQuery.MoveNext(out var uid, out var chargerComp, out var stepTrigger))
while (stepQuery.MoveNext(out var uid, out var chargerComp, out _))
{
if (chargerComp.PresentEntities.Count == 0 ||
(EntityManager.TryGetComponent<ApcPowerReceiverComponent>(uid, out var powerComp) && !powerComp.Powered))
TryComp<ApcPowerReceiverComponent>(uid, out var powerComp) && !powerComp.Powered)
{
if (chargerComp.Active)
{
Expand Down Expand Up @@ -145,7 +144,7 @@ private void HandleChargingEntity(EntityUid entity, float chargeRate, SiliconCha

foreach (var entityToCharge in entitiesToCharge)
{
if (EntityManager.TryGetComponent<BatteryComponent>(entityToCharge, out var batteryComp))
if (EntityManager.TryGetComponent<BatteryComponent>(entityToCharge, out _))
ChargeBattery(entityToCharge, EntityManager.GetComponent<BatteryComponent>(entityToCharge), chargeRate, chargerComp, chargerUid);
else if (EntityManager.TryGetComponent<DamageableComponent>(entityToCharge, out var damageComp))
BurnEntity(entityToCharge, damageComp, frameTime, chargerComp, chargerUid);
Expand All @@ -157,17 +156,17 @@ private List<EntityUid> SearchThroughEntities(EntityUid entity, bool burn = true
var entitiesToCharge = new List<EntityUid>();

// If the given entity has a battery, charge it.
if (!EntityManager.TryGetComponent<UnremoveableComponent>(entity, out var _) &&
if (!EntityManager.TryGetComponent<UnremoveableComponent>(entity, out _) &&
EntityManager.TryGetComponent(entity, out BatteryComponent? batteryComp) &&
batteryComp.CurrentCharge < batteryComp.MaxCharge)
{
entitiesToCharge.Add(entity);
}

// If the given entity contains a battery, charge it.
else if (!EntityManager.TryGetComponent<UnremoveableComponent>(entity, out var _) &&
else if (!EntityManager.TryGetComponent<UnremoveableComponent>(entity, out _) &&
EntityManager.TryGetComponent(entity, out PowerCellSlotComponent? cellSlotComp) &&
_itemSlotsSystem.TryGetSlot(entity, cellSlotComp.CellSlotId, out var slot) &&
_itemSlots.TryGetSlot(entity, cellSlotComp.CellSlotId, out var slot) &&
EntityManager.TryGetComponent<BatteryComponent>(slot.Item, out var cellComp) &&
cellComp.CurrentCharge < cellComp.MaxCharge)
{
Expand Down Expand Up @@ -200,7 +199,7 @@ private List<EntityUid> SearchThroughEntities(EntityUid entity, bool burn = true
}
if (EntityManager.TryGetComponent<ServerStorageComponent>(entity, out var storageComp))
{
foreach ( var containedEntity in storageComp.StoredEntities!)
foreach (var containedEntity in storageComp.StoredEntities!)
{
entitiesToCharge.AddRange(SearchThroughEntities(containedEntity));
}
Expand All @@ -221,44 +220,40 @@ private void ChargeBattery(EntityUid entity, BatteryComponent batteryComp, float
// Do some math so a charger never charges a battery from zero to full in less than 10 seconds, just for the effect of it.
if (chargerComp.ChargeMulti * 10 > batteryComp.MaxCharge / 10)
{
chargeRate /= (chargerComp.ChargeMulti * 10) / (batteryComp.MaxCharge / 10);
chargeRate /= chargerComp.ChargeMulti * 10 / (batteryComp.MaxCharge / 10);
}

if (batteryComp.CurrentCharge + chargeRate < batteryComp.MaxCharge)
batteryComp.CurrentCharge += chargeRate;
_battery.SetCharge(entity, batteryComp.CurrentCharge + chargeRate, batteryComp);
else
batteryComp.CurrentCharge = batteryComp.MaxCharge;
_battery.SetCharge(entity, batteryComp.MaxCharge, batteryComp);

// If the battery is too small, explode it.
if ((batteryComp.MaxCharge - batteryComp.CurrentCharge) * 1.2 + batteryComp.MaxCharge < chargerComp.MinChargeSize)
{
if (EntityManager.TryGetComponent<ExplosiveComponent>(entity, out var explosiveComp))
{
_explosion.TriggerExplosive(entity, explosiveComp);
}
else
{
_explosion.QueueExplosion(entity, "Default", batteryComp.MaxCharge / 50, 1.5f, 200, user: chargerUid);
}
}
}

private void BurnEntity(EntityUid entity, DamageableComponent damageComp, float frameTime, SiliconChargerComponent chargerComp, EntityUid chargerUid)
{
var damage = new DamageSpecifier(_prototypeManager.Index<DamageTypePrototype>("Shock"), frameTime * chargerComp.ChargeMulti / 100);
var damageDealt = _damageableSystem.TryChangeDamage(entity, damage, false, true, damageComp, chargerUid);
chargerComp.warningAccumulator -= frameTime;
var damage = new DamageSpecifier(_prototypes.Index<DamageTypePrototype>(chargerComp.DamageType), frameTime * chargerComp.ChargeMulti / 100);
var damageDealt = _damageable.TryChangeDamage(entity, damage, false, true, damageComp, chargerUid);
chargerComp.WarningAccumulator -= frameTime;

if (damageDealt != null && chargerComp.warningAccumulator <= 0 && damageDealt.Total > 0)
if (damageDealt != null && chargerComp.WarningAccumulator <= 0 && damageDealt.Total > 0)
{
var popupBurn = Loc.GetString("silicon-charger-burn", ("charger", chargerUid), ("entity", entity));
_popup.PopupEntity(popupBurn, entity, PopupType.MediumCaution);
chargerComp.warningAccumulator += 5f;
chargerComp.WarningAccumulator += 5f;
}
}

#region Charger specific
#region Step Trigger Chargers
#region Step Trigger Chargers
// When an entity starts colliding with the charger, add it to the list of entities present on the charger if it has the StepTriggerComponent.
private void OnStartCollide(EntityUid uid, SiliconChargerComponent component, ref StartCollideEvent args)
{
Expand Down Expand Up @@ -294,6 +289,6 @@ private void OnEndCollide(EntityUid uid, SiliconChargerComponent component, ref
component.PresentEntities.Remove(target);
}
}
#endregion Step Trigger Chargers
#endregion Step Trigger Chargers
#endregion Charger specific
}
2 changes: 1 addition & 1 deletion Content.Shared/Alert/AlertType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public enum AlertType : byte
Starving,
Thirsty,
Parched,
Charge // Parkstation-IPC
Charge, // Parkstation-IPC
Stamina,
Pulled,
Pulling,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed class SiliconChargerComponent : Component
/// <summary>
/// Counter for handing out warnings to burning entities.
/// </summary>
public float warningAccumulator = 0f;
public float WarningAccumulator = 0f;


/// <summary>
Expand All @@ -45,6 +45,14 @@ public sealed class SiliconChargerComponent : Component
[DataField("minChargeSize"), ViewVariables(VVAccess.ReadWrite)]
public int MinChargeSize = 1000;

/// <summary>
/// The minimum amount of time it will take to charge a battery, in seconds.
/// </summary>
/// <remarks>
/// This is for the sake of feeling cooler- It's lame to just charge instantly.
/// </remarks>
[DataField("minChargeTime"), ViewVariables(VVAccess.ReadWrite)]
public float MinChargeTime = 10f;

/// <summary>
/// The temperature the charger will stop heating up at.
Expand All @@ -55,6 +63,12 @@ public sealed class SiliconChargerComponent : Component
[DataField("targetTemp"), ViewVariables(VVAccess.ReadWrite)]
public float TargetTemp = 373.15f;

/// <summary>
/// The damage type to deal when a Biological entity is burned.
/// </summary>
[DataField("damageType")]
public string DamageType = "Shock";


/// <summary>
/// The list of entities currently stood on a charger.
Expand Down

0 comments on commit 3a2a6c9

Please sign in to comment.