forge/arma/server/addons/task/functions/fnc_handler.sqf
Jacob Schmidt ff7ff0c4e5 Implement org credit line debt and bank repayment flow (#2)
## Summary

This finishes the org credit line workflow so it behaves like reserved treasury-backed credit instead of a simple member allowance.

## What changed

- reserve org funds immediately when a credit line is assigned
- track credit lines with:
  - approved amount
  - available amount
  - outstanding principal
  - interest rate
  - amount due
- consume reserved credit during store checkout without charging org funds a second time
- add credit line repayment through the bank app
- sync richer credit line state into org and bank payloads/UI
- keep legacy `amount` compatibility mapped to available credit for older consumers

## User-facing behavior

- assigning a credit line now reduces available org funds immediately
- spending on `credit_line` reduces available credit and creates debt with interest
- the bank app now shows outstanding credit debt and allows repayment from personal bank funds
- the org treasury view now shows reserved credit and outstanding due totals

## Validation

- `cargo fmt`
- `npm run build:webui`
- `cargo test -p forge-services --quiet`
- `cargo test -p forge-server --quiet`

## Follow-up checks

- validate in-game that assigning a credit line reduces org funds immediately
- validate store checkout with `credit_line` updates available credit and debt correctly
- validate bank repayment decreases player bank balance, increases org funds, and reduces amount due

Co-authored-by: Jacob Schmidt <innovativestudios@outlook.com>
Reviewed-on: #2
2026-04-02 16:50:38 -05:00

105 lines
3.5 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: IDSolutions
* Server side task handler/spawner
*
* Arguments:
* 0: Type of task <STRING>
* 1: Arguments for task <ARRAY>
* 2: Minimum org reputation for task <NUMBER> (default: 0)
* 3: Requester UID <STRING> (default: "")
*
* Return Value:
* None
*
* Example:
* ["task_type", [_reward, _punish, _time, etc.....], minReputation, requesterUid] call forge_server_task_fnc_handler;
*
* Public: Yes
*/
params [["_taskType", "", [""]], ["_args", [], [[]]], ["_minRating", 0, [0]], ["_requesterUid", "", [""]]];
private _taskID = "";
if (_minRating > 0) then {
if (_requesterUid isEqualTo "") then {
["WARNING", format ["Task %1 requires minimum reputation %2 but no requester UID was provided, skipping reputation gate.", _taskType, _minRating]] call EFUNC(common,log);
} else {
private _requesterActor = EGVAR(actor,Registry) getOrDefault [_requesterUid, createHashMap];
if (_requesterActor isEqualTo createHashMap) then {
_requesterActor = EGVAR(actor,ActorStore) call ["init", [_requesterUid]];
};
private _orgID = _requesterActor getOrDefault ["organization", "default"];
if (_orgID isEqualTo "") then { _orgID = "default"; };
private _org = EGVAR(org,OrgStore) call ["loadById", [_orgID]];
private _orgReputation = _org getOrDefault ["reputation", 0];
if (_orgReputation < _minRating) exitWith {
private _message = format ["Organization reputation of %1 does not meet the minimum required reputation of %2.", _orgReputation, _minRating];
["WARNING", format ["Task %1 blocked: %2", _taskType, _message]] call EFUNC(common,log);
private _player = [_requesterUid] call EFUNC(common,getPlayer);
if (isNull _player) exitWith {};
[CRPC(notifications,recieveNotification), ["warning", "Tasks", _message], _player] call CFUNC(targetEvent);
};
};
};
if (_args isNotEqualTo [] && { (_args select 0) isEqualType "" }) then {
_taskID = _args select 0;
};
if (_taskID isNotEqualTo "") then {
private _ownershipResult = GVAR(TaskStore) call ["bindTaskOwnership", [_taskID, _requesterUid]];
if !(_ownershipResult getOrDefault ["success", false]) then {
["WARNING", format [
"Failed to bind task ownership for %1 (%2): %3",
_taskID,
_taskType,
_ownershipResult getOrDefault ["message", "Unknown error."]
]] call EFUNC(common,log);
};
GVAR(TaskStore) call ["setTaskStatus", [_taskID, "active"]];
};
switch (_taskType) do {
case "attack": {
private _thread = _args spawn FUNC(attack);
waitUntil { sleep 2; scriptDone _thread };
};
case "defuse": {
private _thread = _args spawn FUNC(defuse);
waitUntil { sleep 2; scriptDone _thread };
};
case "destroy": {
private _thread = _args spawn FUNC(destroy);
waitUntil { sleep 2; scriptDone _thread };
};
case "delivery": {
private _thread = _args spawn FUNC(delivery);
waitUntil { sleep 2; scriptDone _thread };
};
case "defend": {
private _thread = _args spawn FUNC(defend);
waitUntil { sleep 2; scriptDone _thread };
};
case "hostage": {
private _thread = _args spawn FUNC(hostage);
waitUntil { sleep 2; scriptDone _thread };
};
case "hvt": {
private _thread = _args spawn FUNC(hvt);
waitUntil { sleep 2; scriptDone _thread };
};
default {
["ERROR", format ["Unknown Contract Type: %1", _taskType]] call EFUNC(common,log);
};
};
["INFO", "Mission Handler Done"] call EFUNC(common,log);