parent
312cf74de4
commit
4f847d25fd
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.
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.
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.
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -42,7 +42,7 @@ UPrimitiveComponent* ABaseEquippable::GetItemMesh()
|
|||
void ABaseEquippable::OnEquipped()
|
||||
{
|
||||
SetIsEquipped(true);
|
||||
AttachToActor(this, FAttachmentTransformRules::SnapToTargetNotIncludingScale, AttachSocketName);
|
||||
AttachActor(AttachSocketName);
|
||||
}
|
||||
|
||||
void ABaseEquippable::OnUnequipped()
|
||||
|
|
|
@ -24,12 +24,12 @@ public:
|
|||
virtual void SetIsEquipped(bool IsEquipped);
|
||||
virtual bool GetIsEquipped();
|
||||
protected:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
|
||||
class USceneComponent* DefaultSceneRoot;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Mesh, meta = (AllowPrivateAccess = "true"))
|
||||
class USkeletalMeshComponent* ItemSkeletalMesh;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Mesh, meta = (AllowPrivateAccess = "true"))
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Mesh, meta = (AllowPrivateAccess = "true"))
|
||||
class UStaticMeshComponent* ItemStaticMesh;
|
||||
protected:
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
|
||||
|
|
|
@ -68,7 +68,7 @@ void ABaseWeapon::OnHit(FHitResult hitResult)
|
|||
if (pActor)
|
||||
{
|
||||
if (pActor->Execute_CanReceiveDamage(hitResult.GetActor()))
|
||||
UGameplayStatics::ApplyPointDamage(hitResult.GetActor(), Damage, GetOwner()->GetActorForwardVector(), hitResult, GetInstigatorController(), this, TSubclassOf<UDamageType>(UDamageType::StaticClass()));
|
||||
UGameplayStatics::ApplyPointDamage(hitResult.GetActor(), GetDamage(), GetOwner()->GetActorForwardVector(), hitResult, GetInstigatorController(), this, TSubclassOf<UDamageType>(UDamageType::StaticClass()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Actor/MasterPose.h"
|
||||
#include "MasterPose.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "Components/StatsComponent.h"
|
||||
|
||||
AMasterPose::AMasterPose()
|
||||
{
|
||||
ArmorValue = 2.f;
|
||||
}
|
||||
|
||||
void AMasterPose::AttachActor(const FName SocketName)
|
||||
{
|
||||
USkeletalMesh* skelMeshAsset = ItemSkeletalMesh->GetSkeletalMeshAsset();
|
||||
if (!IsValid(skelMeshAsset))
|
||||
return;
|
||||
|
||||
|
||||
USkeletalMeshComponent* OwnerSkelMesh = Cast<ACharacter>(GetOwner())->GetMesh();
|
||||
if (!IsValid(OwnerSkelMesh))
|
||||
return;
|
||||
|
||||
FAttachmentTransformRules rules(EAttachmentRule::KeepRelative, EAttachmentRule::KeepRelative, EAttachmentRule::KeepRelative, true);
|
||||
ItemSkeletalMesh->AttachToComponent(OwnerSkelMesh, rules, SocketName);
|
||||
ItemSkeletalMesh->SetLeaderPoseComponent(OwnerSkelMesh);
|
||||
}
|
||||
|
||||
void AMasterPose::OnEquipped()
|
||||
{
|
||||
Super::OnEquipped();
|
||||
if (UStatsComponent* StatComponent = GetOwner()->GetComponentByClass<UStatsComponent>())
|
||||
StatComponent->ModifyCurrentStatValue(EStats::Armor, ArmorValue, false);
|
||||
}
|
||||
|
||||
void AMasterPose::OnUnequipped()
|
||||
{
|
||||
Super::OnUnequipped();
|
||||
if (UStatsComponent* StatComponent = GetOwner()->GetComponentByClass<UStatsComponent>())
|
||||
StatComponent->ModifyCurrentStatValue(EStats::Armor, -1.f * ArmorValue);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Actor/BaseEquippable.h"
|
||||
#include "MasterPose.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class D1_API AMasterPose : public ABaseEquippable
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
AMasterPose();
|
||||
|
||||
public:
|
||||
virtual void AttachActor(const FName SocketName) override;
|
||||
virtual void OnEquipped() override;
|
||||
virtual void OnUnequipped() override;
|
||||
|
||||
public:
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Stats")
|
||||
float ArmorValue;
|
||||
};
|
|
@ -139,7 +139,7 @@ private:
|
|||
bool PerformAction(ECharacterState characterState, ECharacterAction characterAction, int32 montageIndex);
|
||||
void PerformDeath();
|
||||
|
||||
private:
|
||||
protected:
|
||||
bool CanPerformToggleCombat();
|
||||
bool CanPerformAttack();
|
||||
bool CanPerformDodge();
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "CombatPlayerController.h"
|
||||
#include "UI/UI_MainHUD.h"
|
||||
|
||||
void ACombatPlayerController::BeginPlay()
|
||||
{
|
||||
if (MainHUDClass)
|
||||
{
|
||||
UUI_MainHUD* mainHUD = CreateWidget<UUI_MainHUD>(this, MainHUDClass);
|
||||
mainHUD->AddToViewport();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "CombatPlayerController.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class D1_API ACombatPlayerController : public APlayerController
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
private:
|
||||
UPROPERTY(EditDefaultsOnly, Category = UI)
|
||||
TSubclassOf<class UUI_MainHUD> MainHUDClass;
|
||||
};
|
|
@ -4,6 +4,7 @@
|
|||
#include "Components/StatsComponent.h"
|
||||
#include "Components/StateManagerComponent.h"
|
||||
#include "Math/UnrealMathUtility.h"
|
||||
#include "Kismet/KismetSystemLibrary.h"
|
||||
|
||||
// Sets default values for this component's properties
|
||||
UStatsComponent::UStatsComponent()
|
||||
|
@ -96,7 +97,7 @@ void UStatsComponent::StartRegen(EStats statType)
|
|||
if (World)
|
||||
{
|
||||
World->GetTimerManager().ClearTimer(RegenTimerHandle);
|
||||
World->GetTimerManager().SetTimer(RegenTimerHandle, this, &UStatsComponent::RegenerateStamina, 1.5f, true);
|
||||
World->GetTimerManager().SetTimer(AfterRegenTimerHandle, this, &UStatsComponent::AfterDelayExecuteRegenStamina, 1.5f, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,12 +109,28 @@ void UStatsComponent::StartRegen(EStats statType)
|
|||
}
|
||||
}
|
||||
|
||||
void UStatsComponent::AfterDelayExecuteRegenStamina()
|
||||
{
|
||||
if (GEngine)
|
||||
{
|
||||
UWorld* World = GEngine->GetWorldFromContextObjectChecked(this);
|
||||
if (World)
|
||||
{
|
||||
World->GetTimerManager().ClearTimer(RegenTimerHandle);
|
||||
World->GetTimerManager().SetTimer(RegenTimerHandle, this, &UStatsComponent::RegenerateStamina, 0.1f, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UStatsComponent::RegenerateStamina()
|
||||
{
|
||||
float curStamina = StaminaRegenRate + GetCurrentStatValue(EStats::Stamina);
|
||||
curStamina = FMath::Clamp(curStamina, 0.f, GetMaxStatValue(EStats::Stamina));
|
||||
SetCurrentStatValue(EStats::Stamina, curStamina);
|
||||
|
||||
//FString debugStr = FString::Printf(TEXT("Stamina %f"), curStamina);
|
||||
//GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Blue, debugStr);
|
||||
|
||||
if (GetCurrentStatValue(EStats::Stamina) >= GetMaxStatValue(EStats::Stamina))
|
||||
{
|
||||
UWorld* World = GEngine->GetWorldFromContextObjectChecked(this);
|
||||
|
|
|
@ -55,6 +55,7 @@ public:
|
|||
void ModifyCurrentStatValue(EStats stat, float value, bool bShouldRegenerate = true);
|
||||
void TakeDamageOnStat(float inDamage);
|
||||
void StartRegen(EStats statType);
|
||||
void AfterDelayExecuteRegenStamina();
|
||||
void RegenerateStamina();
|
||||
|
||||
public:
|
||||
|
@ -77,5 +78,6 @@ public: //Delegate
|
|||
FOnCurrentStatValueUpdated OnCurrentStatValueUpdated;
|
||||
|
||||
private:
|
||||
FTimerHandle AfterRegenTimerHandle;
|
||||
FTimerHandle RegenTimerHandle;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "TestDummyCharacter.h"
|
||||
#include "Engine/DamageEvents.h"
|
||||
#include "Actor/BaseEquippable.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
void ATestDummyCharacter::BeginPlay()
|
||||
{
|
||||
ACharacter::BeginPlay();
|
||||
StatsComponent->InitializeStats();
|
||||
|
||||
for (auto armor : StartingEquipment)
|
||||
{
|
||||
FActorSpawnParameters spawnParam;
|
||||
spawnParam.Owner = this;
|
||||
spawnParam.Instigator = this;
|
||||
ABaseEquippable* SpawnItem = Cast<ABaseEquippable>(GetWorld()->SpawnActor(armor, &GetActorTransform(), spawnParam));
|
||||
if (SpawnItem)
|
||||
SpawnItem->OnEquipped();
|
||||
}
|
||||
}
|
||||
|
||||
//float ATestDummyCharacter::TakeDamage(float Damage, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
|
||||
//{
|
||||
// float fDamage = ACharacter::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser);
|
||||
//
|
||||
// if (DamageEvent.IsOfType(FPointDamageEvent::ClassID))
|
||||
// {
|
||||
// const FPointDamageEvent* PointDamageEvent = static_cast<const FPointDamageEvent*>(&DamageEvent);
|
||||
//
|
||||
// StatsComponent->TakeDamageOnStat(Damage);
|
||||
//
|
||||
// //Play Sound
|
||||
// UGameplayStatics::PlaySoundAtLocation(this, HitSound, PointDamageEvent->HitInfo.Location);
|
||||
//
|
||||
// //Hit Effect
|
||||
// UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), HitEmitter, PointDamageEvent->HitInfo.Location);
|
||||
//
|
||||
// if (CanReceiveHitReaction())
|
||||
// {
|
||||
// StateManagerComponent->SetCurrentState(ECharacterState::Disable);
|
||||
//
|
||||
// //Play Animation
|
||||
// PlayAnimMontage(HitMontage);
|
||||
// }
|
||||
// }
|
||||
// return fDamage;
|
||||
//}
|
|
@ -0,0 +1,23 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "CombatCharacter.h"
|
||||
#include "TestDummyCharacter.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class D1_API ATestDummyCharacter : public ACombatCharacter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TArray<TSubclassOf<class ABaseEquippable>> StartingEquipment;
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "UI/UI_MainHUD.h"
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "UI_MainHUD.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class D1_API UUI_MainHUD : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
TObjectPtr<class UUI_StatBar> HealthBar;
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
TObjectPtr<class UUI_StatBar> StaminaBar;
|
||||
};
|
|
@ -4,7 +4,25 @@
|
|||
#include "UI/UI_StatBar.h"
|
||||
#include "Components/ProgressBar.h"
|
||||
|
||||
void UUI_StatBar::PreConstruct()
|
||||
void UUI_StatBar::NativeConstruct()
|
||||
{
|
||||
|
||||
APawn* pplayer = GetOwningPlayerPawn();
|
||||
if (pplayer)
|
||||
{
|
||||
StatsComponent = pplayer->GetComponentByClass<UStatsComponent>();
|
||||
if (IsValid(StatsComponent))
|
||||
StatsComponent->OnCurrentStatValueUpdated.AddUObject(this, &UUI_StatBar::StatBarStatValueUpdated);
|
||||
}
|
||||
}
|
||||
|
||||
void UUI_StatBar::StatBarStatValueUpdated(EStats stat, float value)
|
||||
{
|
||||
if (StatType != stat)
|
||||
return;
|
||||
|
||||
if (!IsValid(StatsComponent))
|
||||
return;
|
||||
|
||||
float fPercent = value / StatsComponent->GetMaxStatValue(StatType);
|
||||
StatBar->SetPercent(fPercent);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "Components/StatsComponent.h"
|
||||
#include "UI_StatBar.generated.h"
|
||||
|
||||
/**
|
||||
|
@ -15,8 +16,16 @@ class D1_API UUI_StatBar : public UUserWidget
|
|||
|
||||
GENERATED_BODY()
|
||||
protected:
|
||||
virtual void PreConstruct() override;
|
||||
virtual void NativeConstruct() override;
|
||||
public: //Delegate
|
||||
void StatBarStatValueUpdated(EStats stat, float value);
|
||||
public:
|
||||
UPROPERTY(EditAnywhere, meta = (BindWidget))
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidget))
|
||||
class UProgressBar* StatBar;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Initialization , meta=(AllowPrivateAccess="true"))
|
||||
EStats StatType;
|
||||
|
||||
UPROPERTY(visibleAnywhere, BlueprintReadWrite, Category=Initialization , meta=(AllowPrivateAccess="true"))
|
||||
TObjectPtr<UStatsComponent> StatsComponent;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue