示例#1
0
void AConstructorWeapon::Fire()
{
	Super::Fire();

	if (TheLevelBlockConstructor == NULL)
	{
		if (GetWorld() && GetWorld()->GetAuthGameMode() && GetWorld()->GetAuthGameMode<ARadeGameMode>())
		{
			TheLevelBlockConstructor = GetWorld()->GetAuthGameMode<ARadeGameMode>()->TheLevelBlockConstructor;
		}
	}

	if (TheLevelBlockConstructor)
	{

		FVector CamLoc;
		FRotator CamRot;
		ThePlayer->Controller->GetPlayerViewPoint(CamLoc, CamRot); // Get the camera position and rotation
		FVector StartTrace = Mesh1P->GetSocketLocation(TEXT("FireSocket"));
		//	CamLoc; // trace start is the camera location
		FVector Direction = CamRot.Vector();
		FVector EndTrace = StartTrace + Direction *MainFire.FireDistance;

		if (TheLevelBlockConstructor->AddNewBlock(BlockArchetype, EndTrace, this)) UseMainFireAmmo();
	}
}
示例#2
0
// Pre Fire
void AWeapon::PreFire()
{
	// BP Pre Fire
	BP_PreFire();

	if (!ThePlayer)return;
	
	// If player stopped shooting stop event
	if (!bShooting )
	{
		ThePlayer->GetWorldTimerManager().ClearTimer(PreFireTimeHandle);
		return;
	}

	// Currently Equiping this weapon, delay a bit
	if (ThePlayer->IsAnimState(EAnimState::Equip))
	{
		// try after a small delay
		FTimerHandle MyHandle;
		ThePlayer->GetWorldTimerManager().SetTimer(MyHandle, this, &AWeapon::PreFire, 0.2, false);
		return;
	}

	// Wrong Weapon or Player Anim State
	if (!CanShoot())return;

	// Ammo Check
	if (!MainFire.CanFire())
	{
		//  BP No Ammo
		BP_NoAmmo();

		// if have ammo, start reloading
		if (CanReload())ReloadWeaponStart();
		return;
	}


	// The real fire event
	Fire();

	// Use Ammo
	if (bUseAmmo)UseMainFireAmmo();


	// Set Player Anim State
	ThePlayer->ServerSetAnimID(EAnimState::Fire);

	// Decrease move speed when shooting
	ThePlayer->ResetMoveSpeed();

	///	Stop Fire Anim
	FTimerHandle MyHandle;
	ThePlayer->GetWorldTimerManager().SetTimer(MyHandle, this, &AWeapon::StopFireAnim, 0.1, false);
}