From 6227b4952cebc1bad3f31804bcf704ecf9cfbaff Mon Sep 17 00:00:00 2001 From: PHILIP White Date: Tue, 28 Feb 2023 16:48:30 +0000 Subject: [PATCH] Updated StatusSystem to Bind Player/Enemy Turn Events --- .../TurnBasedCombatV2/StatusEffect.cpp | 12 ++++++++++-- .../TurnBasedCombatV2/StatusEffect.h | 7 ++++--- .../TurnBasedCombatV2/StatusSystem.cpp | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.cpp b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.cpp index 036547b..38c2399 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.cpp +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.cpp @@ -5,6 +5,7 @@ #include "StatusSystem.h" #include "Kismet/GameplayStatics.h" +#include "TurnBaseCombatV2.h" #include "Components/TextBlock.h" void UStatusEffect::Invoke(AActor* Character, float TimeOfInit) @@ -21,16 +22,23 @@ void UStatusEffect::OnExpiry(AActor* Character) StatusSystem->RemoveStatusEffect(this); } -void UStatusEffect::OnPlayerTurn(AActor* Character) +void UStatusEffect::OnPlayerTurn(AActor* Character, AActor* Enemy) { return; } -void UStatusEffect::OnEnemyTurn(AActor* Character) +void UStatusEffect::OnEnemyTurn(AActor* Enemy, AActor* Character) { return; } +void UStatusEffect::OnStatusEffectAdd() +{ + ATurnBaseCombatV2* CombatSystem = Cast(GetWorld()->GetGameState()); + CombatSystem->OnPlayerTurn.AddUObject(this, &UStatusEffect::OnPlayerTurn); + CombatSystem->OnEnemyTurn.AddUObject(this, &UStatusEffect::OnEnemyTurn); +} + void UStatusEffect::CheckForExpiry(const float TimeOfExpiry, AActor* Character) { if (TimeOfExpiry <= UGameplayStatics::GetRealTimeSeconds(GetWorld())) OnExpiry(Character); diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.h b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.h index 317bc56..4d57501 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.h +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.h @@ -26,15 +26,16 @@ public: UFUNCTION() virtual void Invoke(AActor* Character, float TimeOfExpiry); - UFUNCTION() virtual void OnExpiry(AActor* Character); UFUNCTION() - virtual void OnPlayerTurn(AActor* Character); + virtual void OnPlayerTurn(AActor* Character, AActor* Enemy); + UFUNCTION() + virtual void OnEnemyTurn(AActor* Enemy, AActor* Character); UFUNCTION() - virtual void OnEnemyTurn(AActor* Character); + virtual void OnStatusEffectAdd(); protected: UPROPERTY() diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusSystem.cpp b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusSystem.cpp index d3138dc..499df9d 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusSystem.cpp +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusSystem.cpp @@ -48,6 +48,7 @@ void UStatusSystem::AddStatusEffect(UStatusEffect* StatusEffect, const float Dur UImage* StatusIconImage = Cast(NewStatusEffect.StatusIcon->GetWidgetFromName(TEXT("StatusIconImage"))); StatusIconImage->SetBrushFromTexture(StatusEffect->Icon); StatusIconsBox->AddChild(NewStatusEffect.StatusIcon); + NewStatusEffect.StatusEffect->OnStatusEffectAdd(); if (Invoke) NewStatusEffect.StatusEffect->Invoke(GetOwner(), NewStatusEffect.TimeTillExpiry); ActiveStatusEffects.Add(NewStatusEffect);