void AAWeapon::HandleFiring() { if (CurrentAmmoInClip > 0 && CanFire()) { if (GetNetMode() != NM_DedicatedServer) { SimulateWeaponFire(); } if (MyPawn && MyPawn->IsLocallyControlled()) { FireWeapon(); UseAmmo(); BurstCounter++; } } else if (CanReload()) { StartReload(); } else if (MyPawn && MyPawn->IsLocallyControlled()) { if (GetCurrentAmmo() == 0 && !bRefiring) { PlayWeaponSound(OutOfAmmoSound); } /* Reload after firing last round */ if (CurrentAmmoInClip <= 0 && CanReload()) { StartReload(); } /* Stop weapon fire FX, but stay in firing state */ if (BurstCounter > 0) { OnBurstFinished(); } } if (MyPawn && MyPawn->IsLocallyControlled()) { if (Role < ROLE_Authority) { ServerHandleFiring(); } /* Retrigger HandleFiring on a delay for automatic weapons */ bRefiring = (CurrentState == EWeaponState::Firing && TimeBetweenShots > 0.0f); if (bRefiring) { GetWorldTimerManager().SetTimer(TimerHandle_HandleFiring, this, &AAWeapon::HandleFiring, TimeBetweenShots, false); } } LastFireTime = GetWorld()->GetTimeSeconds(); }
void AWeapon::HandleFiring() { if ((CurrentAmmoInClip > 0 || HasInfiniteClip() || HasInfiniteAmmo()) && CanFire()) { if (GetNetMode() != NM_DedicatedServer) { SimulateWeaponFire(); } if (MyPawn && MyPawn->IsLocallyControlled()) { FireWeapon(); UseAmmo(); // update firing FX on remote clients if function was called on server BurstCounter++; } } else if (CanReload()) { StartReload(); } else if (MyPawn && MyPawn->IsLocallyControlled()) { // stop weapon fire FX, but stay in Firing state if (BurstCounter > 0) { OnBurstFinished(); } } if (MyPawn && MyPawn->IsLocallyControlled()) { // local client will notify server if (Role < ROLE_Authority) { ServerHandleFiring(); } // reload after firing last round if (CurrentAmmoInClip <= 0 && CanReload()) { StartReload(); } // setup refire timer bRefiring = (CurrentState == EWeaponState::Firing && WeaponConfig.TimeBetweenShots > 0.0f); if (bRefiring) { GetWorldTimerManager().SetTimer(TimerHandle_HandleFiring, this, &AWeapon::HandleFiring, WeaponConfig.TimeBetweenShots, false); } } LastFireTime = GetWorld()->GetTimeSeconds(); }
void AShooterWeapon::SetWeaponState(EWeaponState::Type NewState) { const EWeaponState::Type PrevState = CurrentState; if (PrevState == EWeaponState::Firing && NewState != EWeaponState::Firing) { OnBurstFinished(); } CurrentState = NewState; if (PrevState != EWeaponState::Firing && NewState == EWeaponState::Firing) { OnBurstStarted(); } }
void ASWeapon::SetWeaponState(EWeaponState inNewState) { const EWeaponState prevState = CurrentState; if ((prevState == EWeaponState::Firing) && (inNewState != EWeaponState::Firing)) { OnBurstFinished(); } CurrentState = inNewState; if ((prevState != EWeaponState::Firing) && (inNewState == EWeaponState::Firing)) { OnBurstStarted(); } }
void AMagicBattleSoccerWeapon::SetWeaponState(EWeaponState NewState) { const EWeaponState PrevState = LocalState; if (PrevState == EWeaponState::Firing && NewState != EWeaponState::Firing) { OnBurstFinished(); } LocalState = NewState; if (ROLE_Authority == Role) { ServerState = NewState; } if (PrevState != EWeaponState::Firing && NewState == EWeaponState::Firing) { OnBurstStarted(); } }
void ASWeapon::HandleFiring() { if (CurrentAmmoInClip > 0 && CanFire()) { if (GetNetMode() != NM_DedicatedServer) { SimulateWeaponFire(); } if (MyPawn && MyPawn->IsLocallyControlled()) { FireWeapon(); UseAmmo(); // Update firing FX on remote clients if this is called on server BurstCounter++; } } else if (CanReload()) { StartReload(); } else if (MyPawn && MyPawn->IsLocallyControlled()) { if (GetCurrentAmmo() == 0 && !bRefiring) { PlayWeaponSound(OutOfAmmoSound); } /* Reload after firing last round */ if (CurrentAmmoInClip <= 0 && CanReload()) { StartReload(); } /* Stop weapon fire FX, but stay in firing state */ if (BurstCounter > 0) { OnBurstFinished(); } } if (MyPawn && MyPawn->IsLocallyControlled()) { if (Role < ROLE_Authority) { ServerHandleFiring(); } /* Retrigger HandleFiring on a delay for automatic weapons */ bRefiring = (CurrentState == EWeaponState::Firing && TimeBetweenShots > 0.0f); if (bRefiring) { GetWorldTimerManager().SetTimer(TimerHandle_HandleFiring, this, &ASWeapon::HandleFiring, TimeBetweenShots, false); } } /* Make Noise on every shot. The data is managed by the PawnNoiseEmitterComponent created in SBaseCharacter and used by PawnSensingComponent in SZombieCharacter */ if (MyPawn) { MyPawn->MakePawnNoise(1.0f); } LastFireTime = GetWorld()->GetTimeSeconds(); }