Advertisement
Vlue

Rudimentary ATB System

Mar 27th, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.12 KB | None | 0 0
  1. #Rudimentary ATB System v1.0d
  2. #----------#
  3. #
  4. #Features: Active Time Battles! Roughly and quickly written. Mostly works.
  5. #
  6. #~ #----------#
  7. #-- Script by: V.M of D.T
  8. #
  9. #- Questions or comments can be:
  10. #    given by email: sumptuaryspade@live.ca
  11. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  12. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  13. #
  14. #--- Free to use in any project, commercial or non-commercial, with credit given
  15. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  16.  
  17.  
  18. class Scene_Battle < Scene_Base
  19.   #Default action time for the quickest battler. (Minimum)
  20.   ACTION_TIMER = 180
  21.   #Max action time (for super duper low agility battlers)
  22.   MAX_TIMER = 540
  23.   def start_party_command_selection
  24.     @status_window.open
  25.   end
  26.   def update_basic
  27.     super
  28.     $game_timer.update
  29.     $game_troop.update
  30.     @spriteset.update
  31.     update_info_viewport
  32.     update_message_open
  33.    
  34.     update_battler_time if update_time_allowed
  35.   end
  36.   def update_battler_time
  37.     unless @speed_timer
  38.       highest_agility = 0
  39.       $game_troop.members.each do |enemy|
  40.         highest_agility = [highest_agility,enemy.agi].max
  41.       end
  42.       $game_party.members.each do |actor|
  43.         highest_agility = [highest_agility,actor.agi].max
  44.       end
  45.       @speed_timer = ACTION_TIMER * highest_agility
  46.     end
  47.     $game_troop.alive_members.each do |enemy|
  48.       break unless update_time_allowed
  49.       enemy.timer += enemy.agi
  50.       if enemy.timer > @speed_timer || enemy.timer / enemy.agi > MAX_TIMER
  51.         enemy.timer = 0
  52.         if enemy.movable?
  53.           enemy.make_actions
  54.           BattleManager.force_action(enemy)
  55.           process_forced_action
  56.         else
  57.           enemy.on_action_end
  58.           enemy.on_turn_end
  59.         end
  60.       end
  61.     end
  62.     $game_party.alive_members.each do |actor|
  63.       break unless update_time_allowed
  64.       actor.timer += actor.agi
  65.       if actor.timer > @speed_timer || actor.timer / actor.agi > MAX_TIMER
  66.         actor.timer = 0
  67.         if actor.confusion? || actor.auto_battle?
  68.           BattleManager.set_actor(actor.index)
  69.           BattleManager.force_action(actor)
  70.           BattleManager.clear_actor
  71.           process_forced_action
  72.         elsif !actor.movable?
  73.           actor.on_action_end
  74.           actor.on_turn_end
  75.         else
  76.           BattleManager.set_actor(actor.index)
  77.           start_actor_command_selection
  78.         end
  79.       end
  80.     end
  81.     @status_window.refresh
  82.   end
  83.   def speed_timer
  84.     @speed_timer ? @speed_timer : 1
  85.   end
  86.   def update_time_allowed
  87.     return false if BattleManager.action_forced?
  88.     return false if BattleManager.actor
  89.     return false if $game_message.busy?
  90.     return false if @actor_command_window.open?
  91.     return true
  92.   end
  93.   def process_forced_action
  94.     if BattleManager.action_forced?
  95.       last_subject = @subject
  96.       @subject = BattleManager.action_forced_battler
  97.       process_action
  98.       @subject = last_subject
  99.     end
  100.   end
  101.   def process_action_end
  102.     @subject.on_action_end
  103.     @subject.on_turn_end
  104.     refresh_status
  105.     @log_window.display_auto_affected_status(@subject)
  106.     @log_window.wait_and_clear
  107.     @log_window.display_current_state(@subject)
  108.     @log_window.wait_and_clear
  109.     BattleManager.clear_action_force
  110.     BattleManager.judge_win_loss
  111.   end
  112.   def command_guard
  113.     close_all
  114.     BattleManager.actor.input.set_guard
  115.     BattleManager.force_action(BattleManager.actor)
  116.     BattleManager.clear_actor
  117.     process_forced_action
  118.   end
  119.   def on_enemy_ok
  120.     BattleManager.actor.input.target_index = @enemy_window.enemy.index
  121.     @enemy_window.hide
  122.     @skill_window.hide
  123.     @item_window.hide
  124.     close_all
  125.     BattleManager.force_action(BattleManager.actor)
  126.     BattleManager.clear_actor
  127.     process_forced_action
  128.   end
  129.   def on_actor_ok
  130.     BattleManager.actor.input.target_index = @actor_window.index
  131.     @actor_window.hide
  132.     @skill_window.hide
  133.     @item_window.hide
  134.     close_all
  135.     BattleManager.force_action(BattleManager.actor)
  136.     BattleManager.clear_actor
  137.     process_forced_action
  138.   end
  139.   def on_skill_ok
  140.     @skill = @skill_window.item
  141.     BattleManager.actor.input.set_skill(@skill.id)
  142.     BattleManager.actor.last_skill.object = @skill
  143.     if !@skill.need_selection?
  144.       @skill_window.hide
  145.       close_all
  146.       BattleManager.force_action(BattleManager.actor)
  147.       BattleManager.clear_actor
  148.       process_forced_action
  149.     elsif @skill.for_opponent?
  150.       select_enemy_selection
  151.     else
  152.       select_actor_selection
  153.     end
  154.   end
  155.   def close_all
  156.     @party_command_window.close
  157.     @actor_command_window.close
  158.     @status_window.unselect
  159.     @log_window.wait
  160.     @log_window.clear
  161.   end
  162. end
  163.  
  164. class Window_ActorCommand
  165.   def cancel_enabled?
  166.     false
  167.   end
  168. end
  169.  
  170. class Game_BattlerBase
  171.   attr_accessor  :timer
  172.   alias atb_init initialize
  173.   def initialize(*args)
  174.     atb_init(*args)
  175.     @timer = 0
  176.   end
  177.   def ap_rate
  178.     [@timer.to_f / SceneManager.scene.speed_timer, 1.0].min
  179.   end
  180. end
  181.  
  182. class Window_Base < Window
  183.   def draw_actor_ap(actor, x, y, width = 124)
  184.     draw_gauge(x, y, width, actor.ap_rate, text_color(0), text_color(8))
  185.     change_color(system_color)
  186.     draw_text(x, y, 30, line_height, "AT")
  187.     change_color(tp_color(actor))
  188.     draw_text(x + width - 42, y, 42, line_height, (actor.ap_rate * 100).to_i, 2)
  189.   end
  190. end
  191.  
  192. class Window_BattleStatus < Window_Selectable
  193.   def draw_gauge_area_with_tp(rect, actor)
  194.     draw_actor_hp(actor, rect.x - 74, rect.y, 72)
  195.     draw_actor_mp(actor, rect.x + 8, rect.y, 64)
  196.     draw_actor_tp(actor, rect.x + 82, rect.y, 64)
  197.     draw_actor_ap(actor, rect.x + 156, rect.y, 64)
  198.   end
  199.   def draw_gauge_area_without_tp(rect, actor)
  200.     draw_actor_hp(actor, rect.x + 0, rect.y, 72)
  201.     draw_actor_mp(actor, rect.x + 82, rect.y, 64)
  202.     draw_actor_ap(actor, rect.x + 156, rect.y, 64)
  203.   end
  204. end
  205.  
  206. module BattleManager
  207.   def self.set_actor(index)
  208.     @actor_index = index
  209.     self.actor.clear_actions
  210.     self.actor.make_actions
  211.   end
  212. end
  213.  
  214. class Scene_Base
  215.   def speed_timer; 0; end
  216. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement