client/addons/task/functions/fnc_handleTaskRewards.sqf
Jacob Schmidt 86ae5c4248 feat: Implement task rewards and penalties
This commit introduces a new task reward and penalty system.

The following changes were made:

- Added `handleTaskRewards` to `XEH_PREP.hpp` for pre-processing.
- Added parameters for equipment, supply, weapon, vehicle, and special rewards to the task definition functions (`fnc_defuse.sqf`, `fnc_destroy.sqf`, `fnc_attack.sqf`, `fnc_hvt.sqf`, `fnc_delivery.sqf`, `fnc_defend.sqf`, `fnc_hostage.sqf`).
- Modified task completion logic to handle rewards and penalties using the new `handleTaskRewards` function.
- Replaced direct reputation and fund modifications with the new reward system.
- Updated documentation to reflect the new reward parameters.
2025-05-25 14:20:36 -05:00

118 lines
4.0 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: IDSolutions
* Handles task completion rewards for organizations
*
* Arguments:
* 0: Task ID <STRING>
* 1: Reward Data <HASHMAP>
* - funds: Amount of money to award <NUMBER>
* - reputation: Amount of reputation to award <NUMBER>
* - equipment: Array of equipment classnames to award <ARRAY>
* - supplies: Array of supply classnames to award <ARRAY>
* - weapons: Array of weapon classnames to award <ARRAY>
* - vehicles: Array of vehicle classnames to award <ARRAY>
* - special: Array of special item classnames to award <ARRAY>
*
* Return Value:
* Success <BOOLEAN>
*
* 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