--------------------------------------------------------------------------------
-- 主程式
--------------------------------------------------------------------------------
function AI(myid)
local msg
local rmsg
local hp_percent
local actors
local x,y
local x1,y1
local result
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 ()
--------------------------------------------------------------------------------
-- 休息
--------------------------------------------------------------------------------
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作者: hamasaki 时间: 2006-5-5 13:35
Const文件
-- 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
--]]
--------------------------------------------------------------------------------
-- 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
----------------------------------------作者: hamasaki 时间: 2006-5-5 13:36