void ASWeapon::DetermineWeaponState()
{
	EWeaponState NewState = EWeaponState::Idle;

	if (bIsEquipped)
	{
		if (bPendingReload)
		{
			if (CanReload())
			{
				NewState = EWeaponState::Reloading;
			}
			else
			{
				NewState = CurrentState;
			}
		}
		else if (!bPendingReload && bWantsToFire && CanFire())
		{
			NewState = EWeaponState::Firing;
		}
	}
	else if (bPendingEquip)
	{
		NewState = EWeaponState::Equipping;
	}

	SetWeaponState(NewState);
}
void AShooterWeapon::DetermineWeaponState()
{
	EWeaponState::Type NewState = EWeaponState::Idle;

	if (bIsEquipped)
	{
		if( bPendingReload  )
		{
			if( CanReload() == false )
			{
				NewState = CurrentState;
			}
			else
			{
				NewState = EWeaponState::Reloading;
			}
		}		
		else if ( (bPendingReload == false ) && ( bWantsToFire == true ) && ( CanFire() == true ))
		{
			NewState = EWeaponState::Firing;
		}
	}
	else if (bPendingEquip)
	{
		NewState = EWeaponState::Equipping;
	}

	SetWeaponState(NewState);
}
//------------------------------------------------------------------------
void CDetonate::StartFire()
{
	if (CanFire(false))
	{
		CActor *pOwner=m_pWeapon->GetOwnerActor();

		CCCPOINT(DetonateFireMode_StartFireOK);
		m_pWeapon->RequireUpdate(eIUS_FireMode);
		m_detonationTimer = 0.1f;
		m_pWeapon->PlayAction(GetFragmentIds().fire);
		m_pWeapon->RequestDetonate();
	}
	else
	{
#if !defined(_RELEASE)
		IFireMode* pFM = m_pWeapon->GetFireMode(m_pWeapon->GetCurrentFireMode());
		EntityId projectileId = pFM ? pFM->GetProjectileId() : 0;
		IEntity * projectile = gEnv->pEntitySystem->GetEntity(projectileId);

		CryLog ("[Detonate] Failure to detonate %s '%s' (timer = %.4f, can detonate = %s, fire mode = '%s') projectile = %u (%s '%s')",
						m_pWeapon->GetEntity()->GetClass()->GetName(),
						m_pWeapon->GetEntity()->GetName(),
						m_detonationTimer,
						m_canDetonate ? "TRUE" : "FALSE",
						pFM ? pFM->GetName() : "NONE",
						projectileId,
						projectile ? projectile->GetClass()->GetName() : "NONE",
						projectile ? projectile->GetName() : "N/A");
#endif

		CCCPOINT_IF(m_detonationTimer > 0.0f, DetonateFireMode_CannotFire_TimerNotReachedZero);
		CCCPOINT(DetonateFireMode_CannotFire);
	}
}
void UMWBotWeaponComponent::Fire()
{
	if (!CanFire())
	{
		return;
	}

	// cast a line
	FHitResult hit;
	FCollisionQueryParams traceParams;
	traceParams.AddIgnoredActor(GetOwner());

	const int32 randSeed = FMath::Rand();
	FRandomStream randStream(randSeed);
	
	const FVector traceStart = GetComponentLocation();
	const FVector aimDir = GetComponentRotation().Vector();
	const FVector shotDir = randStream.VRandCone(aimDir, FMath::DegreesToRadians(Spread));
	const FVector traceEnd = traceStart + shotDir * 1e5;

	GetWorld()->LineTraceSingle(hit, traceStart, traceEnd, ECollisionChannel::ECC_Visibility, traceParams);

	ProcessHit(hit);

	// temporary draw
	
	if (hit.bBlockingHit)
	{
		DrawDebugLine(GetWorld(), traceStart, hit.ImpactPoint, FColor::Red, false, -1.f, 0, 10);
	}
	else
	{
		DrawDebugLine(GetWorld(), traceStart, traceEnd, FColor::Red, false, -1.f, 0, 10);
	}
}
示例#5
0
//------------------------------------------------------------------------
void CAutomatic::Update(float frameTime, uint32 frameId)
{
	CSingle::Update(frameTime, frameId);

	if(m_firing && CanFire(false))
		m_firing = Shoot(true);
}
示例#6
0
文件: Plant.cpp 项目: Xydrel/Infected
//------------------------------------------------------------------------
void CPlant::StartFire()
{
	CActor* pOwner = m_pWeapon->GetOwnerActor();

	if (pOwner && pOwner->IsClient() && !CanFire(true))
	{
		return;
	}

	CPlayer *ownerPlayer = m_pWeapon->GetOwnerPlayer();
	if (ownerPlayer)
	{
		ownerPlayer->StateMachineHandleEventMovement( PLAYER_EVENT_FORCEEXITSLIDE );
	}

	m_pWeapon->RequireUpdate(eIUS_FireMode);

	m_planting = true;
	m_pWeapon->SetBusy(true);
	m_pWeapon->PlayAction(GetFragmentIds().intoPlant, 0,false,CItem::eIPAF_Default);
	
	m_pWeapon->GetScheduler()->TimerAction(m_pWeapon->GetCurrentAnimationTime(eIGS_Owner), CSchedulerAction<StartPlantAction>::Create(this), false);

	m_pWeapon->RequestStartFire();
}
示例#7
0
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();
}
示例#8
0
//------------------------------------------------------------------------
void CDetonate::StartFire()
{
	if (CanFire(false))
	{
		m_pWeapon->RequireUpdate(eIUS_FireMode);
		m_detonationTimer = 0.1f;
		m_pWeapon->PlayAction(m_pShared->actions.fire.c_str());
	}
}
示例#9
0
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();
}
示例#10
0
//-------------------------------------------------------------------------------------------------
// Purpose: Checks if we our m_flNextFireTime tells us to start point-blanking
//-------------------------------------------------------------------------------------------------
bool CSDKBot::ThinkCheckPointBlank() {
	if (CanFire() && m_flNextFireTime < gpGlobals->curtime
		&& m_PlayerSearchInfo.CloseEnemy()) {
		ScheduleThinker(&BotThinkers::PointBlank, 0.05f);
		return false;
	} else if (m_flNextFireTime < gpGlobals->curtime)
		m_flNextFireTime = FLT_MAX;

	return true;
}
示例#11
0
//------------------------------------------------------------------------
void CVehicleWeapon::StartFire()
{
  if (!CheckWaterLevel())
    return;

	if(!CanFire())
		return;

  CWeapon::StartFire();
}
示例#12
0
//-------------------------------------------------------------------------------------------------
// Purpose: Simulates close-quarters combat
//-------------------------------------------------------------------------------------------------
bool CSDKBot::ThinkMelee_Begin() {
	//CheckSwitchWeapon(); //This is instead handled farther below
	SendBotVcommContext(DEFAULT);
	SetUpdateFlags(false);
	//m_curCmd.buttons |= IN_FORWARD;
	m_flNextStrafeTime = gpGlobals->curtime + RandomFloat(0.5f, 1.0f);
	bool canMelee = CanMelee();
	if (CanFire()) {
		//If we can't melee, fire as soon as possible
		if (!canMelee) {
			m_flNextFireTime = -FLT_MAX;
		}
		//Otherwise, possibly fire
		else {
			float random = RandomFloat();
			if (m_pPlayer->GetHealth() < 70)
				random += 0.3;
			if (random > 0.5) {
				m_flNextFireTime = gpGlobals->curtime + RandomFloat(0.5f, 1.2f);
			}
		}
	}
	//If we can't fire and can't melee, switch weapons
	else if (!canMelee){
		m_pPlayer->Weapon_Switch(m_pPlayer->Weapon_FindMeleeWeapon());
		UpdateWeaponInfo();
	}

	float randomStrafe = bot_randfloat();
	if (randomStrafe < 0.45f) {
		m_curCmd.buttons |= IN_LEFT;
		m_curCmd.buttons &= ~IN_RIGHT;
	} else if (randomStrafe < 0.9f) {
		m_curCmd.buttons &= ~IN_LEFT;
		m_curCmd.buttons |= IN_RIGHT;
	} else {
		m_curCmd.buttons &= ~IN_LEFT;
		m_curCmd.buttons &= ~IN_RIGHT;
	}

	float randomForward = bot_randfloat();
	//don't move forward if we're too close
	if ( m_PlayerSearchInfo.CloseEnemyDist() < m_flMeleeRange) {
		m_curCmd.buttons &= ~IN_FORWARD;
		m_curCmd.buttons |= IN_BACK;
	} else if (randomForward < 0.5f){
		m_curCmd.buttons |= IN_FORWARD;
		m_curCmd.buttons &= ~IN_BACK;
	} else {
		m_curCmd.buttons &= ~IN_FORWARD;
		m_curCmd.buttons &= ~IN_BACK;
	}

	return true;
}
示例#13
0
文件: JAW.cpp 项目: amrhead/eaascode
void CJaw::UpdatePendingShot()
{
	if (m_firePending && CanFire() && IsZoomed())
	{
		m_controllingRocket = true;
		m_firePending = false;
		HideRocket();
		BaseClass::StartFire();
		AutoZoomOut();
	}
}
示例#14
0
//-------------------------------------------------------------------------------------------------
// Purpose: Long-range combat
//-------------------------------------------------------------------------------------------------
bool CSDKBot::ThinkLongRange_Begin() {
	SendBotVcommContext(ADVANCE);
	SetUpdateFlags(true);
	if (CanFire()) {
		float random = bot_randfloat();
		if (random < m_pDifficult->m_flLongRangeFire) {
			m_flNextFireTime = gpGlobals->curtime + RandomFloat(0.5f, 4.2f);
		}
	}
	return true;
}
示例#15
0
void ASWeapon::ServerHandleFiring_Implementation()
{
	const bool bShouldUpdateAmmo = CanFire();

	HandleFiring();

	if (bShouldUpdateAmmo)
	{
		// Update firing FX on remote clients
		BurstCounter++;
	}
}
//------------------------------------------------------------------------
void CRapid::StartFire()
{
	if (m_pWeapon->IsBusy() || !CanFire(true))
	{
		//Clip empty sound
		if(!CanFire(true) && !m_reloading)
		{
			int ammoCount = m_pWeapon->GetAmmoCount(m_fireParams->fireparams.ammo_type_class);

			if (GetClipSize()==0)
				ammoCount = m_pWeapon->GetInventoryAmmoCount(m_fireParams->fireparams.ammo_type_class);

			if(ammoCount<=0)
			{
				m_pWeapon->PlayAction(GetFragmentIds().empty_clip);
				m_pWeapon->OnFireWhenOutOfAmmo();
			}
		}
		return;
	}

	m_rapidFlags &= ~eRapidFlag_netShooting;

	if ((m_rapidFlags & (eRapidFlag_decelerating | eRapidFlag_accelerating)) == 0)
	{
		m_pWeapon->EnableUpdate(true, eIUS_FireMode);
	}

	//SpinUpEffect(true);
	Accelerate(m_fireParams->rapidparams.acceleration);

	m_rapidFlags |= eRapidFlag_startedFiring;
	m_firstFire = true;

	m_startFiringTime = gEnv->pTimer->GetAsyncTime();

	m_muzzleEffect.StartFire(this);

	m_pWeapon->RequestStartFire();
}
示例#17
0
bool CSDKBot::ThinkPointBlank() {
	CBasePlayer* pEnemy = m_PlayerSearchInfo.CloseEnemy();
	if (pEnemy) {
		LookAt(pEnemy->Weapon_ShootPosition() + downToChest * bot_randfloat(0.5, 2.0), 0.35f + m_pDifficult->m_flAimTurnLerp, m_pDifficult->m_flRandomAim / 6);
	}
	if (CanFire() && m_flNextFireTime < gpGlobals->curtime && !IsAimingAtTeammate(m_PlayerSearchInfo.CloseEnemyDist())) {
		m_curCmd.buttons |= IN_ATTACK;
		//ScheduleThinker(m_pPrevThinker, 0);
		//return false;
	}

	return true;
}
示例#18
0
void AAWeapon::ServerHandleFiring_Implementation()
{
	const bool bShouldUpdateAmmo = (CurrentAmmoInClip > 0 && CanFire());

	HandleFiring();

	if (bShouldUpdateAmmo)
	{
		UseAmmo();

		BurstCounter++;
	}
}
示例#19
0
//------------------------------------------------------------------------
void CRapid::StartFire()
{
	if (m_pWeapon->IsBusy() || !CanFire(true))
	{
		//Clip empty sound
		if(!CanFire(true) && !m_reloading)
		{
			int ammoCount = m_pWeapon->GetAmmoCount(m_pShared->fireparams.ammo_type_class);

			if (m_pShared->fireparams.clip_size==0)
				ammoCount = m_pWeapon->GetInventoryAmmoCount(m_pShared->fireparams.ammo_type_class);

			if(ammoCount<=0)
			{
				m_pWeapon->PlayAction(m_pShared->actions.empty_clip);
				//Auto reload
				m_pWeapon->Reload();
			}
		}
		return;
	}
	else if(m_pWeapon->IsWeaponLowered())
	{
		m_pWeapon->PlayAction(m_pShared->actions.null_fire);
		return;
	}

	m_netshooting = false;

	m_pWeapon->EnableUpdate(true, eIUS_FireMode);

	//SpinUpEffect(true);
	Accelerate(m_pShared->rapidparams.acceleration);

	m_startedToFire = true;

	m_pWeapon->RequestStartFire();
}
void AMagicBattleSoccerWeapon::DetermineWeaponState()
{	
	EWeaponState NewState = EWeaponState::Idle;

	if (nullptr != MyPawn && bIsEquipped)
	{
		if (bWantsToFire && CanFire())
		{			
			NewState = EWeaponState::Firing;
		}
	}

	SetWeaponState(NewState);
}
//------------------------------------------------------------------------
void CAutomatic::Update(float frameTime, uint32 frameId)
{
	BaseClass::Update(frameTime, frameId);

	if (m_firing && CanFire(false))
	{
		m_firing = Shoot(true, m_fireParams->fireparams.autoReload);

		if(!m_firing)
		{
			StopFire();
		}
	}
}
void AShooterWeapon::ServerHandleFiring_Implementation()
{
	const bool bShouldUpdateAmmo = (CurrentAmmoInClip > 0 && CanFire());

	HandleFiring();

	if (bShouldUpdateAmmo)
	{
		// update ammo
		UseAmmo();

		// update firing FX on remote clients
		BurstCounter++;
	}
}
示例#23
0
void CAutomaticShotgun::Update(float frameTime, uint32 frameId)
{
    CShotgun::Update(frameTime, frameId);

    if (m_firing)
        {
            m_rapidFireCountdown -= frameTime;
            if (m_rapidFireCountdown < 0.0f && CanFire(true))
                {
                    bool shot = Shoot(true, true);
                    if (shot)
                        m_rapidFireCountdown += m_next_shot_dt;
                }
        }
}
示例#24
0
文件: JAW.cpp 项目: amrhead/eaascode
void CJaw::StartFire()
{
	if (!CanFire())
		return;

	CActor* pOwner = GetOwnerActor();
#if (USE_DEDICATED_INPUT)
	if (!pOwner || (!pOwner->IsPlayer() || (gEnv->bMultiplayer && strcmp(pOwner->GetEntityClassName(), "DummyPlayer") == 0)))
#else
	if (!pOwner || !pOwner->IsPlayer())
#endif
	{
		BaseClass::StartFire();
		return;
	}

	if (m_controllingRocket)
		return;

	CPlayer *ownerPlayer = GetOwnerPlayer();
	if (ownerPlayer)
	{
		if(ownerPlayer->IsClient() && ownerPlayer->IsWeaponUnderWater())
		{
			return;
		}

		ownerPlayer->StateMachineHandleEventMovement( PLAYER_EVENT_FORCEEXITSLIDE );
	}

	if (!m_firePending && m_zm && g_pGameCVars->cl_zoomToggle > 0)
	{
		m_zoomAlreadyToggled = (m_zm->IsZoomingIn() || m_zm->IsZoomed());
	}
	else
	{
		m_zoomAlreadyToggled = false;
	}

	if(!IsZoomingInOrOut())
	{
		if (m_zm)
			m_zm->ZoomIn();
	}

	m_fireTriggerDown = true;
	m_firePending = true;
}
示例#25
0
void WeaponBase::Fire(glm::vec3 fireOrigin, glm::vec3 fireDirection)
{
    fireAttempt = true;
    if (CanFire())
    {
        storedAmmo -= GetRequiredAmmoToFire();
        firingTime = fireRateInSeconds;
        coolingTime = cooldownInSeconds;
        FireInternal(fireOrigin, fireDirection);
    }
    else if (continualFire && firingTime > 0.0f)
    {
        // Continue fire weapons we can fire until firing time == 0, at which point we have to wait for the cooldown.
        FireInternal(fireOrigin, fireDirection);
    }
}
示例#26
0
//------------------------------------------------------------------------
void CWorkOnTarget::StartFire()
{
	if(m_pWeapon->IsBusy() || !CanFire(false) || !CanWork())
		return;

	m_firing=true;
	m_pWeapon->SetBusy(true);

	m_soundId=m_pWeapon->PlayAction(m_workactions.work.c_str(), 0, true, CItem::eIPAF_Default|CItem::eIPAF_CleanBlending|CItem::eIPAF_SoundStartPaused);
	m_pWeapon->SetDefaultIdleAnimation(eIGS_FirstPerson, m_workactions.work.c_str());

	m_pWeapon->EnableUpdate(true, eIUS_FireMode);
	m_delayTimer=m_workparams.delay;

	if(!m_pWeapon->IsServer())
		m_pWeapon->RequestStartFire();
}
示例#27
0
void ASWeapon::DetermineWeaponState()
{
	EWeaponState NewState = EWeaponState::Idle;

	if (bIsEquipped)
	{
		if (bWantsToFire && CanFire())
		{
			NewState = EWeaponState::Firing;
		}
	}
	else if (bPendingEquip)
	{
		NewState = EWeaponState::Equipping;
	}

	SetWeaponState(NewState);
}
//------------------------------------------------------------------------
void CThrow::StartFire()
{
	m_netfiring = false;

	if (CanFire(true) && !m_firing && !m_throwing && !m_pulling)
	{
		m_firing = true;
		m_pulling = true;
		m_throwing = false;
		m_thrown = false;
		m_pWeapon->SetBusy(true);
		m_pWeapon->PlayAction(m_pShared->throwactions.pull);
		m_pWeapon->GetScheduler()->TimerAction(m_pWeapon->GetCurrentAnimationTime( eIGS_FirstPerson) + 1, CSchedulerAction<StartThrowAction>::Create(this), false);
		m_pWeapon->SetDefaultIdleAnimation( eIGS_FirstPerson, m_pShared->throwactions.hold);
		m_hold_timer = m_pShared->throwparams.hold_duration;
		m_pWeapon->RequestStartFire();
		m_pWeapon->RequireUpdate(eIUS_FireMode);
	}
}
void AMagicBattleSoccerWeapon::HandleFiring()
{
	if (CanFire())
	{
		if (MyPawn && MyPawn->IsLocallyControlled())
		{
			FireWeapon();
		}
	}

	if (nullptr != MyPawn && MyPawn->IsLocallyControlled())
	{
		// local client will notify server
		if (Role < ROLE_Authority)
		{
			ServerHandleFiring();
		}

		// Make the player aim in the direction they're firing if they're not running
		AMagicBattleSoccerPlayerController* const PlayerController = Instigator ? Cast<AMagicBattleSoccerPlayerController>(Instigator->Controller) : nullptr;
		if (nullptr != PlayerController
			&& nullptr != PlayerController->GetPawn()
			&& nullptr != PlayerController->GetPawn()->GetMovementComponent()
			&& PlayerController->GetPawn()->GetMovementComponent()->Velocity.Size() < 0.001f)
		{
			// We can't aim immediately because that could put the camera out of sync with the pawn. Just assign ourselves to the controller and it
			// will take care of things in the next Tick().
			PlayerController->bFaceMouseCursorInTick = true;
		}

		// setup refire timer
		bRefiring = (LocalState == EWeaponState::Firing && WeaponConfig.TimeBetweenShots > 0.0f && WeaponConfig.RepeatingFire);
		if (bRefiring)
		{
			// Start a timer to handle repeating firing
			GetWorldTimerManager().SetTimer(TimerHandle_HandleFiringTimer, this, &AMagicBattleSoccerWeapon::HandleFiring, WeaponConfig.TimeBetweenShots, false);
		}
	}

	LastFireTime = GetWorld()->GetTimeSeconds();
}
示例#30
0
void ASWeapon::HandleFiring()
{
	if (CanFire())
	{
		if (GetNetMode() != NM_DedicatedServer)
		{
			SimulateWeaponFire();
		}

		if (MyPawn && MyPawn->IsLocallyControlled())
		{
			FireWeapon();

			// TODO: Consume Ammo

			// Update firing FX on remote clients if this is called on server
			// Cause it is replicated value on server.
			BurstCounter++;
		}
	}

	// TODO: End repeat fire if ammo runs dry

	if (MyPawn && MyPawn->IsLocallyControlled())
	{
		if (Role < ROLE_Authority)
		{
			ServerHanleFiring();
		}

		// TODO: if weapon is automatic firing rifle -> Setup refiring timer. (calls HandleFiring())

		bRefiring = (CurrentState == EWeaponState::Firing && TimeBetweenShots > 0.0f);
		if (bRefiring)
		{
			GetWorldTimerManager().SetTimer(HandleFiringTimerHandle, this, &ASWeapon::HandleFiring, TimeBetweenShots, false);
		}
	}

	LastFireTime = GetWorld()->GetTimeSeconds();
}