Skip to content

Commit

Permalink
Merge branch 'master' into Xenowear
Browse files Browse the repository at this point in the history
  • Loading branch information
VMSolidus authored Aug 6, 2024
2 parents 5df91d5 + b6b21da commit dd5aabe
Show file tree
Hide file tree
Showing 262 changed files with 3,023 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private bool IsHeater(GasThermoMachineComponent comp)

private void OnToggleMessage(EntityUid uid, GasThermoMachineComponent thermoMachine, GasThermomachineToggleMessage args)
{
var powerState = _power.TogglePower(uid);
var powerState = _power.TryTogglePower(uid);
_adminLogger.Add(LogType.AtmosPowerChanged, $"{ToPrettyString(args.Session.AttachedEntity)} turned {(powerState ? "On" : "Off")} {ToPrettyString(uid)}");
DirtyUI(uid, thermoMachine);
}
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Atmos/Portable/SpaceHeaterSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void OnToggle(EntityUid uid, SpaceHeaterComponent spaceHeater, SpaceHeat
if (!Resolve(uid, ref powerReceiver))
return;

_power.TogglePower(uid);
_power.TryTogglePower(uid);

UpdateAppearance(uid);
DirtyUI(uid, spaceHeater);
Expand Down
15 changes: 14 additions & 1 deletion Content.Server/Body/Components/BloodstreamComponent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Server.Body.Systems;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Traits.Assorted;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Damage;
Expand All @@ -11,7 +12,7 @@

namespace Content.Server.Body.Components
{
[RegisterComponent, Access(typeof(BloodstreamSystem), typeof(ReactionMixerSystem))]
[RegisterComponent, Access(typeof(BloodstreamSystem), typeof(ReactionMixerSystem), typeof(BloodDeficiencySystem))]
public sealed partial class BloodstreamComponent : Component
{
public static string DefaultChemicalsSolutionName = "chemicals";
Expand Down Expand Up @@ -171,5 +172,17 @@ public sealed partial class BloodstreamComponent : Component
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan StatusTime;

/// <summary>
/// If this is true, the entity will not passively regenerate blood,
/// and instead will slowly lose blood.
/// </summary>
public bool HasBloodDeficiency = false;

/// <summary>
/// How much reagent of blood should be removed with blood deficiency in each update interval?
/// </summary>
[DataField]
public FixedPoint2 BloodDeficiencyLossAmount;
}
}
25 changes: 20 additions & 5 deletions Content.Server/Body/Systems/BloodstreamSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ public override void Update(float frameTime)
if (!_solutionContainerSystem.ResolveSolution(uid, bloodstream.BloodSolutionName, ref bloodstream.BloodSolution, out var bloodSolution))
continue;

// Adds blood to their blood level if it is below the maximum; Blood regeneration. Must be alive.
if (bloodSolution.Volume < bloodSolution.MaxVolume && !_mobStateSystem.IsDead(uid))
{
TryModifyBloodLevel(uid, bloodstream.BloodRefreshAmount, bloodstream);
}
// Removes blood for Blood Deficiency constantly.
if (bloodstream.HasBloodDeficiency)
if (!_mobStateSystem.IsDead(uid))
RemoveBlood(uid, bloodstream.BloodDeficiencyLossAmount, bloodstream);
// Adds blood to their blood level if it is below the maximum.
else if (bloodSolution.Volume < bloodSolution.MaxVolume)
if (!_mobStateSystem.IsDead(uid))
TryModifyBloodLevel(uid, bloodstream.BloodRefreshAmount, bloodstream);

// Removes blood from the bloodstream based on bleed amount (bleed rate)
// as well as stop their bleeding to a certain extent.
Expand Down Expand Up @@ -472,4 +475,16 @@ public void ChangeBloodReagent(EntityUid uid, string reagent, BloodstreamCompone
if (currentVolume > 0)
_solutionContainerSystem.TryAddReagent(component.BloodSolution.Value, component.BloodReagent, currentVolume, out _);
}

/// <summary>
/// Remove blood from an entity, without spilling it.
/// </summary>
private void RemoveBlood(EntityUid uid, FixedPoint2 amount, BloodstreamComponent? component = null)
{
if (!Resolve(uid, ref component, logMissing: false)
|| !_solutionContainerSystem.ResolveSolution(uid, component.BloodSolutionName, ref component.BloodSolution, out var bloodSolution))
return;

bloodSolution.RemoveReagent(component.BloodReagent, amount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private void OnUiButtonPressed(EntityUid uid, SharedDisposalUnitComponent compon
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(player):player} hit flush button on {ToPrettyString(uid)}, it's now {(component.Engaged ? "on" : "off")}");
break;
case SharedDisposalUnitComponent.UiButton.Power:
_power.TogglePower(uid, user: args.Session.AttachedEntity);
_power.TryTogglePower(uid, user: args.Session.AttachedEntity);
break;
default:
throw new ArgumentOutOfRangeException($"{ToPrettyString(player):player} attempted to hit a nonexistant button on {ToPrettyString(uid)}");
Expand Down
33 changes: 19 additions & 14 deletions Content.Server/Emp/EmpSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Content.Server.Explosion.EntitySystems;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Radio;
using Content.Server.SurveillanceCamera;
using Content.Shared.Emp;
using Content.Shared.Examine;
using Robust.Shared.Map;
Expand All @@ -22,8 +22,6 @@ public override void Initialize()

SubscribeLocalEvent<EmpDisabledComponent, RadioSendAttemptEvent>(OnRadioSendAttempt);
SubscribeLocalEvent<EmpDisabledComponent, RadioReceiveAttemptEvent>(OnRadioReceiveAttempt);
SubscribeLocalEvent<EmpDisabledComponent, ApcToggleMainBreakerAttemptEvent>(OnApcToggleMainBreaker);
SubscribeLocalEvent<EmpDisabledComponent, SurveillanceCameraSetActiveAttemptEvent>(OnCameraSetActive);
}

/// <summary>
Expand Down Expand Up @@ -75,7 +73,19 @@ public void DoEmpEffects(EntityUid uid, float energyConsumption, float duration)
if (ev.Disabled)
{
var disabled = EnsureComp<EmpDisabledComponent>(uid);
disabled.DisabledUntil = Timing.CurTime + TimeSpan.FromSeconds(duration);
// couldnt use null-coalescing operator here sadge
if (disabled.DisabledUntil == TimeSpan.Zero)
{
disabled.DisabledUntil = Timing.CurTime;
}
disabled.DisabledUntil = disabled.DisabledUntil + TimeSpan.FromSeconds(duration);

/// i tried my best to go through the Pow3r server code but i literally couldn't find in relation to PowerNetworkBatteryComponent that uses the event system
/// the code is otherwise too esoteric for my innocent eyes
if (TryComp<PowerNetworkBatteryComponent>(uid, out var powerNetBattery))
{
powerNetBattery.CanCharge = false;
}
}
}

Expand All @@ -91,6 +101,11 @@ public override void Update(float frameTime)
RemComp<EmpDisabledComponent>(uid);
var ev = new EmpDisabledRemoved();
RaiseLocalEvent(uid, ref ev);

if (TryComp<PowerNetworkBatteryComponent>(uid, out var powerNetBattery))
{
powerNetBattery.CanCharge = true;
}
}
}
}
Expand All @@ -115,16 +130,6 @@ private void OnRadioReceiveAttempt(EntityUid uid, EmpDisabledComponent component
{
args.Cancelled = true;
}

private void OnApcToggleMainBreaker(EntityUid uid, EmpDisabledComponent component, ref ApcToggleMainBreakerAttemptEvent args)
{
args.Cancelled = true;
}

private void OnCameraSetActive(EntityUid uid, EmpDisabledComponent component, ref SurveillanceCameraSetActiveAttemptEvent args)
{
args.Cancelled = true;
}
}

