Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions Content.Client/_Forge/Trade/Controls/NcContractCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,32 @@ private void OnPrimaryActionPressed(BaseButton.ButtonEventArgs args)
return;
}

if (canClaim || canPartialTurnIn)
OnClaim?.Invoke(_data.Id);
if (canClaim)
{
var contractId = _data.Id;
ShowContractConfirmation(
Loc.GetString("nc-store-contract-confirm-claim-title"),
Loc.GetString("nc-store-contract-confirm-claim", ("contract", BuildPrettyTitle(_data))),
Loc.GetString("nc-store-contract-confirm-claim-action"),
Color.FromHex("#243729"),
Color.FromHex("#7DA260"),
PrimaryActionButton,
() => OnClaim?.Invoke(contractId));
return;
}

if (canPartialTurnIn)
{
var contractId = _data.Id;
ShowContractConfirmation(
Loc.GetString("nc-store-contract-confirm-partial-title"),
Loc.GetString("nc-store-contract-confirm-partial", ("contract", BuildPrettyTitle(_data))),
Loc.GetString("nc-store-contract-confirm-partial-action"),
Color.FromHex("#243729"),
Color.FromHex("#7DA260"),
PrimaryActionButton,
() => OnClaim?.Invoke(contractId));
}
}

private void ShowContractConfirmation(
Expand Down
3 changes: 3 additions & 0 deletions Content.Server/_Forge/AutoSalarySystem/AutoSalaryComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ public sealed partial class AutoSalaryComponent : Component
[DataField]
public TimeSpan LastSalaryAt = TimeSpan.Zero;

[DataField]
public TimeSpan NextRetryAt = TimeSpan.Zero;

[DataField]
public string? JobPrototype;
}
90 changes: 71 additions & 19 deletions Content.Server/_Forge/AutoSalarySystem/AutoSalarySystem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Content.Server.Afk;
using Content.Server._NF.Bank;
using Content.Server._NF.CryoSleep;
using Content.Server.Chat.Managers;
using Content.Server.Mind;
using Content.Server.Roles.Jobs;
using Content.Shared._NF.Bank.Components;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Server.Popups;
using Content.Shared.SSDIndicator;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Robust.Server.Player;
using Content.Shared.Roles;
Expand All @@ -15,19 +18,24 @@ namespace Content.Server._Forge.AutoSalarySystem;

