mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
# Description This improves the random barks by: - Fully moving the random barks to localization files, with the ability to re-use existing types - Adding many new (english) random bark types - Making the random bark system add a random punctuation mark at the end of a random bark - Adjusting some existing random bark configs This also reparents MobSecurityDog to MobCorgi and MobArcticFox to MobFox because for some reason delta-v decided to copy the original mobs instead of using inheritance??? Either way, laika and siobhan will now also have random barks, can be carried, etc. <details><summary><h1>Media</h1></summary> <p>     </p> </details> # Changelog 🆑 - add: Animals now have more unique things to say when not controlled by a player. --------- Signed-off-by: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com> Co-authored-by: FoxxoTrystan <45297731+FoxxoTrystan@users.noreply.github.com>
95 lines
3.3 KiB
C#
95 lines
3.3 KiB
C#
using Content.Server.Chat.Systems;
|
|
using Content.Shared.Mind.Components;
|
|
using Robust.Shared.Random;
|
|
using Content.Server.Speech.Components;
|
|
using Content.Shared.Chat;
|
|
|
|
namespace Content.Server.Speech.Systems;
|
|
|
|
public sealed class RandomBarkSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly ChatSystem _chat = default!;
|
|
|
|
private static readonly string[] AddedPunctuation = [".", "...", "!", "..!", "!!"];
|
|
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<RandomBarkComponent, MapInitEvent>(OnInit);
|
|
}
|
|
|
|
|
|
private void OnInit(Entity<RandomBarkComponent> ent, ref MapInitEvent args)
|
|
{
|
|
ent.Comp.BarkAccumulator = _random.NextFloat(ent.Comp.MinTime, ent.Comp.MaxTime) * ent.Comp.BarkMultiplier;
|
|
ent.Comp.BarkLocaleCount ??= GetBarkLocaleCount(ent);
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
var query = EntityQueryEnumerator<RandomBarkComponent>();
|
|
while (query.MoveNext(out var uid, out var barker))
|
|
{
|
|
barker.BarkAccumulator -= frameTime;
|
|
if (barker.BarkAccumulator > 0)
|
|
continue;
|
|
|
|
barker.BarkAccumulator = _random.NextFloat(barker.MinTime, barker.MaxTime) * barker.BarkMultiplier;
|
|
if (TryComp<MindContainerComponent>(uid, out var actComp) && actComp.HasMind
|
|
|| GetNextBark((uid, barker)) is not { } bark)
|
|
continue;
|
|
|
|
_chat.TrySendInGameICMessage(uid, bark, InGameICChatType.Speak, barker.ChatLog ? ChatTransmitRange.Normal : ChatTransmitRange.HideChat);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to get the next bark for the given entity. Returns null if it fails.
|
|
/// </summary>
|
|
public string? GetNextBark(Entity<RandomBarkComponent> ent)
|
|
{
|
|
var count = GetBarkLocaleCount(ent);
|
|
if (count <= 0)
|
|
return null;
|
|
|
|
var index = _random.Next(0, count) + 1;
|
|
if (!Loc.TryGetString($"bark-{ent.Comp.BarkType}-{index}", out var bark))
|
|
{
|
|
Log.Error($"Could not find bark with index {index} and type {ent.Comp.BarkType} for entity {ent.Owner}.");
|
|
return null;
|
|
}
|
|
|
|
// If the last char of the string is an alphanumeric one, then add a random punctuation mark
|
|
if (bark.Length > 0 && char.IsLetterOrDigit(bark[^1]))
|
|
bark += _random.Pick(AddedPunctuation);
|
|
|
|
return bark;
|
|
}
|
|
|
|
private int GetBarkLocaleCount(Entity<RandomBarkComponent> ent)
|
|
{
|
|
if (ent.Comp.BarkLocaleCount is { } localeCount)
|
|
return localeCount;
|
|
|
|
// All the error logging should cause certain integration tests to fail should someone setup randombark incorrectly
|
|
if (!Loc.TryGetString($"bark-{ent.Comp.BarkType}-count", out var localeCountStr))
|
|
{
|
|
Log.Error($"Entity {ent.Owner} has a bark type {ent.Comp.BarkType} which does not have a respective bark count locale.");
|
|
return 0;
|
|
}
|
|
|
|
if (!int.TryParse(localeCountStr, out localeCount) || localeCount < 0)
|
|
{
|
|
Log.Error($"Entity {ent.Owner} has a bark type {ent.Comp.BarkType} whose respective bark count locale is not a valid number.");
|
|
return 0;
|
|
}
|
|
|
|
return localeCount;
|
|
}
|
|
}
|