Skip to content

Commit

Permalink
forced gamerule objectives refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
SkaldetSkaeg committed Dec 7, 2024
1 parent 665bb04 commit 7349d1b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
11 changes: 10 additions & 1 deletion Content.Server/SS220/GameTicking/Rules/CultYoggRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -49,7 +51,7 @@ public sealed class CultYoggRuleSystem : GameRuleSystem<CultYoggRuleComponent>
[Dependency] private readonly RoundEndSystem _roundEnd = default!;
[Dependency] private readonly SharedRoleSystem _role = default!;

private List<List<String>> _sacraficialTiers = new();
private List<List<string>> _sacraficialTiers = [];
public TimeSpan DefaultShuttleArriving { get; set; } = TimeSpan.FromSeconds(85);

public override void Initialize()
Expand Down Expand Up @@ -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<CultYoggSummonConditionComponent>();
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,20 +28,47 @@ public override void Initialize()

SubscribeLocalEvent<CultYoggSummonConditionComponent, ObjectiveAfterAssignEvent>(OnAfterAssign);

SubscribeLocalEvent<CultYoggSummonConditionComponent, CultYoggReinitObjEvent>(OnReInit);

SubscribeLocalEvent<CultYoggSummonConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
}
//check if gamerule was rewritten
private void OnInit(Entity<CultYoggSummonConditionComponent> ent, ref ComponentInit args)
{
TaskNumberUpdate(ent);
}

private void OnAfterAssign(Entity<CultYoggSummonConditionComponent> ent, ref ObjectiveAfterAssignEvent args)
{
SacraficialsUpdate(ent);
}
private void OnReInit(Entity<CultYoggSummonConditionComponent> ent, ref CultYoggReinitObjEvent args)
{
TaskNumberUpdate(ent);
SacraficialsUpdate(ent);
}
private void OnGetProgress(Entity<CultYoggSummonConditionComponent> 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<CultYoggSummonConditionComponent> ent, ref ObjectiveAfterAssignEvent args)
private void TaskNumberUpdate(Entity<CultYoggSummonConditionComponent> ent)
{
_cultRule.GetCultGameRule(out var ruleComp);

if (ruleComp is null)
return;

ent.Comp.reqSacrAmount = ruleComp.ReqAmountOfSacrifices;
}
private void SacraficialsUpdate(Entity<CultYoggSummonConditionComponent> ent)
{
var title = new StringBuilder();
title.AppendLine(Loc.GetString("objective-cult-yogg-sacrafice-start"));
Expand All @@ -59,15 +87,10 @@ private void OnAfterAssign(Entity<CultYoggSummonConditionComponent> 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<CultYoggSummonConditionComponent> 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
{
}

0 comments on commit 7349d1b

Please sign in to comment.