设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2499|回复: 0
打印 上一主题 下一主题

[已经过期] 可否限定自动战斗AI的使用技能

[复制链接]

Lv4.逐梦者

梦石
0
星屑
6253
在线时间
981 小时
注册时间
2010-12-3
帖子
45
跳转到指定楼层
1
发表于 2019-4-25 23:41:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
因为有些技能不适合在清小怪的时候一直出现,所以想在随机技能那边加一个 限定使用的技能 或 限定不使用的技能
希望在较有研究的前辈能帮帮忙,谢谢

  1. #==============================================================================
  2. # ■ Game_Actor
  3. #------------------------------------------------------------------------------
  4. #  AI模块
  5. #==============================================================================

  6. class  Game_Battler
  7.   attr_accessor :marks
  8. end
  9. class Game_Actor < Game_Battler
  10.   AI = [1,2,3,4] # 需要自动攻击的角色编号

  11.            # 物理攻击倾向指数 魔法攻击倾向指数 防御指数 什么都不做指数
  12.   Action_Index = [50,50]

  13.   IQ = 90 # 智商设定,90为标准值,IQ越高,越优先攻击生命值少,防御力小的
  14.   Hp_Mark = [30,-10] # 生命值评分标准,[生命值最低的得分,步进值(负)]
  15.   Df_Mark = [20,-10] # 防御值评分标准,[防御值最低的得分,步进值(负)]

  16.   EQ = 90 # 情商设定,90为标准值,EQ越高,越优先使用对应魔法(属性有效度为准),
  17.   def make_action
  18.     $game_troop.enemies.each{|i|i.marks=50}
  19.     $game_party.actors.each{|i|i.marks=50}
  20.     # 先确认动作
  21.     index = Action_Index
  22.     skills = self.skills.inject([]){|a,b|a<<b if skill_can_use?(b);a}
  23.     index[1] = 0 if skills == []
  24.     index[0] *= IQ/90.0;index[1] *= IQ/90.0;index[1] *= EQ/90.0
  25.     index[0].to_i;index[1].to_i
  26.     all = index.inject(0){|a,b|a+b}.to_i
  27.     value = rand(all)
  28.     action = 0 # 默认攻击
  29.     for i in 0...index.size
  30.       if i > value
  31.         action = i
  32.         break
  33.       else
  34.         value -= index[i]
  35.       end
  36.     end
  37.     # 目前动作为 action
  38.     case action
  39.     when 0 # 攻击
  40.       # 智商检查
  41.       enemies = $game_troop.enemies.inject([]){|a,b|a<<b if !b.hp0?;a}
  42.       # 评分
  43.       enemies.sort!{|a,b|a.hp<=>b.hp}
  44.       for i in 0...enemies.size
  45.         enemies[i].marks += (Hp_Mark[0] + i*Hp_Mark[1])*IQ/90
  46.       end
  47.       # 防御检查
  48.       enemies.sort!{|a,b|a.pdef<=>b.pdef}
  49.       for i in 0...enemies.size
  50.         enemies[i].marks += (Df_Mark[0] + i*Df_Mark[1])*IQ/90
  51.       end
  52.       # 确认目标
  53.       value = rand(enemies.inject(0){|a,b|a+b.marks})
  54.       tag = nil
  55.       for i in enemies
  56.         if i.marks > value
  57.           tag = i
  58.           break
  59.         else
  60.           value -= i.marks
  61.         end
  62.       end
  63.       # 目标确认 tag
  64.       @current_action.kind = 0
  65.       @current_action.basic = 0
  66.       return @current_action.target_index = 0 unless tag
  67.       @current_action.target_index = $game_troop.enemies.index(tag)
  68.     when 1 # 魔法
  69.       # 魔法分类,对敌/对己(加持)/附着状态/解除状态
  70.       @current_action.kind = 0
  71.       return @current_action.basic = 1 if skills == []
  72.       @current_action.kind = 1
  73.       # 随机技能
  74.       @current_action.skill_id = skills[rand(skills.size)]
  75.       # 确认对象
  76.       scope = $data_skills[@current_action.skill_id].scope
  77.       @current_action.target_index = 0
  78.       case @scope
  79.       when 1 # 敌单体
  80.         # 智商检查
  81.         enemies = $game_troop.enemies.inject([]){|a,b|a<<b if !b.hp0?;a}
  82.         # 属性有效度评分
  83.         table = [0,50,25,10,0,-10,-20]
  84.         for i in 0...enemies.size
  85.           enemies[i].marks += enemies[i].element_ranks[@current_action.skill_id]
  86.         end
  87.         # 确认目标
  88.         value = rand(enemies.inject(0){|a,b|a+b.marks})
  89.         tag = nil
  90.         for i in enemies
  91.          if i.marks > value
  92.             tag = i
  93.             break
  94.           else
  95.             value -= i.marks
  96.           end
  97.         end
  98.         @current_action.target_index = $game_troop.enemies.index(tag) if tag
  99.       when 3
  100.         # 智商检查
  101.         enemies = game_party.actors.inject([]){|a,b|a<<b if !b.hp0?;a}
  102.         # 属性有效度评分
  103.         table = [0,50,25,10,0,-10,-20]
  104.         for i in 0...enemies.size
  105.           enemies[i].marks += enemies[i].element_ranks[@current_action.skill_id]
  106.         end
  107.         # 确认目标
  108.         value = rand(enemies.inject(0){|a,b|a+b.marks})
  109.         tag = nil
  110.         for i in enemies
  111.          if i.marks > value
  112.             tag = i
  113.             break
  114.           else
  115.             value -= i.marks
  116.           end
  117.         end
  118.         @current_action.target_index = game_party.actors.index(tag) if tag
  119.       end
  120.     when 2 # 防御
  121.       @current_action.basic = 0
  122.       @current_action.basic = 1
  123.     end
  124.   end
  125. end
  126. class Scene_Battle
  127.   #--------------------------------------------------------------------------
  128.   # ● 转到输入下一个角色的命令
  129.   #--------------------------------------------------------------------------
  130.   def phase3_next_actor
  131.     # 循环
  132.     begin
  133.       # 角色的明灭效果 OFF
  134.       if @active_battler != nil
  135.         @active_battler.blink = false
  136.       end
  137.       # 最后的角色的情况
  138.       if @actor_index == $game_party.actors.size-1
  139.         # 开始主回合
  140.         start_phase4
  141.         return
  142.       end
  143.       # 推进角色索引
  144.       @actor_index += 1
  145.       @active_battler = $game_party.actors[@actor_index]
  146.       @active_battler.blink = true
  147.     # 如果角色是在无法接受指令的状态就再试
  148.   end until @active_battler.inputable?
  149.   # $
  150.     if Game_Actor::AI.include?(@active_battler.id)
  151.       #AI同伴
  152.       @actor_command_window.active = false
  153.       @actor_command_window.visible = false
  154.       @active_battler.make_action
  155.       phase3_next_actor
  156.     else
  157.       # 设置角色的命令窗口
  158.       phase3_setup_command_window
  159.     end
  160.   end
  161.   #--------------------------------------------------------------------------
  162.   # ● 转向前一个角色的命令输入
  163.   #--------------------------------------------------------------------------
  164.   def phase3_prior_actor
  165.     # 循环
  166.     begin
  167.       # 角色的明灭效果 OFF
  168.       if @active_battler != nil
  169.         @active_battler.blink = false
  170.       end
  171.       # 最初的角色的情况下
  172.       if @actor_index == 0
  173.         # 开始同伴指令回合
  174.         start_phase2
  175.         return
  176.       end
  177.       # 返回角色索引
  178.       @actor_index -= 1
  179.       @active_battler = $game_party.actors[@actor_index]
  180.       @active_battler.blink = true
  181.     # 如果角色是在无法接受指令的状态就再试
  182.     end until @active_battler.inputable?
  183.     # 设置角色的命令窗口
  184.     if Game_Actor::AI.include?(@active_battler.id)
  185.       #AI同伴
  186.       phase3_prior_actor
  187.     else
  188.       phase3_setup_command_window
  189.     end
  190.   end
  191. end
复制代码
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-19 22:51

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表