/// <summary>
Expand Down
26 changes: 26 additions & 0 deletions Content.Server/Gravity/GravityGeneratorSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Server.Administration.Logs;
using Content.Server.Audio;
using Content.Server.Power.Components;
using Content.Server.Emp;
using Content.Shared.Database;
using Content.Shared.Gravity;
using Content.Shared.Interaction;
Expand Down Expand Up @@ -28,6 +29,8 @@ public override void Initialize()
SubscribeLocalEvent<GravityGeneratorComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<GravityGeneratorComponent, SharedGravityGeneratorComponent.SwitchGeneratorMessage>(
OnSwitchGenerator);

SubscribeLocalEvent<GravityGeneratorComponent, EmpPulseEvent>(OnEmpPulse);
}

private void OnParentChanged(EntityUid uid, GravityGeneratorComponent component, ref EntParentChangedMessage args)
Expand Down Expand Up @@ -289,5 +292,28 @@ private void OnSwitchGenerator(
{
SetSwitchedOn(uid, component, args.On, session:args.Session);
}

private void OnEmpPulse(EntityUid uid, GravityGeneratorComponent component, EmpPulseEvent args)
{
/// i really don't think that the gravity generator should use normalised 0-1 charge
/// as opposed to watts charge that every other battery uses

ApcPowerReceiverComponent? powerReceiver = null;
if (!Resolve(uid, ref powerReceiver, false))
return;

var ent = (uid, component, powerReceiver);

// convert from normalised energy to watts and subtract
float maxEnergy = component.ActivePowerUse / component.ChargeRate;
float currentEnergy = maxEnergy * component.Charge;
currentEnergy = Math.Max(0, currentEnergy - args.EnergyConsumption);

// apply renormalised energy to charge variable
component.Charge = currentEnergy / maxEnergy;

// update power state
UpdateState(ent);
}
}
}
4 changes: 2 additions & 2 deletions Content.Server/Nyanotrasen/Abilities/Boxer/BoxingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override void Initialize()
base.Initialize();
SubscribeLocalEvent<BoxerComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<BoxerComponent, MeleeHitEvent>(OnMeleeHit);
SubscribeLocalEvent<BoxingGlovesComponent, StaminaMeleeHitEvent>(OnStamHit);
SubscribeLocalEvent<BoxingGlovesComponent, TakeStaminaDamageEvent>(OnStamHit);
}

