Prevent closed drinks from transferring reagents (#7329)
* Prevent closed drinks from transferring reagents * Inherit from cancellable event
This commit is contained in:
@@ -54,6 +54,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
SubscribeLocalEvent<DrinkComponent, UseInHandEvent>(OnUse);
|
||||
SubscribeLocalEvent<DrinkComponent, AfterInteractEvent>(AfterInteract);
|
||||
SubscribeLocalEvent<DrinkComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<DrinkComponent, SolutionTransferAttemptEvent>(OnTransferAttempt);
|
||||
SubscribeLocalEvent<SharedBodyComponent, DrinkEvent>(OnDrink);
|
||||
SubscribeLocalEvent<DrinkCancelledEvent>(OnDrinkCancelled);
|
||||
}
|
||||
@@ -94,17 +95,6 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
{
|
||||
appearance.SetData(DrinkCanStateVisual.Opened, opened);
|
||||
}
|
||||
|
||||
if (opened)
|
||||
{
|
||||
EntityManager.EnsureComponent<RefillableSolutionComponent>(uid).Solution= component.SolutionName;
|
||||
EntityManager.EnsureComponent<DrainableSolutionComponent>(uid).Solution= component.SolutionName;
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityManager.RemoveComponent<RefillableSolutionComponent>(uid);
|
||||
EntityManager.RemoveComponent<DrainableSolutionComponent>(uid);
|
||||
}
|
||||
}
|
||||
|
||||
private void AfterInteract(EntityUid uid, DrinkComponent component, AfterInteractEvent args)
|
||||
@@ -163,6 +153,10 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
}
|
||||
|
||||
UpdateAppearance(component);
|
||||
|
||||
// Synchronize solution in drink
|
||||
EnsureComp<RefillableSolutionComponent>(uid).Solution = component.SolutionName;
|
||||
EnsureComp<DrainableSolutionComponent>(uid).Solution = component.SolutionName;
|
||||
}
|
||||
|
||||
private void OnSolutionChange(EntityUid uid, DrinkComponent component, SolutionChangedEvent args)
|
||||
@@ -183,6 +177,15 @@ namespace Content.Server.Nutrition.EntitySystems
|
||||
appearance.SetData(DrinkCanStateVisual.Opened, component.Opened);
|
||||
}
|
||||
|
||||
private void OnTransferAttempt(EntityUid uid, DrinkComponent component, SolutionTransferAttemptEvent args)
|
||||
{
|
||||
if (!component.Opened)
|
||||
{
|
||||
args.Cancel(Loc.GetString("drink-component-try-use-drink-not-open",
|
||||
("owner", EntityManager.GetComponent<MetaDataComponent>(component.Owner).EntityName)));
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryDrink(EntityUid user, EntityUid target, DrinkComponent drink)
|
||||
{
|
||||
// cannot stack do-afters
|
||||
|
||||
Reference in New Issue
Block a user