查看: 2831|回复: 8

[已经过期] 脚本挑错求大佬相助

  [复制链接]
奖 90 星屑 回复本帖可获得 10 星屑奖励! 每人限 1 次
梦石
0
星屑
4486
在线时间
419 小时
注册时间
2016-5-11
回帖
127
发表于 2020-7-10 11:48:29 | 显示全部楼层 |阅读模式

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

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

×
游戏自动战斗中跳错了,如下图,有时候出,大部份情况都正常
  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 = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36] # 需要自动攻击的角色编号

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

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

  16.   EQ = 100 # 情商设定,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.battle_skill.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.   if self.sp <= self.maxsp/10
  38.       action = 2
  39.     end
  40.     # 目前动作为 action
  41.     case action
  42.     when 0 # 攻击
  43.       # 智商检查
  44.       enemies = $game_troop.enemies.inject([]){|a,b|a<<b if !b.hp0?;a}
  45.       # 评分
  46.       enemies.sort!{|a,b|a.hp<=>b.hp}
  47.       for i in 0...enemies.size
  48.         enemies[i].marks += (Hp_Mark[0] + i*Hp_Mark[1])*IQ/90
  49.       end
  50.       # 防御检查
  51.       enemies.sort!{|a,b|a.pdef<=>b.pdef}
  52.       for i in 0...enemies.size
  53.         enemies[i].marks += (Df_Mark[0] + i*Df_Mark[1])*IQ/90
  54.       end
  55.       # 确认目标
  56.       value = rand(enemies.inject(0){|a,b|a+b.marks})
  57.       tag = nil
  58.       for i in enemies
  59.         if i.marks > value
  60.           tag = i
  61.           break
  62.         else
  63.           value -= i.marks
  64.         end
  65.       end
  66.       # 目标确认 tag
  67.       @current_action.kind = 0
  68.       @current_action.basic = 0
  69.       d_target=0
  70.       for enemy in $game_troop.enemies
  71.         unless enemy.state?(1)
  72.         d_target+=1
  73.       end
  74.       end
  75.       return @current_action.target_index = rand(d_target) unless tag
  76.       @current_action.target_index = $game_troop.enemies.index(tag)
  77.     when 1 # 魔法
  78.       # 魔法分类,对敌/对己(加持)/附着状态/解除状态
  79.       @current_action.kind = 0
  80.       return @current_action.basic = 1 if skills == []
  81.       @current_action.kind = 1
  82.       # 随机技能
  83.       @current_action.skill_id = skills[rand(skills.size)]
  84.       # 确认对象
  85.       d_target=0
  86.       scope = $data_skills[@current_action.skill_id].scope
  87.       for enemy in $game_troop.enemies
  88.         unless enemy.state?(1)
  89.         d_target+=1
  90.       end
  91.       end
  92.       @current_action.target_index = rand(d_target)
  93.       case @scope
  94.       when 1 # 敌单体
  95.         # 智商检查
  96.         enemies = $game_troop.enemies.inject([]){|a,b|a<<b if !b.hp0?;a}
  97.         # 属性有效度评分
  98.         table = [0,50,25,10,0,-10,-20]
  99.         for i in 0...enemies.size
  100.           enemies[i].marks += enemies[i].element_ranks[@current_action.skill_id]
  101.         end
  102.         # 确认目标
  103.         value = rand(enemies.inject(0){|a,b|a+b.marks})
  104.         tag = nil
  105.         for i in enemies
  106.          if i.marks > value
  107.             tag = i
  108.             break
  109.           else
  110.             value -= i.marks
  111.           end
  112.         end
  113.         @current_action.target_index = $game_troop.enemies.index(tag) if tag
  114.       when 3
  115.         # 智商检查
  116.         enemies = game_party.actors.inject([]){|a,b|a<<b if !b.hp0?;a}
  117.         # 属性有效度评分
  118.         table = [0,50,25,10,0,-10,-20]
  119.         for i in 0...enemies.size
  120.           enemies[i].marks += enemies[i].element_ranks[@current_action.skill_id]
  121.         end
  122.         # 确认目标
  123.         value = rand(enemies.inject(0){|a,b|a+b.marks})
  124.         tag = nil
  125.         for i in enemies
  126.          if i.marks > value
  127.             tag = i
  128.             break
  129.           else
  130.             value -= i.marks
  131.           end
  132.         end
  133.         @current_action.target_index = game_party.actors.index(tag) if tag
  134.       end
  135.     when 2 # 防御
  136.       @current_action.basic = 0
  137.       @current_action.basic = 1
  138.     end
  139.   end
  140. end
  141. class Scene_Battle
  142.   #--------------------------------------------------------------------------
  143.   # ● 转到输入下一个角色的命令
  144.   #--------------------------------------------------------------------------
  145.   def phase3_next_actor
  146.     # 循环
  147.     begin
  148.       # 角色的明灭效果 OFF
  149.       if @active_battler != nil
  150.         @active_battler.blink = false
  151.       end
  152.       # 最后的角色的情况
  153.       if @actor_index == $game_party.actors.size-1
  154.         # 开始主回合
  155.         start_phase4
  156.         return
  157.       end
  158.       # 推进角色索引
  159.       @actor_index += 1
  160.       @active_battler = $game_party.actors[@actor_index]
  161.       @active_battler.blink = true
  162.     # 如果角色是在无法接受指令的状态就再试
  163.   end until @active_battler.inputable?
  164.     unless @active_battler.state?(72)
  165.   #AI同伴
  166.      @actor_command_window.active = false
  167.       @actor_command_window.visible = false
  168.       @active_battler.make_action
  169.       phase3_next_actor
  170.     else  
  171.      phase3_setup_command_window
  172.     end
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # ● 转向前一个角色的命令输入
  176.   #--------------------------------------------------------------------------
  177.   def phase3_prior_actor
  178.     # 循环
  179.     begin
  180.       # 角色的明灭效果 OFF
  181.       if @active_battler != nil
  182.         @active_battler.blink = false
  183.       end
  184.       # 最初的角色的情况下
  185.       if @actor_index == 0
  186.         # 开始同伴指令回合
  187.         start_phase2
  188.         return
  189.       end
  190.       # 返回角色索引
  191.       @actor_index -= 1
  192.       @active_battler = $game_party.actors[@actor_index]
  193.       @active_battler.blink = true
  194.     # 如果角色是在无法接受指令的状态就再试
  195.     end until @active_battler.inputable?
  196.     # 设置角色的命令窗口
  197.     unless @active_battler.state?(72)
  198.       #AI同伴
  199.       phase3_prior_actor
  200.     else
  201.       phase3_setup_command_window
  202.     end
  203.   end
  204. end
复制代码
QQ图片20200710113727.png
梦石
0
星屑
39336
在线时间
11161 小时
注册时间
2009-3-15
回帖
4768
发表于 2020-7-10 11:59:26 | 显示全部楼层

回帖奖励 +10 星屑

  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 = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36] # 需要自动攻击的角色编号

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

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

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

点评

┭┮﹏┭┮  发表于 2020-7-10 13:41
不对..i算了..看不懂...  发表于 2020-7-10 12:49
咳咳..这样吧..28行改成index[0] *= IQ/90;index[1] *= IQ/90;index[1] *= EQ/90  发表于 2020-7-10 12:48
不对呢..这样好像不行..  发表于 2020-7-10 12:45
29行  发表于 2020-7-10 12:40
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部