ECSatize AlertsSystem (#5559)

This commit is contained in:
Acruid
2022-01-05 00:19:23 -08:00
committed by GitHub
parent 36d4de5e61
commit 5b1cd2dd96
59 changed files with 1069 additions and 1038 deletions

View File

@@ -14,11 +14,11 @@ namespace Content.Server.Alert.Click
[DataDefinition]
public class RemoveCuffs : IAlertClick
{
public void AlertClicked(ClickAlertEventArgs args)
public void AlertClicked(EntityUid player)
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(args.Player, out CuffableComponent? cuffableComponent))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(player, out CuffableComponent? cuffableComponent))
{
cuffableComponent.TryUncuff(args.Player);
cuffableComponent.TryUncuff(player);
}
}
}

View File

@@ -1,4 +1,4 @@
using Content.Server.Atmos.Components;
using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Shared.Alert;
using JetBrains.Annotations;
@@ -15,11 +15,11 @@ namespace Content.Server.Alert.Click
[DataDefinition]
public class ResistFire : IAlertClick
{
public void AlertClicked(ClickAlertEventArgs args)
public void AlertClicked(EntityUid player)
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(args.Player, out FlammableComponent? flammable))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(player, out FlammableComponent? flammable))
{
EntitySystem.Get<FlammableSystem>().Resist(args.Player, flammable);
EntitySystem.Get<FlammableSystem>().Resist(player, flammable);
}
}
}

View File

@@ -16,12 +16,12 @@ namespace Content.Server.Alert.Click
[DataDefinition]
public class StopBeingPulled : IAlertClick
{
public void AlertClicked(ClickAlertEventArgs args)
public void AlertClicked(EntityUid player)
{
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(args.Player))
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(player))
return;
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<SharedPullableComponent?>(args.Player, out var playerPullable))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<SharedPullableComponent?>(player, out var playerPullable))
{
EntitySystem.Get<SharedPullingSystem>().TryStopPull(playerPullable);
}

View File

@@ -1,4 +1,4 @@
using Content.Server.Shuttles;
using Content.Server.Shuttles;
using Content.Server.Shuttles.EntitySystems;
using Content.Shared.Alert;
using Content.Shared.Shuttles;
@@ -17,9 +17,9 @@ namespace Content.Server.Alert.Click
[DataDefinition]
public class StopPiloting : IAlertClick
{
public void AlertClicked(ClickAlertEventArgs args)
public void AlertClicked(EntityUid player)
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(args.Player, out PilotComponent? pilotComponent) &&
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(player, out PilotComponent? pilotComponent) &&
pilotComponent.Console != null)
{
EntitySystem.Get<ShuttleConsoleSystem>().RemovePilot(pilotComponent);

View File

@@ -15,10 +15,10 @@ namespace Content.Server.Alert.Click
[DataDefinition]
public class StopPulling : IAlertClick
{
public void AlertClicked(ClickAlertEventArgs args)
public void AlertClicked(EntityUid player)
{
var ps = EntitySystem.Get<SharedPullingSystem>();
var playerTarget = ps.GetPulled(args.Player);
var playerTarget = ps.GetPulled(player);
if (playerTarget != default && IoCManager.Resolve<IEntityManager>().TryGetComponent(playerTarget, out SharedPullableComponent playerPullable))
{
ps.TryStopPull(playerPullable);

View File

@@ -1,4 +1,4 @@
using Content.Server.Buckle.Components;
using Content.Server.Buckle.Components;
using Content.Shared.Alert;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
@@ -14,11 +14,11 @@ namespace Content.Server.Alert.Click
[DataDefinition]
public class Unbuckle : IAlertClick
{
public void AlertClicked(ClickAlertEventArgs args)
public void AlertClicked(EntityUid player)
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(args.Player, out BuckleComponent? buckle))
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(player, out BuckleComponent? buckle))
{
buckle.TryUnbuckle(args.Player);
buckle.TryUnbuckle(player);
}
}
}

View File

@@ -34,21 +34,21 @@ namespace Content.Server.Alert.Commands
if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity)) return;
}
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attachedEntity, out ServerAlertsComponent? alertsComponent))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attachedEntity, out AlertsComponent? alertsComponent))
{
shell.WriteLine("user has no alerts component");
return;
}
var alertType = args[0];
var alertMgr = IoCManager.Resolve<AlertManager>();
if (!alertMgr.TryGet(Enum.Parse<AlertType>(alertType), out var alert))
var alertsSystem = EntitySystem.Get<AlertsSystem>();
if (!alertsSystem.TryGet(Enum.Parse<AlertType>(alertType), out var alert))
{
shell.WriteLine("unrecognized alertType " + alertType);
return;
}
alertsComponent.ClearAlert(alert.AlertType);
alertsSystem.ClearAlert(attachedEntity, alert.AlertType);
}
}
}

View File

