Field Rations - Basic CfgMagazines support (#9008)

* Add basic CfgMagazines support for field_rations

* Update headers

* Fix CBA context menu

* Add backward compatiblity to fnc_consumeItem

* Fix item refill not finishing

Whoopsie.

* Revert "Add backward compatiblity to fnc_consumeItem"

In hindsight it's not necessary, this is not public function.
This commit is contained in:
Filip Maciejewski 2022-09-06 13:21:45 +02:00 committed by GitHub
parent 508e669e05
commit f734fa9e86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 87 additions and 46 deletions

View File

@ -89,7 +89,8 @@ if !(hasInterface) exitWith {};
],
{
params ["_unit", "", "_item"];
[objNull, _unit, _item] call FUNC(consumeItem);
private _itemConfig = configFile >> "CfgWeapons" >> _item;
[objNull, _unit, [_item, _itemConfig, false]] call FUNC(consumeItem);
false
}
] call CBA_fnc_addItemContextMenuOption;

View File

@ -6,23 +6,30 @@
* Arguments:
* 0: Water source <OBJECT>
* 1: Player <OBJECT>
* 2: Item classname <STRING>
* 2: Item data <ARRAY>
* 0: Item classname <STRING>
* 1: Item config <CONFIG>
* 2: Is item magazine <BOOL>
*
* Return Value:
* Can refill item <BOOL>
*
* Example:
* [_source, _player, "ACE_WaterBottle_Empty"] call ace_field_rations_fnc_canRefillItem
* [_source, _player, ["ACE_WaterBottle_Empty", configFile >> "CfgWeapons" >> "ACE_WaterBottle_Empty", false]] call ace_field_rations_fnc_canRefillItem
*
* Public: No
*/
params ["_source", "_player", "_item"];
params ["_source", "_player", "_itemData"];
_itemData params ["_item", "_itemConfig", "_isMagazine"];
alive _source
&& {XGVAR(waterSourceActions) != 0}
&& {_item in (_player call EFUNC(common,uniqueItems))}
&& {
(_isMagazine && {_item in magazines _player})
|| {_item in (_player call EFUNC(common,uniqueItems))}
}
&& {
private _water = _source call FUNC(getRemainingWater);
_water == REFILL_WATER_INFINITE || {_water >= getNumber (configFile >> "CfgWeapons" >> _item >> QXGVAR(refillAmount))}
_water == REFILL_WATER_INFINITE || {_water >= getNumber (_itemConfig >> QXGVAR(refillAmount))}
}

View File

