Updated Thorns Status Effect to Trigger OnPlayerDamage

This commit is contained in:
Philip W 2023-03-02 03:25:00 +00:00
parent 6227b4952c
commit 0be235f6b1
9 changed files with 63 additions and 25 deletions

Binary file not shown.

View File

@ -20,6 +20,9 @@ void UStatusEffect::OnExpiry(AActor* Character)
if (StatusSystem->GetActiveStatusEffect(this).StatusIcon == nullptr) return; if (StatusSystem->GetActiveStatusEffect(this).StatusIcon == nullptr) return;
StatusSystem->GetActiveStatusEffect(this).StatusIcon->RemoveFromParent(); StatusSystem->GetActiveStatusEffect(this).StatusIcon->RemoveFromParent();
StatusSystem->RemoveStatusEffect(this); StatusSystem->RemoveStatusEffect(this);
ATurnBaseCombatV2* CombatSystem = Cast<ATurnBaseCombatV2>(GetWorld()->GetGameState());
CombatSystem->OnPlayerTurn.Remove(OnPlayerTurnDelegateHandle);
CombatSystem->OnEnemyTurn.Remove(OnEnemyTurnDelegateHandle);
} }
void UStatusEffect::OnPlayerTurn(AActor* Character, AActor* Enemy) void UStatusEffect::OnPlayerTurn(AActor* Character, AActor* Enemy)
@ -35,8 +38,8 @@ void UStatusEffect::OnEnemyTurn(AActor* Enemy, AActor* Character)
void UStatusEffect::OnStatusEffectAdd() void UStatusEffect::OnStatusEffectAdd()
{ {
ATurnBaseCombatV2* CombatSystem = Cast<ATurnBaseCombatV2>(GetWorld()->GetGameState()); ATurnBaseCombatV2* CombatSystem = Cast<ATurnBaseCombatV2>(GetWorld()->GetGameState());
CombatSystem->OnPlayerTurn.AddUObject(this, &UStatusEffect::OnPlayerTurn); OnPlayerTurnDelegateHandle = CombatSystem->OnPlayerTurn.AddUObject(this, &UStatusEffect::OnPlayerTurn);
CombatSystem->OnEnemyTurn.AddUObject(this, &UStatusEffect::OnEnemyTurn); OnEnemyTurnDelegateHandle = CombatSystem->OnEnemyTurn.AddUObject(this, &UStatusEffect::OnEnemyTurn);
} }
void UStatusEffect::CheckForExpiry(const float TimeOfExpiry, AActor* Character) void UStatusEffect::CheckForExpiry(const float TimeOfExpiry, AActor* Character)

View File

@ -20,6 +20,8 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString Description; FString Description;
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool IsForCombatOnly = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float BaseDuration; float BaseDuration;
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
UTexture2D* Icon; UTexture2D* Icon;
@ -42,4 +44,7 @@ protected:
FTimerHandle ExpiryTimerHandle; FTimerHandle ExpiryTimerHandle;
UFUNCTION() UFUNCTION()
void CheckForExpiry(float TimeOfExpiry, AActor* Character); void CheckForExpiry(float TimeOfExpiry, AActor* Character);
FDelegateHandle OnPlayerTurnDelegateHandle;
FDelegateHandle OnEnemyTurnDelegateHandle;
}; };

View File

@ -3,6 +3,8 @@
#include "Thorns.h" #include "Thorns.h"
#include "the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h"
void UThorns::Invoke(AActor* Character, float TimeOfExpiry) void UThorns::Invoke(AActor* Character, float TimeOfExpiry)
{ {
Super::Invoke(Character, TimeOfExpiry); Super::Invoke(Character, TimeOfExpiry);
@ -12,3 +14,15 @@ void UThorns::OnExpiry(AActor* Character)
{ {
Super::OnExpiry(Character); Super::OnExpiry(Character);
} }
void UThorns::OnEnemyTurn(AActor* Enemy, AActor* Character)
{
Super::OnEnemyTurn(Enemy, Character);
ATurnBaseCombatV2* CombatSystem = Cast<ATurnBaseCombatV2>(GetWorld()->GetGameState());
CombatSystem->DamageEnemy(DamagePerTurn, "thorns");
BaseDuration -= 1.0f;
if (BaseDuration <= 0.0f)
{
OnExpiry(Character);
}
}

View File

@ -15,6 +15,10 @@ class THE_TWILIGHT_ABYSS_API UThorns : public UStatusEffect
GENERATED_BODY() GENERATED_BODY()
public: public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float DamagePerTurn = 3.0f;
virtual void Invoke(AActor* Character, float TimeOfExpiry) override; virtual void Invoke(AActor* Character, float TimeOfExpiry) override;
virtual void OnExpiry(AActor* Character) override; virtual void OnExpiry(AActor* Character) override;
virtual void OnEnemyTurn(AActor* Enemy, AActor* Character) override;
}; };

