Skip to content

Commit

Permalink
#142 Add empty ammo sound
Browse files Browse the repository at this point in the history
  • Loading branch information
xthebat committed Jan 29, 2024
1 parent 42f6c99 commit c2cec57
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 19 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Content/Blueprints/Weapons/WeaponTableDefinitions.uasset
Binary file not shown.
Binary file modified Content/Maps/warmup.umap
Binary file not shown.
70 changes: 52 additions & 18 deletions Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "Cloud9/Game/Cloud9PlayerController.h"
#include "Cloud9/Character/Cloud9Character.h"
#include "Cloud9/Game/Cloud9DeveloperSettings.h"
#include "Cloud9/Weapon/Sounds/Cloud9SoundPlayer.h"
#include "Cloud9/Weapon/Tables/WeaponTableFirearm.h"

const FName ACloud9WeaponFirearm::TracerProbabilityParameterName = TEXT("Probability");
Expand Down Expand Up @@ -76,13 +77,20 @@ bool ACloud9WeaponFirearm::OnInitialize(const FWeaponId& NewWeaponId, FName NewW

if (MyWeaponInfo->SilencerModel)
{
return InitializeMeshComponent(SilencerMesh, MyWeaponInfo->SilencerModel, MySkinInfo.Material);
if (not InitializeMeshComponent(SilencerMesh, MyWeaponInfo->SilencerModel, MySkinInfo.Material))
{
log(Error, "[Weapon='%s'] Can't initilaize SilencerMesh", *GetName());
return false;
}
}

CurrentAmmo = MyWeaponInfo->MagazineSize;
MagazineSize = MyWeaponInfo->MagazineSize;
AmmoInReserve = MyWeaponInfo->MaxAmmoInReserve;

log(Display, "[Weapon='%s'] CurrentAmmo=%d MagazineSize=%d AmmoInReserve=%d",
*GetName(), CurrentAmmo, MagazineSize, AmmoInReserve);

return true;
}

Expand Down Expand Up @@ -187,21 +195,26 @@ void ACloud9WeaponFirearm::Tick(float DeltaSeconds)
WeaponInfo->CycleTime,
[&]
{
if (not Fire(WeaponInfo, CommonData->Firearm))
let Status = Fire(WeaponInfo, CommonData->Firearm);

if (Status == EFirearmFireStatus::Error)
{
log(Error, "[Weapon='%s'] Weapon fire failure", *GetName());
return false;
}

if (not PlayAnimMontage(PoseMontages->PrimaryActionMontage))
if (Status == EFirearmFireStatus::Success)
{
log(Error, "[Weapon='%s'] No montage for primary action specified", *GetName());
return false;
if (not PlayAnimMontage(PoseMontages->PrimaryActionMontage))
{
log(Error, "[Weapon='%s'] No montage for primary action specified", *GetName());
return false;
}

// TODO: May be move to notifier?
MuzzleFlash->Activate(true);
}

// TODO: May be move to notifier?
MuzzleFlash->Activate(true);

return true;
}
);
Expand All @@ -226,32 +239,54 @@ const FFirearmWeaponInfo* ACloud9WeaponFirearm::GetWeaponInfo() const
return WeaponDefinition.GetWeaponInfo<FFirearmWeaponInfo>();
}

bool ACloud9WeaponFirearm::Fire(const FFirearmWeaponInfo* WeaponInfo, const FFirearmCommonData& FirearmCommonData)
EFirearmFireStatus ACloud9WeaponFirearm::Fire(
const FFirearmWeaponInfo* WeaponInfo,
const FFirearmCommonData& FirearmCommonData)
{
static let Settings = UCloud9DeveloperSettings::Get();

let Character = GetOwner<ACloud9Character>();

if (not IsValid(Character))
{
log(Error, "Character is invalid")
return false;
return EFirearmFireStatus::Error;
}

let Controller = Character->GetCloud9Controller();

if (not IsValid(Controller))
{
log(Error, "Can't hit object because player controller isn't valid")
return false;
return EFirearmFireStatus::Error;
}

if (CurrentAmmo == 0)
{
// TODO: Add click sound
return false;
let EmptyAmmoSound = WeaponInfo->Type == EWeaponType::Pistol
? FirearmCommonData.EmptyAmmoPistol
: FirearmCommonData.EmptyAmmoRifle;

if (IsValid(EmptyAmmoSound))
{
UCloud9SoundPlayer::PlaySingleSound(EmptyAmmoSound, GetActorLocation(), Settings->Volume);
}

return EFirearmFireStatus::OutOfAmmo;
}

// TODO: LowAmmo count???
if (CurrentAmmo < 3)
{
if (let Sound = FirearmCommonData.LowAmmo; IsValid(Sound))
{
UCloud9SoundPlayer::PlaySingleSound(Sound, GetActorLocation(), Settings->Volume);
}
}

CurrentAmmo -= 1;

// TODO: Remove after HUD added
log(Display, "[Weapon='%s'] CurrentAmmo=%d AmmoInReserve=%d", *GetName(), CurrentAmmo, AmmoInReserve);

EjectCase();
Expand All @@ -260,11 +295,9 @@ bool ACloud9WeaponFirearm::Fire(const FFirearmWeaponInfo* WeaponInfo, const FFir
if (not Controller->GetHitResultUnderCursor(ECC_Visibility, true, CursorHit))
{
log(Error, "Cursor not hit anything")
return true;
return EFirearmFireStatus::Success;
}

let Settings = UCloud9DeveloperSettings::Get();

var CollisionParams = FCollisionQueryParams::DefaultQueryParam;

if (Settings->bIsDrawHitScan)
Expand Down Expand Up @@ -339,9 +372,10 @@ bool ACloud9WeaponFirearm::Fire(const FFirearmWeaponInfo* WeaponInfo, const FFir
Squib->SetAutoDestroy(true);
}

return true;
return EFirearmFireStatus::Success;
}
return true;

return EFirearmFireStatus::Success;
}

bool ACloud9WeaponFirearm::UpdateReloadAmmo(bool IsShotgun)
Expand Down
11 changes: 10 additions & 1 deletion Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ class UCooldownActionComponent;
struct FWeaponActionMontages;
struct FFirearmWeaponInfo;

// Maybe just remove verbose logging?
UENUM()
enum class EFirearmFireStatus : uint8
{
Success = 0,
OutOfAmmo = 1,
Error = 0x80
};

UCLASS()
class CLOUD9_API ACloud9WeaponFirearm : public ACloud9WeaponBase
{
Expand All @@ -61,7 +70,7 @@ class CLOUD9_API ACloud9WeaponFirearm : public ACloud9WeaponBase

virtual void Tick(float DeltaSeconds) override;

bool Fire(const FFirearmWeaponInfo* WeaponInfo, const FFirearmCommonData& FirearmCommonData);
EFirearmFireStatus Fire(const FFirearmWeaponInfo* WeaponInfo, const FFirearmCommonData& FirearmCommonData);
bool UpdateReloadAmmo(bool IsShotgun);

bool UpdateMagazineAttachment(bool IsReload);
Expand Down
9 changes: 9 additions & 0 deletions Source/Cloud9/Weapon/Tables/WeaponCommonData.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ struct FFirearmCommonData

UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category=Visual)
UNiagaraSystem* Squib;

UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category=Sound)
USoundBase* LowAmmo;

UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category=Sound)
USoundBase* EmptyAmmoPistol;

UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category=Sound)
USoundBase* EmptyAmmoRifle;
};

USTRUCT(BlueprintType)
Expand Down

0 comments on commit c2cec57

Please sign in to comment.