@@ -34,7 +34,7 @@ namespace Content.Server.Alert.Commands
if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity)) return;
}
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attachedEntity, out ServerAlertsComponent? alertsComponent))
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(attachedEntity, out AlertsComponent? alertsComponent))
{
shell.WriteLine("user has no alerts component");
return;
@@ -42,8 +42,8 @@ namespace Content.Server.Alert.Commands
var alertType = args[0];
var severity = args[1];
var alertMgr = IoCManager.Resolve<AlertManager>();
if (!alertMgr.TryGet(Enum.Parse<AlertType>(alertType), out var alert))
var alertsSystem = EntitySystem.Get<AlertsSystem>();
if (!alertsSystem.TryGet(Enum.Parse<AlertType>(alertType), out var alert))
{
shell.WriteLine("unrecognized alertType " + alertType);
return;
@@ -53,7 +53,9 @@ namespace Content.Server.Alert.Commands
shell.WriteLine("invalid severity " + sevint);
return;
}
alertsComponent.ShowAlert(alert.AlertType, sevint == -1 ? null : sevint);
short? severity1 = sevint == -1 ? null : sevint;
alertsSystem.ShowAlert(attachedEntity, alert.AlertType, severity1, null);
}
}
}

View File

@@ -1,86 +0,0 @@
using System;
using Content.Server.Gravity.EntitySystems;
using Content.Shared.Alert;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Network;
using Robust.Shared.Players;
namespace Content.Server.Alert
{
[RegisterComponent]
[ComponentReference(typeof(SharedAlertsComponent))]
public sealed class ServerAlertsComponent : SharedAlertsComponent
{
protected override void Startup()
{
base.Startup();
if (EntitySystem.TryGet<WeightlessSystem>(out var weightlessSystem))
{
weightlessSystem.AddAlert(this);
}
else
{
Logger.WarningS("alert", "weightlesssystem not found");
}
}
protected override void OnRemove()
{
if (EntitySystem.TryGet<WeightlessSystem>(out var weightlessSystem))
{
weightlessSystem.RemoveAlert(this);
}
else
{
Logger.WarningS("alert", $"{nameof(WeightlessSystem)} not found");
}
base.OnRemove();
}
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null)
{
base.HandleNetworkMessage(message, netChannel, session);
if (session == null)
{
throw new ArgumentNullException(nameof(session));
}
switch (message)
{
case ClickAlertMessage msg:
{
var player = session.AttachedEntity.GetValueOrDefault();
if (player != Owner)
{
break;
}
if (!IsShowingAlert(msg.Type))
{
Logger.DebugS("alert", "user {0} attempted to" +
" click alert {1} which is not currently showing for them",
IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(player).EntityName, msg.Type);
break;
}
if (!AlertManager.TryGet(msg.Type, out var alert))
{
Logger.WarningS("alert", "unrecognized encoded alert {0}", msg.Type);
break;
}
alert.OnClick?.AlertClicked(new ClickAlertEventArgs(player, alert));
break;
}
}
}
}
}

View File

@@ -0,0 +1,7 @@
using Content.Shared.Alert;
namespace Content.Server.Alert;
// The only reason this exists is because the DI system requires the shared AlertsSystem
// to be abstract.
internal class ServerAlertsSystem : AlertsSystem { }

View File

