Files
OldThink/Content.Server/Tools/ToolSystem.Welder.cs

330 lines
13 KiB
C#
Raw Normal View History

2023-01-12 16:41:40 +13:00
using System.Linq;
using Content.Server.Chemistry.Components;
using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Tools.Components;
2023-01-20 10:05:05 -06:00
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.Examine;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
get that crap outta here (completely rewrites inventorysystem) (#5807) * some work * equip: done unequip: todo * unequipping done & refactored events * workin * movin * reee namespaces * stun * mobstate * fixes * some work on events * removes serverside itemcomp & misc fixes * work * smol merge fix * ports template to prototype & finishes ui * moves relay & adds containerenumerator * actions & cuffs * my god what is actioncode * more fixes * im loosing my grasp on reality * more fixes * more work * explosions * yes * more work * more fixes * merge master & misc fixed because i forgot to commit before merging master * more fixes * fixes * moar * more work * moar fixes * suffixmap * more work on client * motivation low * no. no containers * mirroring client to server * fixes * move serverinvcomp * serverinventorycomponent is dead * gaming * only strippable & ai left... * only ai and richtext left * fixes ai * fixes * fixes sprite layers * more fixes * resolves optional * yes * stable:tm: * fixes * moar fixes * moar * fix some tests * lmao * no comment * good to merge:tm: * fixes build but for real * adresses some reviews * adresses some more reviews * nullables, yo * fixes lobbyscreen * timid refactor to differentiate actor & target * adresses more reviews * more * my god what a mess * removed the rest of duplicates * removed duplicate slotflags and renamed shoes to feet * removes another unused one * yes * fixes lobby & makes tryunequip return unequipped item * fixes * some funny renames * fixes * misc improvements to attemptevents * fixes * merge fixes Co-authored-by: Paul Ritter <ritter.paul1@gmail.com>
2021-12-30 22:56:10 +01:00
using Content.Shared.Item;
using Content.Shared.Temperature;
using Content.Shared.Toggleable;
using Content.Shared.Tools.Components;
using Content.Shared.Weapons.Melee.Events;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Utility;
namespace Content.Server.Tools
{
public sealed partial class ToolSystem
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly AppearanceSystem _appearanceSystem = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
private readonly HashSet<EntityUid> _activeWelders = new();
private const float WelderUpdateTimer = 1f;
private float _welderTimer = 0f;
public void InitializeWelders()
{
SubscribeLocalEvent<WelderComponent, ComponentStartup>(OnWelderStartup);
SubscribeLocalEvent<WelderComponent, IsHotEvent>(OnWelderIsHotEvent);
SubscribeLocalEvent<WelderComponent, ExaminedEvent>(OnWelderExamine);
SubscribeLocalEvent<WelderComponent, SolutionChangedEvent>(OnWelderSolutionChange);
SubscribeLocalEvent<WelderComponent, ActivateInWorldEvent>(OnWelderActivate);
SubscribeLocalEvent<WelderComponent, AfterInteractEvent>(OnWelderAfterInteract);
SubscribeLocalEvent<WelderComponent, DoAfterAttemptEvent<ToolDoAfterEvent>>(OnWelderToolUseAttempt);
SubscribeLocalEvent<WelderComponent, ComponentShutdown>(OnWelderShutdown);
SubscribeLocalEvent<WelderComponent, ComponentGetState>(OnWelderGetState);
SubscribeLocalEvent<WelderComponent, GetMeleeDamageEvent>(OnGetMeleeDamage);
}
private void OnGetMeleeDamage(EntityUid uid, WelderComponent component, ref GetMeleeDamageEvent args)
{
if (component.Lit)
args.Damage += component.LitMeleeDamageBonus;
}
public (FixedPoint2 fuel, FixedPoint2 capacity) GetWelderFuelAndCapacity(EntityUid uid, WelderComponent? welder = null, SolutionContainerManagerComponent? solutionContainer = null)
{
if (!Resolve(uid, ref welder, ref solutionContainer)
|| !_solutionContainerSystem.TryGetSolution(uid, welder.FuelSolution, out var fuelSolution, solutionContainer))
return (FixedPoint2.Zero, FixedPoint2.Zero);
return (_solutionContainerSystem.GetReagentQuantity(uid, welder.FuelReagent), fuelSolution.MaxVolume);
}
public bool TryToggleWelder(EntityUid uid, EntityUid? user,
WelderComponent? welder = null,
SolutionContainerManagerComponent? solutionContainer = null,
2022-07-27 03:53:47 -07:00
ItemComponent? item = null,
PointLightComponent? light = null,
2022-03-08 04:06:09 +03:00
AppearanceComponent? appearance = null)
{
// Right now, we only need the welder.
// So let's not unnecessarily resolve components
if (!Resolve(uid, ref welder))
return false;
return !welder.Lit
2022-03-08 04:06:09 +03:00
? TryTurnWelderOn(uid, user, welder, solutionContainer, item, light, appearance)
: TryTurnWelderOff(uid, user, welder, item, light, appearance);
}
public bool TryTurnWelderOn(EntityUid uid, EntityUid? user,
WelderComponent? welder = null,
SolutionContainerManagerComponent? solutionContainer = null,
2022-07-27 03:53:47 -07:00
ItemComponent? item = null,
PointLightComponent? light = null,
Refactors the AtmosphereSystem public-facing API to allow for multiple atmos backends. (#8134) * Refactors the entirety of the AtmosphereSystem public-facing API to allow for multiple atmos backends. * actually compiles * Remove commented out code * funny bracket * Move archived moles, temperature from GasMixture to TileAtmosphere. * WIP customizable map default mixture still VERY buggy * broken mess aaaaaaaaaaaaa * Fix lattice, etc not being considered space * visualization for "IsSpace" * help * Update Content.Client/Atmos/Overlays/AtmosDebugOverlay.cs Co-authored-by: Moony <moonheart08@users.noreply.github.com> * Holy SHIT it compiles AGAIN * Fix AtmosDeviceSystem crash at shutdown * Fix immutable tiles on map blueprints not being fixed by fixgridatmos/revalidate. * Use space instead of gasmixture immutable for heat capacity calculations * Remove all LINDA-specific code from GasMixture, move it to TileAtmosphere/AtmosphereSystem instead. * Fix roundstart tiles not processing * Update Content.Server/Atmos/Commands/SetTemperatureCommand.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Atmos/EntitySystems/AtmosphereSystem.API.cs Changed Files tab is so large I can't commit both suggestions at once mfw Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Moony <moonheart08@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2022-07-04 16:51:34 +02:00
AppearanceComponent? appearance = null,
TransformComponent? transform = null)
{
Refactors the AtmosphereSystem public-facing API to allow for multiple atmos backends. (#8134) * Refactors the entirety of the AtmosphereSystem public-facing API to allow for multiple atmos backends. * actually compiles * Remove commented out code * funny bracket * Move archived moles, temperature from GasMixture to TileAtmosphere. * WIP customizable map default mixture still VERY buggy * broken mess aaaaaaaaaaaaa * Fix lattice, etc not being considered space * visualization for "IsSpace" * help * Update Content.Client/Atmos/Overlays/AtmosDebugOverlay.cs Co-authored-by: Moony <moonheart08@users.noreply.github.com> * Holy SHIT it compiles AGAIN * Fix AtmosDeviceSystem crash at shutdown * Fix immutable tiles on map blueprints not being fixed by fixgridatmos/revalidate. * Use space instead of gasmixture immutable for heat capacity calculations * Remove all LINDA-specific code from GasMixture, move it to TileAtmosphere/AtmosphereSystem instead. * Fix roundstart tiles not processing * Update Content.Server/Atmos/Commands/SetTemperatureCommand.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Atmos/EntitySystems/AtmosphereSystem.API.cs Changed Files tab is so large I can't commit both suggestions at once mfw Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Moony <moonheart08@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2022-07-04 16:51:34 +02:00
if (!Resolve(uid, ref welder, ref solutionContainer, ref transform))
return false;
// Optional components.
2022-03-08 04:06:09 +03:00
Resolve(uid, ref item, ref light, ref appearance, false);
if (!_solutionContainerSystem.TryGetSolution(uid, welder.FuelSolution, out var solution, solutionContainer))
return false;
var fuel = solution.GetReagentQuantity(welder.FuelReagent);
// Not enough fuel to lit welder.
if (fuel == FixedPoint2.Zero || fuel < welder.FuelLitCost)
{
if(user != null)
_popupSystem.PopupEntity(Loc.GetString("welder-component-no-fuel-message"), uid, user.Value);
return false;
}
solution.RemoveReagent(welder.FuelReagent, welder.FuelLitCost);
welder.Lit = true;
2023-01-20 10:05:05 -06:00
// Logging
if (user != null)
_adminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user.Value):user} toggled {ToPrettyString(uid):welder} on");
else
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(uid):welder} toggled on");
2022-08-14 01:59:14 -04:00
var ev = new WelderToggledEvent(true);
RaiseLocalEvent(welder.Owner, ev, false);
var hotEvent = new IsHotEvent() {IsHot = true};
RaiseLocalEvent(uid, hotEvent);
_appearanceSystem.SetData(uid, WelderVisuals.Lit, true);
_appearanceSystem.SetData(uid, ToggleableLightVisuals.Enabled, true);
if (light != null)
light.Enabled = true;
_audioSystem.PlayPvs(welder.WelderOnSounds, uid, AudioParams.Default.WithVariation(0.125f).WithVolume(-5f));
Refactors the AtmosphereSystem public-facing API to allow for multiple atmos backends. (#8134) * Refactors the entirety of the AtmosphereSystem public-facing API to allow for multiple atmos backends. * actually compiles * Remove commented out code * funny bracket * Move archived moles, temperature from GasMixture to TileAtmosphere. * WIP customizable map default mixture still VERY buggy * broken mess aaaaaaaaaaaaa * Fix lattice, etc not being considered space * visualization for "IsSpace" * help * Update Content.Client/Atmos/Overlays/AtmosDebugOverlay.cs Co-authored-by: Moony <moonheart08@users.noreply.github.com> * Holy SHIT it compiles AGAIN * Fix AtmosDeviceSystem crash at shutdown * Fix immutable tiles on map blueprints not being fixed by fixgridatmos/revalidate. * Use space instead of gasmixture immutable for heat capacity calculations * Remove all LINDA-specific code from GasMixture, move it to TileAtmosphere/AtmosphereSystem instead. * Fix roundstart tiles not processing * Update Content.Server/Atmos/Commands/SetTemperatureCommand.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Atmos/EntitySystems/AtmosphereSystem.API.cs Changed Files tab is so large I can't commit both suggestions at once mfw Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Moony <moonheart08@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2022-07-04 16:51:34 +02:00
if (transform.GridUid is {} gridUid)
{
var position = _transformSystem.GetGridOrMapTilePosition(uid, transform);
2023-02-28 14:43:24 -06:00
_atmosphereSystem.HotspotExpose(gridUid, position, 700, 50, uid, true);
Refactors the AtmosphereSystem public-facing API to allow for multiple atmos backends. (#8134) * Refactors the entirety of the AtmosphereSystem public-facing API to allow for multiple atmos backends. * actually compiles * Remove commented out code * funny bracket * Move archived moles, temperature from GasMixture to TileAtmosphere. * WIP customizable map default mixture still VERY buggy * broken mess aaaaaaaaaaaaa * Fix lattice, etc not being considered space * visualization for "IsSpace" * help * Update Content.Client/Atmos/Overlays/AtmosDebugOverlay.cs Co-authored-by: Moony <moonheart08@users.noreply.github.com> * Holy SHIT it compiles AGAIN * Fix AtmosDeviceSystem crash at shutdown * Fix immutable tiles on map blueprints not being fixed by fixgridatmos/revalidate. * Use space instead of gasmixture immutable for heat capacity calculations * Remove all LINDA-specific code from GasMixture, move it to TileAtmosphere/AtmosphereSystem instead. * Fix roundstart tiles not processing * Update Content.Server/Atmos/Commands/SetTemperatureCommand.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Atmos/EntitySystems/AtmosphereSystem.API.cs Changed Files tab is so large I can't commit both suggestions at once mfw Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Moony <moonheart08@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2022-07-04 16:51:34 +02:00
}
_entityManager.Dirty(welder);
_activeWelders.Add(uid);
return true;
}
public bool TryTurnWelderOff(EntityUid uid, EntityUid? user,
WelderComponent? welder = null,
2022-07-27 03:53:47 -07:00
ItemComponent? item = null,
PointLightComponent? light = null,
2022-03-08 04:06:09 +03:00
AppearanceComponent? appearance = null)
{
if (!Resolve(uid, ref welder))
return false;
// Optional components.
2022-03-08 04:06:09 +03:00
Resolve(uid, ref item, ref light, ref appearance, false);
welder.Lit = false;
2023-01-20 10:05:05 -06:00
// Logging
if (user != null)
_adminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user.Value):user} toggled {ToPrettyString(uid):welder} off");
else
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(uid):welder} toggled off");
2022-08-14 01:59:14 -04:00
var ev = new WelderToggledEvent(false);
RaiseLocalEvent(welder.Owner, ev, false);
var hotEvent = new IsHotEvent() {IsHot = false};
RaiseLocalEvent(uid, hotEvent);
// Layer 1 is the flame.
_appearanceSystem.SetData(uid, WelderVisuals.Lit, false);
_appearanceSystem.SetData(uid, ToggleableLightVisuals.Enabled, false);
if (light != null)
light.Enabled = false;
_audioSystem.PlayPvs(welder.WelderOffSounds, uid, AudioParams.Default.WithVariation(0.125f).WithVolume(-5f));
_entityManager.Dirty(welder);
_activeWelders.Remove(uid);
return true;
}
private void OnWelderStartup(EntityUid uid, WelderComponent welder, ComponentStartup args)
{
_entityManager.Dirty(welder);
}
private void OnWelderIsHotEvent(EntityUid uid, WelderComponent welder, IsHotEvent args)
{
args.IsHot = welder.Lit;
}
private void OnWelderExamine(EntityUid uid, WelderComponent welder, ExaminedEvent args)
{
if (welder.Lit)
{
args.PushMarkup(Loc.GetString("welder-component-on-examine-welder-lit-message"));
}
else
{
args.PushMarkup(Loc.GetString("welder-component-on-examine-welder-not-lit-message"));
}
if (args.IsInDetailsRange)
{
var (fuel, capacity) = GetWelderFuelAndCapacity(uid, welder);
args.PushMarkup(Loc.GetString("welder-component-on-examine-detailed-message",
("colorName", fuel < capacity / FixedPoint2.New(4f) ? "darkorange" : "orange"),
("fuelLeft", fuel),
("fuelCapacity", capacity),
("status", string.Empty))); // Lit status is handled above
}
}
private void OnWelderSolutionChange(EntityUid uid, WelderComponent welder, SolutionChangedEvent args)
{
_entityManager.Dirty(welder);
}
private void OnWelderActivate(EntityUid uid, WelderComponent welder, ActivateInWorldEvent args)
{
2021-12-03 15:53:09 +01:00
args.Handled = TryToggleWelder(uid, args.User, welder);
2023-01-20 10:05:05 -06:00
if (args.Handled)
args.WasLogged = true;
}
private void OnWelderAfterInteract(EntityUid uid, WelderComponent welder, AfterInteractEvent args)
{
if (args.Handled)
return;
2021-12-06 00:52:58 +01:00
if (args.Target is not {Valid: true} target || !args.CanReach)
return;
// TODO: Clean up this inherited oldcode.
2021-12-06 00:52:58 +01:00
if (EntityManager.TryGetComponent(target, out ReagentTankComponent? tank)
&& tank.TankType == ReagentTankType.Fuel
2021-12-06 00:52:58 +01:00
&& _solutionContainerSystem.TryGetDrainableSolution(target, out var targetSolution)
&& _solutionContainerSystem.TryGetSolution(uid, welder.FuelSolution, out var welderSolution))
{
2023-01-12 16:41:40 +13:00
var trans = FixedPoint2.Min(welderSolution.AvailableVolume, targetSolution.Volume);
if (trans > 0)
{
2021-12-06 00:52:58 +01:00
var drained = _solutionContainerSystem.Drain(target, targetSolution, trans);
_solutionContainerSystem.TryAddSolution(uid, welderSolution, drained);
_audioSystem.PlayPvs(welder.WelderRefill, uid);
_popupSystem.PopupEntity(Loc.GetString("welder-component-after-interact-refueled-message"), uid, args.User);
}
else if (welderSolution.AvailableVolume <= 0)
{
_popupSystem.PopupEntity(Loc.GetString("welder-component-already-full"), uid, args.User);
}
else
{
_popupSystem.PopupEntity(Loc.GetString("welder-component-no-fuel-in-tank", ("owner", args.Target)), uid, args.User);
}
}
args.Handled = true;
}
private void OnWelderToolUseAttempt(EntityUid uid, WelderComponent welder, DoAfterAttemptEvent<ToolDoAfterEvent> args)
{
var user = args.DoAfter.Args.User;
if (!welder.Lit)
{
_popupSystem.PopupEntity(Loc.GetString("welder-component-welder-not-lit-message"), uid, user);
args.Cancel();
return;
}
}
private void OnWelderShutdown(EntityUid uid, WelderComponent welder, ComponentShutdown args)
{
_activeWelders.Remove(uid);
}
private void OnWelderGetState(EntityUid uid, WelderComponent welder, ref ComponentGetState args)
{
var (fuel, capacity) = GetWelderFuelAndCapacity(uid, welder);
args.State = new WelderComponentState(capacity.Float(), fuel.Float(), welder.Lit);
}
private void UpdateWelders(float frameTime)
{
_welderTimer += frameTime;
if (_welderTimer < WelderUpdateTimer)
return;
Refactors the AtmosphereSystem public-facing API to allow for multiple atmos backends. (#8134) * Refactors the entirety of the AtmosphereSystem public-facing API to allow for multiple atmos backends. * actually compiles * Remove commented out code * funny bracket * Move archived moles, temperature from GasMixture to TileAtmosphere. * WIP customizable map default mixture still VERY buggy * broken mess aaaaaaaaaaaaa * Fix lattice, etc not being considered space * visualization for "IsSpace" * help * Update Content.Client/Atmos/Overlays/AtmosDebugOverlay.cs Co-authored-by: Moony <moonheart08@users.noreply.github.com> * Holy SHIT it compiles AGAIN * Fix AtmosDeviceSystem crash at shutdown * Fix immutable tiles on map blueprints not being fixed by fixgridatmos/revalidate. * Use space instead of gasmixture immutable for heat capacity calculations * Remove all LINDA-specific code from GasMixture, move it to TileAtmosphere/AtmosphereSystem instead. * Fix roundstart tiles not processing * Update Content.Server/Atmos/Commands/SetTemperatureCommand.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Atmos/EntitySystems/AtmosphereSystem.API.cs Changed Files tab is so large I can't commit both suggestions at once mfw Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Moony <moonheart08@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2022-07-04 16:51:34 +02:00
// TODO Use an "active welder" component instead, EntityQuery over that.
foreach (var tool in _activeWelders.ToArray())
{
if (!EntityManager.TryGetComponent(tool, out WelderComponent? welder)
Refactors the AtmosphereSystem public-facing API to allow for multiple atmos backends. (#8134) * Refactors the entirety of the AtmosphereSystem public-facing API to allow for multiple atmos backends. * actually compiles * Remove commented out code * funny bracket * Move archived moles, temperature from GasMixture to TileAtmosphere. * WIP customizable map default mixture still VERY buggy * broken mess aaaaaaaaaaaaa * Fix lattice, etc not being considered space * visualization for "IsSpace" * help * Update Content.Client/Atmos/Overlays/AtmosDebugOverlay.cs Co-authored-by: Moony <moonheart08@users.noreply.github.com> * Holy SHIT it compiles AGAIN * Fix AtmosDeviceSystem crash at shutdown * Fix immutable tiles on map blueprints not being fixed by fixgridatmos/revalidate. * Use space instead of gasmixture immutable for heat capacity calculations * Remove all LINDA-specific code from GasMixture, move it to TileAtmosphere/AtmosphereSystem instead. * Fix roundstart tiles not processing * Update Content.Server/Atmos/Commands/SetTemperatureCommand.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Atmos/EntitySystems/AtmosphereSystem.API.cs Changed Files tab is so large I can't commit both suggestions at once mfw Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Moony <moonheart08@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2022-07-04 16:51:34 +02:00
|| !EntityManager.TryGetComponent(tool, out SolutionContainerManagerComponent? solutionContainer)
|| !EntityManager.TryGetComponent(tool, out TransformComponent? transform))
continue;
if (!_solutionContainerSystem.TryGetSolution(tool, welder.FuelSolution, out var solution, solutionContainer))
continue;
solution.RemoveReagent(welder.FuelReagent, welder.FuelConsumption * _welderTimer);
if (solution.GetReagentQuantity(welder.FuelReagent) <= FixedPoint2.Zero)
TryTurnWelderOff(tool, null, welder);
_entityManager.Dirty(welder);
}
_welderTimer -= WelderUpdateTimer;
}
}
2022-08-14 01:59:14 -04:00
public sealed class WelderToggledEvent : EntityEventArgs
{
public bool WelderOn;
public WelderToggledEvent(bool welderOn)
{
WelderOn = welderOn;
}
}
}