-------------------------------------------
-- 攻击型态选择(以生命体类型为条件) GetMyEnemy
-------------------------------------------
function GetMyEnemy (myid)
local result = 0
local type = GetV (V_HOMUNTYPE,myid)
if (type == LIF or type == LIF_H or type == AMISTR or type == AMISTR_H) then
result = GetMyEnemyA (myid)
elseif (type == FILIR or type == FILIR_H or type == VANILMIRTH or type == VANILMIRTH_H) then
result = GetMyEnemyA (myid)
end
return result
end
-------------------------------------------
-- 非主动攻击型 GetMyEnemyA
-------------------------------------------
function GetMyEnemyA (myid)
local result = 0
local owner = GetV (V_OWNER,myid)
local actors = GetActors ()
local enemys = {}
local index = 1
local target
for i,v in ipairs(actors) do
if (v ~= owner and v ~= myid) then
target = GetV (V_TARGET,v)
if (target == myid) then
enemys[index] = v
index = index+1
end
end
end
local min_dis = 100
local dis
for i,v in ipairs(enemys) do
dis = GetDistance2 (myid,v)
if (dis < min_dis) then
result = v
min_dis = dis
end
end
return result
end
--]]
-------------------------------------------
-- 主动攻击型 GetMyEnemyB
-------------------------------------------
function GetMyEnemy (myid)
local result = 0
local owner = GetV (V_OWNER,myid)
local actors = GetActors ()
local enemys = {}
local index = 1
local type
for i,v in ipairs(actors) do
if (v ~= owner and v ~= myid) then
-- 这里可以插入判断怪物属性的程式
if (1 == IsMonster(v)) then
enemys[index] = v
index = index+1
end
end
end
local min_dis = 100
local dis
for i,v in ipairs(enemys) do
dis = GetDistance2 (myid,v)
if (dis < min_dis) then
result = v
min_dis = dis
end
end