Remove 700 usages of Component.Owner (#21100)
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Singularity.Events;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Physics;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Singularity.Events;
|
||||
using Content.Shared.Construction.Components;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
|
||||
@@ -52,7 +52,7 @@ public sealed class ContainmentFieldGeneratorSystem : EntitySystem
|
||||
|
||||
if (generator.Accumulator >= generator.Threshold)
|
||||
{
|
||||
LosePower(uid, generator.PowerLoss, generator);
|
||||
LosePower((uid, generator), generator.PowerLoss);
|
||||
generator.Accumulator -= generator.Threshold;
|
||||
}
|
||||
}
|
||||
@@ -63,12 +63,12 @@ public sealed class ContainmentFieldGeneratorSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// A generator receives power from a source colliding with it.
|
||||
/// </summary>
|
||||
private void HandleGeneratorCollide(EntityUid uid, ContainmentFieldGeneratorComponent component, ref StartCollideEvent args)
|
||||
private void HandleGeneratorCollide(Entity<ContainmentFieldGeneratorComponent> generator, ref StartCollideEvent args)
|
||||
{
|
||||
if (_tags.HasTag(args.OtherEntity, component.IDTag))
|
||||
if (_tags.HasTag(args.OtherEntity, generator.Comp.IDTag))
|
||||
{
|
||||
ReceivePower(component.PowerReceived, component);
|
||||
component.Accumulator = 0f;
|
||||
ReceivePower(generator.Comp.PowerReceived, generator);
|
||||
generator.Comp.Accumulator = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,35 +81,35 @@ public sealed class ContainmentFieldGeneratorSystem : EntitySystem
|
||||
args.PushMarkup(Loc.GetString("comp-containment-off"));
|
||||
}
|
||||
|
||||
private void OnInteract(EntityUid uid, ContainmentFieldGeneratorComponent component, InteractHandEvent args)
|
||||
private void OnInteract(Entity<ContainmentFieldGeneratorComponent> generator, ref InteractHandEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (TryComp(component.Owner, out TransformComponent? transformComp) && transformComp.Anchored)
|
||||
if (TryComp(generator, out TransformComponent? transformComp) && transformComp.Anchored)
|
||||
{
|
||||
if (!component.Enabled)
|
||||
TurnOn(component);
|
||||
else if (component.Enabled && component.IsConnected)
|
||||
if (!generator.Comp.Enabled)
|
||||
TurnOn(generator);
|
||||
else if (generator.Comp.Enabled && generator.Comp.IsConnected)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-containment-toggle-warning"), args.User, args.User, PopupType.LargeCaution);
|
||||
return;
|
||||
}
|
||||
else
|
||||
TurnOff(component);
|
||||
TurnOff(generator);
|
||||
}
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnAnchorChanged(EntityUid uid, ContainmentFieldGeneratorComponent component, ref AnchorStateChangedEvent args)
|
||||
private void OnAnchorChanged(Entity<ContainmentFieldGeneratorComponent> generator, ref AnchorStateChangedEvent args)
|
||||
{
|
||||
if (!args.Anchored)
|
||||
RemoveConnections(uid, component);
|
||||
RemoveConnections(generator);
|
||||
}
|
||||
|
||||
private void OnReanchorEvent(EntityUid uid, ContainmentFieldGeneratorComponent component, ref ReAnchorEvent args)
|
||||
private void OnReanchorEvent(Entity<ContainmentFieldGeneratorComponent> generator, ref ReAnchorEvent args)
|
||||
{
|
||||
GridCheck(uid, component);
|
||||
GridCheck(generator);
|
||||
}
|
||||
|
||||
private void OnUnanchorAttempt(EntityUid uid, ContainmentFieldGeneratorComponent component,
|
||||
@@ -122,41 +122,42 @@ public sealed class ContainmentFieldGeneratorSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
private void TurnOn(ContainmentFieldGeneratorComponent component)
|
||||
private void TurnOn(Entity<ContainmentFieldGeneratorComponent> generator)
|
||||
{
|
||||
component.Enabled = true;
|
||||
ChangeFieldVisualizer(component);
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-containment-turned-on"), component.Owner);
|
||||
generator.Comp.Enabled = true;
|
||||
ChangeFieldVisualizer(generator);
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-containment-turned-on"), generator);
|
||||
}
|
||||
|
||||
private void TurnOff(ContainmentFieldGeneratorComponent component)
|
||||
private void TurnOff(Entity<ContainmentFieldGeneratorComponent> generator)
|
||||
{
|
||||
component.Enabled = false;
|
||||
ChangeFieldVisualizer(component);
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-containment-turned-off"), component.Owner);
|
||||
generator.Comp.Enabled = false;
|
||||
ChangeFieldVisualizer(generator);
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-containment-turned-off"), generator);
|
||||
}
|
||||
|
||||
private void OnComponentRemoved(EntityUid uid, ContainmentFieldGeneratorComponent component, ComponentRemove args)
|
||||
private void OnComponentRemoved(Entity<ContainmentFieldGeneratorComponent> generator, ref ComponentRemove args)
|
||||
{
|
||||
RemoveConnections(uid, component);
|
||||
RemoveConnections(generator);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the fields and removes the respective connections for the generators.
|
||||
/// </summary>
|
||||
private void RemoveConnections(EntityUid uid, ContainmentFieldGeneratorComponent component)
|
||||
private void RemoveConnections(Entity<ContainmentFieldGeneratorComponent> generator)
|
||||
{
|
||||
var (uid, component) = generator;
|
||||
foreach (var (direction, value) in component.Connections)
|
||||
{
|
||||
foreach (var field in value.Item2)
|
||||
{
|
||||
QueueDel(field);
|
||||
}
|
||||
value.Item1.Connections.Remove(direction.GetOpposite());
|
||||
value.Item1.Comp.Connections.Remove(direction.GetOpposite());
|
||||
|
||||
if (value.Item1.Connections.Count == 0) //Change isconnected only if there's no more connections
|
||||
if (value.Item1.Comp.Connections.Count == 0) //Change isconnected only if there's no more connections
|
||||
{
|
||||
value.Item1.IsConnected = false;
|
||||
value.Item1.Comp.IsConnected = false;
|
||||
ChangeOnLightVisualizer(value.Item1);
|
||||
}
|
||||
|
||||
@@ -164,10 +165,10 @@ public sealed class ContainmentFieldGeneratorSystem : EntitySystem
|
||||
}
|
||||
component.Connections.Clear();
|
||||
component.IsConnected = false;
|
||||
ChangeOnLightVisualizer(component);
|
||||
ChangeFieldVisualizer(component);
|
||||
ChangeOnLightVisualizer(generator);
|
||||
ChangeFieldVisualizer(generator);
|
||||
_adminLogger.Add(LogType.FieldGeneration, LogImpact.Medium, $"{ToPrettyString(uid)} lost field connections"); // Ideally LogImpact would depend on if there is a singulo nearby
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-containment-disconnected"), component.Owner, PopupType.LargeCaution);
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-containment-disconnected"), uid, PopupType.LargeCaution);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -178,11 +179,12 @@ public sealed class ContainmentFieldGeneratorSystem : EntitySystem
|
||||
/// Stores power in the generator. If it hits the threshold, it tries to establish a connection.
|
||||
/// </summary>
|
||||
/// <param name="power">The power that this generator received from the collision in <see cref="HandleGeneratorCollide"/></param>
|
||||
public void ReceivePower(int power, ContainmentFieldGeneratorComponent component)
|
||||
public void ReceivePower(int power, Entity<ContainmentFieldGeneratorComponent> generator)
|
||||
{
|
||||
var component = generator.Comp;
|
||||
component.PowerBuffer += power;
|
||||
|
||||
var genXForm = Transform(component.Owner);
|
||||
var genXForm = Transform(generator);
|
||||
|
||||
if (component.PowerBuffer >= component.PowerMinimum)
|
||||
{
|
||||
@@ -194,23 +196,24 @@ public sealed class ContainmentFieldGeneratorSystem : EntitySystem
|
||||
if (component.Connections.ContainsKey(dir))
|
||||
continue; // This direction already has an active connection
|
||||
|
||||
TryGenerateFieldConnection(dir, component, genXForm);
|
||||
TryGenerateFieldConnection(dir, generator, genXForm);
|
||||
}
|
||||
}
|
||||
|
||||
ChangePowerVisualizer(power, component);
|
||||
ChangePowerVisualizer(power, generator);
|
||||
}
|
||||
|
||||
public void LosePower(EntityUid uid, int power, ContainmentFieldGeneratorComponent component)
|
||||
public void LosePower(Entity<ContainmentFieldGeneratorComponent> generator, int power)
|
||||
{
|
||||
var component = generator.Comp;
|
||||
component.PowerBuffer -= power;
|
||||
|
||||
if (component.PowerBuffer < component.PowerMinimum && component.Connections.Count != 0)
|
||||
{
|
||||
RemoveConnections(uid, component);
|
||||
RemoveConnections(generator);
|
||||
}
|
||||
|
||||
ChangePowerVisualizer(power, component);
|
||||
ChangePowerVisualizer(power, generator);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -218,11 +221,12 @@ public sealed class ContainmentFieldGeneratorSystem : EntitySystem
|
||||
/// If all the checks pass and fields spawn, it will store this connection on each respective generator.
|
||||
/// </summary>
|
||||
/// <param name="dir">The field generator establishes a connection in this direction.</param>
|
||||
/// <param name="component">The field generator component</param>
|
||||
/// <param name="generator">The field generator component</param>
|
||||
/// <param name="gen1XForm">The transform component for the first generator</param>
|
||||
/// <returns></returns>
|
||||
private bool TryGenerateFieldConnection(Direction dir, ContainmentFieldGeneratorComponent component, TransformComponent gen1XForm)
|
||||
private bool TryGenerateFieldConnection(Direction dir, Entity<ContainmentFieldGeneratorComponent> generator, TransformComponent gen1XForm)
|
||||
{
|
||||
var component = generator.Comp;
|
||||
if (!component.Enabled)
|
||||
return false;
|
||||
|
||||
@@ -233,7 +237,7 @@ public sealed class ContainmentFieldGeneratorSystem : EntitySystem
|
||||
var dirRad = dir.ToAngle() + genWorldPosRot.WorldRotation; //needs to be like this for the raycast to work properly
|
||||
|
||||
var ray = new CollisionRay(genWorldPosRot.WorldPosition, dirRad.ToVec(), component.CollisionMask);
|
||||
var rayCastResults = _physics.IntersectRay(gen1XForm.MapID, ray, component.MaxLength, component.Owner, false);
|
||||
var rayCastResults = _physics.IntersectRay(gen1XForm.MapID, ray, component.MaxLength, generator, false);
|
||||
var genQuery = GetEntityQuery<ContainmentFieldGeneratorComponent>();
|
||||
|
||||
RayCastResults? closestResult = null;
|
||||
@@ -254,46 +258,47 @@ public sealed class ContainmentFieldGeneratorSystem : EntitySystem
|
||||
otherFieldGeneratorComponent == component ||
|
||||
!TryComp<PhysicsComponent>(ent, out var collidableComponent) ||
|
||||
collidableComponent.BodyType != BodyType.Static ||
|
||||
gen1XForm.ParentUid != Transform(otherFieldGeneratorComponent.Owner).ParentUid)
|
||||
gen1XForm.ParentUid != Transform(ent).ParentUid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var fields = GenerateFieldConnection(component, otherFieldGeneratorComponent);
|
||||
var otherFieldGenerator = (ent, otherFieldGeneratorComponent);
|
||||
var fields = GenerateFieldConnection(generator, otherFieldGenerator);
|
||||
|
||||
component.Connections[dir] = (otherFieldGeneratorComponent, fields);
|
||||
otherFieldGeneratorComponent.Connections[dir.GetOpposite()] = (component, fields);
|
||||
ChangeFieldVisualizer(otherFieldGeneratorComponent);
|
||||
component.Connections[dir] = (otherFieldGenerator, fields);
|
||||
otherFieldGeneratorComponent.Connections[dir.GetOpposite()] = (generator, fields);
|
||||
ChangeFieldVisualizer(otherFieldGenerator);
|
||||
|
||||
if (!component.IsConnected)
|
||||
{
|
||||
component.IsConnected = true;
|
||||
ChangeOnLightVisualizer(component);
|
||||
ChangeOnLightVisualizer(generator);
|
||||
}
|
||||
|
||||
if (!otherFieldGeneratorComponent.IsConnected)
|
||||
{
|
||||
otherFieldGeneratorComponent.IsConnected = true;
|
||||
ChangeOnLightVisualizer(otherFieldGeneratorComponent);
|
||||
ChangeOnLightVisualizer(otherFieldGenerator);
|
||||
}
|
||||
|
||||
ChangeFieldVisualizer(component);
|
||||
UpdateConnectionLights(component);
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-containment-connected"), component.Owner);
|
||||
ChangeFieldVisualizer(generator);
|
||||
UpdateConnectionLights(generator);
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-containment-connected"), generator);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawns fields between two generators if the <see cref="TryGenerateFieldConnection"/> finds two generators to connect.
|
||||
/// </summary>
|
||||
/// <param name="firstGenComp">The source field generator</param>
|
||||
/// <param name="secondGenComp">The second generator that the source is connected to</param>
|
||||
/// <param name="firstGen">The source field generator</param>
|
||||
/// <param name="secondGen">The second generator that the source is connected to</param>
|
||||
/// <returns></returns>
|
||||
private List<EntityUid> GenerateFieldConnection(ContainmentFieldGeneratorComponent firstGenComp, ContainmentFieldGeneratorComponent secondGenComp)
|
||||
private List<EntityUid> GenerateFieldConnection(Entity<ContainmentFieldGeneratorComponent> firstGen, Entity<ContainmentFieldGeneratorComponent> secondGen)
|
||||
{
|
||||
var fieldList = new List<EntityUid>();
|
||||
var gen1Coords = Transform(firstGenComp.Owner).Coordinates;
|
||||
var gen2Coords = Transform(secondGenComp.Owner).Coordinates;
|
||||
var gen1Coords = Transform(firstGen).Coordinates;
|
||||
var gen2Coords = Transform(secondGen).Coordinates;
|
||||
|
||||
var delta = (gen2Coords - gen1Coords).Position;
|
||||
var dirVec = delta.Normalized();
|
||||
@@ -302,10 +307,10 @@ public sealed class ContainmentFieldGeneratorSystem : EntitySystem
|
||||
while (currentOffset.Length() < stopDist)
|
||||
{
|
||||
var currentCoords = gen1Coords.Offset(currentOffset);
|
||||
var newField = Spawn(firstGenComp.CreatedField, currentCoords);
|
||||
var newField = Spawn(firstGen.Comp.CreatedField, currentCoords);
|
||||
|
||||
var fieldXForm = Transform(newField);
|
||||
fieldXForm.AttachParent(firstGenComp.Owner);
|
||||
fieldXForm.AttachParent(firstGen);
|
||||
if (dirVec.GetDir() == Direction.East || dirVec.GetDir() == Direction.West)
|
||||
{
|
||||
var angle = fieldXForm.LocalPosition.ToAngle();
|
||||
@@ -324,28 +329,28 @@ public sealed class ContainmentFieldGeneratorSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Creates a light component for the spawned fields.
|
||||
/// </summary>
|
||||
public void UpdateConnectionLights(ContainmentFieldGeneratorComponent component)
|
||||
public void UpdateConnectionLights(Entity<ContainmentFieldGeneratorComponent> generator)
|
||||
{
|
||||
if (_light.TryGetLight(component.Owner, out var pointLightComponent))
|
||||
if (_light.TryGetLight(generator, out var pointLightComponent))
|
||||
{
|
||||
_light.SetEnabled(component.Owner, component.Connections.Count > 0, pointLightComponent);
|
||||
_light.SetEnabled(generator, generator.Comp.Connections.Count > 0, pointLightComponent);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if this or the other gens connected to a new grid. If they did, remove connection.
|
||||
/// </summary>
|
||||
public void GridCheck(EntityUid uid, ContainmentFieldGeneratorComponent component)
|
||||
public void GridCheck(Entity<ContainmentFieldGeneratorComponent> generator)
|
||||
{
|
||||
var xFormQuery = GetEntityQuery<TransformComponent>();
|
||||
|
||||
foreach (var (_, generators) in component.Connections)
|
||||
foreach (var (_, generators) in generator.Comp.Connections)
|
||||
{
|
||||
var gen1ParentGrid = xFormQuery.GetComponent(component.Owner).ParentUid;
|
||||
var gent2ParentGrid = xFormQuery.GetComponent(generators.Item1.Owner).ParentUid;
|
||||
var gen1ParentGrid = xFormQuery.GetComponent(generator).ParentUid;
|
||||
var gent2ParentGrid = xFormQuery.GetComponent(generators.Item1).ParentUid;
|
||||
|
||||
if (gen1ParentGrid != gent2ParentGrid)
|
||||
RemoveConnections(uid, component);
|
||||
RemoveConnections(generator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,32 +361,37 @@ public sealed class ContainmentFieldGeneratorSystem : EntitySystem
|
||||
/// Check if a fields power falls between certain ranges to update the field gen visual for power.
|
||||
/// </summary>
|
||||
/// <param name="power"></param>
|
||||
/// <param name="component"></param>
|
||||
private void ChangePowerVisualizer(int power, ContainmentFieldGeneratorComponent component)
|
||||
/// <param name="generator"></param>
|
||||
private void ChangePowerVisualizer(int power, Entity<ContainmentFieldGeneratorComponent> generator)
|
||||
{
|
||||
_visualizer.SetData(component.Owner, ContainmentFieldGeneratorVisuals.PowerLight, component.PowerBuffer switch {
|
||||
<=0 => PowerLevelVisuals.NoPower,
|
||||
>=25 => PowerLevelVisuals.HighPower,
|
||||
_ => (component.PowerBuffer < component.PowerMinimum) ? PowerLevelVisuals.LowPower : PowerLevelVisuals.MediumPower
|
||||
var component = generator.Comp;
|
||||
_visualizer.SetData(generator, ContainmentFieldGeneratorVisuals.PowerLight, component.PowerBuffer switch
|
||||
{
|
||||
<= 0 => PowerLevelVisuals.NoPower,
|
||||
>= 25 => PowerLevelVisuals.HighPower,
|
||||
_ => (component.PowerBuffer < component.PowerMinimum)
|
||||
? PowerLevelVisuals.LowPower
|
||||
: PowerLevelVisuals.MediumPower
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a field has any or no connections and if it's enabled to toggle the field level light
|
||||
/// </summary>
|
||||
/// <param name="component"></param>
|
||||
private void ChangeFieldVisualizer(ContainmentFieldGeneratorComponent component)
|
||||
/// <param name="generator"></param>
|
||||
private void ChangeFieldVisualizer(Entity<ContainmentFieldGeneratorComponent> generator)
|
||||
{
|
||||
_visualizer.SetData(component.Owner, ContainmentFieldGeneratorVisuals.FieldLight, component.Connections.Count switch {
|
||||
_visualizer.SetData(generator, ContainmentFieldGeneratorVisuals.FieldLight, generator.Comp.Connections.Count switch
|
||||
{
|
||||
>1 => FieldLevelVisuals.MultipleFields,
|
||||
1 => FieldLevelVisuals.OneField,
|
||||
_ => component.Enabled ? FieldLevelVisuals.On : FieldLevelVisuals.NoLevel
|
||||
_ => generator.Comp.Enabled ? FieldLevelVisuals.On : FieldLevelVisuals.NoLevel
|
||||
});
|
||||
}
|
||||
|
||||
private void ChangeOnLightVisualizer(ContainmentFieldGeneratorComponent component)
|
||||
private void ChangeOnLightVisualizer(Entity<ContainmentFieldGeneratorComponent> generator)
|
||||
{
|
||||
_visualizer.SetData(component.Owner, ContainmentFieldGeneratorVisuals.OnLight, component.IsConnected);
|
||||
_visualizer.SetData(generator, ContainmentFieldGeneratorVisuals.OnLight, generator.Comp.IsConnected);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user