Arsenal - Fix virtual non-weapon magazines in inventory being treated as unique (#9309)

* sigh

* add comment in scanConfig

* fix misc magazines

* improve magazine misc items check

* check player loadout first for uniqueItems
This commit is contained in:
Grim 2023-08-19 23:38:06 -03:00 committed by GitHub
parent 4b7ee55588
commit 007995612d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 115 additions and 103 deletions

View File

@ -141,6 +141,7 @@ private _isTool = false;
} forEach configProperties [_cfgWeapons, _filterFunction, true];
// Get all grenades
// Explicitly don't look at scope for these, we want hidden items to be sorted as grenades/explosives properly
private _grenadeList = createHashMap;
{
@ -154,11 +155,17 @@ private _putList = createHashMap;
_putList insert [true, (getArray (_cfgWeapons >> "Put" >> _x >> "magazines")) apply {_x call EFUNC(common,getConfigName)}, []];
} forEach getArray (_cfgWeapons >> "Put" >> "muzzles");
// Get all magazine misc items
private _magazineMiscItems = createHashMap;
{
_magazineMiscItems set [configName _x, nil];
} forEach ((toString {getNumber (_x >> "ACE_isUnique") == 1}) configClasses _cfgMagazines);
// Remove invalid/non-existent entries
_grenadeList deleteAt "";
_putList deleteAt "";
private _magazineMiscItems = createHashMap;
_magazineMiscItems deleteAt "";
// Get all other grenades, explosives (and similar) and magazines
{
@ -166,9 +173,8 @@ private _magazineMiscItems = createHashMap;
switch (true) do {
// "Misc. items" magazines (e.g. spare barrels, intel, photos)
case (getNumber (_x >> "ACE_isUnique") isEqualTo 1): {
case (_x in _magazineMiscItems): {
(_configItems get IDX_VIRT_MISC_ITEMS) set [_className, nil];
_magazineMiscItems set [_className, nil];
if (getNumber (_x >> "ACE_isTool") isEqualTo 1) then {_toolList set [_className, nil]};
};
// Grenades

View File

@ -31,14 +31,111 @@ private _cfgMagazines = configFile >> "CfgMagazines";
private _cfgVehicles = configFile >> "CfgVehicles";
private _cfgGlasses = configFile >> "CfgGlasses";
// Remove unique equipment in every panel
private _items = createHashMap;
private _fnc_uniqueEquipment = {
params ["_items", "_item", ["_removeAllUniqueItems", true]];
// Remove all unique equipment from tab
if (_removeAllUniqueItems) then {
private _itemsToDelete = [];
{
if (!isNil "_y") then {
_itemsToDelete pushBack _x;
};
} forEach _items;
{
_items deleteAt _x;
GVAR(virtualItemsFlatAll) deleteAt _x;
} forEach _itemsToDelete;
};
// Add item as a unique equipment
if (_item != "") then {
_items set [_item, true, true];
GVAR(virtualItemsFlatAll) set [_item, true, true];
};
};
// Add the items the player has to virtualItems as unique equipment
{
switch (_forEachIndex) do {
// Primary weapon, Secondary weapon, Handgun weapon, Binoculars
case IDX_LOADOUT_PRIMARY_WEAPON;
case IDX_LOADOUT_SECONDARY_WEAPON;
case IDX_LOADOUT_HANDGUN_WEAPON;
case IDX_LOADOUT_BINO: {
_x params [["_weapon", ""], ["_muzzle", ""], ["_flashlight", ""], ["_optics", ""], ["_primaryMagazine", []], ["_secondaryMagazine", []], ["_bipod", ""]];
// If bino, add it in a different place than regular weapons
_items = if (_forEachIndex != IDX_LOADOUT_BINO) then {
(GVAR(virtualItems) get IDX_VIRT_WEAPONS) get _forEachIndex
} else {
GVAR(virtualItems) get IDX_VIRT_BINO
};
// Remove all unique equipment in tab; Add weapon as a unique equipment
[_items, _weapon call FUNC(baseWeapon)] call _fnc_uniqueEquipment;
private _removeUniqueItems = _forEachIndex == IDX_LOADOUT_PRIMARY_WEAPON;
// Add weapon attachments
{
// Remove all unique equipment in tab; Add weapon attachment as a unique equipment
[(GVAR(virtualItems) get IDX_VIRT_ATTACHMENTS) get _forEachIndex, _x call FUNC(baseWeapon), _removeUniqueItems] call _fnc_uniqueEquipment;
} forEach [_optics, _flashlight, _muzzle, _bipod];
// Add magazines
{
// Remove all unique equipment in tab; Add magazine as unique equipment
[GVAR(virtualItems) get IDX_VIRT_ITEMS_ALL, _x param [0, ""], _removeUniqueItems && {_forEachIndex == 0}] call _fnc_uniqueEquipment;
} forEach [_primaryMagazine, _secondaryMagazine];
};
// Uniform, vest, backpack
case IDX_LOADOUT_UNIFORM;
case IDX_LOADOUT_VEST;
case IDX_LOADOUT_BACKPACK: {
_x params [["_containerClass", ""]];
// Remove all unique equipment in tab; Add container as a unique equipment
[GVAR(virtualItems) get (_forEachIndex + 1), _containerClass] call _fnc_uniqueEquipment;
};
// Helmet
case IDX_LOADOUT_HEADGEAR: {
// Remove all unique equipment in tab; Add item as a unique equipment
[GVAR(virtualItems) get IDX_VIRT_HEADGEAR, _x] call _fnc_uniqueEquipment;
};
// Facewear
case IDX_LOADOUT_GOGGLES: {
// Remove all unique equipment in tab; Add item as a unique equipment
[GVAR(virtualItems) get IDX_VIRT_GOGGLES, _x] call _fnc_uniqueEquipment;
};
// Assigned items: Map, Compass, Watch, GPS / UAV Terminal, Radio, NVGs
case IDX_LOADOUT_ASSIGNEDITEMS: {
{
// Order of storing virtualItems is different than what getUnitLoadout returns, so do some math
// Remove all unique equipment in tab; Add item as a unique equipment
[GVAR(virtualItems) get (IDX_VIRT_NVG + ([2, 6, 4, 3, 5, 0] select _forEachIndex)), _x] call _fnc_uniqueEquipment;
} forEach _x;
};
};
} forEach (getUnitLoadout GVAR(center)); // Only need items, not extended loadout
private _isMagazine = false;
private _isWeapon = false;
private _isGrenade = false;
private _isPut = false;
private _isMiscItem = false;
private _config = configNull;
private _simulationType = "";
private _configItemInfo = "";
private _hasItemInfo = false;
private _itemInfoType = 0;
private _isMiscItem = false;
{
_isMagazine = isClass (_cfgMagazines >> _x);
@ -48,33 +145,36 @@ private _isMiscItem = false;
// Magazines
case (_isMagazine): {
_config = _cfgMagazines >> _x;
_isGrenade = _x in (uiNamespace getVariable QGVAR(grenadeCache));
_isPut = _x in (uiNamespace getVariable QGVAR(putCache));
_isMiscItem = _x in (uiNamespace getVariable QGVAR(magazineMiscItems));
switch (true) do {
// "Misc. items" magazines (e.g. spare barrels, intel, photos)
case (
!(_x in (GVAR(virtualItems) get IDX_VIRT_MISC_ITEMS)) &&
{_x in (uiNamespace getVariable QGVAR(magazineMiscItems)) ||
{getNumber (_config >> "ACE_isUnique") == 1}}
{_isMiscItem}
): {
(GVAR(virtualItems) get IDX_VIRT_UNIQUE_MISC_ITEMS) set [_x, nil];
};
// Grenades
case (
!(_x in (GVAR(virtualItems) get IDX_VIRT_GRENADES)) &&
{_x in (uiNamespace getVariable QGVAR(grenadeCache))}
{_isGrenade}
): {
(GVAR(virtualItems) get IDX_VIRT_UNIQUE_GRENADES) set [_x, nil];
};
// Explosives
case (
!(_x in (GVAR(virtualItems) get IDX_VIRT_EXPLOSIVES)) &&
{_x in (uiNamespace getVariable QGVAR(putCache))}
{_isPut}
): {
(GVAR(virtualItems) get IDX_VIRT_UNIQUE_EXPLOSIVES) set [_x, nil];
};
// Primary, Handgun, Secondary weapon magazines
case (
!(_x in (GVAR(virtualItems) get IDX_VIRT_ITEMS_ALL)) &&
{!_isGrenade && {!_isPut} && {!_isMiscItem}} &&
{_x in (_configItems get IDX_VIRT_ITEMS_ALL) ||
{getNumber (_config >> QGVAR(hide)) == -1} ||
{getNumber (_config >> "type") in [TYPE_MAGAZINE_PRIMARY_AND_THROW, TYPE_MAGAZINE_SECONDARY_AND_PUT, 1536, TYPE_MAGAZINE_HANDGUN_AND_GL, TYPE_MAGAZINE_MISSILE]}}
@ -178,97 +278,3 @@ private _isMiscItem = false;
};
};
} forEach (keys ([GVAR(center), 0, 3, 3, 3, false] call EFUNC(common,uniqueUnitItems))); // Get all items from unit
// Remove unique equipment in every panel
private _items = createHashMap;
private _fnc_uniqueEquipment = {
params ["_items", "_item", ["_removeAllUniqueItems", true]];
// Remove all unique equipment from tab
if (_removeAllUniqueItems) then {
private _itemsToDelete = [];
{
if (!isNil "_y") then {
_itemsToDelete pushBack _x;
};
} forEach _items;
{
_items deleteAt _x;
GVAR(virtualItemsFlatAll) deleteAt _x;
} forEach _itemsToDelete;
};
// Add item as a unique equipment
if (_item != "") then {
_items set [_item, true, true];
GVAR(virtualItemsFlatAll) set [_item, true, true];
};
};
// Add the items the player has to virtualItems as unique equipment
{
switch (_forEachIndex) do {
// Primary weapon, Secondary weapon, Handgun weapon, Binoculars
case IDX_LOADOUT_PRIMARY_WEAPON;
case IDX_LOADOUT_SECONDARY_WEAPON;
case IDX_LOADOUT_HANDGUN_WEAPON;
case IDX_LOADOUT_BINO: {
_x params [["_weapon", ""], ["_muzzle", ""], ["_flashlight", ""], ["_optics", ""], ["_primaryMagazine", []], ["_secondaryMagazine", []], ["_bipod", ""]];
// If bino, add it in a different place than regular weapons
_items = if (_forEachIndex != IDX_LOADOUT_BINO) then {
(GVAR(virtualItems) get IDX_VIRT_WEAPONS) get _forEachIndex
} else {
GVAR(virtualItems) get IDX_VIRT_BINO
};
// Remove all unique equipment in tab; Add weapon as a unique equipment
[_items, _weapon call FUNC(baseWeapon)] call _fnc_uniqueEquipment;
private _removeUniqueItems = _forEachIndex == IDX_LOADOUT_PRIMARY_WEAPON;
// Add weapon attachments
{
// Remove all unique equipment in tab; Add weapon attachment as a unique equipment
[(GVAR(virtualItems) get IDX_VIRT_ATTACHMENTS) get _forEachIndex, _x call FUNC(baseWeapon), _removeUniqueItems] call _fnc_uniqueEquipment;
} forEach [_optics, _flashlight, _muzzle, _bipod];
// Add magazines
{
// Remove all unique equipment in tab; Add magazine as unique equipment
[GVAR(virtualItems) get IDX_VIRT_ITEMS_ALL, _x param [0, ""], _removeUniqueItems && {_forEachIndex == 0}] call _fnc_uniqueEquipment;
} forEach [_primaryMagazine, _secondaryMagazine];
};
// Uniform, vest, backpack
case IDX_LOADOUT_UNIFORM;
case IDX_LOADOUT_VEST;
case IDX_LOADOUT_BACKPACK: {
_x params [["_containerClass", ""]];
// Remove all unique equipment in tab; Add container as a unique equipment
[GVAR(virtualItems) get (_forEachIndex + 1), _containerClass] call _fnc_uniqueEquipment;
};
// Helmet
case IDX_LOADOUT_HEADGEAR: {
// Remove all unique equipment in tab; Add item as a unique equipment
[GVAR(virtualItems) get IDX_VIRT_HEADGEAR, _x] call _fnc_uniqueEquipment;
};
// Facewear
case IDX_LOADOUT_GOGGLES: {
// Remove all unique equipment in tab; Add item as a unique equipment
[GVAR(virtualItems) get IDX_VIRT_GOGGLES, _x] call _fnc_uniqueEquipment;
};
// Assigned items: Map, Compass, Watch, GPS / UAV Terminal, Radio, NVGs
case IDX_LOADOUT_ASSIGNEDITEMS: {
{
// Order of storing virtualItems is different than what getUnitLoadout returns, so do some math
// Remove all unique equipment in tab; Add item as a unique equipment
[GVAR(virtualItems) get (IDX_VIRT_NVG + ([2, 6, 4, 3, 5, 0] select _forEachIndex)), _x] call _fnc_uniqueEquipment;
} forEach _x;
};
};
} forEach (getUnitLoadout GVAR(center)); // Only need items, not extended loadout