2024-07-24 13:28:27 +03:00
|
|
|
using Content.Server._CP14.Objectives.Components;
|
2025-05-29 00:22:47 +03:00
|
|
|
using Content.Server.Cargo.Systems;
|
2024-10-26 18:18:30 +03:00
|
|
|
using Content.Server.Objectives.Components;
|
2024-07-24 13:28:27 +03:00
|
|
|
using Content.Shared._CP14.Currency;
|
2024-10-26 18:18:30 +03:00
|
|
|
using Content.Shared.Interaction;
|
2024-07-24 13:28:27 +03:00
|
|
|
using Content.Shared.Mind;
|
|
|
|
|
using Content.Shared.Mind.Components;
|
|
|
|
|
using Content.Shared.Movement.Pulling.Components;
|
|
|
|
|
using Content.Shared.Objectives.Components;
|
|
|
|
|
using Content.Shared.Objectives.Systems;
|
|
|
|
|
using Robust.Shared.Containers;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server._CP14.Objectives.Systems;
|
|
|
|
|
|
|
|
|
|
public sealed class CP14CurrencyCollectConditionSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
|
|
|
|
[Dependency] private readonly SharedObjectivesSystem _objectives = default!;
|
2024-10-15 15:22:06 +03:00
|
|
|
[Dependency] private readonly CP14SharedCurrencySystem _currency = default!;
|
2025-05-29 00:22:47 +03:00
|
|
|
[Dependency] private readonly PricingSystem _price = default!;
|
2024-10-26 18:18:30 +03:00
|
|
|
|
2024-07-24 13:28:27 +03:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2024-10-26 18:18:30 +03:00
|
|
|
SubscribeLocalEvent<CP14CurrencyCollectConditionComponent, ObjectiveAfterAssignEvent>(OnCollectAfterAssign);
|
|
|
|
|
SubscribeLocalEvent<CP14CurrencyCollectConditionComponent, ObjectiveGetProgressEvent>(OnCollectGetProgress);
|
2024-07-24 13:28:27 +03:00
|
|
|
}
|
|
|
|
|
|
2024-10-26 18:18:30 +03:00
|
|
|
private void OnCollectAfterAssign(Entity<CP14CurrencyCollectConditionComponent> condition, ref ObjectiveAfterAssignEvent args)
|
2024-07-24 13:28:27 +03:00
|
|
|
{
|
2024-11-04 13:41:09 +03:00
|
|
|
_metaData.SetEntityName(condition.Owner, Loc.GetString(condition.Comp.ObjectiveText, ("coins", _currency.GetCurrencyPrettyString(condition.Comp.Currency))), args.Meta);
|
2024-10-26 18:18:30 +03:00
|
|
|
_metaData.SetEntityDescription(condition.Owner, Loc.GetString(condition.Comp.ObjectiveDescription, ("coins", _currency.GetCurrencyPrettyString(condition.Comp.Currency))), args.Meta);
|
|
|
|
|
_objectives.SetIcon(condition.Owner, condition.Comp.ObjectiveSprite);
|
2024-07-24 13:28:27 +03:00
|
|
|
}
|
|
|
|
|
|
2024-10-26 18:18:30 +03:00
|
|
|
private void OnCollectGetProgress(Entity<CP14CurrencyCollectConditionComponent> condition, ref ObjectiveGetProgressEvent args)
|
2024-07-24 13:28:27 +03:00
|
|
|
{
|
|
|
|
|
args.Progress = GetProgress(args.Mind, condition);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-26 18:18:30 +03:00
|
|
|
|
2024-07-24 13:28:27 +03:00
|
|
|
private float GetProgress(MindComponent mind, CP14CurrencyCollectConditionComponent condition)
|
|
|
|
|
{
|
2025-05-29 00:22:47 +03:00
|
|
|
double count = 0;
|
2024-07-24 13:28:27 +03:00
|
|
|
|
2025-03-06 12:01:43 +03:00
|
|
|
if (mind.OwnedEntity is null)
|
|
|
|
|
return 0;
|
2024-10-26 18:18:30 +03:00
|
|
|
|
2025-05-29 00:22:47 +03:00
|
|
|
count += _price.GetPrice(mind.OwnedEntity.Value);
|
|
|
|
|
count -= _price.GetPrice(mind.OwnedEntity.Value, false); //We don't want to count the price of the entity itself.
|
2024-10-26 18:18:30 +03:00
|
|
|
|
|
|
|
|
var result = count / (float)condition.Currency;
|
2024-07-24 13:28:27 +03:00
|
|
|
result = Math.Clamp(result, 0, 1);
|
2025-05-29 00:22:47 +03:00
|
|
|
return (float)result;
|
2024-07-24 13:28:27 +03:00
|
|
|
}
|
|
|
|
|
}
|