diff --git a/Content/Blueprints/Character/BP_BlasterCharacter.uasset b/Content/Blueprints/Character/BP_BlasterCharacter.uasset index 0f48b3a..6d87935 100644 Binary files a/Content/Blueprints/Character/BP_BlasterCharacter.uasset and b/Content/Blueprints/Character/BP_BlasterCharacter.uasset differ diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index 6cf456e..c77dc6b 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -42,6 +42,10 @@ void UCombatComponent::BeginPlay() DefaultFOV = Character->GetFollowCamera()->FieldOfView; CurrentFOV = DefaultFOV; } + if (Character->HasAuthority()) + { + InitializeCarriedAmmo(); + } } } @@ -219,6 +223,16 @@ bool UCombatComponent::CanFire() void UCombatComponent::OnRep_CarriedAmmo() { + Controller = Controller == nullptr ? Cast(Character->Controller) : Controller; + if (Controller) + { + Controller->SetHUDCarriedAmmo(CarriedAmmo); + } +} + +void UCombatComponent::InitializeCarriedAmmo() +{ + CarriedAmmoMap.Emplace(EWeaponType::EWT_AssaultRifle, StartingARAmmo); } void UCombatComponent::ServerFire_Implementation(const FVector_NetQuantize& TraceHitTarget) @@ -299,6 +313,18 @@ void UCombatComponent::EquipWeapon(AWeapon* WeaponToEquip) } EquippedWeapon->SetOwner(Character); EquippedWeapon->SetHUDAmmo(); + + if (CarriedAmmoMap.Contains(EquippedWeapon->GetWeaponType())) + { + CarriedAmmo = CarriedAmmoMap[EquippedWeapon->GetWeaponType()]; + } + + Controller = Controller == nullptr ? Cast(Character->Controller) : Controller; + if (Controller) + { + Controller->SetHUDCarriedAmmo(CarriedAmmo); + } + Character->GetCharacterMovement()->bOrientRotationToMovement = false; Character->bUseControllerRotationYaw = true; } diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index c8c8686..e491dc7 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -110,4 +110,9 @@ private: void OnRep_CarriedAmmo(); TMap CarriedAmmoMap; + + UPROPERTY(EditAnywhere) + int32 StartingARAmmo = 30; + + void InitializeCarriedAmmo(); }; diff --git a/Source/Blaster/Weapon/Weapon.h b/Source/Blaster/Weapon/Weapon.h index 7a21a79..c6d2fbb 100644 --- a/Source/Blaster/Weapon/Weapon.h +++ b/Source/Blaster/Weapon/Weapon.h @@ -3,6 +3,7 @@ #pragma once #include "CoreMinimal.h" +#include "WeaponTypes.h" #include "GameFramework/Actor.h" #include "Weapon.generated.h" @@ -121,6 +122,9 @@ private: UPROPERTY() class ABlasterPlayerController* OwnerController; + + UPROPERTY(EditAnywhere) + EWeaponType WeaponType; public: void SetWeaponState(EWeaponState State); @@ -128,5 +132,6 @@ public: FORCEINLINE USkeletalMeshComponent* GetWeaponMesh() const { return WeaponMesh; }; FORCEINLINE float GetZoomedFOV() const { return ZoomedFOV; }; FORCEINLINE float GetZoomInterpSpeed() const { return ZoomInterpSpeed; }; + FORCEINLINE EWeaponType GetWeaponType() const { return WeaponType; } bool IsEmpty(); };