x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Need some help Implementing a Customer Fighting Mechanic

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!

Product Version: Not Selected
Tags:
more ▼

asked Apr 19 '15 at 08:44 PM in C++ Programming

avatar image

alvarofer0020
95 15 17 24

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

a TableManager contains a list of all tables, and each table contains a list of seats (character references).

instead of using a character reference as a parameter for your StartFightAgainst function, you should use a table reference.

any time you have a valid EnemyTable but you don't have a valid CurrentEnemy, you go through the EnemyTable's list of seats looking for an enemy. if none are valid, you pick a new random table from the list of tables.

more ▼

answered Apr 20 '15 at 08:23 AM

avatar image

ScottSpadea
9.6k 320 205 450

avatar image alvarofer0020 Apr 20 '15 at 08:31 PM

Oh hey thank you!, i cant believe i dident think of that, it worked perfectly Once again Thanks!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question