@@ -1,6 +1,5 @@
using System;
using Content.Server.Administration.Logs;
using Content.Server.Alert;
using Content.Server.Atmos.Components;
using Content.Shared.Alert;
using Content.Shared.Atmos;
@@ -16,11 +15,11 @@ namespace Content.Server.Atmos.EntitySystems
{
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
[Dependency] private readonly AdminLogSystem _logSystem = default!;
private const float UpdateTimer = 1f;
private float _timer = 0f;
private float _timer;
public override void Initialize()
{
@@ -72,7 +71,7 @@ namespace Content.Server.Atmos.EntitySystems
_timer -= UpdateTimer;
foreach (var (barotrauma, damageable, transform) in EntityManager.EntityQuery<BarotraumaComponent, DamageableComponent, TransformComponent>(false))
foreach (var (barotrauma, damageable, transform) in EntityManager.EntityQuery<BarotraumaComponent, DamageableComponent, TransformComponent>())
{
var totalDamage = FixedPoint2.Zero;
foreach (var (barotraumaDamageType, _) in barotrauma.Damage.DamageDict)
@@ -84,28 +83,24 @@ namespace Content.Server.Atmos.EntitySystems
if (totalDamage >= barotrauma.MaxDamage)
continue;
var uid = barotrauma.Owner;
var status = EntityManager.GetComponentOrNull<ServerAlertsComponent>(barotrauma.Owner);
var pressure = 1f;
if (_atmosphereSystem.GetTileMixture(transform.Coordinates) is { } mixture)
{
pressure = MathF.Max(mixture.Pressure, 1f);;
pressure = MathF.Max(mixture.Pressure, 1f);
}
switch (pressure)
{
// Low pressure.
case <= Atmospherics.WarningLowPressure:
pressure = GetFeltLowPressure(uid, pressure);
pressure = GetFeltLowPressure(barotrauma.Owner, pressure);
if (pressure > Atmospherics.WarningLowPressure)
goto default;
// Deal damage and ignore resistances. Resistance to pressure damage should be done via pressure protection gear.
_damageableSystem.TryChangeDamage(uid, barotrauma.Damage * Atmospherics.LowPressureDamage, true, false);
_damageableSystem.TryChangeDamage(barotrauma.Owner, barotrauma.Damage * Atmospherics.LowPressureDamage, true, false);
if (!barotrauma.TakingDamage)
{
@@ -113,20 +108,18 @@ namespace Content.Server.Atmos.EntitySystems
_logSystem.Add(LogType.Barotrauma, $"{ToPrettyString(barotrauma.Owner):entity} started taking low pressure damage");
}
if (status == null) break;
if (pressure <= Atmospherics.HazardLowPressure)
{
status.ShowAlert(AlertType.LowPressure, 2);
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.LowPressure, 2);
break;
}
status.ShowAlert(AlertType.LowPressure, 1);
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.LowPressure, 1);
break;
// High pressure.
case >= Atmospherics.WarningHighPressure:
pressure = GetFeltHighPressure(uid, pressure);
pressure = GetFeltHighPressure(barotrauma.Owner, pressure);
if(pressure < Atmospherics.WarningHighPressure)
goto default;
@@ -134,7 +127,7 @@ namespace Content.Server.Atmos.EntitySystems
var damageScale = MathF.Min((pressure / Atmospherics.HazardHighPressure) * Atmospherics.PressureDamageCoefficient, Atmospherics.MaxHighPressureDamage);
// Deal damage and ignore resistances. Resistance to pressure damage should be done via pressure protection gear.
_damageableSystem.TryChangeDamage(uid, barotrauma.Damage * damageScale, true, false);
_damageableSystem.TryChangeDamage(barotrauma.Owner, barotrauma.Damage * damageScale, true, false);
if (!barotrauma.TakingDamage)
{
@@ -142,15 +135,13 @@ namespace Content.Server.Atmos.EntitySystems
_logSystem.Add(LogType.Barotrauma, $"{ToPrettyString(barotrauma.Owner):entity} started taking high pressure damage");
}
if (status == null) break;
if (pressure >= Atmospherics.HazardHighPressure)
{
status.ShowAlert(AlertType.HighPressure, 2);
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.HighPressure, 2);
break;
}
status.ShowAlert(AlertType.HighPressure, 1);
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.HighPressure, 1);
break;
// Normal pressure.
@@ -160,7 +151,7 @@ namespace Content.Server.Atmos.EntitySystems
barotrauma.TakingDamage = false;
_logSystem.Add(LogType.Barotrauma, $"{ToPrettyString(barotrauma.Owner):entity} stopped taking pressure damage");
}
status?.ClearAlertCategory(AlertCategory.Pressure);
_alertsSystem.ClearAlertCategory(barotrauma.Owner, AlertCategory.Pressure);
break;
}
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using Content.Server.Administration.Logs;
using Content.Server.Alert;
using Content.Server.Atmos.Components;
using Content.Server.Stunnable;
using Content.Server.Temperature.Systems;
@@ -28,6 +27,7 @@ namespace Content.Server.Atmos.EntitySystems
[Dependency] private readonly StunSystem _stunSystem = default!;
[Dependency] private readonly TemperatureSystem _temperatureSystem = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
[Dependency] private readonly AdminLogSystem _logSystem = default!;
private const float MinimumFireStacks = -10f;
@@ -167,10 +167,9 @@ namespace Content.Server.Atmos.EntitySystems
}
public void Resist(EntityUid uid,
FlammableComponent? flammable = null,
ServerAlertsComponent? alerts = null)
FlammableComponent? flammable = null)
{
if (!Resolve(uid, ref flammable, ref alerts))
if (!Resolve(uid, ref flammable))
return;
if (!flammable.OnFire || !_actionBlockerSystem.CanInteract(flammable.Owner) || flammable.Resisting)
@@ -179,7 +178,7 @@ namespace Content.Server.Atmos.EntitySystems
flammable.Resisting = true;
flammable.Owner.PopupMessage(Loc.GetString("flammable-component-resist-message"));
_stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(2f), true, alerts: alerts);
_stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(2f), true);
// TODO FLAMMABLE: Make this not use TimerComponent...
flammable.Owner.SpawnTimer(2000, () =>
@@ -224,15 +223,13 @@ namespace Content.Server.Atmos.EntitySystems
flammable.FireStacks = MathF.Min(0, flammable.FireStacks + 1);
}
EntityManager.TryGetComponent(flammable.Owner, out ServerAlertsComponent? status);
if (!flammable.OnFire)
{
status?.ClearAlert(AlertType.Fire);
_alertsSystem.ClearAlert(uid, AlertType.Fire);
continue;
}
status?.ShowAlert(AlertType.Fire);
_alertsSystem.ShowAlert(uid, AlertType.Fire, null, null);
if (flammable.FireStacks > 0)
{

View File

@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Alert;
using Content.Server.Atmos;
using Content.Server.Body.Components;
using Content.Shared.Alert;
@@ -24,6 +23,7 @@ namespace Content.Server.Body.Systems
[Dependency] private readonly AdminLogSystem _logSys = default!;
[Dependency] private readonly BodySystem _bodySystem = default!;
[Dependency] private readonly LungSystem _lungSystem = default!;
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
public override void Update(float frameTime)
{
@@ -199,10 +199,7 @@ namespace Content.Server.Body.Systems
respirator.Suffocating = true;
if (EntityManager.TryGetComponent(uid, out ServerAlertsComponent? alertsComponent))
{
alertsComponent.ShowAlert(AlertType.LowOxygen);
}
_alertsSystem.ShowAlert(uid, AlertType.LowOxygen);
_damageableSys.TryChangeDamage(uid, respirator.Damage, true, false);
}
@@ -214,10 +211,7 @@ namespace Content.Server.Body.Systems
respirator.Suffocating = false;
if (EntityManager.TryGetComponent(uid, out ServerAlertsComponent? alertsComponent))
{
alertsComponent.ClearAlert(AlertType.LowOxygen);
}
_alertsSystem.ClearAlert(uid, AlertType.LowOxygen);
_damageableSys.TryChangeDamage(uid, respirator.DamageRecovery, true);
}

