Move replacement chance from ReplacementAccentComponent to ReplacementAccentPrototype (#28049)

Move replacement chance to ReplacementAccentPrototype
This commit is contained in:
lzk
2024-05-17 18:33:22 +02:00
committed by GitHub
parent de7e1b33dd
commit b08f79fb38
4 changed files with 12 additions and 11 deletions

View File

@@ -22,6 +22,12 @@ namespace Content.Server.Speech.Components
/// </summary> /// </summary>
[DataField("wordReplacements")] [DataField("wordReplacements")]
public Dictionary<string, string>? WordReplacements; public Dictionary<string, string>? WordReplacements;
/// <summary>
/// Allows you to substitute words, not always, but with some chance
/// </summary>
[DataField]
public float ReplacementChance = 1f;
} }
/// <summary> /// <summary>
@@ -33,10 +39,5 @@ namespace Content.Server.Speech.Components
[DataField("accent", customTypeSerializer: typeof(PrototypeIdSerializer<ReplacementAccentPrototype>), required: true)] [DataField("accent", customTypeSerializer: typeof(PrototypeIdSerializer<ReplacementAccentPrototype>), required: true)]
public string Accent = default!; public string Accent = default!;
/// <summary>
/// Allows you to substitute words, not always, but with some chance
/// </summary>
[DataField]
public float ReplacementChance = 1f;
} }
} }

View File

@@ -24,9 +24,6 @@ namespace Content.Server.Speech.EntitySystems
private void OnAccent(EntityUid uid, ReplacementAccentComponent component, AccentGetEvent args) private void OnAccent(EntityUid uid, ReplacementAccentComponent component, AccentGetEvent args)
{ {
if (!_random.Prob(component.ReplacementChance))
return;
args.Message = ApplyReplacements(args.Message, component.Accent); args.Message = ApplyReplacements(args.Message, component.Accent);
} }
@@ -39,6 +36,9 @@ namespace Content.Server.Speech.EntitySystems
if (!_proto.TryIndex<ReplacementAccentPrototype>(accent, out var prototype)) if (!_proto.TryIndex<ReplacementAccentPrototype>(accent, out var prototype))
return message; return message;
if (!_random.Prob(prototype.ReplacementChance))
return message;
// Prioritize fully replacing if that exists-- // Prioritize fully replacing if that exists--
// ideally both aren't used at the same time (but we don't have a way to enforce that in serialization yet) // ideally both aren't used at the same time (but we don't have a way to enforce that in serialization yet)
if (prototype.FullReplacements != null) if (prototype.FullReplacements != null)

View File

@@ -428,6 +428,7 @@
- type: accent - type: accent
id: liar id: liar
replacementChance: 0.15
wordReplacements: wordReplacements:
liar-word-1: liar-word-replacement-1 liar-word-1: liar-word-replacement-1
liar-word-2: liar-word-replacement-2 liar-word-2: liar-word-replacement-2

View File

@@ -1,4 +1,4 @@
- type: trait - type: trait
id: PirateAccent id: PirateAccent
name: trait-pirate-accent-name name: trait-pirate-accent-name
description: trait-pirate-accent-desc description: trait-pirate-accent-desc
@@ -30,5 +30,4 @@
description: trait-liar-desc description: trait-liar-desc
components: components:
- type: ReplacementAccent - type: ReplacementAccent
replacementChance: 0.15
accent: liar accent: liar