From 7349d1bd6eed47ff0d5ae94f849218e172703dcd Mon Sep 17 00:00:00 2001 From: SkaldetSkaeg Date: Sat, 7 Dec 2024 18:01:50 +0700 Subject: [PATCH] forced gamerule objectives refresh --- .../GameTicking/Rules/CultYoggRuleSystem.cs | 11 ++++- .../Systems/CultYoggSummonConditionSystem.cs | 47 ++++++++++++++----- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/Content.Server/SS220/GameTicking/Rules/CultYoggRuleSystem.cs b/Content.Server/SS220/GameTicking/Rules/CultYoggRuleSystem.cs index 445a38e67c0fa1..b963fad11d9e73 100644 --- a/Content.Server/SS220/GameTicking/Rules/CultYoggRuleSystem.cs +++ b/Content.Server/SS220/GameTicking/Rules/CultYoggRuleSystem.cs @@ -31,6 +31,8 @@ using Robust.Shared.Random; using Content.Shared.Database; using Content.Server.Administration.Logs; +using Content.Server.SS220.Objectives.Systems; +using Content.Server.SS220.Objectives.Components; namespace Content.Server.SS220.GameTicking.Rules; @@ -49,7 +51,7 @@ public sealed class CultYoggRuleSystem : GameRuleSystem [Dependency] private readonly RoundEndSystem _roundEnd = default!; [Dependency] private readonly SharedRoleSystem _role = default!; - private List> _sacraficialTiers = new(); + private List> _sacraficialTiers = []; public TimeSpan DefaultShuttleArriving { get; set; } = TimeSpan.FromSeconds(85); public override void Initialize() @@ -84,6 +86,13 @@ protected override void Started(EntityUid uid, CultYoggRuleComponent component, GenerateJobsList(component); //_adminLogger.Add(LogType.EventRan, LogImpact.High, $"CultYogg game rule has started picking up sacraficials"); SetSacraficials(component); + + var ev = new CultYoggReinitObjEvent(); + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var ent, out var _)) + { + RaiseLocalEvent(ent, ref ev); //Reinitialise objective if gamerule was forced + } } //Filling list of jobs fot better range diff --git a/Content.Server/SS220/Objectives/Systems/CultYoggSummonConditionSystem.cs b/Content.Server/SS220/Objectives/Systems/CultYoggSummonConditionSystem.cs index cf253544a273cb..56e0df83113f3b 100644 --- a/Content.Server/SS220/Objectives/Systems/CultYoggSummonConditionSystem.cs +++ b/Content.Server/SS220/Objectives/Systems/CultYoggSummonConditionSystem.cs @@ -7,6 +7,7 @@ using Content.Server.SS220.GameTicking.Rules; using Content.Shared.SS220.CultYogg.Sacraficials; using Content.Server.SS220.Objectives.Components; +using Robust.Shared.Serialization; namespace Content.Server.SS220.Objectives.Systems; @@ -27,20 +28,47 @@ public override void Initialize() SubscribeLocalEvent(OnAfterAssign); + SubscribeLocalEvent(OnReInit); + SubscribeLocalEvent(OnGetProgress); } //check if gamerule was rewritten private void OnInit(Entity ent, ref ComponentInit args) { + TaskNumberUpdate(ent); + } + + private void OnAfterAssign(Entity ent, ref ObjectiveAfterAssignEvent args) + { + SacraficialsUpdate(ent); + } + private void OnReInit(Entity ent, ref CultYoggReinitObjEvent args) + { + TaskNumberUpdate(ent); + SacraficialsUpdate(ent); + } + private void OnGetProgress(Entity ent, ref ObjectiveGetProgressEvent args) + { + args.Progress = 0; + _cultRule.GetCultGameRule(out var ruleComp); if (ruleComp is null) return; - ent.Comp.reqSacrAmount = ruleComp.ReqAmountOfSacrifices; + args.Progress = ruleComp.AmountOfSacrifices / ent.Comp.reqSacrAmount; } - private void OnAfterAssign(Entity ent, ref ObjectiveAfterAssignEvent args) + private void TaskNumberUpdate(Entity ent) + { + _cultRule.GetCultGameRule(out var ruleComp); + + if (ruleComp is null) + return; + + ent.Comp.reqSacrAmount = ruleComp.ReqAmountOfSacrifices; + } + private void SacraficialsUpdate(Entity ent) { var title = new StringBuilder(); title.AppendLine(Loc.GetString("objective-cult-yogg-sacrafice-start")); @@ -59,15 +87,10 @@ private void OnAfterAssign(Entity ent, ref Obj title.AppendLine(Loc.GetString("objective-condition-cult-yogg-sacrafice-person", ("targetName", targetName), ("job", jobName))); } - _metaData.SetEntityName(ent, title.ToString(), args.Meta); - } - private void OnGetProgress(Entity ent, ref ObjectiveGetProgressEvent args) - { - _cultRule.GetCultGameRule(out var ruleComp); - - if (ruleComp is null) - return; - - args.Progress = ruleComp.AmountOfSacrifices / ent.Comp.reqSacrAmount; + _metaData.SetEntityName(ent, title.ToString()); } } +[ByRefEvent, Serializable] +public sealed class CultYoggReinitObjEvent : EntityEventArgs +{ +}