查看: 2593|回复: 3

[已经解决] 关于敌人的技能AI问题

[复制链接]
梦石
0
星屑
50
在线时间
395 小时
注册时间
2012-1-12
回帖
155
发表于 2015-6-7 23:28:39 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
求教  我现在给敌人设计了一个单人回血的技能  

可是每次施放时   都会默认给速度较快的敌人加血   速度慢的敌人就算残血了  也不会加  

除非速度快的敌人死掉以后   才会加到速度较慢的怪物身上来
  
除了把不同敌人速度调整一致之外  还有别的解决办法吗?

梦石
0
星屑
1736
在线时间
761 小时
注册时间
2013-9-23
回帖
180

开拓者

发表于 2015-6-8 00:40:08 | 显示全部楼层
  1. #==============================================================================
  2. # ■ 敌人AI强化
  3. #==============================================================================
  4. # 使敌人行动的目标具有优先级
  5. # ---------------------------------------------------------------------------
  6. # by Shad3Light 2014/03/20
  7. #==============================================================================
  8. # 写在敌人备注栏内的一些标记
  9. # <target [action_id] [shortcut]>
  10. #  [action_id] :行动ID 这个ID是敌人行动栏内设置的行动的顺序 由上至下为1,2,3 …
  11. #  [shortcut]  :优先准则 决定优先对那种情况下的目标使用 种类如下
  12. #    low_hp       :HP最低
  13. #    high_hp      :HP最高
  14. #    low_hp_rate  :HP率最低
  15. #    high_hp_rate :HP率最高
  16. #    low_mp       :MP最低
  17. #    high_mp      :MP最高
  18. #    low_mp_rate  :MP率最低
  19. #    high_mp_rate :MP率最高
  20. #    low_tp       :TP最低
  21. #    high_tp      :TP最高
  22. #    low_tp_rate  :TP率最低
  23. #    high_tp_rate :TP率最高
  24. #    self
  25. #    not_self
  26. # ---------------------------------------------------------------------------
  27. # 例子:
  28. # <target 1 high_hp>
  29. #  一般情况下第一个行动是"攻击" 目标是敌方HP最高者
  30. # <target 2 low_hp_rate>
  31. #   目标是HP比率最低者 如果第二个行动是治疗 那么将为HP残量最低的角色提供治疗
  32. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  33. # 如果要使自己成为目标
  34. # <target eval [action_id]>
  35. # [eval]
  36. # </target eval>
  37. # 这里的 [eval] 是ruby的一个运算式,以返回-1, 0 或 1 。
  38. # [eval]里的a和b表示战斗者的序列
  39. #
  40. # 例如:让敌人优先攻击埃里克
  41. # <target eval 2>
  42. # if a.name == "埃里克"
  43. #   -1
  44. # elsif b.name == "埃里克"
  45. #   1
  46. # else
  47. #   a.hp <=> b.hp
  48. # end
  49. # </target eval>
  50. # ---------------------------------------------------------------------------
  51. # 注意:
  52. # VA自身的战斗方式是回合制,敌人的行动就和我方一样是在回合开始时指定好的。
  53. # 如果这个敌人的目标因为受到其他敌人的治疗而使得HP不再满足需要治疗的条件了,
  54. # 这个敌人也不会把目标更改为其他的敌人或是采取其他的行动。
  55. #==============================================================================
  56. if $imported && $imported[:SHD_TargetingManipulator]
  57.   msgbox "Warning: Targeting Priority Manipulator script is imported twice."
  58. else
  59. $imported = {} if $imported.nil?
  60. $imported[:SHD_TargetingManipulator] = true
  61. #==============================================================================
  62. # 重写:DataManager
  63. #      self.load_database
  64. #    Game_Action
  65. #      set_enemy_action
  66. # 新增:DataManager
  67. #      self.load_notetags_adv_ai_target
  68. #    RPG::Enemy
  69. #      load_notetags_adv_ai_target
  70. #    RPG::Enemy::Action
  71. #      targeting_shortcut (attr_reader)
  72. #      targeting_shortcut=
  73. #      targeting_eval (attr_reader)
  74. #      targeting_eval=
  75. #      use_adv_targeting?
  76. #    Game_Action
  77. #      set_ai_target
  78. #      set_ai_opponent_target
  79. #      set_ai_friend_target
  80. #      ai_sorting
  81. #      ai_sorting_extension
  82. #==============================================================================
  83. module SHD
  84.   module REGEXP
  85.     ENEMY_TARG_EVAL = /<targ(?:et){,1}?[-_ ]?eval[: ]+(\d+)[ ]*>(.*?)<\/targ(:?et){,1}?[-_ ]?eval>/im
  86.     ENEMY_TARG_SHORTCUT = /<targ(?:et){,1}?[: ]+(\d+)[, ]+(\w+)>/i
  87.   end
  88. end
  89. #==============================================================================
  90. module DataManager
  91.   class <<self
  92.     alias :load_database_adv_ai_target :load_database
  93.   end
  94.   #------------------------------
  95.   def self.load_database
  96.     load_database_adv_ai_target
  97.     load_notetags_adv_ai_target
  98.   end
  99.   #------------------------------
  100.   def self.load_notetags_adv_ai_target
  101.     $data_enemies.each do |o|
  102.       next if o.nil?
  103.       o.load_notetags_adv_ai_target
  104.     end
  105.   end
  106. end
  107. #==============================================================================
  108. # RPG::Enemy
  109. #==============================================================================
  110. class RPG::Enemy < RPG::BaseItem
  111.   #------------------------------
  112.   def load_notetags_adv_ai_target
  113.     self.note.split(/[\r\n]+/).each { |line|
  114.       if line =~ SHD::REGEXP::ENEMY_TARG_SHORTCUT
  115.         action_id = $1.to_i - 1
  116.         if @actions[action_id]
  117.           @actions[action_id].targeting_shortcut = $2.downcase.to_sym
  118.         end
  119.       end
  120.     }
  121.     self.note.scan(SHD::REGEXP::ENEMY_TARG_EVAL).each { |match|
  122.       action_id = match[0].to_i - 1
  123.       if @actions[action_id]
  124.         @actions[action_id].targeting_eval = match[1]
  125.       end
  126.     }
  127.   end
  128. end
  129. #==============================================================================
  130. # RPG::Enemy::Action
  131. #==============================================================================
  132. class RPG::Enemy::Action
  133.   attr_reader :targeting_shortcut
  134.   attr_reader :targeting_eval
  135.   #------------------------------
  136.   def use_adv_targeting?
  137.     @use_adv_targeting
  138.   end
  139.   #------------------------------
  140.   def targeting_shortcut=(symbol)
  141.     @targeting_shortcut = symbol
  142.     @use_adv_targeting = true
  143.   end
  144.   #------------------------------
  145.   def targeting_eval=(string)
  146.     @targeting_shortcut = :eval
  147.     @targeting_eval = string
  148.     @use_adv_targeting = true
  149.   end
  150. end
  151. #==============================================================================
  152. # Game_Action
  153. #==============================================================================
  154. class Game_Action
  155.   alias :set_enemy_action_ai_prio :set_enemy_action
  156.   def set_enemy_action(action)
  157.     set_enemy_action_ai_prio(action)
  158.     set_ai_target(action) if action
  159.   end
  160.   #------------------------------
  161.   def set_ai_target(action)
  162.     return unless action.use_adv_targeting?
  163.     if item.for_opponent?
  164.       set_ai_opponent_target(action)
  165.     elsif item.for_friend?
  166.       set_ai_friend_target(action)
  167.     end
  168.   end
  169.   #------------------------------
  170.   def set_ai_opponent_target(action)
  171.     candidates = opponents_unit.alive_members
  172.     candidates.sort! { |a, b| ai_sorting(a, b, action) }
  173.     @target_index = candidates[0].index
  174.   end
  175.   #------------------------------
  176.   def set_ai_friend_target(action)
  177.     if item.for_dead_friend?
  178.       candidates = friends_unit.dead_members
  179.     else
  180.       candidates = friends_unit.alive_members
  181.     end
  182.     candidates.sort! { |a, b| ai_sorting(a, b, action) }
  183.     @target_index = candidates[0].index
  184.   end
  185.   #------------------------------
  186.   def ai_sorting(a, b, action)
  187.     case action.targeting_shortcut
  188.     when :low_hp
  189.       return a.hp <=> b.hp
  190.     when :high_hp
  191.       return b.hp <=> a.hp
  192.     when :low_hp_rate
  193.       return a.hp_rate <=> b.hp_rate
  194.     when :high_hp_rate
  195.       return b.hp_rate <=> a.hp_rate
  196.     when :low_mp
  197.       return a.mp <=> b.mp
  198.     when :high_mp
  199.       return b.mp <=> a.mp
  200.     when :low_mp_rate
  201.       return a.mp_rate <=> b.mp_rate
  202.     when :high_mp_rate
  203.       return b.mp_rate <=> a.mp_rate
  204.     when :low_tp
  205.       return a.tp <=> b.tp
  206.     when :high_tp
  207.       return b.tp <=> a.tp
  208.     when :low_tp_rate
  209.       return a.tp_rate <=> b.tp_rate
  210.     when :high_tp_rate
  211.       return b.tp_rate <=> a.tp_rate
  212.     when :self
  213.       return a == subject ? -1 : rand(2)
  214.     when :not_self
  215.       return a != subject ? rand(2) - 1 : 1
  216.     when :eval
  217.       return eval(action.targeting_eval)
  218.     else
  219.       return ai_sorting_extension(a, b, action)
  220.     end
  221.   end
  222.   #------------------------------
  223.   def ai_sorting_extension(a, b, action)
  224.     return 0
  225.   end
  226. end
  227. end
