+using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reaction;
+using Content.Shared.DoAfter;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
+using Content.Shared.Nutrition.EntitySystems;
using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Server.Popups;
{
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainers = default!;
+ [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ReactionMixerComponent, AfterInteractEvent>(OnAfterInteract);
+ SubscribeLocalEvent<ReactionMixerComponent, ShakeEvent>(OnShake);
+ SubscribeLocalEvent<ReactionMixerComponent, ReactionMixDoAfterEvent>(OnDoAfter);
}
private void OnAfterInteract(Entity<ReactionMixerComponent> entity, ref AfterInteractEvent args)
{
- if (!args.Target.HasValue || !args.CanReach)
+ if (!args.Target.HasValue || !args.CanReach || !entity.Comp.MixOnInteract)
return;
- var mixAttemptEvent = new MixingAttemptEvent(entity);
- RaiseLocalEvent(entity, ref mixAttemptEvent);
- if (mixAttemptEvent.Cancelled)
- {
+ if (!MixAttempt(entity, args.Target.Value, out var solution))
return;
- }
- if (!_solutionContainers.TryGetMixableSolution(args.Target.Value, out var solution, out _))
+ var doAfterArgs = new DoAfterArgs(EntityManager, args.User, entity.Comp.TimeToMix, new ReactionMixDoAfterEvent(), entity, args.Target.Value, entity);
+
+ _doAfterSystem.TryStartDoAfter(doAfterArgs);
+ }
+
+ private void OnDoAfter(Entity<ReactionMixerComponent> entity, ref ReactionMixDoAfterEvent args)
+ {
+ //Do again to get the solution again
+ if (!MixAttempt(entity, args.Target!.Value, out var solution))
return;
- _popup.PopupEntity(Loc.GetString(entity.Comp.MixMessage, ("mixed", Identity.Entity(args.Target.Value, EntityManager)), ("mixer", Identity.Entity(entity.Owner, EntityManager))), args.User, args.User);
+ _popup.PopupEntity(Loc.GetString(entity.Comp.MixMessage, ("mixed", Identity.Entity(args.Target!.Value, EntityManager)), ("mixer", Identity.Entity(entity.Owner, EntityManager))), args.User, args.User);
+
+ _solutionContainers.UpdateChemicals(solution!.Value, true, entity.Comp);
+
+ var afterMixingEvent = new AfterMixingEvent(entity, args.Target!.Value);
+ RaiseLocalEvent(entity, afterMixingEvent);
+ }
+
+ private void OnShake(Entity<ReactionMixerComponent> entity, ref ShakeEvent args)
+ {
+ if (!MixAttempt(entity, entity, out var solution))
+ return;
- _solutionContainers.UpdateChemicals(solution.Value, true, entity.Comp);
+ _solutionContainers.UpdateChemicals(solution!.Value, true, entity.Comp);
- var afterMixingEvent = new AfterMixingEvent(entity, args.Target.Value);
+ var afterMixingEvent = new AfterMixingEvent(entity, entity);
RaiseLocalEvent(entity, afterMixingEvent);
}
+
+ private bool MixAttempt(EntityUid ent, EntityUid target, out Entity<SolutionComponent>? solution)
+ {
+ solution = null;
+ var mixAttemptEvent = new MixingAttemptEvent(ent);
+ RaiseLocalEvent(ent, ref mixAttemptEvent);
+ if (mixAttemptEvent.Cancelled)
+ {
+ return false;
+ }
+
+ if (!_solutionContainers.TryGetMixableSolution(target, out solution, out _))
+ return false;
+
+ return true;
+ }
}
using Content.Shared.Chemistry.Components;
+using Content.Shared.DoAfter;
using Robust.Shared.Prototypes;
+using Robust.Shared.Serialization;
namespace Content.Shared.Chemistry.Reaction;
[ViewVariables]
[DataField]
public LocId MixMessage = "default-mixing-success";
+
+ /// <summary>
+ /// Defines if interacting is enough to mix with this component
+ /// </summary>
+ [ViewVariables]
+ [DataField]
+ public bool MixOnInteract = true;
+
+ /// <summary>
+ /// How long it takes to mix with this
+ /// </summary>
+ [ViewVariables]
+ [DataField]
+ public TimeSpan TimeToMix = TimeSpan.Zero;
}
[ByRefEvent]
public record struct MixingAttemptEvent(EntityUid Mixed, bool Cancelled = false);
public readonly record struct AfterMixingEvent(EntityUid Mixed, EntityUid Mixer);
+
+[Serializable, NetSerializable]
+public sealed partial class ReactionMixDoAfterEvent : SimpleDoAfterEvent
+{
+}
- type: reaction
id: AlliesCocktail
+ requiredMixerCategories:
+ - Shake
reactants:
Martini:
amount: 2
- type: reaction
id: Amasec
+ requiredMixerCategories:
+ - Shake
reactants:
Wine:
amount: 2
- type: reaction
id: Andalusia
+ requiredMixerCategories:
+ - Stir
reactants:
Rum:
amount: 1
- type: reaction
id: BlueHawaiian
+ requiredMixerCategories:
+ - Shake
reactants:
CoconutRum:
amount: 2
- type: reaction
id: BahamaMama
+ requiredMixerCategories:
+ - Shake
reactants:
Ice:
amount: 1
- type: reaction
id: BeepskySmash
+ requiredMixerCategories:
+ - Shake
reactants:
Iron:
amount: 1
- type: reaction
id: BloodyMary
+ requiredMixerCategories:
+ - Stir
reactants:
JuiceLime:
amount: 1
- type: reaction
id: DemonsBlood
+ requiredMixerCategories:
+ - Stir
reactants:
Rum:
amount: 1
- type: reaction
id: DevilsKiss
+ requiredMixerCategories:
+ - Stir
reactants:
Rum:
amount: 1
- type: reaction
id: DoctorsDelight
+ requiredMixerCategories:
+ - Stir
reactants:
Cream:
amount: 2
- type: reaction
id: DriestMartini
+ requiredMixerCategories:
+ - Shake
reactants:
Gin:
amount: 1
- type: reaction
id: ErikaSurprise
+ requiredMixerCategories:
+ - Shake
reactants:
Ale:
amount: 2
- type: reaction
id: GargleBlaster
+ requiredMixerCategories:
+ - Shake
reactants:
Cognac:
amount: 1
- type: reaction
id: Gildlager
+ requiredMixerCategories:
+ - Shake
reactants:
Gold:
amount: 1
- type: reaction
id: IrishCoffee
+ requiredMixerCategories:
+ - Stir
reactants:
Coffee:
amount: 1
- type: reaction
id: KiraSpecial
+ requiredMixerCategories:
+ - Stir
reactants:
JuiceLime:
amount: 1
- type: reaction
id: Lemonade
+ requiredMixerCategories:
+ - Stir
reactants:
JuiceLemon:
amount: 1
- type: reaction
id: LemonLime
+ requiredMixerCategories:
+ - Stir
reactants:
JuiceLemon:
amount: 1
- type: reaction
id: LongIslandIcedTea
+ requiredMixerCategories:
+ - Stir
reactants:
CubaLibre:
amount: 3
- type: reaction
id: Manhattan
+ requiredMixerCategories:
+ - Shake
reactants:
Whiskey:
amount: 2
- type: reaction
id: Martini
+ requiredMixerCategories:
+ - Shake
reactants:
Gin:
amount: 2
- type: reaction
id: Mojito
+ requiredMixerCategories:
+ - Shake
reactants:
JuiceLime:
amount: 1
- type: reaction
id: Patron
+ requiredMixerCategories:
+ - Shake
reactants:
Tequila:
amount: 10
- type: reaction
id: Painkiller
+ requiredMixerCategories:
+ - Shake
reactants:
JuicePineapple:
amount: 3
- type: reaction
id: ScrewdriverCocktail
+ requiredMixerCategories:
+ - Shake
reactants:
JuiceOrange:
amount: 2
- type: reaction
id: ToxinsSpecial
+ requiredMixerCategories:
+ - Shake
reactants:
Rum:
amount: 2
- type: reaction
id: VodkaMartini
+ requiredMixerCategories:
+ - Shake
reactants:
Vermouth:
amount: 1