Hello
Im working on a fantasy tavern management game, where customers can go to your tavern, buy drinks, take a seat and drink on tables etc
Right now im stuck on a specific feature, Fighting…
Overall a Customer will try to fight if said customer cant find a seat , then the customer will approach a random customer and fight with him, All the customers on the table will start fighting the “Challenger” (Customer that couldnt find a seat and is now fighting a random customer that has taken a seat and is drinking at a table ) , Now i had no trouble implementing Customer VS Challenger fighting
My Issue is how could implement more than 2 customers fighting the same challenger? and vice versa, another Customer that has no seat will pick a random customer to fight, there is still a small chance that this other challenger could pick the same table where a fight is alredy going on, they can attack the same customer with no problem but how do i deal with picking a new target ON the same table after they killed one of the customers?
For the record, challengers keep fighting customers that have a seat on the table if there are still customers to fight, else they just roam arround
I have made about 4 rewrites of this feature so far and all of them end up in crashing or just not working… i tried using a Sphere in each table that holds all the customers currently in the table but then damage dealing becomes a mess becouse both customers and Challengers need to loop trough all the pawns in the sphere, make sure the index is valid and what not. Hence why im here asking for a good way to implement this feature
TLDR, the flow of a fight is
->Random Customer has no seat and triggers a fight with a random customer that has a seat and is drinking on a table
->All customers on the table will start “fighting” / dealing damage to the challenger
->More than 1 challenger can be fighting a customer on the same table
->After a customer has been killed by the challenger, the challenger will pick a new customer on the same table, if it cant find any it will stop fighting
->Same goes for customers, if they kill a challenger they pick a new challenger if there are any on the table
I Have the overall logic layed down, im just stuck on the "Grab a challenger / customer on the same table after you kill the current one " part.
Here is my code so far (Just triggering the fight and damage dealing, no new target picking )
GameMode
void ATheTavernGameMode::StartCustomerFight(ATTCustomerCharacter* Challenger, ATTCustomerCharacter* Fighter)
{
Challenger->StartFightAgainst(Fighter);
Fighter->StartFightAgainst(Challenger);
}
Customer Class
void ATTCustomerCharacter::StartFightAgainst(ATTCustomerCharacter* Enemy)
{
CurrentEnemy = Enemy;
// Once a fight starts, set the timer to deal damage to the enemy / customer
GetWorldTimerManager().SetTimer(this, &ATTCustomerCharacter::DealDamageToEnemy, CustomerData.DealDamageDelay,true);
bIsFighting = true;
}
void ATTCustomerCharacter::DealDamageToEnemy()
{
/* we are dead stop fighting*/
if (bDead)
{
EndFight();
}
/* dont try to damage a enemy that is null*/
if (!CurrentEnemy->IsValidLowLevel())
{
EndFight();
}
/* if the enemy is valid*/
if (CurrentEnemy->IsValidLowLevel())
{
/* if its dead stop fighting*/
if (CurrentEnemy->bDead)
{
EndFight();
}
else
{
/* if the enemy is alive and valid */
CurrentEnemy->CustomerTakeDamage(CustomerData.DealtDamage, Controller, this);
}
}
UE_LOG(LogTemp, Error, TEXT("Customer Dealt Damage! %f"), CustomerData.DealtDamage);
if (bFightingBouncer)
{
if (CurrentBouncer->IsValidLowLevel())
{
CurrentBouncer->BouncerTakeDamage(CustomerData.DealtDamage);
}
}
}
void ATTCustomerCharacter::CustomerTakeDamage(float Damage, AController* EventInstigator, ACharacter* DamageInstigator)
{
ATTCustomerCharacter* Instigator = Cast<ATTCustomerCharacter>(DamageInstigator); //
if (IsValidLowLevel() && bDead == false)
{
CustomerData.Health -= Damage; // if we are valid and not dead take damage
}
if (CustomerData.Health <= 0 && bDead == false) // if our health reaches zero then die
{
Instigator->EndFight(); // tell our instigator to stop fighting since we are dead!
bDead = true;
EndFight();
DestroyPawn();
}
}
void ATTCustomerCharacter::DestroyPawn()
{
bDead = true;
GetWorld()->GetTimerManager().ClearTimer(this, &ATTCustomerCharacter::GenerateGold);
GetWorld()->GetTimerManager().ClearTimer(this, &ATTCustomerCharacter::DealDamageToEnemy);
Destroy();
}
As usual any sort of help is always appreciated!