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

Project1

 找回密码
 注册会员
搜索
查看: 3635|回复: 3

[RMVA发布] 主楼最新更新版——自己写的敌人AI

[复制链接]

Lv1.梦旅人

梦石
0
星屑
66
在线时间
140 小时
注册时间
2012-2-6
帖子
384
发表于 2012-2-7 14:56:38 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 杂兵天下 于 2012-2-18 10:39 编辑
  1. class Game_BaseItem
  2.   def stit(st)
  3.     @class=RPG::Skill
  4.     @item_id=st
  5.   end
  6. end
  7. class Game_Action
  8.   def evaluateforai(fault)#MAXBRAIN=100,MAXFAULT=100
  9.     @value = 0
  10.     evaluate_item_ai if valid?
  11.     @value += fault * rand * 0.01 if @value > 0
  12.     return @value
  13.   end
  14.   def evaluate_item_ai
  15.     item_target_candidates.each do |target|
  16.       value = evaluate_item_with_target_ai(target)
  17.       if item.for_all?
  18.         @value += value
  19.       elsif value > @value
  20.         @value = value
  21.         @target_index = target.index
  22.       end
  23.     end
  24.   end
  25.   def evaluate_item_with_target_ai(target)
  26.     target.result.clear
  27.     target.make_damage_value_ai(subject, item)
  28.     if item.for_opponent?
  29.       solve=target.result.hp_damage.to_f / [target.hp, 1].max
  30.     else
  31.       recovery = [-target.result.hp_damage, target.mhp - target.hp].min
  32.       solve=recovery.to_f / target.hp
  33.     end
  34.     sbef=solve
  35.     #记录之前的solve
  36.     solve=0 if ($data_enemies[subject.enemy_id].enemyblind>=100*rand) and (target.tgr<rand)
  37.     #对于blind不为0的敌人说,被攻击度可能是很重要的。
  38.     #不过被攻击度超过100(嘲讽)对于智能敌人是根本无用的。
  39.     t=target
  40.     u=subject
  41.     m=item
  42.     eval $data_enemies[subject.enemy_id].aievaline
  43.     return solve
  44.   end
  45.   def skl=(skl)
  46.     @item.stit(skl)
  47.   end
  48. end
  49. class Game_Battler
  50.   def make_damage_value_ai(user, item)
  51.     value = item.damage.eval(user, self, $game_variables)
  52.     value *= item_element_rate(user, item)
  53.     value *= pdr if item.physical?
  54.     value *= mdr if item.magical?
  55.     value *= rec if item.damage.recover?
  56.     value = apply_guard(value)
  57.     @result.make_damage(value.to_i, item)
  58.   end
  59. end
  60. class Scene_Battle
  61.   alias ea execute_action
  62.   def execute_action
  63.     $game_troop.aipart
  64.     ea
  65.   end
  66. end
  67. module RPG
  68.   class Enemy
  69.     def enemybrain
  70.       note.split(/[\r\n]+/).each { |line|
  71.         case line
  72.         when /<(?:BRAIN|brain):[ ](\d+)>/i
  73.           return $1.to_i
  74.         end
  75.       }
  76.       return 0
  77.     end
  78.     def enemyfault
  79.       note.split(/[\r\n]+/).each { |line|
  80.         case line
  81.         when /<(?:FAULT|fault):[ ](\d+)>/i
  82.           return $1.to_i
  83.         end
  84.       }
  85.       return 100
  86.     end
  87.     def enemyblind
  88.       note.split(/[\r\n]+/).each { |line|
  89.         case line
  90.         when /<(?:BLIND|blind):[ ](\d+)>/i
  91.           return $1.to_i
  92.         end
  93.       }
  94.       return 100
  95.     end
  96.     def aievaline
  97.       note.split(/[\r\n]+/).each { |line|
  98.         case line
  99.         when "<aieval>"
  100.           @aieval=true
  101.           @aieva=""
  102.         when "</aieval>"
  103.           @aieval=false
  104.           return @aieva
  105.         else
  106.           if @aieval==true
  107.             @aieva+=line
  108.             @aieva+="\n"
  109.           end
  110.         end
  111.       }
  112.       return ""
  113.     end
  114.   end
  115. end
  116. class Game_Enemy
  117.   def make_actions
  118.     super
  119.     return if @actions.empty?
  120.     action_list = enemy.actions.select {|a| action_valid?(a) }
  121.     return if action_list.empty?
  122.     rating_max = action_list.collect {|a| a.rating }.max
  123.     rating_zero = rating_max - 3
  124.     action_list.reject! {|a| a.rating <= rating_zero }
  125.     @actions.each do |action|
  126.       action.set_enemy_action(select_enemy_action(action_list, rating_zero))
  127.     end
  128.     @action_list=action_list
  129.   end
  130.   def aipart
  131.     if $data_enemies[@enemy_id].enemybrain>=100*rand
  132.       a=0
  133.       b=0
  134.       for k in @actions
  135.         for i in @action_list
  136.           j=i.skill_id#skill_id
  137.           k.skl=j
  138.           c=k.evaluateforai($data_enemies[@enemy_id].enemyfault)
  139.           if c>a
  140.             a=c
  141.             b=j
  142.           end
  143.           b=j if (c==a and rand>0.5)
  144.         end
  145.       k.skl=b
  146.       k.evaluateforai($data_enemies[@enemy_id].enemyfault)
  147.       end
  148.     end
  149.   end
  150. end
  151. class Game_Troop < Game_Unit
  152.   def aipart
  153.     members.each {|member| member.aipart }
  154.   end
  155. end
复制代码
这样大概可以了吧。。。
不会出现突然行动一个特别的技能

点评

本人是脚本盲OTZ  发表于 2012-2-7 16:01

Lv1.梦旅人

海原大樹

梦石
0
星屑
205
在线时间
966 小时
注册时间
2011-12-17
帖子
720
发表于 2012-2-7 15:09:32 | 显示全部楼层
漏洞百出还发布0w0(此贴为LZ卖萌无误{:nm_6:})

点评

我卖什么萌。。。。。。 另:这脚本真的漏洞百出,你想 会有100行不到的AI么?  发表于 2012-2-7 15:54

点击有惊喜什么的...
回复 支持 反对

使用道具 举报

Lv6.析梦学徒

Fuzzy Ginkgo
Taciturn Knight

梦石
0
星屑
59775
在线时间
1933 小时
注册时间
2010-6-26
帖子
1605

烫烫烫开拓者

发表于 2012-2-8 00:23:49 | 显示全部楼层
脚本莫非和yea battleengine有关?

点评

$game_temp.evaluating = false if $imported["YEA-BattleEngine"] == true这个只是为了确保兼容性  发表于 2012-2-8 11:11
为什么你这样认为呢?  发表于 2012-2-8 11:11
我的言论只代表我个人的观点,不代表雇主及/或任何第三方的立场。
Opinions expressed are solely my own and do not express the views or opinions of my employer and/or any third parties.
捐赠 | GitHub
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
66
在线时间
140 小时
注册时间
2012-2-6
帖子
384
 楼主| 发表于 2012-2-8 11:46:28 | 显示全部楼层
额,经过一段时间的研究,我终于总结出了这个系统中我自己制作的标签
<aieval>与</aieval>的用法。在这个范例里面
签名是什么?可以吃么?
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-3-28 19:58

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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