View File

@ -43,7 +43,14 @@ void UStatusSystem::AddStatusEffect(UStatusEffect* StatusEffect, const float Dur
FActiveStatusEffect NewStatusEffect; FActiveStatusEffect NewStatusEffect;
NewStatusEffect.StatusEffect = StatusEffect; NewStatusEffect.StatusEffect = StatusEffect;
NewStatusEffect.TimeInitiated = UGameplayStatics::GetRealTimeSeconds(GetWorld()); NewStatusEffect.TimeInitiated = UGameplayStatics::GetRealTimeSeconds(GetWorld());
NewStatusEffect.TimeTillExpiry = UGameplayStatics::GetRealTimeSeconds(GetWorld()) + StatusEffect->BaseDuration * DurationMultiplier; if (StatusEffect->IsForCombatOnly)
{
NewStatusEffect.TimeTillExpiry = StatusEffect->BaseDuration * DurationMultiplier;
}
else
{
NewStatusEffect.TimeTillExpiry = UGameplayStatics::GetRealTimeSeconds(GetWorld()) + StatusEffect->BaseDuration * DurationMultiplier;
}
NewStatusEffect.StatusIcon = CreateWidget<UUserWidget>(GetWorld(), HUDStatusIconWidget); NewStatusEffect.StatusIcon = CreateWidget<UUserWidget>(GetWorld(), HUDStatusIconWidget);
UImage* StatusIconImage = Cast<UImage>(NewStatusEffect.StatusIcon->GetWidgetFromName(TEXT("StatusIconImage"))); UImage* StatusIconImage = Cast<UImage>(NewStatusEffect.StatusIcon->GetWidgetFromName(TEXT("StatusIconImage")));
StatusIconImage->SetBrushFromTexture(StatusEffect->Icon); StatusIconImage->SetBrushFromTexture(StatusEffect->Icon);

View File

@ -86,15 +86,15 @@ void ATurnBaseCombatV2::EndCombat()
PlayerController->bShowMouseCursor = false; PlayerController->bShowMouseCursor = false;
} }
void ATurnBaseCombatV2::FKeyPressed() // void ATurnBaseCombatV2::FKeyPressed()
{ // {
PButtonOnClick(); // PButtonOnClick();
} // }
//
void ATurnBaseCombatV2::WKeyPressed() // void ATurnBaseCombatV2::WKeyPressed()
{ // {
EButtonOnClick(); // EButtonOnClick();
} // }
void ATurnBaseCombatV2::BeginPlay() void ATurnBaseCombatV2::BeginPlay()
{ {
@ -176,6 +176,7 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo)
UStatusEffect* TempThornsStatusEffect = NewObject<UStatusEffect>(PlayerActor, ThornsStatusEffect); UStatusEffect* TempThornsStatusEffect = NewObject<UStatusEffect>(PlayerActor, ThornsStatusEffect);
StatusSystem->AddStatusEffect(TempThornsStatusEffect, 1, false); StatusSystem->AddStatusEffect(TempThornsStatusEffect, 1, false);
StatusEffects.Add(TempThornsStatusEffect); StatusEffects.Add(TempThornsStatusEffect);
AddBattleLogMessage("Player Casted Thorns");
} }
} }
@ -191,6 +192,7 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo)
RevertActionPoints(); RevertActionPoints();
UpdateActionPoints(); UpdateActionPoints();
//Damage Calculation
switch (bIsPlayerTurn) switch (bIsPlayerTurn)
{ {
case true: case true:
@ -241,18 +243,18 @@ void ATurnBaseCombatV2::RevertActionPoints()
UpdateActionPoints(); UpdateActionPoints();
} }
void ATurnBaseCombatV2::DamagePlayer(int Damage) void ATurnBaseCombatV2::DamagePlayer(int Damage, FString DamageType)
{ {
*PlayerHealth -= FMath::Clamp(Damage, 0, 100); *PlayerHealth -= FMath::Clamp(Damage, 0, 100);
UpdateProgressBars(); UpdateProgressBars();
AddBattleLogMessage("Player was damaged for " + FString::FromInt(Damage) + " damage."); AddBattleLogMessage("Player was damaged for " + FString::FromInt(Damage) + " HP by " + DamageType + ".");
} }
void ATurnBaseCombatV2::DamageEnemy(int Damage) void ATurnBaseCombatV2::DamageEnemy(int Damage, FString DamageType)
{ {
*EnemyHealth -= FMath::Clamp(Damage, 0, 100); *EnemyHealth -= FMath::Clamp(Damage, 0, 100);
UpdateProgressBars(); UpdateProgressBars();
AddBattleLogMessage("Enemy was damaged for " + FString::FromInt(Damage) + " damage."); AddBattleLogMessage("Enemy was damaged for " + FString::FromInt(Damage) + " HP by " + DamageType + ".");
} }
void ATurnBaseCombatV2::UpdateProgressBars() const void ATurnBaseCombatV2::UpdateProgressBars() const
@ -455,6 +457,7 @@ void ATurnBaseCombatV2::ToggleButtons() const
void ATurnBaseCombatV2::EnemyTurn() void ATurnBaseCombatV2::EnemyTurn()
{ {
DamagePlayer(10); DamagePlayer(10);
OnEnemyTurn.Broadcast(EnemyActor, PlayerActor);
TurnIndicatorTextBlock->SetText(FText::FromString("Player Turn")); TurnIndicatorTextBlock->SetText(FText::FromString("Player Turn"));
ToggleButtons(); ToggleButtons();
} }

