Remove 700 usages of Component.Owner (#21100)
This commit is contained in:
@@ -4,7 +4,6 @@ using Content.Shared.Explosion;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
@@ -32,18 +31,22 @@ public sealed class ClusterGrenadeSystem : EntitySystem
|
||||
component.GrenadesContainer = _container.EnsureContainer<Container>(uid, "cluster-flash");
|
||||
}
|
||||
|
||||
private void OnClugStartup(EntityUid uid, ClusterGrenadeComponent component, ComponentStartup args)
|
||||
private void OnClugStartup(Entity<ClusterGrenadeComponent> clug, ref ComponentStartup args)
|
||||
{
|
||||
var component = clug.Comp;
|
||||
if (component.FillPrototype != null)
|
||||
{
|
||||
component.UnspawnedCount = Math.Max(0, component.MaxGrenades - component.GrenadesContainer.ContainedEntities.Count);
|
||||
UpdateAppearance(uid, component);
|
||||
UpdateAppearance(clug);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClugUsing(EntityUid uid, ClusterGrenadeComponent component, InteractUsingEvent args)
|
||||
private void OnClugUsing(Entity<ClusterGrenadeComponent> clug, ref InteractUsingEvent args)
|
||||
{
|
||||
if (args.Handled) return;
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
var component = clug.Comp;
|
||||
|
||||
// TODO: Should use whitelist.
|
||||
if (component.GrenadesContainer.ContainedEntities.Count >= component.MaxGrenades ||
|
||||
@@ -51,7 +54,7 @@ public sealed class ClusterGrenadeSystem : EntitySystem
|
||||
return;
|
||||
|
||||
component.GrenadesContainer.Insert(args.Used);
|
||||
UpdateAppearance(uid, component);
|
||||
UpdateAppearance(clug);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
@@ -63,7 +66,7 @@ public sealed class ClusterGrenadeSystem : EntitySystem
|
||||
// TODO: Should be an Update loop
|
||||
uid.SpawnTimer((int) (component.Delay * 1000), () =>
|
||||
{
|
||||
if (Deleted(component.Owner))
|
||||
if (Deleted(uid))
|
||||
return;
|
||||
|
||||
component.CountDown = true;
|
||||
@@ -71,7 +74,7 @@ public sealed class ClusterGrenadeSystem : EntitySystem
|
||||
var grenadesInserted = component.GrenadesContainer.ContainedEntities.Count + component.UnspawnedCount;
|
||||
var thrownCount = 0;
|
||||
var segmentAngle = 360 / grenadesInserted;
|
||||
while (TryGetGrenade(component, out var grenade))
|
||||
while (TryGetGrenade((uid, component), out var grenade))
|
||||
{
|
||||
var angleMin = segmentAngle * thrownCount;
|
||||
var angleMax = segmentAngle * (thrownCount + 1);
|
||||
@@ -99,14 +102,15 @@ public sealed class ClusterGrenadeSystem : EntitySystem
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private bool TryGetGrenade(ClusterGrenadeComponent component, out EntityUid grenade)
|
||||
private bool TryGetGrenade(Entity<ClusterGrenadeComponent> ent, out EntityUid grenade)
|
||||
{
|
||||
grenade = default;
|
||||
var component = ent.Comp;
|
||||
|
||||
if (component.UnspawnedCount > 0)
|
||||
{
|
||||
component.UnspawnedCount--;
|
||||
grenade = EntityManager.SpawnEntity(component.FillPrototype, Transform(component.Owner).MapPosition);
|
||||
grenade = EntityManager.SpawnEntity(component.FillPrototype, Transform(ent).MapPosition);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -124,10 +128,12 @@ public sealed class ClusterGrenadeSystem : EntitySystem
|
||||
return false;
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, ClusterGrenadeComponent component)
|
||||
private void UpdateAppearance(Entity<ClusterGrenadeComponent> ent)
|
||||
{
|
||||
if (!TryComp<AppearanceComponent>(component.Owner, out var appearance)) return;
|
||||
var component = ent.Comp;
|
||||
if (!TryComp<AppearanceComponent>(ent, out var appearance))
|
||||
return;
|
||||
|
||||
_appearance.SetData(uid, ClusterGrenadeVisuals.GrenadesCounter, component.GrenadesContainer.ContainedEntities.Count + component.UnspawnedCount, appearance);
|
||||
_appearance.SetData(ent, ClusterGrenadeVisuals.GrenadesCounter, component.GrenadesContainer.ContainedEntities.Count + component.UnspawnedCount, appearance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
// if the explosion is centered on some grid (and not just space), get the transforms.
|
||||
if (referenceGrid != null)
|
||||
{
|
||||
var targetGrid = _mapManager.GetGrid(referenceGrid.Value);
|
||||
var xform = Transform(targetGrid.Owner);
|
||||
var targetGrid = Comp<MapGridComponent>(referenceGrid.Value);
|
||||
var xform = Transform(referenceGrid.Value);
|
||||
targetAngle = xform.WorldRotation;
|
||||
targetMatrix = xform.InvWorldMatrix;
|
||||
tileSize = targetGrid.TileSize;
|
||||
@@ -84,17 +84,17 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
if (!_gridEdges.TryGetValue(gridToTransform, out var edges))
|
||||
continue;
|
||||
|
||||
if (!_mapManager.TryGetGrid(gridToTransform, out var grid))
|
||||
if (!TryComp(gridToTransform, out MapGridComponent? grid))
|
||||
continue;
|
||||
|
||||
if (grid.TileSize != tileSize)
|
||||
{
|
||||
Logger.Error($"Explosions do not support grids with different grid sizes. GridIds: {gridToTransform} and {referenceGrid}");
|
||||
Log.Error($"Explosions do not support grids with different grid sizes. GridIds: {gridToTransform} and {referenceGrid}");
|
||||
continue;
|
||||
}
|
||||
|
||||
var xforms = EntityManager.GetEntityQuery<TransformComponent>();
|
||||
var xform = xforms.GetComponent(grid.Owner);
|
||||
var xform = xforms.GetComponent(gridToTransform);
|
||||
var (_, gridWorldRotation, gridWorldMatrix, invGridWorldMatrid) = xform.GetWorldPositionRotationMatrixWithInv(xforms);
|
||||
|
||||
var localEpicentre = (Vector2i) invGridWorldMatrid.Transform(epicentre.Position);
|
||||
@@ -228,7 +228,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
if (!ev.NewTile.Tile.IsEmpty && !ev.OldTile.IsEmpty)
|
||||
return;
|
||||
|
||||
if (!_mapManager.TryGetGrid(ev.Entity, out var grid))
|
||||
if (!TryComp(ev.Entity, out MapGridComponent? grid))
|
||||
return;
|
||||
|
||||
var tileRef = ev.NewTile;
|
||||
|
||||
@@ -4,7 +4,6 @@ using Content.Server.Speech.Components;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Explosion.EntitySystems
|
||||
{
|
||||
@@ -26,39 +25,43 @@ namespace Content.Server.Explosion.EntitySystems
|
||||
RemCompDeferred<ActiveListenerComponent>(uid);
|
||||
}
|
||||
|
||||
private void OnListen(EntityUid uid, TriggerOnVoiceComponent component, ListenEvent args)
|
||||
private void OnListen(Entity<TriggerOnVoiceComponent> ent, ref ListenEvent args)
|
||||
{
|
||||
var component = ent.Comp;
|
||||
var message = args.Message.Trim();
|
||||
|
||||
if (component.IsRecording)
|
||||
{
|
||||
if (message.Length >= component.MinLength || message.Length <= component.MaxLength)
|
||||
FinishRecording(component, args.Source, args.Message);
|
||||
FinishRecording(ent, args.Source, args.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(component.KeyPhrase) && message.Contains(component.KeyPhrase, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
_adminLogger.Add(LogType.Trigger, LogImpact.High,
|
||||
$"A voice-trigger on {ToPrettyString(uid):entity} was triggered by {ToPrettyString(args.Source):speaker} speaking the key-phrase {component.KeyPhrase}.");
|
||||
Trigger(uid, args.Source);
|
||||
$"A voice-trigger on {ToPrettyString(ent):entity} was triggered by {ToPrettyString(args.Source):speaker} speaking the key-phrase {component.KeyPhrase}.");
|
||||
Trigger(ent, args.Source);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnVoiceGetAltVerbs(EntityUid uid, TriggerOnVoiceComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||||
private void OnVoiceGetAltVerbs(Entity<TriggerOnVoiceComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
if (!args.CanInteract || !args.CanAccess)
|
||||
return;
|
||||
|
||||
var component = ent.Comp;
|
||||
|
||||
var @event = args;
|
||||
args.Verbs.Add(new AlternativeVerb()
|
||||
{
|
||||
Text = Loc.GetString(component.IsRecording ? "verb-trigger-voice-record-stop" : "verb-trigger-voice-record"),
|
||||
Act = () =>
|
||||
{
|
||||
if (component.IsRecording)
|
||||
StopRecording(component);
|
||||
StopRecording(ent);
|
||||
else
|
||||
StartRecording(component, args.User);
|
||||
StartRecording(ent, @event.User);
|
||||
},
|
||||
Priority = 1
|
||||
});
|
||||
@@ -73,40 +76,43 @@ namespace Content.Server.Explosion.EntitySystems
|
||||
{
|
||||
component.KeyPhrase = null;
|
||||
component.IsRecording = false;
|
||||
RemComp<ActiveListenerComponent>(uid);
|
||||
RemComp<ActiveListenerComponent>(ent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void StartRecording(TriggerOnVoiceComponent component, EntityUid user)
|
||||
public void StartRecording(Entity<TriggerOnVoiceComponent> ent, EntityUid user)
|
||||
{
|
||||
var component = ent.Comp;
|
||||
component.IsRecording = true;
|
||||
EnsureComp<ActiveListenerComponent>(component.Owner).Range = component.ListenRange;
|
||||
EnsureComp<ActiveListenerComponent>(ent).Range = component.ListenRange;
|
||||
|
||||
_adminLogger.Add(LogType.Trigger, LogImpact.Low,
|
||||
$"A voice-trigger on {ToPrettyString(component.Owner):entity} has started recording. User: {ToPrettyString(user):user}");
|
||||
$"A voice-trigger on {ToPrettyString(ent):entity} has started recording. User: {ToPrettyString(user):user}");
|
||||
|
||||
_popupSystem.PopupEntity(Loc.GetString("popup-trigger-voice-start-recording"), component.Owner);
|
||||
_popupSystem.PopupEntity(Loc.GetString("popup-trigger-voice-start-recording"), ent);
|
||||
}
|
||||
|
||||
public void StopRecording(TriggerOnVoiceComponent component)
|
||||
public void StopRecording(Entity<TriggerOnVoiceComponent> ent)
|
||||
{
|
||||
var component = ent.Comp;
|
||||
component.IsRecording = false;
|
||||
if (string.IsNullOrWhiteSpace(component.KeyPhrase))
|
||||
RemComp<ActiveListenerComponent>(component.Owner);
|
||||
RemComp<ActiveListenerComponent>(ent);
|
||||
|
||||
_popupSystem.PopupEntity(Loc.GetString("popup-trigger-voice-stop-recording"), component.Owner);
|
||||
_popupSystem.PopupEntity(Loc.GetString("popup-trigger-voice-stop-recording"), ent);
|
||||
}
|
||||
|
||||
public void FinishRecording(TriggerOnVoiceComponent component, EntityUid source, string message)
|
||||
public void FinishRecording(Entity<TriggerOnVoiceComponent> ent, EntityUid source, string message)
|
||||
{
|
||||
var component = ent.Comp;
|
||||
component.KeyPhrase = message;
|
||||
component.IsRecording = false;
|
||||
|
||||
_adminLogger.Add(LogType.Trigger, LogImpact.Low,
|
||||
$"A voice-trigger on {ToPrettyString(component.Owner):entity} has recorded a new keyphrase: '{component.KeyPhrase}'. Recorded from {ToPrettyString(source):speaker}");
|
||||
$"A voice-trigger on {ToPrettyString(ent):entity} has recorded a new keyphrase: '{component.KeyPhrase}'. Recorded from {ToPrettyString(source):speaker}");
|
||||
|
||||
_popupSystem.PopupEntity(Loc.GetString("popup-trigger-voice-recorded", ("keyphrase", component.KeyPhrase!)), component.Owner);
|
||||
_popupSystem.PopupEntity(Loc.GetString("popup-trigger-voice-recorded", ("keyphrase", component.KeyPhrase!)), ent);
|
||||
}
|
||||
|
||||
private void OnVoiceExamine(EntityUid uid, TriggerOnVoiceComponent component, ExaminedEvent args)
|
||||
|
||||
Reference in New Issue
Block a user