diff --git a/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset b/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset index c5b8a23..a180436 100644 Binary files a/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset and b/Content/Blueprints/Character/Animation/BlasterAnimBP.uasset differ diff --git a/Content/Blueprints/Character/Animation/Reload.uasset b/Content/Blueprints/Character/Animation/Reload.uasset index 06883b4..21ac83a 100644 Binary files a/Content/Blueprints/Character/Animation/Reload.uasset and b/Content/Blueprints/Character/Animation/Reload.uasset differ diff --git a/Source/Blaster/Character/BlasterAnimInstance.cpp b/Source/Blaster/Character/BlasterAnimInstance.cpp index 73094a0..f59c41e 100644 --- a/Source/Blaster/Character/BlasterAnimInstance.cpp +++ b/Source/Blaster/Character/BlasterAnimInstance.cpp @@ -74,4 +74,6 @@ void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaSeconds) RightHandRotation = FMath::RInterpTo(RightHandRotation, LookAtRotation, DeltaSeconds, 30.f); } } + + bUseFABRIK = BlasterCharacter->GetCombatState() != ECombatState::ECS_Reloading; } diff --git a/Source/Blaster/Character/BlasterAnimInstance.h b/Source/Blaster/Character/BlasterAnimInstance.h index 0edd344..fa6da7d 100644 --- a/Source/Blaster/Character/BlasterAnimInstance.h +++ b/Source/Blaster/Character/BlasterAnimInstance.h @@ -79,4 +79,7 @@ private: UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true")) bool bEliminated; + + UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true")) + bool bUseFABRIK; }; diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index 1eb9feb..9a3c412 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -636,6 +636,12 @@ FVector ABlasterCharacter::GetHitTarget() const return Combat->HitTarget; } +ECombatState ABlasterCharacter::GetCombatState() const +{ + if (Combat == nullptr) return ECombatState::ECS_MAX; + return Combat->CombatState; +} + void ABlasterCharacter::OnRep_OverlappingWeapon(AWeapon* LastWeapon) { if (OverlappingWeapon) diff --git a/Source/Blaster/Character/BlasterCharacter.h b/Source/Blaster/Character/BlasterCharacter.h index 9b190f4..497f5d8 100644 --- a/Source/Blaster/Character/BlasterCharacter.h +++ b/Source/Blaster/Character/BlasterCharacter.h @@ -4,6 +4,7 @@ #include "CoreMinimal.h" #include "Blaster/Interfaces/InteractWithCrosshairInterface.h" +#include "Blaster/Types/CombatState.h" #include "Blaster/Types/TurningInPlace.h" #include "Components/TimelineComponent.h" #include "GameFramework/Character.h" @@ -78,7 +79,7 @@ private: UFUNCTION() void OnRep_OverlappingWeapon(AWeapon* LastWeapon); - UPROPERTY(VisibleAnywhere) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true")) class UCombatComponent* Combat; UFUNCTION(Server, Reliable) @@ -184,4 +185,5 @@ public: FORCEINLINE bool IsEliminated() const { return bEliminated; } FORCEINLINE float GetHealth() const { return Health; } FORCEINLINE float GetMaxHealth() const { return MaxHealth; } + ECombatState GetCombatState() const; }; diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index b8089e4..b971afa 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -27,6 +27,7 @@ void UCombatComponent::GetLifetimeReplicatedProps(TArray& Out DOREPLIFETIME(UCombatComponent, EquippedWeapon); DOREPLIFETIME_CONDITION(UCombatComponent, CarriedAmmo, COND_OwnerOnly); DOREPLIFETIME(UCombatComponent, bAiming); + DOREPLIFETIME(UCombatComponent, CombatState); } void UCombatComponent::BeginPlay() @@ -331,16 +332,41 @@ void UCombatComponent::EquipWeapon(AWeapon* WeaponToEquip) void UCombatComponent::Reload() { - if (CarriedAmmo > 0) + if (CarriedAmmo > 0 && CombatState != ECombatState::ECS_Reloading) { ServerReload(); } } +void UCombatComponent::FinishedReloading() +{ + if (Character == nullptr) return; + if (Character->HasAuthority()) + { + CombatState = ECombatState::ECS_Unoccupied;; + } +} + void UCombatComponent::ServerReload_Implementation() { if (Character == nullptr) return; + CombatState = ECombatState::ECS_Reloading; + HandleReload(); +} + +void UCombatComponent::OnRep_CombatState() +{ + switch (CombatState) + { + case ECombatState::ECS_Reloading: + HandleReload(); + break; + } +} + +void UCombatComponent::HandleReload() +{ Character->PlayReloadMontage(); } diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index 7df5605..c51aad0 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -4,6 +4,7 @@ #include "CoreMinimal.h" #include "Blaster/HUD/BlasterHUD.h" +#include "Blaster/Types/CombatState.h" #include "Blaster/Weapon/WeaponTypes.h" #include "Components/ActorComponent.h" #include "CombatComponent.generated.h" @@ -24,6 +25,8 @@ public: void EquipWeapon(class AWeapon* WeaponToEquip); void Reload(); + UFUNCTION(BlueprintCallable) + void FinishedReloading(); protected: virtual void BeginPlay() override; @@ -50,6 +53,8 @@ protected: UFUNCTION(Server, Reliable) void ServerReload(); + + void HandleReload(); private: UPROPERTY() class ABlasterCharacter* Character; @@ -118,4 +123,10 @@ private: int32 StartingARAmmo = 30; void InitializeCarriedAmmo(); + + UPROPERTY(ReplicatedUsing=OnRep_CombatState) + ECombatState CombatState = ECombatState::ECS_Unoccupied; + + UFUNCTION() + void OnRep_CombatState(); }; diff --git a/Source/Blaster/Types/CombatState.h b/Source/Blaster/Types/CombatState.h new file mode 100644 index 0000000..0a82ac1 --- /dev/null +++ b/Source/Blaster/Types/CombatState.h @@ -0,0 +1,10 @@ +#pragma once + +UENUM(BlueprintType) +enum class ECombatState : uint8 +{ + ECS_Unoccupied UMETA(DisplayName = "Unoccupied"), + ECS_Reloading UMETA(DisplayName = "Reloading"), + + ECS_MAX UMETA(DisplayName = "DefaultMAX") +};