From ea279fb32174d90bd5fa9c402fd551e1219b2afc Mon Sep 17 00:00:00 2001 From: pierow Date: Fri, 12 Nov 2021 09:02:21 -0500 Subject: [PATCH] reload while using armory --- main/source/mod/AvHBasePlayerWeapon.cpp | 19 ++++++++++++++-- main/source/mod/AvHBasePlayerWeapon.h | 2 ++ main/source/mod/AvHMarineWeapon.cpp | 29 +++++++++++++++++-------- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/main/source/mod/AvHBasePlayerWeapon.cpp b/main/source/mod/AvHBasePlayerWeapon.cpp index 5cb335104..a1b155a23 100644 --- a/main/source/mod/AvHBasePlayerWeapon.cpp +++ b/main/source/mod/AvHBasePlayerWeapon.cpp @@ -1087,14 +1087,29 @@ bool AvHBasePlayerWeapon::Resupply() this->m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] = min(theCurrentPrimary + theAmountToAdd, theMaxPrimary); const float theDelay = 1.0f; - //bugfix - don't let resupply shorten reload time - this->m_pPlayer->m_flNextAttack = max(this->m_pPlayer->m_flNextAttack,UTIL_WeaponTimeBase() + theDelay); + + if (this->m_iId != AVH_WEAPON_SONIC && this->m_iId != AVH_WEAPON_GRENADE_GUN) + { + this->m_flNextPrimaryAttack = max(this->m_flNextPrimaryAttack, (UTIL_WeaponTimeBase() + (theDelay * 2)));// Delay*2 because nextprimary attack gets decremented twice. + } + else + { + bool startingReload = (this->m_pPlayer->pev->button & IN_RELOAD && (this->m_iClip < this->GetClipSize())); + //Some edge cases here but it allows staged reload to start or continue while resupplying and adds resupply delay if not reloading. + if ((this->m_fInSpecialReload == 0 && !startingReload) || (this->m_fInSpecialReload >= 2 && this->m_iClip >= (this->GetClipSize() - 1))) + this->m_flNextPrimaryAttack = max(this->m_flNextPrimaryAttack, (UTIL_WeaponTimeBase() + (theDelay * 2))); + } this->mTimeOfLastResupply = UTIL_WeaponTimeBase() + theDelay; } return theResupplied; } +float AvHBasePlayerWeapon::GetResupplyTimer() const +{ + return this->mTimeOfLastResupply; +} + void AvHBasePlayerWeapon::SendWeaponAnim(int inAnimation, int skiplocal, int body) { if(inAnimation >= 0) diff --git a/main/source/mod/AvHBasePlayerWeapon.h b/main/source/mod/AvHBasePlayerWeapon.h index 067f178df..1c19ab053 100644 --- a/main/source/mod/AvHBasePlayerWeapon.h +++ b/main/source/mod/AvHBasePlayerWeapon.h @@ -140,6 +140,8 @@ class AvHBasePlayerWeapon : public CBasePlayerWeapon virtual float GetRateOfFire() const; + virtual float GetResupplyTimer() const; + virtual char* GetPlayerModel() const; virtual char* GetPrimeSound() const; diff --git a/main/source/mod/AvHMarineWeapon.cpp b/main/source/mod/AvHMarineWeapon.cpp index a3480d33a..1ff4174c7 100644 --- a/main/source/mod/AvHMarineWeapon.cpp +++ b/main/source/mod/AvHMarineWeapon.cpp @@ -151,19 +151,30 @@ void AvHReloadableMarineWeapon::Reload(void) if (this->m_fInSpecialReload == kSpecialReloadPump) { //pump the shotgun to end the reload if attack is pressed during a reload - //ALERT(at_console, "reloadpump3\n"); this->SendWeaponAnim(this->GetEndReloadAnimation()); - //float theEndReloadAnimationTime = this->GetEndReloadAnimationTime(); - //this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + theEndReloadAnimationTime; - //this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + theEndReloadAnimationTime; - //this->m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + theEndReloadAnimationTime; - //+1 is the average of the gotoreload and shellreload times previously used to limit primary attack and matches the marine putting his hand on the gun. Actual time is half these values in seconds because timers get decremented twice. + const float theEndReloadTime = 1.0f; + //this->m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.0f; - this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.0f; - this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 1.0f; - this->m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.0f; + + //Server code is a bug fix for being able to beat the resupply shoot delay timer. + //Only the server tracks resupply time but it has 500ms here to update the client's m_flNextPrimaryAttack. If it's buggy then remove it and the resupply code that adds to primary attack, network the resupply timer, and check it alongside m_flNextPrimaryAttack in AvHBasePlayerWeapon::ProcessValidAttack. +#ifdef AVH_SERVER + float resupplyTimer = this->GetResupplyTimer(); + if (resupplyTimer > 0.0f) + { + this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + max(theEndReloadTime,(resupplyTimer * 2.0f)); + this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + max(theEndReloadTime,(resupplyTimer * 2.0f)); + this->m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + max(theEndReloadTime,(resupplyTimer * 2.0f)); + } + else +#endif + { + this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + theEndReloadTime; + this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + theEndReloadTime; + this->m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + theEndReloadTime; + } this->m_pPlayer->SetAnimation(PLAYER_RELOAD_END); this->m_fInSpecialReload = kSpecialReloadNone;