private void OnInit(EntityUid uid, BoxerComponent component, ComponentInit args)
Expand All @@ -27,7 +27,7 @@ private void OnMeleeHit(EntityUid uid, BoxerComponent component, MeleeHitEvent a
args.ModifiersList.Add(component.UnarmedModifiers);
}

private void OnStamHit(EntityUid uid, BoxingGlovesComponent component, StaminaMeleeHitEvent args)
private void OnStamHit(EntityUid uid, BoxingGlovesComponent component, TakeStaminaDamageEvent args)
{
if (!_containerSystem.TryGetContainingContainer(uid, out var equipee))
return;
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Nyanotrasen/Abilities/Oni/OniSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override void Initialize()
SubscribeLocalEvent<OniComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
SubscribeLocalEvent<OniComponent, MeleeHitEvent>(OnOniMeleeHit);
SubscribeLocalEvent<HeldByOniComponent, MeleeHitEvent>(OnHeldMeleeHit);
SubscribeLocalEvent<HeldByOniComponent, StaminaMeleeHitEvent>(OnStamHit);
SubscribeLocalEvent<HeldByOniComponent, TakeStaminaDamageEvent>(OnStamHit);
}

private void OnEntInserted(EntityUid uid, OniComponent component, EntInsertedIntoContainerMessage args)
Expand Down Expand Up @@ -68,7 +68,7 @@ private void OnHeldMeleeHit(EntityUid uid, HeldByOniComponent component, MeleeHi
args.ModifiersList.Add(oni.MeleeModifiers);
}

