private void OnCanisterContainerRemoved(EntityUid uid, GasCanisterComponent component, EntRemovedFromContainerMessage args) { if (args.Container.ID != component.ContainerName) { return; } DirtyUI(uid); if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer) || !nodeContainer.TryGetNode(component.TankName, out PipeNode? tankNode)) { return; } tankNode.NodeGroup.RemakeGroup(); tankNode.ConnectToContainedEntities = false; tankNode.EnvironmentalAir = true; if (!ComponentManager.TryGetComponent(uid, out AppearanceComponent? appearance)) { return; } appearance.SetData(GasCanisterVisuals.TankInserted, false); }
private void OnCanisterInteractUsing(EntityUid canister, GasCanisterComponent component, InteractUsingEvent args) { var container = canister.EnsureContainer <ContainerSlot>(component.ContainerName); // Container full. if (container.ContainedEntity != null) { return; } // Check the used item is valid... if (!EntityManager.TryGetComponent(args.Used, out GasTankComponent? _)) { return; } if (!_handsSystem.TryDropIntoContainer(args.User, args.Used, container)) { return; } _adminLogger.Add(LogType.CanisterTankInserted, LogImpact.Medium, $"Player {ToPrettyString(args.User):player} inserted tank {ToPrettyString(container.ContainedEntities[0]):tank} into {ToPrettyString(canister):canister}"); args.Handled = true; }
private static void OnBodyTypeChanged( EntityUid uid, GasCanisterComponent component, PhysicsBodyTypeChangedEvent args) { component.AnchorUpdate(); }
private void OnCanisterInteractUsing(EntityUid uid, GasCanisterComponent component, InteractUsingEvent args) { var canister = EntityManager.GetEntity(uid); var container = canister.EnsureContainer <ContainerSlot>(component.ContainerName); // Container full. if (container.ContainedEntity != null) { return; } // Check the used item is valid... if (!args.Used.TryGetComponent(out GasTankComponent? _)) { return; } // Check the user has hands. if (!args.User.TryGetComponent(out HandsComponent? hands)) { return; } if (!args.User.InRangeUnobstructed(canister, SharedInteractionSystem.InteractionRange, popup: true)) { return; } if (!hands.TryPutEntityIntoContainer(args.Used, container)) { return; } args.Handled = true; }
private void OnCanisterChangeReleasePressure(EntityUid uid, GasCanisterComponent canister, GasCanisterChangeReleasePressureMessage args) { var pressure = Math.Clamp(args.Pressure, canister.MinReleasePressure, canister.MaxReleasePressure); _adminLogger.Add(LogType.CanisterPressure, LogImpact.Medium, $"{ToPrettyString(args.Session.AttachedEntity.GetValueOrDefault()):player} set the release pressure on {ToPrettyString(uid):canister} to {args.Pressure}"); canister.ReleasePressure = pressure; DirtyUI(uid, canister); }
private void OnCanisterChangeReleaseValve(EntityUid uid, GasCanisterComponent canister, GasCanisterChangeReleaseValveMessage args) { if (!CheckInteract(args.Session)) { return; } canister.ReleaseValve = args.Valve; DirtyUI(uid, canister); }
private void OnCanisterInteractHand(EntityUid uid, GasCanisterComponent component, InteractHandEvent args) { if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor)) { return; } _userInterfaceSystem.GetUiOrNull(uid, GasCanisterUiKey.Key)?.Open(actor.PlayerSession); args.Handled = true; }
private void OnCanisterInteractHand(EntityUid uid, GasCanisterComponent component, InteractHandEvent args) { if (!args.User.TryGetComponent(out ActorComponent? actor)) { return; } component.Owner.GetUIOrNull(GasCanisterUiKey.Key)?.Open(actor.PlayerSession); args.Handled = true; }
private void OnCanisterStartup(EntityUid uid, GasCanisterComponent canister, ComponentStartup args) { // Ensure container manager. var containerManager = EntityManager.EnsureComponent <ContainerManagerComponent>(uid); // Ensure container. if (!containerManager.TryGetContainer(canister.ContainerName, out _)) { containerManager.MakeContainer <ContainerSlot>(canister.ContainerName); } }
private void OnCanisterChangeReleasePressure(EntityUid uid, GasCanisterComponent canister, GasCanisterChangeReleasePressureMessage args) { if (!CheckInteract(args.Session)) { return; } var pressure = Math.Clamp(args.Pressure, canister.MinReleasePressure, canister.MaxReleasePressure); canister.ReleasePressure = pressure; DirtyUI(uid, canister); }
private void OnCanisterChangeReleasePressure(EntityUid uid, GasCanisterComponent canister, GasCanisterChangeReleasePressureMessage args) { if (!CheckInteract(args.Session)) { return; } var pressure = Math.Clamp(args.Pressure, canister.MinReleasePressure, canister.MaxReleasePressure); _adminLogSystem.Add(LogType.CanisterPressure, LogImpact.Medium, $"{args.Session.AttachedEntity:player} set the release pressure on {uid} to {args.Pressure}"); canister.ReleasePressure = pressure; DirtyUI(uid, canister); }
private void OnCanisterChangeReleaseValve(EntityUid uid, GasCanisterComponent canister, GasCanisterChangeReleaseValveMessage args) { var impact = LogImpact.High; if (EntityManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager) && containerManager.TryGetContainer(canister.ContainerName, out var container)) { impact = container.ContainedEntities.Count != 0 ? LogImpact.Medium : LogImpact.High; } _adminLogger.Add(LogType.CanisterValve, impact, $"{ToPrettyString(args.Session.AttachedEntity.GetValueOrDefault()):player} set the valve on {ToPrettyString(uid):canister} to {args.Valve:valveState}"); canister.ReleaseValve = args.Valve; DirtyUI(uid, canister); }
private void OnCanisterContainerInserted(EntityUid uid, GasCanisterComponent component, EntInsertedIntoContainerMessage args) { if (args.Container.ID != component.ContainerName) { return; } DirtyUI(uid, component); if (!EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance)) { return; } appearance.SetData(GasCanisterVisuals.TankInserted, true); }
private void OnHoldingTankEjectMessage(EntityUid uid, GasCanisterComponent canister, GasCanisterHoldingTankEjectMessage args) { if (!EntityManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager) || !containerManager.TryGetContainer(canister.ContainerName, out var container)) { return; } if (container.ContainedEntities.Count == 0) { return; } _adminLogger.Add(LogType.CanisterTankEjected, LogImpact.Medium, $"Player {ToPrettyString(args.Session.AttachedEntity.GetValueOrDefault()):player} ejected tank {ToPrettyString(container.ContainedEntities[0]):tank} from {ToPrettyString(uid):canister}"); container.Remove(container.ContainedEntities[0]); }
private void OnCanisterContainerRemoved(EntityUid uid, GasCanisterComponent component, EntRemovedFromContainerMessage args) { if (args.Container.ID != component.ContainerName) { return; } DirtyUI(uid); if (!ComponentManager.TryGetComponent(uid, out AppearanceComponent? appearance)) { return; } appearance.SetData(GasCanisterVisuals.TankInserted, false); }
private void OnCanisterUIMessage(EntityUid uid, GasCanisterComponent canister, ServerBoundUserInterfaceMessage msg) { if (msg.Session.AttachedEntity is not { } entity || !Get <ActionBlockerSystem>().CanInteract(entity) || !Get <ActionBlockerSystem>().CanUse(entity)) { return; } if (!ComponentManager.TryGetComponent(uid, out GasPassiveGateComponent? passiveGate) || !ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager) || !containerManager.TryGetContainer(canister.ContainerName, out var container)) { return; } switch (msg.Message) { case GasCanisterHoldingTankEjectMessage: if (container.ContainedEntities.Count == 0) { break; } container.Remove(container.ContainedEntities[0]); break; case GasCanisterChangeReleasePressureMessage changeReleasePressure: var pressure = Math.Clamp(changeReleasePressure.Pressure, canister.MinReleasePressure, canister.MaxReleasePressure); passiveGate.TargetPressure = pressure; DirtyUI(uid); break; case GasCanisterChangeReleaseValveMessage changeReleaseValve: passiveGate.Enabled = changeReleaseValve.Valve; DirtyUI(uid); break; } }
private void OnHoldingTankEjectMessage(EntityUid uid, GasCanisterComponent canister, GasCanisterHoldingTankEjectMessage args) { if (!CheckInteract(args.Session)) { return; } if (!EntityManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager) || !containerManager.TryGetContainer(canister.ContainerName, out var container)) { return; } if (container.ContainedEntities.Count == 0) { return; } container.Remove(container.ContainedEntities[0]); }
private void OnCanisterChangeReleaseValve(EntityUid uid, GasCanisterComponent canister, GasCanisterChangeReleaseValveMessage args) { if (!CheckInteract(args.Session)) { return; } var impact = LogImpact.High; if (EntityManager.TryGetComponent(uid, out ContainerManagerComponent containerManager) && containerManager.TryGetContainer(canister.ContainerName, out var container)) { impact = container.ContainedEntities.Count != 0 ? LogImpact.Medium : LogImpact.High; } _adminLogSystem.Add(LogType.CanisterValve, impact, $"{args.Session.AttachedEntity:player} set the valve on {uid} to {args.Valve:valveState}"); canister.ReleaseValve = args.Valve; DirtyUI(uid, canister); }
private void OnCanisterStartup(EntityUid uid, GasCanisterComponent canister, ComponentStartup args) { // TODO ATMOS: Don't use Owner to get the UI. if (canister.Owner.GetUIOrNull(GasCanisterUiKey.Key) is {} ui) { ui.OnReceiveMessage += msg => OnCanisterUIMessage(uid, canister, msg); } // Ensure container manager. if (!ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager)) { containerManager = ComponentManager.AddComponent <ContainerManagerComponent>(EntityManager.GetEntity(uid)); } // Ensure container. if (!containerManager.TryGetContainer(canister.ContainerName, out _)) { containerManager.MakeContainer <ContainerSlot>(canister.ContainerName); } }
private void OnHoldingTankEjectMessage(EntityUid uid, GasCanisterComponent canister, GasCanisterHoldingTankEjectMessage args) { if (!CheckInteract(args.Session)) { return; } if (!EntityManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager) || !containerManager.TryGetContainer(canister.ContainerName, out var container)) { return; } if (container.ContainedEntities.Count == 0) { return; } _adminLogSystem.Add(LogType.CanisterTankEjected, LogImpact.Medium, $"Player {args.Session.AttachedEntity:player} ejected tank {container.ContainedEntities[0]:tank} from {uid}"); container.Remove(container.ContainedEntities[0]); }
private void OnCanisterUpdated(EntityUid uid, GasCanisterComponent canister, AtmosDeviceUpdateEvent args) { if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer) || !ComponentManager.TryGetComponent(uid, out AppearanceComponent? appearance)) { return; } if (!nodeContainer.TryGetNode(canister.PortName, out PipeNode? portNode)) { return; } DirtyUI(uid); // Nothing to do here. if (MathHelper.CloseTo(portNode.Air.Pressure, canister.LastPressure)) { return; } canister.LastPressure = portNode.Air.Pressure; if (portNode.Air.Pressure < 10) { appearance.SetData(GasCanisterVisuals.PressureState, 0); } else if (portNode.Air.Pressure < Atmospherics.OneAtmosphere) { appearance.SetData(GasCanisterVisuals.PressureState, 1); } else if (portNode.Air.Pressure < (15 * Atmospherics.OneAtmosphere)) { appearance.SetData(GasCanisterVisuals.PressureState, 2); } else { appearance.SetData(GasCanisterVisuals.PressureState, 3); } }
private void OnCanisterStartup(EntityUid uid, GasCanisterComponent canister, ComponentStartup args) { // TODO ATMOS: Don't use Owner to get the UI. if (canister.Owner.GetUIOrNull(GasCanisterUiKey.Key) is {} ui) { ui.OnReceiveMessage += msg => OnCanisterUIMessage(uid, canister, msg); } if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)) { return; } if (!nodeContainer.TryGetNode(canister.PortName, out PipeNode? portNode)) { return; } // Create a pipenet if we don't have one already. portNode.TryAssignGroupIfNeeded(); portNode.Air.Merge(canister.InitialMixture); portNode.Air.Temperature = canister.InitialMixture.Temperature; portNode.Volume = canister.InitialMixture.Volume; }
private void OnCanisterInteractUsing(EntityUid canister, GasCanisterComponent component, InteractUsingEvent args) { var container = canister.EnsureContainer <ContainerSlot>(component.ContainerName); // Container full. if (container.ContainedEntity != null) { return; } // Check the used item is valid... if (!EntityManager.TryGetComponent(args.Used, out GasTankComponent? _)) { return; } // Check the user has hands. if (!EntityManager.TryGetComponent(args.User, out HandsComponent? hands)) { return; } if (!args.User.InRangeUnobstructed(canister, SharedInteractionSystem.InteractionRange, popup: true)) { return; } if (!hands.Drop(args.Used, container)) { return; } _adminLogSystem.Add(LogType.CanisterTankInserted, LogImpact.Medium, $"Player {args.User:player} inserted tank {container.ContainedEntities[0]} into {canister}"); args.Handled = true; }
private void OnCanisterUpdated(EntityUid uid, GasCanisterComponent canister, AtmosDeviceUpdateEvent args) { if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer) || !ComponentManager.TryGetComponent(uid, out AppearanceComponent? appearance)) { return; } if (!nodeContainer.TryGetNode(canister.PortName, out PipeNode? portNode)) { return; } // Release valve is open, release gas. if (canister.ReleaseValve) { if (!ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager) || !containerManager.TryGetContainer(canister.ContainerName, out var container)) { return; } var atmosphereSystem = Get <AtmosphereSystem>(); if (container.ContainedEntities.Count > 0) { var gasTank = container.ContainedEntities[0].GetComponent <GasTankComponent>(); atmosphereSystem.ReleaseGasTo(portNode.Air, gasTank.Air, canister.ReleasePressure); } else { var tileAtmosphere = canister.Owner.Transform.Coordinates.GetTileAtmosphere(); atmosphereSystem.ReleaseGasTo(portNode.Air, tileAtmosphere?.Air, canister.ReleasePressure); tileAtmosphere?.Invalidate(); } } DirtyUI(uid); // Nothing to do here. if (MathHelper.CloseTo(portNode.Air.Pressure, canister.LastPressure)) { return; } canister.LastPressure = portNode.Air.Pressure; if (portNode.Air.Pressure < 10) { appearance.SetData(GasCanisterVisuals.PressureState, 0); } else if (portNode.Air.Pressure < Atmospherics.OneAtmosphere) { appearance.SetData(GasCanisterVisuals.PressureState, 1); } else if (portNode.Air.Pressure < (15 * Atmospherics.OneAtmosphere)) { appearance.SetData(GasCanisterVisuals.PressureState, 2); } else { appearance.SetData(GasCanisterVisuals.PressureState, 3); } }
private void OnCanisterUpdated(EntityUid uid, GasCanisterComponent canister, AtmosDeviceUpdateEvent args) { if (!ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer) || !ComponentManager.TryGetComponent(uid, out AppearanceComponent? appearance)) { return; } if (!nodeContainer.TryGetNode(canister.PortName, out PortablePipeNode? portNode)) { return; } var atmosphereSystem = Get <AtmosphereSystem>(); atmosphereSystem.React(canister.Air, portNode); if (portNode.NodeGroup is PipeNet { NodeCount: > 1 } net) { var buffer = new GasMixture(net.Air.Volume + canister.Air.Volume); atmosphereSystem.Merge(buffer, net.Air); atmosphereSystem.Merge(buffer, canister.Air); net.Air.Clear(); atmosphereSystem.Merge(net.Air, buffer); net.Air.Multiply(net.Air.Volume / buffer.Volume); canister.Air.Clear(); atmosphereSystem.Merge(canister.Air, buffer); canister.Air.Multiply(canister.Air.Volume / buffer.Volume); } // Release valve is open, release gas. if (canister.ReleaseValve) { if (!ComponentManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager) || !containerManager.TryGetContainer(canister.ContainerName, out var container)) { return; } if (container.ContainedEntities.Count > 0) { var gasTank = container.ContainedEntities[0].GetComponent <GasTankComponent>(); atmosphereSystem.ReleaseGasTo(canister.Air, gasTank.Air, canister.ReleasePressure); } else { var tileAtmosphere = canister.Owner.Transform.Coordinates.GetTileAtmosphere(); atmosphereSystem.ReleaseGasTo(canister.Air, tileAtmosphere?.Air, canister.ReleasePressure); tileAtmosphere?.Invalidate(); } } DirtyUI(uid); // If last pressure is very close to the current pressure, do nothing. if (MathHelper.CloseTo(canister.Air.Pressure, canister.LastPressure)) { return; } canister.LastPressure = canister.Air.Pressure; if (canister.Air.Pressure < 10) { appearance.SetData(GasCanisterVisuals.PressureState, 0); } else if (canister.Air.Pressure < Atmospherics.OneAtmosphere) { appearance.SetData(GasCanisterVisuals.PressureState, 1); } else if (canister.Air.Pressure < (15 * Atmospherics.OneAtmosphere)) { appearance.SetData(GasCanisterVisuals.PressureState, 2); } else { appearance.SetData(GasCanisterVisuals.PressureState, 3); } }
public void ConnectGasCanister(GasCanisterComponent gasCanister) { ConnectedCanister = gasCanister; }
public void DisconnectGasCanister() { ConnectedCanister = null; }
private void OnCanisterUpdated(EntityUid uid, GasCanisterComponent canister, AtmosDeviceUpdateEvent args) { _atmosphereSystem.React(canister.Air, canister); if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer) || !EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance)) { return; } if (!nodeContainer.TryGetNode(canister.PortName, out PortablePipeNode? portNode)) { return; } if (portNode.NodeGroup is PipeNet { NodeCount: > 1 } net) { MixContainerWithPipeNet(canister.Air, net.Air); } ContainerManagerComponent?containerManager = null; // Release valve is open, release gas. if (canister.ReleaseValve) { if (!EntityManager.TryGetComponent(uid, out containerManager) || !containerManager.TryGetContainer(canister.ContainerName, out var container)) { return; } if (container.ContainedEntities.Count > 0) { var gasTank = EntityManager.GetComponent <GasTankComponent>(container.ContainedEntities[0]); _atmosphereSystem.ReleaseGasTo(canister.Air, gasTank.Air, canister.ReleasePressure); } else { var environment = _atmosphereSystem.GetContainingMixture(uid, false, true); _atmosphereSystem.ReleaseGasTo(canister.Air, environment, canister.ReleasePressure); } } // If last pressure is very close to the current pressure, do nothing. if (MathHelper.CloseToPercent(canister.Air.Pressure, canister.LastPressure)) { return; } DirtyUI(uid, canister, nodeContainer, containerManager); canister.LastPressure = canister.Air.Pressure; if (canister.Air.Pressure < 10) { appearance.SetData(GasCanisterVisuals.PressureState, 0); } else if (canister.Air.Pressure < Atmospherics.OneAtmosphere) { appearance.SetData(GasCanisterVisuals.PressureState, 1); } else if (canister.Air.Pressure < (15 * Atmospherics.OneAtmosphere)) { appearance.SetData(GasCanisterVisuals.PressureState, 2); } else { appearance.SetData(GasCanisterVisuals.PressureState, 3); } }