Skip to content

Commit

Permalink
weighted announcers
Browse files Browse the repository at this point in the history
  • Loading branch information
DEATHB4DEFEAT committed Jul 9, 2024
1 parent 14166e4 commit 08fb5b3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
16 changes: 11 additions & 5 deletions Content.Server/Announcements/Systems/AnnouncerSystem.Announcer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
using Content.Shared.GameTicking;
using Content.Shared.Announcements.Prototypes;
using Content.Shared.CCVar;
using Robust.Shared.Random;
using Content.Shared.Random;
using Content.Shared.Random.Helpers;
using Robust.Shared.Utility;

namespace Content.Server.Announcements.Systems;
Expand All @@ -25,9 +26,14 @@ private void OnRoundRestarting(RoundRestartCleanupEvent ev)
/// <remarks>Probably not very useful for any other system</remarks>
public AnnouncerPrototype PickAnnouncer()
{
return _random.Pick(_proto.EnumeratePrototypes<AnnouncerPrototype>()
.Where(x => !_config.GetCVar(CCVars.AnnouncerBlacklist).Contains(x.ID))
.ToArray());
var list = _proto.Index<WeightedRandomPrototype>(_config.GetCVar(CCVars.AnnouncerList));
var modWeights = list.Weights.Where(a => !_config.GetCVar(CCVars.AnnouncerBlacklist).Contains(a.Key));

list = new WeightedRandomPrototype();
foreach (var (key, value) in modWeights)
list.Weights.Add(key, value);

return _proto.Index<AnnouncerPrototype>(list.Pick());
}


Expand All @@ -38,7 +44,7 @@ public AnnouncerPrototype PickAnnouncer()
public void SetAnnouncer(string announcerId)
{
if (!_proto.TryIndex<AnnouncerPrototype>(announcerId, out var announcer))
DebugTools.Assert("Set announcer does not exist, attempting to use previously set one.");
DebugTools.Assert($"Set announcer {announcerId} does not exist, attempting to use previously set one.");
else
Announcer = announcer;
}
Expand Down
2 changes: 0 additions & 2 deletions Content.Server/Announcements/Systems/AnnouncerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
using Content.Shared.CCVar;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;

namespace Content.Server.Announcements.Systems;

public sealed partial class AnnouncerSystem : SharedAnnouncerSystem
{
[Dependency] private readonly IConfigurationManager _config = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly ChatSystem _chat = default!;

Expand Down
6 changes: 6 additions & 0 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,12 @@ public static readonly CVarDef<bool>
* Announcers
*/

/// <summary>
/// Weighted list of announcers to choose from
/// </summary>
public static readonly CVarDef<string> AnnouncerList =
CVarDef.Create("announcer.list", "RandomAnnouncers", CVar.SERVERONLY | CVar.REPLICATED);

/// <summary>
/// Optionally force set an announcer
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions Resources/Prototypes/Announcers/!randomAnnouncers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- type: weightedRandom
id: RandomAnnouncers
weights:
Intern: 0.15
MedBot: 0.5
Michael: 0.9
NEIL: 1
VoxFem: 0.55

0 comments on commit 08fb5b3

Please sign in to comment.