#include "..\script_component.hpp" /* * File: fnc_initVAStore.sqf * Author: IDSolutions * Date: 2025-12-17 * Last Update: 2026-03-27 * Public: No * * Description: * Initializes the Virtual Arsenal store for managing player arsenal unlocks. * Provides methods for syncing, saving, and applying virtual items to BIS Arsenal. * * Arguments: * None * * Return Value: * VA store object [HASHMAP OBJECT] * * Example: * call forge_server_locker_fnc_initVAStore */ #pragma hemtt ignore_variables ["_self"] GVAR(VArsenalModel) = compileFinal createHashMapObject [[ ["#type", "VArsenalModel"], ["defaults", compileFinal { private _vArsenal = createHashMap; _vArsenal set ["backpacks", ["B_AssaultPack_rgr"]]; _vArsenal set ["items", ["FirstAidKit", "G_Combat", "H_Cap_blk_ION", "H_HelmetB", "ItemCompass", "ItemGPS", "ItemMap", "ItemRadio", "ItemWatch", "U_IG_Guerrilla_6_1", "V_TacVest_oli", "ACE_EarPlugs"]]; _vArsenal set ["magazines", ["16Rnd_9x21_Mag", "30Rnd_65x39_caseless_black_mag", "Chemlight_blue", "Chemlight_green", "Chemlight_red", "Chemlight_yellow", "HandGrenade", "SmokeShell", "SmokeShellBlue", "SmokeShellGreen", "SmokeShellOrange", "SmokeShellPurple", "SmokeShellRed", "SmokeShellYellow"]]; _vArsenal set ["weapons", ["arifle_MX_F", "hgun_P07_F"]]; _vArsenal }] ]]; GVAR(VABaseStore) = compileFinal createHashMapFromArray [ ["#base", EGVAR(common,BaseStore)], ["#type", "VABaseStore"], ["#create", compileFinal { GVAR(VARegistry) = createHashMap; ["INFO", "VArsenal Store Initialized!"] call EFUNC(common,log); }], ["init", compileFinal { params [["_uid", "", [""]]]; private _player = [_uid] call EFUNC(common,getPlayer); private _cached = GVAR(VARegistry) getOrDefault [_uid, nil]; if !(isNil { _cached }) exitWith { [CRPC(locker,responseInitVA), [_cached], _player] call CFUNC(targetEvent); _cached }; ["owned:locker:exists", [_uid]] call EFUNC(extension,extCall) params ["_result", "_isSuccess"]; if !(_isSuccess) exitWith { ["ERROR", format ["Failed to check if virtual arsenal %1 exists! Using fallback virtual arsenal.", _uid]] call EFUNC(common,log); private _fallbackVArsenal = GVAR(VArsenalModel) call ["defaults", []]; GVAR(VARegistry) set [_uid, _fallbackVArsenal]; [CRPC(locker,responseInitVA), [_fallbackVArsenal], _player] call CFUNC(targetEvent); _fallbackVArsenal }; private _finalVArsenal = createHashMap; if (_result == "true") then { _finalVArsenal = _self call ["fetch", ["owned:locker:fetch", _uid]]; ["INFO", format ["Found virtual arsenal for %1", _uid]] call EFUNC(common,log); } else { _finalVArsenal = GVAR(VArsenalModel) call ["defaults", []]; ["owned:locker:create", [_uid]] call EFUNC(extension,extCall) params ["_result", "_isSuccess"]; if !(_isSuccess) exitWith { ["ERROR", format ["Failed to create virtual arsenal for %1! Using fallback virtual arsenal.", _uid]] call EFUNC(common,log); GVAR(VARegistry) set [_uid, _finalVArsenal]; [CRPC(locker,responseInitVA), [_finalVArsenal], _player] call CFUNC(targetEvent); _finalVArsenal }; ["INFO", format ["Created new virtual arsenal for %1", _uid]] call EFUNC(common,log); }; GVAR(VARegistry) set [_uid, _finalVArsenal]; [CRPC(locker,responseInitVA), [_finalVArsenal], _player] call CFUNC(targetEvent); _finalVArsenal }], ["unlockItems", compileFinal { params [["_uid", "", [""]], ["_items", [], [[]]], ["_commit", false, [false]]]; private _result = createHashMapFromArray [ ["success", false], ["message", "VA unlock failed."], ["patch", createHashMap], ["arsenal", createHashMap] ]; private _defaultArsenal = GVAR(VArsenalModel) call ["defaults", []]; private _arsenal = +(GVAR(VARegistry) getOrDefault [_uid, _defaultArsenal]); private _patch = createHashMap; private _categoriesToSync = []; { private _item = _x; private _className = _item getOrDefault ["classname", ""]; private _category = toLowerANSI (_item getOrDefault ["category", ""]); private _arsenalCategory = switch (_category) do { case "item": { "items" }; case "weapon": { "weapons" }; case "magazine": { "magazines" }; case "backpack": { "backpacks" }; default { "items" }; }; private _categoryUnlocks = +(_arsenal getOrDefault [_arsenalCategory, []]); _categoryUnlocks pushBackUnique _className; _arsenal set [_arsenalCategory, _categoryUnlocks]; _categoriesToSync pushBackUnique _arsenalCategory; } forEach _items; { private _category = _x; private _categoryUnlocks = _arsenal getOrDefault [_category, []]; _patch set [_category, _categoryUnlocks]; } forEach _categoriesToSync; if (_commit) then { GVAR(VARegistry) set [_uid, _arsenal]; }; _result set ["success", true]; _result set ["message", ""]; _result set ["patch", _patch]; _result set ["arsenal", _arsenal]; _result }] ]; GVAR(VAStore) = createHashMapObject [GVAR(VABaseStore)]; GVAR(VAStore)