Bartending+: Shaking and Stirring (#29243)

* Shaking and Stirring

* Remove shake message

* Switch if order a bit

* Add doafter supprot for reactionmixer

* Fix nullability

* Timespan zero

* Forgot to remove loc string

* Reorganize usings

* Remove unneeded usings, fix b52 needing to be shaken
This commit is contained in:
Verm
2024-07-07 09:21:53 -05:00
committed by GitHub
parent 71b7dddb59
commit 13b84870ec
7 changed files with 161 additions and 13 deletions

View File

@@ -1,6 +1,9 @@
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;
@@ -10,34 +13,68 @@ public sealed partial class ReactionMixerSystem : EntitySystem
{
[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)
{
return;
}
if (!_solutionContainers.TryGetMixableSolution(args.Target.Value, out var solution, out _))
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);
var doAfterArgs = new DoAfterArgs(EntityManager, args.User, entity.Comp.TimeToMix, new ReactionMixDoAfterEvent(), entity, args.Target.Value, entity);
_solutionContainers.UpdateChemicals(solution.Value, true, entity.Comp);
_doAfterSystem.TryStartDoAfter(doAfterArgs);
}
var afterMixingEvent = new AfterMixingEvent(entity, args.Target.Value);
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);
_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);
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;
}
}

View File

