Project1

标题: 请教自动战斗的AI设置 [打印本页]

作者: morningboo    时间: 2014-10-7 19:30
标题: 请教自动战斗的AI设置
本帖最后由 morningboo 于 2014-10-7 19:58 编辑

1、请教各路大神,原版脚本中关于自动战斗的部分,能否详细讲解下,比如他的运行逻辑,每个语句表达的意思与作用,技能发动的条件如何设置,敌人的AI与我军的AI如何设置,敌人的攻击顺序能否指定?我军的人员在自动战斗状态下攻击顺序能否指定?
PS:我知道自己问的问题可能会比较麻烦,也实在是没有办法了,论坛里的入门脚本教程都看了,包括RGSS2圆周率的那个,还是无法读懂这一块,有一个自动战斗可以调整AI的脚本,奈何全是英文,里面还有增加选项的内容,问题是我不需要那么复杂,只需要在自带的自动战斗脚本上能够扩展一下,使的自动战斗时攻击目标不是随机,而是按照我设计的顺序来,发动技能也不是随机而是按照我设计的条件来,条件也很简单,只要MP够就放技能,不够就用另一个不需要MP的技能,且技能释放对象大部分与攻击目标一致,只有个别几个随机(这个可以在数据库里设置),还请各路大神能够不吝赐教,拜谢。
2、请教如何每攻击一下就恢复自身的魔力,在数据库的技能里设置了无效,请教?
作者: 你最珍贵    时间: 2014-10-7 20:13
技术区有自动战斗
作者: taroxd    时间: 2014-10-7 20:18
2. 攻击的技能公式按照如下设置: a.mp+=5; a.atk*4-b.def*2
作者: tseyik    时间: 2014-10-7 20:56
本帖最后由 tseyik 于 2014-10-7 21:03 编辑

敵人AI,
http://shad3light.blogspot.com/2 ... ty-manipulator.html

以下狐狗翻譯,不通順請自行脳補
預設 VX Ace 敵人瞄準目標的行為只是挑任意一個目標的任何行動。
此腳本將添加一些 AI 目標優先。使用此腳本,敵人變得能夠挑選基於行動具體的優先目標。

下載該腳本在這裡。你可能也想看看下面的修補程式。
安裝

把此腳本 ▼ 材料上下 ▼ 主要過程。

使用

在敵人的 notebox,你可以添加一些標記。

<target [action_id] [shortcut]>

在 [action_id] 對應于敵人的動作清單中,並且 [快捷方式] 對應到實現目標的優先方法之一。

示例:

<target 1 high_hp>

使用行動編號 1 (預設情況下攻擊) 時,這將使敵方目標 HP 值最大的武士。

<target 2 low_hp_rate>

使用 2 號行動時,這將使敵方目標巴特勒爾號 HP 的比例最低。如果行動號 2 設置為治癒,敵人將著手醫治其盟友與健康的最低百分比。

可用目標快捷方式如下所示:

low_hp
high_hp
low_hp_rate
high_hp_rate
low_mp
high_mp
low_mp_rate
high_mp_rate
low_tp
high_tp
low_tp_rate
high_tp_rate
self
not_self


如果你想要使自己的目標的條件,請使用

<target eval [action_id]>
[eval]
</target eval>

在 [eval] 是一個 ruby 的運算式,以返回-1、 0 或 1。
在 eval,b 表示將排序的武士。

例如,若要使敵人優先 Eric 做其終極技能時,標記將被

<target eval 8>
if a.name == "Eric"
-1
elsif b.name == "Eric"
1
else
a.hp <=> b.hp
end
</target eval>



請注意在轉,像演員一樣開始時做了目標選擇。敵人不會突然改變目標中期轉,例如,如果其目標已經痊癒。
庫區還對收購目標沒有影響。
作者: morningboo    时间: 2014-10-7 21:06
本帖最后由 morningboo 于 2014-10-7 21:30 编辑

谢谢解答,按照你的设置,是恢复了MP,但是每次恢复太多,我只想让它恢复2点,把5改成2后,恢复的还是很多,请问怎么回事?还有就是这样设置后,自动战斗释放的另一个耗MP的技能,第一次会消耗MP,第二次就不消耗了?
作者: morningboo    时间: 2014-10-7 21:20
tseyik 发表于 2014-10-7 20:56
敵人AI,
http://shad3light.blogspot.com/2014/03/enemy-ai-targeting-priority-manipulator.html

