decouple objectives round end text from traitor (#19687)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -51,7 +51,9 @@ public sealed class TraitorRuleSystem : GameRuleSystem<TraitorRuleComponent>
|
||||
SubscribeLocalEvent<RoundStartAttemptEvent>(OnStartAttempt);
|
||||
SubscribeLocalEvent<RulePlayerJobsAssignedEvent>(OnPlayersSpawned);
|
||||
SubscribeLocalEvent<PlayerSpawnCompleteEvent>(HandleLatejoin);
|
||||
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEndText);
|
||||
|
||||
SubscribeLocalEvent<TraitorRuleComponent, ObjectivesTextGetInfoEvent>(OnObjectivesTextGetInfo);
|
||||
SubscribeLocalEvent<TraitorRuleComponent, ObjectivesTextPrependEvent>(OnObjectivesTextPrepend);
|
||||
}
|
||||
|
||||
protected override void ActiveTick(EntityUid uid, TraitorRuleComponent component, GameRuleComponent gameRule, float frameTime)
|
||||
@@ -367,90 +369,15 @@ public sealed class TraitorRuleSystem : GameRuleSystem<TraitorRuleComponent>
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRoundEndText(RoundEndTextAppendEvent ev)
|
||||
private void OnObjectivesTextGetInfo(EntityUid uid, TraitorRuleComponent comp, ref ObjectivesTextGetInfoEvent args)
|
||||
{
|
||||
var query = EntityQueryEnumerator<TraitorRuleComponent, GameRuleComponent>();
|
||||
while (query.MoveNext(out var uid, out var traitor, out var gameRule))
|
||||
{
|
||||
if (!GameTicker.IsGameRuleAdded(uid, gameRule))
|
||||
continue;
|
||||
args.Minds = comp.TraitorMinds;
|
||||
args.AgentName = Loc.GetString("traitor-round-end-agent-name");
|
||||
}
|
||||
|
||||
var result = Loc.GetString("traitor-round-end-result", ("traitorCount", traitor.TraitorMinds.Count));
|
||||
|
||||
result += "\n" + Loc.GetString("traitor-round-end-codewords", ("codewords", string.Join(", ", traitor.Codewords))) +
|
||||
"\n";
|
||||
|
||||
foreach (var mindId in traitor.TraitorMinds)
|
||||
{
|
||||
if (!TryComp(mindId, out MindComponent? mind))
|
||||
continue;
|
||||
|
||||
var name = mind.CharacterName;
|
||||
_mindSystem.TryGetSession(mindId, out var session);
|
||||
var username = session?.Name;
|
||||
|
||||
var objectives = mind.AllObjectives.ToArray();
|
||||
if (objectives.Length == 0)
|
||||
{
|
||||
if (username != null)
|
||||
{
|
||||
if (name == null)
|
||||
result += "\n" + Loc.GetString("traitor-user-was-a-traitor", ("user", username));
|
||||
else
|
||||
result += "\n" + Loc.GetString("traitor-user-was-a-traitor-named", ("user", username),
|
||||
("name", name));
|
||||
}
|
||||
else if (name != null)
|
||||
result += "\n" + Loc.GetString("traitor-was-a-traitor-named", ("name", name));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (username != null)
|
||||
{
|
||||
if (name == null)
|
||||
result += "\n" + Loc.GetString("traitor-user-was-a-traitor-with-objectives",
|
||||
("user", username));
|
||||
else
|
||||
result += "\n" + Loc.GetString("traitor-user-was-a-traitor-with-objectives-named",
|
||||
("user", username), ("name", name));
|
||||
}
|
||||
else if (name != null)
|
||||
result += "\n" + Loc.GetString("traitor-was-a-traitor-with-objectives-named", ("name", name));
|
||||
|
||||
foreach (var objectiveGroup in objectives.GroupBy(o => o.Prototype.Issuer))
|
||||
{
|
||||
result += "\n" + Loc.GetString($"preset-traitor-objective-issuer-{objectiveGroup.Key}");
|
||||
|
||||
foreach (var objective in objectiveGroup)
|
||||
{
|
||||
foreach (var condition in objective.Conditions)
|
||||
{
|
||||
var progress = condition.Progress;
|
||||
if (progress > 0.99f)
|
||||
{
|
||||
result += "\n- " + Loc.GetString(
|
||||
"traitor-objective-condition-success",
|
||||
("condition", condition.Title),
|
||||
("markupColor", "green")
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
result += "\n- " + Loc.GetString(
|
||||
"traitor-objective-condition-fail",
|
||||
("condition", condition.Title),
|
||||
("progress", (int) (progress * 100)),
|
||||
("markupColor", "red")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ev.AddLine(result);
|
||||
}
|
||||
private void OnObjectivesTextPrepend(EntityUid uid, TraitorRuleComponent comp, ref ObjectivesTextPrependEvent args)
|
||||
{
|
||||
args.Text += "\n" + Loc.GetString("traitor-round-end-codewords", ("codewords", string.Join(", ", comp.Codewords)));
|
||||
}
|
||||
|
||||
public List<(EntityUid Id, MindComponent Mind)> GetOtherTraitorMindsAliveAndConnected(MindComponent ourMind)
|
||||
|
||||
Reference in New Issue
Block a user