Add solution pouring / click-transfer (#574)
* Add click-based solution transfer For example, clicking on a beaker with a soda can to transfer the soda to the beaker. Works on plain solution containers like beakers and also on open drink containers like soda cans as long as they have the `PourIn` and `PourOut` solution capabilities. If no `SolutionComponent` is added to a drink entity, the `DrinkComponent` will give the entity one. This PR extends that behavior slightly by also giving these default `SolutionComponent`'s the proper capabilities for pouring in/out. * Improve fix for poured drinks not immediately disappearing Instead of making `DrinkComponent.Use` public this splits out the code important to both users and made that function public, leaving `Use` private. * Shorten solution transfer popup * Make code review changes - Move pouring code from SolutionComponent to new PourableComponent. Added PourableComponent to client ignore list and added to existing container prototypes. - Added EmptyVolume property to shared SolutionComponent for convenience. - Removed DrinkComponent fix from pouring AttackBy code. Instead DrinkComponent subscribes to the SolutionChanged action and updates its self when necessary. - Fixed pouring being able to add more than a containers max volume and sometimes deleting reagents. - Added message for when a container is full. * More code review changes - Remove IAttackBy ComponentReference attribute in PourableComponent - Remove _transferAmount from shared SolutionComponent. Left over var from previous commit not being used anymore.
This commit is contained in:
@@ -80,10 +80,18 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
else
|
||||
{
|
||||
_contents = Owner.AddComponent<SolutionComponent>();
|
||||
//Ensure SolutionComponent supports click transferring if custom one not set
|
||||
_contents.Capabilities = SolutionCaps.PourIn
|
||||
| SolutionCaps.PourOut
|
||||
| SolutionCaps.Injectable;
|
||||
|
||||
var pourable = Owner.AddComponent<PourableComponent>();
|
||||
pourable.TransferAmount = 5;
|
||||
}
|
||||
}
|
||||
|
||||
_contents.MaxVolume = _initialContents.TotalVolume;
|
||||
_contents.SolutionChanged += HandleSolutionChangedEvent;
|
||||
}
|
||||
|
||||
protected override void Startup()
|
||||
@@ -117,7 +125,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
UseDrink(eventArgs.Attacked);
|
||||
}
|
||||
|
||||
void UseDrink(IEntity user)
|
||||
private void UseDrink(IEntity user)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
@@ -150,34 +158,53 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
}
|
||||
}
|
||||
|
||||
Finish(user);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Trigger finish behavior in the drink if applicable.
|
||||
/// Depending on the drink this will either delete it,
|
||||
/// or convert it to another entity, like an empty variant.
|
||||
/// </summary>
|
||||
/// <param name="user">The entity that is using the drink</param>
|
||||
public void Finish(IEntity user)
|
||||
{
|
||||
// Drink containers are mostly transient.
|
||||
if (!_despawnOnFinish || UsesLeft() > 0)
|
||||
{
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
var gridPos = Owner.Transform.GridPosition;
|
||||
_contents.SolutionChanged -= HandleSolutionChangedEvent;
|
||||
Owner.Delete();
|
||||
|
||||
if (_finishPrototype != null)
|
||||
{
|
||||
var finisher = Owner.EntityManager.SpawnEntity(_finishPrototype, Owner.Transform.GridPosition);
|
||||
if (user.TryGetComponent(out HandsComponent handsComponent) && finisher.TryGetComponent(out ItemComponent itemComponent))
|
||||
{
|
||||
if (handsComponent.CanPutInHand(itemComponent))
|
||||
{
|
||||
handsComponent.PutInHand(itemComponent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
finisher.Transform.GridPosition = user.Transform.GridPosition;
|
||||
if (finisher.TryGetComponent(out DrinkComponent drinkComponent))
|
||||
{
|
||||
drinkComponent.MaxVolume = MaxVolume;
|
||||
}
|
||||
if (_finishPrototype == null || user == null)
|
||||
return;
|
||||
|
||||
var finisher = Owner.EntityManager.SpawnEntity(_finishPrototype, Owner.Transform.GridPosition);
|
||||
if (user.TryGetComponent(out HandsComponent handsComponent) && finisher.TryGetComponent(out ItemComponent itemComponent))
|
||||
{
|
||||
if (handsComponent.CanPutInHand(itemComponent))
|
||||
{
|
||||
handsComponent.PutInHand(itemComponent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
finisher.Transform.GridPosition = gridPos;
|
||||
if (finisher.TryGetComponent(out DrinkComponent drinkComponent))
|
||||
{
|
||||
drinkComponent.MaxVolume = MaxVolume;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates drink state when the solution is changed by something other
|
||||
/// than this component. Without this some drinks won't properly delete
|
||||
/// themselves without additional clicks/uses after them being emptied.
|
||||
/// </summary>
|
||||
private void HandleSolutionChangedEvent()
|
||||
{
|
||||
Finish(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user