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

Project1

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

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

 关闭 [复制链接]
回帖奖励 90 星屑 回复本帖可获得 10 星屑奖励! 每人限 1 次

Lv3.寻梦者

梦石
0
星屑
4299
在线时间
407 小时
注册时间
2016-5-11
帖子
140
跳转到指定楼层
1
发表于 2020-7-10 11:48:29 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
游戏自动战斗中跳错了,如下图,有时候出,大部份情况都正常
[pre lang="ruby" file="队友自动化"]#==============================================================================
# ■ Game_Actor
#------------------------------------------------------------------------------
#  AI模块
#==============================================================================

class  Game_Battler
  attr_accessor :marks
end
class Game_Actor < Game_Battler
  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] # 需要自动攻击的角色编号

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

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

  EQ = 100 # 情商设定,90为标准值,EQ越高,越优先使用对应魔法(属性有效度为准),
  def make_action
   $game_troop.enemies.each{|i|i.marks=50}
    $game_party.actors.each{|i|i.marks=50}
    # 先确认动作
    index = Action_Index
    skills = self.battle_skill.inject([]){|a,b|a<<b if skill_can_use?(b);a}
    index[1] = 0 if skills == []
    index[0] *= IQ/90.0;index[1] *= IQ/90.0;index[1] *= EQ/90.0
  #  index[0].to_i;index[1].to_i
    all = index.inject(0){|a,b|a+b}.to_i
    value = rand(all)
    action = 0 # 默认攻击
    for i in 0...index.size
      if i > value
        action = i
        break
      else
        value -= index
      end
    end
  if self.sp <= self.maxsp/10
      action = 2
    end
    # 目前动作为 action
    case action
    when 0 # 攻击
      # 智商检查
      enemies = $game_troop.enemies.inject([]){|a,b|a<<b if !b.hp0?;a}
      # 评分
      enemies.sort!{|a,b|a.hp<=>b.hp}
      for i in 0...enemies.size
        enemies.marks += (Hp_Mark[0] + i*Hp_Mark[1])*IQ/90
      end
      # 防御检查
      enemies.sort!{|a,b|a.pdef<=>b.pdef}
      for i in 0...enemies.size
        enemies.marks += (Df_Mark[0] + i*Df_Mark[1])*IQ/90
      end
      # 确认目标
      value = rand(enemies.inject(0){|a,b|a+b.marks})
      tag = nil
      for i in enemies
        if i.marks > value
          tag = i
          break
        else
          value -= i.marks
        end
      end
      # 目标确认 tag
      @current_action.kind = 0
      @current_action.basic = 0
      d_target=0
      for enemy in $game_troop.enemies
        unless enemy.state?(1)
        d_target+=1
      end
      end
      return @current_action.target_index = rand(d_target) unless tag
      @current_action.target_index = $game_troop.enemies.index(tag)
    when 1 # 魔法
      # 魔法分类,对敌/对己(加持)/附着状态/解除状态
      @current_action.kind = 0
      return @current_action.basic = 1 if skills == []
      @current_action.kind = 1
      # 随机技能
      @current_action.skill_id = skills[rand(skills.size)]
      # 确认对象
      d_target=0
      scope = $data_skills[@current_action.skill_id].scope
      for enemy in $game_troop.enemies
        unless enemy.state?(1)
        d_target+=1
      end
      end
      @current_action.target_index = rand(d_target)
      case @scope
      when 1 # 敌单体
        # 智商检查
        enemies = $game_troop.enemies.inject([]){|a,b|a<<b if !b.hp0?;a}
        # 属性有效度评分
        table = [0,50,25,10,0,-10,-20]
        for i in 0...enemies.size
          enemies.marks += enemies.element_ranks[@current_action.skill_id]
        end
        # 确认目标
        value = rand(enemies.inject(0){|a,b|a+b.marks})
        tag = nil
        for i in enemies
         if i.marks > value
            tag = i
            break
          else
            value -= i.marks
          end
        end
        @current_action.target_index = $game_troop.enemies.index(tag) if tag
      when 3
        # 智商检查
        enemies = game_party.actors.inject([]){|a,b|a<<b if !b.hp0?;a}
        # 属性有效度评分
        table = [0,50,25,10,0,-10,-20]
        for i in 0...enemies.size
          enemies.marks += enemies.element_ranks[@current_action.skill_id]
        end
        # 确认目标
        value = rand(enemies.inject(0){|a,b|a+b.marks})
        tag = nil
        for i in enemies
         if i.marks > value
            tag = i
            break
          else
            value -= i.marks
          end
        end
        @current_action.target_index = game_party.actors.index(tag) if tag
      end
    when 2 # 防御
      @current_action.basic = 0
      @current_action.basic = 1
    end
  end
end
class Scene_Battle
  #--------------------------------------------------------------------------
  # ● 转到输入下一个角色的命令
  #--------------------------------------------------------------------------
  def phase3_next_actor
    # 循环
    begin
      # 角色的明灭效果 OFF
      if @active_battler != nil
        @active_battler.blink = false
      end
      # 最后的角色的情况
      if @actor_index == $game_party.actors.size-1
        # 开始主回合
        start_phase4
        return
      end
      # 推进角色索引
      @actor_index += 1
      @active_battler = $game_party.actors[@actor_index]
      @active_battler.blink = true
    # 如果角色是在无法接受指令的状态就再试
  end until @active_battler.inputable?
    unless @active_battler.state?(72)
  #AI同伴
     @actor_command_window.active = false
      @actor_command_window.visible = false
      @active_battler.make_action
      phase3_next_actor
    else  
     phase3_setup_command_window
    end
  end
  #--------------------------------------------------------------------------
  # ● 转向前一个角色的命令输入
  #--------------------------------------------------------------------------
  def phase3_prior_actor
    # 循环
    begin
      # 角色的明灭效果 OFF
      if @active_battler != nil
        @active_battler.blink = false
      end
      # 最初的角色的情况下
      if @actor_index == 0
        # 开始同伴指令回合
        start_phase2
        return
      end
      # 返回角色索引
      @actor_index -= 1
      @active_battler = $game_party.actors[@actor_index]
      @active_battler.blink = true
    # 如果角色是在无法接受指令的状态就再试
    end until @active_battler.inputable?
    # 设置角色的命令窗口
    unless @active_battler.state?(72)
      #AI同伴
      phase3_prior_actor
    else
      phase3_setup_command_window
    end
  end
end[/pre]

QQ图片20200710113727.png (349.54 KB, 下载次数: 5)

QQ图片20200710113727.png

Lv5.捕梦者

梦石
0
星屑
33143
在线时间
10485 小时
注册时间
2009-3-15
帖子
4756
2
发表于 2020-7-10 11:59:26 | 只看该作者

回帖奖励 +10 星屑

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

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-19 16:54

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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