Files
tbd-station-14/Content.Server/Weapons/Ranged/Systems/GunSystem.Solution.cs
TemporalOroboros d75e743dd7 Solution Entities (#21916)
* Creates Content.Shared.Chemistry.Solutions
Copies Solution class to new namespace
Obsoletes old Solution class

* Switches over to the Solutions.Solution Solution

* Creates Content.Shared.Chemistry.Containers
Copies relevant components/systems to the new namespace
Obsoletes old versions

* Switches over to the Containers.XYZ namespace

* Creates SolutionSystem and obsoletes old SolutionContainerSystem methods

* Start using SolutionSystem for Solution manipulation

* EnumerateSolutions

* Move TryGetMixableSolution

* Move EnsureSolution to Server

* Create Solution Entities

* Stop using obsolete solution system methods

* Fix prototype component tests

* Add using ..Audio.Systems; back

* Wrap solution container slots in ContainerSlots

* Actually add the slot to the solution container map

* Dirty SolutionContainerComponent when ensuring solutions

* Revert namespace changes

* Remerge SolutionSystem and SolutionContainerSystem

* SolutionContainerManagerComponent refactor

* Avoid wrapping necessary code in DebugTools.Assert as it is removed when compiling for release

* Readd examine reagent sorting

* Fix errors

* Poke tests

* Fix solution names not being applied

* Fix WoolyComponent including statement

* Fix merge skew

* Fix compile errors

* Make reactions use solntities

* Reindent solution class namespace

* Field attribute changes

* AutoGenerateComponentState for SolutionContainerComponent

* SolutionContainerComponent -> ContainedSolutionComponent

* ref ReactionAttemptEvent

* Denetwork preinit solutions

* Misc 1

* Nullable TryGetSolution out vars

* Cache associated solutions

* Fix merge skew

* Use explicit regions in SharedSolutionContainerSystem.Capabilities

* Add debug assert

* Use explicit regions in SharedSolutionContainerSystem.Relay + ref SolutionContainerChangedEvent

* ContainedSolutionComponent.Name -> ContainedSolutionComponent.ContainerName

* SolutionComponent doc comments

* Implicit DataField names and property purge

* ReagentEffect DataField names

* Local variables for readability

* Sort using statements + Entity<T> event handlers

* Fix compile erros

* Fix compile errors

---------

Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
2023-12-28 17:58:14 -08:00

84 lines
3.1 KiB
C#

using Content.Server.Chemistry.Components;
using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.FixedPoint;
using Content.Shared.Vapor;
using Content.Shared.Weapons.Ranged;
using Content.Shared.Weapons.Ranged.Components;
using Robust.Shared.Map;
namespace Content.Server.Weapons.Ranged.Systems;
public sealed partial class GunSystem
{
[Dependency] private readonly SolutionContainerSystem _solutionContainer = default!;
protected override void InitializeSolution()
{
base.InitializeSolution();
SubscribeLocalEvent<SolutionAmmoProviderComponent, MapInitEvent>(OnSolutionMapInit);
SubscribeLocalEvent<SolutionAmmoProviderComponent, SolutionContainerChangedEvent>(OnSolutionChanged);
}
private void OnSolutionMapInit(Entity<SolutionAmmoProviderComponent> entity, ref MapInitEvent args)
{
UpdateSolutionShots(entity.Owner, entity.Comp);
}
private void OnSolutionChanged(Entity<SolutionAmmoProviderComponent> entity, ref SolutionContainerChangedEvent args)
{
if (args.Solution.Name == entity.Comp.SolutionId)
UpdateSolutionShots(entity.Owner, entity.Comp, args.Solution);
}
protected override void UpdateSolutionShots(EntityUid uid, SolutionAmmoProviderComponent component, Solution? solution = null)
{
var shots = 0;
var maxShots = 0;
if (solution == null && !_solutionContainer.TryGetSolution(uid, component.SolutionId, out _, out solution))
{
component.Shots = shots;
component.MaxShots = maxShots;
Dirty(uid, component);
return;
}
shots = (int) (solution.Volume / component.FireCost);
maxShots = (int) (solution.MaxVolume / component.FireCost);
component.Shots = shots;
component.MaxShots = maxShots;
Dirty(uid, component);
UpdateSolutionAppearance(uid, component);
}
protected override (EntityUid Entity, IShootable) GetSolutionShot(EntityUid uid, SolutionAmmoProviderComponent component, EntityCoordinates position)
{
var (ent, shootable) = base.GetSolutionShot(uid, component, position);
if (!_solutionContainer.TryGetSolution(uid, component.SolutionId, out var solution, out _))
return (ent, shootable);
var newSolution = _solutionContainer.SplitSolution(solution.Value, component.FireCost);
if (newSolution.Volume <= FixedPoint2.Zero)
return (ent, shootable);
if (TryComp<AppearanceComponent>(ent, out var appearance))
{
Appearance.SetData(ent, VaporVisuals.Color, newSolution.GetColor(ProtoManager).WithAlpha(1f), appearance);
Appearance.SetData(ent, VaporVisuals.State, true, appearance);
}
// Add the solution to the vapor and actually send the thing
if (_solutionContainer.TryGetSolution(ent, VaporComponent.SolutionName, out var vaporSolution, out _))
{
_solutionContainer.TryAddSolution(vaporSolution.Value, newSolution);
}
return (ent, shootable);
}
}