Skip to content

Commit 4f4adda

Browse files
committed
tf2: fix shields not restoring charge with pickups when mid charge
Source: ValveSoftware/source-sdk-2013#1896
1 parent b469af0 commit 4f4adda

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/game/server/tf/entity_ammopack.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "tf_shareddefs.h"
1010
#include "tf_player.h"
1111
#include "tf_team.h"
12+
#include "tf_wearable_weapons.h"
1213
#include "engine/IEngineSound.h"
1314
#include "entity_ammopack.h"
1415
#include "tf_gamestats.h"
@@ -104,7 +105,16 @@ bool CAmmoPack::MyTouch( CBasePlayer *pPlayer )
104105
{
105106
flPackRatio *= 0.2;
106107
}
108+
107109
pTFPlayer->m_Shared.SetDemomanChargeMeter( flCurrentCharge + flPackRatio * 100.0f );
110+
111+
// Update the shield charge condition to reflect the ammo pack increase
112+
if ( pTFPlayer->m_Shared.InCond( TF_COND_SHIELD_CHARGE ) )
113+
{
114+
float flChargeTime = ( pTFPlayer->m_Shared.GetDemomanChargeMeter() / 100.0f ) + flPackRatio;
115+
116+
pTFPlayer->m_Shared.SetConditionDuration( TF_COND_SHIELD_CHARGE, flChargeTime );
117+
}
108118
bSuccess = true;
109119
}
110120
}

src/game/server/tf/tf_ammo_pack.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "ammodef.h"
1111
#include "tf_gamerules.h"
1212
#include "explode.h"
13+
#include "tf_wearable_weapons.h"
1314
#include "tf_gamestats.h"
1415

1516
// memdbgon must be the last include file in a .cpp file!!!
@@ -395,7 +396,17 @@ void CTFAmmoPack::PackTouch( CBaseEntity *pOther )
395396
{
396397
m_flAmmoRatio *= 0.2;
397398
}
399+
398400
pPlayer->m_Shared.SetDemomanChargeMeter( flCurrentCharge + m_flAmmoRatio * 100.0f );
401+
402+
// Update the shield charge condition to reflect the ammo pack increase
403+
if ( pPlayer->m_Shared.InCond( TF_COND_SHIELD_CHARGE ) )
404+
{
405+
float flChargeTime = (pPlayer->m_Shared.GetDemomanChargeMeter() / 100.0f ) + m_flAmmoRatio;
406+
407+
pPlayer->m_Shared.SetConditionDuration( TF_COND_SHIELD_CHARGE, flChargeTime );
408+
}
409+
399410
iAmmoTaken++;
400411
}
401412
}

src/game/server/tf/tf_player.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4100,6 +4100,17 @@ void CTFPlayer::Regenerate( bool bRefillHealthAndAmmo /*= true*/ )
41004100
m_Shared.SetScoutEnergyDrinkMeter( 100.0f );
41014101
m_Shared.SetDemomanChargeMeter( 100.0f );
41024102

4103+
// Update the shield charge condition to reflect the reset for charge
4104+
if ( m_Shared.InCond(TF_COND_SHIELD_CHARGE ) )
4105+
{
4106+
float flChargeTime = 1.5f;
4107+
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( this, flChargeTime, mod_charge_time );
4108+
4109+
flChargeTime = m_Shared.GetConditionDuration( TF_COND_SHIELD_CHARGE ) + flChargeTime;
4110+
4111+
m_Shared.SetConditionDuration( TF_COND_SHIELD_CHARGE, flChargeTime );
4112+
}
4113+
41034114
// Selectively refill the item effect meters if they're allowed
41044115
for( int i = FIRST_LOADOUT_SLOT_WITH_CHARGE_METER; i <= LAST_LOADOUT_SLOT_WITH_CHARGE_METER; ++i )
41054116
{
@@ -14851,6 +14862,17 @@ void CTFPlayer::CheatImpulseCommands( int iImpulse )
1485114862
m_Shared.m_flRageMeter = 100.f;
1485214863
m_Shared.SetDemomanChargeMeter( 100.f );
1485314864

14865+
// Update the shield charge condition to reflect the reset for charge
14866+
if ( m_Shared.InCond( TF_COND_SHIELD_CHARGE ) )
14867+
{
14868+
float flChargeTime = 1.5f;
14869+
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( this, flChargeTime, mod_charge_time );
14870+
14871+
flChargeTime = m_Shared.GetConditionDuration( TF_COND_SHIELD_CHARGE ) + flChargeTime;
14872+
14873+
m_Shared.SetConditionDuration( TF_COND_SHIELD_CHARGE, flChargeTime );
14874+
}
14875+
1485414876
for( int i = FIRST_LOADOUT_SLOT_WITH_CHARGE_METER; i <= LAST_LOADOUT_SLOT_WITH_CHARGE_METER; ++i )
1485514877
{
1485614878
m_Shared.SetItemChargeMeter( (loadout_positions_t)i, 100.f );

0 commit comments

Comments
 (0)