#include "..\script_component.hpp" /* * Author: IDSolutions * Handles task completion rewards for organizations * * Arguments: * 0: Task ID * 1: Reward Data * - funds: Amount of money to award * - reputation: Amount of reputation to award * - equipment: Array of equipment classnames to award * - supplies: Array of supply classnames to award * - weapons: Array of weapon classnames to award * - vehicles: Array of vehicle classnames to award * - special: Array of special item classnames to award * * Return Value: * Success * * Example: * private _rewards = createHashMapFromArray [ * ["funds", 10000], * ["reputation", 50], * ["equipment", ["ItemGPS", "ItemCompass"]], * ["supplies", ["FirstAidKit", "Medikit"]], * ["weapons", ["arifle_MX_F"]], * ["vehicles", ["B_MRAP_01_F"]], * ["special", ["B_UAV_01_F"]] * ]; * ["task_1", _rewards] call forge_client_task_fnc_handleTaskRewards; * * Public: No */ params [["_taskID", ""], ["_rewards", createHashMap]]; if (_taskID == "") exitWith { diag_log "ERROR: No task ID provided for rewards"; false }; private _store = call EFUNC(org,verifyOrgStore); if (isNil "_store") exitWith { ["No organization found to receive rewards", "error", 5, "right"] call EFUNC(misc,notify); false }; private _success = true; private _funds = _rewards getOrDefault ["funds", 0]; if (_funds > 0) then { if !([_funds] call EFUNC(org,addFunds)) then { diag_log format ["Failed to award funds %1 for task %2", _funds, _taskID]; _success = false; }; }; private _reputation = _rewards getOrDefault ["reputation", 0]; if (_reputation > 0) then { if !([_reputation] call EFUNC(org,addReputation)) then { diag_log format ["Failed to award reputation %1 for task %2", _reputation, _taskID]; _success = false; }; }; private _fnc_addAssets = { params ["_type", "_items"]; { private _properties = createHashMap; _properties set ["source", format ["Task Reward: %1", _taskID]]; _properties set ["acquired", call EFUNC(misc,getSystemTime)]; if !([_type, _x, _properties] call EFUNC(org,addAsset)) then { diag_log format ["Failed to award %1 asset %2 for task %3", _type, _x, _taskID]; _success = false; }; } forEach _items; }; private _equipment = _rewards getOrDefault ["equipment", []]; if (count _equipment > 0) then { ["equipment", _equipment] call _fnc_addAssets; }; private _supplies = _rewards getOrDefault ["supplies", []]; if (count _supplies > 0) then { ["supply", _supplies] call _fnc_addAssets; }; private _weapons = _rewards getOrDefault ["weapons", []]; if (count _weapons > 0) then { ["weapon", _weapons] call _fnc_addAssets; }; private _vehicles = _rewards getOrDefault ["vehicles", []]; if (count _vehicles > 0) then { ["vehicle", _vehicles] call _fnc_addAssets; }; private _special = _rewards getOrDefault ["special", []]; if (count _special > 0) then { ["special", _special] call _fnc_addAssets; }; if (_success) then { private _rewardText = "Task Rewards:"; if (_funds > 0) then { _rewardText = _rewardText + format ["\n- $%1", _funds call EFUNC(misc,formatNumber)]; }; if (_reputation > 0) then { _rewardText = _rewardText + format ["\n- %1 Reputation", _reputation]; }; if (count _equipment > 0) then { _rewardText = _rewardText + format ["\n- %1 Equipment Items", count _equipment]; }; if (count _supplies > 0) then { _rewardText = _rewardText + format ["\n- %1 Supply Items", count _supplies]; }; if (count _weapons > 0) then { _rewardText = _rewardText + format ["\n- %1 Weapons", count _weapons]; }; if (count _vehicles > 0) then { _rewardText = _rewardText + format ["\n- %1 Vehicles", count _vehicles]; }; if (count _special > 0) then { _rewardText = _rewardText + format ["\n- %1 Special Items", count _special]; }; [_rewardText, "success", 10, "right"] call EFUNC(misc,notify); }; _success