private void OnStamHit(EntityUid uid, HeldByOniComponent component, StaminaMeleeHitEvent args)
private void OnStamHit(EntityUid uid, HeldByOniComponent component, TakeStaminaDamageEvent args)
{
if (!TryComp<OniComponent>(component.Holder, out var oni))
return;
Expand Down
12 changes: 5 additions & 7 deletions Content.Server/Nyanotrasen/Psionics/PsionicsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override void Initialize()
base.Initialize();
SubscribeLocalEvent<PotentialPsionicComponent, MapInitEvent>(OnStartup);
SubscribeLocalEvent<AntiPsionicWeaponComponent, MeleeHitEvent>(OnMeleeHit);
SubscribeLocalEvent<AntiPsionicWeaponComponent, StaminaMeleeHitEvent>(OnStamHit);
SubscribeLocalEvent<AntiPsionicWeaponComponent, TakeStaminaDamageEvent>(OnStamHit);

SubscribeLocalEvent<PsionicComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<PsionicComponent, ComponentRemove>(OnRemove);
Expand Down Expand Up @@ -110,14 +110,12 @@ private void OnRemove(EntityUid uid, PsionicComponent component, ComponentRemove
_npcFactonSystem.RemoveFaction(uid, "PsionicInterloper");
}

private void OnStamHit(EntityUid uid, AntiPsionicWeaponComponent component, StaminaMeleeHitEvent args)
private void OnStamHit(EntityUid uid, AntiPsionicWeaponComponent component, TakeStaminaDamageEvent args)
{
var bonus = false;
foreach (var stam in args.HitList)
{
if (HasComp<PsionicComponent>(stam.Entity))
bonus = true;
}

if (HasComp<PsionicComponent>(args.Target))
bonus = true;

if (!bonus)
return;
Expand Down
10 changes: 0 additions & 10 deletions Content.Server/Power/Components/ActiveChargerComponent.cs

This file was deleted.

19 changes: 19 additions & 0 deletions Content.Server/Power/Components/ChargingComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Power;

namespace Content.Server.Power.Components
{
[RegisterComponent]
public sealed partial class ChargingComponent : Component
{
///<summary>
///References the entity of the charger that is currently powering this battery
///</summary>
public EntityUid ChargerUid;

///<summary>
///References the component of the charger that is currently powering this battery
///</summary>
public ChargerComponent ChargerComponent;
}
}
19 changes: 11 additions & 8 deletions Content.Server/Power/EntitySystems/ApcSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Content.Shared.APC;
using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.Emp;
using Content.Shared.Popups;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
Expand Down Expand Up @@ -37,6 +38,7 @@ public override void Initialize()
SubscribeLocalEvent<ApcComponent, GotEmaggedEvent>(OnEmagged);

SubscribeLocalEvent<ApcComponent, EmpPulseEvent>(OnEmpPulse);
SubscribeLocalEvent<ApcComponent, EmpDisabledRemoved>(OnEmpDisabledRemoved);
}

public override void Update(float deltaTime)
Expand Down Expand Up @@ -163,7 +165,7 @@ public void UpdateUIState(EntityUid uid,

private ApcChargeState CalcChargeState(EntityUid uid, PowerState.Battery battery)
{
if (HasComp<EmaggedComponent>(uid))
if (HasComp<EmaggedComponent>(uid) || HasComp<EmpDisabledComponent>(uid))
return ApcChargeState.Emag;

if (battery.CurrentStorage / battery.Capacity > ApcComponent.HighPowerThreshold)
Expand All @@ -190,15 +192,16 @@ private ApcExternalPowerState CalcExtPowerState(EntityUid uid, PowerState.Batter

return ApcExternalPowerState.Good;
}

private void OnEmpPulse(EntityUid uid, ApcComponent component, ref EmpPulseEvent args)
{
if (component.MainBreakerEnabled)
{
args.Affected = true;
args.Disabled = true;
ApcToggleBreaker(uid, component);
}
EnsureComp<EmpDisabledComponent>(uid, out var emp); //event calls before EmpDisabledComponent is added, ensure it to force sprite update
UpdateApcState(uid);
}

private void OnEmpDisabledRemoved(EntityUid uid, ApcComponent component, ref EmpDisabledRemoved args)
{
UpdateApcState(uid);
}
}

Expand Down
Loading

0 comments on commit dd5aabe

Please sign in to comment.