请教你的地址如何翻墙?我这边看不到,谢谢
作者: tseyik    时间: 2014-10-8 13:35
本帖最后由 tseyik 于 2014-10-8 13:41 编辑
  1. #===============================================================================
  2. # Enemy AI : Targeting Priority Manipulator
  3. #   by Shad3Light
  4. #
  5. # 2014/03/20
  6. # Link: http://shad3light.blogspot.com/2014/03/enemy-ai-targeting-priority-manipulator.html
  7. #===============================================================================


  8. =begin
  9. ================================================================================
  10. Description

  11. The default VX Ace's enemy targeting behavior just pick a random target for
  12. any actions.
  13. This script adds some AI targeting priority. With this script, the enemies
  14. become able to pick a target based on the action specific priority.

  15. --------------------------------------------------------------------------------
  16. History

  17. v1.0 (2014/03/20)
  18.   Initial release
  19.    
  20. --------------------------------------------------------------------------------
  21. Terms of Use

  22. - You are free to use this script for non-commercial projects.
  23. - For commercial projects, at least contact me first.
  24. - This script is provided as-is. Don't expect me to give support.
  25. - Reported bug will be fixed, but no guarantee on requested features.
  26. - No guarantee either for compatibility fixes.
  27. - Give credit to Shad3Light (me), and do not delete this header.
  28. --------------------------------------------------------------------------------
  29. Installation

  30. Put this script below Бе Materials and above Бе Main Process.
  31. If there are scripts that overwrite the aliased methods below,
  32. put this script below said script.
  33. --------------------------------------------------------------------------------
  34. Usage

  35. In an enemy notebox, you can add some tags.
  36.   <target [action_id] [shortcut]>
  37. where [action_id] corresponds to the enemy's action list, and [shortcut]
  38. corresponds to one of the implemented targeting priority method.

  39. Example:
  40.   <target 1 high_hp>
  41. This will make the enemy target the battlers with the highest HP value when
  42. using action number 1 (by default Attack).
  43.    
  44.   <target 2 low_hp_rate>
  45. This will make the enemy target the battler with the lowest HP percentage when
  46. using action number 2. If the action no. 2 is set to Heal, the enemy will
  47. proceed to heal its ally with the lowest percentage of health.

  48. Available targeting shortcut is as follows:
  49.   low_hp
  50.   high_hp
  51.   low_hp_rate
  52.   high_hp_rate
  53.   low_mp
  54.   high_mp
  55.   low_mp_rate
  56.   high_mp_rate
  57.   low_tp
  58.   high_tp
  59.   low_tp_rate
  60.   high_tp_rate
  61.   self
  62.   not_self
  63.    
  64. If you want to make your own targeting condition, use
  65.   <target eval [action_id]>
  66.   [eval]
  67.   </target eval>
  68. where [eval] is a ruby expression that takes returns -1, 0, or 1.
  69. In the eval, a and b denotes the battlers that would be sorted.

  70. For example, to make the enemy prioritize Eric when doing its ultimate skill,
  71. the tag will be
  72.   <target eval 8>
  73.   if a.name == "Eric"
  74.     -1
  75.   elsif b.name == "Eric"
  76.     1
  77.   else
  78.     a.hp <=> b.hp
  79.   end
  80.   </target eval>


  81. Do note that target selection is done at the start of the turn, like actors.
  82. The enemy will not suddenly change target mid-turn, for example if its target
  83. had already healed.
  84. Also, TGR have no effect on acquiring target.
  85. ================================================================================
  86. =end

  87. if $imported && $imported[:SHD_TargetingManipulator]
  88.   msgbox "Warning: Targeting Priority Manipulator script is imported twice."
  89. else

  90. $imported = {} if $imported.nil?
  91. $imported[:SHD_TargetingManipulator] = true

  92. #===============================================================================
  93. # Configuration Module
  94. #
  95. # None.
  96. #
  97. # Configuration Module End
  98. #===============================================================================

  99. #===============================================================================
  100. # Code Start
  101. #   Configuration ends here. Edit what's below at your own risk.
  102. #-------------------------------------------------------------------------------
  103. # Aliased methods:
  104. #   DataManager
  105. #     self.load_database
  106. #   Game_Action
  107. #     set_enemy_action
  108. #
  109. # New methods:
  110. #   DataManager
  111. #     self.load_notetags_adv_ai_target
  112. #   RPG::Enemy
  113. #     load_notetags_adv_ai_target
  114. #   RPG::Enemy::Action
  115. #     targeting_shortcut (attr_reader)
  116. #     targeting_shortcut=
  117. #     targeting_eval (attr_reader)
  118. #     targeting_eval=
  119. #     use_adv_targeting?
  120. #   Game_Action
  121. #     set_ai_target
  122. #     set_ai_opponent_target
  123. #     set_ai_friend_target
  124. #     ai_sorting
  125. #     ai_sorting_extension
  126. #===============================================================================
  127.    
  128. #-------------------------------------------------------------------------------
  129. # Module SHD
  130. # Mainly contains Regular Expressions.
  131. #
  132. module SHD
  133.    
  134.   module REGEXP
  135.     ENEMY_TARG_EVAL = /<targ(?:et){,1}?[-_ ]?eval[: ]+(\d+)[ ]*>(.*?)<\/targ(:?et){,1}?[-_ ]?eval>/im
  136.     ENEMY_TARG_SHORTCUT = /<targ(?:et){,1}?[: ]+(\d+)[, ]+(\w+)>/i
  137.   end
  138.    
  139. end
  140. #
  141. # End Module SHD
  142. #-------------------------------------------------------------------------------


  143. #-------------------------------------------------------------------------------
  144. # Module DataManager
  145. # Adding methods for reading enemy notetags.
  146. #
  147. module DataManager
  148.    
  149.   class <<self
  150.     alias :load_database_adv_ai_target :load_database
  151.   end
  152.    
  153.   def self.load_database
  154.     load_database_adv_ai_target
  155.     load_notetags_adv_ai_target
  156.   end
  157.    
  158.   def self.load_notetags_adv_ai_target
  159.     $data_enemies.each do |o|
  160.       next if o.nil?
  161.       o.load_notetags_adv_ai_target
  162.     end
  163.   end
  164.    
  165. end
  166. #
  167. # End Module DataManager
  168. #-------------------------------------------------------------------------------


  169. #-------------------------------------------------------------------------------
  170. # Class RPG::Enemy
  171. #
  172. class RPG::Enemy < RPG::BaseItem
  173.    
  174.   def load_notetags_adv_ai_target
  175.     self.note.split(/[\r\n]+/).each { |line|
  176.       if line =~ SHD::REGEXP::ENEMY_TARG_SHORTCUT
  177.         action_id = $1.to_i - 1
  178.         if @actions[action_id]
  179.           @actions[action_id].targeting_shortcut = $2.downcase.to_sym
  180.         end
  181.       end
  182.     }
  183.     self.note.scan(SHD::REGEXP::ENEMY_TARG_EVAL).each { |match|
  184.       action_id = match[0].to_i - 1
  185.       if @actions[action_id]
  186.         @actions[action_id].targeting_eval = match[1]
  187.       end
  188.     }
  189.   end
  190.    
  191. end
  192. #
  193. # End Class RPG::Enemy
  194. #-------------------------------------------------------------------------------


  195. #-------------------------------------------------------------------------------
  196. # Class RPG::Enemy::Action
  197. #
  198. class RPG::Enemy::Action
  199.    
  200.   attr_reader :targeting_shortcut
  201.   attr_reader :targeting_eval
  202.    
  203.   def use_adv_targeting?
  204.     @use_adv_targeting
  205.   end
  206.    
  207.   def targeting_shortcut=(symbol)
  208.     @targeting_shortcut = symbol
  209.     @use_adv_targeting = true
  210.   end
  211.    
  212.   def targeting_eval=(string)
  213.     @targeting_shortcut = :eval
  214.     @targeting_eval = string
  215.     @use_adv_targeting = true
  216.   end
  217.    
  218. end
  219. #
  220. # End Class RPG::Enemy::Action
  221. #-------------------------------------------------------------------------------


  222. #-------------------------------------------------------------------------------
  223. # Class Game_Action
  224. #
  225. class Game_Action
  226.    
  227.   #-----------------------------------------------------------------------------
  228.   # Alias Method: set_enemy_action
  229.   #
  230.   alias :set_enemy_action_ai_prio :set_enemy_action
  231.   def set_enemy_action(action)
  232.     set_enemy_action_ai_prio(action)
  233.     set_ai_target(action) if action
  234.   end
  235.    
  236.   #-----------------------------------------------------------------------------
  237.   # New Method: set_ai_target
  238.   #
  239.   def set_ai_target(action)
  240.     return unless action.use_adv_targeting?
  241.     if item.for_opponent?
  242.       set_ai_opponent_target(action)
  243.     elsif item.for_friend?
  244.       set_ai_friend_target(action)
  245.     end
  246.   end
  247.    
  248.   #-----------------------------------------------------------------------------
  249.   # New Method: set_ai_opponent_target
  250.   #
  251.   def set_ai_opponent_target(action)
  252.     candidates = opponents_unit.alive_members
  253.     candidates.sort! { |a, b| ai_sorting(a, b, action) }
  254.     @target_index = candidates[0].index
  255.   end
  256.    
  257.   #-----------------------------------------------------------------------------
  258.   # New Method: set_ai_friend_target
  259.   #
  260.   def set_ai_friend_target(action)
  261.     if item.for_dead_friend?
  262.       candidates = friends_unit.dead_members
  263.     else
  264.       candidates = friends_unit.alive_members
  265.     end
  266.     candidates.sort! { |a, b| ai_sorting(a, b, action) }
  267.     @target_index = candidates[0].index
  268.   end
  269.    
  270.   #-----------------------------------------------------------------------------
  271.   # New Method: ai_sorting
  272.   #
  273.   def ai_sorting(a, b, action)
  274.     case action.targeting_shortcut
  275.       
  276.     when :low_hp
  277.       return a.hp <=> b.hp
  278.       
  279.     when :high_hp
  280.       return b.hp <=> a.hp
  281.       
  282.     when :low_hp_rate
  283.       return a.hp_rate <=> b.hp_rate
  284.       
  285.     when :high_hp_rate
  286.       return b.hp_rate <=> a.hp_rate
  287.       
  288.     when :low_mp
  289.       return a.mp <=> b.mp
  290.       
  291.     when :high_mp
  292.       return b.mp <=> a.mp
  293.       
  294.     when :low_mp_rate
  295.       return a.mp_rate <=> b.mp_rate
  296.       
  297.     when :high_mp_rate
  298.       return b.mp_rate <=> a.mp_rate
  299.       
  300.     when :low_tp
  301.       return a.tp <=> b.tp
  302.       
  303.     when :high_tp
  304.       return b.tp <=> a.tp
  305.       
  306.     when :low_tp_rate
  307.       return a.tp_rate <=> b.tp_rate
  308.       
  309.     when :high_tp_rate
  310.       return b.tp_rate <=> a.tp_rate
  311.       
  312.     when :self
  313.       return a == subject ? -1 : rand(2)
  314.       
  315.     when :not_self
  316.       return a != subject ? rand(2) - 1 : 1
  317.       
  318.     when :eval
  319.       return eval(action.targeting_eval)
  320.       
  321.     else
  322.       return ai_sorting_extension(a, b, action)
  323.       
  324.     end
  325.   end
  326.    
  327.   #-----------------------------------------------------------------------------
  328.   # New Method: ai_sorting_extension
  329.   # To be aliased by script extensions.
  330.   #
  331.   def ai_sorting_extension(a, b, action)
  332.     return 0
  333.   end
  334.    
  335. end
  336. #
  337. # End Class Game_Action
  338. #-------------------------------------------------------------------------------

  339. end #if $imported
