Search Unity

Question 2DRPG: How to have a party in combat?

Discussion in 'Scripting' started by mardeljevan, Feb 10, 2024.

  1. mardeljevan

    mardeljevan

    Joined:
    Feb 10, 2024
    Posts:
    2
    I want to be able to have multiple party members during combat like chrono trigger or persona for example. I've been following a template series by Gamedev Experiments on making a pokemon style game. I got the combat down, I just wanna be able to use multiple party members while in combat.

    I have multiple c# scripts all for the hud, player and enemy units, and the battlesystem. Any advice would be helpful. I've attached just a handful of files below to show my code. Apologies if this isnt the best place to put this.
     

    Attached Files:

    Last edited: Feb 10, 2024
  2. R1PFake

    R1PFake

    Joined:
    Aug 7, 2015
    Posts:
    540
    If you have a fully working 1vs1 pokemon style game, then it shouldn't be hard to convert it to a party based combat, you just have to replace every "pokemon" with a list of party members and then every turn you have to decide which of these members should act on the current turn, for example a simple index variable which you increment every turn.
     
    mardeljevan likes this.
  3. mardeljevan

    mardeljevan

    Joined:
    Feb 10, 2024
    Posts:
    2

    Ahhh okay. First I do wanna thank you for taking the time to reach out and answer my question. With that I just have 1 question going about that. When you say replace "pokemon" or in my case "player" in a list like <List> where I can store my characters? or code out separately every "pokemon" with multiple pokemon with its own code.

    I tried adding a "player2" to the scripts, such as updating its HUD and adding it as a player unit, but that was under the same code. I was thinking if they were both considered "PlayerUnit" they would be able to use the same attack and turn script. Maybe its something I could continue working on if it works.
     
  4. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,631
    I recommend using a list<T> for combatants.
    https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1?view=net-8.0

    There's no reason to have variables called "Player1" and "Player2" and fill your scripts with all sorts of duplicate code.

    With a list you can refer to players as Player[0], Player[1], Player[2], but the power comes in when you replace the number with an int variable. You can write the code once and it can apply to any player on the list.
     
    Last edited: Feb 10, 2024
    mardeljevan likes this.
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,674
    Adding onto the great stuff already posted by kdgalla and R1PFake above...

    Be sure to answer critical questions like what "party combat" means.

    If you currently have 1 attacking 1, what happens with 1 attacking 3?

    Does the attack focus on only one of the three targets? Or all of them?

    How does an attacker choose targets?
    - they choose and pick
    - their attack always hits the guy in front
    - something else??

    What about 2 attacking 3? Can both attack at the same time? How does each one choose targets? How do you choose targets? Weakest? Strongest? Most-damaging? The player has to choose? What does that user interface look like? Does it do something special if they do? Or are there just two separate turns taken? Or are the turns simultaneous?

    The answers to these questions matter greatly when you go to decide how to structure things.

    And yes, get very very very comfortable using collection (such as arrays or List<T>) types. No sense rewriting all the code twice when you have two players! Collections allow a single piece of code to be iteratively applied to many different things.