Remove 700 usages of Component.Owner (#21100)
This commit is contained in:
@@ -53,31 +53,35 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
SubscribeLocalEvent<GasTankComponent, GetVerbsEvent<AlternativeVerb>>(OnGetAlternativeVerb);
|
||||
}
|
||||
|
||||
private void OnGasShutdown(EntityUid uid, GasTankComponent component, ComponentShutdown args)
|
||||
private void OnGasShutdown(Entity<GasTankComponent> gasTank, ref ComponentShutdown args)
|
||||
{
|
||||
DisconnectFromInternals(component);
|
||||
DisconnectFromInternals(gasTank);
|
||||
}
|
||||
|
||||
private void OnGasTankToggleInternals(EntityUid uid, GasTankComponent component, GasTankToggleInternalsMessage args)
|
||||
private void OnGasTankToggleInternals(Entity<GasTankComponent> ent, ref GasTankToggleInternalsMessage args)
|
||||
{
|
||||
if (args.Session is not IPlayerSession playerSession ||
|
||||
playerSession.AttachedEntity is not {} player) return;
|
||||
playerSession.AttachedEntity == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ToggleInternals(component);
|
||||
ToggleInternals(ent);
|
||||
}
|
||||
|
||||
private void OnGasTankSetPressure(EntityUid uid, GasTankComponent component, GasTankSetPressureMessage args)
|
||||
private void OnGasTankSetPressure(Entity<GasTankComponent> ent, ref GasTankSetPressureMessage args)
|
||||
{
|
||||
var pressure = Math.Min(args.Pressure, component.MaxOutputPressure);
|
||||
var pressure = Math.Min(args.Pressure, ent.Comp.MaxOutputPressure);
|
||||
|
||||
component.OutputPressure = pressure;
|
||||
ent.Comp.OutputPressure = pressure;
|
||||
|
||||
UpdateUserInterface(component, true);
|
||||
UpdateUserInterface(ent, true);
|
||||
}
|
||||
|
||||
public void UpdateUserInterface(GasTankComponent component, bool initialUpdate = false)
|
||||
public void UpdateUserInterface(Entity<GasTankComponent> ent, bool initialUpdate = false)
|
||||
{
|
||||
_ui.TrySetUiState(component.Owner, SharedGasTankUiKey.Key,
|
||||
var (owner, component) = ent;
|
||||
_ui.TrySetUiState(owner, SharedGasTankUiKey.Key,
|
||||
new GasTankBoundUserInterfaceState
|
||||
{
|
||||
TankPressure = component.Air?.Pressure ?? 0,
|
||||
@@ -87,10 +91,10 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
});
|
||||
}
|
||||
|
||||
private void BeforeUiOpen(EntityUid uid, GasTankComponent component, BeforeActivatableUIOpenEvent args)
|
||||
private void BeforeUiOpen(Entity<GasTankComponent> ent, ref BeforeActivatableUIOpenEvent args)
|
||||
{
|
||||
// Only initial update includes output pressure information, to avoid overwriting client-input as the updates come in.
|
||||
UpdateUserInterface(component, true);
|
||||
UpdateUserInterface(ent, true);
|
||||
}
|
||||
|
||||
private void OnParentChange(EntityUid uid, GasTankComponent component, ref EntParentChangedMessage args)
|
||||
@@ -115,12 +119,12 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
args.PushMarkup(Loc.GetString(component.IsValveOpen ? "comp-gas-tank-examine-open-valve" : "comp-gas-tank-examine-closed-valve"));
|
||||
}
|
||||
|
||||
private void OnActionToggle(EntityUid uid, GasTankComponent component, ToggleActionEvent args)
|
||||
private void OnActionToggle(Entity<GasTankComponent> gasTank, ref ToggleActionEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
ToggleInternals(component);
|
||||
ToggleInternals(gasTank);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
@@ -130,30 +134,33 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
|
||||
_timer += frameTime;
|
||||
|
||||
if (_timer < TimerDelay) return;
|
||||
if (_timer < TimerDelay)
|
||||
return;
|
||||
|
||||
_timer -= TimerDelay;
|
||||
|
||||
var query = EntityQueryEnumerator<GasTankComponent>();
|
||||
while (query.MoveNext(out var uid, out var gasTank))
|
||||
while (query.MoveNext(out var uid, out var comp))
|
||||
{
|
||||
if (gasTank.IsValveOpen && !gasTank.IsLowPressure)
|
||||
var gasTank = (uid, comp);
|
||||
if (comp.IsValveOpen && !comp.IsLowPressure)
|
||||
{
|
||||
ReleaseGas(uid, gasTank);
|
||||
ReleaseGas(gasTank);
|
||||
}
|
||||
|
||||
if (gasTank.CheckUser)
|
||||
if (comp.CheckUser)
|
||||
{
|
||||
gasTank.CheckUser = false;
|
||||
if (Transform(uid).ParentUid != gasTank.User)
|
||||
comp.CheckUser = false;
|
||||
if (Transform(uid).ParentUid != comp.User)
|
||||
{
|
||||
DisconnectFromInternals(gasTank);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (gasTank.Air != null)
|
||||
if (comp.Air != null)
|
||||
{
|
||||
_atmosphereSystem.React(gasTank.Air, gasTank);
|
||||
_atmosphereSystem.React(comp.Air, comp);
|
||||
}
|
||||
CheckStatus(gasTank);
|
||||
if (_ui.IsUiOpen(uid, SharedGasTankUiKey.Key))
|
||||
@@ -163,47 +170,48 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
private void ReleaseGas(EntityUid uid, GasTankComponent component)
|
||||
private void ReleaseGas(Entity<GasTankComponent> gasTank)
|
||||
{
|
||||
var removed = RemoveAirVolume(component, component.ValveOutputRate * TimerDelay);
|
||||
var environment = _atmosphereSystem.GetContainingMixture(uid, false, true);
|
||||
var removed = RemoveAirVolume(gasTank, gasTank.Comp.ValveOutputRate * TimerDelay);
|
||||
var environment = _atmosphereSystem.GetContainingMixture(gasTank, false, true);
|
||||
if (environment != null)
|
||||
{
|
||||
_atmosphereSystem.Merge(environment, removed);
|
||||
}
|
||||
var impulse = removed.TotalMoles * removed.Temperature;
|
||||
_physics.ApplyLinearImpulse(uid, _random.NextAngle().ToWorldVec() * impulse);
|
||||
_physics.ApplyAngularImpulse(uid, _random.NextFloat(-3f, 3f));
|
||||
_audioSys.PlayPvs(component.RuptureSound, uid);
|
||||
_physics.ApplyLinearImpulse(gasTank, _random.NextAngle().ToWorldVec() * impulse);
|
||||
_physics.ApplyAngularImpulse(gasTank, _random.NextFloat(-3f, 3f));
|
||||
_audioSys.PlayPvs(gasTank.Comp.RuptureSound, gasTank);
|
||||
}
|
||||
|
||||
private void ToggleInternals(GasTankComponent component)
|
||||
private void ToggleInternals(Entity<GasTankComponent> ent)
|
||||
{
|
||||
if (component.IsConnected)
|
||||
if (ent.Comp.IsConnected)
|
||||
{
|
||||
DisconnectFromInternals(component);
|
||||
DisconnectFromInternals(ent);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConnectToInternals(component);
|
||||
ConnectToInternals(ent);
|
||||
}
|
||||
}
|
||||
|
||||
public GasMixture? RemoveAir(GasTankComponent component, float amount)
|
||||
public GasMixture? RemoveAir(Entity<GasTankComponent> gasTank, float amount)
|
||||
{
|
||||
var gas = component.Air?.Remove(amount);
|
||||
CheckStatus(component);
|
||||
var gas = gasTank.Comp.Air?.Remove(amount);
|
||||
CheckStatus(gasTank);
|
||||
return gas;
|
||||
}
|
||||
|
||||
public GasMixture RemoveAirVolume(GasTankComponent component, float volume)
|
||||
public GasMixture RemoveAirVolume(Entity<GasTankComponent> gasTank, float volume)
|
||||
{
|
||||
var component = gasTank.Comp;
|
||||
if (component.Air == null)
|
||||
return new GasMixture(volume);
|
||||
|
||||
var molesNeeded = component.OutputPressure * volume / (Atmospherics.R * component.Air.Temperature);
|
||||
|
||||
var air = RemoveAir(component, molesNeeded);
|
||||
var air = RemoveAir(gasTank, molesNeeded);
|
||||
|
||||
if (air != null)
|
||||
air.Volume = volume;
|
||||
@@ -215,12 +223,13 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
|
||||
public bool CanConnectToInternals(GasTankComponent component)
|
||||
{
|
||||
var internals = GetInternalsComponent(component);
|
||||
var internals = GetInternalsComponent(component, component.User);
|
||||
return internals != null && internals.BreathToolEntity != null && !component.IsValveOpen;
|
||||
}
|
||||
|
||||
public void ConnectToInternals(GasTankComponent component)
|
||||
public void ConnectToInternals(Entity<GasTankComponent> ent)
|
||||
{
|
||||
var (owner, component) = ent;
|
||||
if (component.IsConnected || !CanConnectToInternals(component))
|
||||
return;
|
||||
|
||||
@@ -228,7 +237,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
if (internals == null)
|
||||
return;
|
||||
|
||||
if (_internals.TryConnectTank(internals, component.Owner))
|
||||
if (_internals.TryConnectTank((internals.Owner, internals), owner))
|
||||
component.User = internals.Owner;
|
||||
|
||||
_actions.SetToggled(component.ToggleActionEntity, component.IsConnected);
|
||||
@@ -240,13 +249,14 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
component.ConnectStream?.Stop();
|
||||
|
||||
if (component.ConnectSound != null)
|
||||
component.ConnectStream = _audioSys.PlayPvs(component.ConnectSound, component.Owner);
|
||||
component.ConnectStream = _audioSys.PlayPvs(component.ConnectSound, owner);
|
||||
|
||||
UpdateUserInterface(component);
|
||||
UpdateUserInterface(ent);
|
||||
}
|
||||
|
||||
public void DisconnectFromInternals(GasTankComponent component)
|
||||
public void DisconnectFromInternals(Entity<GasTankComponent> ent)
|
||||
{
|
||||
var (owner, component) = ent;
|
||||
if (component.User == null)
|
||||
return;
|
||||
|
||||
@@ -259,29 +269,30 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
component.DisconnectStream?.Stop();
|
||||
|
||||
if (component.DisconnectSound != null)
|
||||
component.DisconnectStream = _audioSys.PlayPvs(component.DisconnectSound, component.Owner);
|
||||
component.DisconnectStream = _audioSys.PlayPvs(component.DisconnectSound, owner);
|
||||
|
||||
UpdateUserInterface(component);
|
||||
UpdateUserInterface(ent);
|
||||
}
|
||||
|
||||
private InternalsComponent? GetInternalsComponent(GasTankComponent component, EntityUid? owner = null)
|
||||
{
|
||||
owner ??= component.User;
|
||||
if (Deleted(component.Owner)) return null;
|
||||
if (Deleted(component.Owner))return null;
|
||||
if (owner != null) return CompOrNull<InternalsComponent>(owner.Value);
|
||||
return _containers.TryGetContainingContainer(component.Owner, out var container)
|
||||
? CompOrNull<InternalsComponent>(container.Owner)
|
||||
: null;
|
||||
}
|
||||
|
||||
public void AssumeAir(GasTankComponent component, GasMixture giver)
|
||||
public void AssumeAir(Entity<GasTankComponent> ent, GasMixture giver)
|
||||
{
|
||||
_atmosphereSystem.Merge(component.Air, giver);
|
||||
CheckStatus(component);
|
||||
_atmosphereSystem.Merge(ent.Comp.Air, giver);
|
||||
CheckStatus(ent);
|
||||
}
|
||||
|
||||
public void CheckStatus(GasTankComponent component)
|
||||
public void CheckStatus(Entity<GasTankComponent> ent)
|
||||
{
|
||||
var (owner, component) = ent;
|
||||
if (component.Air == null)
|
||||
return;
|
||||
|
||||
@@ -305,7 +316,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
range = GasTankComponent.MaxExplosionRange;
|
||||
}
|
||||
|
||||
_explosions.TriggerExplosive(component.Owner, radius: range);
|
||||
_explosions.TriggerExplosive(owner, radius: range);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -314,13 +325,13 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
if (component.Integrity <= 0)
|
||||
{
|
||||
var environment = _atmosphereSystem.GetContainingMixture(component.Owner, false, true);
|
||||
var environment = _atmosphereSystem.GetContainingMixture(owner, false, true);
|
||||
if(environment != null)
|
||||
_atmosphereSystem.Merge(environment, component.Air);
|
||||
|
||||
_audioSys.Play(component.RuptureSound, Filter.Pvs(component.Owner), Transform(component.Owner).Coordinates, true, AudioParams.Default.WithVariation(0.125f));
|
||||
_audioSys.Play(component.RuptureSound, Filter.Pvs(owner), Transform(owner).Coordinates, true, AudioParams.Default.WithVariation(0.125f));
|
||||
|
||||
QueueDel(component.Owner);
|
||||
QueueDel(owner);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -332,7 +343,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
if (component.Integrity <= 0)
|
||||
{
|
||||
var environment = _atmosphereSystem.GetContainingMixture(component.Owner, false, true);
|
||||
var environment = _atmosphereSystem.GetContainingMixture(owner, false, true);
|
||||
if (environment == null)
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user