Advertisement
roninator2

CTB System - Circle Cross

Dec 17th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 21.25 KB | None | 0 0
  1. #==============================================================================
  2. # □ CTB(2013/03/08)
  3. #------------------------------------------------------------------------------
  4. #  CTB introduction
  5. #==============================================================================
  6.  
  7. module R2_CTB_SETTINGS
  8. #==============================================================================
  9. # ☆ Customization here.
  10. #==============================================================================
  11.  
  12.   # Set the AP required to act.
  13.   CC_CTB_AP_ACTION_LIMIT = 100
  14.  
  15.   # Select whether to set AP to 0 after action.
  16.   # Specify true to set to 0, false otherwise.
  17.   CC_CTB_AP_RESET = true
  18.  
  19.   # Set combat speed. Smaller is faster.
  20.   # Set a value greater than 0.
  21.   CC_CTB_BATTLE_SPEED = 20.0
  22.  
  23.   # Adjust or set combat speed to be constant regardless of agility.
  24.   # When true, make battle speed constant.
  25.   CC_CTB_BATTLE_SPEED_ADJUST = true
  26.  
  27.   # Sets the battle speed when CC_CTB_BATTLE_SPEED_ADJUST is true.
  28.   # Higher values are faster.
  29.   CC_CTB_ADJUSTED_SPEED = 20.0
  30.  
  31.   # Set the timing of automatic recovery.
  32.   # At the end of action = 0, at the time of TP natural increase = 1
  33.   CC_CTB_REGENERATE_TIMING = 1
  34.  
  35.   # Adjust the auto-recovery speed. Smaller is faster.
  36.   # Set a value greater than 0.
  37.   CC_CTB_REGENERATE_SPEED = 20.0
  38.  
  39.   # Set the AP consumed when using the item.
  40.   CC_CTB_ITEM_AP_COST = CC_CTB_AP_ACTION_LIMIT
  41.  
  42. #==============================================================================
  43. # ☆ Customization here.
  44. #==============================================================================
  45. end
  46. #==============================================================================
  47. # □ BattleManager
  48. #------------------------------------------------------------------------------
  49. #  A module that manages the progress of battles.
  50. #==============================================================================
  51.  
  52. module BattleManager
  53.   class << self
  54.     #--------------------------------------------------------------------------
  55.     # ○ Combat start
  56.     #--------------------------------------------------------------------------
  57.     alias cc_ctb_battle_start battle_start
  58.     def battle_start
  59.       cc_ctb_battle_start
  60.       if @preemptive
  61.         $game_party.members.each {|member| member.ap += R2_CTB_SETTINGS::CC_CTB_AP_ACTION_LIMIT / 2 }
  62.       elsif @surprise
  63.         $game_troop.members.each {|member| member.ap += R2_CTB_SETTINGS::CC_CTB_AP_ACTION_LIMIT / 2 }
  64.       end
  65.       speed_adjust_set if R2_CTB_SETTINGS::CC_CTB_BATTLE_SPEED_ADJUST
  66.     end
  67.     #--------------------------------------------------------------------------
  68.     # ○ Creating action sequences
  69.     #--------------------------------------------------------------------------
  70.     def make_action_orders
  71.       @action_battlers = [next_action_battler]
  72.       @action_battlers[0].increase_turn if @action_battlers[0].is_a?(Game_Enemy)
  73.     end
  74.     #--------------------------------------------------------------------------
  75.     # ○ Acquiring the next battler to act
  76.     #--------------------------------------------------------------------------
  77.     def next_action_battler
  78.       battlers = []
  79.       battlers += $game_party.alive_members unless @surprise
  80.       battlers += $game_troop.alive_members unless @preemptive
  81.       battlers.sort! {|a,b| b.agi - a.agi }
  82.       battlers.min_by {|battler|
  83.         (R2_CTB_SETTINGS::CC_CTB_AP_ACTION_LIMIT - battler.ap) / battler.agi
  84.       }
  85.     end
  86.     #--------------------------------------------------------------------------
  87.     # ○ Get Combat Speed Modifier
  88.     #--------------------------------------------------------------------------
  89.     def speed_adjust_set
  90.       battlers = $game_party.members + $game_troop.members
  91.       $cc_ctb_speed_adjust = battlers.max_by {|battler| battler.agi }.agi / R2_CTB_SETTINGS::CC_CTB_ADJUSTED_SPEED
  92.     end
  93.   end
  94. end
  95.  
  96. #==============================================================================
  97. # □ Game_BattlerBase
  98. #------------------------------------------------------------------------------
  99. #  This is the basic class that handles battlers.
  100. #  Mainly contains methods for ability score calculation. child
  101. #  class is used as the superclass of the Game_Battler class.
  102. #==============================================================================
  103.  
  104. class Game_BattlerBase
  105.   alias cc_ctb_hrg hrg
  106.   alias cc_ctb_mrg mrg
  107.   alias cc_ctb_trg trg
  108.   def hrg;  cc_ctb_hrg / (R2_CTB_SETTINGS::CC_CTB_REGENERATE_TIMING == 1 ?
  109.     R2_CTB_SETTINGS::CC_CTB_REGENERATE_SPEED : 1);  end    # HP再生率   Hp ReGeneration rate
  110.   def mrg;  cc_ctb_mrg / (R2_CTB_SETTINGS::CC_CTB_REGENERATE_TIMING == 1 ?
  111.     R2_CTB_SETTINGS::CC_CTB_REGENERATE_SPEED : 1);  end    # MP再生率   Mp ReGeneration rate
  112.   def trg;  cc_ctb_trg / (R2_CTB_SETTINGS::CC_CTB_REGENERATE_TIMING == 1 ?
  113.     R2_CTB_SETTINGS::CC_CTB_REGENERATE_SPEED : 1);  end    # TP再生率   Tp ReGeneration rate
  114.   #--------------------------------------------------------------------------
  115.   # ○ public instance variables
  116.   #--------------------------------------------------------------------------
  117.   attr_reader   :ap                       # AP
  118.   #--------------------------------------------------------------------------
  119.   # ○ object initialization
  120.   #--------------------------------------------------------------------------
  121.   alias cc_atb_initialize initialize
  122.   def initialize
  123.     @ap = 0
  124.     cc_atb_initialize
  125.   end
  126.   #--------------------------------------------------------------------------
  127.   # ○ AP change of
  128.   #--------------------------------------------------------------------------
  129.   def ap=(ap)
  130.     @ap = [[ap, max_ap].min, 0].max
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # ○ AP get the percentage of
  134.   #--------------------------------------------------------------------------
  135.   def ap_rate
  136.     @ap.to_f / max_ap
  137.   end
  138.   #--------------------------------------------------------------------------
  139.   # ○ AP get the maximum value of
  140.   #--------------------------------------------------------------------------
  141.   def max_ap
  142.     return R2_CTB_SETTINGS::CC_CTB_AP_ACTION_LIMIT
  143.   end
  144.   #--------------------------------------------------------------------------
  145.   # ○ Skill AP consumption calculation
  146.   #--------------------------------------------------------------------------
  147.   def skill_ap_cost(skill)
  148.     skill.speed
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   # ○ Ability to pay for skill use cost
  152.   #--------------------------------------------------------------------------
  153.   alias cc_ctb_skill_cost_payable? skill_cost_payable?
  154.   def skill_cost_payable?(skill)
  155.     (!$game_party.in_battle || ap >= skill_ap_cost(skill)) && cc_ctb_skill_cost_payable?(skill)
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # ○ Pay skill use cost
  159.   #--------------------------------------------------------------------------
  160.   alias cc_ctb_pay_skill_cost pay_skill_cost
  161.   def pay_skill_cost(skill)
  162.     cc_ctb_pay_skill_cost(skill)
  163.     self.ap -= skill_ap_cost(skill) if $game_party.in_battle
  164.   end
  165.   #--------------------------------------------------------------------------
  166.   # ○ action judgment
  167.   #--------------------------------------------------------------------------
  168.   def action?
  169.     ap >= R2_CTB_SETTINGS::CC_CTB_AP_ACTION_LIMIT && self == BattleManager.next_action_battler
  170.   end
  171. end
  172.  
  173. #==============================================================================
  174. # □ Game_Battler
  175. #------------------------------------------------------------------------------
  176. #  A Butler class with sprite and action related methods added. this class
  177. #  is used as the superclass for the Game_Actor and Game_Enemy classes.
  178. #==============================================================================
  179.  
  180. class Game_Battler < Game_BattlerBase
  181.   #--------------------------------------------------------------------------
  182.   # ○ AP initialization of
  183.   #--------------------------------------------------------------------------
  184.   def init_ap
  185.     self.ap = rand * 25
  186.   end
  187.   #--------------------------------------------------------------------------
  188.   # ○ Battle start process
  189.   #--------------------------------------------------------------------------
  190.   alias cc_ctb_on_battle_start on_battle_start
  191.   def on_battle_start
  192.     cc_ctb_on_battle_start
  193.     init_ap
  194.   end
  195.   #--------------------------------------------------------------------------
  196.   # ○ Combat action creation
  197.   #--------------------------------------------------------------------------
  198.   alias cc_ctb_make_actions make_actions
  199.   def make_actions
  200.     cc_ctb_make_actions
  201.     @actions = [] if self != BattleManager.next_action_battler
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   # ○ Judgment that command input is possible
  205.   #--------------------------------------------------------------------------
  206.   alias cc_ctb_inputable? inputable?
  207.   def inputable?
  208.     cc_ctb_inputable? && action?
  209.   end
  210.   #--------------------------------------------------------------------------
  211.   # ○ HP the playback of
  212.   #--------------------------------------------------------------------------
  213.   def regenerate_hp
  214.     damage = -(mhp * hrg / (R2_CTB_SETTINGS::CC_CTB_REGENERATE_TIMING == 1 &&
  215.     R2_CTB_SETTINGS::CC_CTB_BATTLE_SPEED_ADJUST ? $cc_ctb_speed_adjust : 1)).to_i
  216.     perform_map_damage_effect if $game_party.in_battle && damage > 0
  217.     @result.hp_damage = [damage, max_slip_damage].min
  218.     self.hp -= @result.hp_damage
  219.   end
  220.   #--------------------------------------------------------------------------
  221.   # ○ MP the playback of
  222.   #--------------------------------------------------------------------------
  223.   def regenerate_mp
  224.     @result.mp_damage = -(mmp * mrg / (R2_CTB_SETTINGS::CC_CTB_REGENERATE_TIMING == 1 &&
  225.     R2_CTB_SETTINGS::CC_CTB_BATTLE_SPEED_ADJUST ? $cc_ctb_speed_adjust : 1))
  226.     self.mp -= @result.mp_damage
  227.   end
  228.   #--------------------------------------------------------------------------
  229.   # ○ TP the playback of
  230.   #--------------------------------------------------------------------------
  231.   def regenerate_tp
  232.     self.tp += R2_CTB_SETTINGS::CC_CTB_AP_ACTION_LIMIT * trg / (R2_CTB_SETTINGS::CC_CTB_REGENERATE_TIMING == 1 &&
  233.     R2_CTB_SETTINGS::CC_CTB_BATTLE_SPEED_ADJUST ? $cc_ctb_speed_adjust : 1)
  234.   end
  235.   #--------------------------------------------------------------------------
  236.   # ○ Processing at the end of combat action
  237.   #--------------------------------------------------------------------------
  238.   alias cc_ctb_on_action_end on_action_end
  239.   def on_action_end
  240.     cc_ctb_on_action_end
  241.     regenerate_all if R2_CTB_SETTINGS::CC_CTB_REGENERATE_TIMING == 0
  242.   end
  243.   #--------------------------------------------------------------------------
  244.   # ○ TP consumption when acting
  245.   #--------------------------------------------------------------------------
  246.   def cc_ctb_ap_action_cost
  247.     if (R2_CTB_SETTINGS::CC_CTB_AP_RESET || !current_action) && action?
  248.       self.ap -= R2_CTB_SETTINGS::CC_CTB_AP_ACTION_LIMIT
  249.     elsif current_action && current_action.item.is_a?(RPG::Item)
  250.       self.ap -= R2_CTB_SETTINGS::CC_CTB_ITEM_AP_COST
  251.     end
  252.   end
  253.   #--------------------------------------------------------------------------
  254.   # ○ End of turn process
  255.   #--------------------------------------------------------------------------
  256.   def on_turn_end
  257.     @result.clear
  258.     remove_states_auto(2)
  259.   end
  260. end
  261.  
  262. #==============================================================================
  263. # □ Game_Enemy
  264. #------------------------------------------------------------------------------
  265. #  A class that handles enemy characters. This class is the Game_Troop class
  266. #  ($game_troop) Used internally.
  267. #==============================================================================
  268.  
  269. class Game_Enemy < Game_Battler
  270.   #--------------------------------------------------------------------------
  271.   # ○ public instance variables
  272.   #--------------------------------------------------------------------------
  273.   attr_reader   :turn_count               # Enemy group index
  274.   #--------------------------------------------------------------------------
  275.   # ○ object initialization
  276.   #--------------------------------------------------------------------------
  277.   alias cc_ctb_initialize initialize
  278.   def initialize(index, enemy_id)
  279.     cc_ctb_initialize(index, enemy_id)
  280.     @turn_count = 1
  281.   end
  282.   #--------------------------------------------------------------------------
  283.   # ○ Action condition match judgment [number of turns]
  284.   #--------------------------------------------------------------------------
  285.   def conditions_met_turns?(param1, param2)
  286.     n = @turn_count
  287.     if param2 == 0
  288.       n == param1
  289.     else
  290.       n > 0 && n >= param1 && n % param2 == param1 % param2
  291.     end
  292.   end
  293.   #--------------------------------------------------------------------------
  294.   # ○ increase in turns
  295.   #--------------------------------------------------------------------------
  296.   def increase_turn
  297.     @turn_count += 1
  298.   end
  299. end
  300.  
  301. #==============================================================================
  302. # □ Window_Base
  303. #------------------------------------------------------------------------------
  304. #  The superclass of all windows in the game.
  305. #==============================================================================
  306.  
  307. class Window_Base < Window
  308.   #--------------------------------------------------------------------------
  309.   # ○ Acquisition of various character colors
  310.   #--------------------------------------------------------------------------
  311.   def ap_gauge_color1;   text_color(30);  end;    # AP gauge 1
  312.   def ap_gauge_color2;   text_color(31);  end;    # AP gauge 2
  313.   #--------------------------------------------------------------------------
  314.   # ○ AP get the text color of
  315.   #--------------------------------------------------------------------------
  316.   def ap_color(actor)
  317.     return normal_color
  318.   end
  319.   #--------------------------------------------------------------------------
  320.   # ○ AP Drawing of
  321.   #--------------------------------------------------------------------------
  322.   def draw_actor_ap(actor, x, y, width = 124)
  323.     draw_gauge(x, y, width, actor.ap_rate, ap_gauge_color1, ap_gauge_color2)
  324.     #change_color(system_color)
  325.     #draw_text(x, y, 30, line_height, Vocab::ap_a)
  326.     #change_color(ap_color(actor))
  327.     #draw_text(x + width - 42, y, 42, line_height, actor.ap.to_i, 2)
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # ○ HP Drawing of
  331.   #--------------------------------------------------------------------------
  332.   def draw_actor_hp(actor, x, y, width = 124)
  333.     draw_gauge(x, y, width, actor.hp_rate, hp_gauge_color1, hp_gauge_color2)
  334.     change_color(system_color)
  335.     draw_text(x, y, 30, line_height, Vocab::hp_a)
  336.     draw_current_and_max_values(x, y, width, actor.hp.to_i, actor.mhp,
  337.       hp_color(actor), normal_color)
  338.   end
  339.   #--------------------------------------------------------------------------
  340.   # ○ MP Drawing of
  341.   #--------------------------------------------------------------------------
  342.   def draw_actor_mp(actor, x, y, width = 124)
  343.     draw_gauge(x, y, width, actor.mp_rate, mp_gauge_color1, mp_gauge_color2)
  344.     change_color(system_color)
  345.     draw_text(x, y, 30, line_height, Vocab::mp_a)
  346.     draw_current_and_max_values(x, y, width, actor.mp.to_i, actor.mmp,
  347.       mp_color(actor), normal_color)
  348.   end
  349. end
  350.  
  351. #==============================================================================
  352. # □ Window_BattleStatus
  353. #------------------------------------------------------------------------------
  354. #  A window that displays the status of party members on the battle screen.
  355. #==============================================================================
  356.  
  357. class Window_BattleStatus < Window_Selectable
  358.   #--------------------------------------------------------------------------
  359.   # ○ Draw a basic area
  360.   #--------------------------------------------------------------------------
  361.   alias cc_atb_draw_basic_area draw_basic_area
  362.   def draw_basic_area(rect, actor)
  363.     draw_actor_ap(actor, rect.x + 0, rect.y, 100)
  364.     cc_atb_draw_basic_area(rect, actor)
  365.   end
  366. end
  367.  
  368. #==============================================================================
  369. # □ Window_Selectable
  370. #------------------------------------------------------------------------------
  371. #  Window class with cursor movement and scrolling functions.
  372. #==============================================================================
  373.  
  374. class Window_Selectable < Window_Base
  375.   #--------------------------------------------------------------------------
  376.   # ○ Redraw all items
  377.   #--------------------------------------------------------------------------
  378.   def redraw_all_items
  379.     item_max.times {|i| clear_item(i) }
  380.     item_max.times {|i| draw_item(i) }
  381.   end
  382. end
  383.  
  384. #==============================================================================
  385. # □ Scene_Battle
  386. #------------------------------------------------------------------------------
  387. #  A class that processes the battle screen.
  388. #==============================================================================
  389.  
  390. class Scene_Battle < Scene_Base
  391.   #--------------------------------------------------------------------------
  392.   # ○ Redraw the information in the status window
  393.   #--------------------------------------------------------------------------
  394.   def redraw_status
  395.     @status_window.redraw_all_items
  396.     @enemy_window.redraw_all_items
  397.   end
  398.   #--------------------------------------------------------------------------
  399.   # ○ Update information in status window
  400.   #--------------------------------------------------------------------------
  401.   def refresh_status
  402.     @status_window.refresh
  403.     @enemy_window.refresh
  404.   end
  405.   #--------------------------------------------------------------------------
  406.   # ○ Frame update (AP increase)
  407.   #--------------------------------------------------------------------------
  408.   def update_ap
  409.     all_alive_members.each do |member|
  410.       member.ap += member.agi / R2_CTB_SETTINGS::CC_CTB_BATTLE_SPEED / (R2_CTB_SETTINGS::CC_CTB_BATTLE_SPEED_ADJUST ? $cc_ctb_speed_adjust : 1)
  411.       member.regenerate_all if R2_CTB_SETTINGS::CC_CTB_REGENERATE_TIMING == 1
  412.     end
  413.     redraw_status
  414.     update_basic
  415.   end
  416.   #--------------------------------------------------------------------------
  417.   # ○ Start party command selection
  418.   #--------------------------------------------------------------------------
  419.   def start_party_command_selection
  420.     unless scene_changing?
  421.       refresh_status
  422.       @status_window.unselect
  423.       @status_window.open
  424.       while BattleManager.next_action_battler.ap < R2_CTB_SETTINGS::CC_CTB_AP_ACTION_LIMIT
  425.         update_ap
  426.       end
  427.       if BattleManager.input_start
  428.         @actor_command_window.close
  429.         @party_command_window.setup
  430.       else
  431.         @party_command_window.deactivate
  432.         turn_start
  433.       end
  434.     end
  435.   end
  436.   #--------------------------------------------------------------------------
  437.   # ○ Acquisition of all battle members including enemies and allies
  438.   #--------------------------------------------------------------------------
  439.   def all_movable_members
  440.     $game_party.movable_members + $game_troop.movable_members
  441.   end
  442.   #--------------------------------------------------------------------------
  443.   # ○ Acquisition of all surviving members including enemies and allies
  444.   #--------------------------------------------------------------------------
  445.   def all_alive_members
  446.     $game_party.alive_members + $game_troop.alive_members
  447.   end
  448.   #--------------------------------------------------------------------------
  449.   # ○ Command [Escape]
  450.   #--------------------------------------------------------------------------
  451.   alias cc_ctb_command_escape command_escape
  452.   def command_escape
  453.     cc_ctb_command_escape
  454.     $game_party.movable_members.each do |member|
  455.       member.ap = 0
  456.     end
  457.   end
  458.   #--------------------------------------------------------------------------
  459.   # ○ start of turn
  460.   #--------------------------------------------------------------------------
  461.   def turn_start
  462.     @party_command_window.close
  463.     @actor_command_window.close
  464.     @status_window.unselect
  465.     @subject = nil
  466.     BattleManager.turn_start
  467.     @log_window.clear
  468.   end
  469.   #--------------------------------------------------------------------------
  470.   # ○ Handling Combat Actions
  471.   #--------------------------------------------------------------------------
  472.   def process_action
  473.     return if scene_changing?
  474.     if !@subject || !@subject.current_action
  475.       @subject = BattleManager.next_subject
  476.     end
  477.     return turn_end unless @subject
  478.     if @subject.action?
  479.       @subject.update_state_turns
  480.       @subject.update_buff_turns
  481.     end
  482.     if @subject.current_action
  483.       @subject.current_action.prepare
  484.       if @subject.current_action.valid?
  485.         @status_window.open
  486.         execute_action
  487.       end
  488.     end
  489.     if @subject.action?
  490.       @subject.cc_ctb_ap_action_cost
  491.     end
  492.     if @subject.current_action
  493.       @subject.remove_current_action
  494.     end
  495.     process_action_end unless @subject.current_action
  496.   end
  497. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement