Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common - Allow custom event name for status effects #10473

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions addons/common/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ ACE_COUNTERS = [];
// Load ace_settings into CBA Settings
[] call FUNC(cbaSettings);

GVAR(statusEffect_Names) = [];
GVAR(statusEffect_isGlobal) = [];
GVAR(statusEffect_sendJIP) = [];
GVAR(statusEffects) = createHashMap;

GVAR(setHearingCapabilityMap) = [];

Expand Down
13 changes: 7 additions & 6 deletions addons/common/functions/fnc_statusEffect_addType.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* 1: Send event globally <BOOL>
* 2: Common Effect Reaons to pre-seed durring init <ARRAY>
* 3: Send event to JIP (requires sending event globally) <BOOL>
* 4: Event name <STRING> (default: "ace_common_<effect>")
*
* Return Value:
* None
Expand All @@ -18,16 +19,16 @@
* Public: No
*/

params [["_name", "", [""]], ["_isGlobal", false, [false]], ["_commonReasonsArray", [], [[]]], ["_sendJIP", false, [false]]];
TRACE_3("params",_name,_isGlobal,_commonReasonsArray);
params [["_name", "", [""]], ["_isGlobal", false, [false]], ["_commonReasonsArray", [], [[]]], ["_sendJIP", false, [false]], ["_eventName", "", [""]]];
TRACE_4("params",_name,_isGlobal,_commonReasonsArray,_eventName);

_name = toLowerANSI _name;
if (_name == "") exitWith {ERROR_1("addStatusEffect - Bad Name %1",_this)};
if (_name in GVAR(statusEffect_Names)) exitWith {WARNING_1("addStatusEffect - Effect Already Added (note, will not update global bit) %1",_this)};
if (_name in GVAR(statusEffects)) exitWith {WARNING_1("addStatusEffect - Effect Already Added (note, will not update global bit) %1",_this)};
if (_sendJIP && !_isGlobal) exitWith {WARNING_1("addStatusEffect - Trying to add non-global JIP effect %1",_this)};
if (_eventName == "") then { _eventName = format [QGVAR(%1), _name]; };

GVAR(statusEffect_Names) pushBack _name;
GVAR(statusEffect_isGlobal) pushBack _isGlobal;
GVAR(statusEffect_sendJIP) pushBack _sendJIP;
GVAR(statusEffects) set [_name, [_isGlobal, _sendJIP, _eventName]];

//We add reasons at any time, but more efficenet to add all common ones at one time during init
if (isServer && {_commonReasonsArray isNotEqualTo []}) then {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ if (_object == _objectRef) exitWith {};
TRACE_2("forced reset defined array on object mismatch",_x,_effectNumber);
_object setVariable [_effectVarName, 0, true]; //This always resets to 0 (not -1/nil)!
};
} forEach GVAR(statusEffect_Names);
} forEach GVAR(statusEffects);

_object setVariable [QGVAR(statusEffect_object), _object, true];
53 changes: 28 additions & 25 deletions addons/common/functions/fnc_statusEffect_sendEffects.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,34 @@ TRACE_2("params",_object,_effectName);

if (isNull _object) exitWith {};

{
if ((_effectName == "") || {_effectName == _x}) then {
private _effectVarName = format [QGVAR(effect_%1), _x];
private _effectNumber = _object getVariable [_effectVarName, -1];
if (_effectName == "") exitWith { // recurse though all possible effects
PabstMirror marked this conversation as resolved.
Show resolved Hide resolved
PabstMirror marked this conversation as resolved.
Show resolved Hide resolved
{
[_object, _x] call FUNC(statusEffect_sendEffects)
} forEach (keys GVAR(statusEffects));
};

//We only do anything if the effect has been defined at some point in the game for this unit
TRACE_2("checking if event is nil",_x,_effectNumber);
if (_effectNumber != -1) then {
private _eventName = format [QGVAR(%1), _x];
switch (true) do {
case (GVAR(statusEffect_sendJIP) select _forEachIndex): {
TRACE_2("Sending Global JIP Event",_object,_effectNumber);
private _jipID = format [QGVAR(effect_%1_%2), _eventName, hashValue _object];
[_eventName, [_object, _effectNumber], _jipID] call CBA_fnc_globalEventJIP;
[_jipID, _object] call CBA_fnc_removeGlobalEventJIP;
};
case (GVAR(statusEffect_isGlobal) select _forEachIndex): {
TRACE_2("Sending Global Event",_object,_effectNumber);
[_eventName, [_object, _effectNumber]] call CBA_fnc_globalEvent;
};
default {
TRACE_2("Sending Target Event",_object,_effectNumber);
[_eventName, [_object, _effectNumber], _object] call CBA_fnc_targetEvent;
};
};

private _effectVarName = format [QGVAR(effect_%1), _effectName];
private _effectNumber = _object getVariable [_effectVarName, -1];

//We only do anything if the effect has been defined at some point in the game for this unit
PabstMirror marked this conversation as resolved.
Show resolved Hide resolved
TRACE_2("checking if event is nil",_effectName,_effectNumber);
if (_effectNumber != -1) then {
(GVAR(statusEffects) get toLowerANSI _effectName) params ["_isGlobal", "_sendJIP", "_eventName"];
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
switch (true) do {
case (_sendJIP): {
TRACE_2("Sending Global JIP Event",_object,_effectNumber);
private _jipID = format [QGVAR(effect_%1_%2), _eventName, hashValue _object];
[_eventName, [_object, _effectNumber], _jipID] call CBA_fnc_globalEventJIP;
[_jipID, _object] call CBA_fnc_removeGlobalEventJIP;
};
case (_isGlobal): {
TRACE_2("Sending Global Event",_object,_effectNumber);
[_eventName, [_object, _effectNumber]] call CBA_fnc_globalEvent;
};
default {
TRACE_2("Sending Target Event",_object,_effectNumber);
[_eventName, [_object, _effectNumber], _object] call CBA_fnc_targetEvent;
};
};
} forEach GVAR(statusEffect_Names);
};