复制代码
原脚本不知道跑哪去了,以上是脑补+机翻+人工人话化...你懂的,一般机翻出来的东西都比较让人不知道说的是啥,
所以使用方法有啥不准确的地方,本渣灰常任性地概不负责,呵呵。

点评

非常感谢  发表于 2015-6-8 09:44
http://www.rpgmakervxace.net/topic/22710-enemy-ai-targeting-priority-manipulator/?hl=shad3light  发表于 2015-6-8 08:06

评分

参与人数 1星屑 +200 收起 理由
taroxd + 200 认可答案

查看全部评分

回复

使用道具 举报

梦石
0
星屑
62
在线时间
839 小时
注册时间
2010-6-26
回帖
652
发表于 2015-6-8 08:11:17 | 显示全部楼层
楼上的是针对每个怪物设计的,然后还有一个是针对技能设计的。
两个能不能同时用暂时没测试过
给网址
http://www.rpgmakervxace.net/top ... ng-ai/?hl=targeting

点评

非常感谢  发表于 2015-6-8 17:19

评分

参与人数 1星屑 +200 收起 理由
taroxd + 200 认可答案

查看全部评分

新手们!不要被看扁了!我们也会用论坛搜索,我们也会自己找脚本,我们也会自己点击关闭按钮旁边的小问号!
回复

