- UID
- 280967
- 帖子
- 344
- 精华
- 0
- 威望
- 0
- 阅读权限
- 100
- 注册时间
- 2005-4-22
|
等斑竹或是某人帮我把4个AI文件传上来
注意下载后,放到自己的RO目录的AI目录的USER_AI目录,注意备份。
打开config.lua.只要能打开文本文件的程序都能打开,根据自己的喜好去改。
你想有M4陪你练级吗,你想生命体自动爆炸杀BOSS吗,你想避过一死吗,这个脚本将实现你的愿望。
PS:因为我没传文件的权限,我把4个文件的文件内容贴出来,自行生成文件
config.lua
--------------------------------------------------------------------------------
-- 生命体本质 ( 0 = 辅助型 ; 1 = 助攻型 ; 2 = 被动型 ; 3 = 主动型 ; 4 = PK型 )
--------------------------------------------------------------------------------
HOMUN_KIND = 4
--[[
辅助型 : 绝对不会打敌人
助攻型 : 帮主人打敌人
被动型 : 包含助攻型,被敌人打就反击
主动型 : 包含被动型,主动打怪
杀神型 : 包含主动型,连玩家都打
--]]
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 生命体视距
--------------------------------------------------------------------------------
HOMUN_SIGHT = 15
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 和主人距离
--------------------------------------------------------------------------------
DIST_OWNER_MIN = 2 -- 大于会跟随
DIST_OWNER_MAX = 6 -- 大于会回归
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 生命体HP百分比
--------------------------------------------------------------------------------
HOMUN_HP_LOW = 60 -- 小于会逃跑
HOMUN_HP_HIGH = 75 -- 小于不出击
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 逃跑方式 ( 0 = 乱跑 ; 1 = 八卦 )
--------------------------------------------------------------------------------
ESCAPE_WAY = 1
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 技能使用机率 ( 0 = 不使用 ; 100 = 永远使用 ; 1 ~ 99 = 自订机率 )
--------------------------------------------------------------------------------
-- 丽芙
LIF_HEAL_PROB = 0 -- 治愈之手 (实装)
LIF_AVOID_PROB = 0 -- 轻捷移动
-- 进化丽芙
LIF_CHANGE_PROB = 0 -- 智力变换
-- 艾咪斯可鲁
AMI_CASTLE_PROB = 0 -- 位置互换
AMI_DEFENSE_PROB = 0 -- 防御力
-- 进化艾咪斯可鲁
AMI_BLOODLUST_PROB = 0 -- 血的贪求
-- 飞里乐
FLI_MOON_PROB = 0 -- 月光 (实装)
FLI_FLEET_PROB = 0 -- 横越速度 (实装)
FLI_SPEED_PROB = 0 -- 紧急回避
-- 进化飞里乐
FLI_SBR44_PROB = 0 -- S.B.R.44
-- 巴尼米乐斯
VAN_CAPRICE_PROB = 0 -- 善变 (实装)
VAN_PRAY_OWNER_PROB = 0 -- 混乱的祈福 ( 主人 )
VAN_PRAY_HOMUN_PROB = 0 -- 混乱的祈福 ( 生命体 )
-- 进化巴尼米乐斯
VAN_EXPLOSION_PROB = 0 -- 生物爆炸
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 技能使用等级 ( 0 = 不使用 ; 1 ~ 5 = 自订等级 )
--------------------------------------------------------------------------------
-- 丽芙
LIF_HEAL_LEVEL = 0 -- 治愈之手
LIF_AVOID_LEVEL = 0 -- 轻捷移动
-- 进化丽芙
LIF_CHANGE_LEVEL = 0 -- 智力变换
-- 艾咪斯可鲁
AMI_CASTLE_LEVEL = 0 -- 位置互换
AMI_DEFENSE_LEVEL = 0 -- 防御力
-- 进化艾咪斯可鲁
AMI_BLOODLUST_LEVEL = 0 -- 血的贪求
-- 飞里乐
FLI_MOON_LEVEL = 0 -- 月光
FLI_FLEET_LEVEL = 0 -- 横越速度
FLI_SPEED_LEVEL = 0 -- 紧急回避
-- 进化飞里乐
FLI_SBR44_LEVEL = 0 -- S.B.R.44
-- 巴尼米乐斯
VAN_CAPRICE_LEVEL = 0 -- 善变
VAN_PRAY_OWNER_LEVEL = 0 -- 混乱的祈福 ( 主人 )
VAN_PRAY_HOMUN_LEVEL = 0 -- 混乱的祈福 ( 生命体 )
-- 进化巴尼米乐斯
VAN_EXPLOSION_LEVEL = 0 -- 生物爆炸
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 技能使用最少SP值 ( 注意 : 并非百分比 )
--------------------------------------------------------------------------------
-- 丽芙
LIF_HEAL_SP = 0 -- 治愈之手
LIF_AVOID_SP = 0 -- 轻捷移动
-- 进化丽芙
LIF_CHANGE_SP = 0 -- 智力变换
-- 艾咪斯可鲁
AMI_CASTLE_SP = 0 -- 位置互换
AMI_DEFENSE_SP = 0 -- 防御力
-- 进化艾咪斯可鲁
AMI_BLOODLUST_SP = 0 -- 血的贪求
-- 飞里乐
FLI_MOON_SP = 0 -- 月光
FLI_FLEET_SP = 0 -- 横越速度
FLI_SPEED_SP = 0 -- 紧急回避
-- 进化飞里乐
FLI_SBR44_SP = 0 -- S.B.R.44
-- 巴尼米乐斯
VAN_CAPRICE_SP = 0 -- 善变
VAN_PRAY_OWNER_SP = 0 -- 混乱的祈福 ( 主人 )
VAN_PRAY_HOMUN_SP = 0 -- 混乱的祈福 ( 生命体 )
-- 进化巴尼米乐斯
VAN_EXPLOSION_SP = 0 -- 生物爆炸
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 技能使用间隔 ( 0 = 无限制 ; 1 ~ = 自订秒数 )
--------------------------------------------------------------------------------
-- 丽芙
LIF_HEAL_DELAY = 0 -- 治愈之手
LIF_AVOID_DELAY = 0 -- 轻捷移动
-- 进化丽芙
LIF_CHANGE_DELAY = 0 -- 智力变换
-- 艾咪斯可鲁
AMI_CASTLE_DELAY = 0 -- 位置互换
AMI_DEFENSE_DELAY = 0 -- 防御力
-- 进化艾咪斯可鲁
AMI_BLOODLUST_DELAY = 0 -- 血的贪求
-- 飞里乐
FLI_MOON_DELAY = 0 -- 月光
FLI_FLEET_DELAY = 0 -- 横越速度
FLI_SPEED_DELAY = 0 -- 紧急回避
-- 进化飞里乐
FLI_SBR44_DELAY = 0 -- S.B.R.44
-- 巴尼米乐斯
VAN_CAPRICE_DELAY = 0 -- 善变
VAN_PRAY_OWNER_DELAY = 0 -- 混乱的祈福 ( 主人 )
VAN_PRAY_HOMUN_DELAY = 0 -- 混乱的祈福 ( 生命体 )
-- 进化巴尼米乐斯
VAN_EXPLOSION_DELAY = 0 -- 生物爆炸
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 技能启动限制
--------------------------------------------------------------------------------
LIMIT_OWNER_HP_LOW = 60 -- 小于主人HP百分比 ( 治愈之手 , 位置互换 , 混乱的祈福 )
LIMIT_HOMUN_HP_LOW = 60 -- 小于生命体HP百分比 ( 混乱的祈福 )
LIMIT_HOMUN_HP_HIGH = 75 -- 大于生命体HP百分比 ( 位置互换 )
--------------------------------------------------------------------------------
AI.lua
require "./AI/USER_AI/Const.lua"
require "./AI/USER_AI/Config.lua"
require "./AI/USER_AI/Util.lua"
--------------------------------------------------------------------------------
-- 状态
--------------------------------------------------------------------------------
IDLE_ST = 0 -- 休息
FOLLOW_ST = 1 -- 跟随
CHASE_ST = 2 -- 追击
ATTACK_ST = 3 -- 攻击
ATTACK_SKILL_ST = 4 -- 技能攻击
RETURN_ST = 5 -- 回归
ESCAPE_ST = 6 -- 逃跑
MOVE_CMD_ST = 10 -- 移动指令
STOP_CMD_ST = 11 -- 停止指令
ATTACK_OBJECT_CMD_ST = 12 -- 攻击指令
ATTACK_AREA_CMD_ST = 13 -- 区域攻击指令
PATROL_CMD_ST = 14 -- 巡逻指令
HOLD_CMD_ST = 15 -- 死守指令
SKILL_OBJECT_CMD_ST = 16 -- 技能指令
SKILL_AREA_CMD_ST = 17 -- 区域技能指令
FOLLOW_CMD_ST = 18 -- 跟随指令
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 整体变数
--------------------------------------------------------------------------------
MyKind = HOMUN_KIND -- 本质
MyState = FOLLOW_ST -- 状态
HomunType = 0 -- 生命体种类
OwnerID = 0 -- 主人ID
MyID = 0 -- 生命体ID
MyEnemy = 0 -- 敌人ID
AllActors = {} -- 所有ID集合
DestX = 0 -- 目的座标x
DestY = 0 -- 目的座标y
PatrolX = 0 -- 巡逻座标x
PatrolY = 0 -- 巡逻座标y
ResCmdList = List.new() -- 指令清单
MySkill = 0 -- 生命体技能
MySkillLevel = 0 -- 生命体技能等级
EscapeAngle = 22.5 -- 逃跑角度
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 技能使用间隔计数器
--------------------------------------------------------------------------------
-- 丽芙
LIF_HEAL_TIMER = 0 -- 治愈之手
LIF_AVOID_TIMER = 0 -- 轻捷移动
-- 进化丽芙
LIF_CHANGE_TIMER = 0 -- 智力变换
-- 艾咪斯可鲁
AMI_CASTLE_TIMER = 0 -- 位置互换
AMI_DEFENSE_TIMER = 0 -- 防御力
-- 进化艾咪斯可鲁
AMI_BLOODLUST_TIMER = 0 -- 血的贪求
-- 飞里乐
FLI_MOON_TIMER = 0 -- 月光
FLI_FLEET_TIMER = 0 -- 横越速度
FLI_SPEED_TIMER = 0 -- 紧急回避
-- 进化飞里乐
FLI_SBR44_TIMER = 0 -- S.B.R.44
-- 巴尼米乐斯
VAN_CAPRICE_TIMER = 0 -- 善变
VAN_PRAY_OWNER_TIMER = 0 -- 混乱的祈福 ( 主人 )
VAN_PRAY_HOMUN_TIMER = 0 -- 混乱的祈福 ( 生命体 )
-- 进化巴尼米乐斯
VAN_EXPLOSION_TIMER = 0 -- 生物爆炸
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 主程式
--------------------------------------------------------------------------------
function AI(myid)
local msg
local rmsg
local hp_percent
local actors
local x,y
local x1,y1
local result
MyID = myid -- 生命体ID
HomunType = GetV (V_HOMUNTYPE,MyID) -- 生命体种类
OwnerID = GetV (V_OWNER,MyID) -- 主人ID
AllActors = GetActors() -- 所有ID集合
msg = GetMsg (MyID) -- 指令
rmsg = GetResMsg (MyID) -- 预订指令
if msg[1] == NONE_CMD then
if rmsg[1] ~= NONE_CMD then
if List.size(ResCmdList) < 10 then
List.pushright (ResCmdList,rmsg) -- 储存预订指令
end
end
else
List.clear (ResCmdList) -- 清除预订指令
ProcessCommand (msg) -- 处理指令
end
hp_percent = Get_HP_Percent(MyID)
if (hp_percent < HOMUN_HP_LOW) then
actors = GetActors ()
result = 0
for i,v in ipairs(actors) do
if (v ~= OwnerID and v ~= MyID) then
if (GetV(V_TARGET,v) == MyID) then
result = 1
break
end
end
end
if (result == 1) then
if (MyState ~= ESCAPE_ST) then
MyState = ESCAPE_ST
x,y = GetV(V_POSITION,OwnerID)
if (ESCAPE_WAY == 0) then
math.randomseed(GetTick())
repeat
x1 = x + math.random(-DIST_OWNER_MAX,DIST_OWNER_MAX)
y1 = y + math.random(-DIST_OWNER_MAX,DIST_OWNER_MAX)
until Get_Distance_IDxy(OwnerID,x1,y1) <= DIST_OWNER_MAX
DestX,DestY = x1,y1
elseif (ESCAPE_WAY == 1) then
x1 = math.floor(math.cos(math.rad(EscapeAngle)) * DIST_OWNER_MAX + 0.5)
y1 = math.floor(math.sin(math.rad(EscapeAngle)) * DIST_OWNER_MAX + 0.5)
DestX = x + x1
DestY = y + y1
EscapeAngle = EscapeAngle + 45
if (EscapeAngle >= 360) then
EscapeAngle = EscapeAngle - 360
end
end
Move(MyID,DestX,DestY)
TraceAI (string.format("-> 逃跑 : HP百分比为%3.2f",hp_percent))
end
elseif (MyState == ESCAPE_ST) then
MyState = FOLLOW_ST
TraceAI ("逃跑 -> 跟随 : 敌人已消失")
end
end
-- 状态切换
if (MyState == IDLE_ST) then
OnIDLE_ST ()
elseif (MyState == FOLLOW_ST) then
OnFOLLOW_ST ()
elseif (MyState == CHASE_ST) then
OnCHASE_ST ()
elseif (MyState == ATTACK_ST) then
OnATTACK_ST ()
elseif (MyState == ATTACK_SKILL_ST) then
OnATTACK_SKILL_ST ()
elseif (MyState == RETURN_ST) then
OnRETURN_ST ()
elseif (MyState == ESCAPE_ST) then
OnESCAPE_ST ()
elseif (MyState == MOVE_CMD_ST) then
OnMOVE_CMD_ST ()
elseif (MyState == STOP_CMD_ST) then
OnSTOP_CMD_ST ()
elseif (MyState == ATTACK_OBJECT_CMD_ST) then
OnATTACK_OBJECT_CMD_ST ()
elseif (MyState == ATTACK_AREA_CMD_ST) then
OnATTACK_AREA_CMD_ST ()
elseif (MyState == PATROL_CMD_ST) then
OnPATROL_CMD_ST ()
elseif (MyState == HOLD_CMD_ST) then
OnHOLD_CMD_ST ()
elseif (MyState == SKILL_OBJECT_CMD_ST) then
OnSKILL_OBJECT_CMD_ST ()
elseif (MyState == SKILL_AREA_CMD_ST) then
OnSKILL_AREA_CMD_ST ()
elseif (MyState == FOLLOW_CMD_ST) then
OnFOLLOW_CMD_ST ()
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 指令处理
--------------------------------------------------------------------------------
function ProcessCommand (msg)
if (msg[1] == MOVE_CMD) then
OnMOVE_CMD (msg[2],msg[3])
elseif (msg[1] == STOP_CMD) then
OnSTOP_CMD ()
elseif (msg[1] == ATTACK_OBJECT_CMD) then
OnATTACK_OBJECT_CMD (msg[2])
elseif (msg[1] == ATTACK_AREA_CMD) then
OnATTACK_AREA_CMD (msg[2],msg[3])
elseif (msg[1] == PATROL_CMD) then
OnPATROL_CMD (msg[2],msg[3])
elseif (msg[1] == HOLD_CMD) then
OnHOLD_CMD ()
elseif (msg[1] == SKILL_OBJECT_CMD) then
OnSKILL_OBJECT_CMD (msg[2],msg[3],msg[4],msg[5])
elseif (msg[1] == SKILL_AREA_CMD) then
OnSKILL_AREA_CMD (msg[2],msg[3],msg[4],msg[5])
elseif (msg[1] == FOLLOW_CMD) then
OnFOLLOW_CMD ()
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 移动指令处理
--------------------------------------------------------------------------------
function OnMOVE_CMD (x,y)
TraceAI ("移动指令")
Move (MyID,x,y)
MyState = MOVE_CMD_ST
DestX = x
DestY = y
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 停止指令处理
--------------------------------------------------------------------------------
function OnSTOP_CMD ()
TraceAI ("停止指令")
if (GetV(V_MOTION,MyID) ~= MOTION_STAND) then
Move (MyID,GetV(V_POSITION,MyID))
end
MyState = IDLE_ST
DestX = 0
DestY = 0
MyEnemy = 0
MySkill = 0
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 攻击指令处理
--------------------------------------------------------------------------------
function OnATTACK_OBJECT_CMD (id)
TraceAI ("攻击指令")
MyEnemy = id
MyState = CHASE_ST
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 区域攻击指令处理
--------------------------------------------------------------------------------
function OnATTACK_AREA_CMD (x,y)
TraceAI ("区域攻击指令")
if (x ~= DestX or y ~= DestY or MOTION_MOVE ~= GetV(V_MOTION,MyID)) then
Move (MyID,x,y)
end
DestX = x
DestY = y
MyEnemy = 0
MyState = ATTACK_AREA_CMD_ST
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 巡逻指令处理
--------------------------------------------------------------------------------
function OnPATROL_CMD (x,y)
TraceAI ("巡逻指令")
PatrolX , PatrolY = GetV (V_POSITION,MyID)
DestX = x
DestY = y
Move (MyID,x,y)
MyState = PATROL_CMD_ST
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 死守指令处理
--------------------------------------------------------------------------------
function OnHOLD_CMD ()
TraceAI ("死守指令")
DestX = 0
DestY = 0
MyEnemy = 0
MyState = HOLD_CMD_ST
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 技能指令处理
--------------------------------------------------------------------------------
function OnSKILL_OBJECT_CMD (level,skill,id)
TraceAI ("技能指令")
MySkillLevel = level
MySkill = skill
MyEnemy = id
MyState = CHASE_ST
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 区域技能指令处理
--------------------------------------------------------------------------------
function OnSKILL_AREA_CMD (level,skill,x,y)
TraceAI ("区域技能指令")
Move (MyID,x,y)
DestX = x
DestY = y
MySkillLevel = level
MySkill = skill
MyState = SKILL_AREA_CMD_ST
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 跟随指令处理
--------------------------------------------------------------------------------
function OnFOLLOW_CMD ()
TraceAI ("跟随指令 : 变更生命体本质")
if (MyKind == 0) then
MyKind = HOMUN_KIND
else
MyKind = 0
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 状态处理
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 休息
--------------------------------------------------------------------------------
function OnIDLE_ST ()
TraceAI ("休息状态中")
local cmd = List.popleft(ResCmdList)
local timer
if (cmd ~= nil) then
ProcessCommand (cmd) -- 处理预订指令
return
end
if (HomunType == LIF or HomunType == LIF_H) then
if (LIF_HEAL_LEVEL > 0) then
if (Get_HP_Percent(OwnerID) < LIMIT_OWNER_HP_LOW) then
timer = GetTick() / 1000
if ((timer - LIF_HEAL_TIMER) > LIF_HEAL_DELAY) then
math.randomseed(GetTick())
if (math.random(0,99) < LIF_HEAL_PROB) then
sp = GetV(V_SP,MyID)
if (sp >= LIF_HEAL_COST[LIF_HEAL_LEVEL]) then
if (sp >= LIF_HEAL_SP) then
SkillObject(MyID,LIF_HEAL_LEVEL,LIF_HEAL,OwnerID)
LIF_HEAL_TIMER = timer
TraceAI ("使用技能 : 治愈之手")
end
end
end
end
end
end
end
Seek_Enemy ()
if (MyEnemy ~= 0) then
MyState = CHASE_ST
TraceAI ("休息 -> 追击")
return
end
if (Get_Distance_ID(MyID,OwnerID) > DIST_OWNER_MIN) then
MyState = FOLLOW_ST
TraceAI ("休息 -> 跟随")
return
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 跟随
--------------------------------------------------------------------------------
function OnFOLLOW_ST ()
TraceAI ("跟随状态中")
local x,y
x,y = GetV (V_POSITION,OwnerID)
if (Get_Distance_IDxy(MyID,x,y) <= DIST_OWNER_MIN) then
MyState = IDLE_ST
TraceAI ("跟随 -> 休息")
return
end
if (x ~= DestX or y ~= DestY) then
Move(MyID,x,y)
DestX,DestY = x,y
TraceAI ("跟随 -> 跟随 : 主人座标改变")
return
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 追击
--------------------------------------------------------------------------------
function OnCHASE_ST ()
TraceAI ("追击中")
local dis
local timer
local sp
local x,y
if (Get_Distance_ID(MyID,OwnerID) > DIST_OWNER_MAX) then
MyState = RETURN_ST
MyEnemy = 0
TraceAI ("追击 -> 回归 : 离主人太远")
return
end
dis = Get_Distance_ID(MyID,MyEnemy)
if (dis == -1) then
MyState = RETURN_ST
MyEnemy = 0
TraceAI ("追击 -> 回归 : 敌人已死")
return
end
if (dis > HOMUN_SIGHT) then
MyState = RETURN_ST
MyEnemy = 0
TraceAI ("追击 -> 回归 : 敌人超出视距")
return
end
x, y = GetV (V_POSITION,MyEnemy)
if (Get_Distance_IDxy(OwnerID,x,y) > DIST_OWNER_MAX) then
MyState = RETURN_ST
MyEnemy = 0
TraceAI ("追击 -> 回归 : 敌人离主人太远")
return
end
if (DestX ~= x or DestY ~= y) then
DestX, DestY = x,y
Move (MyID,DestX,DestY)
TraceAI ("追击 -> 追击 : 敌人座标改变")
return
end
if (HomunType == FILIR or HomunType == FILIR_H) then
if (FLI_FLEET_LEVEL > 0) then
timer = GetTick() / 1000
if ((timer - FLI_FLEET_TIMER) > FLI_FLEET_DELAY) then
math.randomseed(GetTick())
if (math.random(0,99) < FLI_FLEET_PROB) then
sp = GetV(V_SP,MyID)
if (sp >= FLI_FLEET_COST[FLI_FLEET_LEVEL]) then
if (sp >= FLI_FLEET_SP) then
SkillObject(MyID,FLI_FLEET_LEVEL,FLI_FLEET,MyID)
FLI_FLEET_TIMER = timer
TraceAI ("使用技能 : 横越速度")
end
end
end
end
end
if (FLI_MOON_LEVEL > 0) then
if (dis <= GetV (V_SKILLATTACKRANGE,MyID,FLI_MOON)) then
timer = GetTick() / 1000
if ((timer - FLI_MOON_TIMER) > FLI_MOON_DELAY) then
math.randomseed(GetTick())
if (math.random(0,99) < FLI_MOON_PROB) then
sp = GetV(V_SP,MyID)
if (sp >= FLI_MOON_COST[FLI_MOON_LEVEL]) then
if (sp >= FLI_MOON_SP) then
MyState = ATTACK_SKILL_ST
MySkill = FLI_MOON
MySkillLevel = FLI_MOON_LEVEL
FLI_MOON_TIMER = timer
TraceAI ("追击 -> 技能攻击 : 月光")
return
end
end
end
end
end
end
end
if (HomunType == VANILMIRTH or HomunType == VANILMIRTH_H) then
if (VAN_CAPRICE_LEVEL > 0) then
if (dis <= GetV (V_SKILLATTACKRANGE,MyID,VAN_CAPRICE)) then
timer = GetTick() / 1000
if ((timer - VAN_CAPRICE_TIMER) > VAN_CAPRICE_DELAY) then
math.randomseed(GetTick())
if (math.random(0,99) < VAN_CAPRICE_PROB) then
sp = GetV(V_SP,MyID)
if (sp >= VAN_CAPRICE_COST[VAN_CAPRICE_LEVEL]) then
if (sp >= VAN_CAPRICE_SP) then
MyState = ATTACK_SKILL_ST
MySkill = VAN_CAPRICE
MySkillLevel = VAN_CAPRICE_LEVEL
VAN_CAPRICE_TIMER = timer
TraceAI ("追击 -> 技能攻击 : 善变")
return
end
end
end
end
end
end
end
if (dis <= GetV (V_ATTACKRANGE,MyID)) then
MyState = ATTACK_ST
TraceAI ("追击 -> 攻击")
return
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 攻击
--------------------------------------------------------------------------------
function OnATTACK_ST ()
TraceAI ("攻击状态中")
Attack (MyID,MyEnemy)
MyState = CHASE_ST
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 技能攻击
--------------------------------------------------------------------------------
function OnATTACK_SKILL_ST ()
TraceAI ("技能攻击状态中")
SkillObject(MyID,MySkillLevel,MySkill,MyEnemy)
MyState = CHASE_ST
MySkill = 0
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 回归
--------------------------------------------------------------------------------
function OnRETURN_ST ()
TraceAI ("回归状态中")
local x,y
Seek_Enemy ()
if (MyEnemy ~= 0) then
MyState = CHASE_ST
TraceAI ("回归 -> 追击")
return
end
x,y = GetV(V_POSITION,OwnerID)
if (Get_Distance_IDxy(MyID,x,y) <= DIST_OWNER_MIN) then
MyState = IDLE_ST
TraceAI ("回归 -> 休息")
return
end
if (x ~= DestX or y ~= DestY) then
Move(MyID,x,y)
DestX,DestY = x,y
TraceAI ("回归 -> 回归 : 主人座标改变")
return
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 逃跑
--------------------------------------------------------------------------------
function OnESCAPE_ST ()
TraceAI ("逃跑状态中")
local hp_percent = Get_HP_Percent(MyID)
local x,y
local x1,y1
if (hp_percent >= HOMUN_HP_LOW) then
MyState = FOLLOW_ST
TraceAI ("逃跑 -> 回归")
return
end
x,y = GetV(V_POSITION,MyID)
if (x == DestX and y == DestY) then
x,y = GetV(V_POSITION,OwnerID)
if (ESCAPE_WAY == 0) then
math.randomseed(GetTick())
repeat
x1 = x + math.random(-DIST_OWNER_MAX,DIST_OWNER_MAX)
y1 = y + math.random(-DIST_OWNER_MAX,DIST_OWNER_MAX)
until Get_Distance_IDxy(OwnerID,x1,y1) <= DIST_OWNER_MAX
DestX,DestY = x1,y1
elseif (ESCAPE_WAY == 1) then
x1 = math.floor(math.cos(math.rad(EscapeAngle)) * DIST_OWNER_MAX + 0.5)
y1 = math.floor(math.sin(math.rad(EscapeAngle)) * DIST_OWNER_MAX + 0.5)
DestX = x + x1
DestY = y + y1
EscapeAngle = EscapeAngle + 45
if (EscapeAngle >= 360) then
EscapeAngle = EscapeAngle - 360
end
end
Move(MyID,DestX,DestY)
TraceAI (string.format("逃跑 -> 逃跑 : HP百分比为%3.2f : 到定点",hp_percent))
return
end
if (GetV(V_MOTION,MyID) == MOTION_STAND) then
x,y = GetV(V_POSITION,OwnerID)
if (ESCAPE_WAY == 0) then
math.randomseed(GetTick())
repeat
x1 = x + math.random(-DIST_OWNER_MAX,DIST_OWNER_MAX)
y1 = y + math.random(-DIST_OWNER_MAX,DIST_OWNER_MAX)
until Get_Distance_IDxy(OwnerID,x1,y1) <= DIST_OWNER_MAX
DestX,DestY = x1,y1
elseif (ESCAPE_WAY == 1) then
x1 = math.floor(math.cos(math.rad(EscapeAngle)) * DIST_OWNER_MAX + 0.5)
y1 = math.floor(math.sin(math.rad(EscapeAngle)) * DIST_OWNER_MAX + 0.5)
DestX = x + x1
DestY = y + y1
EscapeAngle = EscapeAngle + 45
if (EscapeAngle >= 360) then
EscapeAngle = EscapeAngle - 360
end
end
Move(MyID,DestX,DestY)
TraceAI (string.format("逃跑 -> 逃跑 : HP百分比为%3.2f : 站立",hp_percent))
return
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 移动指令
--------------------------------------------------------------------------------
function OnMOVE_CMD_ST ()
TraceAI ("移动指令状态中")
local x, y = GetV (V_POSITION,MyID)
if (x == DestX and y == DestY) then
MyState = RETURN_ST
TraceAI ("移动指令 -> 回归")
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 停止指令
--------------------------------------------------------------------------------
function OnSTOP_CMD_ST ()
TraceAI ("停止指令状态中")
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 攻击指令
--------------------------------------------------------------------------------
function OnATTACK_OBJECT_CMD_ST ()
TraceAI ("攻击指令状态中")
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 区域攻击指令
--------------------------------------------------------------------------------
function OnATTACK_AREA_CMD_ST ()
TraceAI ("区域攻击指令状态中")
local object = GetOwnerEnemy (MyID)
if (object == 0) then
object = GetMyEnemy (MyID)
end
if (object ~= 0) then
MyState = CHASE_ST
MyEnemy = object
return
end
local x , y = GetV (V_POSITION,MyID)
if (x == DestX and y == DestY) then
MyState = IDLE_ST
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 巡逻指令
--------------------------------------------------------------------------------
function OnPATROL_CMD_ST ()
TraceAI ("巡逻指令状态中")
local object = GetOwnerEnemy (MyID)
if (object == 0) then
object = GetMyEnemy (MyID)
end
if (object ~= 0) then
MyState = CHASE_ST
MyEnemy = object
TraceAI ("PATROL_CMD_ST -> CHASE_ST : ATTACKED_IN")
return
end
local x , y = GetV (V_POSITION,MyID)
if (x == DestX and y == DestY) then
DestX = PatrolX
DestY = PatrolY
PatrolX = x
PatrolY = y
Move (MyID,DestX,DestY)
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 死守指令
--------------------------------------------------------------------------------
function OnHOLD_CMD_ST ()
TraceAI ("死守指令状态中")
if (MyEnemy ~= 0) then
local d = Get_Distance_ID(MyID,MyEnemy)
if (d ~= -1 and d <= GetV(V_ATTACKRANGE,MyID)) then
Attack (MyID,MyEnemy)
else
MyEnemy = 0
end
return
end
local object = GetOwnerEnemy (MyID)
if (object == 0) then
object = GetMyEnemy (MyID)
if (object == 0) then
return
end
end
MyEnemy = object
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 技能指令
--------------------------------------------------------------------------------
function OnSKILL_OBJECT_CMD_ST ()
TraceAI ("技能指令状态中")
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 区域技能指令
--------------------------------------------------------------------------------
function OnSKILL_AREA_CMD_ST ()
TraceAI ("区域技能指令状态中")
local x , y = GetV (V_POSITION,MyID)
if (Get_Distance_xy(x,y,DestX,DestY) <= GetV(V_SKILLATTACKRANGE,MyID,MySkill)) then
SkillGround (MyID,MySkillLevel,MySkill,DestX,DestY)
MyState = IDLE_ST
MySkill = 0
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 跟随指令
--------------------------------------------------------------------------------
function OnFOLLOW_CMD_ST ()
TraceAI ("跟随指令状态中")
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 搜寻敌人
--------------------------------------------------------------------------------
function Seek_Enemy ()
local result = 0
local actors = GetActors ()
local enemys_1 = {}
local enemys_2 = {}
local enemys_3 = {}
local enemys_4 = {}
local index = {1,1,1,1}
local target
local motion
local dis
local min_dis
for i,v in ipairs(actors) do
if (v ~= OwnerID and v ~= MyID) then
target = GetV (V_TARGET,OwnerID)
if (target == v) then
if (Get_Distance_ID(OwnerID,v) <= DIST_OWNER_MAX) then
enemys_1[index[1]] = v
index[1] = index[1] + 1
end
end
target = GetV (V_TARGET,v)
if (target == OwnerID or target == MyID) then
if (Get_Distance_ID(OwnerID,v) <= DIST_OWNER_MAX) then
enemys_2[index[2]] = v
index[2] = index[2] + 1
end
end
if (IsMonster(v) == 1) then
if (Get_Distance_ID(OwnerID,v) <= DIST_OWNER_MAX) then
enemys_3[index[3]] = v
index[3] = index[3] + 1
end
end
if (Get_Distance_ID(OwnerID,v) <= DIST_OWNER_MAX) then
enemys_4[index[4]] = v
index[4] = index[4] + 1
end
end
end
if (MyKind > 0) then
min_dis = HOMUN_SIGHT + 1
for i,v in ipairs(enemys_1) do
dis = Get_Distance_ID(MyID,v)
if (dis < min_dis) then
result = v
min_dis = dis
end
end
if (result ~= 0) then
if (Get_HP_Percent(MyID) >= HOMUN_HP_HIGH) then
MyEnemy = result
return
end
end
end
if (MyKind > 1) then
min_dis = HOMUN_SIGHT + 1
for i,v in ipairs(enemys_2) do
dis = Get_Distance_ID(MyID,v)
if (dis < min_dis) then
result = v
min_dis = dis
end
end
if (result ~= 0) then
if (Get_HP_Percent(MyID) >= HOMUN_HP_HIGH) then
MyEnemy = result
return
end
end
end
if (MyKind > 2) then
min_dis = HOMUN_SIGHT + 1
for i,v in ipairs(enemys_3) do
dis = Get_Distance_ID(MyID,v)
if (dis < min_dis) then
result = v
min_dis = dis
end
end
if (result ~= 0) then
if (Get_HP_Percent(MyID) >= HOMUN_HP_HIGH) then
MyEnemy = result
return
end
end
end
if (MyKind > 3) then
min_dis = HOMUN_SIGHT + 1
for i,v in ipairs(enemys_4) do
dis = Get_Distance_ID(MyID,v)
if (dis < min_dis) then
result = v
min_dis = dis
end
end
if (result ~= 0) then
if (Get_HP_Percent(MyID) >= HOMUN_HP_HIGH) then
MyEnemy = result
return
end
end
end
MyEnemy = 0
end
--------------------------------------------------------------------------------
const.lua
-- c function
--[[
function TraceAI (string) end
function MoveToOwner (id) end
function Move (id,x,y) end
function Attack (id,id) end
function GetV (V_,id) end
function GetActors () end
function GetTick () end
function GetMsg (id) end
function GetResMsg (id) end
function SkillObject (id,level,skill,target) end
function SkillGround (id,level,skill,x,y) end
function IsMonster (id) end
--]]
--------------------------------------------------------------------------------
-- GetV 使用常数值
--------------------------------------------------------------------------------
V_OWNER = 0 -- 主人ID
V_POSITION = 1 -- 现在位置x,y
V_TYPE = 2 -- 个体类型
V_MOTION = 3 -- 动作
V_ATTACKRANGE = 4 -- 攻击范围
V_TARGET = 5 -- 目标
V_SKILLATTACKRANGE = 6 -- 技能攻击范围
V_HOMUNTYPE = 7 -- 生命体种类
V_HP = 8 -- HP
V_SP = 9 -- SP
V_MAXHP = 10 -- 最大HP
V_MAXSP = 11 -- 最大SP
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 生命体种类
--------------------------------------------------------------------------------
LIF = 1 -- 丽芙
AMISTR = 2 -- 艾咪斯可鲁
FILIR = 3 -- 飞里乐
VANILMIRTH = 4 -- 巴尼米乐斯
LIF_H = 5 -- 进化丽芙
AMISTR_H = 6 -- 进化艾咪斯可鲁
FILIR_H = 7 -- 进化飞里乐
VANILMIRTH_H = 8 -- 进化巴尼米乐斯
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 动作
--------------------------------------------------------------------------------
MOTION_STAND = 0 -- 站立
MOTION_MOVE = 1 -- 移动
MOTION_ATTACK = 2 -- 攻击中
MOTION_DEAD = 3 -- 死亡
MOTION_SUFFER = 4 -- 挨打
MOTION_SIT = 6 -- 坐下
MOTION_ATTACK2 = 9 -- 攻击时
MOTION_SKILL = 12 -- 主人投掷药水给生命体时主人状态
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 技能
--------------------------------------------------------------------------------
-- 丽芙
LIF_HEAL = 8001 -- 治愈之手
LIF_AVOID = 8002 -- 轻捷移动
LIF_BRAIN = 8003 -- 脑手术
-- 进化丽芙
LIF_CHANGE = 8004 -- 智力变换
-- 艾咪斯可鲁
AMI_CASTLE = 8005 -- 位置互换
AMI_DEFENSE = 8006 -- 防御力
AMI_SKIN = 8007 -- 活命之肤
-- 进化艾咪斯可鲁
AMI_BLOODLUST = 8008 -- 血的贪求
-- 飞里乐
FLI_MOON = 8009 -- 月光
FLI_FLEET = 8010 -- 横越速度
FLI_SPEED = 8011 -- 紧急回避
-- 进化飞里乐
FLI_SBR44 = 8012 -- S.B.R.44
-- 巴尼米乐斯
VAN_CAPRICE = 8013 -- 善变
VAN_CHAOTIC = 8014 -- 混乱的祈福
VAN_INSTRUCT = 8015 -- 变更指示
-- 进化巴尼米乐斯
VAN_EXPLOSION = 8016 -- 生物爆炸
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 技能消耗
--------------------------------------------------------------------------------
-- 丽芙
LIF_HEAL_COST = {13,16,19,22,25} -- 治愈之手
LIF_AVOID_COST = {20,25,30,35,40} -- 轻捷移动
-- 进化丽芙
LIF_CHANGE_COST = {0,0,0,0,0} -- 智力变换
-- 艾咪斯可鲁
AMI_CASTLE_COST = {10,10,10,10,10} -- 位置互换
AMI_DEFENSE_COST = {20,25,30,35,40} -- 防御力
-- 进化艾咪斯可鲁
AMI_BLOODLUST_COST = {0,0,0,0,0} -- 血的贪求
-- 飞里乐
FLI_MOON_COST = {4,8,12,16,20} -- 月光
FLI_FLEET_COST = {30,40,50,60,70} -- 横越速度
FLI_SPEED_COST = {30,40,50,60,70} -- 紧急回避
-- 进化飞里乐
FLI_SBR44_COST = {0,0,0,0,0} -- S.B.R.44
-- 巴尼米乐斯
VAN_CAPRICE_COST = {22,24,26,28,30} -- 善变
VAN_CHAOTIC_COST = {40,40,40,40,40} -- 混乱的祈福
-- 进化巴尼米乐斯
VAN_EXPLOSION_COST = {0,0,0,0,0} -- 生物爆炸
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 指令
--------------------------------------------------------------------------------
NONE_CMD = 0 -- 无指令
MOVE_CMD = 1 -- 移动
STOP_CMD = 2 -- 停止
ATTACK_OBJECT_CMD = 3 -- 攻击
ATTACK_AREA_CMD = 4 -- 区域攻击
PATROL_CMD = 5 -- 巡逻
HOLD_CMD = 6 -- 死守
SKILL_OBJECT_CMD = 7 -- 技能
SKILL_AREA_CMD = 8 -- 区域技能
FOLLOW_CMD = 9 -- 跟随
--------------------------------------------------------------------------------
--[[ 指令参数
MOVE_CMD
{命令编号,X座标,Y座标}
STOP_CMD
{命令编号}
ATTACK_OBJECT_CMD
{命令编号,目标ID}
ATTACK_AREA_CMD
{命令编号,X座标,Y座标}
PATROL_CMD
{命令编号,X座标,Y座标}
HOLD_CMD
{命令编号}
SKILL_OBJECT_CMD
{命令编号,技能等级,技能种类,目标ID}
SKILL_AREA_CMD
{命令编号,技能等级,技能种类,X座标,Y座标}
FOLLOW_CMD
{命令编号}
--]]
Util.lua
require "./AI/USER_AI/Const.lua"
--------------------------------------------------------------------------------
-- List清单处理函式
--------------------------------------------------------------------------------
List = {}
--------------------------------------------------------------------------------
function List.new ()
return { first = 0, last = -1}
end
--------------------------------------------------------------------------------
function List.pushleft (list, value)
local first = list.first-1
list.first = first
list[first] = value;
end
--------------------------------------------------------------------------------
function List.pushright (list, value)
local last = list.last + 1
list.last = last
list[last] = value
end
--------------------------------------------------------------------------------
function List.popleft (list)
local first = list.first
if first > list.last then
return nil
end
local value = list[first]
list[first] = nil -- to allow garbage collection
list.first = first+1
return value
end
--------------------------------------------------------------------------------
function List.popright (list)
local last = list.last
if list.first > last then
return nil
end
local value = list[last]
list[last] = nil
list.last = last-1
return value
end
--------------------------------------------------------------------------------
function List.clear (list)
for i,v in ipairs(list) do
list = nil
end
--[[
if List.size(list) == 0 then
return
end
local first = list.first
local last = list.last
for i=first, last do
list = nil
end
--]]
list.first = 0
list.last = -1
end
--------------------------------------------------------------------------------
function List.size (list)
local size = list.last - list.first + 1
return size
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 计算座标间距离
--------------------------------------------------------------------------------
function Get_Distance_xy (x1,y1,x2,y2)
return math.floor(math.sqrt((x1-x2)^2+(y1-y2)^2) + 0.5)
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 计算两者距离
--------------------------------------------------------------------------------
function Get_Distance_ID (id1,id2)
local x1, y1 = GetV (V_POSITION,id1)
local x2, y2 = GetV (V_POSITION,id2)
if (x1 == -1 or x2 == -1) then
return -1
end
return Get_Distance_xy (x1,y1,x2,y2)
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 计算与座标距离
--------------------------------------------------------------------------------
function Get_Distance_IDxy (id,x,y)
local x1, y1 = GetV (V_POSITION,id)
if (x1 == -1 or x2 == -1) then
return -1
end
return Get_Distance_xy (x,y,x1,y1)
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 是否在攻击范围
--------------------------------------------------------------------------------
function IsInAttackSight (id1,id2)
local d = Get_Distance_ID (id1,id2)
if (d == -1) then
return false
end
local a = 0
if (MySkill == 0) then
a = GetV (V_ATTACKRANGE,id1)
else
a = GetV (V_SKILLATTACKRANGE,id1,MySkill)
end
if a >= d then
return true;
else
return false;
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 计算HP百分比
--------------------------------------------------------------------------------
function Get_HP_Percent (id)
return (GetV (V_HP,id)/GetV (V_MAXHP,id))*100
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 计算SP百分比
--------------------------------------------------------------------------------
function Get_SP_Percent (id)
return (GetV (V_SP,id)/GetV (V_MAXSP,id))*100
end
--------------------------------------------------------------------------------
[ 本帖最后由 Detry 于 2006-3-24 21:46 编辑 ] |
|