Bugfix Enemy Always Started First

This commit is contained in:
Philip W 2023-04-26 06:21:08 +01:00
parent 37268a3dc2
commit 4f336263fb
4 changed files with 16 additions and 13 deletions

BIN
Content/BlueprintAI/AI/AIBruh.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -76,7 +76,7 @@ void UHoldToInitCombat::OnClickDown()
EnemyBlackboard = Cast<AAIController>(TargetEnemy->GetInstigatorController())->GetBlackboardComponent(); EnemyBlackboard = Cast<AAIController>(TargetEnemy->GetInstigatorController())->GetBlackboardComponent();
if (!EnemyBlackboard->GetValueAsBool("WasInCombat")) if (!EnemyBlackboard->GetValueAsBool("WasInCombat"))
{ {
Cast<ATurnBaseCombatV2>(GetWorld()->GetGameState())->StartCombat(TargetEnemy); Cast<ATurnBaseCombatV2>(GetWorld()->GetGameState())->StartCombat(TargetEnemy, true);
return; return;
} }
InitCombatWidget->SetVisibility(ESlateVisibility::Hidden); InitCombatWidget->SetVisibility(ESlateVisibility::Hidden);

View File

@ -32,7 +32,7 @@ ATurnBaseCombatV2::ATurnBaseCombatV2()
} }
} }
void ATurnBaseCombatV2::StartCombat(AActor* Enemy) void ATurnBaseCombatV2::StartCombat(AActor* Enemy, bool bWasShot)
{ {
if (Enemy == nullptr) return; if (Enemy == nullptr) return;
EnemyActor = Enemy; EnemyActor = Enemy;
@ -71,11 +71,11 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy)
return; return;
} }
CombatCheck(); CombatCheck(bWasShot);
//DrawDebugPoint(GetWorld(), Enemy->GetActorLocation(), 10, FColor::Red, false, 10); //DrawDebugPoint(GetWorld(), Enemy->GetActorLocation(), 10, FColor::Red, false, 10);
} }
void ATurnBaseCombatV2::CombatCheck() void ATurnBaseCombatV2::CombatCheck(bool bWasShot)
{ {
const UBlackboardComponent* EnemyBlackboard = Cast<AAIController>(EnemyActor->GetInstigatorController())->GetBlackboardComponent(); const UBlackboardComponent* EnemyBlackboard = Cast<AAIController>(EnemyActor->GetInstigatorController())->GetBlackboardComponent();
@ -93,15 +93,18 @@ void ATurnBaseCombatV2::CombatCheck()
ClearBattleLog(); ClearBattleLog();
EnableButtons(); EnableButtons();
if (EnemyBlackboard->GetValueAsBool("Sight")) FProperty* ReactionSpeedProperty = EnemyActor->GetClass()->FindPropertyByName(FName("ReactionSpeed"));
float* EnemyReactionSpeedPtr = ReactionSpeedProperty->ContainerPtrToValuePtr<float>(EnemyActor);
if (EnemyBlackboard->GetValueAsBool("Sight") && !bWasShot)
{ {
//bEnemyHasExtraTurn = true; //bEnemyHasExtraTurn = true;
SwitchTurn(); SwitchTurn();
} }
else else if (Cast<ATempCharacter>(PlayerActor)->ReactionSpeed > *EnemyReactionSpeedPtr && bWasShot)
{ {
bPlayerHasExtraTurn = true; bPlayerHasExtraTurn = true;
} }
TurnIndicatorTextBlock->SetText(FText::FromString("Player Turn"));
} }
void ATurnBaseCombatV2::EndCombat() void ATurnBaseCombatV2::EndCombat()

View File

@ -97,9 +97,9 @@ public:
FString BattleLog; FString BattleLog;
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void StartCombat(AActor* Enemy); void StartCombat(AActor* Enemy, bool bWasShot = false);
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void CombatCheck(); void CombatCheck(bool bWasShot = false);
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void EndCombat(); void EndCombat();