Add text coloring for inspected solution containers, code cleanup (#2010)
* Initial commit * remove helper * fixes * small fix
This commit is contained in:
@@ -61,12 +61,8 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
{
|
||||
base.Startup();
|
||||
|
||||
Owner.EnsureComponent<SolutionComponent>();
|
||||
|
||||
if (Owner.TryGetComponent(out SolutionComponent? solution))
|
||||
{
|
||||
solution.Capabilities |= SolutionCaps.Injector;
|
||||
}
|
||||
var solution = Owner.EnsureComponent<SolutionContainerComponent>();
|
||||
solution.Capabilities = SolutionContainerCaps.AddTo | SolutionContainerCaps.RemoveFrom;
|
||||
|
||||
// Set _toggleState based on prototype
|
||||
_toggleState = _injectOnly ? InjectorToggleMode.Inject : InjectorToggleMode.Draw;
|
||||
@@ -111,30 +107,51 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return;
|
||||
|
||||
//Make sure we have the attacking entity
|
||||
if (eventArgs.Target == null || !Owner.TryGetComponent(out SolutionComponent? solution) || !solution.Injector)
|
||||
if (eventArgs.Target == null || !Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var targetEntity = eventArgs.Target;
|
||||
//Handle injecting/drawing for solutions
|
||||
if (targetEntity.TryGetComponent<SolutionComponent>(out var targetSolution) && targetSolution.Injectable)
|
||||
|
||||
// Handle injecting/drawing for solutions
|
||||
if (targetEntity.TryGetComponent<SolutionContainerComponent>(out var targetSolution))
|
||||
{
|
||||
if (_toggleState == InjectorToggleMode.Inject)
|
||||
{
|
||||
TryInject(targetSolution, eventArgs.User);
|
||||
if (solution.CanRemoveSolutions && targetSolution.CanAddSolutions)
|
||||
{
|
||||
TryInject(targetSolution, eventArgs.User);
|
||||
}
|
||||
else
|
||||
{
|
||||
eventArgs.User.PopupMessage(eventArgs.User, Loc.GetString("You aren't able to transfer to {0:theName}!", targetSolution.Owner));
|
||||
}
|
||||
}
|
||||
else if (_toggleState == InjectorToggleMode.Draw)
|
||||
{
|
||||
TryDraw(targetSolution, eventArgs.User);
|
||||
if (targetSolution.CanRemoveSolutions && solution.CanAddSolutions)
|
||||
{
|
||||
TryDraw(targetSolution, eventArgs.User);
|
||||
}
|
||||
else
|
||||
{
|
||||
eventArgs.User.PopupMessage(eventArgs.User, Loc.GetString("You aren't able to draw from {0:theName}!", targetSolution.Owner));
|
||||
}
|
||||
}
|
||||
}
|
||||
else //Handle injecting into bloodstream
|
||||
else // Handle injecting into bloodstream
|
||||
{
|
||||
if (targetEntity.TryGetComponent(out BloodstreamComponent? bloodstream) &&
|
||||
_toggleState == InjectorToggleMode.Inject)
|
||||
if (targetEntity.TryGetComponent(out BloodstreamComponent? bloodstream) && _toggleState == InjectorToggleMode.Inject)
|
||||
{
|
||||
TryInjectIntoBloodstream(bloodstream, eventArgs.User);
|
||||
if (solution.CanRemoveSolutions)
|
||||
{
|
||||
TryInjectIntoBloodstream(bloodstream, eventArgs.User);
|
||||
}
|
||||
else
|
||||
{
|
||||
eventArgs.User.PopupMessage(eventArgs.User, Loc.GetString("You aren't able to inject {0:theName}!", targetEntity));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,88 +169,91 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
|
||||
private void TryInjectIntoBloodstream(BloodstreamComponent targetBloodstream, IEntity user)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? solution) ||
|
||||
solution.CurrentVolume == 0)
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution) || solution.CurrentVolume == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
// Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(_transferAmount, targetBloodstream.EmptyVolume);
|
||||
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("Container full."));
|
||||
Owner.PopupMessage(user, Loc.GetString("You aren't able to inject {0:theName}!", targetBloodstream.Owner));
|
||||
return;
|
||||
}
|
||||
|
||||
//Move units from attackSolution to targetSolution
|
||||
// Move units from attackSolution to targetSolution
|
||||
var removedSolution = solution.SplitSolution(realTransferAmount);
|
||||
|
||||
if (!targetBloodstream.TryTransferSolution(removedSolution))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Owner.PopupMessage(user, Loc.GetString("Injected {0}u", removedSolution.TotalVolume));
|
||||
Owner.PopupMessage(user, Loc.GetString("You inject {0}u into {1:theName}!", removedSolution.TotalVolume, targetBloodstream.Owner));
|
||||
Dirty();
|
||||
}
|
||||
|
||||
private void TryInject(SolutionComponent targetSolution, IEntity user)
|
||||
private void TryInject(SolutionContainerComponent targetSolution, IEntity user)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? solution) ||
|
||||
solution.CurrentVolume == 0)
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution) || solution.CurrentVolume == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
// Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(_transferAmount, targetSolution.EmptyVolume);
|
||||
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("Container full."));
|
||||
Owner.PopupMessage(user, Loc.GetString("{0:theName} is already full!", targetSolution.Owner));
|
||||
return;
|
||||
}
|
||||
|
||||
//Move units from attackSolution to targetSolution
|
||||
// Move units from attackSolution to targetSolution
|
||||
var removedSolution = solution.SplitSolution(realTransferAmount);
|
||||
|
||||
if (!targetSolution.TryAddSolution(removedSolution))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Owner.PopupMessage(user, Loc.GetString("Injected {0}u", removedSolution.TotalVolume));
|
||||
Owner.PopupMessage(user, Loc.GetString("You transfter {0}u to {1:theName}", removedSolution.TotalVolume, targetSolution.Owner));
|
||||
Dirty();
|
||||
}
|
||||
|
||||
private void TryDraw(SolutionComponent targetSolution, IEntity user)
|
||||
private void TryDraw(SolutionContainerComponent targetSolution, IEntity user)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent? solution) ||
|
||||
solution.EmptyVolume == 0)
|
||||
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution) || solution.EmptyVolume == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
// Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(_transferAmount, targetSolution.CurrentVolume);
|
||||
|
||||
if (realTransferAmount <= 0)
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("Container empty"));
|
||||
Owner.PopupMessage(user, Loc.GetString("{0:theName} is empty!", targetSolution.Owner));
|
||||
return;
|
||||
}
|
||||
|
||||
//Move units from attackSolution to targetSolution
|
||||
// Move units from attackSolution to targetSolution
|
||||
var removedSolution = targetSolution.SplitSolution(realTransferAmount);
|
||||
|
||||
if (!solution.TryAddSolution(removedSolution))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Owner.PopupMessage(user, Loc.GetString("Drew {0}u", removedSolution.TotalVolume));
|
||||
Owner.PopupMessage(user, Loc.GetString("Drew {0}u from {1:theName}", removedSolution.TotalVolume, targetSolution.Owner));
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
Owner.TryGetComponent(out SolutionComponent? solution);
|
||||
Owner.TryGetComponent(out SolutionContainerComponent? solution);
|
||||
|
||||
var currentVolume = solution?.CurrentVolume ?? ReagentUnit.Zero;
|
||||
var maxVolume = solution?.MaxVolume ?? ReagentUnit.Zero;
|
||||
|
||||
Reference in New Issue
Block a user