forge/arma/server/addons/garage/functions/fnc_initVGStore.sqf
Jacob Schmidt 7a214d835d Enable vehicle checkout grants and garage/org sync updates
- Wire store checkout to grant purchased vehicles via virtual garage
- Add org fleet updates for org-funded vehicle purchases and sync to members
- Simplify client garage sync to always apply incoming category patches
2026-03-12 22:20:21 -05:00

152 lines
5.3 KiB
Plaintext

#include "..\script_component.hpp"
/*
* File: fnc_initVGStore.sqf
* Author: IDSolutions
* Date: 2025-12-17
* Last Update: 2026-02-13
* Public: No
*
* Description:
* Initializes the Virtual Garage store for managing player vehicle unlocks.
* Provides methods for syncing, saving, and applying virtual vehicles to BIS Garage.
*
* Arguments:
* None
*
* Return Value:
* VG store object [HASHMAP OBJECT]
*
* Example:
* call forge_server_garage_fnc_initVGStore
*/
#pragma hemtt ignore_variables ["_self"]
GVAR(VGarageModel) = compileFinal createHashMapObject [[
["#type", "VGarageModel"],
["defaults", compileFinal {
private _vGarage = createHashMap;
_vGarage set ["armor", []];
_vGarage set ["cars", ["B_Quadbike_01_F"]];
_vGarage set ["helis", []];
_vGarage set ["naval", []];
_vGarage set ["other", []];
_vGarage set ["planes", []];
_vGarage
}]
]];
GVAR(VGBaseStore) = compileFinal createHashMapFromArray [
["#base", EGVAR(common,BaseStore)],
["#type", "VGBaseStore"],
["#create", compileFinal {
GVAR(VGRegistry) = createHashMap;
["INFO", "VGarage Store Initialized!"] call EFUNC(common,log);
}],
["init", compileFinal {
params [["_uid", "", [""]]];
private _player = [_uid] call EFUNC(common,getPlayer);
private _cached = GVAR(VGRegistry) getOrDefault [_uid, nil];
if !(isNil { _cached }) exitWith {
[CRPC(garage,responseInitVG), [_cached], _player] call CFUNC(targetEvent);
_cached
};
["owned:garage:exists", [_uid]] call EFUNC(extension,extCall) params ["_result", "_isSuccess"];
if !(_isSuccess) exitWith {
["ERROR", format ["Failed to check if virtual garage %1 exists! Using fallback virtual garage.", _uid]] call EFUNC(common,log);
private _fallbackVGarage = GVAR(VGarageModel) call ["defaults", []];
GVAR(VGRegistry) set [_uid, _fallbackVGarage];
[CRPC(garage,responseInitVG), [_fallbackVGarage], _player] call CFUNC(targetEvent);
_fallbackVGarage
};
private _finalVGarage = createHashMap;
if (_result == "true") then {
_finalVGarage = _self call ["fetch", ["owned:garage:fetch", _uid]];
["INFO", format ["Found virtual garage for %1", _uid]] call EFUNC(common,log);
} else {
_finalVGarage = GVAR(VGarageModel) call ["defaults", []];
["owned:garage:create", [_uid]] call EFUNC(extension,extCall) params ["_result", "_isSuccess"];
if !(_isSuccess) exitWith {
["ERROR", format ["Failed to create virtual garage for %1! Using fallback virtual garage.", _uid]] call EFUNC(common,log);
GVAR(VGRegistry) set [_uid, _finalVGarage];
[CRPC(garage,responseInitVG), [_finalVGarage], _player] call CFUNC(targetEvent);
_finalVGarage
};
["INFO", format ["Created new virtual garage for %1", _uid]] call EFUNC(common,log);
};
GVAR(VGRegistry) set [_uid, _finalVGarage];
[CRPC(garage,responseInitVG), [_finalVGarage], _player] call CFUNC(targetEvent);
_finalVGarage
}],
["grantVehicles", compileFinal {
params [["_uid", "", [""]], ["_vehicles", [], [[]]], ["_commit", false, [false]]];
private _result = createHashMapFromArray [
["success", false],
["message", "Virtual garage grant failed."],
["patch", createHashMap],
["granted", []],
["garage", createHashMap]
];
private _defaultGarage = GVAR(VGarageModel) call ["defaults", []];
private _garage = +(GVAR(VGRegistry) getOrDefault [_uid, _defaultGarage]);
private _patch = createHashMap;
private _granted = [];
private _categoriesToSync = [];
{
private _className = _x getOrDefault ["classname", ""];
private _category = toLowerANSI (_x getOrDefault ["category", ""]);
if (_className isEqualTo "") exitWith {
_result set ["message", "Vehicle checkout entry was missing a classname."];
};
if !(_category in ["cars", "armor", "helis", "planes", "naval", "other"]) exitWith {
_result set ["message", format ["Vehicle category '%1' is unsupported.", _category]];
};
private _categoryUnlocks = +(_garage getOrDefault [_category, []]);
_categoryUnlocks pushBackUnique _className;
_garage set [_category, _categoryUnlocks];
_categoriesToSync pushBackUnique _category;
_granted pushBack (createHashMapFromArray [
["classname", _className],
["category", _category]
]);
} forEach _vehicles;
{
private _category = _x;
_patch set [_category, _garage getOrDefault [_category, []]];
} forEach _categoriesToSync;
if (_commit) then { GVAR(VGRegistry) set [_uid, _garage]; };
_result set ["success", true];
_result set ["message", ""];
_result set ["patch", _patch];
_result set ["granted", _granted];
_result set ["garage", _garage];
_result
}]
];
GVAR(VGarageStore) = createHashMapObject [GVAR(VGBaseStore)];
GVAR(VGarageStore)