Added Steal Functionality

This commit is contained in:
Philip W 2023-03-23 00:42:28 +00:00
parent 50edc1aa0a
commit 4639a4d1ac
2 changed files with 45 additions and 3 deletions

View File

@ -135,6 +135,8 @@ void ATurnBaseCombatV2::BeginPlay()
AButton = Cast<UButton>(HUD->GetWidgetFromName("AButton")); AButton = Cast<UButton>(HUD->GetWidgetFromName("AButton"));
IButton = Cast<UButton>(HUD->GetWidgetFromName("IButton")); IButton = Cast<UButton>(HUD->GetWidgetFromName("IButton"));
BackspaceButton = Cast<UButton>(HUD->GetWidgetFromName("BackspaceButton")); BackspaceButton = Cast<UButton>(HUD->GetWidgetFromName("BackspaceButton"));
StealButton = Cast<UButton>(HUD->GetWidgetFromName("StealButton"));
StealButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::StealButtonOnClick);
CastButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::CastButtonOnClick); CastButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::CastButtonOnClick);
PButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::PButtonOnClick); PButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::PButtonOnClick);
EButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::EButtonOnClick); EButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::EButtonOnClick);
@ -210,7 +212,7 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo)
{ {
case true: case true:
// Player Turn // Player Turn
DamageEnemy(*ValidCombos.Find(Combo)); DamageEnemy(*ValidCombos.Find(Combo), Combo);
OnPlayerTurn.Broadcast(PlayerActor, EnemyActor); OnPlayerTurn.Broadcast(PlayerActor, EnemyActor);
break; break;
case false: case false:
@ -522,5 +524,43 @@ void ATurnBaseCombatV2::UpdateActionPlanWidget()
void ATurnBaseCombatV2::ClearActionPlanWidget() void ATurnBaseCombatV2::ClearActionPlanWidget()
{ {
return; for (UUserWidget* ActionWidget : ActionPlanWidgets)
{
ActionPlanWrapBox->RemoveChild(ActionWidget);
}
}
void ATurnBaseCombatV2::StealButtonOnClick()
{
StealButton->SetIsEnabled(false);
ClearActionPlanWidget();
TArray<int*> 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();
} }

View File

@ -196,7 +196,7 @@ private:
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
UButton* BackspaceButton; UButton* BackspaceButton;
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
UButton* RunButton; UButton* StealButton;
UFUNCTION() UFUNCTION()
void CastButtonOnClick(); void CastButtonOnClick();
@ -244,4 +244,6 @@ private:
void UpdateActionPlanWidget(); void UpdateActionPlanWidget();
UFUNCTION() UFUNCTION()
void ClearActionPlanWidget(); void ClearActionPlanWidget();
UFUNCTION()
void StealButtonOnClick();
}; };