View File

@@ -1,6 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Content.Server.Alert;
using Content.Server.Hands.Components;
using Content.Server.Pulling;
using Content.Shared.ActionBlocker;
@@ -36,7 +35,6 @@ namespace Content.Server.Buckle.Components
[Dependency] private readonly IGameTiming _gameTiming = default!;
[ComponentDependency] public readonly AppearanceComponent? Appearance = null;
[ComponentDependency] private readonly ServerAlertsComponent? _serverAlerts = null;
[ComponentDependency] private readonly MobStateComponent? _mobState = null;
[DataField("size")]
@@ -94,18 +92,14 @@ namespace Content.Server.Buckle.Components
/// </summary>
private void UpdateBuckleStatus()
{
if (_serverAlerts == null)
{
return;
}
if (Buckled)
{
_serverAlerts.ShowAlert(BuckledTo?.BuckledAlertType ?? AlertType.Buckled);
AlertType alertType = BuckledTo?.BuckledAlertType ?? AlertType.Buckled;
EntitySystem.Get<AlertsSystem>().ShowAlert(Owner, alertType);
}
else
{
_serverAlerts.ClearAlertCategory(AlertCategory.Buckled);
EntitySystem.Get<AlertsSystem>().ClearAlertCategory(Owner, AlertCategory.Buckled);
}
}

View File

