Drink fixes (#605)
* Fix max_volume in cup YAML Fixes #563 Added parsing of max_volume from YAML. Before it would get max volume only from drink content total. * Fix drink owner getting deleted early _contents.SplitSolution causes _contents.SolutionChanged to call Finish early causing a crash when try to get SoundComponent from the deleted Entity.
This commit is contained in:
@@ -43,9 +43,12 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Solution _initialContents; // This is just for loading from yaml
|
private Solution _initialContents; // This is just for loading from yaml
|
||||||
|
private int _maxVolume;
|
||||||
|
|
||||||
private bool _despawnOnFinish;
|
private bool _despawnOnFinish;
|
||||||
|
|
||||||
|
private bool _drinking;
|
||||||
|
|
||||||
public int UsesLeft()
|
public int UsesLeft()
|
||||||
{
|
{
|
||||||
// In case transfer amount exceeds volume left
|
// In case transfer amount exceeds volume left
|
||||||
@@ -61,6 +64,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
{
|
{
|
||||||
base.ExposeData(serializer);
|
base.ExposeData(serializer);
|
||||||
serializer.DataField(ref _initialContents, "contents", null);
|
serializer.DataField(ref _initialContents, "contents", null);
|
||||||
|
serializer.DataField(ref _maxVolume, "max_volume", 0);
|
||||||
serializer.DataField(ref _useSound, "use_sound", "/Audio/items/drink.ogg");
|
serializer.DataField(ref _useSound, "use_sound", "/Audio/items/drink.ogg");
|
||||||
// E.g. cola can when done or clear bottle, whatever
|
// E.g. cola can when done or clear bottle, whatever
|
||||||
// Currently this will enforce it has the same volume but this may change.
|
// Currently this will enforce it has the same volume but this may change.
|
||||||
@@ -90,7 +94,11 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_contents.MaxVolume = _initialContents.TotalVolume;
|
_drinking = false;
|
||||||
|
if (_maxVolume != 0)
|
||||||
|
_contents.MaxVolume = _maxVolume;
|
||||||
|
else
|
||||||
|
_contents.MaxVolume = _initialContents.TotalVolume;
|
||||||
_contents.SolutionChanged += HandleSolutionChangedEvent;
|
_contents.SolutionChanged += HandleSolutionChangedEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,6 +148,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
|
|
||||||
if (user.TryGetComponent(out StomachComponent stomachComponent))
|
if (user.TryGetComponent(out StomachComponent stomachComponent))
|
||||||
{
|
{
|
||||||
|
_drinking = true;
|
||||||
var transferAmount = Math.Min(_transferAmount, _contents.CurrentVolume);
|
var transferAmount = Math.Min(_transferAmount, _contents.CurrentVolume);
|
||||||
var split = _contents.SplitSolution(transferAmount);
|
var split = _contents.SplitSolution(transferAmount);
|
||||||
if (stomachComponent.TryTransferSolution(split))
|
if (stomachComponent.TryTransferSolution(split))
|
||||||
@@ -156,6 +165,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
_contents.TryAddSolution(split);
|
_contents.TryAddSolution(split);
|
||||||
user.PopupMessage(user, _localizationManager.GetString("Can't drink"));
|
user.PopupMessage(user, _localizationManager.GetString("Can't drink"));
|
||||||
}
|
}
|
||||||
|
_drinking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Finish(user);
|
Finish(user);
|
||||||
@@ -170,7 +180,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
public void Finish(IEntity user)
|
public void Finish(IEntity user)
|
||||||
{
|
{
|
||||||
// Drink containers are mostly transient.
|
// Drink containers are mostly transient.
|
||||||
if (!_despawnOnFinish || UsesLeft() > 0)
|
if (_drinking || !_despawnOnFinish || UsesLeft() > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var gridPos = Owner.Transform.GridPosition;
|
var gridPos = Owner.Transform.GridPosition;
|
||||||
|
|||||||
@@ -5,9 +5,10 @@
|
|||||||
name: Base cup
|
name: Base cup
|
||||||
abstract: true
|
abstract: true
|
||||||
components:
|
components:
|
||||||
- type: Drink
|
- type: Drink
|
||||||
max_volume: 4
|
max_volume: 4
|
||||||
despawn_empty: false
|
despawn_empty: false
|
||||||
|
- type: Sound
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
state: icon
|
state: icon
|
||||||
- type: Icon
|
- type: Icon
|
||||||
@@ -19,7 +20,7 @@
|
|||||||
name: Golden cup
|
name: Golden cup
|
||||||
description: A golden cup
|
description: A golden cup
|
||||||
components:
|
components:
|
||||||
- type: Drink
|
- type: Drink
|
||||||
max_volume: 10
|
max_volume: 10
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Drinks/golden_cup.rsi
|
sprite: Objects/Drinks/golden_cup.rsi
|
||||||
@@ -32,7 +33,7 @@
|
|||||||
name: Insulated pitcher
|
name: Insulated pitcher
|
||||||
description: A stainless steel insulated pitcher. Everyone's best friend in the morning.
|
description: A stainless steel insulated pitcher. Everyone's best friend in the morning.
|
||||||
components:
|
components:
|
||||||
- type: Drink
|
- type: Drink
|
||||||
max_volume: 15
|
max_volume: 15
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Drinks/pitcher.rsi
|
sprite: Objects/Drinks/pitcher.rsi
|
||||||
@@ -51,7 +52,7 @@
|
|||||||
name: Mug
|
name: Mug
|
||||||
description: A plain white mug.
|
description: A plain white mug.
|
||||||
components:
|
components:
|
||||||
- type: Drink
|
- type: Drink
|
||||||
max_volume: 4
|
max_volume: 4
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Drinks/mug.rsi
|
sprite: Objects/Drinks/mug.rsi
|
||||||
@@ -70,7 +71,7 @@
|
|||||||
name: Mug Black
|
name: Mug Black
|
||||||
description: A sleek black mug.
|
description: A sleek black mug.
|
||||||
components:
|
components:
|
||||||
- type: Drink
|
- type: Drink
|
||||||
max_volume: 4
|
max_volume: 4
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Drinks/mug_black.rsi
|
sprite: Objects/Drinks/mug_black.rsi
|
||||||
@@ -89,7 +90,7 @@
|
|||||||
name: Mug Blue
|
name: Mug Blue
|
||||||
description: A blue and black mug.
|
description: A blue and black mug.
|
||||||
components:
|
components:
|
||||||
- type: Drink
|
- type: Drink
|
||||||
max_volume: 4
|
max_volume: 4
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Drinks/mug_blue.rsi
|
sprite: Objects/Drinks/mug_blue.rsi
|
||||||
@@ -108,7 +109,7 @@
|
|||||||
name: Mug Green
|
name: Mug Green
|
||||||
description: A pale green and pink mug.
|
description: A pale green and pink mug.
|
||||||
components:
|
components:
|
||||||
- type: Drink
|
- type: Drink
|
||||||
max_volume: 4
|
max_volume: 4
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Drinks/mug_green.rsi
|
sprite: Objects/Drinks/mug_green.rsi
|
||||||
@@ -127,7 +128,7 @@
|
|||||||
name: Mug Heart
|
name: Mug Heart
|
||||||
description: A white mug, it prominently features a red heart.
|
description: A white mug, it prominently features a red heart.
|
||||||
components:
|
components:
|
||||||
- type: Drink
|
- type: Drink
|
||||||
max_volume: 4
|
max_volume: 4
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Drinks/mug_heart.rsi
|
sprite: Objects/Drinks/mug_heart.rsi
|
||||||
@@ -146,7 +147,7 @@
|
|||||||
name: Mug Metal
|
name: Mug Metal
|
||||||
description: A metal mug. You're not sure which metal.
|
description: A metal mug. You're not sure which metal.
|
||||||
components:
|
components:
|
||||||
- type: Drink
|
- type: Drink
|
||||||
max_volume: 4
|
max_volume: 4
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Drinks/mug_metal.rsi
|
sprite: Objects/Drinks/mug_metal.rsi
|
||||||
@@ -165,7 +166,7 @@
|
|||||||
name: Mug Moebius
|
name: Mug Moebius
|
||||||
description: A mug with a Moebius Laboratories logo on it. Not even your morning coffee is safe from corporate advertising.
|
description: A mug with a Moebius Laboratories logo on it. Not even your morning coffee is safe from corporate advertising.
|
||||||
components:
|
components:
|
||||||
- type: Drink
|
- type: Drink
|
||||||
max_volume: 4
|
max_volume: 4
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Drinks/mug_moebius.rsi
|
sprite: Objects/Drinks/mug_moebius.rsi
|
||||||
@@ -184,7 +185,7 @@
|
|||||||
name: "#1 mug"
|
name: "#1 mug"
|
||||||
description: "A white mug, it prominently features a #1."
|
description: "A white mug, it prominently features a #1."
|
||||||
components:
|
components:
|
||||||
- type: Drink
|
- type: Drink
|
||||||
max_volume: 4
|
max_volume: 4
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Drinks/mug_one.rsi
|
sprite: Objects/Drinks/mug_one.rsi
|
||||||
@@ -203,7 +204,7 @@
|
|||||||
name: Mug Rainbow
|
name: Mug Rainbow
|
||||||
description: A rainbow mug. The colors are almost as blinding as a welder.
|
description: A rainbow mug. The colors are almost as blinding as a welder.
|
||||||
components:
|
components:
|
||||||
- type: Drink
|
- type: Drink
|
||||||
max_volume: 4
|
max_volume: 4
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Drinks/mug_rainbow.rsi
|
sprite: Objects/Drinks/mug_rainbow.rsi
|
||||||
@@ -222,7 +223,7 @@
|
|||||||
name: Mug Red
|
name: Mug Red
|
||||||
description: A red and black mug.
|
description: A red and black mug.
|
||||||
components:
|
components:
|
||||||
- type: Drink
|
- type: Drink
|
||||||
max_volume: 4
|
max_volume: 4
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Drinks/mug_red.rsi
|
sprite: Objects/Drinks/mug_red.rsi
|
||||||
|
|||||||
Reference in New Issue
Block a user