Project1

标题: 有什麼辦法可以强化敵人使用技能的AI嗎? [打印本页]

作者: 卡奥尼特    时间: 2015-8-25 08:34
标题: 有什麼辦法可以强化敵人使用技能的AI嗎?
本帖最后由 卡奥尼特 于 2015-8-25 10:23 编辑

就和勇者大戰魔物娘   (勇戰並不是RM啊喂!) ,天使華音差不多的。。我所知道的是這兩個遊戲的共同特征
那就是敵人有AI,同時自己也想在自己的VX Ace裏實現這個的
如果是腳本的話但願不要太复雜了...就算复雜的話,也要告訴我怎麼用這個腳本....
| ω・´)
可以的話就尽量不要純事件了...


2015年8月25日 10:23:58
顺便,刚才站内搜索找到了这个。但是插入之后感觉没效果。能帮我看看吗?
https://rpg.blue/forum.php?mod=viewthread&tid=222156
作者: 黑崎一护    时间: 2015-8-25 08:54
外站有个链接:

http://forums.rpgmakerweb.com/in ... nced-ai-conditions/
作者: tseyik    时间: 2015-8-25 09:37
https://rpg.blue/forum.php?mod=viewthread&tid=379791
作者: tseyik    时间: 2015-8-25 10:31
叧一个
  1. #==============================================================================
  2. # ** TDS Custom Action AI (Skill Use AI)
  3. #    Ver: 1.4 BETA
  4. #------------------------------------------------------------------------------
  5. #  * Description:
  6. #  This script allows you to set requirements for enemies to use skills. Such
  7. #  as its target not having a certain state or its HP  being above a certain
  8. #  value
  9. #------------------------------------------------------------------------------
  10. #  * Features:
  11. #  Adds a simple AI to enemies to decide which skill to use.
  12. #------------------------------------------------------------------------------
  13. #  * Instructions:
  14. #  To add AI to a skill, put this in the enemy's notebox:
  15. #
  16. #    <Skill_Use_AI: ID>
  17. #     AI_TAGS
  18. #    </skill_use_AI>
  19. #
  20. #    ID = Is the ID of the skill to apply the AI to.
  21. #    AI_TAGS = These are the tags that determine how the AI for the skill will
  22. #              work. A list is below.
  23. #
  24. #  Examples:
  25. #
  26. #  Here are some examples of AI based on certain scenarios. (The default RMVXACE
  27. #  is used for them)
  28. #
  29. #  Scenario:
  30. #    The enemy has the skill "Heal II" (ID 27) and only wants to use it on
  31. #    targets that do not have full HP. It also wants to select whoever has
  32. #    the least HP to heal them.
  33. #
  34. #    Here is how it would translate into tags.
  35. #
  36. #    <Skill_Use_AI: 27>
  37. #      Remove_If: (t.hp_rate * 100) == 100
  38. #      Sort_by: t.hp_rate
  39. #      Select_First
  40. #    </Skill_Use_AI>
  41. #
  42. #
  43. #  Scenario:
  44. #    The enemy has the skill "Poison" (ID 27) and only wants to use it on
  45. #    targets that are not already afflicted with the state Poison (ID 2). It
  46. #    also wants to select whoever has the highest HP.
  47. #   
  48. #    Here is how it would translate into tags.
  49. #
  50. #    <Skill_Use_AI: 35>
  51. #      Remove_If: t.state?(2)
  52. #      Sort_by: t.hp
  53. #      Select_First
  54. #    </Skill_Use_AI>
  55. #
  56. #------------------------------------------------------------------------------
  57. #  * AI Commands List:
  58. #------------------------------------------------------------------------------
  59. #  Condition Shorcuts:
  60. #   Some tags use conditions as part of their process and these are some
  61. #   shorcuts to relevant objects such as targets, user, switches and variables.
  62. #------------------------------------------------------------------------------
  63. #     t = Target within a block of code of targets array.
  64. #     u = Action AI user. (Battler that is processing skill AI)
  65. #     s = Switches. (s[1] would be the same as Switch ID 1 or $game_switches[1])
  66. #     v = Variables. (v[1] would be the same as Variable ID 1 or $game_variables[1])
  67. #
  68. #     Examples:
  69. #       t.hp (This would get you the HP of a target)
  70. #       s[1] == true (This would be true if Switch ID 1 is ON)
  71. #       v[10] < 100 (This would be true if the value of Variable ID 1 is less than 100)
  72. #
  73. #------------------------------------------------------------------------------
  74. #  Requirements:
  75. #    Requirement tags are required parameters from the user in order to use the
  76. #    skill.
  77. #------------------------------------------------------------------------------
  78. #    Required_Turn: Turn_A, Turn_B
  79. #    Req_HP/MP: Min, Max
  80. #      ^ HP/MP Should be replaced with either.
  81. #      ^ Min and Max are the ranges the HP or MP must be between. (As Float values)
  82. #      ^ Example: Req_HP: 0.5, 1.0
  83. #
  84. #    Required_State: State_ID
  85. #    Required_Party_Level: Level
  86. #    Required_Switch: Switch_ID, State
  87. #      ^ State is the state of the switch to check (ON or OFF)
  88. #
  89. #    Require: Condition
  90. #      ^ Require that Condition code is true.
  91. #
  92. #    TRequire(_ALL):
  93. #      ^ Targets must meet required conditions.
  94. #      ^ If _All is part of the tag then all targets must meet the condition.
  95. #      ^ Example: TRequire: t.hp > 100 or TRequire_All: t.hp < 100
  96. #------------------------------------------------------------------------------
  97. #  Remove:
  98. #    Remove tags remove targets if the tag requirements are met.
  99. #------------------------------------------------------------------------------
  100. #    TRemove_If: Condition
  101. #      ^ Remove target if conditions code is true.
  102. #      ^ Example: t.hp > 100
  103. #
  104. #------------------------------------------------------------------------------
  105. #   Select:
  106. #     Select tags allow you select a specific target if necessary.
  107. #------------------------------------------------------------------------------
  108. #    Sort_By: Condition
  109. #      ^ Sorts targets by condition code. (Must be a comparable value)
  110. #      ^ This tag is meant to be used with others like "Select_First/Last"
  111. #
  112. #    Select_(First/Last)(: Min)
  113. #     ^ First/Last Should be replaced with either for selection.
  114. #     ^ Min is the minimun amount of random targets to select. (Optional)
  115. #     ^ Example: Select_First or Select_First: 2
  116. #
  117. #    Select_Default
  118. #      ^ Selects amounts of targets based on the scope of the skill.
  119. #
  120. #    Select_If: Condition
  121. #      ^ Select Targets if condition code is true.
  122. #      ^ Example: t.id == 20
  123. #
  124. #    Select_Random(: Min)
  125. #      ^ Min is the minimun amount of random targets to select. (Optional)
  126. #      ^ If no value is used then the default 1 will be used.
  127. #      ^ Example: Select_Random or Select_Random: 3
  128. #
  129. #    Select_Targeting_User
  130. #      ^ Selects targets whose actions are targeting the AI user.
  131. #
  132. #------------------------------------------------------------------------------
  133. #  * Notes:
  134. #  None.
  135. #------------------------------------------------------------------------------
  136. # WARNING:
  137. #
  138. # Do not release, distribute or change my work without my expressed written
  139. # consent, doing so violates the terms of use of this work.
  140. #
  141. # If you really want to share my work please just post a link to the original
  142. # site.
  143. #
  144. # * Not Knowing English or understanding these terms will not excuse you in any
  145. #   way from the consequenses.
  146. #==============================================================================
  147. # * Import to Global Hash *
  148. #==============================================================================
  149. ($imported ||= {})[:TDS_Custom_Action_AI] = true


  150. #==============================================================================
  151. # ** Scene_Battle
  152. #------------------------------------------------------------------------------
  153. #  This class performs battle screen processing.
  154. #==============================================================================

  155. class Scene_Battle < Scene_Base
  156.   #--------------------------------------------------------------------------
  157.   # * Alias Listing
  158.   #--------------------------------------------------------------------------
  159.   alias tds_custom_action_ai_scene_battle_execute_action       execute_action   
  160.   #--------------------------------------------------------------------------
  161.   # * Execute Battle Actions
  162.   #--------------------------------------------------------------------------
  163.   def execute_action
  164.     # Evaluate Enemy Battle AI
  165.     evaluate_custom_action_ai(@subject) if @subject.enemy?
  166.     # Run Original Method
  167.     tds_custom_action_ai_scene_battle_execute_action
  168.   end
  169.   #--------------------------------------------------------------------------
  170.   # * Evaluate Custom Action Battle AI
  171.   #--------------------------------------------------------------------------
  172.   def evaluate_custom_action_ai(battler)
  173.     # Return if Battler is nil or Subject is not an enemy
  174.     return if battler.nil?
  175.     # Create AI Targets
  176.     @ai_targets = []
  177.     # Selected Skill
  178.     skill = nil
  179.     # Get All Battler Custom Skill AI
  180.     ai_actions = battler.all_custom_skill_ai   
  181.     # Go Through AI Actions
  182.     ai_actions.each {|a|
  183.       # Get Skill Object
  184.       skill = $data_skills[a.at(0)]   
  185.       # Next if Skill is not usable
  186.       next if !battler.usable?(skill)
  187.       # Process Battle Action AI
  188.       break if process_battle_action_ai(battler, skill, a.at(1))      
  189.     }   
  190.     # Set Current Action to Selected Skill
  191.     battler.current_action.set_skill(skill.id) if !skill.nil?     
  192.     # Set Current Action Custom Action AI Targets
  193.     battler.current_action.custom_action_ai_targets = @ai_targets   
  194.   end
  195.   #--------------------------------------------------------------------------
  196.   # * Conver Match String value to proper Numerical
  197.   #--------------------------------------------------------------------------
  198.   def convert_match_value(string)
  199.     # Return if string is not a number
  200.     return nil if !(string =~ /^\d+/)
  201.     # Convert String to float if it contains a period
  202.     return string.to_f if string =~ /\./
  203.     # Convert String to integer
  204.     return string.to_i
  205.   end
  206.   #--------------------------------------------------------------------------
  207.   # * Process Battle Action AI
  208.   #--------------------------------------------------------------------------
  209.   def process_battle_action_ai(battler, skill, ai_list)   
  210.     # Clear AI Targets
  211.     @ai_targets.clear
  212.     # Return if AI List is empty
  213.     return true if ai_list.empty?   
  214.     # Get Targets Avaiable for skill
  215.     @ai_targets = skill.for_opponent? ? battler.opponents_unit.members.dup : battler.friends_unit.members.dup
  216.     # Delete Dead Members if Skill is not for dead friends
  217.     @ai_targets.delete_if {|t| t.dead? and !skill.for_dead_friend?}
  218.     # Go Through AI List
  219.     ai_list.each {|ai|
  220.       # Process Required, Remove and Select Action AI Tags
  221.       process_battle_required_action_ai(battler, skill, ai) if !@ai_targets.empty?
  222.       process_battle_remove_action_ai(battler, skill, ai)   if !@ai_targets.empty?
  223.       process_battle_select_action_ai(battler, skill, ai)   if !@ai_targets.empty?
  224.       # Break if Targets is empty
  225.       break if @ai_targets.empty?      
  226.     }   
  227.     # Return if AI Targets is empty
  228.     return false if @ai_targets.empty?
  229.     # Return true
  230.     return true
  231.   end
  232.   #--------------------------------------------------------------------------
  233.   # * [Required] Process Battle Action AI
  234.   #--------------------------------------------------------------------------
  235.   def process_battle_required_action_ai(battler, skill, ai)   
  236.     # Set Object Shorcuts
  237.     v = $game_variables ; s = $game_switches ; u = battler
  238.     # AI Case
  239.     case ai
  240.     # Require User conditions are met. (Condition)
  241.     when /\bRequire\b: (?'condition'.+)/i
  242.       # Get Match Information
  243.       m = Regexp.last_match
  244.       # Clear AI Targets (Breaking Loop)
  245.       @ai_targets.clear if !eval(m[:condition])   
  246.     # Require Target conditions are met for one or all targets. (Condition)
  247.     when /\bTRequire[_]?(?'con'ALL)?: (?'condition'.+)/i
  248.       # Get Match Information
  249.       m = Regexp.last_match
  250.       # Clear AI Targets (Breaking Loop)
  251.       @ai_targets.clear if m[:con] =~ /ALL/i and !@ai_targets.all? {|t| eval(m[:condition])}      
  252.       @ai_targets.clear if m[:con].nil? and !@ai_targets.any? {|t| eval(m[:condition])}
  253.     # Required Turn to use skill (Turn A, Turn B)
  254.     when /Required_Turn: (?'turn_a'[\d]+), (?'turn_b'[\d]+)/i
  255.       # Get Match Information
  256.       m = Regexp.last_match
  257.       # Get Turns and A & B Parameters
  258.       n = $game_troop.turn_count ; a = m[:turn_a].to_i ; b = m[:turn_b].to_i
  259.       # Clear AI Targets (Breaking Loop)
  260.       @ai_targets.clear if (b == 0 and n != a) or (b > 0 and (n < 1 or n < a or n % b != a % b))
  261.     # Required HP/MP to use skill (Min, Max) rates
  262.     when /Required_(?'type'HP|MP): (?'min'[\.\d]+), (?'max'[\.\d]+)/i
  263.       # Get Match Information
  264.       m = Regexp.last_match
  265.       # Get Converted String Values
  266.       min = convert_match_value(m[:min]) ; max = convert_match_value(m[:max])
  267.       # Clear All AI Targets (Breaking the loop)
  268.       @ai_targets.clear if m[:type] =~ /HP/i and !battler.hp_rate.between?(min, max)
  269.       @ai_targets.clear if m[:type] =~ /MP/i and !battler.mp_rate.between?(min, max)        
  270.     # Required State to have to use the skill (State ID)
  271.     when /Required_State: (?'id'[\d]+)/i
  272.       # Get Match Information
  273.       m = Regexp.last_match
  274.       # Clear All AI Targets (Breaking the loop)
  275.       @ai_targets.clear if !battler.state?(m[:id].to_i)        
  276.     # Minimun Party Level Required to use the skill (Level)
  277.     when /Required_Party_Level: (?'level'[\d]+)/i
  278.       # Get Match Information
  279.       m = Regexp.last_match
  280.       # Clear All AI Targets (Breaking the loop)
  281.       @ai_targets.clear if $game_party.highest_level < m[:level].to_i
  282.     # Required Active Switch to use the skill (Switch ID, State)
  283.     when /Required_Switch: (?'id'[\d]+), (?'state'[ON|OFF]+)/i
  284.       # Get Match Information
  285.       m = Regexp.last_match
  286.       # Clear All AI Targets (Breaking the loop)
  287.       @ai_targets.clear if m[:state] =~ /ON/i  and $game_switches[m[:id].to_i] == false
  288.       @ai_targets.clear if m[:state] =~ /OFF/i and $game_switches[m[:id].to_i] == true
  289.     # Require Variable conditions are met. (Condition)
  290.     when /Required_Variable: (?'condition'.+)/i
  291.       # Get Match Information
  292.       m = Regexp.last_match
  293.       # Clear AI Targets (Breaking Loop)
  294.       @ai_targets.clear if !eval(m[:condition])      
  295.     # Require Code conditions are met. (Condition)        
  296.     when /Required_Code: (?'condition'.+)/
  297.       # Get Match Information
  298.       m = Regexp.last_match      
  299.       # Clear AI Targets (Breaking Loop)
  300.       @ai_targets.clear if !eval(m[:condition])      
  301.     end      
  302.   end
  303.   #--------------------------------------------------------------------------
  304.   # * [Remove] Process Battle Action AI
  305.   #--------------------------------------------------------------------------
  306.   def process_battle_remove_action_ai(battler, skill, ai)  
  307.     # Set Object Shorcuts
  308.     v = $game_variables ; s = $game_switches ; u = battler   
  309.     # AI Case
  310.     case ai
  311.     # Remove Dead Targets
  312.     when /Remove_Dead/i ; @ai_targets.delete_if {|t| t.dead?}
  313.     # Remove Alive Targets
  314.     when /Remove_Alive/i ; @ai_targets.delete_if {|t| t.alive?}        
  315.     # Remove Target if conditions are met. (Condition)
  316.     when /Remove_If: (?'condition'.+)/i
  317.       # Get Match Information
  318.       m = Regexp.last_match
  319.       # Process Target Removal Condition
  320.       @ai_targets.delete_if {|t| eval(m[:condition])}
  321.     end
  322.   end  
  323.   #--------------------------------------------------------------------------
  324.   # * [Select] Process Battle Action AI
  325.   #--------------------------------------------------------------------------
  326.   def process_battle_select_action_ai(battler, skill, ai)
  327.     # Set Object Shorcuts
  328.     v = $game_variables ; s = $game_switches ; u = battler   
  329.     # AI Case
  330.     case ai
  331.     # Sort Targets Array by condition
  332.     when /Sort_by: (?'condition'.+)/i
  333.       # Get Match Information
  334.       m = Regexp.last_match
  335.       # Sort Targets Array
  336.       @ai_targets.sort_by! {|t| eval(m[:condition])}
  337.     # Select Targets by Default Targetting Scope (Skill Range)
  338.     when /Select_Default/i
  339.       # Select User As Target if skill is for user
  340.       @ai_targets = [battler] if skill.for_user?
  341.       # If Skill is for one target (Select one randomly)
  342.       @ai_targets = [@ai_targets.sample] if skill.for_one?
  343.       # Select Random Targets
  344.       @ai_targets = [@ai_targets.sample(skill.number_of_targets)].flatten if skill.for_random?
  345.     # Select First or Last Targets in the Targets Array (Min Amount to Select)
  346.     when /Select_(?'type'First|Last)[:]?(?'min'\s\d+)?/i
  347.       # Get Match Information
  348.       m = Regexp.last_match
  349.       # Get First Targets from Target Array
  350.       @ai_targets = @ai_targets.take([m[:min].to_i, 1].max) if m[:type] =~ /First/i
  351.       # Get Last Targets from Target Array
  352.       @ai_targets = @ai_targets.reverse.take([m[:min].to_i, 1].max) if m[:type] =~ /Last/i
  353.     # Select Target if conditions are met. (Condition)
  354.     when /Select_If: (?'condition'.+)/i
  355.       # Get Match Information
  356.       m = Regexp.last_match
  357.       # Process Target Selection Condition
  358.       @ai_targets.select! {|t| eval(m[:condition])}
  359.     # Select Random Target (Min Random value)
  360.     when /Select_Random[:]?(?'min'\s\d+)?/i
  361.       # Get Match Information
  362.       m = Regexp.last_match
  363.       # Get Random AI Targets
  364.       @ai_targets = [@ai_targets.sample([m[:min].to_i, 1].max)].flatten
  365.     # Select Targets that are targeting the user with their action
  366.     when /Select_Targeting_User/i
  367.       # Get Match Information
  368.       m = Regexp.last_match
  369.       # Get Random AI Targets      
  370.       @ai_targets.select! {|t| t.targeting_battler?(battler)}   
  371.     end
  372.   end
  373. end


  374. #==============================================================================
  375. # ** Game_Battler
  376. #------------------------------------------------------------------------------
  377. #  A battler class with methods for sprites and actions added. This class
  378. # is used as a super class of the Game_Actor class and Game_Enemy class.
  379. #==============================================================================

  380. class Game_Battler < Game_BattlerBase
  381.   #--------------------------------------------------------------------------
  382.   # * Get Battler Note Text
  383.   #--------------------------------------------------------------------------
  384.   def note ; return actor.note if actor? ; return enemy.note if enemy? ; '' end   
  385.   #--------------------------------------------------------------------------
  386.   # * Get Battler ID
  387.   #--------------------------------------------------------------------------
  388.   def id ; actor.id if actor? ; enemy.enemy_id if enemy? end   
  389.   #--------------------------------------------------------------------------
  390.   # * Get Battler Battle Actions
  391.   #--------------------------------------------------------------------------
  392.   def battle_actions
  393.     return enemy.actions if enemy?
  394.     []
  395.   end  
  396.   #--------------------------------------------------------------------------
  397.   # * Get Custom Skill AI Array
  398.   #     skill_id : ID of skill to check
  399.   #--------------------------------------------------------------------------
  400.   def custom_skill_ai(skill_id)
  401.     # Match text to Get Custom AI for Skill Use
  402.     note[/\<Skill_Use_AI: [#{skill_id}]+\>(.+?)<\/[^>]+>/im]
  403.     # Return Match Stripped and Separated into individual lines
  404.     return $1.nil? ? [] : $1.strip.split(/\r\n/)
  405.   end  
  406.   #--------------------------------------------------------------------------
  407.   # * Get All Custom Skill AI Array
  408.   #--------------------------------------------------------------------------
  409.   def all_custom_skill_ai
  410.     # Create Actions Array
  411.     actions = []
  412.     # Scan Notes for Skill Use AI Actions
  413.     note.scan(/\<Skill_Use_AI: (\d+)\>(.+?)<\/[^>]+>/im) {|id, tags|
  414.       # Strip and Remove Empty lines from tags
  415.       tags = tags.strip.split(/\r\n/).delete_if {|s| s.empty?}
  416.       # Add Skill ID and Tags to actions array
  417.       actions << [id.to_i, tags]
  418.     }   
  419.     # Return Actions Array
  420.     return actions
  421.   end
  422.   #--------------------------------------------------------------------------
  423.   # * Determine if Targeting Battler
  424.   #--------------------------------------------------------------------------
  425.   def targeting_battler?(battler)
  426.     # Return false if Current Action is nil
  427.     return false if current_action.nil?
  428.     # Check if Targeting battler
  429.     return current_action.make_targets.compact.include?(battler)
  430.   end  
  431. end


  432. #==============================================================================
  433. # ** Game_Action
  434. #------------------------------------------------------------------------------
  435. #  This class handles battle actions. This class is used within the
  436. # Game_Battler class.
  437. #==============================================================================

  438. class Game_Action
  439.   #--------------------------------------------------------------------------
  440.   # * Public Instance Variables
  441.   #--------------------------------------------------------------------------
  442.   attr_accessor :custom_action_ai_targets          # Custom AI Targets Array  
  443.   #--------------------------------------------------------------------------
  444.   # * Alias Listings
  445.   #--------------------------------------------------------------------------
  446.   alias tds_custom_action_ai_game_action_clear                   clear
  447.   alias tds_custom_action_ai_game_action_make_targets            make_targets
  448.   #--------------------------------------------------------------------------
  449.   # * Clear
  450.   #--------------------------------------------------------------------------
  451.   def clear(*args, &block)
  452.     # Run Original Method
  453.     tds_custom_action_ai_game_action_clear(*args, &block)
  454.     # Clear Custom Action AI Targets Array
  455.     @custom_action_ai_targets = []
  456.   end
  457.   #--------------------------------------------------------------------------
  458.   # * Create Target Array
  459.   #--------------------------------------------------------------------------
  460.   def make_targets(*args, &block)
  461.     # Delete Custom Targets if dead and item is not for dead friend
  462.     @custom_action_ai_targets.delete_if {|t| t.dead? and !item.for_dead_friend?}
  463.     # Return Custom Action AI Targets If Custom Action AI Targets Array is not empty
  464.     return @custom_action_ai_targets if !@custom_action_ai_targets.empty?
  465.     # Run Original Method
  466.     tds_custom_action_ai_game_action_make_targets(*args, &block)
  467.   end
  468. end
复制代码

作者: Silentever    时间: 2015-8-26 01:41
没玩过楼主提到的那些游戏,所以不知道楼主想要让AI有什么样的行动。
不过比起单纯地去找AI强化脚本,看看有没有符合要求的东西比较好吧?

其实VA本身的AI设定也没那么糟糕,对于基本系统而言功能足够了。




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