diff --git a/Config/DefaultInput.ini b/Config/DefaultInput.ini index 19da539..e2688b2 100644 --- a/Config/DefaultInput.ini +++ b/Config/DefaultInput.ini @@ -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) diff --git a/Content/Assets/Animations/Reload_Rifle_Hip_Fixed.uasset b/Content/Assets/Animations/Reload_Rifle_Hip_Fixed.uasset new file mode 100644 index 0000000..1559403 Binary files /dev/null and b/Content/Assets/Animations/Reload_Rifle_Hip_Fixed.uasset differ diff --git a/Content/Assets/LearningKit_Games/Assets/Characters/Character/Mesh/SK_EpicCharacter_Skeleton.uasset b/Content/Assets/LearningKit_Games/Assets/Characters/Character/Mesh/SK_EpicCharacter_Skeleton.uasset index a193b8b..645ad06 100644 Binary files a/Content/Assets/LearningKit_Games/Assets/Characters/Character/Mesh/SK_EpicCharacter_Skeleton.uasset and b/Content/Assets/LearningKit_Games/Assets/Characters/Character/Mesh/SK_EpicCharacter_Skeleton.uasset differ diff --git a/Content/Blueprints/Character/Animation/Reload.uasset b/Content/Blueprints/Character/Animation/Reload.uasset new file mode 100644 index 0000000..06883b4 Binary files /dev/null and b/Content/Blueprints/Character/Animation/Reload.uasset differ diff --git a/Content/Blueprints/Character/BP_BlasterCharacter.uasset b/Content/Blueprints/Character/BP_BlasterCharacter.uasset index 6d87935..66903ab 100644 Binary files a/Content/Blueprints/Character/BP_BlasterCharacter.uasset and b/Content/Blueprints/Character/BP_BlasterCharacter.uasset differ diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index 5f82e86..1eb9feb 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -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) diff --git a/Source/Blaster/Character/BlasterCharacter.h b/Source/Blaster/Character/BlasterCharacter.h index e4a50d1..9b190f4 100644 --- a/Source/Blaster/Character/BlasterCharacter.h +++ b/Source/Blaster/Character/BlasterCharacter.h @@ -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; diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index c77dc6b..b8089e4 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -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; } -} \ No newline at end of file +} diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index e491dc7..7df5605 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -23,6 +23,7 @@ public: virtual void GetLifetimeReplicatedProps(TArray& 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;