dragon refactor, objectives and use GenericAntag (#20201)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-09-30 21:18:01 +01:00
committed by GitHub
parent 007db2599b
commit 94a11f28ca
18 changed files with 455 additions and 252 deletions

View File

@@ -0,0 +1,56 @@
using Content.Server.Objectives.Components;
using Content.Server.Roles;
using Content.Shared.Objectives.Components;
namespace Content.Server.Objectives.Systems;
public sealed class CarpRiftsConditionSystem : EntitySystem
{
[Dependency] private readonly NumberObjectiveSystem _number = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CarpRiftsConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
}
private void OnGetProgress(EntityUid uid, CarpRiftsConditionComponent comp, ref ObjectiveGetProgressEvent args)
{
args.Progress = GetProgress(comp, _number.GetTarget(uid));
}
private float GetProgress(CarpRiftsConditionComponent comp, int target)
{
// prevent divide-by-zero
if (target == 0)
return 1f;
if (comp.RiftsCharged >= target)
return 1f;
return (float) comp.RiftsCharged / (float) target;
}
/// <summary>
/// Increments RiftsCharged, called after a rift fully charges.
/// </summary>
public void RiftCharged(EntityUid uid, CarpRiftsConditionComponent? comp = null)
{
if (!Resolve(uid, ref comp))
return;
comp.RiftsCharged++;
}
/// <summary>
/// Resets RiftsCharged to 0, called after rifts get destroyed.
/// </summary>
public void ResetRifts(EntityUid uid, CarpRiftsConditionComponent? comp = null)
{
if (!Resolve(uid, ref comp))
return;
comp.RiftsCharged = 0;
}
}