#include "..\script_component.hpp" /* * Author: IDSolutions * Server side task handler/spawner * * Arguments: * 0: Type of task * 1: Arguments for task * 2: Minimum org reputation for task (default: 0) * 3: Requester UID (default: "") * * Return Value: * None * * Example: * ["task_type", [_reward, _punish, _time, etc.....], minReputation, requesterUid] call forge_server_task_fnc_handler; * * Public: Yes */ params [["_taskType", "", [""]], ["_args", [], [[]]], ["_minRating", 0, [0]], ["_requesterUid", "", [""]]]; private _taskID = ""; private _shouldStartTaskLogic = true; private _catalogEntry = createHashMap; private _source = ""; if (_minRating > 0) then { if (_requesterUid isEqualTo "") then { ["WARNING", format ["Task %1 requires minimum reputation %2 but no requester UID was provided, skipping reputation gate.", _taskType, _minRating]] call EFUNC(common,log); } else { private _orgID = EGVAR(actor,ActorStore) call ["getOrganization", [_requesterUid]]; private _org = EGVAR(org,OrgStore) call ["loadById", [_orgID]]; private _orgReputation = _org getOrDefault ["reputation", 0]; if (_orgReputation < _minRating) exitWith { private _message = format ["Organization reputation of %1 does not meet the minimum required reputation of %2.", _orgReputation, _minRating]; ["WARNING", format ["Task %1 blocked: %2", _taskType, _message]] call EFUNC(common,log); private _player = [_requesterUid] call EFUNC(common,getPlayer); if (isNull _player) exitWith {}; [CRPC(notifications,recieveNotification), ["warning", "Tasks", _message], _player] call CFUNC(targetEvent); }; }; }; if (_args isNotEqualTo [] && { (_args select 0) isEqualType "" }) then { _taskID = _args select 0; }; if (_taskID isNotEqualTo "") then { _catalogEntry = GVAR(TaskStore) call ["getTaskCatalogEntry", [_taskID]]; _source = if (_catalogEntry isEqualType createHashMap) then { _catalogEntry getOrDefault ["source", ""] } else { "" }; if (_requesterUid isNotEqualTo "") then { private _ownershipResult = GVAR(TaskStore) call ["bindTaskOwnership", [_taskID, _requesterUid]]; if !(_ownershipResult getOrDefault ["success", false]) then { ["WARNING", format [ "Failed to bind task ownership for %1 (%2): %3", _taskID, _taskType, _ownershipResult getOrDefault ["message", "Unknown error."] ]] call EFUNC(common,log); }; } else { ["INFO", format [ "Skipped automatic ownership bind for %1 from source '%2' so it remains unaccepted until CAD acknowledgement.", _taskID, _source ]] call EFUNC(common,log); }; private _initialStatus = GVAR(TaskStore) call ["resolveInitialTaskStatus", [_taskID, _catalogEntry]]; GVAR(TaskStore) call ["setTaskStatus", [_taskID, _initialStatus]]; if (_initialStatus isEqualTo "locked") then { ["INFO", format ["Task %1 is waiting for chained prerequisites before task logic starts.", _taskID]] call EFUNC(common,log); waitUntil { sleep 2; private _status = GVAR(TaskStore) call ["getTaskStatus", [_taskID]]; _status isNotEqualTo "locked" }; if ((GVAR(TaskStore) call ["getTaskStatus", [_taskID]]) isEqualTo "") then { _shouldStartTaskLogic = false; ["WARNING", format ["Task %1 was cleared before its chained prerequisites unlocked.", _taskID]] call EFUNC(common,log); }; }; if (_shouldStartTaskLogic && { _source in ["eden", "mission_manager"] }) then { ["INFO", format ["Task %1 from source '%2' is waiting for dispatcher assignment acknowledgement before task logic starts.", _taskID, _source]] call EFUNC(common,log); waitUntil { sleep 2; private _status = GVAR(TaskStore) call ["getTaskStatus", [_taskID]]; _status in ["active", "failed", "succeeded", ""] }; private _acknowledgedStatus = GVAR(TaskStore) call ["getTaskStatus", [_taskID]]; if (_acknowledgedStatus isNotEqualTo "active") then { _shouldStartTaskLogic = false; ["WARNING", format [ "Task %1 from source '%2' did not become active before task logic start. Status=%3", _taskID, _source, _acknowledgedStatus ]] call EFUNC(common,log); }; }; }; if !(_shouldStartTaskLogic) exitWith {}; if (_taskID isNotEqualTo "") then { GVAR(TaskStore) call ["ensureBisTaskCreated", [_taskID]]; }; switch (_taskType) do { case "attack": { private _thread = _args spawn FUNC(attack); waitUntil { sleep 2; scriptDone _thread }; }; case "defuse": { private _thread = _args spawn FUNC(defuse); waitUntil { sleep 2; scriptDone _thread }; }; case "destroy": { private _thread = _args spawn FUNC(destroy); waitUntil { sleep 2; scriptDone _thread }; }; case "delivery": { private _thread = _args spawn FUNC(delivery); waitUntil { sleep 2; scriptDone _thread }; }; case "defend": { private _thread = _args spawn FUNC(defend); waitUntil { sleep 2; scriptDone _thread }; }; case "hostage": { private _thread = _args spawn FUNC(hostage); waitUntil { sleep 2; scriptDone _thread }; }; case "hvt": { private _thread = _args spawn FUNC(hvt); waitUntil { sleep 2; scriptDone _thread }; }; default { ["ERROR", format ["Unknown Contract Type: %1", _taskType]] call EFUNC(common,log); }; }; ["INFO", "Mission Handler Done"] call EFUNC(common,log);