CyberForte

DoW Counter

Oct 10th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 38.59 KB | None | 0 0
  1. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  2. #_/ ◆ Counter - KGC_Counter ◆ VX ◆
  3. #_/ ◇  Last Update: 02/15/2009
  4. #_/ ◆ Written by TOMY    
  5. #_/ ◆ Translation by Mr. Anonymous                  
  6. #_/ ◆ KGC Site:                                                  
  7. #_/ ◆  http://ytomy.sakura.ne.jp/                                  
  8. #_/ ◆ Translator's Blog:                                            
  9. #_/ ◆  http://mraprojects.wordpress.com    
  10. #_/----------------------------------------------------------------------------
  11. #_/  This script allows you to designate armors, weapons, or states that may
  12. #_/ grant the actor (or enemy) the ability to counter attack specific actions.
  13. #_/----------------------------------------------------------------------------
  14. #_/                         ◆ Instructions For Usage ◆
  15. #_/  To make use of this function, you must insert the tags into the "Note" box
  16. #_/ located in the weapons, armors, states, or enemies section of the database.
  17. #_/ This is a little more complicated than most KGC scripts note box formats,
  18. #_/ similar to KGC_CooperationSkill.
  19. #_/
  20. #_/ You begin setting up the counter ability requirements/effects with a tag...
  21. #_/ <COUNTER> or <counter>
  22. #_/ You end the requirements block with the tag...
  23. #_/ </COUNTER> or </counter>
  24. #_/ In between these tags, you'll insert the subtags that determine what the
  25. #_/ requirements and effects are. Here's are the subtags you can use.
  26. #_/
  27. #_/ KIND A/G/S/I
  28. #_/ -or-
  29. #_/ type A/G/S/I
  30. #_/
  31. #_/ * Used to determine what sort of attack is countered. After the tag, use one
  32. #_/   of the following letters to define the type.(Use commas between multiples)
  33. #_/   A = All
  34. #_/   G = Attack
  35. #_/   S = Skill
  36. #_/   I = Item
  37. #_/
  38. #_/ PHYSICAL -or- MAGICAL
  39. #_/ -or-
  40. #_/ phys -or- mag
  41. #_/
  42. #_/ * Counters the specified type of attack.
  43. #_/
  44. #_/ ELEMENT elementID1, elementID2...
  45. #_/ -or-
  46. #_/ element elementID1, elementID2...
  47. #_/
  48. #_/ * Sets the type of element(s) used for the counter attack.
  49. #_/
  50. #_/ ATK_F xxx
  51. #_/ -or-
  52. #_/ atk_f xxx
  53. #_/
  54. #_/ * The basic value at which physical damage is calculated. 100 is treated as
  55. #_/   using 100% of the user's attack power.
  56. #_/
  57. #_/ SPI_F xxx
  58. #_/ -or-
  59. #_/ spi_f xxx
  60. #_/
  61. #_/ * The basic value at which magical damage is calculated. 0 is treated as using
  62. #_/   100% of the user's SPI power.
  63. #_/
  64. #_/ REMAIN_(HP / MP) xxx (OVER  UNDER)
  65. #_/ -or-
  66. #_/ remain_(hp / mp) xxx (over / under)
  67. #_/
  68. #_/ * Causes the counter ability to only react when over or under a given  
  69. #_/ percentage of HP or MP.
  70. #_/   Ex. REMAIN_HP 20 UNDER
  71. #_/   This would cause counter to kick in only when the battler is below 20% HP.
  72. #_/  
  73. #_/ IGNORE_TARGET -or- ignore_target
  74. #_/
  75. #_/ * Counters target regardless of evasion.
  76. #_/
  77. #_/ ACTION_(A / G) -or- action_(A / G)
  78. #_/
  79. #_/ * When a counter move is invoked, their attack or guard becomes interupted.
  80. #_/   A = Attack
  81. #_/   G = Guard
  82. #_/
  83. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  84.  
  85. #==============================================================================
  86. # ★ BEGIN Customization ★                                
  87. #==============================================================================
  88.  
  89. module KGC
  90.   module Counter
  91.   #                       ◆ Counter Use Limitation ◆
  92.   #  This toggle allows you to set counter to attack only once, or behave just
  93.   # like the actor's normal attack.
  94.   #  true  : One-time use only.
  95.   #  false : If the actor can strike multiple times, counter will do the same.
  96.   RESTRICT_COUNTER = true
  97.  
  98.   #                       ◆ Counter Attack Message ◆
  99.   #  This allows you to change the message displayed when an actor or enemy
  100.   # performs a counter-attack.
  101.   #  %s = Counter Attacker's Name
  102.   VOCAB_COUNTER_ATTACK = "%s counter-attacks!"
  103.  
  104.   #                     ◆ Counter Interruption Message ◆
  105.   #  This allows you to change the message displayed when an actor or enemy
  106.   # successfully interrupts an attacker's action with a counter attack.
  107.   # Special Formatting:
  108.   #   \\N : Attacker's name
  109.   #   \\C : Counter Attacker's name
  110.   #   \\A : Name of action interrupted
  111.   VOCAB_INTERRUPT_COUNTER = "\\C interrupted \\N's \\A!"
  112.   end
  113. end
  114.  
  115. #==============================================================================
  116. # ★ END Customization ★                                
  117. #==============================================================================
  118.  
  119. #=================================================#
  120. #                    IMPORT                       #
  121. #=================================================#
  122.  
  123. $imported = {} if $imported == nil
  124. $imported["Counter"] = true
  125.  
  126. #=================================================#
  127.  
  128. #==============================================================================
  129. # □ KGC::Counter::Regexp
  130. #==============================================================================
  131. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #
  132. #                          Note Field Tag Strings                             #
  133. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #
  134. #  Whatever word(s) are after the separator ( | ) in the following lines are
  135. #   what are used to determine what is searched for in the "Note" section of a
  136. #   enemy, armor, weapon, or state.
  137.  
  138. module KGC
  139. module Counter
  140.   module Regexp
  141.     # Define Counter Start Tag
  142.     BEGIN_COUNTER = /<(?:COUNTER|counter)\s*([ASI])(\s*\:\s*\d+)?
  143.                      (\s+\d+[%%])?(\s*\/)?>/ix
  144.     # Define Counter End Tag
  145.     END_COUNTER = /<\/(?:COUNTER|counter)>/i
  146.  
  147.     # ~ Counter Conditions ~
  148.     # Action Designation
  149.     KIND = /^\s*(?:KIND|type)\s*([AGSI])(\s*\:\s*\d+(?:\s*,\s*\d+)*)?/i
  150.     # Attack Type
  151.     ATTACK_TYPE = /^\s*(PHYSICAL|MAGICAL|physical|magic)(?:_ATTACK|_attack)/i
  152.     # Element Type
  153.     ELEMENT = /^\s*(?:ELEMENT|element)\s*(\d+(?:\s*,\s*\d+)*)/i
  154.     # Attack Level
  155.     ATK_F = /^\s*(?:ATK_F|atk_f)\s*(\d+)(?:\s*above)?/i
  156.     # Spirit Level
  157.     SPI_F = /^\s*(?:SPI_F|spi_f)\s*(\d+)(?:\s*above)?/i
  158.     # Remaining HP/MP
  159.     REMAIN_HPMP = /^\s*(?:REMAIN_|remain_)?(HP|MP)\s*(\d+)(?:\s*[%%]\s*)
  160.                    (OVER|UNDER|over|under)/ix
  161.     # Ignore Target
  162.     IGNORE_TARGET = /^\s*(?:IGNORE_TARGET|ignore_target)/i
  163.     # Interrupt Action
  164.     INTERRUPT = /^\s*(?:ACTION_|action_)?(?:INTERRUPT|interrupt)\s*$/i
  165.  
  166.     # Interrupt Message
  167.     INTERRUPT_MESSAGE = /^\s*(?:INTERRUPT_MESSAGE|interrupt_message)\s*\"
  168.                         ([^\"]*)(\")?/ix
  169.  end
  170.  
  171.  KIND_ALL   = -1  # Type : ALL
  172.  KIND_BASIC = 0   # Type : Basic
  173.  KIND_SKILL = 1   # Type : Skill
  174.  KIND_ITEM  = 2   # Type : Item
  175.  
  176.  BASIC_ATTACK = 0  # Basic Action : Attack
  177.  BASIC_GUARD  = 1  # Basic Action : Defend
  178.  
  179.  TYPE_ALL      = -1  # Attack Type : ALL
  180.  TYPE_PHYSICAL = 0   # Attack Type : Physical
  181.  TYPE_MAGICAL  = 1   # Attack Type : Magical
  182.  
  183.  REMAIN_TYPE_OVER  = 0  # Remaining HP/MP : x Or More
  184.  REMAIN_TYPE_UNDER = 1  # Remaining HP/MP : x Or Less
  185.  
  186.  # Counter Type Table
  187.  COUNTER_KINDS = {
  188.    "A" => KIND_BASIC,
  189.    "G" => KIND_BASIC,
  190.    "S" => KIND_SKILL,
  191.    "I" => KIND_ITEM,
  192.  }
  193.  
  194.  # Basic Actions Counter Type Table
  195.  COUNTER_BASIC = {
  196.    "A" => BASIC_ATTACK,
  197.    "G" => BASIC_GUARD
  198.  }
  199.  
  200.  # Counter Attack Type Table
  201.  COUNTER_TYPES = {
  202.    "PHYSICAL" => TYPE_PHYSICAL,
  203.    "phys"     => TYPE_PHYSICAL,
  204.    "MAGICAL"  => TYPE_MAGICAL,
  205.    "mag"      => TYPE_MAGICAL
  206.  }
  207.  
  208.  #--------------------------------------------------------------------------
  209.  # ○ カウンター行動リストの作成
  210.  #     note : メモ欄
  211.  #--------------------------------------------------------------------------
  212.  def self.create_counter_action_list(note)
  213.    result = []
  214.  
  215.    counter_flag = false
  216.    action = nil
  217.  
  218.    interrupt_message = ""
  219.    define_interrupt_message = false
  220.    note.each_line { |line|
  221.      if line =~ KGC::Counter::Regexp::BEGIN_COUNTER
  222.        match = $~.clone
  223.        # カウンター定義開始
  224.        action = Game_CounterAction.new
  225.        if match[1] != nil
  226.          action.kind = COUNTER_KINDS[match[1].upcase]
  227.        end
  228.        case action.kind
  229.        when KIND_SKILL
  230.          next if match[2] == nil
  231.          action.skill_id = match[2][/\d+/].to_i
  232.        when KIND_ITEM
  233.          next if match[2] == nil
  234.          action.item_id = match[2][/\d+/].to_i
  235.        end
  236.        if match[3] != nil
  237.          action.execute_prob = match[3][/\d+/].to_i
  238.        end
  239.        counter_flag = true
  240.        if match[4] != nil
  241.          # そのまま定義終了
  242.          result << action
  243.          counter_flag = false
  244.        end
  245.      end
  246.  
  247.      next unless counter_flag
  248.  
  249.      # 割り込みメッセージ定義中
  250.      if define_interrupt_message
  251.        if line =~ /\s*([^\"]*)(\")?/
  252.          action.interrupt_message += $1.chomp
  253.          define_interrupt_message = ($2 == nil)
  254.        end
  255.        next
  256.      end
  257.  
  258.      case line
  259.      when KGC::Counter::Regexp::END_COUNTER
  260.        # カウンター定義終了
  261.        result << action
  262.        counter_flag = false
  263.  
  264.      when KGC::Counter::Regexp::KIND
  265.        # 行動種別
  266.        match = $~.clone
  267.        action.condition.kind = COUNTER_KINDS[match[1].upcase]
  268.        if action.condition.kind == KIND_BASIC
  269.          action.condition.basic = COUNTER_BASIC[match[1].upcase]
  270.          if action.condition.basic == nil
  271.            action.condition.basic = KGC::Counter::BASIC_ATTACK
  272.          end
  273.        end
  274.        if match[2] != nil
  275.          ids = []
  276.          match[2].scan(/\d+/).each { |num| ids << num.to_i }
  277.          case action.condition.kind
  278.          when KIND_SKILL
  279.            action.condition.skill_ids = ids
  280.          when KIND_ITEM
  281.            action.condition.item_ids = ids
  282.          end
  283.        end
  284.  
  285.      when KGC::Counter::Regexp::ATTACK_TYPE
  286.        # 攻撃タイプ
  287.        action.condition.type = COUNTER_TYPES[$1.upcase]
  288.  
  289.      when KGC::Counter::Regexp::ELEMENT
  290.        # 属性
  291.        elements = []
  292.        $1.scan(/\d+/).each { |num| elements << num.to_i }
  293.        action.condition.element_set |= elements
  294.  
  295.      when KGC::Counter::Regexp::ATK_F
  296.        # 打撃関係度
  297.        action.condition.atk_f = $1.to_i
  298.  
  299.      when KGC::Counter::Regexp::SPI_F
  300.        # 精神関係度
  301.        action.condition.spi_f = $1.to_i
  302.  
  303.      when KGC::Counter::Regexp::REMAIN_HPMP
  304.        type = REMAIN_TYPE_OVER
  305.        case $3.upcase
  306.        when "UNDER", "under"
  307.          type = REMAIN_TYPE_UNDER
  308.        end
  309.        case $1.upcase
  310.        when "HP"  # 残存 HP
  311.          action.condition.remain_hp = $2.to_i
  312.          action.condition.remain_hp_type = type
  313.        when "MP"  # 残存 MP
  314.          action.condition.remain_mp = $2.to_i
  315.          action.condition.remain_mp_type = type
  316.        end
  317.  
  318.      when KGC::Counter::Regexp::IGNORE_TARGET
  319.        # ターゲット無視
  320.        action.condition.ignore_target = true
  321.  
  322.      when KGC::Counter::Regexp::INTERRUPT
  323.        # 行動割り込み
  324.        action.condition.interrupt = true
  325.  
  326.      when KGC::Counter::Regexp::INTERRUPT_MESSAGE
  327.        # 割り込みメッセージ
  328.        define_interrupt_message = true
  329.        action.interrupt_message += $1.chomp
  330.        define_interrupt_message = ($2 == nil)
  331.      end
  332.    }
  333.    return result
  334.  end
  335. end
  336. end
  337.  
  338. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
  339.  
  340. #==============================================================================
  341. # ■ Vocab
  342. #==============================================================================
  343.  
  344. module Vocab
  345.  # カウンター関連メッセージ
  346.  CounterAttack = KGC::Counter::VOCAB_COUNTER_ATTACK
  347.  InterruptCounter = KGC::Counter::VOCAB_INTERRUPT_COUNTER
  348. end
  349.  
  350. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
  351.  
  352. #==============================================================================
  353. # ■ RPG::BaseItem
  354. #==============================================================================
  355.  
  356. class RPG::BaseItem
  357.  #--------------------------------------------------------------------------
  358.  # ○ カウンター行動リスト
  359.  #--------------------------------------------------------------------------
  360.  def counter_actions
  361.    if @__counter_actions == nil
  362.      @__counter_actions = KGC::Counter.create_counter_action_list(self.note)
  363.    end
  364.    return @__counter_actions
  365.  end
  366. end
  367.  
  368. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
  369.  
  370. #==============================================================================
  371. # ■ RPG::Enemy
  372. #==============================================================================
  373.  
  374. class RPG::Enemy
  375.  #--------------------------------------------------------------------------
  376.  # ○ カウンター行動リスト
  377.  #--------------------------------------------------------------------------
  378.  def counter_actions
  379.    if @__counter_actions == nil
  380.      @__counter_actions = KGC::Counter.create_counter_action_list(self.note)
  381.    end
  382.    return @__counter_actions
  383.  end
  384. end
  385.  
  386. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
  387.  
  388. #==============================================================================
  389. # ■ RPG::State
  390. #==============================================================================
  391.  
  392. class RPG::State
  393.  #--------------------------------------------------------------------------
  394.  # ○ カウンター行動リスト
  395.  #--------------------------------------------------------------------------
  396.  def counter_actions
  397.    if @__counter_actions == nil
  398.      @__counter_actions = KGC::Counter.create_counter_action_list(self.note)
  399.    end
  400.    return @__counter_actions
  401.  end
  402. end
  403.  
  404. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
  405.  
  406. #==============================================================================
  407. # ■ Game_BattleAction
  408. #==============================================================================
  409.  
  410. class Game_BattleAction
  411.  #--------------------------------------------------------------------------
  412.  # ○ 公開インスタンス変数
  413.  #--------------------------------------------------------------------------
  414.  attr_accessor :made_targets             # 作成済みターゲット
  415.  #--------------------------------------------------------------------------
  416.  # ● ターゲットの配列作成
  417.  #--------------------------------------------------------------------------
  418.  alias make_targets_KGC_Counter make_targets unless $@
  419.  def make_targets
  420.    if @made_targets == nil
  421.      @made_targets = make_targets_KGC_Counter
  422.    end
  423.    return @made_targets
  424.  end
  425.  #--------------------------------------------------------------------------
  426.  # ○ アクション名
  427.  #--------------------------------------------------------------------------
  428.  def action_name
  429.    case kind
  430.    when 0  # 基本
  431.      case basic
  432.      when 0  # 攻撃
  433.        return Vocab.attack
  434.      when 1  # 防御
  435.        return Vocab.guard
  436.      when 2  # 逃走
  437.        return Vocab.escape
  438.      when 3  # 待機
  439.        return Vocab.wait
  440.      end
  441.    when 1  # スキル
  442.      return skill.name
  443.    when 2  # アイテム
  444.      return item.name
  445.    end
  446.    return ""
  447.  end
  448. end
  449.  
  450. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
  451.  
  452. #==============================================================================
  453. # □ Game_CounterAction
  454. #------------------------------------------------------------------------------
  455. #   カウンター行動を扱うクラスです。
  456. #==============================================================================
  457.  
  458. class Game_CounterAction
  459.  #--------------------------------------------------------------------------
  460.  # ○ 公開インスタンス変数
  461.  #--------------------------------------------------------------------------
  462.  attr_accessor :kind                     # 種別 (基本 / スキル / アイテム)
  463.  attr_accessor :basic                    # 基本 (攻撃 / 防御 / 逃走 / 待機)
  464.  attr_accessor :skill_id                 # スキル ID
  465.  attr_accessor :item_id                  # アイテム ID
  466.  attr_accessor :execute_prob             # 発動確率
  467.  attr_accessor :condition                # 発動条件
  468.  attr_accessor :interrupt_message        # 割り込みメッセージ
  469.  #--------------------------------------------------------------------------
  470.  # ○ オブジェクト初期化
  471.  #--------------------------------------------------------------------------
  472.  def initialize
  473.    clear
  474.  end
  475.  #--------------------------------------------------------------------------
  476.  # ○ クリア
  477.  #--------------------------------------------------------------------------
  478.  def clear
  479.    @kind              = KGC::Counter::KIND_BASIC
  480.    @basic             = 0
  481.    @skill_id          = 0
  482.    @item_id           = 0
  483.    @execute_prob      = 100
  484.    @condition         = Game_CounterCondition.new
  485.    @interrupt_message = ""
  486.  end
  487.  #--------------------------------------------------------------------------
  488.  # ○ 有効判定
  489.  #     attacker : 攻撃者
  490.  #     defender : 被攻撃者
  491.  #--------------------------------------------------------------------------
  492.  def valid?(attacker, defender)
  493.    return false if attacker.class == defender.class  # 味方からの攻撃
  494.  
  495.    return condition.valid?(attacker, defender)
  496.  end
  497.  #--------------------------------------------------------------------------
  498.  # ○ 発動判定
  499.  #--------------------------------------------------------------------------
  500.  def exec?
  501.    return (execute_prob > rand(100))
  502.  end
  503. end
  504.  
  505. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
  506.  
  507. #==============================================================================
  508. # □ Game_CounterCondition
  509. #------------------------------------------------------------------------------
  510. #   カウンター条件を扱うクラスです。
  511. #==============================================================================
  512.  
  513. class Game_CounterCondition
  514.  #--------------------------------------------------------------------------
  515.  # ○ 公開インスタンス変数
  516.  #--------------------------------------------------------------------------
  517.  attr_accessor :kind                     # 種別 (ALL / 基本 / スキル / アイテム)
  518.  attr_accessor :basic                    # 基本 (攻撃 / 防御 / 逃走 / 待機)
  519.  attr_accessor :skill_ids                # スキル ID リスト
  520.  attr_accessor :item_ids                 # アイテム ID リスト
  521.  attr_accessor :type                     # 攻撃タイプ (ALL / 物理 / 魔法)
  522.  attr_accessor :element_set              # 属性
  523.  attr_accessor :atk_f                    # 打撃関係度
  524.  attr_accessor :spi_f                    # 精神関係度
  525.  attr_accessor :remain_hp                # 残存 HP
  526.  attr_accessor :remain_hp_type           # 残存 HP の形式 (以上 / 以下)
  527.  attr_accessor :remain_mp                # 残存 MP
  528.  attr_accessor :remain_mp_type           # 残存 MP の形式 (以上 / 以下)
  529.  attr_accessor :ignore_target            # ターゲット無視
  530.  attr_accessor :interrupt                # 行動割り込み
  531.  #--------------------------------------------------------------------------
  532.  # ○ オブジェクト初期化
  533.  #--------------------------------------------------------------------------
  534.  def initialize
  535.    clear
  536.  end
  537.  #--------------------------------------------------------------------------
  538.  # ○ クリア
  539.  #--------------------------------------------------------------------------
  540.  def clear
  541.    @kind           = KGC::Counter::KIND_ALL
  542.    @basic          = KGC::Counter::BASIC_ATTACK
  543.    @skill_ids      = []
  544.    @item_ids       = []
  545.    @type           = KGC::Counter::TYPE_ALL
  546.    @element_set    = []
  547.    @atk_f          = 0
  548.    @spi_f          = 0
  549.    @remain_hp      = 0
  550.    @remain_hp_type = KGC::Counter::REMAIN_TYPE_OVER
  551.    @remain_mp      = 0
  552.    @remain_mp_type = KGC::Counter::REMAIN_TYPE_OVER
  553.    @ignore_target  = false
  554.    @interrupt      = false
  555.  end
  556.  #--------------------------------------------------------------------------
  557.  # ○ 有効判定
  558.  #     attacker : 攻撃者
  559.  #     defender : 被攻撃者
  560.  #--------------------------------------------------------------------------
  561.  def valid?(attacker, defender)
  562.    action_item = nil
  563.    if attacker.action.skill?
  564.      action_item = attacker.action.skill
  565.    elsif attacker.action.item?
  566.      action_item = attacker.action.item
  567.    end
  568.  
  569.    return false unless kind_valid?(attacker, defender, action_item)
  570.    return false unless attack_type_valid?(attacker, defender, action_item)
  571.    return false unless element_valid?(attacker, defender, action_item)
  572.    return false unless atk_f_valid?(attacker, defender, action_item)
  573.    return false unless spi_f_valid?(attacker, defender, action_item)
  574.    return false unless remain_hpmp_valid?(attacker, defender, action_item)
  575.  
  576.    return true
  577.  end
  578.  #--------------------------------------------------------------------------
  579.  # ○ 種別有効判定
  580.  #     attacker : 攻撃者
  581.  #     defender : 被攻撃者
  582.  #     obj      : スキルまたはアイテム
  583.  #--------------------------------------------------------------------------
  584.  def kind_valid?(attacker, defender, obj)
  585.    return true  if self.kind == KGC::Counter::KIND_ALL
  586.    return false if self.kind != attacker.action.kind
  587.  
  588.    case self.kind
  589.    when KGC::Counter::KIND_BASIC
  590.      return (self.basic == attacker.action.basic)
  591.    when KGC::Counter::KIND_SKILL
  592.      # スキル ID 判定
  593.      return true if self.skill_ids.empty?
  594.      self.skill_ids.each { |sid|
  595.        return true if sid == attacker.action.skill_id
  596.      }
  597.      return false
  598.    when KGC::Counter::KIND_ITEM
  599.      # アイテム ID 判定
  600.      return true if self.item_ids.empty?
  601.      self.item_ids.each { |iid|
  602.        return true if iid == attacker.action.item_id
  603.      }
  604.      return false
  605.    end
  606.    return false
  607.  end
  608.  #--------------------------------------------------------------------------
  609.  # ○ 攻撃タイプ有効判定
  610.  #     attacker : 攻撃者
  611.  #     defender : 被攻撃者
  612.  #     obj      : スキルまたはアイテム
  613.  #--------------------------------------------------------------------------
  614.  def attack_type_valid?(attacker, defender, obj)
  615.    return true if self.type == KGC::Counter::TYPE_ALL
  616.  
  617.    if obj == nil
  618.      # 物理カウンターでない
  619.      return false if self.type != KGC::Counter::TYPE_PHYSICAL
  620.    else
  621.      # [物理攻撃] なら物理、そうでなければ魔法カウンター判定
  622.      if self.type != (obj.physical_attack ?
  623.          KGC::Counter::TYPE_PHYSICAL : KGC::Counter::TYPE_MAGICAL)
  624.        return false
  625.      end
  626.    end
  627.    return true
  628.  end
  629.  #--------------------------------------------------------------------------
  630.  # ○ 属性有効判定
  631.  #     attacker : 攻撃者
  632.  #     defender : 被攻撃者
  633.  #     obj      : スキルまたはアイテム
  634.  #--------------------------------------------------------------------------
  635.  def element_valid?(attacker, defender, obj)
  636.    return true if self.element_set.empty?
  637.  
  638.    if attacker.action.attack?
  639.      elements = attacker.element_set
  640.    else
  641.      return false if obj == nil
  642.      # 属性リスト取得
  643.      if $imported["SetAttackElement"]
  644.        elements = defender.get_inherited_element_set(attacker, obj)
  645.      else
  646.        elements = obj.element_set
  647.      end
  648.    end
  649.    return !(self.element_set & elements).empty?
  650.  end
  651.  #--------------------------------------------------------------------------
  652.  # ○ 打撃関係度有効判定
  653.  #     attacker : 攻撃者
  654.  #     defender : 被攻撃者
  655.  #     obj      : スキルまたはアイテム
  656.  #--------------------------------------------------------------------------
  657.  def atk_f_valid?(attacker, defender, obj)
  658.    return true if self.atk_f == 0
  659.  
  660.    n = (attacker.action.attack? ? 100 : (obj != nil ? obj.atk_f : 0) )
  661.    return (self.atk_f <= n)
  662.  end
  663.  #--------------------------------------------------------------------------
  664.  # ○ 精神関係度有効判定
  665.  #     attacker : 攻撃者
  666.  #     defender : 被攻撃者
  667.  #     obj      : スキルまたはアイテム
  668.  #--------------------------------------------------------------------------
  669.  def spi_f_valid?(attacker, defender, obj)
  670.    return true if self.spi_f == 0
  671.  
  672.    n = (attacker.action.attack? ? 0 : (obj != nil ? obj.spi_f : 0) )
  673.    return (self.spi_f <= n)
  674.  end
  675.  #--------------------------------------------------------------------------
  676.  # ○ 残存 HP/MP 有効判定
  677.  #     attacker : 攻撃者
  678.  #     defender : 被攻撃者
  679.  #     obj      : スキルまたはアイテム
  680.  #--------------------------------------------------------------------------
  681.  def remain_hpmp_valid?(attacker, defender, obj)
  682.    hp_rate = defender.hp * 100 / defender.maxhp
  683.    case @remain_hp_type
  684.    when KGC::Counter::REMAIN_TYPE_OVER
  685.      return false unless (hp_rate >= @remain_hp)
  686.    when KGC::Counter::REMAIN_TYPE_UNDER
  687.      return false unless (hp_rate <= @remain_hp)
  688.    end
  689.  
  690.    mp_rate = defender.mp * 100 / [defender.maxmp, 1].max
  691.    case @remain_mp_type
  692.    when KGC::Counter::REMAIN_TYPE_OVER
  693.      return false unless (mp_rate >= @remain_mp)
  694.    when KGC::Counter::REMAIN_TYPE_UNDER
  695.      return false unless (mp_rate <= @remain_mp)
  696.    end
  697.  
  698.    return true
  699.  end
  700. end
  701.  
  702. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
  703.  
  704. #==============================================================================
  705. # □ Game_CounterInfo
  706. #------------------------------------------------------------------------------
  707. #   カウンター情報を扱うクラスです。
  708. #==============================================================================
  709.  
  710. class Game_CounterInfo
  711.  #--------------------------------------------------------------------------
  712.  # ○ 公開インスタンス変数
  713.  #--------------------------------------------------------------------------
  714.  attr_accessor :battler                  # 行動者
  715.  attr_accessor :action                   # カウンター行動
  716.  attr_accessor :target_index             # 対象インデックス
  717.  #--------------------------------------------------------------------------
  718.  # ○ オブジェクト初期化
  719.  #--------------------------------------------------------------------------
  720.  def initialize
  721.    @battler      = nil
  722.    @action       = nil
  723.    @target_index = 0
  724.  end
  725. end
  726.  
  727. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
  728.  
  729. #==============================================================================
  730. # ■ Game_Battler
  731. #==============================================================================
  732.  
  733. class Game_Battler
  734.  #--------------------------------------------------------------------------
  735.  # ○ カウンター行動リストの取得
  736.  #--------------------------------------------------------------------------
  737.  def counter_actions
  738.    result = []
  739.    states.each { |state| result += state.counter_actions }
  740.    return result
  741.  end
  742. end
  743.  
  744. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
  745.  
  746. #==============================================================================
  747. # ■ Game_Actor
  748. #==============================================================================
  749.  
  750. class Game_Actor < Game_Battler
  751.  #--------------------------------------------------------------------------
  752.  # ○ カウンター行動リストの取得
  753.  #--------------------------------------------------------------------------
  754.  def counter_actions
  755.    result = super
  756.    equips.compact.each { |item| result += item.counter_actions }
  757.    return result
  758.  end
  759. end
  760.  
  761. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
  762.  
  763. #==============================================================================
  764. # ■ Game_Enemy
  765. #==============================================================================
  766.  
  767. class Game_Enemy < Game_Battler
  768.  #--------------------------------------------------------------------------
  769.  # ○ カウンター行動リストの取得
  770.  #--------------------------------------------------------------------------
  771.  def counter_actions
  772.    return (super + enemy.counter_actions)
  773.  end
  774. end
  775.  
  776. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
  777.  
  778. #==============================================================================
  779. # ■ Scene_Battle
  780. #==============================================================================
  781.  
  782. class Scene_Battle < Scene_Base
  783.  #--------------------------------------------------------------------------
  784.  # ● 開始処理
  785.  #--------------------------------------------------------------------------
  786.  alias start_KGC_Counter start unless $@
  787.  def start
  788.    start_KGC_Counter
  789.  
  790.    @counter_added = false
  791.    @counter_infos = []
  792.  end
  793.  #--------------------------------------------------------------------------
  794.  # ● 戦闘行動の処理
  795.  #--------------------------------------------------------------------------
  796.  alias process_action_KGC_Counter process_action unless $@
  797.  def process_action
  798.    process_action_KGC_Counter
  799.  
  800.    register_ignore_target_counter_action
  801.    unset_counter_action
  802.  end
  803.  #--------------------------------------------------------------------------
  804.  # ○ カウンター行動の解除
  805.  #--------------------------------------------------------------------------
  806.  def unset_counter_action
  807.    return unless @counter_exec
  808.  
  809.    # 行動を元に戻す
  810.    @active_battler.action.forcing      = @former_action.forcing
  811.    @active_battler.action.kind         = @former_action.kind
  812.    @active_battler.action.basic        = @former_action.basic
  813.    @active_battler.action.skill_id     = @former_action.skill_id
  814.    @active_battler.action.item_id      = @former_action.item_id
  815.    @active_battler.action.target_index = @former_action.target_index
  816.  
  817.    @former_action     = nil
  818.    @counter_exec      = false
  819.    @counter_interrupt = false
  820.  end
  821.  #--------------------------------------------------------------------------
  822.  # ● 次に行動するべきバトラーの設定
  823.  #--------------------------------------------------------------------------
  824.  alias set_next_active_battler_KGC_Counter set_next_active_battler unless $@
  825.  def set_next_active_battler
  826.    set_counter_action
  827.  
  828.    unless @counter_exec
  829.      set_next_active_battler_KGC_Counter
  830.    end
  831.  end
  832.  #--------------------------------------------------------------------------
  833.  # ○ カウンター行動の作成
  834.  #--------------------------------------------------------------------------
  835.  def set_counter_action
  836.    @former_action     = nil
  837.    @counter_exec      = false
  838.    @counter_added     = false
  839.    @counter_interrupt = false
  840.    counter = @counter_infos.shift
  841.    return if counter == nil
  842.  
  843.    last_active_battler = @active_battler
  844.    @active_battler     = counter.battler
  845.    # 元の行動を退避
  846.    @former_action = @active_battler.action.clone
  847.    @counter_exec  = true
  848.    # カウンター行動を設定
  849.    @active_battler.action.kind     = counter.action.kind
  850.    @active_battler.action.basic    = counter.action.basic
  851.    @active_battler.action.skill_id = counter.action.skill_id
  852.    @active_battler.action.item_id  = counter.action.item_id
  853.  
  854.    # カウンター対象を設定
  855.    target_index = counter.target_index
  856.    # 対象が味方なら自分に対して発動
  857.    if @active_battler.action.for_friend?
  858.      target_index = @active_battler.index
  859.    end
  860.    @active_battler.action.target_index = target_index
  861.  
  862.    unless @active_battler.action.valid?
  863.      # カウンター発動不能ならキャンセル
  864.      unset_counter_action
  865.      @active_battler = last_active_battler
  866.    else
  867.      @active_battler.action.forcing = true
  868.    end
  869.  end
  870.  #--------------------------------------------------------------------------
  871.  # ● 戦闘行動の実行
  872.  #--------------------------------------------------------------------------
  873.  alias execute_action_KGC_Counter execute_action unless $@
  874.  def execute_action
  875.    unless @counter_exec
  876.      register_interrupt_counter_action
  877.    end
  878.  
  879.    if @counter_interrupt
  880.      execute_interrupt_counter
  881.    else
  882.      execute_action_KGC_Counter
  883.    end
  884.    @active_battler.action.made_targets = nil
  885.  end
  886.  #--------------------------------------------------------------------------
  887.  # ● 戦闘行動の実行 : 攻撃
  888.  #--------------------------------------------------------------------------
  889.  alias execute_action_attack_KGC_Counter execute_action_attack unless $@
  890.  def execute_action_attack
  891.    if @counter_exec
  892.      # 攻撃時メッセージを無理矢理書き換える
  893.      old_DoAttack = Vocab::DoAttack
  894.      Vocab.const_set(:DoAttack, Vocab::CounterAttack)
  895.    end
  896.  
  897.    execute_action_attack_KGC_Counter
  898.  
  899.    if @counter_exec
  900.      # 後始末
  901.      Vocab.const_set(:DoAttack, old_DoAttack)
  902.    end
  903.  end
  904.  #--------------------------------------------------------------------------
  905.  # ● 行動結果の表示
  906.  #     target : 対象者
  907.  #     obj    : スキルまたはアイテム
  908.  #--------------------------------------------------------------------------
  909.  alias display_action_effects_KGC_Counter display_action_effects unless $@
  910.  def display_action_effects(target, obj = nil)
  911.    display_action_effects_KGC_Counter(target, obj)
  912.  
  913.    unless target.skipped
  914.      register_counter_action(target)
  915.    end
  916.  end
  917.  #--------------------------------------------------------------------------
  918.  # ○ カウンター行動の登録
  919.  #     target    : 被攻撃者
  920.  #     interrupt : 割り込みフラグ
  921.  #--------------------------------------------------------------------------
  922.  def register_counter_action(target, interrupt = false)
  923.    return unless can_counter?(target)
  924.  
  925.    # 有効なカウンター行動をセット
  926.    target.counter_actions.each { |counter|
  927.      break if counter_added?
  928.      break if counter.condition.ignore_target
  929.      break if counter.condition.interrupt != interrupt
  930.      judge_counter_action(@active_battler, target, counter)
  931.    }
  932.  end
  933.  #--------------------------------------------------------------------------
  934.  # ○ カウンター可否
  935.  #     target   : 被攻撃者
  936.  #--------------------------------------------------------------------------
  937.  def can_counter?(target = nil)
  938.    return false if @counter_exec   # カウンターに対するカウンターは行わない
  939.    return false if counter_added?  # カウンター済み
  940.    if target != nil
  941.      return false unless target.movable?  # 行動不能
  942.    end
  943.  
  944.    if $imported["CooperationSkill"]
  945.      # 連係スキルにはカウンターを適用しない
  946.      return false if @active_battler.is_a?(Game_CooperationBattler)
  947.    end
  948.  
  949.    return true
  950.  end
  951.  #--------------------------------------------------------------------------
  952.  # ○ カウンター登録済み判定
  953.  #--------------------------------------------------------------------------
  954.  def counter_added?
  955.    return (KGC::Counter::RESTRICT_COUNTER && @counter_added)
  956.  end
  957.  #--------------------------------------------------------------------------
  958.  # ○ カウンター判定
  959.  #     attacker : 攻撃者
  960.  #     target   : 被攻撃者
  961.  #     counter  : カウンター行動
  962.  #--------------------------------------------------------------------------
  963.  def judge_counter_action(attacker, target, counter)
  964.    if counter.valid?(attacker, target) && counter.exec?
  965.      info = Game_CounterInfo.new
  966.      info.battler = target
  967.      info.action  = counter
  968.      info.target_index = attacker.index
  969.      @counter_infos << info
  970.      @counter_added = true
  971.    end
  972.  end
  973.  #--------------------------------------------------------------------------
  974.  # ○ ターゲット無視のカウンター行動の登録
  975.  #     interrupt : 割り込み判定
  976.  #--------------------------------------------------------------------------
  977.  def register_ignore_target_counter_action(interrupt = false)
  978.    return unless can_counter?
  979.  
  980.    target_unit = []
  981.    case @active_battler
  982.    when Game_Actor
  983.      target_unit = $game_troop.members
  984.    when Game_Enemy
  985.      target_unit = $game_party.members
  986.    else
  987.      return
  988.    end
  989.  
  990.    target_unit.each { |battler|
  991.      next unless can_counter?(battler)
  992.      battler.counter_actions.each { |counter|
  993.        break if counter_added?
  994.        break unless counter.condition.ignore_target
  995.        break if counter.condition.interrupt != interrupt
  996.        judge_counter_action(@active_battler, battler, counter)
  997.      }
  998.    }
  999.  end
  1000.  #--------------------------------------------------------------------------
  1001.  # ○ 割り込みカウンター行動の登録
  1002.  #--------------------------------------------------------------------------
  1003.  def register_interrupt_counter_action
  1004.    return unless can_counter?
  1005.  
  1006.    # 自分が対象
  1007.    targets = @active_battler.action.make_targets
  1008.    if targets != nil
  1009.      targets.each { |t|
  1010.        break if counter_added?
  1011.        register_counter_action(t, true)
  1012.      }
  1013.    end
  1014.  
  1015.    # ターゲット無視
  1016.    register_ignore_target_counter_action(true) unless counter_added?
  1017.  
  1018.    @counter_interrupt = counter_added?
  1019.  end
  1020.  #--------------------------------------------------------------------------
  1021.  # ○ 割り込みカウンターの実行
  1022.  #--------------------------------------------------------------------------
  1023.  def execute_interrupt_counter
  1024.    counter = @counter_infos[0]
  1025.    text = counter.action.interrupt_message.clone
  1026.    text = Vocab::InterruptCounter.clone if text.empty?
  1027.  
  1028.    text.gsub!(/\\\\/, "\\")
  1029.    text.gsub!(/\\N([^\[]|$)/i) { "#{@active_battler.name}#{$1}" }
  1030.     text.gsub!(/\\C([^\[]|$)/i) { "#{counter.battler.name}#{$1}" }
  1031.     text.gsub!(/\\A([^\[]|$)/i) { "#{@active_battler.action.action_name}#{$1}" }
  1032.     @message_window.add_instant_text(text)
  1033.     wait(45)
  1034.   end
  1035. end
Advertisement
Add Comment
Please, Sign In to add comment