Dragging - Add additional weight checks on inventory modification (#9225)

* Allow run when carrying light-weight objects

* Use global var instead of macro

* add weight check, improve getWeight & conditions

* changes from review

* changes from review - postInit

* add param to ignore PhysX mass

* add settings

* BI issue tracker in comment

* change defaults, remove overweight setting

* remove public variable

* setting name changes

* updating case in statusEffect_addType

* move to XEH

* derp

* Add some extra checks for closed events

* Update XEH_postInit.sqf

* conditions

---------

Co-authored-by: Dystopian <sddex@ya.ru>
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
This commit is contained in:
Grim 2023-07-22 06:30:40 +03:00 committed by GitHub
parent ad1f50304f
commit e5dc124fe8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 144 additions and 34 deletions

View File

@ -19,12 +19,12 @@
//Status Effect EHs:
[QGVAR(setStatusEffect), {_this call FUNC(statusEffect_set)}] call CBA_fnc_addEventHandler;
["forceWalk", false, ["ace_advanced_fatigue", "ACE_SwitchUnits", "ACE_Attach", "ACE_dragging", "ACE_Explosives", "ACE_Ladder", "ACE_Sandbag", "ACE_refuel", "ACE_rearm", "ACE_Trenches", "ace_medical_fracture"]] call FUNC(statusEffect_addType);
["forceWalk", false, ["ace_advanced_fatigue", "ACE_SwitchUnits", "ACE_Attach", "ace_dragging", "ACE_Explosives", "ACE_Ladder", "ACE_Sandbag", "ACE_refuel", "ACE_rearm", "ACE_Trenches", "ace_medical_fracture"]] call FUNC(statusEffect_addType);
["blockSprint", false, ["ace_advanced_fatigue", "ace_dragging", "ace_medical_fracture"]] call FUNC(statusEffect_addType);
["setCaptive", true, [QEGVAR(captives,Handcuffed), QEGVAR(captives,Surrendered)]] call FUNC(statusEffect_addType);
["blockDamage", false, ["fixCollision", "ACE_cargo"]] call FUNC(statusEffect_addType);
["blockEngine", false, ["ACE_Refuel"]] call FUNC(statusEffect_addType);
["blockThrow", false, ["ACE_Attach", "ACE_concertina_wire", "ACE_dragging", "ACE_Explosives", "ACE_Ladder", "ACE_rearm", "ACE_refuel", "ACE_Sandbag", "ACE_Trenches", "ACE_tripod"]] call FUNC(statusEffect_addType);
["blockThrow", false, ["ACE_Attach", "ACE_concertina_wire", "ace_dragging", "ACE_Explosives", "ACE_Ladder", "ACE_rearm", "ACE_refuel", "ACE_Sandbag", "ACE_Trenches", "ACE_tripod"]] call FUNC(statusEffect_addType);
["setHidden", true, ["ace_unconscious"]] call FUNC(statusEffect_addType);
["blockRadio", false, [QEGVAR(captives,Handcuffed), QEGVAR(captives,Surrendered), "ace_unconscious"]] call FUNC(statusEffect_addType);
["blockSpeaking", false, ["ace_unconscious"]] call FUNC(statusEffect_addType);

View File

@ -3,6 +3,7 @@ PREP(canCarry);
PREP(canDrag);
PREP(canDrop);
PREP(canDrop_carry);
PREP(canRun_carry);
PREP(carryObject);
PREP(carryObjectPFH);
PREP(dragObject);

View File

@ -33,6 +33,43 @@ if (isNil QGVAR(maxWeightCarryRun)) then {
// display event handler
["MouseZChanged", {_this select 1 call FUNC(handleScrollWheel)}] call CBA_fnc_addDisplayHandler;
[QGVAR(carryingContainerClosed), {
params ["_container", "_owner"];
TRACE_2("carryingContainerClosed EH",_container,_owner);
if !(_owner getVariable [QGVAR(isCarrying), false]) exitWith { ERROR_1("not carrying - %1",_this) };
private _weight = 0;
if !(_container getVariable [QGVAR(ignoreWeightCarry), false]) then {
_weight = [_container] call FUNC(getWeight);
};
// drop the object if overweight
if (_weight > ACE_maxWeightCarry) exitWith {
[_owner, _container] call FUNC(dropObject_carry);
};
private _canRun = [_weight] call FUNC(canRun_carry);
// force walking based on weight
[_owner, "forceWalk", QUOTE(ADDON), !_canRun] call EFUNC(common,statusEffect_set);
[_owner, "blockSprint", QUOTE(ADDON), _canRun] call EFUNC(common,statusEffect_set);
}] call CBA_fnc_addEventHandler;
[QGVAR(draggingContainerClosed), {
params ["_container", "_owner"];
TRACE_2("draggingContainerClosed EH",_container,_owner);
if !(_owner getVariable [QGVAR(isDragging), false]) exitWith { ERROR_1("not dragging - %1",_this) };
private _weight = 0;
if !(_container getVariable [QGVAR(ignoreWeightDrag), false]) then {
_weight = [_container] call FUNC(getWeight);
};
// drop the object if overweight
if (_weight > ACE_maxWeightDrag) exitWith {
[_owner, _container] call FUNC(dropObject);
};
}] call CBA_fnc_addEventHandler;
//@todo Captivity?
//Add Keybind:

View File

@ -0,0 +1,20 @@
#include "script_component.hpp"
/*
* Author: LinkIsGrim
* Check if weight can be carried while running
*
* Arguments:
* 0: Weight <NUMBER>
*
* Return Value:
* Can the weight be carried while running? <BOOL>
*
* Example:
* [500] call ace_dragging_fnc_canRun_carry
*
* Public: No
*/
params ["_weight"];
GVAR(allowRunWithLightweight) && {_weight <= GVAR(maxWeightCarryRun)}

View File

@ -74,7 +74,7 @@ GVAR(currentHeightChange) = 0;
private _UAVCrew = _target call EFUNC(common,getVehicleUAVCrew);
// fixes not being able to move when in combat pace
[_unit, "forceWalk", "ACE_dragging", true] call EFUNC(common,statusEffect_set);
[_unit, "forceWalk", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);
if (_UAVCrew isNotEqualTo []) then {
{_target deleteVehicleCrew _x} count _UAVCrew;

View File

@ -51,7 +51,7 @@ if (_target isKindOf "CAManBase") then {
_unit removeWeapon "ACE_FakePrimaryWeapon";
[_unit, "blockThrow", "ACE_dragging", false] call EFUNC(common,statusEffect_set);
[_unit, "blockThrow", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set);
// prevent object from flipping inside buildings
if (_inBuilding) then {
@ -83,7 +83,7 @@ if (_target getVariable [QGVAR(isUAV), false]) then {
};
// fixes not being able to move when in combat pace
[_unit, "forceWalk", "ACE_dragging", false] call EFUNC(common,statusEffect_set);
[_unit, "forceWalk", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set);
// reset mass
private _mass = _target getVariable [QGVAR(originalMass), 0];

View File

@ -55,9 +55,9 @@ if (_previousWeaponIndex != -1) then {
_unit action ["SwitchWeapon", _unit, _unit, _previousWeaponIndex];
};
[_unit, "forceWalk", "ACE_dragging", false] call EFUNC(common,statusEffect_set);
[_unit, "blockSprint", "ACE_dragging", false] call EFUNC(common,statusEffect_set);
[_unit, "blockThrow", "ACE_dragging", false] call EFUNC(common,statusEffect_set);
[_unit, "forceWalk", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set);
[_unit, "blockSprint", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set);
[_unit, "blockThrow", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set);
// prevent object from flipping inside buildings
if (_inBuilding) then {

View File

@ -2,7 +2,7 @@
/*
* Author: L-H, edited by commy2, rewritten by joko // Jonas, re-rewritten by mharis001
* Returns the weight of the given object.
* Weight is calculated from the object's mass and its current inventory.
* Weight is calculated from the object's mass, its current inventory, and PhysX mass if applicable.
*
* Arguments:
* 0: Object <OBJECT>
@ -20,11 +20,14 @@ params ["_object"];
private _weight = loadAbs _object;
// Add the mass of the object itself
// The container object is generally of type SupplyX and has mass of zero
_weight = _weight + getNumber (configOf _object >> "mass");
if !(GVAR(skipContainerWeight)) then {
// Add the mass of the object itself
// getMass handles PhysX mass, this should be 0 for SupplyX containers and WeaponHolders
// Use originalMass in case we're checking weight for a carried object
_weight = _weight + ((_object getVariable [QGVAR(originalMass), getMass _object]));
};
// Contents of backpacks get counted twice (see https://github.com/acemod/ACE3/pull/8457#issuecomment-1062522447)
// Contents of backpacks get counted twice (https://github.com/acemod/ACE3/pull/8457#issuecomment-1062522447 and https://feedback.bistudio.com/T167469)
// This is a workaround until that is fixed on BI's end
{
_x params ["", "_container"];

View File

@ -46,6 +46,15 @@ if (_type in _initializedClasses) exitWith {};
_initializedClasses pushBack _type;
GVAR(initializedClasses_carry) = _initializedClasses;
[_type, "ContainerClosed", {
params ["_object"];
private _owner = _object getVariable [QEGVAR(common,owner), objNull];
TRACE_2("ContainerClosed-carry",_object,_owner);
if (isNull _owner) exitWith {};
if (_object isNotEqualTo (_owner getVariable [QGVAR(carriedObject), objNull])) exitWith {};
[QGVAR(carryingContainerClosed), [_object, _owner], _owner] call CBA_fnc_targetEvent;
}, false] call CBA_fnc_addClassEventHandler;
private _icon = [QUOTE(PATHTOF(UI\icons\box_carry.paa)), QUOTE(PATHTOF(UI\icons\person_carry.paa))] select (_object isKindOf "Man");
private _carryAction = [QGVAR(carry), localize LSTRING(Carry), _icon, {[_player, _target] call FUNC(startCarry)}, {[_player, _target] call FUNC(canCarry)}] call EFUNC(interact_menu,createAction);

View File

@ -46,6 +46,16 @@ if (_type in _initializedClasses) exitWith {};
_initializedClasses pushBack _type;
GVAR(initializedClasses) = _initializedClasses;
[_type, "ContainerClosed", {
params ["_object"];
private _owner = _object getVariable [QEGVAR(common,owner), objNull];
TRACE_2("ContainerClosed-drag",_object,_owner);
if (isNull _owner) exitWith {};
if (_object isNotEqualTo (_owner getVariable [QGVAR(draggedObject), objNull])) exitWith {};
[QGVAR(draggingContainerClosed), [_object, _owner], _owner] call CBA_fnc_targetEvent;
}, false] call CBA_fnc_addClassEventHandler;
private _icon = [QUOTE(PATHTOF(UI\icons\box_drag.paa)), QUOTE(PATHTOF(UI\icons\person_drag.paa))] select (_object isKindOf "Man");
private _dragAction = [QGVAR(drag), localize LSTRING(Drag), _icon, {[_player, _target] call FUNC(startDrag)}, {[_player, _target] call FUNC(canDrag)}] call EFUNC(interact_menu,createAction);

View File

@ -22,10 +22,13 @@ TRACE_2("params",_unit,_target);
private _weight = [_target] call FUNC(getWeight);
// exempt from weight check if object has override variable set
if (!GETVAR(_target,GVAR(ignoreWeightCarry),false) && {
_weight > GETMVAR(ACE_maxWeightCarry,1E11)
}) exitWith {
// exit if object weight is over global var value
private _weight = 0;
if !(_target getVariable [QGVAR(ignoreWeightCarry), false]) then {
_weight = [_target] call FUNC(getWeight);
};
// exit if object weight is over global var value
if (_weight > GETMVAR(ACE_maxWeightCarry,1E11)) exitWith {
[localize LSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured);
};
@ -58,23 +61,18 @@ if (_target isKindOf "CAManBase") then {
_unit action ["SwitchWeapon", _unit, _unit, 299];
[_unit, "AmovPercMstpSnonWnonDnon", 0] call EFUNC(common,doAnimation);
// objects other than containers have calculated weight == 0 so we use getMass
if (-1 == ["ReammoBox_F", "WeaponHolder", "WeaponHolderSimulated"] findIf {_target isKindOf _x}) then {
_weight = getMass _target;
};
if (_weight > GVAR(maxWeightCarryRun)) then {
[_unit, "forceWalk", "ACE_dragging", true] call EFUNC(common,statusEffect_set);
} else {
[_unit, "blockSprint", "ACE_dragging", true] call EFUNC(common,statusEffect_set);
};
private _canRun = [_weight] call FUNC(canRun_carry);
// only force walking if we're overweight
[_unit, "forceWalk", QUOTE(ADDON), !_canRun] call EFUNC(common,statusEffect_set);
[_unit, "blockSprint", QUOTE(ADDON), _canRun] call EFUNC(common,statusEffect_set);
};
[_unit, "blockThrow", "ACE_dragging", true] call EFUNC(common,statusEffect_set);
[_unit, "blockThrow", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);
// prevent multiple players from accessing the same object
[_unit, _target, true] call EFUNC(common,claim);
// prevents draging and carrying at the same time
_unit setVariable [QGVAR(isCarrying), true, true];

View File

@ -20,11 +20,13 @@ params ["_unit", "_target"];
TRACE_2("params",_unit,_target);
// exempt from weight check if object has override variable set
if (!GETVAR(_target,GVAR(ignoreWeightDrag),false) && {
private _weight = [_target] call FUNC(getWeight);
_weight > GETMVAR(ACE_maxWeightDrag,1E11)
}) exitWith {
// exit if object weight is over global var value
private _weight = 0;
if !(_target getVariable [QGVAR(ignoreWeightDrag), false]) then {
_weight = [_target] call FUNC(getWeight);
};
// exit if object weight is over global var value
if (_weight > GETMVAR(ACE_maxWeightDrag,1E11)) exitWith {
[localize LSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured);
};
@ -57,7 +59,7 @@ if !(GVAR(dragAndFire)) then {
// Save the weapon so we can monitor if it changes
_unit setVariable [QGVAR(currentWeapon), currentWeapon _unit];
[_unit, "blockThrow", "ACE_dragging", true] call EFUNC(common,statusEffect_set);
[_unit, "blockThrow", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);
// prevent multiple players from accessing the same object
[_unit, _target, true] call EFUNC(common,claim);

View File

@ -6,3 +6,21 @@
true,
false
] call CBA_fnc_addSetting;
[
QGVAR(allowRunWithLightweight),
"CHECKBOX",
[LSTRING(allowRunWithLightweight_DisplayName), LSTRING(allowRunWithLightweight_Description)],
localize LSTRING(SettingsName),
true,
true
] call CBA_fnc_addSetting;
[
QGVAR(skipContainerWeight),
"CHECKBOX",
[LSTRING(skipContainerWeight_DisplayName), LSTRING(skipContainerWeight_Description)],
localize LSTRING(SettingsName),
false,
true
] call CBA_fnc_addSetting;

View File

@ -147,5 +147,17 @@
<Chinesesimp>允许玩家在拖动时开火。</Chinesesimp>
<Korean>플레이어가 무기를 끄는 동안에 무기를 사용할 수 있게합니다.</Korean>
</Key>
<Key ID="STR_ACE_Dragging_allowRunWithLightweight_DisplayName">
<English>Allow Running with Lightweight Objects</English>
</Key>
<Key ID="STR_ACE_Dragging_allowRunWithLightweight_Description">
<English>Allow the player to run when carrying lightweight objects.</English>
</Key>
<Key ID="STR_ACE_Dragging_skipContainerWeight_DisplayName">
<English>Skip Object Weight</English>
</Key>
<Key ID="STR_ACE_Dragging_skipContainerWeight_Description">
<English>Determines whether object's weight is added onto weight calculations.</English>
</Key>
</Package>
</Project>