Advertisement
kirinelf

Ao no Kiseki CBS 2

Apr 2nd, 2012
1,732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 15.59 KB | None | 0 0
  1. #==============================================================================
  2. # ■ Ao no Kiseki Custom Battle System 13_3 OrderManager
  3. #   @version 0.23 12/01/28
  4. #   @author Saba Kan
  5. #   @translator kirinelf
  6. #------------------------------------------------------------------------------
  7. #  This is the module that handles the turn order.
  8. #  No configuration needed.
  9. #=========================================================================
  10. # Do not edit anything under this line unless you know what you're doing!
  11. #=========================================================================
  12.  
  13. module OrderManager
  14.  
  15.   #--------------------------------------------------------------------------
  16.   # ○ オブジェクト初期化
  17.   #--------------------------------------------------------------------------
  18.   def initialize
  19.     init_unit
  20.   end
  21.   #--------------------------------------------------------------------------
  22.   # ○ 先頭のユニット取得
  23.   #--------------------------------------------------------------------------
  24.   def self.top_unit
  25.     return @top_unit
  26.   end
  27.   #--------------------------------------------------------------------------
  28.   # ○ ユニット初期化
  29.   #--------------------------------------------------------------------------
  30.   def self.init_unit
  31.     @units = []
  32.     for actor in $game_party.battle_members
  33.       next if actor.dead?
  34.       if BattleManager.preemptive
  35.         delay_time = $data_skills[7].operate_time(actor)
  36.       else
  37.         delay_time = $data_skills[4].operate_time(actor)
  38.       end
  39.       @units.push(Game_BattleUnit.new(actor, delay_time))
  40.     end
  41.     for enemy in $game_troop.members
  42.       if BattleManager.surprise
  43.         delay_time = $data_skills[7].operate_time(enemy)
  44.       else
  45.         delay_time = $data_skills[4].operate_time(enemy)
  46.       end
  47.       @units.push(Game_BattleUnit.new(enemy, delay_time)) if enemy.alive?
  48.     end
  49.     sort
  50.     update_top
  51.     init_position
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # ○ 座標を初期化
  55.   #--------------------------------------------------------------------------
  56.   def self.init_position
  57.     @top_unit.init_position
  58.     @units.each { |unit| unit.init_position }
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # ○ フレーム更新
  62.   #--------------------------------------------------------------------------
  63.   def self.update
  64.     check_alive
  65.     check_dead
  66.     self.units.each { |unit| unit.update }
  67.   end
  68.   #--------------------------------------------------------------------------
  69.   # ○ バトラーの配列を返します。
  70.   #--------------------------------------------------------------------------
  71.   def self.battlers
  72.     @units.collect {|unit| unit.battler }.uniq
  73.   end
  74.   #--------------------------------------------------------------------------
  75.   # ○ ユニットの点滅を停止します。
  76.   #--------------------------------------------------------------------------
  77.   def self.clear_blink
  78.     for unit in @units
  79.       unit.blink = false
  80.       unit.targeted = false
  81.     end
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # ○ 指定のキャラの最小さいディレイコマ数を取得
  85.   #--------------------------------------------------------------------------
  86.   def self.min_delay_count(battler)
  87.     unit = find_unit(battler)
  88.     return -@units.index(unit)
  89.   end
  90.   #--------------------------------------------------------------------------
  91.   # ○ 指定のキャラの最大ディレイコマ数を取得
  92.   #--------------------------------------------------------------------------
  93.   def self.max_delay_count(battler)
  94.     unit = find_unit(battler)
  95.     return @units.size - @units.index(unit) - 1
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ○ 指定のキャラの待ち時間に指定の値を加えます。
  99.   #--------------------------------------------------------------------------
  100.   def self.add_delay(battler, delay)
  101.     unit = find_unit(battler)
  102.     return unless unit
  103.     unit.delay_time += delay if unit
  104.     sort
  105.     update_delay_time
  106.   end
  107.   #--------------------------------------------------------------------------
  108.   # ○ 指定のキャラのスキル発動待ちをキャンセルします。
  109.   #--------------------------------------------------------------------------
  110.   def self.cancel(unit)
  111.     return false if unit == nil
  112.     unit.cancel
  113.     unit.delay_time = $data_skills[6].operate_time(unit.battler)
  114.     sort
  115.     update_delay_time
  116.     return true
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # ○ 先頭ユニットを削除し、次のユニットに入れ替えます。
  120.   #--------------------------------------------------------------------------
  121.   def self.update_top
  122.     check_remove
  123.    
  124.     old = @top_unit
  125.     @top_unit = @units[0]
  126.    
  127.     @units.delete(@top_unit)
  128.     @top_unit.forecast = false
  129.     @top_unit.delay_time_decimal = 99
  130.     @units.each_with_index do |unit, i|
  131.       unit.delay_time -= @top_unit.delay_time
  132.       unit.forecast = false
  133.     end
  134.     @top_unit.delay_time = 0
  135.     update_delay_time
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   # ○ 指定のバトラーのユニットが存在するかを返します。
  139.   #--------------------------------------------------------------------------
  140.   def self.contains?(battler)
  141.     return find_unit(battler) != nil
  142.   end
  143.   #--------------------------------------------------------------------------
  144.   # ○ ユニット内のキャラの死亡を判定します。
  145.   #--------------------------------------------------------------------------
  146.   def self.check_dead
  147.     for unit in @units.clone
  148.       if  (unit.battler.dead? || unit.battler.hidden?)
  149.         remove(unit.battler)
  150.         next
  151.       end
  152.     end
  153.   end
  154.   #--------------------------------------------------------------------------
  155.   # ○ ユニット内の死亡したキャラの復活を判定します。
  156.   #--------------------------------------------------------------------------
  157.   def self.check_alive
  158.     for actor in $game_party.battle_members
  159.       next if actor.dead?
  160.       if find_unit(actor) == nil
  161.         insert(actor, $data_skills[5].operate_time(actor))
  162.       end
  163.     end
  164.     for actor in $game_troop.members
  165.       next if actor.dead? || actor.hidden?
  166.       if find_unit(actor) == nil
  167.         insert(actor, $data_skills[5].operate_time(actor))
  168.       end
  169.     end
  170.   end
  171.   #--------------------------------------------------------------------------
  172.   # ○ ユニット内のパーティー抜けを判定します。
  173.   #--------------------------------------------------------------------------
  174.   def self.check_remove
  175.     for unit in @units.clone
  176.      if unit.battler.actor?
  177.         unless $game_party.battle_members.include?(unit.battler)
  178.           remove(unit.battler)
  179.           next
  180.         end
  181.       end
  182.     end
  183.   end
  184.   #--------------------------------------------------------------------------
  185.   # ○ 指定のバトラーをユニットとして追加します。
  186.   #  battler 追加するバトラー
  187.   #  delay_time 待ち時間
  188.   #  forecast 行動順の予想ユニットかどうかのフラグ
  189.   #  item 待ち時間が必要なアイテム
  190.   #--------------------------------------------------------------------------
  191.   def self.insert(battler, delay_time, forecast = false, item = nil, operate = false)
  192.     delay_time = delay_time.round
  193.     unit = find_not_top_unit(battler)
  194.     if unit
  195.       update_unit(unit, delay_time, forecast, item, operate)
  196.     else
  197.       insert_new_unit(battler, delay_time, forecast, item, operate)
  198.     end
  199.     sort
  200.     update_delay_time
  201.   end
  202.   #--------------------------------------------------------------------------
  203.   # ○ ユニットの状態を更新
  204.   #--------------------------------------------------------------------------
  205.   def self.update_unit(unit, delay_time, forecast, item, operate)
  206.     index = @units.index(unit)
  207.     if forecast
  208.       unit.delay_time = delay_time
  209.     end
  210.     unit.forecast = forecast
  211.     unit.usable_item = item
  212.     unit.operate = operate
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # ○ 新しいユニットを追加
  216.   #--------------------------------------------------------------------------
  217.   def self.insert_new_unit(battler, delay_time, forecast, item, operate)
  218.     new_unit = Game_BattleUnit.new(battler, delay_time, forecast, item, operate)
  219.     new_unit.x = Saba::Kiseki::INSERT_DISTANCE
  220.     @units.push(new_unit)
  221.   end
  222.   #--------------------------------------------------------------------------
  223.   # ○ 待ち時間を更新
  224.   #--------------------------------------------------------------------------
  225.   def self.update_delay_time
  226.     @top_unit.index = 0 if @top_unit != nil
  227.     @units.each_with_index do |unit, i|
  228.       unit.index = i + 1
  229.       unit.delay_time_decimal = i * 500 # 間にディレイキャラを差し込むため
  230.     end
  231.   end
  232.   #--------------------------------------------------------------------------
  233.   # ○ 先頭以外で指定のバトラーを内部に持つユニットを検索します。
  234.   #--------------------------------------------------------------------------
  235.   def self.find_not_top_unit(battler)
  236.     return @units.reverse.select { |unit| unit.battler == battler}[0]
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # ○ 指定のバトラーを内部に持つユニットを検索します。
  240.   #--------------------------------------------------------------------------
  241.   def self.find_unit(battler)
  242.     return self.units.reverse.select { |unit| unit.battler == battler}[0]
  243.   end
  244.   #--------------------------------------------------------------------------
  245.   # ○ 指定のバトラーを内部に持つユニットを削除します。
  246.   #--------------------------------------------------------------------------
  247.   def self.remove(battler)
  248.     unit = find_unit(battler)
  249.     return if unit == nil
  250.     @units.delete(unit)
  251.   end
  252.   #--------------------------------------------------------------------------
  253.   # ○ 全てのユニットを返します。
  254.   #--------------------------------------------------------------------------
  255.   def self.units
  256.     return ([@top_unit] + @units).compact
  257.   end
  258.   #--------------------------------------------------------------------------
  259.   # ○ 全てのユニットを行動順に並び替えます。
  260.   #--------------------------------------------------------------------------
  261.   def self.sort
  262.     @units.sort! { |a, b| a.delay_time_compare <=> b.delay_time_compare }
  263.   end
  264.   #--------------------------------------------------------------------------
  265.   # ○ 指定のバトラーを含むユニットを点滅
  266.   #--------------------------------------------------------------------------
  267.   def self.blink(battler, show_targeted = true)
  268.     unit = find_unit(battler)
  269.     return if unit == nil
  270.     unit.blink = true
  271.     show_target(battler) if show_targeted
  272.   end
  273.   #--------------------------------------------------------------------------
  274.   # ○ 指定のバトラーの攻撃目標を表示
  275.   #--------------------------------------------------------------------------
  276.   def self.show_target(battler)
  277.     for unit in @units.reverse
  278.       unit.targeted = battler.target?(unit.battler)
  279.     end
  280.   end
  281.   #--------------------------------------------------------------------------
  282.   # ○ 指定のバトラーの順番を遅らせる。
  283.   #--------------------------------------------------------------------------
  284.   def self.delay_order(battler, value)
  285.     unit = find_unit(battler)
  286.  
  287.     return unless unit
  288.    
  289.     if value > 0
  290.       target = find_next_unit(unit, value)
  291.       unit.delay_time_decimal = target.delay_time_decimal + 1 + unit.delay_time_decimal / 500
  292.       unit.delay_time = target.delay_time
  293.     else
  294.       target = find_prev_unit(unit, value)
  295.       return if target == nil
  296.       unit.delay_time = target.delay_time
  297.       unit.delay_time_decimal = target.delay_time_decimal - 1
  298.     end
  299.     sort
  300.   end
  301.   #--------------------------------------------------------------------------
  302.   # ○ 指定のユニットのvalue後ろのユニットを返す
  303.   #    返されるユニットは delay_count が 0 のものに限る
  304.   #--------------------------------------------------------------------------
  305.   def self.find_next_unit(unit, value)
  306.     index = @units.index(unit) + value
  307.     begin
  308.       target = @units[index]
  309.       index += 1
  310.       return last_unit if target == nil
  311.     end while target.battler.result.delay_count != 0
  312.     return target
  313.   end
  314.   #--------------------------------------------------------------------------
  315.   # ○ 指定のユニットのvalue前のユニットを返す
  316.   #    返されるユニットは delay_count が 0 のものに限る
  317.   #--------------------------------------------------------------------------
  318.   def self.find_prev_unit(unit, value)
  319.     index = @units.index(unit) + value
  320.     begin
  321.       return top_unit if index < 0
  322.       target = @units[index]
  323.       index -= 1
  324.       return top_unit if target == nil
  325.     end while target.battler.result.delay_count != 0
  326.     return target
  327.   end
  328.   #--------------------------------------------------------------------------
  329.   # ○ 行動予想のマークを削除
  330.   #--------------------------------------------------------------------------
  331.   def self.clear_forecast
  332.     @units.each {|unit| unit.forecast = false }
  333.   end
  334.   #--------------------------------------------------------------------------
  335.   # ○ 行動予想のユニットを返す
  336.   #--------------------------------------------------------------------------
  337.   def self.forecast_unit
  338.     @units.each {|unit| return unit if unit.forecast }
  339.     return nil
  340.   end
  341.   #--------------------------------------------------------------------------
  342.   # ○ 行動予想のユニットを削除
  343.   #--------------------------------------------------------------------------
  344.   def self.remove_forecast_unit
  345.     @units.delete_if {|unit| unit.forecast }
  346.     update_delay_time
  347.   end
  348.   #--------------------------------------------------------------------------
  349.   # ○ 指定のユニットを選択
  350.   #--------------------------------------------------------------------------
  351.   def self.select(battler)
  352.     clear_selection
  353.     return unless find_unit(battler)
  354.     find_unit(battler).selected = true
  355.     show_targeted(battler)
  356.   end
  357.   #--------------------------------------------------------------------------
  358.   # ○ 攻撃対象のユニットを表示
  359.   #--------------------------------------------------------------------------
  360.   def self.show_targeted(battler)
  361.     return if battler.actor?
  362.     unit = find_unit(battler)
  363.     return unless unit
  364.     unit.targets.each do |b|
  365.       next unless find_unit(b)
  366.       find_unit(b).targeted = true
  367.     end
  368.   end
  369.   #--------------------------------------------------------------------------
  370.   # ○ 選択状態をクリア
  371.   #--------------------------------------------------------------------------
  372.   def self.clear_selection
  373.     @top_unit.selected = false
  374.     @top_unit.targeted = false
  375.     @units.each {|unit| unit.selected = false; unit.targeted = false }
  376.   end
  377.   #--------------------------------------------------------------------------
  378.   # ○ 一番最後のユニットを返します。
  379.   #--------------------------------------------------------------------------
  380.   def self.last_unit
  381.     return @units[-1]
  382.   end
  383. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement