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 AAWeapon::ServerHandleFiring_Implementation() { const bool bShouldUpdateAmmo = (CurrentAmmoInClip > 0 && CanFire()); HandleFiring(); if (bShouldUpdateAmmo) { UseAmmo(); BurstCounter++; } }
void AShooterWeapon::ServerHandleFiring_Implementation() { const bool bShouldUpdateAmmo = (CurrentAmmoInClip > 0 && CanFire()); HandleFiring(); if (bShouldUpdateAmmo) { // update ammo UseAmmo(); // update firing FX on remote clients BurstCounter++; } }
void JetPack::StartShooting() { if (active) { Deselect(); if (EnoughAmmo()) Select(); } else { if (EnoughAmmo()) { UseAmmo(); Game::GetInstance()->SetCharacterChosen(true); active = true; ActiveCharacter().SetClothe("jetpack-fire"); } } }
bool Weapon::Shoot() { MSG_DEBUG("weapon.shoot", "Enough ammo ? %d", EnoughAmmo()); MSG_DEBUG("weapon.shoot", "Enough ammo unit ? %d", EnoughAmmoUnit()); MSG_DEBUG("weapon.shoot", "Use unit on 1st shoot ? %d", use_unit_on_first_shoot); if (!IsReady()) return false; MSG_DEBUG("weapon.shoot", "Enough ammo"); #ifdef DEBUG Point2i hand; ActiveCharacter().GetHandPosition(hand); MSG_DEBUG("weapon.shoot", "%s Shooting at position:%d,%d (hand: %d,%d)", ActiveCharacter().GetName().c_str(), ActiveCharacter().GetX(), ActiveCharacter().GetY(), hand.GetX(), hand.GetY()); ActiveCharacter().body->DebugState(); #endif if (!p_Shoot()) { MSG_DEBUG("weapon.shoot", "shoot has failed!!"); return false; } m_last_fire_time = Time::GetInstance()->Read(); MSG_DEBUG("weapon.shoot", "shoot!"); // Is this the first shoot for this ammo use ? if (ActiveTeam().ReadNbUnits() == m_initial_nb_unit_per_ammo) { UseAmmo(); } if (use_unit_on_first_shoot){ UseAmmoUnit(); } if (max_strength.IsNotZero()) ActiveCharacter().previous_strength = m_strength; Game::GetInstance()->SetCharacterChosen(true); return true; }
void CEgon::Fire( const Vector &vecOrigSrc, const Vector &vecDir ) { Vector vecDest = vecOrigSrc + vecDir * 2048; edict_t *pentIgnore; TraceResult tr; pentIgnore = m_pPlayer->edict(); Vector tmpSrc = vecOrigSrc + gpGlobals->v_up * -8 + gpGlobals->v_right * 3; // ALERT( at_console, "." ); UTIL_TraceLine( vecOrigSrc, vecDest, dont_ignore_monsters, pentIgnore, &tr ); if (tr.fAllSolid) return; #ifndef CLIENT_DLL CBaseEntity *pEntity = CBaseEntity::Instance(tr.pHit); if (pEntity == NULL) return; if ( g_pGameRules->IsMultiplayer() ) { if ( m_pSprite && pEntity->pev->takedamage ) { m_pSprite->pev->effects &= ~EF_NODRAW; } else if ( m_pSprite ) { m_pSprite->pev->effects |= EF_NODRAW; } } #endif float timedist; switch ( m_fireMode ) { case FIRE_NARROW: #ifndef CLIENT_DLL if ( pev->dmgtime < gpGlobals->time ) { // Narrow mode only does damage to the entity it hits ClearMultiDamage(); if (pEntity->pev->takedamage) { pEntity->TraceAttack( m_pPlayer->pev, gSkillData.plrDmgEgonNarrow, vecDir, &tr, DMG_ENERGYBEAM ); } ApplyMultiDamage(m_pPlayer->pev, m_pPlayer->pev); if ( g_pGameRules->IsMultiplayer() ) { // multiplayer uses 1 ammo every 1/10th second if ( gpGlobals->time >= m_flAmmoUseTime ) { UseAmmo( 1 ); m_flAmmoUseTime = gpGlobals->time + 0.1; } } else { // single player, use 3 ammo/second if ( gpGlobals->time >= m_flAmmoUseTime ) { UseAmmo( 1 ); m_flAmmoUseTime = gpGlobals->time + 0.166; } } pev->dmgtime = gpGlobals->time + GetPulseInterval(); } #endif timedist = ( pev->dmgtime - gpGlobals->time ) / GetPulseInterval(); break; case FIRE_WIDE: #ifndef CLIENT_DLL if ( pev->dmgtime < gpGlobals->time ) { // wide mode does damage to the ent, and radius damage ClearMultiDamage(); if (pEntity->pev->takedamage) { pEntity->TraceAttack( m_pPlayer->pev, gSkillData.plrDmgEgonWide, vecDir, &tr, DMG_ENERGYBEAM | DMG_ALWAYSGIB); } ApplyMultiDamage(m_pPlayer->pev, m_pPlayer->pev); if ( g_pGameRules->IsMultiplayer() ) { // radius damage a little more potent in multiplayer. ::RadiusDamage( tr.vecEndPos, pev, m_pPlayer->pev, gSkillData.plrDmgEgonWide/4, 128, CLASS_NONE, DMG_ENERGYBEAM | DMG_BLAST | DMG_ALWAYSGIB ); } if ( !m_pPlayer->IsAlive() ) return; if ( g_pGameRules->IsMultiplayer() ) { //multiplayer uses 5 ammo/second if ( gpGlobals->time >= m_flAmmoUseTime ) { UseAmmo( 1 ); m_flAmmoUseTime = gpGlobals->time + 0.2; } } else { // Wide mode uses 10 charges per second in single player if ( gpGlobals->time >= m_flAmmoUseTime ) { UseAmmo( 1 ); m_flAmmoUseTime = gpGlobals->time + 0.1; } } pev->dmgtime = gpGlobals->time + GetDischargeInterval(); if ( m_shakeTime < gpGlobals->time ) { UTIL_ScreenShake( tr.vecEndPos, 5.0, 150.0, 0.75, 250.0 ); m_shakeTime = gpGlobals->time + 1.5; } } #endif timedist = ( pev->dmgtime - gpGlobals->time ) / GetDischargeInterval(); break; } if ( timedist < 0 ) timedist = 0; else if ( timedist > 1 ) timedist = 1; timedist = 1-timedist; UpdateEffect( tmpSrc, tr.vecEndPos, timedist ); }
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(); }
void Parachute::Refresh() { if (Game::GetInstance()->GetRemainingTime() <= 0) return; if (Game::GetInstance()->ReadState() != Game::PLAYING) return; Character& active = ActiveCharacter(); Double speed = active.GetSpeedXY().Norm(); if (active.FootsInVacuum() && speed.IsNotZero()) { // We are falling if (!open && (speed > GameMode::GetInstance()->safe_fall)) { // with a sufficient speed if (EnoughAmmo() && !m_used_this_turn) { // We have enough ammo => start opening the parachute if (!m_used_this_turn) { UseAmmo(); m_used_this_turn = true; } active.SetAirResistFactor(cfg().air_resist_factor); active.SetWindFactor(cfg().wind_factor); open = true; img->animation.SetPlayBackward(false); img->Start(); active.SetSpeedXY(Point2d(0,0)); active.SetMovement("parachute"); Camera::GetInstance()->FollowObject(&active); } } } else { // We are on the ground if (open) { // The parachute is opened active.SetMovement("walk"); if (!closing) { // We have just hit the ground. Start closing animation img->animation.SetPlayBackward(true); img->animation.SetShowOnFinish(SpriteAnimation::show_blank); img->Start(); closing = true; return; } else { // The parachute is closing if (img->IsFinished()) { // The animation is finished... We are done with the parachute open = false; closing = false; UseAmmoUnit(); } } } m_used_this_turn = false; } if (open) { active.UpdateLastMovingTime(); // If parachute is open => character can move a little to the left or to the right const LRMoveIntention * lr_move_intention = active.GetLastLRMoveIntention(); if (lr_move_intention) { LRDirection direction = lr_move_intention->GetDirection(); active.SetDirection(direction); if (direction == DIRECTION_LEFT) active.SetExternForce(-cfg().force_side_displacement, 0.0); else active.SetExternForce(cfg().force_side_displacement, 0.0); } } }
void CWeaponEgon::Fire( const Vector &vecOrigSrc, const Vector &vecDir ) { CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if ( !pPlayer ) { return; } //CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), 450, 0.1 ); WeaponSound( SINGLE ); Vector vecDest = vecOrigSrc + (vecDir * MAX_TRACE_LENGTH); trace_t tr; UTIL_TraceLine( vecOrigSrc, vecDest, MASK_SHOT, pPlayer, COLLISION_GROUP_NONE, &tr ); if ( tr.allsolid ) return; CBaseEntity *pEntity = tr.m_pEnt; if ( pEntity == NULL ) return; if ( g_pGameRules->IsMultiplayer() ) { if ( m_hSprite ) { if ( pEntity->m_takedamage != DAMAGE_NO ) { m_hSprite->TurnOn(); } else { m_hSprite->TurnOff(); } } } if ( m_flDmgTime < gpGlobals->curtime ) { // wide mode does damage to the ent, and radius damage if ( pEntity->m_takedamage != DAMAGE_NO ) { ClearMultiDamage(); CTakeDamageInfo info(this, pPlayer, sk_plr_dmg_egon_wide.GetFloat() * g_pGameRules->GetDamageMultiplier(), DMG_ENERGYBEAM | DMG_ALWAYSGIB | DMG_CRUSH); CalculateMeleeDamageForce( &info, vecDir, tr.endpos ); pEntity->DispatchTraceAttack( info, vecDir, &tr ); ApplyMultiDamage(); } if ( g_pGameRules->IsMultiplayer() ) { // radius damage a little more potent in multiplayer. #ifndef CLIENT_DLL RadiusDamage(CTakeDamageInfo(this, pPlayer, sk_plr_dmg_egon_wide.GetFloat() * g_pGameRules->GetDamageMultiplier() / 4, DMG_ENERGYBEAM | DMG_BLAST | DMG_ALWAYSGIB | DMG_CRUSH), tr.endpos, 128, CLASS_NONE, NULL); #endif } if ( !pPlayer->IsAlive() ) return; if ( g_pGameRules->IsMultiplayer() ) { //multiplayer uses 5 ammo/second if ( gpGlobals->curtime >= m_flAmmoUseTime ) { UseAmmo( 1 ); m_flAmmoUseTime = gpGlobals->curtime + 0.2; } } else { // Wide mode uses 10 charges per second in single player if ( gpGlobals->curtime >= m_flAmmoUseTime ) { UseAmmo( 1 ); m_flAmmoUseTime = gpGlobals->curtime + 0.1; } } m_flDmgTime = gpGlobals->curtime + EGON_DISCHARGE_INTERVAL; if ( m_flShakeTime < gpGlobals->curtime ) { #ifndef CLIENT_DLL UTIL_ScreenShake( tr.endpos, 5.0, 150.0, 0.75, 250.0, SHAKE_START ); #endif m_flShakeTime = gpGlobals->curtime + 1.5; } } Vector vecUp, vecRight; QAngle angDir; VectorAngles( vecDir, angDir ); AngleVectors( angDir, NULL, &vecRight, &vecUp ); Vector tmpSrc = vecOrigSrc + (vecUp * -8) + (vecRight * 3); UpdateEffect( tmpSrc, tr.endpos ); }