144 - Shotgun Reload
This commit is contained in:
parent
d4afa9f956
commit
6fdfeef596
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -196,4 +196,5 @@ public:
|
|||
ECombatState GetCombatState() const;
|
||||
FORCEINLINE UCombatComponent* GetCombat() const { return Combat; }
|
||||
FORCEINLINE bool GetDisableGameplay() const { return bDisableGameplay; }
|
||||
FORCEINLINE UAnimMontage* GetReloadMontage() const { return ReloadMontage; }
|
||||
};
|
||||
|
|
|
@ -74,6 +74,14 @@ void UCombatComponent::FireButtonPressed(bool bPressed)
|
|||
}
|
||||
}
|
||||
|
||||
void UCombatComponent::ShotgunShellReload()
|
||||
{
|
||||
if (Character && Character->HasAuthority())
|
||||
{
|
||||
UpdateShotgunAmmoValues();
|
||||
}
|
||||
}
|
||||
|
||||
void UCombatComponent::Fire()
|
||||
{
|
||||
if (CanFire())
|
||||
|
@ -121,6 +129,13 @@ void UCombatComponent::ServerFire_Implementation(const FVector_NetQuantize& Trac
|
|||
void UCombatComponent::MulticastFire_Implementation(const FVector_NetQuantize& TraceHitTarget)
|
||||
{
|
||||
if (EquippedWeapon == nullptr) return;
|
||||
if (Character && CombatState == ECombatState::ECS_Reloading && EquippedWeapon->GetWeaponType() == EWeaponType::EWT_Shotgun)
|
||||
{
|
||||
Character->PlayFireMontage(bAiming);
|
||||
EquippedWeapon->Fire(TraceHitTarget);
|
||||
CombatState = ECombatState::ECS_Unoccupied;
|
||||
return;
|
||||
}
|
||||
if (Character && CombatState == ECombatState::ECS_Unoccupied)
|
||||
{
|
||||
Character->PlayFireMontage(bAiming);
|
||||
|
@ -188,7 +203,7 @@ void UCombatComponent::ServerReload_Implementation()
|
|||
|
||||
// return if weapon mag is at max capacity
|
||||
if (EquippedWeapon->GetAmmo() == EquippedWeapon->GetMagCapacity()) return;
|
||||
|
||||
|
||||
CombatState = ECombatState::ECS_Reloading;
|
||||
HandleReload();
|
||||
}
|
||||
|
@ -224,6 +239,38 @@ void UCombatComponent::UpdateAmmoValues()
|
|||
EquippedWeapon->AddAmmo(-ReloadAmount);
|
||||
}
|
||||
|
||||
void UCombatComponent::UpdateShotgunAmmoValues()
|
||||
{
|
||||
if (Character == nullptr || EquippedWeapon == nullptr) return;
|
||||
|
||||
if (CarriedAmmoMap.Contains(EquippedWeapon->GetWeaponType()))
|
||||
{
|
||||
CarriedAmmoMap[EquippedWeapon->GetWeaponType()] -= 1;
|
||||
CarriedAmmo = CarriedAmmoMap[EquippedWeapon->GetWeaponType()];
|
||||
}
|
||||
Controller = Controller == nullptr ? Cast<ABlasterPlayerController>(Character->Controller) : Controller;
|
||||
if (Controller)
|
||||
{
|
||||
Controller->SetHUDCarriedAmmo(CarriedAmmo);
|
||||
}
|
||||
EquippedWeapon->AddAmmo(-1);
|
||||
bCanFire = true;
|
||||
if (EquippedWeapon->IsFull() || CarriedAmmo == 0)
|
||||
{
|
||||
JumpToShotgunEnd();
|
||||
}
|
||||
}
|
||||
|
||||
void UCombatComponent::JumpToShotgunEnd()
|
||||
{
|
||||
// Jump to ShotgunEnd section
|
||||
UAnimInstance* AnimInstance = Character->GetMesh()->GetAnimInstance();
|
||||
if (AnimInstance && Character->GetReloadMontage())
|
||||
{
|
||||
AnimInstance->Montage_JumpToSection(FName("ShotgunEnd"));
|
||||
}
|
||||
}
|
||||
|
||||
void UCombatComponent::OnRep_CombatState()
|
||||
{
|
||||
switch (CombatState)
|
||||
|
@ -425,7 +472,7 @@ void UCombatComponent::SetAiming(bool bIsAiming)
|
|||
ServerSetAiming(bIsAiming);
|
||||
|
||||
Character->GetCharacterMovement()->MaxWalkSpeed = bIsAiming ? AimWalkSpeed : BaseWalkSpeed;
|
||||
|
||||
|
||||
if (Character->IsLocallyControlled() && EquippedWeapon->GetWeaponType() == EWeaponType::EWT_SniperRifle)
|
||||
{
|
||||
Character->ShowSniperScopeWidget(bIsAiming);
|
||||
|
@ -444,7 +491,10 @@ void UCombatComponent::ServerSetAiming_Implementation(bool bIsAiming)
|
|||
bool UCombatComponent::CanFire()
|
||||
{
|
||||
if (EquippedWeapon == nullptr) return false;
|
||||
return !EquippedWeapon->IsEmpty() && bCanFire && CombatState == ECombatState::ECS_Unoccupied;
|
||||
if (EquippedWeapon->IsEmpty()) return false;
|
||||
if (!bCanFire) return false;
|
||||
if (CombatState == ECombatState::ECS_Reloading && EquippedWeapon->GetWeaponType() == EWeaponType::EWT_Shotgun) return true;
|
||||
return CombatState == ECombatState::ECS_Unoccupied;
|
||||
}
|
||||
|
||||
void UCombatComponent::OnRep_CarriedAmmo()
|
||||
|
@ -454,6 +504,15 @@ void UCombatComponent::OnRep_CarriedAmmo()
|
|||
{
|
||||
Controller->SetHUDCarriedAmmo(CarriedAmmo);
|
||||
}
|
||||
bool bJumpToShotgunEnd = CombatState == ECombatState::ECS_Reloading &&
|
||||
EquippedWeapon != nullptr &&
|
||||
EquippedWeapon->GetWeaponType() == EWeaponType::EWT_Shotgun &&
|
||||
CarriedAmmo == 0;
|
||||
|
||||
if (bJumpToShotgunEnd)
|
||||
{
|
||||
JumpToShotgunEnd();
|
||||
}
|
||||
}
|
||||
|
||||
void UCombatComponent::InitializeCarriedAmmo()
|
||||
|
|
|
@ -25,9 +25,14 @@ public:
|
|||
void Reload();
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void FinishedReloading();
|
||||
void UpdateAmmoValues();
|
||||
|
||||
void FireButtonPressed(bool bPressed);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void ShotgunShellReload();
|
||||
|
||||
void JumpToShotgunEnd();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
void SetAiming(bool bIsAiming);
|
||||
|
@ -146,4 +151,7 @@ private:
|
|||
|
||||
UFUNCTION()
|
||||
void OnRep_CombatState();
|
||||
|
||||
void UpdateAmmoValues();
|
||||
void UpdateShotgunAmmoValues();
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "Casing.h"
|
||||
#include "Blaster/Character/BlasterCharacter.h"
|
||||
#include "Blaster/Components/CombatComponent.h"
|
||||
#include "Blaster/PlayerController/BlasterPlayerController.h"
|
||||
#include "Components/SphereComponent.h"
|
||||
#include "Components/WidgetComponent.h"
|
||||
|
@ -119,6 +120,11 @@ void AWeapon::SpendRound()
|
|||
|
||||
void AWeapon::OnRep_Ammo()
|
||||
{
|
||||
OwnerCharacter = OwnerCharacter == nullptr ? Cast<ABlasterCharacter>(GetOwner()) : OwnerCharacter;
|
||||
if (OwnerCharacter && OwnerCharacter->GetCombat() && IsFull())
|
||||
{
|
||||
OwnerCharacter->GetCombat()->JumpToShotgunEnd();
|
||||
}
|
||||
SetHUDAmmo();
|
||||
}
|
||||
|
||||
|
@ -160,6 +166,11 @@ bool AWeapon::IsEmpty()
|
|||
return Ammo <= 0;
|
||||
}
|
||||
|
||||
bool AWeapon::IsFull()
|
||||
{
|
||||
return Ammo == MagCapacity;
|
||||
}
|
||||
|
||||
void AWeapon::OnRep_WeaponState()
|
||||
{
|
||||
switch (WeaponState)
|
||||
|
|
|
@ -140,4 +140,5 @@ public:
|
|||
FORCEINLINE int32 GetAmmo() const { return Ammo; }
|
||||
FORCEINLINE int32 GetMagCapacity() const { return MagCapacity; }
|
||||
bool IsEmpty();
|
||||
bool IsFull();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue