using Content.Server._DV.Objectives.Components; using Content.Server.Objectives.Systems; using Content.Server.Store.Systems; using Content.Shared._DV.Objectives.Systems; using Content.Shared._DV.Reputation; using Content.Shared.FixedPoint; namespace Content.Server._DV.Objectives.Systems; /// /// Handles reputation + TC gains for . /// public sealed class ContractObjectiveSystem : SharedContractObjectiveSystem { [Dependency] private readonly CodeConditionSystem _codeCondition = default!; [Dependency] private readonly ReputationSystem _reputation = default!; [Dependency] private readonly StoreSystem _store = default!; private Dictionary _currency = new(); public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnTaken); SubscribeLocalEvent(OnCompleted); } private void OnTaken(Entity ent, ref ContractTakenEvent args) { ent.Comp.Pda = args.Pda; if (ent.Comp.Prepaid) Pay(ent, args.Pda); } private void OnCompleted(Entity ent, ref ContractCompletedEvent args) { _reputation.GiveReputation(args.Pda, ent.Comp.Reputation); if (!ent.Comp.Prepaid) Pay(ent, args.Pda); } private void Pay(Entity ent, EntityUid pda) { _currency.Clear(); _currency[ent.Comp.Currency] = ent.Comp.Payment; _store.TryAddCurrency(_currency, pda); } /// /// Fail all active incomplete contracts with a given component, based on a predicate. /// public void FailContracts(Predicate> pred) where T: Component { var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var comp, out var contract)) { if (_codeCondition.IsCompleted(uid) || !pred((uid, comp))) continue; if (contract.Pda is {} pda && TryComp(pda, out var contracts)) _reputation.TryFailContract((pda, contracts), uid); } } /// /// Look up an objective's stored pda and try to fail it. /// public bool TryFailContract(Entity objective) { return Resolve(objective, ref objective.Comp) && objective.Comp.Pda is {} pda && TryComp(pda, out var comp) && _reputation.TryFailContract((pda, comp), objective); } public override string ContractName(EntityUid objective) { var title = base.ContractName(objective); if (!TryComp(objective, out var contract)) return title; return $"{title} - {contract.Reputation} REP + {contract.Payment} TC"; } }