Add a system for modifying entity names without causing conflicts (#27863)

This commit is contained in:
Tayrtahn
2024-06-16 15:38:53 -04:00
committed by GitHub
parent ee2769ed9f
commit 89a9f07c3a
30 changed files with 326 additions and 123 deletions

View File

@@ -14,8 +14,8 @@ using Content.Server.Emoting.Systems;
using Content.Server.Speech.EntitySystems;
using Content.Shared.Cluwne;
using Content.Shared.Interaction.Components;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Content.Shared.NameModifier.EntitySystems;
namespace Content.Server.Cluwne;
@@ -30,6 +30,7 @@ public sealed class CluwneSystem : EntitySystem
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly AutoEmoteSystem _autoEmote = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly NameModifierSystem _nameMod = default!;
public override void Initialize()
{
@@ -39,6 +40,7 @@ public sealed class CluwneSystem : EntitySystem
SubscribeLocalEvent<CluwneComponent, MobStateChangedEvent>(OnMobState);
SubscribeLocalEvent<CluwneComponent, EmoteEvent>(OnEmote, before:
new[] { typeof(VocalSystem), typeof(BodyEmotesSystem) });
SubscribeLocalEvent<CluwneComponent, RefreshNameModifiersEvent>(OnRefreshNameModifiers);
}
/// <summary>
@@ -47,19 +49,19 @@ public sealed class CluwneSystem : EntitySystem
private void OnMobState(EntityUid uid, CluwneComponent component, MobStateChangedEvent args)
{
if (args.NewMobState == MobState.Dead)
{
{
RemComp<CluwneComponent>(uid);
RemComp<ClumsyComponent>(uid);
RemComp<AutoEmoteComponent>(uid);
var damageSpec = new DamageSpecifier(_prototypeManager.Index<DamageGroupPrototype>("Genetic"), 300);
_damageableSystem.TryChangeDamage(uid, damageSpec);
}
}
}
public EmoteSoundsPrototype? EmoteSounds;
/// <summary>
/// OnStartup gives the cluwne outfit, ensures clumsy, gives name prefix and makes sure emote sounds are laugh.
/// OnStartup gives the cluwne outfit, ensures clumsy, and makes sure emote sounds are laugh.
/// </summary>
private void OnComponentStartup(EntityUid uid, CluwneComponent component, ComponentStartup args)
{
@@ -67,9 +69,6 @@ public sealed class CluwneSystem : EntitySystem
return;
_prototypeManager.TryIndex(component.EmoteSoundsId, out EmoteSounds);
var meta = MetaData(uid);
var name = meta.EntityName;
EnsureComp<AutoEmoteComponent>(uid);
_autoEmote.AddEmote(uid, "CluwneGiggle");
EnsureComp<ClumsyComponent>(uid);
@@ -77,7 +76,7 @@ public sealed class CluwneSystem : EntitySystem
_popupSystem.PopupEntity(Loc.GetString("cluwne-transform", ("target", uid)), uid, PopupType.LargeCaution);
_audio.PlayPvs(component.SpawnSound, uid);
_metaData.SetEntityName(uid, Loc.GetString("cluwne-name-prefix", ("target", name)), meta);
_nameMod.RefreshNameModifiers(uid);
SetOutfitCommand.SetOutfit(uid, "CluwneGear", EntityManager);
}
@@ -104,4 +103,12 @@ public sealed class CluwneSystem : EntitySystem
_chat.TrySendInGameICMessage(uid, "spasms", InGameICChatType.Emote, ChatTransmitRange.Normal);
}
}
/// <summary>
/// Applies "Cluwnified" prefix
/// </summary>
private void OnRefreshNameModifiers(Entity<CluwneComponent> entity, ref RefreshNameModifiersEvent args)
{
args.AddModifier("cluwne-name-prefix");
}
}