antag objective issuing refactor (#28216)
* add AntagObjectives from GenericAntag * add AntagRandomObjectives that traitor and thief can use * make ObjectivesSystem use initial character name which AntagSelection passes * make thief and traitor use AntagRandomObjectives * remove now unused locale * make sleeper agents rule use baseTraitorRule * restore dragon rule oop * bandaid for genericantag * real * typo --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -36,14 +36,14 @@ public sealed class ObjectivesSystem : SharedObjectivesSystem
|
||||
private void OnRoundEndText(RoundEndTextAppendEvent ev)
|
||||
{
|
||||
// go through each gamerule getting data for the roundend summary.
|
||||
var summaries = new Dictionary<string, Dictionary<string, List<EntityUid>>>();
|
||||
var summaries = new Dictionary<string, Dictionary<string, List<(EntityUid, string)>>>();
|
||||
var query = EntityQueryEnumerator<GameRuleComponent>();
|
||||
while (query.MoveNext(out var uid, out var gameRule))
|
||||
{
|
||||
if (!_gameTicker.IsGameRuleAdded(uid, gameRule))
|
||||
continue;
|
||||
|
||||
var info = new ObjectivesTextGetInfoEvent(new List<EntityUid>(), string.Empty);
|
||||
var info = new ObjectivesTextGetInfoEvent(new List<(EntityUid, string)>(), string.Empty);
|
||||
RaiseLocalEvent(uid, ref info);
|
||||
if (info.Minds.Count == 0)
|
||||
continue;
|
||||
@@ -51,7 +51,7 @@ public sealed class ObjectivesSystem : SharedObjectivesSystem
|
||||
// first group the gamerules by their agents, for example 2 different dragons
|
||||
var agent = info.AgentName;
|
||||
if (!summaries.ContainsKey(agent))
|
||||
summaries[agent] = new Dictionary<string, List<EntityUid>>();
|
||||
summaries[agent] = new Dictionary<string, List<(EntityUid, string)>>();
|
||||
|
||||
var prepend = new ObjectivesTextPrependEvent("");
|
||||
RaiseLocalEvent(uid, ref prepend);
|
||||
@@ -79,7 +79,7 @@ public sealed class ObjectivesSystem : SharedObjectivesSystem
|
||||
foreach (var (_, minds) in summary)
|
||||
{
|
||||
total += minds.Count;
|
||||
totalInCustody += minds.Where(m => IsInCustody(m)).Count();
|
||||
totalInCustody += minds.Where(pair => IsInCustody(pair.Item1)).Count();
|
||||
}
|
||||
|
||||
var result = new StringBuilder();
|
||||
@@ -104,19 +104,16 @@ public sealed class ObjectivesSystem : SharedObjectivesSystem
|
||||
}
|
||||
}
|
||||
|
||||
private void AddSummary(StringBuilder result, string agent, List<EntityUid> minds)
|
||||
private void AddSummary(StringBuilder result, string agent, List<(EntityUid, string)> minds)
|
||||
{
|
||||
var agentSummaries = new List<(string summary, float successRate, int completedObjectives)>();
|
||||
|
||||
foreach (var mindId in minds)
|
||||
foreach (var (mindId, name) in minds)
|
||||
{
|
||||
if (!TryComp(mindId, out MindComponent? mind))
|
||||
continue;
|
||||
|
||||
var title = GetTitle(mindId, mind);
|
||||
if (title == null)
|
||||
if (!TryComp<MindComponent>(mindId, out var mind))
|
||||
continue;
|
||||
|
||||
var title = GetTitle((mindId, mind), name);
|
||||
var custody = IsInCustody(mindId, mind) ? Loc.GetString("objectives-in-custody") : string.Empty;
|
||||
|
||||
var objectives = mind.Objectives;
|
||||
@@ -238,34 +235,18 @@ public sealed class ObjectivesSystem : SharedObjectivesSystem
|
||||
|
||||
/// <summary>
|
||||
/// Get the title for a player's mind used in round end.
|
||||
/// Pass in the original entity name which is shown alongside username.
|
||||
/// </summary>
|
||||
public string? GetTitle(EntityUid mindId, MindComponent? mind = null)
|
||||
public string GetTitle(Entity<MindComponent?> mind, string name)
|
||||
{
|
||||
if (!Resolve(mindId, ref mind))
|
||||
return null;
|
||||
|
||||
var name = mind.CharacterName;
|
||||
var username = (string?) null;
|
||||
|
||||
if (mind.OriginalOwnerUserId != null &&
|
||||
_player.TryGetPlayerData(mind.OriginalOwnerUserId.Value, out var sessionData))
|
||||
if (Resolve(mind, ref mind.Comp) &&
|
||||
mind.Comp.OriginalOwnerUserId != null &&
|
||||
_player.TryGetPlayerData(mind.Comp.OriginalOwnerUserId.Value, out var sessionData))
|
||||
{
|
||||
username = sessionData.UserName;
|
||||
var username = sessionData.UserName;
|
||||
return Loc.GetString("objectives-player-user-named", ("user", username), ("name", name));
|
||||
}
|
||||
|
||||
|
||||
if (username != null)
|
||||
{
|
||||
if (name != null)
|
||||
return Loc.GetString("objectives-player-user-named", ("user", username), ("name", name));
|
||||
|
||||
return Loc.GetString("objectives-player-user", ("user", username));
|
||||
}
|
||||
|
||||
// nothing to identify the player by, just give up
|
||||
if (name == null)
|
||||
return null;
|
||||
|
||||
return Loc.GetString("objectives-player-named", ("name", name));
|
||||
}
|
||||
}
|
||||
@@ -279,7 +260,7 @@ public sealed class ObjectivesSystem : SharedObjectivesSystem
|
||||
/// The objectives system already checks if the game rule is added so you don't need to check that in this event's handler.
|
||||
/// </remarks>
|
||||
[ByRefEvent]
|
||||
public record struct ObjectivesTextGetInfoEvent(List<EntityUid> Minds, string AgentName);
|
||||
public record struct ObjectivesTextGetInfoEvent(List<(EntityUid, string)> Minds, string AgentName);
|
||||
|
||||
/// <summary>
|
||||
/// Raised on the game rule before text for each agent's objectives is added, letting you prepend something.
|
||||
|
||||
Reference in New Issue
Block a user