forge/arma/server/addons/garage/XEH_preInit.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

117 lines
4.1 KiB
Plaintext

#include "script_component.hpp"
PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;
// private _category = [QUOTE(MOD_NAME), LLSTRING(displayName)];
[QGVAR(requestInitGarage), {
params [["_uid", "", [""]]];
if (_uid isEqualTo "") exitWith { diag_log "[FORGE:Server:Garage] Empty/Invalid UID!" };
GVAR(GarageStore) call ["init", [_uid]];
}] call CFUNC(addEventHandler);
[QGVAR(requestSaveGarage), {
params [["_uid", "", [""]]];
if (_uid isEqualTo "") exitWith { diag_log "[FORGE:Server:Garage] Empty/Invalid UID!" };
private _finalData = GVAR(GarageStore) call ["save", [_uid]];
private _player = [_uid] call EFUNC(common,getPlayer);
[CRPC(garage,responseSyncGarage), [_finalData], _player] call CFUNC(targetEvent);
}] call CFUNC(addEventHandler);
[QGVAR(requestStoreVehicle), {
params [
["_uid", "", [""]],
["_className", "", [""]],
["_fuel", 0, [0]],
["_damage", 0, [0]],
["_hitPointsJson", "", [""]]
];
private _player = [_uid] call EFUNC(common,getPlayer);
if (_uid isEqualTo "" || { _className isEqualTo "" } || { _hitPointsJson isEqualTo "" }) exitWith {
[CRPC(garage,responseGarageAction), [createHashMapFromArray [
["action", "store"],
["success", false],
["message", "Missing vehicle data for garage storage."]
]], _player] call CFUNC(targetEvent);
};
private _payloadJson = toJSON (createHashMapFromArray [
["classname", _className],
["fuel", _fuel],
["damage", _damage],
["hit_points", fromJSON _hitPointsJson]
]);
private _garage = GVAR(GarageStore) call ["storeVehicle", [_uid, _payloadJson]];
if (_garage isEqualTo createHashMap) exitWith {
[CRPC(garage,responseGarageAction), [createHashMapFromArray [
["action", "store"],
["success", false],
["message", "Failed to store vehicle."]
]], _player] call CFUNC(targetEvent);
};
[CRPC(garage,responseSyncGarage), [_garage], _player] call CFUNC(targetEvent);
[CRPC(garage,responseGarageAction), [createHashMapFromArray [
["action", "store"],
["success", true],
["message", "Vehicle stored in garage."]
]], _player] call CFUNC(targetEvent);
}] call CFUNC(addEventHandler);
[QGVAR(requestRetrieveVehicle), {
params [["_uid", "", [""]], ["_plate", "", [""]]];
private _player = [_uid] call EFUNC(common,getPlayer);
if (_uid isEqualTo "" || { _plate isEqualTo "" }) exitWith {
[CRPC(garage,responseGarageAction), [createHashMapFromArray [
["action", "retrieve"],
["success", false],
["message", "Select a stored vehicle to retrieve."]
]], _player] call CFUNC(targetEvent);
};
private _payloadJson = toJSON (createHashMapFromArray [["plate", _plate]]);
private _garage = GVAR(GarageStore) call ["retrieveVehicle", [_uid, _payloadJson]];
if (_garage isEqualTo createHashMap) exitWith {
[CRPC(garage,responseGarageAction), [createHashMapFromArray [
["action", "retrieve"],
["success", false],
["message", "Failed to retrieve vehicle."]
]], _player] call CFUNC(targetEvent);
};
[CRPC(garage,responseSyncGarage), [_garage], _player] call CFUNC(targetEvent);
[CRPC(garage,responseGarageAction), [createHashMapFromArray [
["action", "retrieve"],
["success", true],
["message", "Vehicle retrieved from garage."]
]], _player] call CFUNC(targetEvent);
}] call CFUNC(addEventHandler);
[QGVAR(requestInitVG), {
params [["_uid", "", [""]]];
if (_uid isEqualTo "") exitWith { diag_log "[FORGE:Server:VGarage] Empty/Invalid UID!" };
GVAR(VGarageStore) call ["init", [_uid]];
}] call CFUNC(addEventHandler);
[QGVAR(requestSaveVG), {
params [["_uid", "", [""]]];
if (_uid isEqualTo "") exitWith { diag_log "[FORGE:Server:VGarage] Empty/Invalid UID!" };
private _finalData = GVAR(VGarageStore) call ["save", [_uid]];
private _player = [_uid] call EFUNC(common,getPlayer);
[CRPC(garage,responseSyncVG), [_finalData], _player] call CFUNC(targetEvent);
}] call CFUNC(addEventHandler);