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

Project1

 找回密码
 注册会员
搜索
楼主: 风雪优游
打印 上一主题 下一主题

自动战斗·同伴的AI

 关闭 [复制链接]

Lv1.梦旅人

v

梦石
0
星屑
50
在线时间
55 小时
注册时间
2007-12-19
帖子
99
1
发表于 2007-12-31 16:10:55 | 显示全部楼层
RMVX的自动战斗是有AI的,不是XP那种随机行动
大概就是评估每个行动(普通攻击、每种特技对每个可能的目标等等)的价值,然后取价值最大的作为最终行动。
详见:
Game_Actor 670行
  #--------------------------------------------------------------------------
  # ● 戦闘行動の作成 (自動戦闘用)
  #--------------------------------------------------------------------------
  def make_action
    @action.clear
    return unless movable?
    action_list = []
    action = Game_BattleAction.new(self)
    action.set_attack
    action.evaluate
    action_list.push(action)
    for skill in skills
      action = Game_BattleAction.new(self)
      action.set_skill(skill.id)
      action.evaluate
      action_list.push(action)
    end
    max_value = 0
    for action in action_list
      if action.value > max_value
        @action = action
        max_value = action.value
      end
    end
  end

Game_BattleAction 288行
  #--------------------------------------------------------------------------
  # ● 行動の価値評価 (自動戦闘用)
  #    @value および @target_index を自動的に設定する。
  #--------------------------------------------------------------------------
  def evaluate
    if attack?
      evaluate_attack
    elsif skill?
      evaluate_skill
    else
      @value = 0
    end
    if @value > 0
      @value + rand(nil)
    end
  end
  #--------------------------------------------------------------------------
  # ● 通常攻撃の評価
  #--------------------------------------------------------------------------
  def evaluate_attack
    @value = 0
    for target in opponents_unit.existing_members
      value = evaluate_attack_with_target(target)
      if value > @value
        @value = value
        @target_index = target.index
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 通常攻撃の評価 (ターゲット指定)
  #     target : 対象バトラー
  #--------------------------------------------------------------------------
  def evaluate_attack_with_target(target)
    target.clear_action_results
    target.make_attack_damage_value(battler)
    return target.hp_damage.to_f / [target.hp, 1].max
  end
  #--------------------------------------------------------------------------
  # ● スキルの評価
  #--------------------------------------------------------------------------
  def evaluate_skill
    @value = 0
    unless battler.skill_can_use?(skill)
      return
    end
    if skill.for_opponent?
      targets = opponents_unit.existing_members
    elsif skill.for_user?
      targets = [battler]
    elsif skill.for_dead_friend?
      targets = friends_unit.dead_members
    else
      targets = friends_unit.existing_members
    end
    for target in targets
      value = evaluate_skill_with_target(target)
      if skill.for_all?
        @value += value
      elsif value > @value
        @value = value
        @target_index = target.index
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● スキルの評価 (ターゲット指定)
  #     target : 対象バトラー
  #--------------------------------------------------------------------------
  def evaluate_skill_with_target(target)
    target.clear_action_results
    target.make_obj_damage_value(battler, skill)
    if skill.for_opponent?
      return target.hp_damage.to_f / [target.hp, 1].max
    else
      recovery = [-target.hp_damage, target.maxhp - target.hp].min
      return recovery.to_f / target.maxhp
    end
  end

没实测过,不过八九不离十了吧{/gg}
回复 支持 反对

使用道具 举报

Lv1.梦旅人

v

梦石
0
星屑
50
在线时间
55 小时
注册时间
2007-12-19
帖子
99
2
发表于 2007-12-31 16:18:43 | 显示全部楼层
特别的是自动行动角色不会用物品..估计杂兵战用了某个珍贵药品的话会被主角打死吧
另外那句rand(nil)很强大..
回复 支持 反对

使用道具 举报

Lv1.梦旅人

v

梦石
0
星屑
50
在线时间
55 小时
注册时间
2007-12-19
帖子
99
3
发表于 2007-12-31 21:02:47 | 显示全部楼层
嗯,的确这种回合制战斗的AI也是比较好设计的
回复 支持 反对

使用道具 举报

Lv1.梦旅人

v

梦石
0
星屑
50
在线时间
55 小时
注册时间
2007-12-19
帖子
99
4
发表于 2008-1-13 08:56:31 | 显示全部楼层
还能要求VX怎样..每个人的游戏都不同,用模拟伤害的方法已经是最大限度地实现自动战斗了,剩下的只能根据每个游戏的特定情况自己写了
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-13 15:10

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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