复制代码
Path
使用Schala Battle System時的Path
  1. #===============================================================================
  2. # Enemy AI : Targeting Priority Manipulator Schala BS Patch
  3. #   by Shad3Light
  4. #
  5. # 2014/03/21
  6. # Link: http://shad3light.blogspot.com/2014/03/enemy-ai-targeting-priority-manipulator.html
  7. #===============================================================================


  8. =begin
  9. ================================================================================
  10. Description

  11. This is a patch for the Enemy AI : Targeting Priority Manipulator script for
  12. compatibility with Schala Battle System.

  13. --------------------------------------------------------------------------------
  14. History

  15. v1.0 (2014/03/21)
  16.   Initial release
  17.    
  18. --------------------------------------------------------------------------------
  19. Terms of Use

  20. - Refer to the these scripts' terms:
  21.   - Enemy AI : Targeting Priority Manipulator
  22.   - Schala Battle System
  23. --------------------------------------------------------------------------------
  24. Installation

  25. Put this script below Enemy AI : Targeting Priority Manipulator and
  26. Schala Battle System.
  27. --------------------------------------------------------------------------------
  28. Usage

  29. Plug and play.
  30. ================================================================================
  31. =end

  32. $imported = {} if $imported.nil?

  33. if $imported[:SHD_TargetingManipulatorSchalaPatch]
  34.   msgbox "Warning: Targeting Priority Manipulator Schala BS Patch script is imported twice."
  35. elsif !$imported[:SHD_TargetingManipulator]
  36.   msgbox "Warning: Targeting Priority Manipulator Schala BS Patch script needs Targeting Priority Manipulator above it."
  37. else

  38. $imported[:SHD_TargetingManipulatorSchalaPatch] = true

  39. #===============================================================================
  40. # Configuration Module
  41. #
  42. # None.
  43. #
  44. # Configuration Module End
  45. #===============================================================================

  46. #===============================================================================
  47. # Code Start
  48. #   Configuration ends here. Edit what's below at your own risk.
  49. #-------------------------------------------------------------------------------
  50. # Overwritten methods:
  51. #   Game_Action
  52. #     set_ai_target
  53. #   Game_Character
  54. #     enemy_target_selection
  55. #
  56. # New methods:
  57. #   Game_Action
  58. #     schala_set_ai_target
  59. #   Game_Enemy
  60. #     ai_action (attr_accessor)
  61. #===============================================================================

  62. #-------------------------------------------------------------------------------
  63. # Class Game_Action
  64. #
  65. class Game_Action
  66.    
  67.   #-----------------------------------------------------------------------------
  68.   # Overwrite Method: set_ai_target
  69.   # This will instead set the ai_action in Game_Enemy
  70.   #
  71.   def set_ai_target(action)
  72.     @subject.ai_action = action unless @subject.ai_action
  73.   end
  74.    
  75.   #-----------------------------------------------------------------------------
  76.   # New Method: shcala_set_ai_target
  77.   # As Schala uses it's own actors and enemies array, it is needed to
  78.   # pass it for picking candidates.
  79.   # It should be noted that targets here is a Character array, not Battler.
  80.   def schala_set_ai_target(action, targets)
  81.     return targets.sample unless action.use_adv_targeting?
  82.     targets.sort! { |a, b| ai_sorting(a.battler, b.battler, action) }
  83.     targets[0]
  84.   end
  85.    
  86. end
  87. #
  88. # End Class Game_Action
  89. #-------------------------------------------------------------------------------

  90. #-------------------------------------------------------------------------------
  91. # Class Game_Enemy
  92. #
  93. class Game_Enemy < Game_Battler
  94.    
  95.   attr_accessor :ai_action
  96.    
  97. end
  98. #
  99. # End Class Game_Enemy
  100. #-------------------------------------------------------------------------------


  101. #-------------------------------------------------------------------------------
  102. # Class Game_Character
  103. #
  104. class Game_Character < Game_CharacterBase
  105.    
  106.   #-----------------------------------------------------------------------------
  107.   # Overwrite Method: enemy_target_selection
  108.   # Making the target is not really random anymore.
  109.   def enemy_target_selection
  110.     skill = $data_skills[self.action_movement[2]]
  111.     ai_action = self.battler.ai_action
  112.     return unless (skill && ai_action)
  113.     action = Game_Action.new(self)
  114.     targets = []
  115.     if skill.scope >= 7
  116.       for i in $game_temp.target_enemies
  117.         targets.push(i) if !i.battler.dead?
  118.       end      
  119.     else
  120.       for i in $game_temp.target_actors
  121.         targets.push(i) if !i.battler.dead?
  122.       end
  123.     end
  124.     self.action_movement[4] =  action.schala_set_ai_target(ai_action, targets)
  125.     self.battler.ai_action = nil
  126.   end
  127.    
  128. end
  129. #
  130. # End Class Game_Character
  131. #-------------------------------------------------------------------------------

  132. end # if $imported
复制代码

作者: morningboo    时间: 2014-10-8 21:11
tseyik 发表于 2014-10-8 13:35
Path
使用Schala Battle System時的Path

谢谢大神提供,还请大神帮忙看看那个攻击一下就恢复自身魔法值固定点数这个问题该如何解决,还有那个指定攻击顺序的问题?谢谢?




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1