113 - Reloading

This commit is contained in:
Kingsmedia 2022-05-09 22:19:20 +02:00
parent 2d10e1886d
commit f630c5d6a2
9 changed files with 56 additions and 2 deletions

View File

@ -79,6 +79,7 @@ DoubleClickTime=0.200000
+ActionMappings=(ActionName="Crouch",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=LeftControl)
+ActionMappings=(ActionName="Aim",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=RightMouseButton)
+ActionMappings=(ActionName="Fire",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=LeftMouseButton)
+ActionMappings=(ActionName="Reload",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=R)
+AxisMappings=(AxisName="MoveForward",Scale=1.000000,Key=W)
+AxisMappings=(AxisName="MoveForward",Scale=-1.000000,Key=S)
+AxisMappings=(AxisName="MoveRight",Scale=1.000000,Key=D)

Binary file not shown.

View File

@ -116,6 +116,25 @@ void ABlasterCharacter::PlayFireMontage(bool bAiming)
}
}
void ABlasterCharacter::PlayReloadMontage()
{
if (Combat == nullptr || Combat->EquippedWeapon == nullptr) return;
UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (AnimInstance && ReloadMontage)
{
AnimInstance->Montage_Play(ReloadMontage);
FName SectionName;
switch (Combat->EquippedWeapon->GetWeaponType())
{
case EWeaponType::EWT_AssaultRifle:
SectionName = FName("Rifle");
break;
}
AnimInstance->Montage_JumpToSection(SectionName);
}
}
void ABlasterCharacter::PlayEliminatedMontage()
{
UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
@ -266,6 +285,7 @@ void ABlasterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCo
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ABlasterCharacter::Jump);
PlayerInputComponent->BindAction("Equip", IE_Pressed, this, &ABlasterCharacter::EquipButtonPressed);
PlayerInputComponent->BindAction("Reload", IE_Pressed, this, &ABlasterCharacter::ReloadButtonPressed);
PlayerInputComponent->BindAction("Crouch", IE_Pressed, this, &ABlasterCharacter::CrouchButtonPressed);
PlayerInputComponent->BindAction("Aim", IE_Pressed, this, &ABlasterCharacter::AimButtonPressed);
PlayerInputComponent->BindAction("Aim", IE_Released, this, &ABlasterCharacter::AimButtonReleased);
@ -325,6 +345,14 @@ void ABlasterCharacter::EquipButtonPressed()
}
}
void ABlasterCharacter::ReloadButtonPressed()
{
if (Combat)
{
Combat->Reload();
}
}
void ABlasterCharacter::CrouchButtonPressed()
{
if (bIsCrouched)

View File

@ -24,6 +24,7 @@ public:
virtual void OnRep_ReplicatedMovement() override;
virtual void Destroyed() override;
void PlayFireMontage(bool bAiming);
void PlayReloadMontage();
void PlayEliminatedMontage();
void Eliminated();
@ -39,6 +40,7 @@ protected:
void Turn(float Value);
void LookUp(float Value);
void EquipButtonPressed();
void ReloadButtonPressed();
void CrouchButtonPressed();
void AimButtonPressed();
void AimButtonReleased();
@ -90,8 +92,13 @@ private:
ETurningInPlace TurningInPlace;
void TurnInPlace(float DeltaTime);
// Animation montages
UPROPERTY(EditAnywhere, Category = Combat)
class UAnimMontage* FireWeaponMontage;
UPROPERTY(EditAnywhere, Category = Combat)
class UAnimMontage* ReloadMontage;
UPROPERTY(EditAnywhere, Category = Combat)
class UAnimMontage* HitReactMontage;

View File

@ -329,6 +329,21 @@ void UCombatComponent::EquipWeapon(AWeapon* WeaponToEquip)
Character->bUseControllerRotationYaw = true;
}
void UCombatComponent::Reload()
{
if (CarriedAmmo > 0)
{
ServerReload();
}
}
void UCombatComponent::ServerReload_Implementation()
{
if (Character == nullptr) return;
Character->PlayReloadMontage();
}
void UCombatComponent::OnRep_EquippedWeapon()
{
if (EquippedWeapon && Character)
@ -342,4 +357,4 @@ void UCombatComponent::OnRep_EquippedWeapon()
Character->GetCharacterMovement()->bOrientRotationToMovement = false;
Character->bUseControllerRotationYaw = true;
}
}
}

View File

@ -23,6 +23,7 @@ public:
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
void EquipWeapon(class AWeapon* WeaponToEquip);
void Reload();
protected:
virtual void BeginPlay() override;
@ -46,7 +47,9 @@ protected:
void TraceUnderCrosshairs(FHitResult& TraceHitResult);
void SetHUDCrosshairs(float DeltaTime);
UFUNCTION(Server, Reliable)
void ServerReload();
private:
UPROPERTY()
class ABlasterCharacter* Character;