Project1
标题:
主楼最新更新版——自己写的敌人AI
[打印本页]
作者:
杂兵天下
时间:
2012-2-7 14:56
标题:
主楼最新更新版——自己写的敌人AI
本帖最后由 杂兵天下 于 2012-2-18 10:39 编辑
class Game_BaseItem
def stit(st)
@class=RPG::Skill
@item_id=st
end
end
class Game_Action
def evaluateforai(fault)#MAXBRAIN=100,MAXFAULT=100
@value = 0
evaluate_item_ai if valid?
@value += fault * rand * 0.01 if @value > 0
return @value
end
def evaluate_item_ai
item_target_candidates.each do |target|
value = evaluate_item_with_target_ai(target)
if item.for_all?
@value += value
elsif value > @value
@value = value
@target_index = target.index
end
end
end
def evaluate_item_with_target_ai(target)
target.result.clear
target.make_damage_value_ai(subject, item)
if item.for_opponent?
solve=target.result.hp_damage.to_f / [target.hp, 1].max
else
recovery = [-target.result.hp_damage, target.mhp - target.hp].min
solve=recovery.to_f / target.hp
end
sbef=solve
#记录之前的solve
solve=0 if ($data_enemies[subject.enemy_id].enemyblind>=100*rand) and (target.tgr<rand)
#对于blind不为0的敌人说,被攻击度可能是很重要的。
#不过被攻击度超过100(嘲讽)对于智能敌人是根本无用的。
t=target
u=subject
m=item
eval $data_enemies[subject.enemy_id].aievaline
return solve
end
def skl=(skl)
@item.stit(skl)
end
end
class Game_Battler
def make_damage_value_ai(user, item)
value = item.damage.eval(user, self, $game_variables)
value *= item_element_rate(user, item)
value *= pdr if item.physical?
value *= mdr if item.magical?
value *= rec if item.damage.recover?
value = apply_guard(value)
@result.make_damage(value.to_i, item)
end
end
class Scene_Battle
alias ea execute_action
def execute_action
$game_troop.aipart
ea
end
end
module RPG
class Enemy
def enemybrain
note.split(/[\r\n]+/).each { |line|
case line
when /<(?:BRAIN|brain):[ ](\d+)>/i
return $1.to_i
end
}
return 0
end
def enemyfault
note.split(/[\r\n]+/).each { |line|
case line
when /<(?:FAULT|fault):[ ](\d+)>/i
return $1.to_i
end
}
return 100
end
def enemyblind
note.split(/[\r\n]+/).each { |line|
case line
when /<(?:BLIND|blind):[ ](\d+)>/i
return $1.to_i
end
}
return 100
end
def aievaline
note.split(/[\r\n]+/).each { |line|
case line
when "<aieval>"
@aieval=true
@aieva=""
when "</aieval>"
@aieval=false
return @aieva
else
if @aieval==true
@aieva+=line
@aieva+="\n"
end
end
}
return ""
end
end
end
class Game_Enemy
def make_actions
super
return if @actions.empty?
action_list = enemy.actions.select {|a| action_valid?(a) }
return if action_list.empty?
rating_max = action_list.collect {|a| a.rating }.max
rating_zero = rating_max - 3
action_list.reject! {|a| a.rating <= rating_zero }
@actions.each do |action|
action.set_enemy_action(select_enemy_action(action_list, rating_zero))
end
@action_list=action_list
end
def aipart
if $data_enemies[@enemy_id].enemybrain>=100*rand
a=0
b=0
for k in @actions
for i in @action_list
j=i.skill_id#skill_id
k.skl=j
c=k.evaluateforai($data_enemies[@enemy_id].enemyfault)
if c>a
a=c
b=j
end
b=j if (c==a and rand>0.5)
end
k.skl=b
k.evaluateforai($data_enemies[@enemy_id].enemyfault)
end
end
end
end
class Game_Troop < Game_Unit
def aipart
members.each {|member| member.aipart }
end
end
复制代码
这样大概可以了吧。。。
不会出现突然行动一个特别的技能
作者:
小镜子
时间:
2012-2-7 15:09
漏洞百出还发布0w0(
此贴为LZ卖萌无误
{:nm_6:})
作者:
orzfly
时间:
2012-2-8 00:23
脚本莫非和yea battleengine有关?
作者:
杂兵天下
时间:
2012-2-8 11:46
额,经过一段时间的研究,我终于总结出了这个系统中我自己制作的标签
<aieval>与</aieval>的用法。在这个
范例
里面
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1