Exemplo n.º 1
0
void ABaseWeapon::Fire()
{
	switch (ProjectileType)
	{
	case EWeaponProjectile::EBullet:
		Instant_Fire();
		LastFireTime = GetWorld()->GetTimeSeconds();
		GetWorldTimerManager().SetTimer(time_handler, this, &ABaseWeapon::Fire, WeaponConfig.TimeBetweenShots, false);
		break;
	case EWeaponProjectile::ESniper:
		Instant_Fire();
		LastFireTime = GetWorld()->GetTimeSeconds();
		GetWorldTimerManager().SetTimer(time_handler, this, &ABaseWeapon::Fire, WeaponConfig.TimeBetweenShots, false);
		break;
	case EWeaponProjectile::EProjectile:
		if (MissleWeaponConfig.CurrentAmmo > 0 && Target)
		{
			Server_ProjectileFire(WeaponConfig, Target);
			MissleWeaponConfig.CurrentAmmo--;
			LastFireTime = GetWorld()->GetTimeSeconds();
			GetWorldTimerManager().SetTimer(time_handler, this, &ABaseWeapon::Fire, WeaponConfig.TimeBetweenShots, false);
		}
		else
		{
			LastFireTime = GetWorld()->GetTimeSeconds();
			GetWorldTimerManager().ClearTimer(time_handler);
		}
		break;
	}
}
Exemplo n.º 2
0
void AWeapon::Fire()
{
	if (ProjectileType == EWeaponProjectile::EBullet)
	{
		if (CurrentClip > 0)
		{
			GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Bullet"));
			Instant_Fire();
			PlayWeaponSound(FireSound);
			CurrentClip -= WeaponConfig.ShotCost;
		}
		else
		{
			ReloadAmmo();
		}
	}
	if (ProjectileType == EWeaponProjectile::ESpread)
	{
		if (CurrentClip > 0)
		{
			GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Spread"));
			for (int32 i = 0; i <= WeaponConfig.WeaponSpread; i++)
			{
				Instant_Fire();
			}
			PlayWeaponSound(FireSound);
			CurrentClip -= WeaponConfig.ShotCost;
		}
		else
		{
			ReloadAmmo();
		}
	}
	if (ProjectileType == EWeaponProjectile::EProjectile)
	{
		if (CurrentClip > 0)
		{
			GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Projectile"));
			ProjectileFire();
			PlayWeaponSound(FireSound);
			CurrentClip -= WeaponConfig.ShotCost;
		}
		else
		{
			ReloadAmmo();
		}
	}
}