Solution refactor (#4407)

* Rename SolutionContainerCaps -> Capability

* Move IExamine event to Chemistry System.

* ECS the ISolutionChange into SolutionChangeEvent

* Unify SolutionContainer into a single shared component

* Replace ISolutionInteraction with SolutionContainerComponent

* Move all methods from SolutionContainer to ChemistrySystem

* Refactor EntitySystem calls to Dependencies

* Refactor SolutionContainer to SolutionManager

* Fix yamls

* Fix test fails

* Fix post merge issues

* Fix various issues with SolutionManager

* More fixes

* Fix more components

* Fix events not being directed

* Fixes for Hypospray

* Separate removal and iteration on Metabolism

* Fix creampie problems

* Address some of sloth's issues

* Refactors for Systems

* Refactored solution location

* Fix tests

* Address more sloth issues

* Fix dependency

* Fix merge conflicts

* Add xmldocs for Capabilities components

* Remove HasSolution/TryGetDefaultSolution and Add/Remove Drainable/Refillable

* Replace Grindable/Juiceable with Extractable

* Refactor field names

* Fix Drainable

* Fix some issues with spillable and injector

* Fix issues with Grinder

* Fix Beaker having duplicate solutions

* Fix foaming

* Address some MGS issues

* Fix Uid issues

* Fix errors in solution Tranfer

* Fixed some extra values constant values

* Cola is drinkable now
This commit is contained in:
Ygg01
2021-09-06 15:49:44 +02:00
committed by GitHub
parent b8911d58ac
commit c209e3f29b
166 changed files with 4268 additions and 3278 deletions

View File

@@ -1,8 +1,8 @@
using Content.Server.Interaction.Components;
using Content.Server.MobState.States;
using Content.Server.Weapon.Melee;
using Content.Shared.Chemistry;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Notification.Managers;
using Content.Shared.Sound;
@@ -18,7 +18,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.Chemistry.Components
{
[RegisterComponent]
public sealed class HyposprayComponent : SharedHyposprayComponent, ISolutionChange
public sealed class HyposprayComponent : SharedHyposprayComponent
{
[DataField("ClumsyFailChance")]
[ViewVariables(VVAccess.ReadWrite)]
@@ -31,8 +31,6 @@ namespace Content.Server.Chemistry.Components
[DataField("InjectSound")]
private SoundSpecifier _injectSound = new SoundPathSpecifier("/Audio/Items/hypospray.ogg");
[ComponentDependency] private readonly SolutionContainerComponent? _solution = default!;
protected override void Initialize()
{
base.Initialize();
@@ -57,13 +55,24 @@ namespace Content.Server.Chemistry.Components
target = user;
}
if (_solution == null || _solution.CurrentVolume == 0)
var solutionsSys = EntitySystem.Get<SolutionContainerSystem>();
solutionsSys.TryGetSolution(Owner, SolutionName, out var hypoSpraySolution);
if (hypoSpraySolution == null || hypoSpraySolution.CurrentVolume == 0)
{
user.PopupMessageCursor(Loc.GetString("hypospray-component-empty-message"));
return true;
}
user.PopupMessage(Loc.GetString(msgFormat ?? "hypospray-component-inject-other-message",("other", target)));
if (!solutionsSys.TryGetInjectableSolution(target.Uid, out var targetSolution))
{
user.PopupMessage(user,
Loc.GetString("hypospray-cant-inject", ("target", target)));
return false;
}
user.PopupMessage(Loc.GetString(msgFormat ?? "hypospray-component-inject-other-message",
("other", target)));
if (target != user)
{
target.PopupMessage(Loc.GetString("hypospray-component-feel-prick-message"));
@@ -74,19 +83,21 @@ namespace Content.Server.Chemistry.Components
SoundSystem.Play(Filter.Pvs(user), _injectSound.GetSound(), user);
var targetSolution = target.GetComponent<SolutionContainerComponent>();
// Get transfer amount. May be smaller than _transferAmount if not enough room
var realTransferAmount = ReagentUnit.Min(TransferAmount, targetSolution.EmptyVolume);
var realTransferAmount = ReagentUnit.Min(TransferAmount, targetSolution.AvailableVolume);
if (realTransferAmount <= 0)
{
user.PopupMessage(user, Loc.GetString("hypospray-component-transfer-already-full-message ",("owner", targetSolution.Owner)));
user.PopupMessage(user,
Loc.GetString("hypospray-component-transfer-already-full-message",
("owner", target)));
return true;
}
// Move units from attackSolution to targetSolution
var removedSolution = _solution.SplitSolution(realTransferAmount);
var removedSolution =
EntitySystem.Get<SolutionContainerSystem>()
.SplitSolution(Owner.Uid, hypoSpraySolution, realTransferAmount);
if (!targetSolution.CanAddSolution(removedSolution))
{
@@ -95,29 +106,26 @@ namespace Content.Server.Chemistry.Components
removedSolution.DoEntityReaction(target, ReactionMethod.Injection);
targetSolution.TryAddSolution(removedSolution);
EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(target.Uid, targetSolution, removedSolution);
static bool EligibleEntity(IEntity entity)
{
// TODO: Does checking for BodyComponent make sense as a "can be hypospray'd" tag?
// In SS13 the hypospray ONLY works on mobs, NOT beakers or anything else.
return entity.HasComponent<SolutionContainerComponent>() && entity.HasComponent<MobStateComponent>();
return entity.HasComponent<SharedChemMasterComponent>()
&& entity.HasComponent<MobStateComponent>();
}
return true;
}
void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs)
{
Dirty();
}
public override ComponentState GetComponentState(ICommonSession player)
{
if (_solution == null)
return new HyposprayComponentState(ReagentUnit.Zero, ReagentUnit.Zero);
return new HyposprayComponentState(_solution.CurrentVolume, _solution.MaxVolume);
var solutionSys = Owner.EntityManager.EntitySysManager.GetEntitySystem<SolutionContainerSystem>();
return solutionSys.TryGetSolution(Owner, SolutionName, out var solution)
? new HyposprayComponentState(solution.CurrentVolume, solution.MaxVolume)
: new HyposprayComponentState(ReagentUnit.Zero, ReagentUnit.Zero);
}
}
}