diff --git a/Content/Blueprints/StatusEffects/BP_Thorns.uasset b/Content/Blueprints/StatusEffects/BP_Thorns.uasset index bf52405..e8fe436 100644 --- a/Content/Blueprints/StatusEffects/BP_Thorns.uasset +++ b/Content/Blueprints/StatusEffects/BP_Thorns.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:48a4ca28df9c381f5b0f29fd9a0a4a5ab3baad4524263a0cfac9be21675ad0eb -size 6382 +oid sha256:851cdfb16956e96b0965fe275332897cb64b3a78df1b00925db70e581b20bc6a +size 6482 diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.cpp b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.cpp index 38c2399..2aefba5 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.cpp +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.cpp @@ -20,6 +20,9 @@ void UStatusEffect::OnExpiry(AActor* Character) if (StatusSystem->GetActiveStatusEffect(this).StatusIcon == nullptr) return; StatusSystem->GetActiveStatusEffect(this).StatusIcon->RemoveFromParent(); StatusSystem->RemoveStatusEffect(this); + ATurnBaseCombatV2* CombatSystem = Cast(GetWorld()->GetGameState()); + CombatSystem->OnPlayerTurn.Remove(OnPlayerTurnDelegateHandle); + CombatSystem->OnEnemyTurn.Remove(OnEnemyTurnDelegateHandle); } void UStatusEffect::OnPlayerTurn(AActor* Character, AActor* Enemy) @@ -35,8 +38,8 @@ void UStatusEffect::OnEnemyTurn(AActor* Enemy, AActor* Character) void UStatusEffect::OnStatusEffectAdd() { ATurnBaseCombatV2* CombatSystem = Cast(GetWorld()->GetGameState()); - CombatSystem->OnPlayerTurn.AddUObject(this, &UStatusEffect::OnPlayerTurn); - CombatSystem->OnEnemyTurn.AddUObject(this, &UStatusEffect::OnEnemyTurn); + OnPlayerTurnDelegateHandle = CombatSystem->OnPlayerTurn.AddUObject(this, &UStatusEffect::OnPlayerTurn); + OnEnemyTurnDelegateHandle = CombatSystem->OnEnemyTurn.AddUObject(this, &UStatusEffect::OnEnemyTurn); } void UStatusEffect::CheckForExpiry(const float TimeOfExpiry, AActor* Character) diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.h b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.h index 4d57501..f8cd426 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.h +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffect.h @@ -20,6 +20,8 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite) FString Description; UPROPERTY(EditAnywhere, BlueprintReadWrite) + bool IsForCombatOnly = false; + UPROPERTY(EditAnywhere, BlueprintReadWrite) float BaseDuration; UPROPERTY(EditAnywhere, BlueprintReadWrite) UTexture2D* Icon; @@ -42,4 +44,7 @@ protected: FTimerHandle ExpiryTimerHandle; UFUNCTION() void CheckForExpiry(float TimeOfExpiry, AActor* Character); + + FDelegateHandle OnPlayerTurnDelegateHandle; + FDelegateHandle OnEnemyTurnDelegateHandle; }; diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffects/Thorns.cpp b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffects/Thorns.cpp index ae9f142..4d27d0d 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffects/Thorns.cpp +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffects/Thorns.cpp @@ -3,6 +3,8 @@ #include "Thorns.h" +#include "the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h" + void UThorns::Invoke(AActor* Character, float TimeOfExpiry) { Super::Invoke(Character, TimeOfExpiry); @@ -12,3 +14,15 @@ void UThorns::OnExpiry(AActor* Character) { Super::OnExpiry(Character); } + +void UThorns::OnEnemyTurn(AActor* Enemy, AActor* Character) +{ + Super::OnEnemyTurn(Enemy, Character); + ATurnBaseCombatV2* CombatSystem = Cast(GetWorld()->GetGameState()); + CombatSystem->DamageEnemy(DamagePerTurn, "thorns"); + BaseDuration -= 1.0f; + if (BaseDuration <= 0.0f) + { + OnExpiry(Character); + } +} diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffects/Thorns.h b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffects/Thorns.h index 9abc89c..09862ae 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffects/Thorns.h +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusEffects/Thorns.h @@ -15,6 +15,10 @@ class THE_TWILIGHT_ABYSS_API UThorns : public UStatusEffect GENERATED_BODY() public: + UPROPERTY(EditAnywhere, BlueprintReadWrite) + float DamagePerTurn = 3.0f; + virtual void Invoke(AActor* Character, float TimeOfExpiry) override; virtual void OnExpiry(AActor* Character) override; + virtual void OnEnemyTurn(AActor* Enemy, AActor* Character) override; }; diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusSystem.cpp b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusSystem.cpp index 499df9d..46b1b43 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/StatusSystem.cpp +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/StatusSystem.cpp @@ -43,7 +43,14 @@ void UStatusSystem::AddStatusEffect(UStatusEffect* StatusEffect, const float Dur FActiveStatusEffect NewStatusEffect; NewStatusEffect.StatusEffect = StatusEffect; 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(GetWorld(), HUDStatusIconWidget); UImage* StatusIconImage = Cast(NewStatusEffect.StatusIcon->GetWidgetFromName(TEXT("StatusIconImage"))); StatusIconImage->SetBrushFromTexture(StatusEffect->Icon); diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp index fa527c2..eb2eb90 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp @@ -86,15 +86,15 @@ void ATurnBaseCombatV2::EndCombat() PlayerController->bShowMouseCursor = false; } -void ATurnBaseCombatV2::FKeyPressed() -{ - PButtonOnClick(); -} - -void ATurnBaseCombatV2::WKeyPressed() -{ - EButtonOnClick(); -} +// void ATurnBaseCombatV2::FKeyPressed() +// { +// PButtonOnClick(); +// } +// +// void ATurnBaseCombatV2::WKeyPressed() +// { +// EButtonOnClick(); +// } void ATurnBaseCombatV2::BeginPlay() { @@ -176,6 +176,7 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo) UStatusEffect* TempThornsStatusEffect = NewObject(PlayerActor, ThornsStatusEffect); StatusSystem->AddStatusEffect(TempThornsStatusEffect, 1, false); StatusEffects.Add(TempThornsStatusEffect); + AddBattleLogMessage("Player Casted Thorns"); } } @@ -191,6 +192,7 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo) RevertActionPoints(); UpdateActionPoints(); + //Damage Calculation switch (bIsPlayerTurn) { case true: @@ -241,18 +243,18 @@ void ATurnBaseCombatV2::RevertActionPoints() UpdateActionPoints(); } -void ATurnBaseCombatV2::DamagePlayer(int Damage) +void ATurnBaseCombatV2::DamagePlayer(int Damage, FString DamageType) { *PlayerHealth -= FMath::Clamp(Damage, 0, 100); 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); 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 @@ -455,6 +457,7 @@ void ATurnBaseCombatV2::ToggleButtons() const void ATurnBaseCombatV2::EnemyTurn() { DamagePlayer(10); + OnEnemyTurn.Broadcast(EnemyActor, PlayerActor); TurnIndicatorTextBlock->SetText(FText::FromString("Player Turn")); ToggleButtons(); } diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h index 4a339a2..db67b13 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.h @@ -94,15 +94,18 @@ public: void StartCombat(AActor* Enemy); UFUNCTION(BlueprintCallable) void EndCombat(); - UFUNCTION(BlueprintCallable) - void FKeyPressed(); - UFUNCTION(BlueprintCallable) - void WKeyPressed(); + // UFUNCTION(BlueprintCallable) + // void FKeyPressed(); + // UFUNCTION(BlueprintCallable) + // void WKeyPressed(); DECLARE_EVENT_TwoParams(ATurnBaseCombatV2, FOnPlayerTurn, AActor*, AActor*); DECLARE_EVENT_TwoParams(ATurnBaseCombatV2, FOnEnemyTurn, AActor*, AActor*); FOnPlayerTurn OnPlayerTurn; FOnEnemyTurn OnEnemyTurn; + + void DamagePlayer(int Damage, FString DamageType = "unknown"); + void DamageEnemy(int Damage, FString DamageType = "unknown"); protected: virtual void BeginPlay() override; @@ -110,8 +113,6 @@ protected: void UseActionPoint(); void ReuseActionPoint(); void RevertActionPoints(); - void DamagePlayer(int Damage); - void DamageEnemy(int Damage); void UpdateProgressBars() const; private: diff --git a/the_twilight_abyss.uproject.DotSettings b/the_twilight_abyss.uproject.DotSettings index 2323d1b..81ddebe 100644 --- a/the_twilight_abyss.uproject.DotSettings +++ b/the_twilight_abyss.uproject.DotSettings @@ -1,4 +1,5 @@  True True - True \ No newline at end of file + True + True \ No newline at end of file