diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.cpp b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.cpp index 49df134..c545ce5 100644 --- a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.cpp +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.cpp @@ -135,6 +135,8 @@ void ATurnBaseCombatV2::BeginPlay() AButton = Cast(HUD->GetWidgetFromName("AButton")); IButton = Cast(HUD->GetWidgetFromName("IButton")); BackspaceButton = Cast(HUD->GetWidgetFromName("BackspaceButton")); + StealButton = Cast(HUD->GetWidgetFromName("StealButton")); + StealButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::StealButtonOnClick); CastButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::CastButtonOnClick); PButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::PButtonOnClick); EButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::EButtonOnClick); @@ -210,7 +212,7 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo) { case true: // Player Turn - DamageEnemy(*ValidCombos.Find(Combo)); + DamageEnemy(*ValidCombos.Find(Combo), Combo); OnPlayerTurn.Broadcast(PlayerActor, EnemyActor); break; case false: @@ -522,5 +524,43 @@ void ATurnBaseCombatV2::UpdateActionPlanWidget() void ATurnBaseCombatV2::ClearActionPlanWidget() { - return; + for (UUserWidget* ActionWidget : ActionPlanWidgets) + { + ActionPlanWrapBox->RemoveChild(ActionWidget); + } +} + +void ATurnBaseCombatV2::StealButtonOnClick() +{ + StealButton->SetIsEnabled(false); + ClearActionPlanWidget(); + TArray Resources = {&EnemyProbertiumResource, &EnemyEisResource, &EnemyAzosResource, &EnemyIroquoidResource}; + Resources.Sort([](const int& A, const int& B) { return A > B; }); + for (int* Resource : Resources) + { + if (*Resource > 0) + { + *Resource -= 1; + if (Resource == &EnemyProbertiumResource) + { + ProbertiumResource += 1; + } + else if (Resource == &EnemyEisResource) + { + EisResource += 1; + } + else if (Resource == &EnemyAzosResource) + { + AzosResource += 1; + } + else if (Resource == &EnemyIroquoidResource) + { + IroquoidResource += 1; + } + break; + } + } + UpdateResourceBars(); + EnemyActionPlan = EnemyGOAPAgent->Plan(GetWorldState(), EnemyGOAPAgent->Goals); + UpdateActionPlanWidget(); } diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h index 4ba6245..a0f7462 100644 --- a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h @@ -196,7 +196,7 @@ private: UPROPERTY(VisibleAnywhere) UButton* BackspaceButton; UPROPERTY(VisibleAnywhere) - UButton* RunButton; + UButton* StealButton; UFUNCTION() void CastButtonOnClick(); @@ -244,4 +244,6 @@ private: void UpdateActionPlanWidget(); UFUNCTION() void ClearActionPlanWidget(); + UFUNCTION() + void StealButtonOnClick(); };