@@ -7,12 +7,15 @@ using Content.Shared.Movement.EntitySystems;
using Content.Shared.Slippery;
using Content.Shared.Verbs;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Content.Server.Clothing
{
public sealed class MagbootsSystem : EntitySystem
{
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
public override void Initialize()
{
base.Initialize();
@@ -35,16 +38,13 @@ namespace Content.Server.Clothing
movedByPressure.Enabled = state;
}
if (TryComp(parent, out ServerAlertsComponent? alerts))
if (state)
{
if (state)
{
alerts.ShowAlert(AlertType.Magboots);
}
else
{
alerts.ClearAlert(AlertType.Magboots);
}
_alertsSystem.ShowAlert(parent, AlertType.Magboots);
}
else
{
_alertsSystem.ClearAlert(parent, AlertType.Magboots);
}
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.Alert;
using Content.Server.DoAfter;
using Content.Server.Hands.Components;
using Content.Shared.Alert;
@@ -158,16 +157,13 @@ namespace Content.Server.Cuffs.Components
/// </summary>
private void UpdateAlert()
{
if (_entMan.TryGetComponent(Owner, out ServerAlertsComponent? status))
if (CanStillInteract)
{
if (CanStillInteract)
{
status.ClearAlert(AlertType.Handcuffed);
}
else
{
status.ShowAlert(AlertType.Handcuffed);
}
EntitySystem.Get<AlertsSystem>().ClearAlert(Owner, AlertType.Handcuffed);
}
else
{
EntitySystem.Get<AlertsSystem>().ShowAlert(Owner, AlertType.Handcuffed);
}
}

View File

@@ -9,7 +9,6 @@ using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Power.NodeGroups;
using Content.Server.Window;
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Database;
@@ -109,8 +108,10 @@ namespace Content.Server.Electrocution
var actual = _damageableSystem.TryChangeDamage(finished.Electrocuting, damage);
if (actual != null)
{
_logSystem.Add(LogType.Electrocution,
$"{ToPrettyString(finished.Owner):entity} received {actual.Total:damage} powered electrocution damage");
}
}
EntityManager.DeleteEntity(uid);
@@ -232,10 +233,10 @@ namespace Content.Server.Electrocution
Node? TryNode(string? id)
{
if (id != null && nodeContainer.TryGetNode<Node>(id, out var node)
&& node.NodeGroup is IBasePowerNet { NetworkNode: { LastAvailableSupplySum: >0 } })
if (id != null && nodeContainer.TryGetNode<Node>(id, out var tryNode)
&& tryNode.NodeGroup is IBasePowerNet { NetworkNode: { LastAvailableSupplySum: >0 } })
{
return node;
return tryNode;
}
return null;
@@ -245,11 +246,10 @@ namespace Content.Server.Electrocution
/// <returns>Whether the entity <see cref="uid"/> was stunned by the shock.</returns>
public bool TryDoElectrocution(
EntityUid uid, EntityUid? sourceUid, int shockDamage, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
StatusEffectsComponent? statusEffects = null,
SharedAlertsComponent? alerts = null)
StatusEffectsComponent? statusEffects = null)
{
if (!DoCommonElectrocutionAttempt(uid, sourceUid, ref siemensCoefficient)
|| !DoCommonElectrocution(uid, sourceUid, shockDamage, time, refresh, siemensCoefficient, statusEffects, alerts))
|| !DoCommonElectrocution(uid, sourceUid, shockDamage, time, refresh, siemensCoefficient, statusEffects))
return false;
RaiseLocalEvent(uid, new ElectrocutedEvent(uid, sourceUid, siemensCoefficient));
@@ -266,7 +266,6 @@ namespace Content.Server.Electrocution
bool refresh,
float siemensCoefficient = 1f,
StatusEffectsComponent? statusEffects = null,
SharedAlertsComponent? alerts = null,
TransformComponent? sourceTransform = null)
{
if (!DoCommonElectrocutionAttempt(uid, sourceUid, ref siemensCoefficient))
@@ -274,9 +273,9 @@ namespace Content.Server.Electrocution
// Coefficient needs to be higher than this to do a powered electrocution!
if(siemensCoefficient <= 0.5f)
return DoCommonElectrocution(uid, sourceUid, shockDamage, time, refresh, siemensCoefficient, statusEffects, alerts);
return DoCommonElectrocution(uid, sourceUid, shockDamage, time, refresh, siemensCoefficient, statusEffects);
if (!DoCommonElectrocution(uid, sourceUid, null, time, refresh, siemensCoefficient, statusEffects, alerts))
if (!DoCommonElectrocution(uid, sourceUid, null, time, refresh, siemensCoefficient, statusEffects))
return false;
if (!Resolve(sourceUid, ref sourceTransform)) // This shouldn't really happen, but just in case...
@@ -318,8 +317,7 @@ namespace Content.Server.Electrocution
private bool DoCommonElectrocution(EntityUid uid, EntityUid? sourceUid,
int? shockDamage, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
StatusEffectsComponent? statusEffects = null,
SharedAlertsComponent? alerts = null)
StatusEffectsComponent? statusEffects = null)
{
if (siemensCoefficient <= 0)
return false;
@@ -332,21 +330,18 @@ namespace Content.Server.Electrocution
return false;
}
// Optional component.
Resolve(uid, ref alerts, false);
if (!Resolve(uid, ref statusEffects, false) ||
!_statusEffectsSystem.CanApplyEffect(uid, StatusEffectKey, statusEffects))
return false;
if (!_statusEffectsSystem.TryAddStatusEffect<ElectrocutedComponent>(uid, StatusEffectKey, time, refresh,
statusEffects, alerts))
statusEffects))
return false;
var shouldStun = siemensCoefficient > 0.5f;
if (shouldStun)
_stunSystem.TryParalyze(uid, time * ParalyzeTimeMultiplier, refresh, statusEffects, alerts);
_stunSystem.TryParalyze(uid, time * ParalyzeTimeMultiplier, refresh, statusEffects);
// TODO: Sparks here.
@@ -356,13 +351,15 @@ namespace Content.Server.Electrocution
new DamageSpecifier(_prototypeManager.Index<DamageTypePrototype>(DamageType), dmg));
if (actual != null)
{
_logSystem.Add(LogType.Electrocution,
$"{ToPrettyString(statusEffects.Owner):entity} received {actual.Total:damage} powered electrocution damage");
}
}
_stutteringSystem.DoStutter(uid, time * StutteringTimeMultiplier, refresh, statusEffects, alerts);
_stutteringSystem.DoStutter(uid, time * StutteringTimeMultiplier, refresh, statusEffects);
_jitteringSystem.DoJitter(uid, time * JitterTimeMultiplier, refresh, JitterAmplitude, JitterFrequency, true,
statusEffects, alerts);
statusEffects);
_popupSystem.PopupEntity(Loc.GetString("electrocuted-component-mob-shocked-popup-player"), uid,
Filter.Entities(uid).Unpredicted());

View File

