Chem Master & Dispenser Power Fixes (#1622)

* -ChemDispenser & Master can now open the UI without power
-Both can also eject beaker without power

* -Disables button if not powered
-Disables clear & eject buttons if no beaker

* Fix server freeze
This commit is contained in:
Exp
2020-08-10 16:30:56 +02:00
committed by GitHub
parent 9785a8e647
commit aaffd7e198
7 changed files with 119 additions and 23 deletions

View File

@@ -83,6 +83,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
_beakerContainer =
ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-reagentContainerContainer", Owner);
_powerReceiver = Owner.GetComponent<PowerReceiverComponent>();
_powerReceiver.OnPowerStateChanged += OnPowerChanged;
//BufferSolution = Owner.BufferSolution
BufferSolution.Solution = new Solution();
@@ -91,6 +92,11 @@ namespace Content.Server.GameObjects.Components.Chemistry
UpdateUserInterface();
}
private void OnPowerChanged(object sender, PowerStateEventArgs e)
{
UpdateUserInterface();
}
/// <summary>
/// Handles ui messages from the client. For things such as button presses
/// which interact with the world and require server action.
@@ -98,10 +104,16 @@ namespace Content.Server.GameObjects.Components.Chemistry
/// <param name="obj">A user interface message from the client.</param>
private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
{
if (!PlayerCanUseChemMaster(obj.Session.AttachedEntity))
var msg = (UiActionMessage) obj.Message;
var needsPower = msg.action switch
{
UiAction.Eject => false,
_ => true,
};
if (!PlayerCanUseChemMaster(obj.Session.AttachedEntity, needsPower))
return;
var msg = (UiActionMessage) obj.Message;
switch (msg.action)
{
case UiAction.Eject:
@@ -134,7 +146,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
/// </summary>
/// <param name="playerEntity">The player entity.</param>
/// <returns>Returns true if the entity can use the chem master, and false if it cannot.</returns>
private bool PlayerCanUseChemMaster(IEntity playerEntity)
private bool PlayerCanUseChemMaster(IEntity playerEntity, bool needsPower = true)
{
//Need player entity to check if they are still able to use the chem master
if (playerEntity == null)
@@ -143,7 +155,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
if (!ActionBlockerSystem.CanInteract(playerEntity) || !ActionBlockerSystem.CanUse(playerEntity))
return false;
//Check if device is powered
if (!Powered)
if (needsPower && !Powered)
return false;
return true;
@@ -158,12 +170,12 @@ namespace Content.Server.GameObjects.Components.Chemistry
var beaker = _beakerContainer.ContainedEntity;
if (beaker == null)
{
return new ChemMasterBoundUserInterfaceState(false, ReagentUnit.New(0), ReagentUnit.New(0),
return new ChemMasterBoundUserInterfaceState(Powered, false, ReagentUnit.New(0), ReagentUnit.New(0),
"", Owner.Name, null, BufferSolution.ReagentList.ToList(), BufferModeTransfer, BufferSolution.CurrentVolume, BufferSolution.MaxVolume);
}
var solution = beaker.GetComponent<SolutionComponent>();
return new ChemMasterBoundUserInterfaceState(true, solution.CurrentVolume, solution.MaxVolume,
return new ChemMasterBoundUserInterfaceState(Powered, true, solution.CurrentVolume, solution.MaxVolume,
beaker.Name, Owner.Name, solution.ReagentList.ToList(), BufferSolution.ReagentList.ToList(), BufferModeTransfer, BufferSolution.CurrentVolume, BufferSolution.MaxVolume);
}
@@ -252,9 +264,15 @@ namespace Content.Server.GameObjects.Components.Chemistry
{
var random = IoCManager.Resolve<IRobustRandom>();
if (BufferSolution.CurrentVolume == 0)
return;
if (action == UiAction.CreateBottles)
{
var individualVolume = BufferSolution.CurrentVolume / ReagentUnit.New(bottleAmount);
if (individualVolume < ReagentUnit.New(1))
return;
var actualVolume = ReagentUnit.Min(individualVolume, ReagentUnit.New(30));
for (int i = 0; i < bottleAmount; i++)
{
@@ -289,6 +307,9 @@ namespace Content.Server.GameObjects.Components.Chemistry
else //Pills
{
var individualVolume = BufferSolution.CurrentVolume / ReagentUnit.New(pillAmount);
if (individualVolume < ReagentUnit.New(1))
return;
var actualVolume = ReagentUnit.Min(individualVolume, ReagentUnit.New(50));
for (int i = 0; i < pillAmount; i++)
{
@@ -341,9 +362,6 @@ namespace Content.Server.GameObjects.Components.Chemistry
return;
}
if (!Powered)
return;
var activeHandEntity = hands.GetActiveHand?.Owner;
if (activeHandEntity == null)
{