molegato

multiple turns

Mar 3rd, 2012
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.74 KB | None | 0 0
  1. #==============================================================================
  2. # Multiple turns
  3. # Author Molegato
  4. # Version 1.0
  5. #------------------------------------------------------------------------------
  6. # Every turn, every actor and enemy has a set number of actions, rather than 1.
  7. #------------------------------------------------------------------------------
  8. # INSTRUCTIONS
  9. #==============================================================================
  10.  
  11. $imported = {} if $imported.nil?
  12. $imported['Molegato-Multiple_turns'] = true
  13.  
  14. #==============================================================================
  15. # CONFIGURATION, YOU CAN TOUCH THIS
  16. #==============================================================================
  17.  
  18. module MOLEGATO_MULTIPLE_TURNS
  19.   #If set to true, after each action is performed, the order for the remaining
  20.   #ones will be calculated again. If set to false, the exact same order pattern
  21.   #will be followed again and again, making the first action the one that affects
  22.   #the order.
  23.   RECALCULATE_ORDER = true
  24.  
  25.   #When set to 0, characters will have 1 turn, plus the extra turns allowed via
  26.   #traits, plus the extra turns added by agi.
  27.   GLOBAL_EXTRA_TURNS = 0
  28.  
  29.   #If agi is greater than the average of the battlers, the battler will have
  30.   #additional turns for each agi point surpassing the average.
  31.   #If this value is 0.5, for example, for each 2 agi points that surpass
  32.   #the average, the battler will gain 1 turn. I advise to use very small values.
  33.   TURNS_PER_AGI = 1
  34.  
  35.   #If this is set as true, turns will be rewarded for every agi point, regardless
  36.   #of the average. Use only if you have very very small agi values in your game.
  37.   IGNORE_AVERAGE = false
  38. end
  39. #==============================================================================
  40. # END OF CONFIGURATION. EVERYTHING UNDER HERE IS A HELLISH MESS OF DEFICIENT
  41. # AMATEUR SCRIPTING. BE AWARE THAT MESSING WITH IT CAN RESULT IN DISASTER
  42. #==============================================================================
  43.  
  44. #==============================================================================
  45. # ■ Game_Battler
  46. #==============================================================================
  47.  
  48. class Game_Battler < Game_BattlerBase
  49.  
  50.   alias multiturns_make_action_times make_action_times
  51.   def make_action_times
  52.     total_turns = multiturns_make_action_times + MOLEGATO_MULTIPLE_TURNS::GLOBAL_EXTRA_TURNS
  53.     total_turns += calculate_extra_turns.to_i
  54.     return total_turns
  55.   end
  56.  
  57.   alias multiturns_make_speed make_speed
  58.   def make_speed
  59.     multiturns_make_speed
  60.     @speed+= agi
  61.   end
  62.  
  63.   def calculate_extra_turns
  64.     if MOLEGATO_MULTIPLE_TURNS::IGNORE_AVERAGE
  65.       return MOLEGATO_MULTIPLE_TURNS::TURNS_PER_AGI * agi
  66.     end
  67.      
  68.     if agi< BattleManager.average_speed
  69.       return 0
  70.     else
  71.       return (agi - BattleManager.average_speed) * MOLEGATO_MULTIPLE_TURNS::TURNS_PER_AGI
  72.     end
  73.   end
  74.  
  75. end
  76.  
  77. #==============================================================================
  78. # ■ BattleManager
  79. #==============================================================================
  80.  
  81. module BattleManager
  82.  
  83.   def self.change_subject
  84.     delete_dead_battlers
  85.     loop do
  86.       battler = @action_battlers.shift
  87.       return nil unless battler
  88.       @action_battlers.push(battler)
  89.       if MOLEGATO_MULTIPLE_TURNS::RECALCULATE_ORDER
  90.         @action_battlers.sort! {|a,b| b.speed - a.speed }
  91.       end
  92.       next unless battler.index && battler.alive?
  93.       return battler
  94.     end
  95.   end
  96.  
  97.   def self.average_speed
  98.     total_battlers = []
  99.     total_battlers += $game_party.alive_members
  100.     total_battlers += $game_troop.alive_members
  101.     average=0
  102.     return 0 if total_battlers.size<=1
  103.    
  104.     for i in 0..total_battlers.size-1
  105.       average+=total_battlers[i].agi
  106.     end
  107.     average=average/total_battlers.size
  108.     return average
  109.   end
  110.  
  111. end
  112.  
  113. #==============================================================================
  114. # ■ Scene_Battle
  115. #==============================================================================
  116.  
  117. class Scene_Battle < Scene_Base
  118.  
  119.   def process_action
  120.     return if scene_changing?
  121.        
  122.     if !@subject || !@subject.current_action
  123.       @subject = BattleManager.change_subject
  124.     end
  125.  
  126.     return turn_end unless @subject
  127.     if @subject.current_action
  128.       @subject.current_action.prepare
  129.       if @subject.current_action.valid?
  130.         @status_window.open
  131.         execute_action
  132.       end
  133.       @subject.remove_current_action
  134.     end
  135.    
  136.     if @subject.current_action
  137.       @subject = BattleManager.change_subject
  138.       process_action_end
  139.     else
  140.       process_action_end
  141.       @subject = BattleManager.next_subject
  142.     end
  143.    
  144.   end
  145.  
  146. end
Advertisement
Add Comment
Please, Sign In to add comment