@@ -89,7 +89,6 @@ namespace Content.Server.Entry
IoCManager.Resolve<ISandboxManager>().Initialize();
IoCManager.Resolve<RecipeManager>().Initialize();
IoCManager.Resolve<AlertManager>().Initialize();
IoCManager.Resolve<ActionManager>().Initialize();
IoCManager.Resolve<BlackboardManager>().Initialize();
IoCManager.Resolve<ConsiderationsManager>().Initialize();

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using Content.Server.Alert;
using System.Collections.Generic;
using Content.Shared.Alert;
using Content.Shared.GameTicking;
using Content.Shared.Gravity;
@@ -15,8 +14,9 @@ namespace Content.Server.Gravity.EntitySystems
public class WeightlessSystem : EntitySystem
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
private readonly Dictionary<GridId, List<ServerAlertsComponent>> _alerts = new();
private readonly Dictionary<GridId, List<AlertsComponent>> _alerts = new();
public override void Initialize()
{
@@ -25,6 +25,7 @@ namespace Content.Server.Gravity.EntitySystems
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
SubscribeLocalEvent<GravityChangedMessage>(GravityChanged);
SubscribeLocalEvent<EntParentChangedMessage>(EntParentChanged);
SubscribeLocalEvent<AlertsComponent, AlertSyncEvent>(HandleAlertSyncEvent);
}
public void Reset(RoundRestartCleanupEvent ev)
@@ -32,7 +33,7 @@ namespace Content.Server.Gravity.EntitySystems
_alerts.Clear();
}
public void AddAlert(ServerAlertsComponent status)
public void AddAlert(AlertsComponent status)
{
var gridId = EntityManager.GetComponent<TransformComponent>(status.Owner).GridID;
var alerts = _alerts.GetOrNew(gridId);
@@ -43,16 +44,16 @@ namespace Content.Server.Gravity.EntitySystems
{
if (EntityManager.GetComponent<GravityComponent>(grid.GridEntityId).Enabled)
{
RemoveWeightless(status);
RemoveWeightless(status.Owner);
}
else
{
AddWeightless(status);
AddWeightless(status.Owner);
}
}
}
public void RemoveAlert(ServerAlertsComponent status)
public void RemoveAlert(AlertsComponent status)
{
var grid = EntityManager.GetComponent<TransformComponent>(status.Owner).GridID;
if (!_alerts.TryGetValue(grid, out var statuses))
@@ -74,31 +75,31 @@ namespace Content.Server.Gravity.EntitySystems
{
foreach (var status in statuses)
{
RemoveWeightless(status);
RemoveWeightless(status.Owner);
}
}
else
{
foreach (var status in statuses)
{
AddWeightless(status);
AddWeightless(status.Owner);
}
}
}
private void AddWeightless(ServerAlertsComponent status)
private void AddWeightless(EntityUid euid)
{
status.ShowAlert(AlertType.Weightless);
_alertsSystem.ShowAlert(euid, AlertType.Weightless);
}
private void RemoveWeightless(ServerAlertsComponent status)
private void RemoveWeightless(EntityUid euid)
{
status.ClearAlert(AlertType.Weightless);
_alertsSystem.ClearAlert(euid, AlertType.Weightless);
}
private void EntParentChanged(ref EntParentChangedMessage ev)
{
if (!EntityManager.TryGetComponent(ev.Entity, out ServerAlertsComponent? status))
if (!EntityManager.TryGetComponent(ev.Entity, out AlertsComponent? status))
{
return;
}
@@ -119,5 +120,18 @@ namespace Content.Server.Gravity.EntitySystems
newStatuses.Add(status);
}
private void HandleAlertSyncEvent(EntityUid uid, AlertsComponent component, AlertSyncEvent args)
{
switch (component.LifeStage)
{
case ComponentLifeStage.Starting:
AddAlert(component);
break;
case ComponentLifeStage.Removing:
RemoveAlert(component);
break;
}
}
}
}

View File

@@ -7,10 +7,7 @@ using Content.Server.AI.WorldState;
using Content.Server.Chat.Managers;
using Content.Server.Connection;
using Content.Server.Database;
using Content.Server.DeviceNetwork;
using Content.Server.EUI;
using Content.Server.Holiday;
using Content.Server.Holiday.Interfaces;
using Content.Server.Info;
using Content.Server.Maps;
using Content.Server.Module;
@@ -20,11 +17,9 @@ using Content.Server.Objectives;
using Content.Server.Objectives.Interfaces;
using Content.Server.Preferences.Managers;
using Content.Server.Sandbox;
using Content.Server.Speech;
using Content.Server.Voting.Managers;
using Content.Shared.Actions;
using Content.Shared.Administration;
using Content.Shared.Alert;
using Content.Shared.Kitchen;
using Content.Shared.Module;
using Robust.Shared.IoC;
@@ -43,7 +38,6 @@ namespace Content.Server.IoC
IoCManager.Register<IServerPreferencesManager, ServerPreferencesManager>();
IoCManager.Register<IServerDbManager, ServerDbManager>();
IoCManager.Register<RecipeManager, RecipeManager>();
IoCManager.Register<AlertManager, AlertManager>();
IoCManager.Register<ActionManager, ActionManager>();
IoCManager.Register<INodeGroupFactory, NodeGroupFactory>();
IoCManager.Register<BlackboardManager, BlackboardManager>();

View File

