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);
|
||||
}
|
||||
|
||||
@@ -9,18 +9,14 @@ using Content.Shared.Light.Components;
|
||||
using Content.Shared.Rounding;
|
||||
using Content.Shared.Toggleable;
|
||||
using Content.Shared.Verbs;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Light.EntitySystems
|
||||
{
|
||||
public sealed class HandheldLightSystem : SharedHandheldLightSystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
[Dependency] private readonly ActionsSystem _actions = default!;
|
||||
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
|
||||
[Dependency] private readonly PopupSystem _popup = default!;
|
||||
@@ -31,7 +27,7 @@ namespace Content.Server.Light.EntitySystems
|
||||
|
||||
// TODO: Ideally you'd be able to subscribe to power stuff to get events at certain percentages.. or something?
|
||||
// But for now this will be better anyway.
|
||||
private readonly HashSet<HandheldLightComponent> _activeLights = new();
|
||||
private readonly HashSet<Entity<HandheldLightComponent>> _activeLights = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -55,22 +51,16 @@ namespace Content.Server.Light.EntitySystems
|
||||
SubscribeLocalEvent<HandheldLightComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
|
||||
}
|
||||
|
||||
private void OnEntInserted(
|
||||
EntityUid uid,
|
||||
HandheldLightComponent component,
|
||||
EntInsertedIntoContainerMessage args)
|
||||
private void OnEntInserted(Entity<HandheldLightComponent> ent, ref EntInsertedIntoContainerMessage args)
|
||||
{
|
||||
// Not guaranteed to be the correct container for our slot, I don't care.
|
||||
UpdateLevel(uid, component);
|
||||
UpdateLevel(ent);
|
||||
}
|
||||
|
||||
private void OnEntRemoved(
|
||||
EntityUid uid,
|
||||
HandheldLightComponent component,
|
||||
EntRemovedFromContainerMessage args)
|
||||
private void OnEntRemoved(Entity<HandheldLightComponent> ent, ref EntRemovedFromContainerMessage args)
|
||||
{
|
||||
// Ditto above
|
||||
UpdateLevel(uid, component);
|
||||
UpdateLevel(ent);
|
||||
}
|
||||
|
||||
private void OnGetActions(EntityUid uid, HandheldLightComponent component, GetItemActionsEvent args)
|
||||
@@ -78,28 +68,29 @@ namespace Content.Server.Light.EntitySystems
|
||||
args.AddAction(ref component.ToggleActionEntity, component.ToggleAction);
|
||||
}
|
||||
|
||||
private void OnToggleAction(EntityUid uid, HandheldLightComponent component, ToggleActionEvent args)
|
||||
private void OnToggleAction(Entity<HandheldLightComponent> ent, ref ToggleActionEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (component.Activated)
|
||||
TurnOff(uid, component);
|
||||
if (ent.Comp.Activated)
|
||||
TurnOff(ent);
|
||||
else
|
||||
TurnOn(args.Performer, uid, component);
|
||||
TurnOn(args.Performer, ent);
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, HandheldLightComponent component, ref ComponentGetState args)
|
||||
private void OnGetState(Entity<HandheldLightComponent> ent, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new HandheldLightComponent.HandheldLightComponentState(component.Activated, GetLevel(uid, component));
|
||||
args.State = new HandheldLightComponent.HandheldLightComponentState(ent.Comp.Activated, GetLevel(ent));
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, HandheldLightComponent component, MapInitEvent args)
|
||||
private void OnMapInit(Entity<HandheldLightComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
_actionContainer.EnsureAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
|
||||
_actions.AddAction(uid, ref component.SelfToggleActionEntity, component.ToggleAction);
|
||||
var component = ent.Comp;
|
||||
_actionContainer.EnsureAction(ent, ref component.ToggleActionEntity, component.ToggleAction);
|
||||
_actions.AddAction(ent, ref component.SelfToggleActionEntity, component.ToggleAction);
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, HandheldLightComponent component, ComponentShutdown args)
|
||||
@@ -108,31 +99,31 @@ namespace Content.Server.Light.EntitySystems
|
||||
_actions.RemoveAction(uid, component.SelfToggleActionEntity);
|
||||
}
|
||||
|
||||
private byte? GetLevel(EntityUid uid, HandheldLightComponent component)
|
||||
private byte? GetLevel(Entity<HandheldLightComponent> ent)
|
||||
{
|
||||
// Curently every single flashlight has the same number of levels for status and that's all it uses the charge for
|
||||
// Thus we'll just check if the level changes.
|
||||
|
||||
if (!_powerCell.TryGetBatteryFromSlot(uid, out var battery))
|
||||
if (!_powerCell.TryGetBatteryFromSlot(ent, out var battery))
|
||||
return null;
|
||||
|
||||
if (MathHelper.CloseToPercent(battery.CurrentCharge, 0) || component.Wattage > battery.CurrentCharge)
|
||||
if (MathHelper.CloseToPercent(battery.CurrentCharge, 0) || ent.Comp.Wattage > battery.CurrentCharge)
|
||||
return 0;
|
||||
|
||||
return (byte?) ContentHelpers.RoundToNearestLevels(battery.CurrentCharge / battery.MaxCharge * 255, 255, HandheldLightComponent.StatusLevels);
|
||||
}
|
||||
|
||||
private void OnRemove(EntityUid uid, HandheldLightComponent component, ComponentRemove args)
|
||||
private void OnRemove(Entity<HandheldLightComponent> ent, ref ComponentRemove args)
|
||||
{
|
||||
_activeLights.Remove(component);
|
||||
_activeLights.Remove(ent);
|
||||
}
|
||||
|
||||
private void OnActivate(EntityUid uid, HandheldLightComponent component, ActivateInWorldEvent args)
|
||||
private void OnActivate(Entity<HandheldLightComponent> ent, ref ActivateInWorldEvent args)
|
||||
{
|
||||
if (args.Handled || !component.ToggleOnInteract)
|
||||
if (args.Handled || !ent.Comp.ToggleOnInteract)
|
||||
return;
|
||||
|
||||
if (ToggleStatus(args.User, uid, component))
|
||||
if (ToggleStatus(args.User, ent))
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
@@ -140,9 +131,9 @@ namespace Content.Server.Light.EntitySystems
|
||||
/// Illuminates the light if it is not active, extinguishes it if it is active.
|
||||
/// </summary>
|
||||
/// <returns>True if the light's status was toggled, false otherwise.</returns>
|
||||
public bool ToggleStatus(EntityUid user, EntityUid uid, HandheldLightComponent component)
|
||||
public bool ToggleStatus(EntityUid user, Entity<HandheldLightComponent> ent)
|
||||
{
|
||||
return component.Activated ? TurnOff(uid, component) : TurnOn(user, uid, component);
|
||||
return ent.Comp.Activated ? TurnOff(ent) : TurnOn(user, ent);
|
||||
}
|
||||
|
||||
private void OnExamine(EntityUid uid, HandheldLightComponent component, ExaminedEvent args)
|
||||
@@ -160,20 +151,20 @@ namespace Content.Server.Light.EntitySystems
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
var toRemove = new RemQueue<HandheldLightComponent>();
|
||||
var toRemove = new RemQueue<Entity<HandheldLightComponent>>();
|
||||
|
||||
foreach (var handheld in _activeLights)
|
||||
{
|
||||
var uid = handheld.Owner;
|
||||
|
||||
if (handheld.Deleted)
|
||||
if (handheld.Comp.Deleted)
|
||||
{
|
||||
toRemove.Add(handheld);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Paused(uid)) continue;
|
||||
TryUpdate(uid, handheld, frameTime);
|
||||
if (Paused(handheld))
|
||||
continue;
|
||||
|
||||
TryUpdate(handheld, frameTime);
|
||||
}
|
||||
|
||||
foreach (var light in toRemove)
|
||||
@@ -182,39 +173,41 @@ namespace Content.Server.Light.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
private void AddToggleLightVerb(EntityUid uid, HandheldLightComponent component, GetVerbsEvent<ActivationVerb> args)
|
||||
private void AddToggleLightVerb(Entity<HandheldLightComponent> ent, ref GetVerbsEvent<ActivationVerb> args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract || !component.ToggleOnInteract)
|
||||
if (!args.CanAccess || !args.CanInteract || !ent.Comp.ToggleOnInteract)
|
||||
return;
|
||||
|
||||
var @event = args;
|
||||
ActivationVerb verb = new()
|
||||
{
|
||||
Text = Loc.GetString("verb-common-toggle-light"),
|
||||
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/light.svg.192dpi.png")),
|
||||
Act = component.Activated
|
||||
? () => TurnOff(uid, component)
|
||||
: () => TurnOn(args.User, uid, component)
|
||||
Act = ent.Comp.Activated
|
||||
? () => TurnOff(ent)
|
||||
: () => TurnOn(@event.User, ent)
|
||||
};
|
||||
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
public bool TurnOff(EntityUid uid, HandheldLightComponent component, bool makeNoise = true)
|
||||
public bool TurnOff(Entity<HandheldLightComponent> ent, bool makeNoise = true)
|
||||
{
|
||||
if (!component.Activated || !_lights.TryGetLight(uid, out var pointLightComponent))
|
||||
if (!ent.Comp.Activated || !_lights.TryGetLight(ent, out var pointLightComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_lights.SetEnabled(uid, false, pointLightComponent);
|
||||
SetActivated(uid, false, component, makeNoise);
|
||||
component.Level = null;
|
||||
_activeLights.Remove(component);
|
||||
_lights.SetEnabled(ent, false, pointLightComponent);
|
||||
SetActivated(ent, false, ent, makeNoise);
|
||||
ent.Comp.Level = null;
|
||||
_activeLights.Remove(ent);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TurnOn(EntityUid user, EntityUid uid, HandheldLightComponent component)
|
||||
public bool TurnOn(EntityUid user, Entity<HandheldLightComponent> uid)
|
||||
{
|
||||
var component = uid.Comp;
|
||||
if (component.Activated || !_lights.TryGetLight(uid, out var pointLightComponent))
|
||||
{
|
||||
return false;
|
||||
@@ -240,17 +233,18 @@ namespace Content.Server.Light.EntitySystems
|
||||
|
||||
_lights.SetEnabled(uid, true, pointLightComponent);
|
||||
SetActivated(uid, true, component, true);
|
||||
_activeLights.Add(component);
|
||||
_activeLights.Add(uid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void TryUpdate(EntityUid uid, HandheldLightComponent component, float frameTime)
|
||||
public void TryUpdate(Entity<HandheldLightComponent> uid, float frameTime)
|
||||
{
|
||||
var component = uid.Comp;
|
||||
if (!_powerCell.TryGetBatteryFromSlot(uid, out var battery) &&
|
||||
!TryComp(uid, out battery))
|
||||
{
|
||||
TurnOff(uid, component, false);
|
||||
TurnOff(uid, false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -271,20 +265,20 @@ namespace Content.Server.Light.EntitySystems
|
||||
}
|
||||
|
||||
if (component.Activated && !battery.TryUseCharge(component.Wattage * frameTime))
|
||||
TurnOff(uid, component, false);
|
||||
TurnOff(uid, false);
|
||||
|
||||
UpdateLevel(uid, component);
|
||||
UpdateLevel(uid);
|
||||
}
|
||||
|
||||
private void UpdateLevel(EntityUid uid, HandheldLightComponent comp)
|
||||
private void UpdateLevel(Entity<HandheldLightComponent> ent)
|
||||
{
|
||||
var level = GetLevel(uid, comp);
|
||||
var level = GetLevel(ent);
|
||||
|
||||
if (level == comp.Level)
|
||||
if (level == ent.Comp.Level)
|
||||
return;
|
||||
|
||||
comp.Level = level;
|
||||
Dirty(comp);
|
||||
ent.Comp.Level = level;
|
||||
Dirty(ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Content.Server.Light.EntitySystems
|
||||
&& EntityManager.TryGetComponent(args.Used, out MatchstickComponent? matchstick)
|
||||
&& matchstick.CurrentState == SmokableState.Unlit)
|
||||
{
|
||||
_stickSystem.Ignite(args.Used, matchstick, args.User);
|
||||
_stickSystem.Ignite((args.Used, matchstick), args.User);
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Content.Server.Light.EntitySystems
|
||||
[Dependency] private readonly SharedPointLightSystem _lights = default!;
|
||||
[Dependency] private readonly TransformSystem _transformSystem = default!;
|
||||
|
||||
private HashSet<MatchstickComponent> _litMatches = new();
|
||||
private readonly HashSet<Entity<MatchstickComponent>> _litMatches = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -29,42 +29,43 @@ namespace Content.Server.Light.EntitySystems
|
||||
SubscribeLocalEvent<MatchstickComponent, ComponentShutdown>(OnShutdown);
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, MatchstickComponent component, ComponentShutdown args)
|
||||
private void OnShutdown(Entity<MatchstickComponent> ent, ref ComponentShutdown args)
|
||||
{
|
||||
_litMatches.Remove(component);
|
||||
_litMatches.Remove(ent);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
foreach (var match in _litMatches)
|
||||
{
|
||||
if (match.CurrentState != SmokableState.Lit || Paused(match.Owner) || match.Deleted)
|
||||
if (match.Comp.CurrentState != SmokableState.Lit || Paused(match) || match.Comp.Deleted)
|
||||
continue;
|
||||
|
||||
var xform = Transform(match.Owner);
|
||||
var xform = Transform(match);
|
||||
|
||||
if (xform.GridUid is not {} gridUid)
|
||||
return;
|
||||
|
||||
var position = _transformSystem.GetGridOrMapTilePosition(match.Owner, xform);
|
||||
var position = _transformSystem.GetGridOrMapTilePosition(match, xform);
|
||||
|
||||
_atmosphereSystem.HotspotExpose(gridUid, position, 400, 50, match.Owner, true);
|
||||
_atmosphereSystem.HotspotExpose(gridUid, position, 400, 50, match, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInteractUsing(EntityUid uid, MatchstickComponent component, InteractUsingEvent args)
|
||||
private void OnInteractUsing(Entity<MatchstickComponent> ent, ref InteractUsingEvent args)
|
||||
{
|
||||
if (args.Handled || component.CurrentState != SmokableState.Unlit)
|
||||
if (args.Handled || ent.Comp.CurrentState != SmokableState.Unlit)
|
||||
return;
|
||||
|
||||
var isHotEvent = new IsHotEvent();
|
||||
RaiseLocalEvent(args.Used, isHotEvent, false);
|
||||
RaiseLocalEvent(args.Used, isHotEvent);
|
||||
|
||||
if (!isHotEvent.IsHot)
|
||||
return;
|
||||
|
||||
Ignite(uid, component, args.User);
|
||||
Ignite(ent, args.User);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
@@ -73,19 +74,21 @@ namespace Content.Server.Light.EntitySystems
|
||||
args.IsHot = component.CurrentState == SmokableState.Lit;
|
||||
}
|
||||
|
||||
public void Ignite(EntityUid uid, MatchstickComponent component, EntityUid user)
|
||||
public void Ignite(Entity<MatchstickComponent> matchstick, EntityUid user)
|
||||
{
|
||||
var component = matchstick.Comp;
|
||||
|
||||
// Play Sound
|
||||
SoundSystem.Play(component.IgniteSound.GetSound(), Filter.Pvs(component.Owner),
|
||||
component.Owner, AudioHelpers.WithVariation(0.125f).WithVolume(-0.125f));
|
||||
SoundSystem.Play(component.IgniteSound.GetSound(), Filter.Pvs(matchstick),
|
||||
matchstick, AudioHelpers.WithVariation(0.125f).WithVolume(-0.125f));
|
||||
|
||||
// Change state
|
||||
SetState(uid, component, SmokableState.Lit);
|
||||
_litMatches.Add(component);
|
||||
component.Owner.SpawnTimer(component.Duration * 1000, delegate
|
||||
SetState(matchstick, component, SmokableState.Lit);
|
||||
_litMatches.Add(matchstick);
|
||||
matchstick.Owner.SpawnTimer(component.Duration * 1000, delegate
|
||||
{
|
||||
SetState(uid, component, SmokableState.Burnt);
|
||||
_litMatches.Remove(component);
|
||||
SetState(matchstick, component, SmokableState.Burnt);
|
||||
_litMatches.Remove(matchstick);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Clothing.Components;
|
||||
using Content.Server.DeviceLinking.Events;
|
||||
using Content.Server.DeviceLinking.Systems;
|
||||
using Content.Server.DeviceNetwork;
|
||||
using Content.Server.DeviceNetwork.Systems;
|
||||
using Content.Server.Emp;
|
||||
using Content.Server.Ghost;
|
||||
using Content.Server.Light.Components;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Temperature.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Light;
|
||||
using Content.Shared.Light.Components;
|
||||
using Content.Shared.Popups;
|
||||
@@ -19,11 +23,6 @@ using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Server.Emp;
|
||||
using Content.Server.DeviceLinking.Events;
|
||||
using Content.Server.DeviceLinking.Systems;
|
||||
using Content.Shared.Inventory;
|
||||
|
||||
namespace Content.Server.Light.EntitySystems
|
||||
{
|
||||
@@ -333,7 +332,7 @@ namespace Content.Server.Light.EntitySystems
|
||||
light.LastGhostBlink = time;
|
||||
|
||||
ToggleBlinkingLight(uid, light, true);
|
||||
light.Owner.SpawnTimer(light.GhostBlinkingTime, () =>
|
||||
uid.SpawnTimer(light.GhostBlinkingTime, () =>
|
||||
{
|
||||
ToggleBlinkingLight(uid, light, false);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user