Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Turn-Based RPG Turn Order when you use Haste

Discussion in 'General Discussion' started by RLord321, Apr 25, 2020.

  1. RLord321

    RLord321

    Joined:
    Feb 25, 2017
    Posts:
    28
    I have a RPG game that generates a list of about 10 turns that you can see. The turn list is based on the characters speed value and based on clock ticks - it adds the speed until each reaches 1000 and whoever reaches 1000 first goes next (actTimer += speed).

    My problem is that since I have a pre-calculated turn list, how do I properly implement a haste (or slow) spell. This will obviously increase the rate of your turn (maybe actTimer += (speed * 1.5f)).

    But I already have the pre-calculated turn list up to 10 so this would only be effected either after the 10 entries in the queue already...which doesn't make sense. I also tried resetting the turn list from scratch but that doesn't work as the player who could be next can be waaay down the line if their speed was low.

    I also thought I could generate the list but keep cycling through as if a player took his turn. But then this wouldn't be accurate as what if I'm on turn 300 but on turn 10, someone used Haste or slow? I would have to know this when I am simulating the turns in the background to calculate accurately.

    So how would you implement a character using a Haste spell when you have a predefined turn-list that you display on the screen?
     
  2. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    Why can't it be recalculated when they use the ability?
     
  3. RLord321

    RLord321

    Joined:
    Feb 25, 2017
    Posts:
    28
    I tried that and let's take the scenario where the player with the lowest speed is up next. If I recalculate, that player would again, be at the end of the line...which isn't fair because he/she was next.
     
  4. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,759
    You can solve this with a pretty basic queue system to ignore that specific condition.
     
    EternalAmbiguity likes this.
  5. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,325
    The solution is to get rid of precalculated turn list and rebuild the queue periodically.
     
  6. RLord321

    RLord321

    Joined:
    Feb 25, 2017
    Posts:
    28
    I found a way to recalculate the list and maintaining the right order. I now store a previousACT variable for all the players. This stores the last ACT value before it gets reset to 0 (their turn order). So now when someone does a modifier (Haste, Slow, etc), it will set all of the ACT's the the previousACT value and then restart the calculation.

    A simple solution and it works perfectly.
     
    EternalAmbiguity likes this.