使用道具 举报

梦石
0
星屑
22879
在线时间
8598 小时
注册时间
2011-12-31
回帖
3270
发表于 2015-6-8 08:50:39 | 显示全部楼层
本帖最后由 tseyik 于 2015-6-8 08:55 编辑

Advanced AI Conditions

Version 1.0c
qwuXSOl.png
這個可設定针对技能设计
也可针对每个怪物设计(僵先比技能高)
http://forums.rpgmakerweb.com/in ... nced-ai-conditions/
設定方法Notetags explanation:

<ai_conditions>
Explanation: You always start the block with this one.

target_hpgt: n
Explanation: The target HP must be greater or equal to n%.

target_hplt: n
Explanation: The target HP must be lesser or equal to n%.

target_states: n, n...
Explanation: The target must have the specified states already inflicted.

target_states_not: n, n...
Explanation: The target must NOT have the specified states already inflicted.

only_if_target
Explanation: If no suitable target is found, the skill won't be used AT ALL.

</ai_conditions>
Explanation: You always end the block with this one.

PART 2: ENEMY AI CONFIGURATION

On top on a default AI, you can setup individual AI conditions for every different enemy. In case of conflict with the default targeting AI, these settings will take precedence.
All these settings make use of the enemy's notebox.

NOTE: the term "action index" refers to the order of the action pattern you enter for enemies in the database. For instance, if your list is like this:

Attack
Fire II
Poison

Attack will be index 1, Fire II will be index 2 and Poison index 3. And so on.

Notetags explanation:

<ai_conditions: n, n...>
Explanation: One way of starting an AI block. n must be an action index and if you put more than one (separated by comma), the conditions will be applied to each of them.

<ai_conditions: n, n...> use_id
Explanation: Same as above, but instead of the action index, the skill ID will be used. n must be a valid skill ID in this case.

switches: n, n...
Condition: designated switches are ON.

variables: x, y, x, y...
Condition: the variables x have the value y.

states: n, n...
Condition: acting enemy is under the every of the designated states.

hpgt: n
Condition: acting enemy has hp greater or equal than n%.

hplt: n
Condition: acting enemy has hp lesser or equal than n%.

mpgt: n
Condition: acting enemy has mp greater or equal than n%.

mplt: n
Condition: acting enemy has mp lesser or equal than n%.

party_level: n
Condition: party level is greater than n.

turns_order: a+bx
Condition: it's exactly like in the database condition for turns.

target_hpgt: n
Condition: The target HP must be greater or equal to n%.

target_hplt: n
Condition: The target HP must be lesser or equal to n%.

target_states: n, n...
Condition: The target must have the specified states already inflicted.

target_states_not: n, n...
Condition: The target must NOT have the specified states already inflicted.

only_if_target
Condition: If no suitable target is found, the skill won't be used AT ALL.

</ai_conditions>
Explanation: You must end the block with this one.


- Creating Turn Patterns

Turn patterns is a special AI setting which completely replace an action pattern with another one at the designated turns. During a turn pattern, the "normal" actions (the ones you entered into the database) won't be taken into consideration, ever. You need to create another block to make a Turn Pattern.

<turn_pattern: a+bx>
Used to define the pattern. a is the first turn and b the number of turns after the first.

skill: a, b
a is the skill id and b the rating.

</turn_pattern>
End the pattern.

点评

非常感谢!  发表于 2015-6-8 09:45

评分

参与人数 1星屑 +200 收起 理由
taroxd + 200 认可答案

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部