void AMurphysLawCharacter::Fire() { // check if we have a weapon equipped if (HasWeaponEquipped()) { // if the weapon has been able to fire if (GetEquippedWeapon()->Fire(this)) { // Stop the character from running SetIsRunning(false); // try and play a firing animation if specified if (FireAnimation != nullptr) { // Get the animation object for the arms mesh UAnimInstance* AnimInstance = Mesh1P->GetAnimInstance(); if (AnimInstance != nullptr) { AnimInstance->Montage_Play(FireAnimation, 1.f); } } // check for bullet collisions ComputeBulletCollisions(); } // We reload the weapon if it is empty and we have bullets left in our inventory if (ShouldReload()) { Reload(); } } }
bool CSDKBot::ThinkFlag() { CFlag* pFlag = m_PlayerSearchInfo.CloseEnemyFlagVisible(); if (IsCapturingEnemyFlagAttempt()) { if (!m_bLastThinkWasInFlag) { m_bLastThinkWasInFlag = true; if (bot_randfloat() < 0.4f && ShouldReload()) { m_curCmd.buttons |= IN_RELOAD; } m_flNextStrafeTime = gpGlobals->curtime; } CBasePlayer* pEnemy = m_PlayerSearchInfo.CloseEnemy(); if (pEnemy) { LookAt(pEnemy->Weapon_ShootPosition(), 0.7f, 3); if (pFlag) DanceAround(pFlag->GetAbsOrigin(), pFlag->m_flCaptureRadius); if (bot_randfloat() < 0.3f) m_flNextFireTime = gpGlobals->curtime; } else { StopMoving(); } } else { m_bLastThinkWasInFlag = false; if (pFlag) { m_curCmd.buttons |= IN_FORWARD; LookAt(pFlag->GetAbsOrigin() + g_vUpFromFlag, 0.8f, 5); } TeammateGoAround(true); } return true; }
// Refills ammos for the current equipped weapon void AMurphysLawCharacter::ReceiveAmmo(const int32 NumberOfAmmo) { GetEquippedWeapon()->AddAmmoInInventory(NumberOfAmmo); // If the equipped weapon is empty when picking up ammos, it auto-reloads if (ShouldReload()) { Reload(); } }
// Refills ammos for the collected weapon or collects it if character didn't have it yet void AMurphysLawCharacter::CollectWeapon(class AMurphysLawBaseWeapon* Weapon) { Inventory->CollectWeapon(Weapon); // If the equipped weapon is empty when picking up the weapon and it's the same, it auto-reloads if (HasWeaponEquipped() && GetEquippedWeapon()->IsOfSameType(Weapon) && ShouldReload()) { Reload(); } }
bool CSDKBot::ThinkPointBlank_Check() { if (!(ThinkCheckDeath() && ThinkCheckMelee() && ThinkCheckExitCombat())) return false; //don't stop too quicky... or else we'll start moving before the bullet's fired. if (m_flNextFireTime + 0.8f < gpGlobals->curtime && !CanFire()) { //we've just shot! if (bot_randfloat() < 0.7f && ShouldReload()) { ScheduleThinker(&BotThinkers::Reload, 0.4f); } else { ScheduleThinker(&BotThinkers::MedRange, 0.2f); } return false; } //check if we've been sitting too long because the enemy died or something if (m_flNextFireTime + 1.0f < gpGlobals->curtime) { ScheduleThinker(&BotThinkers::LongRange, 0.15f); return false; } return true; }