@ -6,21 +6,23 @@
* Arguments:
* 0: Target (not used) <OBJECT>
* 1: Player <OBJECT>
* 2: Item classname <STRING>
* 2: Item data <ARRAY>
* 0: Item classname <STRING>
* 1: Item config <CONFIG>
* 2: Is item magazine <BOOL>
*
* Return Value:
* None
*
* Example:
* [objNull, ACE_player, "ACE_WaterBottle"] call ace_field_rations_fnc_consumeItem
* [objNull, ACE_player, "["ACE_WaterBottle_Empty", configFile >> "CfgWeapons" >> "ACE_WaterBottle_Empty", false]] call ace_field_rations_fnc_consumeItem
*
* Public: No
*/
params ["", "_player", "_consumeItem"];
TRACE_2("Consume item started",_player,_consumeItem);
private _config = configFile >> "CfgWeapons" >> _consumeItem;
params ["", "_player", "_consumeData"];
_consumeData params ["_consumeItem", "_config", "_isMagazine"];
TRACE_3("Consume item started",_player,_consumeItem,_config);
// Get consume time for item
private _consumeTime = getNumber (_config >> QXGVAR(consumeTime));
@ -70,11 +72,15 @@ private _soundPlayed = if (_consumeAnim != "" && {vehicle _player == _player &&
private _fnc_onSuccess = {
params ["_args"];
_args params ["_player", "_consumeItem", "_replacementItem", "_thirstQuenched", "_hungerSatiated"];
_args params ["_player", "_consumeItem", "_replacementItem", "_thirstQuenched", "_hungerSatiated", "", "", "", "_isMagazine"];
TRACE_1("Consume item successful",_args);
// Remove consumed item
if (_isMagazine) then {
_player removeMagazineGlobal _consumeItem;
} else {
_player removeItem _consumeItem;
};
// Add replacement item if needed
if (_replacementItem != "") then {
@ -92,7 +98,7 @@ private _fnc_onSuccess = {
_player setVariable [QXGVAR(hunger), (_hunger - _hungerSatiated) max 0];
};
["acex_rationConsumed", [_player, _consumeItem, _replacementItem, _thirstQuenched, _hungerSatiated]] call CBA_fnc_localEvent;
["acex_rationConsumed", [_player, _consumeItem, _replacementItem, _thirstQuenched, _hungerSatiated, _isMagazine]] call CBA_fnc_localEvent;
_player setVariable [QGVAR(previousAnim), nil];
};
@ -115,7 +121,7 @@ private _fnc_onFailure = {
private _fnc_condition = {
params ["_args"];
_args params ["_player", "_consumeItem", "", "", "", "_consumeAnim", "_consumeSound", "_soundPlayed"];
_args params ["_player", "_consumeItem", "", "", "", "_consumeAnim", "_consumeSound", "_soundPlayed", "_isMagazine"];
// Attempt to sync sound with animation start
if (!_soundPlayed && {_consumeSound != "" && {_consumeAnim == "" || {animationState _player == _consumeAnim}}}) then {
@ -123,7 +129,10 @@ private _fnc_condition = {
_args set [7, true];
};
_consumeItem in (_player call EFUNC(common,uniqueItems))
if (_isMagazine) exitWith {
_consumeItem in magazines _player // return
};
_consumeItem in (_player call EFUNC(common,uniqueItems)) // return
};
[
@ -136,7 +145,8 @@ private _fnc_condition = {
_hungerSatiated,
_consumeAnim,
_consumeSound,
_soundPlayed
_soundPlayed,
_isMagazine
],
_fnc_onSuccess,
_fnc_onFailure,

View File

@ -22,18 +22,26 @@ private _fnc_getActions = {
private _actions = [];
private _cfgWeapons = configFile >> "CfgWeapons";
private _cfgMagazines = configFile >> "CfgMagazines";
{
private _config = _cfgWeapons >> _x;
if (getNumber (_config >> QXGVAR(thirstQuenched)) > 0 || {getNumber (_config >> QXGVAR(hungerSatiated)) > 0}) then {
private _displayName = getText (_config >> "displayName");
private _picture = getText (_config >> "picture");
_x params ["_config", "_items"];
private _isMagazine = _config == _cfgMagazines;
{
private _itemConfig = _config >> _x;
if (getNumber (_itemConfig >> QXGVAR(thirstQuenched)) > 0 || {getNumber (_itemConfig >> QXGVAR(hungerSatiated)) > 0}) then {
private _displayName = getText (_itemConfig >> "displayName");
private _picture = getText (_itemConfig >> "picture");
// Exec next frame so closing interaction menu doesn't block progressBar
private _action = [_x, _displayName, _picture, {[FUNC(consumeItem), _this] call CBA_fnc_execNextFrame}, {true}, {}, _x] call EFUNC(interact_menu,createAction);
private _action = [_x, _displayName, _picture, {[FUNC(consumeItem), _this] call CBA_fnc_execNextFrame}, {true}, {}, [_x, _itemConfig, _isMagazine]] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _player];
};
} forEach (_player call EFUNC(common,uniqueItems));
} forEach _items;
} forEach [
[_cfgWeapons, _player call EFUNC(common,uniqueItems)],
[_cfgMagazines, [magazines _player] call EFUNC(common,uniqueElements)]
];
_actions
};

View File

@ -24,15 +24,23 @@ if (_water == 0 || {_water == REFILL_WATER_DISABLED}) exitWith {[]};
private _actions = [];
private _cfgWeapons = configFile >> "CfgWeapons";
private _cfgMagazines = configFile >> "CfgMagazines";
{
private _config = _cfgWeapons >> _x;
if (getText (_config >> QXGVAR(refillItem)) != "" && {_water == REFILL_WATER_INFINITE || {getNumber (_config >> QXGVAR(refillAmount)) <= _water}}) then {
private _displayName = format ["%1: %2", LLSTRING(Refill), getText (_config >> "displayName")];
private _picture = getText (_config >> "picture");
private _action = [_x, _displayName, _picture, FUNC(refillItem), FUNC(canRefillItem), {}, _x] call EFUNC(interact_menu,createAction);
_x params ["_config", "_items"];
private _isMagazine = _config == _cfgMagazines;
{
private _itemConfig = _config >> _x;
if (getText (_itemConfig >> QXGVAR(refillItem)) != "" && {_water == REFILL_WATER_INFINITE || {getNumber (_itemConfig >> QXGVAR(refillAmount)) <= _water}}) then {
private _displayName = format ["%1: %2", LLSTRING(Refill), getText (_itemConfig >> "displayName")];
private _picture = getText (_itemConfig >> "picture");
private _action = [_x, _displayName, _picture, FUNC(refillItem), FUNC(canRefillItem), {}, [_x, _itemConfig, _isMagazine]] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _source];
};
} forEach (_player call EFUNC(common,uniqueItems));
} forEach _items;
} forEach [
[_cfgWeapons, _player call EFUNC(common,uniqueItems)],
[_cfgMagazines, [magazines _player] call EFUNC(common,uniqueElements)]
];
_actions

View File

@ -6,22 +6,24 @@
* Arguments:
* 0: Water source <OBJECT>
* 1: Player <OBJECT>
* 2: Item classname <STRING>
* 2: Item data <ARRAY>
* 0: Item classname <STRING>
* 1: Item config <CONFIG>
* 2: Is item magazine <BOOL>
*
* Return Value:
* None
*
* Example:
* [_source, _player, "ACE_WaterBottle_Empty"] call ace_field_rations_fnc_refillItem
* [_source, _player, ["ACE_WaterBottle_Empty", configFile >> "CfgWeapons" >> "ACE_WaterBottle_Empty", false]] call ace_field_rations_fnc_refillItem
*
* Public: No
*/
params ["_source", "_player", "_item"];
params ["_source", "_player", "_itemData"];
_itemData params ["_item", "_config", "_isMagazine"];
TRACE_3("Item refill started",_source,_player,_item);
private _config = configFile >> "CfgWeapons" >> _item;
// Get config values for refill
private _refillItem = getText (_config >> QXGVAR(refillItem));
private _refillAmount = getNumber (_config >> QXGVAR(refillAmount));
@ -29,11 +31,16 @@ private _refillTime = getNumber (_config >> QXGVAR(refillTime));
private _fnc_onSuccess = {
params ["_args"];
_args params ["_source", "_player", "_item", "_refillItem", "_refillAmount"];
_args params ["_source", "_player", "_itemData", "_refillItem", "_refillAmount", "_itemData"];
_itemData params ["_item", "", "_isMagazine"];
TRACE_1("Refill item successful",_args);
// Replace item with refilled one
if (_isMagazine) then {
_player removeMagazineGlobal _item;
} else {
_player removeItem _item;
};
[_player, _refillItem] call EFUNC(common,addToInventory);
// Update remaining water in source
@ -43,7 +50,7 @@ private _fnc_onSuccess = {
[_source, _waterInSource] call FUNC(setRemainingWater);
};
["acex_rationRefilled", [_source, _player, _item, _refillItem, _refillAmount]] call CBA_fnc_localEvent;
["acex_rationRefilled", [_source, _player, _item, _refillItem, _refillAmount, _isMagazine]] call CBA_fnc_localEvent;
// Show refilled item hint
private _picture = getText (configFile >> "CfgWeapons" >> _refillItem >> "picture");
@ -64,7 +71,7 @@ private _fnc_condition = {
[
_source,
_player,
_item,
_itemData,
_refillItem,
_refillAmount
],

View File

@ -45,8 +45,8 @@ Config Name | Type | Description
Event Name | Passed Parameter(s) | Locality | Description
---------- | ------------------- | -------- | -----------
`acex_rationConsumed` | [_player, _consumeItem, _replacementItem, _thirstQuenched, _hungerSatiated] | Local | Item consumed
`acex_rationRefilled` | [_source, _player, _item, _refillItem, _refillAmount] | Local | Item refilled
`acex_rationConsumed` | [_player, _consumeItem, _replacementItem, _thirstQuenched, _hungerSatiated, _isMagazine] | Local | Item consumed
`acex_rationRefilled` | [_source, _player, _item, _refillItem, _refillAmount, _isMagazine] | Local | Item refilled
## 3. Scripting