@@ -1,4 +1,4 @@
using Content.Server.Alert;
using System;
using Content.Server.Stunnable;
using Content.Server.Stunnable.Components;
using Content.Shared.Alert;
@@ -17,10 +17,7 @@ namespace Content.Server.MobState.States
{
base.EnterState(uid, entityManager);
if (entityManager.TryGetComponent(uid, out ServerAlertsComponent? status))
{
status.ShowAlert(AlertType.HumanDead);
}
EntitySystem.Get<AlertsSystem>().ShowAlert(uid, AlertType.HumanDead);
if (entityManager.TryGetComponent(uid, out StatusEffectsComponent? stun))
{

View File

@@ -1,4 +1,4 @@
using Content.Server.Alert;
using System;
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.FixedPoint;
@@ -19,11 +19,6 @@ namespace Content.Server.MobState.States
return;
}
if (!entityManager.TryGetComponent(entity, out ServerAlertsComponent? alerts))
{
return;
}
if (!entityManager.TryGetComponent(entity, out MobStateComponent? stateComponent))
{
return;
@@ -36,7 +31,7 @@ namespace Content.Server.MobState.States
modifier = (short) (damageable.TotalDamage / (earliestThreshold / 7f));
}
alerts.ShowAlert(AlertType.HumanHealth, modifier);
EntitySystem.Get<AlertsSystem>().ShowAlert(entity, AlertType.HumanHealth, modifier);
}
}
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using Content.Server.Administration.Logs;
using Content.Server.Alert;
using Content.Shared.Administration.Logs;
using Content.Shared.Alert;
using Content.Shared.Damage;
@@ -95,15 +94,13 @@ namespace Content.Server.Nutrition.Components
}
// Update UI
_entMan.TryGetComponent(Owner, out ServerAlertsComponent? alertsComponent);
if (HungerThresholdAlertTypes.TryGetValue(_currentHungerThreshold, out var alertId))
{
alertsComponent?.ShowAlert(alertId);
EntitySystem.Get<AlertsSystem>().ShowAlert(Owner, alertId);
}
else
{
alertsComponent?.ClearAlertCategory(AlertCategory.Hunger);
EntitySystem.Get<AlertsSystem>().ClearAlertCategory(Owner, AlertCategory.Hunger);
}
switch (_currentHungerThreshold)

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using Content.Server.Administration.Logs;
using Content.Server.Alert;
using Content.Shared.Administration.Logs;
using Content.Shared.Alert;
using Content.Shared.Damage;
@@ -94,15 +93,13 @@ namespace Content.Server.Nutrition.Components
}
// Update UI
_entMan.TryGetComponent(Owner, out ServerAlertsComponent? alertsComponent);
if (ThirstThresholdAlertTypes.TryGetValue(_currentThirstThreshold, out var alertId))
{
alertsComponent?.ShowAlert(alertId);
EntitySystem.Get<AlertsSystem>().ShowAlert(Owner, alertId);
}
else
{
alertsComponent?.ClearAlertCategory(AlertCategory.Thirst);
EntitySystem.Get<AlertsSystem>().ClearAlertCategory(Owner, AlertCategory.Thirst);
}
switch (_currentThirstThreshold)

View File

@@ -1,4 +1,4 @@
using Content.Server.Alert;
using System;
using Content.Server.Power.Components;
using Content.Server.Shuttles.Components;
using Content.Shared.ActionBlocker;
@@ -18,6 +18,7 @@ namespace Content.Server.Shuttles.EntitySystems
internal sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem
{
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
public override void Initialize()
{
@@ -141,10 +142,7 @@ namespace Content.Server.Shuttles.EntitySystems
component.SubscribedPilots.Add(pilotComponent);
if (EntityManager.TryGetComponent(entity, out ServerAlertsComponent? alertsComponent))
{
alertsComponent.ShowAlert(AlertType.PilotingShuttle);
}
_alertsSystem.ShowAlert(entity, AlertType.PilotingShuttle);
entity.PopupMessage(Loc.GetString("shuttle-pilot-start"));
pilotComponent.Console = component;
@@ -163,10 +161,7 @@ namespace Content.Server.Shuttles.EntitySystems
if (!helmsman.SubscribedPilots.Remove(pilotComponent)) return;
if (EntityManager.TryGetComponent(pilotComponent.Owner, out ServerAlertsComponent? alertsComponent))
{
alertsComponent.ClearAlert(AlertType.PilotingShuttle);
}
_alertsSystem.ClearAlert(pilotComponent.Owner, AlertType.PilotingShuttle);
pilotComponent.Owner.PopupMessage(Loc.GetString("shuttle-pilot-end"));

View File

@@ -1,9 +1,7 @@
using System;
using System.Text;
using System.Text.RegularExpressions;
using Content.Server.Alert;
using Content.Server.Speech.Components;
using Content.Shared.Alert;
using Content.Shared.Speech.EntitySystems;
using Content.Shared.StatusEffect;
using Robust.Shared.GameObjects;
@@ -28,12 +26,12 @@ namespace Content.Server.Speech.EntitySystems
SubscribeLocalEvent<StutteringAccentComponent, AccentGetEvent>(OnAccent);
}
public override void DoStutter(EntityUid uid, TimeSpan time, bool refresh, StatusEffectsComponent? status = null, SharedAlertsComponent? alerts = null)
public override void DoStutter(EntityUid uid, TimeSpan time, bool refresh, StatusEffectsComponent? status = null)
{
if (!Resolve(uid, ref status, false))
return;
_statusEffectsSystem.TryAddStatusEffect<StutteringAccentComponent>(uid, StutterKey, time, refresh, status, alerts);
_statusEffectsSystem.TryAddStatusEffect<StutteringAccentComponent>(uid, StutterKey, time, refresh, status);
}
private void OnAccent(EntityUid uid, StutteringAccentComponent component, AccentGetEvent args)

View File

@@ -1,5 +1,4 @@
using System;
using Content.Server.Alert;
using Content.Server.Stunnable.Components;
using Content.Shared.Standing;
using Content.Shared.StatusEffect;
@@ -27,20 +26,19 @@ namespace Content.Server.Stunnable
if (EntityManager.TryGetComponent<StatusEffectsComponent>(otherUid, out var status))
{
ServerAlertsComponent? alerts = null;
StandingStateComponent? standingState = null;
AppearanceComponent? appearance = null;
// Let the actual methods log errors for these.
Resolve(otherUid, ref alerts, ref standingState, ref appearance, false);
Resolve(otherUid, ref standingState, ref appearance, false);
_stunSystem.TryStun(otherUid, TimeSpan.FromSeconds(component.StunAmount), true, status, alerts);
_stunSystem.TryStun(otherUid, TimeSpan.FromSeconds(component.StunAmount), true, status);
_stunSystem.TryKnockdown(otherUid, TimeSpan.FromSeconds(component.KnockdownAmount), true,
status, alerts);
status);
_stunSystem.TrySlowdown(otherUid, TimeSpan.FromSeconds(component.SlowdownAmount), true,
component.WalkSpeedMultiplier, component.RunSpeedMultiplier, status, alerts);
component.WalkSpeedMultiplier, component.RunSpeedMultiplier, status);
}
}
}

