查看: 3132|回复: 1

[推荐问答] 人物设定问题,求助。

[复制链接]
梦石
0
星屑
130
在线时间
178 小时
注册时间
2011-8-7
回帖
996
发表于 2012-8-29 21:36:29 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 1584927450 于 2012-8-30 11:42 编辑

废话少说了,
问题上:
       本人想设个电脑队员,求助啊~
       就是在你的队伍,自己攻击、使用技能、防御(随机攻击、使用技能、防御),并且不会使用物品、不会逃跑的队员。
       应该是脚本处理吧,求助啊,有人吗!求知者回复啊!!!

点评

AI程序吗,我喜欢....不过你没给数据...全随机...??  发表于 2012-8-30 01:10
梦石
0
星屑
55
在线时间
323 小时
注册时间
2010-8-21
回帖
638
发表于 2012-8-30 03:25:17 | 显示全部楼层
本帖最后由 沙漠点灰 于 2012-8-30 03:26 编辑

写出来了,希望多给点经验,好人卡,因为虽然只有100来行,但是debug耗时很久....
这个脚本在默认战斗系统可用,有改动的话......

下面这个是设定,全是"优先",仅仅是概率大些,应该看得懂吧。擦...3点了,写这个花了我3个小时,{:2_258:} ,希望满意

  AI = [2] # 需要自动攻击的角色编号,多的用[]括着...
  
           # 物理攻击倾向指数 魔法攻击倾向指数 防御指数
  Action_Index = [50,  60, 20]
  
  IQ = 80 # 智商设定,90为标准值,IQ越高,越优先攻击生命值少,防御力小的
  Hp_Mark = [30,-10] # 生命值评分标准,[生命值最低的得分,步进值(负)]
  Df_Mark = [20,-10] # 防御值评分标准,[防御值最低的得分,步进值(负)]
  
  EQ = 80 # 情商设定,90为标准值,EQ越高,越优先使用对应魔法(属性有效度为准),


[pre lang="ruby" line="1"]#==============================================================================
# ■ Game_Actor
#------------------------------------------------------------------------------
#  AI模块
#==============================================================================

class  Game_Battler
  attr_accessor :marks
end
class Game_Actor < Game_Battler
  AI = [2] # 需要自动攻击的角色编号
  
           # 物理攻击倾向指数 魔法攻击倾向指数 防御指数 什么都不做指数
  Action_Index = [50,  60, 20]
  
  IQ = 80 # 智商设定,90为标准值,IQ越高,越优先攻击生命值少,防御力小的
  Hp_Mark = [30,-10] # 生命值评分标准,[生命值最低的得分,步进值(负)]
  Df_Mark = [20,-10] # 防御值评分标准,[防御值最低的得分,步进值(负)]
  
  EQ = 80 # 情商设定,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.skills.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
    # 目前动作为 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
      return @current_action.target_index = 0 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)]
      # 确认对象
      scope = $data_skills[@current_action.skill_id].scope
      @current_action.target_index = 0
      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?
  # $$$$$$$$$$$$$$
    if Game_Actor::AI.include?(@active_battler.id)
      #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?
    # 设置角色的命令窗口
    if Game_Actor::AI.include?(@active_battler.id)
      #AI同伴
      phase3_prior_actor
    else
      phase3_setup_command_window
    end
  end
end[/pre]���

点评

按照你的要求,追加了100EXP,现在论坛得经验难啊!只能追加这么多了,我会了接近两年才有这么点经验啊!  发表于 2012-8-30 11:43
一张好人卡来之不易啊,论坛现在都不提供好人卡了%>_<%  发表于 2012-8-30 11:41
还真给力,这么快就来了个脚本,我还以为要花几天时间等呢  发表于 2012-8-30 11:34

评分

参与人数 3星屑 +146 梦石 +2 收起 理由
yagami + 14 精品文章
hcm + 2 认可答案
Wind2010 + 132 给个糖w

查看全部评分

>>猛戳>>MetalSagaR游戏主页<<这里<<
欢迎提供您的意见
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部