@@ -1,5 +1,7 @@
using Content.Shared.Chemistry.Components;
using Content.Shared.DoAfter;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
namespace Content.Shared.Chemistry.Reaction;
@@ -19,9 +21,28 @@ public sealed partial class ReactionMixerComponent : Component
[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
{
}

View File

@@ -6,9 +6,12 @@ mixing-verb-default-condense = condense
mixing-verb-centrifuge = centrifugation
mixing-verb-electrolysis = electrolyze
mixing-verb-holy = bless
mixing-verb-stir = stir
mixing-verb-shake = shake
## Entity
default-mixing-success = You mix the {$mixed} with the {$mixer}
bible-mixing-success = You bless the {$mixed} with the {$mixer}
spoon-mixing-success = You stir the {$mixed} with the {$mixer}

View File

@@ -51,3 +51,17 @@
icon:
sprite: Objects/Specific/Chapel/bible.rsi
state: icon
- type: mixingCategory
id: Shake
verbText: mixing-verb-shake
icon:
sprite: Objects/Consumable/Drinks/shaker.rsi
state: icon
- type: mixingCategory
id: Stir
verbText: mixing-verb-stir
icon:
sprite: Objects/Misc/utensils.rsi
state: spoon

View File

@@ -11,7 +11,7 @@
- type: MixableSolution
solution: drink
- type: Drink
- type: Shakeable # Doesn't do anything, but I mean...
- type: Shakeable
- type: FitsInDispenser
solution: drink
- type: DrawableSolution
@@ -34,6 +34,10 @@
- type: PhysicalComposition
materialComposition:
Steel: 50
- type: ReactionMixer
mixOnInteract: false
reactionTypes:
- Shake
- type: entity
parent: DrinkGlassBase

View File

@@ -87,6 +87,11 @@
Blunt: 1
- type: Shovel
speedModifier: 0.1 # you can try
- type: ReactionMixer
mixMessage: "spoon-mixing-success"
timeToMix: 0.5
reactionTypes:
- Stir
- type: entity
parent: UtensilBasePlastic
@@ -103,6 +108,11 @@
- Spoon
- type: Shovel
speedModifier: 0.1 # you can try
- type: ReactionMixer
mixMessage: "spoon-mixing-success"
timeToMix: 0.5
reactionTypes:
- Stir
- type: entity
parent: UtensilBasePlastic
@@ -137,6 +147,11 @@
- type: Utensil
types:
- Spoon
- type: ReactionMixer
mixMessage: "spoon-mixing-success"
timeToMix: 0.5
reactionTypes:
- Stir
- type: MeleeWeapon
wideAnimationRotation: 180
attackRate: 2

View File

@@ -10,6 +10,8 @@
- type: reaction
id: AlliesCocktail
requiredMixerCategories:
- Shake
reactants:
Martini:
amount: 2
@@ -20,6 +22,8 @@
- type: reaction
id: Amasec
requiredMixerCategories:
- Shake
reactants:
Wine:
amount: 2
@@ -32,6 +36,8 @@
- type: reaction
id: Andalusia
requiredMixerCategories:
- Stir
reactants:
Rum:
amount: 1
@@ -98,6 +104,8 @@
- type: reaction
id: BlueHawaiian
requiredMixerCategories:
- Shake
reactants:
CoconutRum:
amount: 2
@@ -126,6 +134,8 @@
- type: reaction
id: BahamaMama
requiredMixerCategories:
- Shake
reactants:
Ice:
amount: 1
@@ -168,6 +178,8 @@
- type: reaction
id: BeepskySmash
requiredMixerCategories:
- Shake
reactants:
Iron:
amount: 1
@@ -190,6 +202,8 @@
- type: reaction
id: BloodyMary
requiredMixerCategories:
- Stir
reactants:
JuiceLime:
amount: 1
@@ -280,6 +294,8 @@
- type: reaction
id: DemonsBlood
requiredMixerCategories:
- Stir
reactants:
Rum:
amount: 1
@@ -294,6 +310,8 @@
- type: reaction
id: DevilsKiss
requiredMixerCategories:
- Stir
reactants:
Rum:
amount: 1
@@ -306,6 +324,8 @@
- type: reaction
id: DoctorsDelight
requiredMixerCategories:
- Stir
reactants:
Cream:
amount: 2
@@ -322,6 +342,8 @@
- type: reaction
id: DriestMartini
requiredMixerCategories:
- Shake
reactants:
Gin:
amount: 1
@@ -332,6 +354,8 @@
- type: reaction
id: ErikaSurprise
requiredMixerCategories:
- Shake
reactants:
Ale:
amount: 2
@@ -373,6 +397,8 @@
- type: reaction
id: GargleBlaster
requiredMixerCategories:
- Shake
reactants:
Cognac:
amount: 1
@@ -411,6 +437,8 @@
- type: reaction
id: Gildlager
requiredMixerCategories:
- Shake
reactants:
Gold:
amount: 1
@@ -548,6 +576,8 @@
- type: reaction
id: IrishCoffee
requiredMixerCategories:
- Stir
reactants:
Coffee:
amount: 1
@@ -568,6 +598,8 @@
- type: reaction
id: KiraSpecial
requiredMixerCategories:
- Stir
reactants:
JuiceLime:
amount: 1
@@ -580,6 +612,8 @@
- type: reaction
id: Lemonade
requiredMixerCategories:
- Stir
reactants:
JuiceLemon:
amount: 1
@@ -592,6 +626,8 @@
- type: reaction
id: LemonLime
requiredMixerCategories:
- Stir
reactants:
JuiceLemon:
amount: 1
@@ -604,6 +640,8 @@
- type: reaction
id: LongIslandIcedTea
requiredMixerCategories:
- Stir
reactants:
CubaLibre:
amount: 3
@@ -618,6 +656,8 @@
- type: reaction
id: Manhattan
requiredMixerCategories:
- Shake
reactants:
Whiskey:
amount: 2
@@ -658,6 +698,8 @@
- type: reaction
id: Martini
requiredMixerCategories:
- Shake
reactants:
Gin:
amount: 2
@@ -679,6 +721,8 @@
- type: reaction
id: Mojito
requiredMixerCategories:
- Shake
reactants:
JuiceLime:
amount: 1
@@ -726,6 +770,8 @@
- type: reaction
id: Patron
requiredMixerCategories:
- Shake
reactants:
Tequila:
amount: 10
@@ -736,6 +782,8 @@
- type: reaction
id: Painkiller
requiredMixerCategories:
- Shake
reactants:
JuicePineapple:
amount: 3
@@ -838,6 +886,8 @@
- type: reaction
id: ScrewdriverCocktail
requiredMixerCategories:
- Shake
reactants:
JuiceOrange:
amount: 2
@@ -955,6 +1005,8 @@
- type: reaction
id: ToxinsSpecial
requiredMixerCategories:
- Shake
reactants:
Rum:
amount: 2
@@ -967,6 +1019,8 @@
- type: reaction
id: VodkaMartini
requiredMixerCategories:
- Shake
reactants:
Vermouth:
amount: 1