forked from DeltaV-Station/Delta-v
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Randomized lollipop and gumball flavors (DeltaV-Station#1074)
* Give lollipops and gumballs random flavors * RandomizedCandy: Fix borg lollipop action * RandomizedCandy: Play sound when candy is fabricated * RandomizedCandy: Lollipop can now be put in mouth * RandomizedCandy: Quieten fab sound * RandomizedCandy: merge icons and reexport without pHYs chunk should speed up downloading these textures on 9600 baud modems * RandomizedCandy: loads more flavors and update description * RandomizedCandy: Fix duplicate candyFlavor IDs * RandomizedCandy: Fix attrib and preserve flavor order * RandomizedCandy: init on MapInit instead of ComponentInit * RandomizedCandy: Fix minor code style issues, file placement * RandomizedCandy: put new code into DeltaV namespace * RandomizedCandy: Removed redundant datafield tags Signed-off-by: no <165581243+pissdemon@users.noreply.github.com> --------- Signed-off-by: no <165581243+pissdemon@users.noreply.github.com>
- Loading branch information
Showing
19 changed files
with
486 additions
and
11 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
Content.Client/DeltaV/Abilities/Borgs/RandomizedCandyVisualizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Content.Shared.DeltaV.Abilities.Borgs; | ||
using Robust.Client.GameObjects; | ||
|
||
namespace Content.Client.DeltaV.Abilities.Borgs; | ||
|
||
/// <summary> | ||
/// Responsible for coloring randomized candy. | ||
/// </summary> | ||
public sealed class RandomizedCandyVisualizer : VisualizerSystem<RandomizedCandyComponent> | ||
{ | ||
protected override void OnAppearanceChange(EntityUid uid, RandomizedCandyComponent component, ref AppearanceChangeEvent args) | ||
{ | ||
if (!TryComp<SpriteComponent>(uid, out var sprite) | ||
|| !AppearanceSystem.TryGetData<Color>(uid, RandomizedCandyVisuals.Color, out var color, args.Component)) | ||
{ | ||
return; | ||
} | ||
|
||
sprite.LayerSetColor(CandyVisualLayers.Ball, color); | ||
} | ||
} | ||
|
||
public enum CandyVisualLayers : byte | ||
{ | ||
Ball | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Content.Server/DeltaV/Abilities/Borgs/CandyFlavorPrototype.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Content.Shared.Nutrition; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Server.DeltaV.Abilities.Borgs; | ||
|
||
/// <summary> | ||
/// Describes the color and flavor profile of lollipops and gumballs. Yummy! | ||
/// </summary> | ||
[Prototype("candyFlavor")] | ||
public sealed partial class CandyFlavorPrototype : IPrototype | ||
{ | ||
/// <inheritdoc/> | ||
[IdDataField] | ||
public string ID { get; private set; } = default!; | ||
|
||
/// <summary> | ||
/// The display name for this candy. Not localized. | ||
/// </summary> | ||
[DataField] public string Name { get; private set; } = ""; | ||
|
||
/// <summary> | ||
/// The color of the candy. | ||
/// </summary> | ||
[DataField] public Color Color { get; private set; } = Color.White; | ||
|
||
/// <summary> | ||
/// How the candy tastes like. | ||
/// </summary> | ||
[DataField] | ||
public HashSet<ProtoId<FlavorPrototype>> Flavors { get; private set; } = []; | ||
} |
83 changes: 83 additions & 0 deletions
83
Content.Server/DeltaV/Abilities/Borgs/RandomizedCandySystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.Linq; | ||
using Content.Server.Nutrition.Components; | ||
using Content.Shared.DeltaV.Abilities.Borgs; | ||
using Content.Shared.Nutrition; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Random; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Server.DeltaV.Abilities.Borgs; | ||
|
||
/// <summary> | ||
/// Gives things with a <see cref="RandomizedCandyComponent"/> a random flavor, with corresponding appearance and | ||
/// examine text. | ||
/// </summary> | ||
public sealed partial class RandomizedCandySystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; | ||
[Dependency] private readonly MetaDataSystem _metaData = default!; | ||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!; | ||
|
||
/// <summary> | ||
/// Flavors that are masked by the candy. | ||
/// </summary> | ||
private static readonly string[] MaskedReagents = { "Sugar", "Iron" }; // sugar is obvious and iron is "metallic" :( | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<RandomizedCandyComponent, MapInitEvent>(OnInit); | ||
} | ||
|
||
private void OnInit(EntityUid uid, RandomizedCandyComponent candyComp, MapInitEvent args) | ||
{ | ||
// pick a random flavor | ||
var flavors = _prototypeManager.EnumeratePrototypes<CandyFlavorPrototype>(); | ||
var candyFlavor = _random.Pick(flavors.ToList()); | ||
|
||
// color the candy :3 | ||
_appearance.SetData(uid, RandomizedCandyVisuals.Color, candyFlavor.Color); | ||
|
||
// flavor the candy! yummy | ||
var flavorProfile = EnsureComp<FlavorProfileComponent>(uid); | ||
flavorProfile.Flavors.Clear(); // it shouldn't be flavored but clear it anyway | ||
foreach (var flavorId in candyFlavor.Flavors) | ||
{ | ||
flavorProfile.Flavors.Add(flavorId); | ||
} | ||
flavorProfile.IgnoreReagents.UnionWith(MaskedReagents); // otherwise the nom text gets too long | ||
|
||
// update the candy's metadata with fluff | ||
var meta = MetaData(uid); | ||
if (!string.IsNullOrEmpty(candyFlavor.Name)) | ||
_metaData.SetEntityName(uid, $"{candyFlavor.Name} {meta.EntityName}", meta); | ||
_metaData.SetEntityDescription(uid, $"{meta.EntityDescription} {GetExamineFluff(candyFlavor.Flavors)}"); | ||
Dirty(uid, meta); | ||
} | ||
|
||
// this technically duplicates code from FlavorProfileSystem but what we would need to call | ||
// is upstream code in a private method with fixed loc strings and unnecessary sorting, so i don't want to touch it | ||
private string GetExamineFluff(HashSet<ProtoId<FlavorPrototype>> flavorIds) | ||
{ | ||
var flavors = new List<string>(); | ||
foreach (var flavorId in flavorIds) | ||
{ | ||
if (_prototypeManager.TryIndex(flavorId, out var flavor) && | ||
Loc.TryGetString(flavor.FlavorDescription, out var flavorText)) | ||
{ | ||
flavors.Add(flavorText); | ||
} | ||
} | ||
|
||
return flavors.Count switch | ||
{ | ||
> 1 => Loc.GetString("candy-flavor-profile-multiple", | ||
("lastFlavor", flavors.Pop()), | ||
("flavors", string.Join(", ", flavors)) | ||
), | ||
1 => Loc.GetString("candy-flavor-profile", ("flavor", flavors.Single())), | ||
_ => Loc.GetString("candy-flavor-profile-unknown") | ||
}; | ||
} | ||
} |
18 changes: 16 additions & 2 deletions
18
Content.Server/Nyanotrasen/Abilities/Borgs/FabricateCandyComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
using Robust.Shared.Audio; | ||
|
||
namespace Content.Server.Abilities.Borgs; | ||
|
||
[RegisterComponent] | ||
public sealed partial class FabricateCandyComponent : Component | ||
{ | ||
[DataField("lollipopAction")] | ||
[DataField] | ||
public EntityUid? LollipopAction; | ||
|
||
[DataField("gumballAction")] | ||
[DataField] | ||
public EntityUid? GumballAction; | ||
|
||
/// <summary> | ||
/// The sound played when fabricating candy. | ||
/// </summary> | ||
[DataField] | ||
public SoundSpecifier FabricationSound = new SoundPathSpecifier("/Audio/Machines/machine_vend.ogg") | ||
{ | ||
Params = new AudioParams | ||
{ | ||
Volume = -2f | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
Content.Shared/DeltaV/Abilities/Borgs/RandomizedCandyComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared.DeltaV.Abilities.Borgs; | ||
|
||
/// <summary> | ||
/// Marks this entity as being candy with a random flavor and color. | ||
/// </summary> | ||
[RegisterComponent, NetworkedComponent] | ||
public sealed partial class RandomizedCandyComponent : Component | ||
{ | ||
} | ||
|
||
[Serializable, NetSerializable] | ||
public enum RandomizedCandyVisuals : byte | ||
{ | ||
Color | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.