View File

@ -94,15 +94,18 @@ public:
void StartCombat(AActor* Enemy); void StartCombat(AActor* Enemy);
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void EndCombat(); void EndCombat();
UFUNCTION(BlueprintCallable) // UFUNCTION(BlueprintCallable)
void FKeyPressed(); // void FKeyPressed();
UFUNCTION(BlueprintCallable) // UFUNCTION(BlueprintCallable)
void WKeyPressed(); // void WKeyPressed();
DECLARE_EVENT_TwoParams(ATurnBaseCombatV2, FOnPlayerTurn, AActor*, AActor*); DECLARE_EVENT_TwoParams(ATurnBaseCombatV2, FOnPlayerTurn, AActor*, AActor*);
DECLARE_EVENT_TwoParams(ATurnBaseCombatV2, FOnEnemyTurn, AActor*, AActor*); DECLARE_EVENT_TwoParams(ATurnBaseCombatV2, FOnEnemyTurn, AActor*, AActor*);
FOnPlayerTurn OnPlayerTurn; FOnPlayerTurn OnPlayerTurn;
FOnEnemyTurn OnEnemyTurn; FOnEnemyTurn OnEnemyTurn;
void DamagePlayer(int Damage, FString DamageType = "unknown");
void DamageEnemy(int Damage, FString DamageType = "unknown");
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
@ -110,8 +113,6 @@ protected:
void UseActionPoint(); void UseActionPoint();
void ReuseActionPoint(); void ReuseActionPoint();
void RevertActionPoints(); void RevertActionPoints();
void DamagePlayer(int Damage);
void DamageEnemy(int Damage);
void UpdateProgressBars() const; void UpdateProgressBars() const;
private: private:

View File

@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Azos/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Azos/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Iroquoid/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Iroquoid/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Probertium/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> <s:Boolean x:Key="/Default/UserDictionary/Words/=Probertium/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=UFUNCTION/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>