Remove 700 usages of Component.Owner (#21100)
This commit is contained in:
@@ -9,8 +9,6 @@ using Content.Shared.Temperature;
|
||||
using Content.Shared.Verbs;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Light.EntitySystems
|
||||
@@ -36,15 +34,18 @@ namespace Content.Server.Light.EntitySystems
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var light in EntityManager.EntityQuery<ExpendableLightComponent>())
|
||||
var query = EntityQueryEnumerator<ExpendableLightComponent>();
|
||||
while (query.MoveNext(out var uid, out var light))
|
||||
{
|
||||
UpdateLight(light, frameTime);
|
||||
UpdateLight((uid, light), frameTime);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLight(ExpendableLightComponent component, float frameTime)
|
||||
private void UpdateLight(Entity<ExpendableLightComponent> ent, float frameTime)
|
||||
{
|
||||
if (!component.Activated) return;
|
||||
var component = ent.Comp;
|
||||
if (!component.Activated)
|
||||
return;
|
||||
|
||||
component.StateExpiryTime -= frameTime;
|
||||
|
||||
@@ -56,25 +57,25 @@ namespace Content.Server.Light.EntitySystems
|
||||
component.CurrentState = ExpendableLightState.Fading;
|
||||
component.StateExpiryTime = component.FadeOutDuration;
|
||||
|
||||
UpdateVisualizer(component);
|
||||
UpdateVisualizer(ent);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
case ExpendableLightState.Fading:
|
||||
component.CurrentState = ExpendableLightState.Dead;
|
||||
var meta = MetaData(component.Owner);
|
||||
_metaData.SetEntityName(component.Owner, Loc.GetString(component.SpentName), meta);
|
||||
_metaData.SetEntityDescription(component.Owner, Loc.GetString(component.SpentDesc), meta);
|
||||
var meta = MetaData(ent);
|
||||
_metaData.SetEntityName(ent, Loc.GetString(component.SpentName), meta);
|
||||
_metaData.SetEntityDescription(ent, Loc.GetString(component.SpentDesc), meta);
|
||||
|
||||
_tagSystem.AddTag(component.Owner, "Trash");
|
||||
_tagSystem.AddTag(ent, "Trash");
|
||||
|
||||
UpdateSounds(component);
|
||||
UpdateVisualizer(component);
|
||||
UpdateSounds(ent);
|
||||
UpdateVisualizer(ent);
|
||||
|
||||
if (TryComp<ItemComponent>(component.Owner, out var item))
|
||||
if (TryComp<ItemComponent>(ent, out var item))
|
||||
{
|
||||
_item.SetHeldPrefix(component.Owner, "unlit", item);
|
||||
_item.SetHeldPrefix(ent, "unlit", item);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -85,20 +86,21 @@ namespace Content.Server.Light.EntitySystems
|
||||
/// <summary>
|
||||
/// Enables the light if it is not active. Once active it cannot be turned off.
|
||||
/// </summary>
|
||||
public bool TryActivate(ExpendableLightComponent component)
|
||||
public bool TryActivate(Entity<ExpendableLightComponent> ent)
|
||||
{
|
||||
var component = ent.Comp;
|
||||
if (!component.Activated && component.CurrentState == ExpendableLightState.BrandNew)
|
||||
{
|
||||
if (TryComp<ItemComponent>(component.Owner, out var item))
|
||||
if (TryComp<ItemComponent>(ent, out var item))
|
||||
{
|
||||
_item.SetHeldPrefix(component.Owner, "lit", item);
|
||||
_item.SetHeldPrefix(ent, "lit", item);
|
||||
}
|
||||
|
||||
component.CurrentState = ExpendableLightState.Lit;
|
||||
component.StateExpiryTime = component.GlowDuration;
|
||||
|
||||
UpdateSounds(component);
|
||||
UpdateVisualizer(component);
|
||||
UpdateSounds(ent);
|
||||
UpdateVisualizer(ent);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -106,49 +108,51 @@ namespace Content.Server.Light.EntitySystems
|
||||
return false;
|
||||
}
|
||||
|
||||
private void UpdateVisualizer(ExpendableLightComponent component, AppearanceComponent? appearance = null)
|
||||
private void UpdateVisualizer(Entity<ExpendableLightComponent> ent, AppearanceComponent? appearance = null)
|
||||
{
|
||||
if (!Resolve(component.Owner, ref appearance, false)) return;
|
||||
var component = ent.Comp;
|
||||
if (!Resolve(ent, ref appearance, false))
|
||||
return;
|
||||
|
||||
_appearance.SetData(appearance.Owner, ExpendableLightVisuals.State, component.CurrentState, appearance);
|
||||
_appearance.SetData(ent, ExpendableLightVisuals.State, component.CurrentState, appearance);
|
||||
|
||||
switch (component.CurrentState)
|
||||
{
|
||||
case ExpendableLightState.Lit:
|
||||
_appearance.SetData(appearance.Owner, ExpendableLightVisuals.Behavior, component.TurnOnBehaviourID, appearance);
|
||||
_appearance.SetData(ent, ExpendableLightVisuals.Behavior, component.TurnOnBehaviourID, appearance);
|
||||
break;
|
||||
|
||||
case ExpendableLightState.Fading:
|
||||
_appearance.SetData(appearance.Owner, ExpendableLightVisuals.Behavior, component.FadeOutBehaviourID, appearance);
|
||||
_appearance.SetData(ent, ExpendableLightVisuals.Behavior, component.FadeOutBehaviourID, appearance);
|
||||
break;
|
||||
|
||||
case ExpendableLightState.Dead:
|
||||
_appearance.SetData(appearance.Owner, ExpendableLightVisuals.Behavior, string.Empty, appearance);
|
||||
_appearance.SetData(ent, ExpendableLightVisuals.Behavior, string.Empty, appearance);
|
||||
var isHotEvent = new IsHotEvent() {IsHot = true};
|
||||
RaiseLocalEvent(component.Owner, isHotEvent);
|
||||
RaiseLocalEvent(ent, isHotEvent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateSounds(ExpendableLightComponent component)
|
||||
private void UpdateSounds(Entity<ExpendableLightComponent> ent)
|
||||
{
|
||||
var uid = component.Owner;
|
||||
var component = ent.Comp;
|
||||
|
||||
switch (component.CurrentState)
|
||||
{
|
||||
case ExpendableLightState.Lit:
|
||||
_audio.PlayPvs(component.LitSound, uid);
|
||||
_audio.PlayPvs(component.LitSound, ent);
|
||||
break;
|
||||
case ExpendableLightState.Fading:
|
||||
break;
|
||||
default:
|
||||
_audio.PlayPvs(component.DieSound, uid);
|
||||
_audio.PlayPvs(component.DieSound, ent);
|
||||
break;
|
||||
}
|
||||
|
||||
if (TryComp<ClothingComponent>(uid, out var clothing))
|
||||
if (TryComp<ClothingComponent>(ent, out var clothing))
|
||||
{
|
||||
_clothing.SetEquippedPrefix(uid, component.Activated ? "Activated" : string.Empty, clothing);
|
||||
_clothing.SetEquippedPrefix(ent, component.Activated ? "Activated" : string.Empty, clothing);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,21 +167,23 @@ namespace Content.Server.Light.EntitySystems
|
||||
EntityManager.EnsureComponent<PointLightComponent>(uid);
|
||||
}
|
||||
|
||||
private void OnExpLightUse(EntityUid uid, ExpendableLightComponent component, UseInHandEvent args)
|
||||
private void OnExpLightUse(Entity<ExpendableLightComponent> ent, ref UseInHandEvent args)
|
||||
{
|
||||
if (args.Handled) return;
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
var isHotEvent = new IsHotEvent() {IsHot = true};
|
||||
RaiseLocalEvent(uid, isHotEvent);
|
||||
if (TryActivate(component))
|
||||
RaiseLocalEvent(ent, isHotEvent);
|
||||
if (TryActivate(ent))
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void AddIgniteVerb(EntityUid uid, ExpendableLightComponent component, GetVerbsEvent<ActivationVerb> args)
|
||||
private void AddIgniteVerb(Entity<ExpendableLightComponent> ent, ref GetVerbsEvent<ActivationVerb> args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract)
|
||||
return;
|
||||
|
||||
if (component.CurrentState != ExpendableLightState.BrandNew)
|
||||
if (ent.Comp.CurrentState != ExpendableLightState.BrandNew)
|
||||
return;
|
||||
|
||||
// Ignite the flare or make the glowstick glow.
|
||||
@@ -186,7 +192,7 @@ namespace Content.Server.Light.EntitySystems
|
||||
{
|
||||
Text = Loc.GetString("expendable-light-start-verb"),
|
||||
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/light.svg.192dpi.png")),
|
||||
Act = () => TryActivate(component)
|
||||
Act = () => TryActivate(ent)
|
||||
};
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user