View File

@@ -2,15 +2,12 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Alert;
using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Temperature.Components;
using Content.Shared.Administration.Logs;
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -20,6 +17,7 @@ namespace Content.Server.Temperature.Systems
{
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
[Dependency] private readonly AdminLogSystem _logSystem = default!;
/// <summary>
@@ -31,13 +29,13 @@ namespace Content.Server.Temperature.Systems
public float UpdateInterval = 1.0f;
private float _accumulatedFrametime = 0.0f;
private float _accumulatedFrametime;
public override void Initialize()
{
SubscribeLocalEvent<TemperatureComponent, OnTemperatureChangeEvent>(EnqueueDamage);
SubscribeLocalEvent<TemperatureComponent, AtmosExposedUpdateEvent>(OnAtmosExposedUpdate);
SubscribeLocalEvent<ServerAlertsComponent, OnTemperatureChangeEvent>(ServerAlert);
SubscribeLocalEvent<AlertsComponent, OnTemperatureChangeEvent>(ServerAlert);
SubscribeLocalEvent<TemperatureProtectionComponent, ModifyChangedTemperatureEvent>(OnTemperatureChangeAttempt);
}
@@ -103,43 +101,43 @@ namespace Content.Server.Temperature.Systems
ChangeHeat(uid, heat * temperature.AtmosTemperatureTransferEfficiency, temperature: temperature );
}
private void ServerAlert(EntityUid uid, ServerAlertsComponent status, OnTemperatureChangeEvent args)
private void ServerAlert(EntityUid uid, AlertsComponent status, OnTemperatureChangeEvent args)
{
switch (args.CurrentTemperature)
{
// Cold strong.
case <= 260:
status.ShowAlert(AlertType.Cold, 3);
_alertsSystem.ShowAlert(uid, AlertType.Cold, 3);
break;
// Cold mild.
case <= 280 and > 260:
status.ShowAlert(AlertType.Cold, 2);
_alertsSystem.ShowAlert(uid, AlertType.Cold, 2);
break;
// Cold weak.
case <= 292 and > 280:
status.ShowAlert(AlertType.Cold, 1);
_alertsSystem.ShowAlert(uid, AlertType.Cold, 1);
break;
// Safe.
case <= 327 and > 292:
status.ClearAlertCategory(AlertCategory.Temperature);
_alertsSystem.ClearAlertCategory(uid, AlertCategory.Temperature);
break;
// Heat weak.
case <= 335 and > 327:
status.ShowAlert(AlertType.Hot, 1);
_alertsSystem.ShowAlert(uid, AlertType.Hot, 1);
break;
// Heat mild.
case <= 360 and > 335:
status.ShowAlert(AlertType.Hot, 2);
_alertsSystem.ShowAlert(uid, AlertType.Hot, 2);
break;
// Heat strong.
case > 360:
status.ShowAlert(AlertType.Hot, 3);
_alertsSystem.ShowAlert(uid, AlertType.Hot, 3);
break;
}
}
@@ -151,7 +149,7 @@ namespace Content.Server.Temperature.Systems
private void ChangeDamage(EntityUid uid, TemperatureComponent temperature)
{
if (!EntityManager.TryGetComponent<DamageableComponent>(uid, out var damage))
if (!EntityManager.HasComponent<DamageableComponent>(uid))
return;
// See this link for where the scaling func comes from: