There are usually 3 timers: Global ATB Timer, Party ATB Timer and Battler ATB Timer.
My tick addon video should illustrate this point:
https://www.youtube.com/watch?v=aHn4zM_Siek&index=13&list=PLp-0SJbFnYdw-laxpgITmo88EvluvBg2x
The window at the upper right corner shows the global atb timer and the gray bar of each battler shows the battler's atb timer.
About the global atb timer -
Its speed is usually the same as the frame per second. It maybe a constant 60, Graphics.frame_rate, something that's defined by users, or just something else.
The atb update per frame is usually implemented in a method under module BattleManager or class Scene_Battle, and that method must be able to be called(and should be called) per frame so the atb can be updated per frame.
About the battler atb timer -
Its speed is usually based on a battler's stat(likely agi, although my atb addon lets users set that to whatever they want). The formula can be something like base atb gain value * battler's stat / average of that stat of all battlers
base atb gain value is usually the maximum atb value / base atb fill time, and both maximum atb value and base atb fill time can sometimes be set by users.
This formula is likely implemented in a method under class Game_BattlerBase or Game_Battler.
(I'm not familiar with party atb timer so I'm not going to talk about that)
About both -
For example:
- YSA-CATB
Spoiler
class Scene_Battle < Scene_Base #-------------------------------------------------------------------------- # alias method: process_action #-------------------------------------------------------------------------- alias catb_process_action process_action def process_action if BattleManager.btype?🙂catb) process_catb perform_catb_action(@subject, true) if BattleManager.action_forced? end catb_process_action unless BattleManager.btype?🙂catb) end #-------------------------------------------------------------------------- # new method: catb_pause? #-------------------------------------------------------------------------- def catb_pause? return true if BattleManager.action_forced? return YSA::CATB:😛AUSE_WHEN_ACTIVE_PARTY_COMMAND if @party_command_window.active return true if $imported["YEA-CombatLogDisplay"] && @combatlog_window && @combatlog_window.visible return false if $game_system.catb_wait_type == :full return true if $game_system.catb_wait_type == :wait && (@actor_command_window.active || @skill_window.active || @item_window.active || @actor_window.active || @enemy_window.active) return true if $game_system.catb_wait_type == :quarter && (@skill_window.active || @item_window.active || @actor_window.active || @enemy_window.active) return true if $game_system.catb_wait_type == :semi && (@actor_window.active || @enemy_window.active) end #-------------------------------------------------------------------------- # new method: process_catb #-------------------------------------------------------------------------- def process_catb if @status_window.index >= 0 && ($game_party.members[@status_window.index].dead? || !BattleManager.action_list🙂actor).include?($game_party.members[@status_window.index])) $game_party.members[@status_window.index].clear_catb if @skill_window.visible || @item_window.visible @status_window.open @status_window.show @status_aid_window.hide end @actor_window.hide.deactivate @enemy_window.hide.deactivate @actor_command_window.deactivate @actor_command_window.close @skill_window.hide.deactivate @item_window.hide.deactivate @status_window.unselect end return unless SceneManager.scene_is?(Scene_Battle) return if scene_changing? return unless BattleManager.btype?🙂catb) return if catb_pause? battler_hash = $game_party.members + $game_troop.members battler_hash.each { |a| a.make_catb_update a.make_catb_action a.make_ct_catb_update } #--- Update Tick Turn if $game_system.catb_turn_type == :tick @tick_clock = 0 if !@tick_clock @tick_clock += 1 if @tick_clock >= $game_system.catb_tick_count @tick_clock = 0 all_battle_members.each { |battler| battler.on_turn_end } @status_window.refresh $game_troop.increase_turn end end #--- Fix make action BattleManager.action_list🙂actor).each { |battler| battler.make_actions if (battler.actor? && !battler.input) } #--- @status_window.refresh_catb #--- Setup Actor @f_actor_index = 0 if !@f_actor_index || @f_actor_index < 0 || @f_actor_index + 1 > BattleManager.action_list🙂actor).size f_actor = BattleManager.action_list🙂actor)[@f_actor_index] @f_actor_index += 1 if (@f_actor_index + 1) < BattleManager.action_list🙂actor).size && f_actor && f_actor.input && f_actor.input.item && f_actor.input.confirm f_actor = BattleManager.action_list🙂actor)[@f_actor_index] if f_actor && f_actor.input && !f_actor.input.confirm && (!BattleManager.actor || @status_window.index != BattleManager.actor.index) && !@actor_command_window.active && !@party_command_window.active BattleManager.set_actor(f_actor.index) @status_window.select(BattleManager.actor.index) @actor_command_window.setup(BattleManager.actor) @actor_command_window.show end BattleManager.action_list.each { |battler| battler.make_actions if battler.enemy? perform_catb_action(battler) if !@subject } end
process_action is a method that's supposed to be called per frame, catb_pause? checks if the atb should stop updating and process_catb is the method updating the atb per frame.
If the turn type is :tick, then the global atb timer will be updated via this part of process_catb:
Spoiler
if $game_system.catb_turn_type == :tick @tick_clock = 0 if !@tick_clock @tick_clock += 1 if @tick_clock >= $game_system.catb_tick_count @tick_clock = 0 all_battle_members.each { |battler| battler.on_turn_end } @status_window.refresh $game_troop.increase_turn end end
Where @tick_clock is the frames lasted for the current turn and $game_system.catb_tick_count is the maximum frame per turn.
All battler's atb timer is updated via this part of process_catb:
Spoiler
battler_hash.each { |a| a.make_catb_update a.make_catb_action a.make_ct_catb_update }
Where make_catb_update is a method under class Game_Battler:
Spoiler
def make_catb_update return if @catb_value >= MAX_CATB_VALUE return if not movable? value = $imported["YSA-LunaticCATBRate"] ? lunatic_catb_rate_formula : real_gain_catb @catb_value += [value, MAX_CATB_VALUE - @catb_value].min end
Where @catb_value is the atb value of a battler, MAX_CATB_VALUE is the maximum atb value, and both the lunatic_catb_rate_formula and real_gain_catb determines the speed of a battler's atb timer:
(lunatic_catb_rate_formula would be too complicated to be shown here)
Spoiler
def real_gain_catb value = (self.agi.to_f / BattleManager.average_agi) * base_gain_catb return value end
Where self.agi.to_f is the battler's agi, BattleManager.average_agi is the average agi of all battlers and base_gain_catb is the base atb gain value.
As I'm not familiar with the other atb systems, I won't be able to use their implementations as examples
🙂
P.S.:
1.
CTB and ATB are 2 completely different battle systems with completely different implementations(even though full wait ATB functions just like a CT😎.
2. Implementing a party atb timer can be quite different from implementing a battler atb timer though
😀