- UID
- 291831
- 帖子
- 1571
- 精华
- 0
- 威望
- 20
- 阅读权限
- 100
- 注册时间
- 2005-6-8
|
4#
发表于 2006-5-5 13:35
| 只看该作者
我把我的USER_AI贴出来吧,达人帮我看看
AI文件
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_PRO 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_PRO 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_PRO 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_PRO 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 |
|