public sealed class AutoSalarySystem : EntitySystem
{
private static readonly TimeSpan FailedPaymentRetryDelay = TimeSpan.FromMinutes(1);

[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly JobSystem _jobs = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly MindSystem _mindSystem = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly BankSystem _bank = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IAfkManager _afkManager = default!;
[Dependency] private readonly IChatManager _chat = default!;

public override void Update(float frameTime)
{
CleanupSalariesWithoutBankAccounts();

var query = EntityQueryEnumerator<BankAccountComponent>();
while (query.MoveNext(out var uid, out _))
while (query.MoveNext(out var uid, out var bank))
{
if (!TryGetCurrentJob(uid, out var job)
|| job.Salary <= 0)
Expand All @@ -42,6 +50,7 @@ public override void Update(float frameTime)
{
comp = EnsureComp<AutoSalaryComponent>(uid);
comp.LastSalaryAt = _timing.CurTime;
comp.NextRetryAt = TimeSpan.Zero;
comp.JobPrototype = job.ID;
Dirty(uid, comp);
continue;
Expand All @@ -50,6 +59,7 @@ public override void Update(float frameTime)
if (comp.JobPrototype != job.ID)
{
comp.LastSalaryAt = _timing.CurTime;
comp.NextRetryAt = TimeSpan.Zero;
comp.JobPrototype = job.ID;
Dirty(uid, comp);
continue;
Expand All @@ -58,22 +68,50 @@ public override void Update(float frameTime)
if (comp.LastSalaryAt + job.SalaryInterval > _timing.CurTime)
continue;

if (!ShouldSkipEntity(uid))
TryPaySalary(uid, job.Salary);
if (comp.NextRetryAt > _timing.CurTime)
continue;

if (ShouldSkipEntity(uid))
{
MarkSalaryHandled(uid, comp);
continue;
}

comp.LastSalaryAt = _timing.CurTime;
Dirty(uid, comp);
if (!TryPaySalary(uid, bank, job.Salary))
{
comp.NextRetryAt = _timing.CurTime + FailedPaymentRetryDelay;
Dirty(uid, comp);
continue;
}

MarkSalaryHandled(uid, comp);
}
}

private void CleanupSalariesWithoutBankAccounts()
{
var query = EntityQueryEnumerator<AutoSalaryComponent>();
while (query.MoveNext(out var uid, out _))
{
if (!HasComp<BankAccountComponent>(uid))
RemCompDeferred<AutoSalaryComponent>(uid);
}
}

private bool HasActivePlayer(EntityUid body)
{
if (!_mindSystem.TryGetMind(body, out _, out var mind))
return false;
if (!_playerManager.TryGetSessionByEntity(body, out var session) && session == null)
if (!_playerManager.TryGetSessionByEntity(body, out var session))
return false;
if (session.Status != SessionStatus.InGame)
return false;
if (_afkManager.IsAfk(session))
return false;
if (mind.IsVisitingEntity)
return false;
if (TryComp<SSDIndicatorComponent>(body, out var ssd) && ssd.IsSSD)
return false;
return true;
}

Expand All @@ -91,30 +129,44 @@ private bool IsEntityDead(EntityUid body)
return !TryComp<MobStateComponent>(body, out var mobState) || _mobState.IsDead(body, mobState);
}

private void TryPaySalary(EntityUid body, int salary)
private bool TryPaySalary(EntityUid body, BankAccountComponent bank, int salary)
{
if (_bank.TryBankDeposit(body, salary))
{
_popup.PopupEntity(Loc.GetString("auto-salary-popup", ("salary", salary)), body, body);
}
if (!_bank.TryBankDeposit(body, salary))
return false;

var message = Loc.GetString("auto-salary-popup",
("salary", salary),
("balance", bank.Balance));

if (_playerManager.TryGetSessionByEntity(body, out var session))
_chat.DispatchServerMessage(session, message, suppressLog: true);

return true;
}

private void MarkSalaryHandled(EntityUid body, AutoSalaryComponent comp)
{
comp.LastSalaryAt = _timing.CurTime;
comp.NextRetryAt = TimeSpan.Zero;
Dirty(body, comp);
}

private bool TryGetCurrentJob(EntityUid body, out JobPrototype job)
{
job = default!;
ProtoId<JobPrototype>? jobId = null;

if (_mindSystem.TryGetMind(body, out var mindId, out _)
if (TryComp<PlayerJobComponent>(body, out var playerJob)
&& !string.IsNullOrWhiteSpace(playerJob.JobPrototype))
{
jobId = playerJob.JobPrototype;
}
else if (_mindSystem.TryGetMind(body, out var mindId, out _)
&& _jobs.MindTryGetJobId(mindId, out var currentMindJobId)
&& !string.IsNullOrWhiteSpace(currentMindJobId))
{
jobId = currentMindJobId;
}
else if (TryComp<PlayerJobComponent>(body, out var playerJob)
&& !string.IsNullOrWhiteSpace(playerJob.JobPrototype))
{
jobId = playerJob.JobPrototype;
}

if (jobId is not { } resolvedJobId
|| !_proto.TryIndex(resolvedJobId, out JobPrototype? resolvedJob))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,19 @@ ContractServerData contract
)
{
EnsureObjectiveRuntimeDefaults(contract);
SyncDroneHuntObjectiveProgress(store, contractId, contract);
ScanTrackedDeliveryTransferSources(user, out var userItems, out _, out var crateItems);
RefreshDroneHuntObjectiveProgressFromProofScan(store, contractId, contract, userItems, crateItems);

if (contract.Runtime.Failed)
return ClaimAttemptResult.Fail(ClaimFailureReason.ObjectiveFailed, contract.Runtime.FailureReason);

if (!contract.Completed)
{
return ClaimAttemptResult.Fail(
ClaimFailureReason.ObjectiveNotCompleted,
$"Drone hunt proof progress {contract.Progress}/{contract.Required} for '{contractId}'.");
}

if (!TryValidateDroneHuntProofClaim(store, user, contractId, contract, out var proofFail))
return proofFail;

Expand Down
6 changes: 6 additions & 0 deletions Resources/Locale/en-US/_Forge/trade/trade.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ nc-store-contract-action-pinpointer-tooltip = Issue a new pinpointer for the cur

nc-store-contract-confirm-take-title = Accept Contract
nc-store-contract-confirm-skip-title = Skip Contract
nc-store-contract-confirm-claim-title = Complete Contract
nc-store-contract-confirm-partial-title = Turn In Cargo
nc-store-contract-confirm-take = Accept contract "{ $contract }"?
nc-store-contract-confirm-skip = Skip contract "{ $contract }" and replace it with a new one?
nc-store-contract-confirm-claim = Complete contract "{ $contract }" and receive the reward?
nc-store-contract-confirm-partial = Turn in available cargo for "{ $contract }"?
nc-store-contract-confirm-take-action = Accept
nc-store-contract-confirm-skip-action = Skip
nc-store-contract-confirm-claim-action = Complete
nc-store-contract-confirm-partial-action = Turn in
nc-store-contract-confirm-no = No

nc-store-contract-claim-tooltip-single = Complete this one-time contract and receive the full reward.
Expand Down
2 changes: 1 addition & 1 deletion Resources/Locale/ru-RU/_Forge/auto-salary/component.ftl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
auto-salary-popup = Вам начислена зарплата: { $salary } кредитов
auto-salary-popup = Вам начислена зарплата: { $salary } кредитов. На счете: { $balance } кредитов.
6 changes: 6 additions & 0 deletions Resources/Locale/ru-RU/_Forge/trade/trade.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ nc-store-contract-action-pinpointer-tooltip = Выдать новый пелен

nc-store-contract-confirm-take-title = Взятие контракта
nc-store-contract-confirm-skip-title = Пропуск контракта
nc-store-contract-confirm-claim-title = Завершение контракта
nc-store-contract-confirm-partial-title = Сдача груза
nc-store-contract-confirm-take = Взять контракт «{ $contract }»?
nc-store-contract-confirm-skip = Пропустить контракт «{ $contract }» и заменить его новым?
nc-store-contract-confirm-claim = Завершить контракт «{ $contract }» и получить награду?
nc-store-contract-confirm-partial = Сдать доступный груз для контракта «{ $contract }»?
nc-store-contract-confirm-take-action = Взять
nc-store-contract-confirm-skip-action = Пропустить
nc-store-contract-confirm-claim-action = Завершить
nc-store-contract-confirm-partial-action = Сдать
nc-store-contract-confirm-no = Нет

nc-store-contract-claim-tooltip-single = Завершить разовый контракт и получить полную награду.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
supervisors: job-supervisors-sr
weight: 60 # Frontier
displayWeight: 10 # Frontier
salary: 20000 # Frontier
assignedCompany: Colonial
canBeAntag: false
access:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
startingGear: PrisonGuardGear
icon: "JobIconWarden"
supervisors: job-supervisors-bailiff # Frontier
salary: 20000 # Frontier
canBeAntag: false
access:
- Security
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
supervisors: job-supervisors-sr
weight: 90 # Frontier
displayWeight: 30 # Frontier
salary: 20000 # Frontier
assignedCompany: Colonial
canBeAntag: false
access:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
icon: "JobIconPrisoner"
supervisors: job-supervisors-prisoner
displayWeight: 10 # Frontier
salary: 20000 # Frontier
special:
- !type:AddImplantSpecial
implants: [ TrackingImplant ] # Frontier
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Roles/Jobs/Cargo/cargo_technician.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
startingGear: CargoTechGear
icon: "JobIconCargoTechnician"
supervisors: job-supervisors-hire # Frontier
salary: 20000 # Frontier
accessGroups: # Frontier
- GeneralAccess # Frontier
special:
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Roles/Jobs/Cargo/quartermaster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- !type:OverallPlaytimeRequirement
time: 144000 #40 hrs
weight: 10
salary: 20000 # Frontier
startingGear: QuartermasterGear
icon: "JobIconQuarterMaster"
supervisors: job-supervisors-captain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
icon: "JobIconShaftMiner"
startingGear: SalvageSpecialistGear
supervisors: job-supervisors-hire # Frontier
salary: 20000 # Frontier
accessGroups: # Frontier
- GeneralAccess # Frontier

Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Roles/Jobs/CentComm/cburn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
startingGear: CBURNGear
icon: "JobIconNanotrasen"
supervisors: job-supervisors-centcom
salary: 20000 # Frontier
canBeAntag: false
accessGroups:
- AllAccess
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Roles/Jobs/CentComm/deathsquad.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
startingGear: DeathSquadGear
icon: "JobIconNanotrasen"
supervisors: job-supervisors-centcom
salary: 20000 # Frontier
canBeAntag: false
accessGroups:
- AllAccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
startingGear: ERTLeaderGearEVA
icon: "JobIconNanotrasen"
supervisors: job-supervisors-centcom
salary: 20000 # Frontier
canBeAntag: false
accessGroups:
- AllAccess
Expand Down Expand Up @@ -98,6 +99,7 @@
startingGear: ERTChaplainGear
icon: "JobIconNanotrasen"
supervisors: job-supervisors-centcom
salary: 20000 # Frontier
canBeAntag: false
accessGroups:
- AllAccess
Expand Down Expand Up @@ -180,6 +182,7 @@
startingGear: ERTEngineerGearEVA
icon: "JobIconNanotrasen"
supervisors: job-supervisors-centcom
salary: 20000 # Frontier
canBeAntag: false
accessGroups:
- AllAccess
Expand Down Expand Up @@ -252,6 +255,7 @@
startingGear: ERTEngineerGearEVA
icon: "JobIconNanotrasen"
supervisors: job-supervisors-centcom
salary: 20000 # Frontier
canBeAntag: false
accessGroups:
- AllAccess
Expand Down Expand Up @@ -341,6 +345,7 @@
startingGear: ERTMedicalGearEVA
icon: "JobIconNanotrasen"
supervisors: job-supervisors-centcom
salary: 20000 # Frontier
canBeAntag: false
accessGroups:
- AllAccess
Expand Down Expand Up @@ -405,6 +410,7 @@
startingGear: ERTJanitorGearEVA
icon: "JobIconNanotrasen"
supervisors: job-supervisors-centcom
salary: 20000 # Frontier
canBeAntag: false
accessGroups:
- AllAccess
Expand Down
Loading
Loading