## 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
167 lines
6.6 KiB
Plaintext
167 lines
6.6 KiB
Plaintext
#include "script_component.hpp"
|
|
|
|
PREP_RECOMPILE_START;
|
|
#include "XEH_PREP.hpp"
|
|
PREP_RECOMPILE_END;
|
|
|
|
// private _category = [QUOTE(MOD_NAME), LLSTRING(displayName)];
|
|
|
|
[QGVAR(requestInitOrg), {
|
|
params [["_uid", "", [""]]];
|
|
|
|
if (_uid isEqualTo "") exitWith { diag_log "[FORGE:Server:Org] Empty/Invalid UID!" };
|
|
|
|
GVAR(OrgStore) call ["init", [_uid]];
|
|
}] call CFUNC(addEventHandler);
|
|
|
|
[QGVAR(requestHydrateOrg), {
|
|
params [["_uid", "", [""]], ["_bridgeEvent", "org::sync", [""]]];
|
|
|
|
if (_uid isEqualTo "") exitWith { diag_log "[FORGE:Server:Org] Empty/Invalid UID!" };
|
|
|
|
if !(_bridgeEvent in ["org::login::success", "org::create::success", "org::sync"]) then {
|
|
_bridgeEvent = "org::sync";
|
|
};
|
|
|
|
private _player = [_uid] call EFUNC(common,getPlayer);
|
|
if (_player isEqualTo objNull) exitWith {};
|
|
|
|
private _payload = GVAR(OrgStore) call ["buildPortalPayload", [_uid]];
|
|
if (_payload isEqualTo createHashMap) exitWith {};
|
|
|
|
[CRPC(org,responseHydrateOrg), [_payload, _bridgeEvent], _player] call CFUNC(targetEvent);
|
|
}] call CFUNC(addEventHandler);
|
|
|
|
[QGVAR(requestCreateOrg), {
|
|
params [["_uid", "", [""]], ["_orgName", "", [""]]];
|
|
|
|
if (_uid isEqualTo "" || { _orgName isEqualTo "" }) exitWith {
|
|
diag_log "[FORGE:Server:Org] Empty/Invalid UID or Organization Name!"
|
|
};
|
|
|
|
private _player = [_uid] call EFUNC(common,getPlayer);
|
|
private _result = GVAR(OrgStore) call ["register", [_uid, _orgName]];
|
|
|
|
if (_result getOrDefault ["success", false]) then {
|
|
private _actorPatch = _result getOrDefault ["actorPatch", createHashMap];
|
|
if (_actorPatch isNotEqualTo createHashMap) then {
|
|
[CRPC(actor,responseSyncActor), [_actorPatch], _player] call CFUNC(targetEvent);
|
|
};
|
|
};
|
|
|
|
[CRPC(org,responseCreateOrg), [_result], _player] call CFUNC(targetEvent);
|
|
}] call CFUNC(addEventHandler);
|
|
|
|
[QGVAR(requestAssignCreditLine), {
|
|
params [
|
|
["_uid", "", [""]],
|
|
["_memberUid", "", [""]],
|
|
["_memberName", "", [""]],
|
|
["_amount", 0, [0]]
|
|
];
|
|
|
|
if (_uid isEqualTo "" || { _memberUid isEqualTo "" } || { _amount <= 0 }) exitWith {
|
|
diag_log "[FORGE:Server:Org] Invalid credit line request payload!"
|
|
};
|
|
|
|
private _requester = [_uid] call EFUNC(common,getPlayer);
|
|
if (_requester isEqualTo objNull) exitWith {};
|
|
|
|
private _result = GVAR(OrgStore) call ["assignCreditLine", [_uid, _memberUid, _memberName, _amount]];
|
|
if (_result getOrDefault ["success", false]) then {
|
|
private _patch = _result getOrDefault ["patch", createHashMap];
|
|
|
|
{
|
|
private _memberPlayer = [_x] call EFUNC(common,getPlayer);
|
|
if (_memberPlayer isNotEqualTo objNull && { _patch isNotEqualTo createHashMap }) then {
|
|
[CRPC(org,responseSyncOrg), [_patch], _memberPlayer] call CFUNC(targetEvent);
|
|
};
|
|
} forEach (_result getOrDefault ["memberUids", []]);
|
|
};
|
|
|
|
[CRPC(org,responseCreditLine), [createHashMapFromArray [
|
|
["success", _result getOrDefault ["success", false]],
|
|
["message", _result getOrDefault ["message", "Unable to assign credit line."]]
|
|
]], _requester] call CFUNC(targetEvent);
|
|
}] call CFUNC(addEventHandler);
|
|
|
|
[QGVAR(requestLeaveOrg), {
|
|
params [["_uid", "", [""]]];
|
|
|
|
if (_uid isEqualTo "") exitWith {
|
|
diag_log "[FORGE:Server:Org] Empty/Invalid UID for leave request!"
|
|
};
|
|
|
|
private _player = [_uid] call EFUNC(common,getPlayer);
|
|
if (_player isEqualTo objNull) exitWith {};
|
|
|
|
private _result = GVAR(OrgStore) call ["leave", [_uid]];
|
|
if (_result getOrDefault ["success", false]) then {
|
|
private _actorPatch = _result getOrDefault ["actorPatch", createHashMap];
|
|
if (_actorPatch isNotEqualTo createHashMap) then {
|
|
[CRPC(actor,responseSyncActor), [_actorPatch], _player] call CFUNC(targetEvent);
|
|
};
|
|
|
|
GVAR(OrgStore) call ["init", [_uid]];
|
|
|
|
private _notificationParams = _result getOrDefault ["notification", []];
|
|
if (_notificationParams isEqualType [] && { count _notificationParams > 0 }) then {
|
|
[CRPC(notifications,recieveNotification), _notificationParams, _player] call CFUNC(targetEvent);
|
|
};
|
|
};
|
|
|
|
[CRPC(org,responseLeaveOrg), [createHashMapFromArray [
|
|
["success", _result getOrDefault ["success", false]],
|
|
["message", _result getOrDefault ["message", "Unable to leave the organization."]]
|
|
]], _player] call CFUNC(targetEvent);
|
|
}] call CFUNC(addEventHandler);
|
|
|
|
[QGVAR(requestDisbandOrg), {
|
|
params [["_uid", "", [""]]];
|
|
|
|
if (_uid isEqualTo "") exitWith {
|
|
diag_log "[FORGE:Server:Org] Empty/Invalid UID for disband request!"
|
|
};
|
|
|
|
private _requester = [_uid] call EFUNC(common,getPlayer);
|
|
if (_requester isEqualTo objNull) exitWith {};
|
|
|
|
private _result = GVAR(OrgStore) call ["disband", [_uid]];
|
|
if !(_result getOrDefault ["success", false]) exitWith {
|
|
[CRPC(org,responseDisbandOrg), [createHashMapFromArray [
|
|
["success", false],
|
|
["message", _result getOrDefault ["message", "Failed to disband organization."]],
|
|
["requester", true]
|
|
]], _requester] call CFUNC(targetEvent);
|
|
};
|
|
|
|
{
|
|
[_x, _result] call {
|
|
params [["_member", createHashMap, [createHashMap]], ["_disbandResult", createHashMap, [createHashMap]]];
|
|
|
|
private _memberUid = _member getOrDefault ["uid", ""];
|
|
if (_memberUid isEqualTo "") exitWith {};
|
|
|
|
private _memberPlayer = [_memberUid] call EFUNC(common,getPlayer);
|
|
if (_memberPlayer isEqualTo objNull) exitWith {};
|
|
|
|
private _actorPatch = _member getOrDefault ["actorPatch", createHashMap];
|
|
if (_actorPatch isNotEqualTo createHashMap) then {
|
|
[CRPC(actor,responseSyncActor), [_actorPatch], _memberPlayer] call CFUNC(targetEvent);
|
|
};
|
|
|
|
GVAR(OrgStore) call ["init", [_memberUid]];
|
|
[CRPC(org,responseDisbandOrg), [createHashMapFromArray [
|
|
["success", true],
|
|
["message", _member getOrDefault ["message", _disbandResult getOrDefault ["message", "Organization disbanded."]]],
|
|
["requester", _member getOrDefault ["requester", false]]
|
|
]], _memberPlayer] call CFUNC(targetEvent);
|
|
|
|
private _notificationParams = _member getOrDefault ["notification", []];
|
|
if (_notificationParams isEqualType [] && { count _notificationParams > 0 }) then {
|
|
[CRPC(notifications,recieveNotification), _notificationParams, _memberPlayer] call CFUNC(targetEvent);
|
|
};
|
|
};
|
|
} forEach (_result getOrDefault ["members", []]);
|
|
}] call CFUNC(addEventHandler);
|