Browse Source

Merge branch 'add-shield-health' of https://github.com/501st-Aux-Mod-Team/Aux-Mod-501st into add-shield-health

Erliens 3 years ago
parent
commit
2a2decc237

+ 4 - 2
addons - Copy/RD501_Main/functions/shield/fnc_shield_checkState.sqf

@@ -1,7 +1,7 @@
 params["_shield"];
 
 if(_shield isEqualTo objNull) exitWith {
-	diag_log format["[RD501][Shield] Specified shield is null while checking state"];
+	diag_log format["[RD501][Shield] Specified shield is null while checking state '%1", _shield];
 };
 
 private _maxHealth = _shield getVariable ["rd501_shield_maxHealth", false];
@@ -13,6 +13,7 @@ private _type = _shield getVariable ["rd501_shield_type", "REPUBLIC"];
 
 if(_isLowHealth) exitWith {
 	if(_currentHealth >= _threshold) then {
+		diag_log "[RD501][Shield] Shield is now normal health, updating texture on clients";
 		_shield setVariable["rd501_shield_isLowHealth", false];
 		
 		private _jipId = _shield getVariable ["rd501_shield_stateJipId", false];
@@ -31,11 +32,12 @@ if(_isLowHealth) exitWith {
 
 if!(_isLowHealth) exitWith {
 	if(_currentHealth < _threshold) then {
+		diag_log "[RD501][Shield] Shield is now normal health, updating texture on clients";
 		_shield setVariable["rd501_shield_isLowHealth", true];
 
 		private _jipId = _shield getVariable ["rd501_shield_stateJipId", false];
 		if(_jipId isEqualTo false) then {
-			_jipId = ["rd501_shield_normalHealth",[_shield, _type]] call CBA_fnc_globalEventJIP;
+			_jipId = ["rd501_shield_lowHealth",[_shield, _type]] call CBA_fnc_globalEventJIP;
 			_shield setVariable ["rd501_shield_stateJipId", _jipId, true];
 			[_jipId, _shield] call CBA_fnc_removeGlobalEventJIP;
 		}

+ 1 - 4
addons - Copy/RD501_Main/functions/shield/fnc_shield_init.sqf

@@ -71,10 +71,7 @@ _target setVariable ["rd501_shield_regenStartsAt", diag_tickTime];
 _target setVariable ["rd501_shield_stateJipId", false];
 
 _pfhId = [
-	{
-		params["_shield"];
-		[_shield] call rd501_fnc_shield_regenPerFrameHandler;
-	},
+	rd501_fnc_shield_regenPerFrameHandler,
 	1,
 	[_target]
 ] call CBA_fnc_addPerFrameHandler;

+ 4 - 1
addons - Copy/RD501_Main/functions/shield/fnc_shield_onDestroy.sqf

@@ -1,2 +1,5 @@
 params["_shield"];
-deleteVehicle _shield;
+if(local _shield) then {
+	diag_log format["[RD501][Shield] Deleting local shield '%1'", _shield];
+	deleteVehicle _shield;
+};

+ 1 - 1
addons - Copy/RD501_Main/functions/shield/fnc_shield_onHit.sqf

@@ -20,7 +20,7 @@ else
 {
 	// Set locally only to reduce network traffic
 	_target setVariable ["rd501_shield_currentHealth", _result];
-	[_shield] call rd501_fnc_shield_checkState;
+	[_target] call rd501_fnc_shield_checkState;
 	private _delay = _target getVariable["rd501_shield_regenDelay", 5];
 	_target setVariable ["rd501_shield_regenStartsAt", diag_tickTime + _delay];
 };

+ 1 - 0
addons - Copy/RD501_Main/functions/shield/fnc_shield_onLowHealth.sqf

@@ -1,4 +1,5 @@
 params["_shield", "_type"];
 
+diag_log format["[RD501][Shield] Updating texture for '%1'(%2) to low health", _shield, _type];
 private _textures = [_type] call rd501_fnc_shield_getTextureSet;
 _shield setObjectTexture [0, _textures select 0];

+ 1 - 0
addons - Copy/RD501_Main/functions/shield/fnc_shield_onNormalHealth.sqf

@@ -1,4 +1,5 @@
 params["_shield", "_type"];
 
+diag_log format["[RD501][Shield] Updating texture for '%1'(%2) to normal health", _shield, _type];
 private _textures = [_type] call rd501_fnc_shield_getTextureSet;
 _shield setObjectTexture [0, _textures select 1];

+ 7 - 2
addons - Copy/RD501_Main/functions/shield/fnc_shield_regenPerFrameHandler.sqf

@@ -2,20 +2,25 @@ params["_args", "_handle"];
 _args params["_shield"];
 
 if(_shield isEqualTo objNull || !alive _shield) exitWith {
+	diag_log format["[RD501][Shield] removed PFH %1", _shield];
 	[_handle] call CBA_fnc_removePerFrameHandler;
 };
 
 private _regenDelayTime = _shield getVariable ["rd501_shield_regenStartsAt", diag_tickTime];;
-if(diag_tickTime < _regenDelayTime) exitWith { };
+if(diag_tickTime < _regenDelayTime) exitWith {
+	diag_log format["[RD501][Shield] Still waiting for delay before regen on %1", _regenDelayTime];
+};
 
 private _maxHealth = _shield getVariable["rd501_shield_maxHealth", 100];
 private _currentHealth = _shield getVariable["rd501_shield_currentHealth", 100];
 private _regenAmount = _shield getVariable ["rd501_shield_regenPerSecond", 0];
 
-if(_currentHealth isEqualTo _maxHealth) exitWith { };
+if(_currentHealth isEqualTo _maxHealth) exitWith {  };
 
 private _newHealth = (_currentHealth + _regenAmount) min _maxHealth;
 
 _shield setVariable["rd501_shield_currentHealth", _newHealth];
 
+// diag_log format["[RD501][Shield] Regen health %1 to %2", _currentHealth, _newHealth]; 
+
 [_shield] call rd501_fnc_shield_checkState;