浆糊论坛-RO小站's Archiver

y87800777 发表于 2009-7-1 14:12

求炼金AI或懂的帮改下AI!!!

别锁帖 我已经很含蓄的表达了
我有个AI但里面设置不会改求高手帮改下让BB主动打怪
----------------------Version B06----------------------
--------------------Powered by D Lo--------------------
-------------------------------------------------------
                                       
------------Const.lua------------
V_OWNER                        = 0               
V_POSITION                = 1
V_TYPE                        = 2
V_MOTION                = 3
V_ATTACKRANGE                = 4
V_TARGET                = 5
V_SKILLATTACKRANGE        = 6
V_HOMUNTYPE                = 7
V_HP                        = 8
V_SP                        = 9
V_MAXHP                        = 10
V_MAXSP                        = 11
---------------------------------
MOTION_STAND                = 0
MOTION_MOVE                = 1
MOTION_ATTACK                = 2
MOTION_DEAD             = 3
MOTION_ATTACK2                = 9
---------------------------------
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


------------Util.lua------------
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
        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        GetDistance (x1,y1,x2,y2)
        return math.floor(math.sqrt((x1-x2)^2+(y1-y2)^2))
end

function        GetDistance2 (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 GetDistance (x1,y1,x2,y2)
end

function        GetOwnerPosition (id)
        return GetV (V_POSITION,GetV(V_OWNER,id))
end

function        GetDistanceFromOwner (id)
        local x1, y1 = GetOwnerPosition (id)
        local x2, y2 = GetV (V_POSITION,id)
        if (x1 == -1 or x2 == -1) then
                return -1
        end
        return GetDistance (x1,y1,x2,y2)
end

function        IsOutOfSight (id1,id2)
        local x1,y1 = GetV (V_POSITION,id1)
        local x2,y2 = GetV (V_POSITION,id2)
        if (x1 == -1 or x2 == -1) then
                return true
        end
        local d = GetDistance (x1,y1,x2,y2)
        if d > 20 then
                return true
        else
                return false
        end
end

function        IsInAttackSight (id1,id2)
        local x1,y1 = GetV (V_POSITION,id1)
        local x2,y2 = GetV (V_POSITION,id2)
        if (x1 == -1 or x2 == -1) then
                return false
        end
        local d                = GetDistance (x1,y1,x2,y2)
        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

-----------------------------
-- state
-----------------------------
IDLE_ST                                        = 0
FOLLOW_ST                                = 1
CHASE_ST                                = 2
ATTACK_ST                                = 3
MOVE_CMD_ST                                = 4
STOP_CMD_ST                                = 5
ATTACK_OBJECT_CMD_ST                        = 6
ATTACK_AREA_CMD_ST                        = 7
PATROL_CMD_ST                                = 8
HOLD_CMD_ST                                = 9
SKILL_OBJECT_CMD_ST                        = 10
SKILL_AREA_CMD_ST                        = 11
FOLLOW_CMD_ST                                = 12
----------------------------



------------------------------------------
-- global variable
------------------------------------------
MyState                                = CHECK_ST        
MyEnemy                                = 0               
MyDestX                                = 0               
MyDestY                                = 0               
MyPatrolX                        = 0               
MyPatrolY                        = 0               
ResCmdList                        = List.new()        
MyID                                = 0               
MySkill                                = 0               
MySkillLevel                        = 0
MyOwner                                = 0
--------------FRIEND_SYSTEM---------------
MyFriend                        = -1
FriendList                        = {}
SavedFriend                        = {}
ScoreGain                        = 0
ScoreLoss                        = 0
ScoreRequire                        = 50000
ScoreTimer                        = 0
ScoreSaveNeed                        = 0
ScoreSaveTimer                        = 0
FriendDeleteTime                = 0
FDListCleanTime                        = 0
------------AUTO_SKILL_SYSTEM-------------
MyHP                                = 0
DamagedHP                        = 0
AutoSkill                        = 1
AutoSkillID                        = {[1] = 0, [2] = 0, [3] = 0}
AutoSkillLevel                        = {[1] = 0, [2] = 0, [3] = 0}
AutoSkillSP                        = {[1] = 0, [2] = 0, [3] = 0}
AutoSkillAttackTime                = {[0] = 0, [1] = 0, [2] = 0, [3] = 0}
AutoSkillConsumeTime                = {[0] = 1000, [1] = 0, [2] = 0, [3] = 0}
AutoSkillConfig1                = {[1] = 0, [2] = 0, [3] = 0}
AutoSkillConfig2                = {[1] = 0}
--------------FREEDOM_SYSTEM--------------
FreedomStartTime                = 0
FreedomDelayTime                = 0
FreedomTime                        = 0
FreedomDistance                        = 0
FreedomRest                        = 0
FreedomMoveTime                        = 0
FreedomMoveDelayFrom                = 0
FreedomMoveDelayTo                = 0
FriendListName                        = 0
--------------OTHERS_SYSTEM---------------
AttackMode                        = 0
AdvancedTimer                        = 0
MoveStartTime                        = 0
MoveEndTime                        = 0
MoveDistance                        = 0
MoveTestTime                        = 0
ServerType                        = 0
LowHPEsc                        = 0.4
AutoFollow                        = 0
IgnoreList                        = {}
------------------------------------------



------------- command process  ---------------------

function        OnMOVE_CMD (x,y)
        
        TraceAI ("OnMOVE_CMD")

        if ( x == MyDestX and y == MyDestY and MOTION_MOVE == GetV(V_MOTION,MyID)) then
                return        
        end

        local OwnerX, OwnerY = GetOwnerPosition (MyID)                                -- [AT_SYS]ATTACK_MODE_SWITCH
        if (OwnerX == x and OwnerY == y) then
                if (AttackMode == 1) then
                        AttackMode = 0
                else
                        AttackMode = 1
                end
                SaveMode ()
                return
        end

        local curX, curY = GetV (V_POSITION,MyID)                                -- [AS_SYS]AUTOSKILL_SWITCH
        if (curX == x and curY == y) then
                if (AutoSkill == 0) then
                        AutoSkill = 1
                else
                        AutoSkill = 0
                end
                SaveMode ()
                MyState = IDLE_ST
                return
        end
                                
        for i,v in ipairs(GetActors ()) do                                        -- [FD_SYS]GET_A_FRIEND
                if (v ~= MyOwner and v ~= MyID and v > 99999) then
                        local FriendX, FriendY = GetV (V_POSITION,v);
                        if (FriendX == x and FriendY == y) then
                                if (SavedFriend[v] == nil) then
                                        FriendList[v] = 0
                                        TraceAI ("NewFriend Added")
                                elseif (SavedFriend[v] >= ScoreRequire) then
                                        if (GetTick () - FriendDeleteTime < 500) then
                                                FriendList[v] = nil
                                                SavedFriend[v] = nil
                                                MyFriend = -1
                                                SaveFriendList ()
                                                TraceAI ("ScoredFriend Deleted")
                                        else
                                                FriendDeleteTime = GetTick ()
                                        end
                                else
                                        FriendList[v] = SavedFriend[v]
                                        TraceAI ("SavedFriend Added")        
                                end

                                if (MyFriend == -1) then
                                        FreedomStartTime = 0
                                        FreedomTime = 0
                                end
                                MyState = IDLE_ST
                                return
                        end
                end
        end

        if (GetDistance(x,y,curX,curY) > 15) then                        
                List.pushleft (ResCmdList,{MOVE_CMD,x,y})                                
                x = math.floor((x+curX)/2)                                       
                y = math.floor((y+curY)/2)                                       
        end

        Move (MyID,x,y)        
        
        MyState = MOVE_CMD_ST
        MyDestX = x
        MyDestY = y
        MyEnemy = 0
        MySkill = 0

end




function        OnSTOP_CMD ()

        TraceAI ("OnSTOP_CMD")

        if (GetV(V_MOTION,MyID) ~= MOTION_STAND) then
                Move (MyID,GetV(V_POSITION,MyID))
        end
        MyState = IDLE_ST
        MyDestX = 0
        MyDestY = 0
        MyEnemy = 0
        MySkill = 0

end




function        OnATTACK_OBJECT_CMD (id)

        TraceAI ("OnATTACK_OBJECT_CMD")

        MySkill = 0
        MyEnemy = id
        MyState = CHASE_ST

end




function        OnATTACK_AREA_CMD (x,y)

        TraceAI ("OnATTACK_AREA_CMD")

        if (x ~= MyDestX or y ~= MyDestY or MOTION_MOVE ~= GetV(V_MOTION,MyID)) then
                Move (MyID,x,y)        
        end
        MyDestX = x
        MyDestY = y
        MyEnemy = 0
        MyState = ATTACK_AREA_CMD_ST
        
end



function        OnPATROL_CMD (x,y)

        TraceAI ("OnPATROL_CMD")

        MyPatrolX , MyPatrolY = GetV (V_POSITION,MyID)
        MyDestX = x
        MyDestY = y
        Move (MyID,x,y)
        MyState = PATROL_CMD_ST

end




function        OnHOLD_CMD ()

        TraceAI ("OnHOLD_CMD")

        MyDestX = 0
        MyDestY = 0
        MyEnemy = 0
        MyState = HOLD_CMD_ST

end




function        OnSKILL_OBJECT_CMD (level,skill,id)

        TraceAI ("OnSKILL_OBJECT_CMD")

        MySkillLevel = level
        MySkill = skill
        MyEnemy = id
        MyState = SKILL_OBJECT_CMD_ST

end




function        OnSKILL_AREA_CMD (level,skill,x,y)

        TraceAI ("OnSKILL_AREA_CMD")

        Move (MyID,x,y)
        MyDestX = x
        MyDestY = y
        MySkillLevel = level
        MySkill = skill
        MyState = SKILL_AREA_CMD_ST
        
end




function        OnFOLLOW_CMD ()

        if (GetTick () - FDListCleanTime < 500) then
                for i,s in pairs(FriendList) do                        -- [FD_SYS]FRIENDS_CLEANER
                        if (s < ScoreRequire) then
                                FriendList = nil
                                TraceAI ("FriendList["..i.."] Cleared")
                        end
                end
                ScoreTimer = 0
                MyFriend = -1
                TraceAI ("FriendList Cleaning DONE")
        else
                FDListCleanTime = GetTick ()
        end

        if (MyState ~= FOLLOW_CMD_ST) then
                MoveToOwner (MyID)
                MyState = FOLLOW_CMD_ST
                MyDestX, MyDestY = GetV (V_POSITION,MyOwner)
                MyEnemy = 0
                MySkill = 0
                TraceAI ("OnFOLLOW_CMD")
        else
                MyState = IDLE_ST
                MyEnemy = 0
                MySkill = 0
                TraceAI ("FOLLOW_CMD_ST --> IDLE_ST")
        end

end




function        ProcessCommand (msg)

        if        (msg[1] == MOVE_CMD) then
                OnMOVE_CMD (msg[2],msg[3])
                TraceAI ("MOVE_CMD")
        elseif        (msg[1] == STOP_CMD) then
                OnSTOP_CMD ()
                TraceAI ("STOP_CMD")
        elseif        (msg[1] == ATTACK_OBJECT_CMD) then
                OnATTACK_OBJECT_CMD (msg[2])
                TraceAI ("ATTACK_OBJECT_CMD")
        elseif        (msg[1] == ATTACK_AREA_CMD) then
                OnATTACK_AREA_CMD (msg[2],msg[3])
                TraceAI ("ATTACK_AREA_CMD")
        elseif        (msg[1] == PATROL_CMD) then
                OnPATROL_CMD (msg[2],msg[3])
                TraceAI ("PATROL_CMD")
        elseif        (msg[1] == HOLD_CMD) then
                OnHOLD_CMD ()
                TraceAI ("HOLD_CMD")
        elseif        (msg[1] == SKILL_OBJECT_CMD) then
                OnSKILL_OBJECT_CMD (msg[2],msg[3],msg[4],msg[5])
                TraceAI ("SKILL_OBJECT_CMD")
        elseif        (msg[1] == SKILL_AREA_CMD) then
                OnSKILL_AREA_CMD (msg[2],msg[3],msg[4],msg[5])
                TraceAI ("SKILL_AREA_CMD")
        elseif        (msg[1] == FOLLOW_CMD) then
                OnFOLLOW_CMD ()
                TraceAI ("FOLLOW_CMD")
        end
end




-------------- state process  --------------------


function        OnIDLE_ST ()

        local cmd = List.popleft(ResCmdList)
        if (cmd ~= nil) then               
                ProcessCommand (cmd)
                return
        end

        if (AutoSkill == 1) then
                if (AutoSkillID[1] == 8001) then
                        if (AutoSkillSPChecker (1,"MIN") and AutoSkillTimer (1) == true) then
                                if (GetV(V_HP,MyOwner) < GetV(V_MAXHP,MyOwner)*AutoSkillConfig1[1]) then
                                        SkillObject (MyID,AutoSkillLevel[1],AutoSkillID[1],MyOwner)
                                        return
                                end
                        end
                end
                if (AutoSkillID[2] == 8002 and GetV (V_MOTION,AutoSkillConfig1[2]) == 1) then
                        if (AutoSkillTimer (2) == true and AutoSkillSPChecker (2,"MIN")) then
                                SkillObject (MyID,AutoSkillLevel[2],AutoSkillID[2],MyID)
                                return
                        end
                end
        end

        if (GetV(V_HP,MyID) > GetV(V_MAXHP,MyID)*LowHPEsc) then
                local SFD = GetMySavedFriend (MyID)                                -- [SFD_SYS]FIND_SAVED_FRIEND
                if (SFD ~= 0 and SFD ~= MyFriend) then
                        MyFriend = SFD
                end

                if(GetMyEnemy (AttackMode) == true) then
                        return
                end

                if(MyFriend ~= -1 and MoveTimer () == false) then                -- [FD_SYS]FOLLOW_FRIEND
                        if (FreedomTimer (MyFriend,FreedomRest*2) == true) then
                                FreedomMove (FreedomMoveTime)
                        else
                                local x, y = GetV (V_POSITION,MyFriend)
                                if(x == -1) then
                                        MyFriend = -1
                                        ScoreTimer = 0
                                elseif (GetDistance2 (MyID,MyFriend) > 2 or StayOutofActor() == true) then
                                        AdvancedMove (MyFriend,2)
                                end
                        end
                        return
                end
        else
                if(GetMyEnemy (0) == true) then
                        return
                end

        end

        if (FreedomTimer (MyOwner,FreedomRest) == true) then
                FreedomMove (FreedomMoveTime)
        else
                local distance = GetDistanceFromOwner(MyID)
                if ( distance > 3 or distance == -1 or StayOutofActor() == true) then        -- MYOWNER_OUTSIGNT_IN
                        AdvancedMove (MyOwner,3)
                end
        end
end



function        OnCHASE_ST ()

        if (GetDistance2 (MyID,MyEnemy) <= 1) then        -- ENEMY_INATTACKSIGHT_IN
                MyState = ATTACK_ST
                TraceAI ("CHASE_ST -> ATTACK_ST : ENEMY_INATTACKSIGHT_IN")
                return
        end

        if (GetMyEnemy (AttackMode) == false or MOTION_DEAD == GetV(V_MOTION,MyEnemy) or GetV (V_POSITION,MyEnemy) == -1) then
                MyState = IDLE_ST
                MyEnemy = 0
                DamagedHP = 0
                TraceAI ("CHASE_ST -> IDLE_ST : ENEMY_DEAD_OR_OUT_SIGHT_OR_BE_ATTACKED")
                return
        end

        if (AutoSkill == 1) then
                if (AutoSkillID[2] == 8006) then
                        if (AutoSkillTimer (2) == true and AutoSkillSPChecker (2,"MIN")) then
                                SkillObject (MyID,AutoSkillLevel[2],AutoSkillID[2],MyID)
                                return
                        end
                end
                if (AutoSkillID[1] == 8013) then
                        if (GetDistance2 (MyID,MyEnemy) <= GetV (V_SKILLATTACKRANGE,MyID,AutoSkillID[1]) and AutoSkillSPChecker (1,"MAX")) then
                                if (AutoSkillTimer (1) == true) then
                                        SkillObject (MyID,AutoSkillLevel[1],AutoSkillID[1],MyEnemy)
                                        MyDestX, MyDestY = GetV (V_POSITION,MyID)
                                        return
                                end
                        end
                end
                if (AutoSkillID[1] == 8001) then
                        if (AutoSkillSPChecker (1,"MIN") and AutoSkillTimer (1) == true) then
                                if (GetV(V_HP,MyOwner) < GetV(V_MAXHP,MyOwner)*AutoSkillConfig1[1]) then
                                        SkillObject (MyID,AutoSkillLevel[1],AutoSkillID[1],MyOwner)
                                        return
                                end
                        end
                end
                if (AutoSkillID[2] == 8002 and GetV (V_MOTION,AutoSkillConfig1[2]) == 1) then
                        if (AutoSkillTimer (2) == true and AutoSkillSPChecker (2,"MIN")) then
                                SkillObject (MyID,AutoSkillLevel[2],AutoSkillID[2],MyID)
                                return
                        end
                end
        end

        AdvancedMove (MyEnemy,1)
end               


function        OnATTACK_ST ()

        if (MoveTimer () == true) then
                AdvancedMove (MyOwner,3)
                return
        end

        if (GetV(V_MOTION,MyEnemy) == MOTION_DEAD or GetV (V_POSITION,MyEnemy) == -1 or (GetV(V_HP,MyID) <= GetV(V_MAXHP,MyID)*LowHPEsc and GetDistanceFromOwner(MyID) > 3)) then
                MyState = IDLE_ST
                MyEnemy = 0
                DamagedHP = 0
                TraceAI ("ATTACK_ST -> IDLE_ST : ENEMY_DEAD_OR_OUT_SIGHT_OR_LOW_HP_WARNING")
                return
        end

        local GME = GetMyEnemy (AttackMode)
        if (GME == true) then
                return
        end
        if (GetDistance2 (MyID,MyEnemy) > 1) then  -- ENEMY_OUTATTACKSIGHT_IN
                if (GME == false) then
                        MyState = IDLE_ST
                        MyEnemy = 0
                        DamagedHP = 0
                        TraceAI ("ATTACK_ST -> IDLE_ST : ENEMY_BE_ATTACKED")
                        return
                elseif (GME == allow) then
                        AdvancedMove (MyEnemy,1)
                        TraceAI ("ATTACK_ST : DESTCHANGED_IN")
                        return
                end
        end

        if (StayOutofActor() == true) then
                AdvancedMove (MyEnemy,1)
                TraceAI ("ATTACK_ST : STAY_OUT_OF_ACTOR")
        end

        if (AutoSkill == 1) then
                if (AutoSkillID[1] == 8001) then
                        if (AutoSkillSPChecker (1,"MIN") and AutoSkillTimer (1) == true) then
                                if (GetV(V_HP,MyOwner) < GetV(V_MAXHP,MyOwner)*AutoSkillConfig1[1]) then
                                        SkillObject (MyID,AutoSkillLevel[1],AutoSkillID[1],MyOwner)
                                        return
                                end
                        end
                end
                if (AutoSkillID[2] == 8002 and GetV (V_MOTION,AutoSkillConfig1[2]) == 1) then
                        if (AutoSkillTimer (2) == true and AutoSkillSPChecker (2,"MIN")) then
                                SkillObject (MyID,AutoSkillLevel[2],AutoSkillID[2],MyID)
                                return
                        end
                end

                if (AutoSkillID[2] == 8010) then
                        if (AutoSkillSPChecker (2,"MIN") and AutoSkillTimer (2) == true) then
                                SkillObject (MyID,AutoSkillLevel[2],AutoSkillID[2],MyID)
                                TraceAI ("ATTACK_ST -> ATTACK_ST  : AUTO_SKILL_2")
                                return
                        end
                end

                if (AutoSkillID[3] == 8011) then
                        if (DamagedHPCounter () == true and AutoSkillSPChecker (3,"MIN") and AutoSkillTimer (3) == true) then
                                SkillObject (MyID,AutoSkillLevel[3],AutoSkillID[3],MyID)
                                TraceAI ("ATTACK_ST -> ATTACK_ST  : AUTO_SKILL_3")
                                return
                        end
                end

                if (AutoSkillID[1] == 8009 or AutoSkillID[1] == 8013) then
                        local target = GetV (V_TARGET,MyEnemy)
                        if (DamagedHPCounter () == true or target == MyFriend or target == MyOwner or AutoSkillSPChecker (1,"MAX")) then
                                if (AutoSkillSPChecker (1,"MIX") and AutoSkillTimer (1) == true) then
                                        SkillObject (MyID,AutoSkillLevel[1],AutoSkillID[1],MyEnemy)                        -- [AS_SYS]AUTO_SKILL_ATTACK
                                        TraceAI ("ATTACK_ST -> ATTACK_ST  : AUTO_SKILL_1")
                                        return;
                                end
                        end
                end
        end

        Attack (MyID,MyEnemy)

        TraceAI ("ATTACK_ST -> ATTACK_ST  : ENERGY_RECHARGED_IN")
end



function        OnCHECK_ST ()                                                        -- ADD_CHECK_STATE

        local type = GetV (V_HOMUNTYPE,MyID)                                        -- FIND_OUT_HOMUN_TYPE
        if (type ~= -1) then
                MyOwner        = GetV(V_OWNER,MyID)
                    if (type == 1 or type == 9) then
                        type = "LIF"
                elseif (type == 2 or type == 10) then
                        type = "AMISTR"
                elseif (type == 3 or type == 11) then
                        type = "FILIR"
                elseif (type == 4 or type == 12) then
                        type = "VANILMIRTH"
                elseif (type == 5 or type == 13) then
                        type = "LIF2"
                elseif (type == 6 or type == 14) then
                        type = "AMISTR2"
                elseif (type == 7 or type == 15) then
                        type = "FILIR2"
                elseif (type == 8 or type == 16) then
                        type = "VANILMIRTH2"
                end

                FriendListName = "./AI/USER_AI/FriendList_"..type..".lua"
                local ConfigFileName = "./AI/USER_AI/Config_"..type..".ini"

                local CF = io.open (ConfigFileName, "r" )
                if ( CF == nil ) then
                        CF = io.open (ConfigFileName, "w+" )
                        CF:write ("AutoSkillLevel                = {[1] = 0, [2] = 0, [3] = 0}","\n","AutoSkillConfig1        = {[1] = 0, [2] = 0, [3] = 0}","\n","AutoSkillConfig2        = {[1] = 0}","\n","ServerType                = 0","\n","LowHPEsc                = 0.4","\n","AutoFollow                = 0","\n","IgnoreList                = {}")
                        CF:close ()
                end
                require (ConfigFileName)

                if (type == "LIF") then
                        ScoreGain = 200
                        ScoreLoss = 10
                        FreedomDistance = 3
                        FreedomRest = 120000
                        FreedomMoveTime = 60000
                        FreedomMoveDelayFrom = 5000
                        FreedomMoveDelayTo = 15000
                elseif (type == "AMISTR") then
                        ScoreGain = 100
                        ScoreLoss = 4
                        FreedomDistance = 8
                        FreedomRest = 90000
                        FreedomMoveTime = 90000
                        FreedomMoveDelayFrom = 10000
                        FreedomMoveDelayTo = 15000
                elseif (type == "FILIR") then
                        ScoreGain = 400
                        ScoreLoss = 32
                        FreedomDistance = 10
                        FreedomRest = 60000
                        FreedomMoveTime = 120000
                        FreedomMoveDelayFrom = 5000
                        FreedomMoveDelayTo = 10000
                elseif (type == "VANILMIRTH") then
                        ScoreGain = 300
                        ScoreLoss = 20
                        FreedomDistance = 5
                        FreedomRest = 60000
                        FreedomMoveTime = 120000
                        FreedomMoveDelayFrom = 3000
                        FreedomMoveDelayTo = 7000
                elseif (type == "LIF2") then
                        ScoreGain = 500
                        ScoreLoss = 45
                        FreedomDistance = 12
                        FreedomRest = 60000
                        FreedomMoveTime = 180000
                        FreedomMoveDelayFrom = 10000
                        FreedomMoveDelayTo = 20000
                elseif (type == "AMISTR2") then
                        ScoreGain = 150
                        ScoreLoss = 8
                        FreedomDistance = 7
                        FreedomRest = 60000
                        FreedomMoveTime = 90000
                        FreedomMoveDelayFrom = 8000
                        FreedomMoveDelayTo = 12000
                elseif (type == "FILIR2") then
                        ScoreGain = 250
                        ScoreLoss = 28
                        FreedomDistance = 2
                        FreedomRest = 40000
                        FreedomMoveTime = 180000
                        FreedomMoveDelayFrom = 3000
                        FreedomMoveDelayTo = 6000
                elseif (type == "VANILMIRTH2") then
                        ScoreGain = 50
                        ScoreLoss = 8
                        FreedomDistance = 5
                        FreedomRest = 180000
                        FreedomMoveTime = 240000
                        FreedomMoveDelayFrom = 15000
                        FreedomMoveDelayTo = 30000
                end

                if (type == "LIF" or type == "LIF2") then
                        if ( AutoSkillLevel[1] ~= 0 and AutoSkillLevel[1] <= 5) then
                                AutoSkillID[1] = 8001
                                AutoSkillConsumeTime[1] = 1500
                                AutoSkillSP[1] = 10+AutoSkillLevel[1]*3
                        end
                        if ( AutoSkillLevel[2] ~= 0 and AutoSkillLevel[2] <= 5) then
                                AutoSkillID[2] = 8002
                                AutoSkillSP[2] = 15+AutoSkillLevel[2]*5
                                AutoSkillConsumeTime[2] = 47000-AutoSkillLevel[2]*5000
                                if (AutoSkillConfig1[2] == 0) then
                                        AutoSkillConfig1[2] = MyOwner
                                elseif (AutoSkillConfig1[2] == 1) then
                                        AutoSkillConfig1[2] = MyID
                                end
                        end
                elseif (type == "AMISTR" or type == "AMISTR2") then
                        if ( AutoSkillLevel[2] ~= 0 and AutoSkillLevel[2] <= 5) then
                                AutoSkillID[2] = 8006
                                AutoSkillSP[2] = 15+AutoSkillLevel[2]*5
                                AutoSkillConsumeTime[2] = 47000-AutoSkillLevel[2]*5000
                        end
                elseif (type == "FILIR" or type == "FILIR2") then
                        if ( AutoSkillLevel[1] ~= 0 and AutoSkillLevel[1] <= 5) then
                                AutoSkillID[1] = 8009
                                if (AutoSkillConfig1[1] == 0)then
                                        AutoSkillConsumeTime[1] = 5000
                                else
                                        AutoSkillConsumeTime[1] = AutoSkillConfig1[1]
                                end
                                AutoSkillSP[1] = AutoSkillLevel[1]*4
                        end
                        if ( AutoSkillLevel[2] ~= 0 and AutoSkillLevel[2] <= 5) then
                                AutoSkillID[2] = 8010
                                AutoSkillSP[2] = 20+AutoSkillLevel[2]*10
                                AutoSkillConsumeTime[2] = 52000+AutoSkillLevel[2]*10000
                                if (AutoSkillLevel[2] == 5) then
                                        AutoSkillConsumeTime[2] = AutoSkillConsumeTime[2]+20000
                                end
                        end
                        if ( AutoSkillLevel[3] ~= 0 and AutoSkillLevel[3] <= 5) then
                                AutoSkillID[3] = 8011
                                AutoSkillSP[3] = 20+AutoSkillLevel[3]*10
                                AutoSkillConsumeTime[3] = 52000+AutoSkillLevel[3]*10000
                                if (AutoSkillLevel[3] == 5) then
                                        AutoSkillConsumeTime[3] = AutoSkillConsumeTime[3]+20000
                                end
                        end
                elseif (type == "VANILMIRTH" or type == "VANILMIRTH2") then
                        if ( AutoSkillLevel[1] ~= 0 and AutoSkillLevel[1] <= 5) then
                                AutoSkillID[1] = 8013
                                if (AutoSkillConfig1[1] == 0)then
                                        AutoSkillConsumeTime[1] = 5000
                                else
                                        AutoSkillConsumeTime[1] = AutoSkillConfig1[1]
                                end
                                AutoSkillSP[1] = 20+AutoSkillLevel[1]*2
                        end
                end

                local SM = io.open ( "./AI/USER_AI/SavedMode.lua", "r" )
                if ( SM == nil ) then
                        SaveMode ()
                else
                        SM:close ()
                end
                require "./AI/USER_AI/SavedMode.lua"

                local FL = io.open (FriendListName, "r" )
                if ( FL ~= nil ) then
                        FL:close ()
                        require (FriendListName);        

                        for i,s in pairs(SavedFriend) do                                -- ADD_SCORED_FRINED_TO_LIST
                                if (SavedFriend >= ScoreRequire) then
                                        FriendList = s
                                end
                        end
                end

                MyState = IDLE_ST
                TraceAI ("CHECK_ST -> IDLE_ST : Initial Check Done")
        end
end




function        OnMOVE_CMD_ST ()

        TraceAI ("OnMOVE_CMD_ST")

        local x, y = GetV (V_POSITION,MyID)
        if (x == MyDestX and y == MyDestY) then                                        -- DESTINATION_ARRIVED_IN
                MyState = IDLE_ST
        end
end




function OnSTOP_CMD_ST ()


end




function OnATTACK_OBJECT_CMD_ST ()

        

end




function OnATTACK_AREA_CMD_ST ()

        TraceAI ("OnATTACK_AREA_CMD_ST")
                                                        
        object = GetMyEnemy (AttackMode)
        if (object ~= 0) then                                                        -- MYOWNER_ATTACKED_IN or ATTACKED_IN
                MyState = CHASE_ST
                MyEnemy = object
                return
        end

        local x , y = GetV (V_POSITION,MyID)
        if (x == MyDestX and y == MyDestY) then                                        -- DESTARRIVED_IN
                        MyState = IDLE_ST
        end

end




function OnPATROL_CMD_ST ()

        TraceAI ("OnPATROL_CMD_ST")
                                                
        object = GetMyEnemy (AttackMode)
        if (object ~= 0) then                                                        -- MYOWNER_ATTACKED_IN or ATTACKED_IN
                MyState = CHASE_ST
                MyEnemy = object
                TraceAI ("PATROL_CMD_ST -> CHASE_ST : ATTACKED_IN")
                return
        end

        local x , y = GetV (V_POSITION,MyID)
        if (x == MyDestX and y == MyDestY) then                                        -- DESTARRIVED_IN
                MyDestX = MyPatrolX
                MyDestY = MyPatrolY
                MyPatrolX = x
                MyPatrolY = y
                Move (MyID,MyDestX,MyDestY)
        end

end




function OnHOLD_CMD_ST ()

        TraceAI ("OnHOLD_CMD_ST")
        
        if (MyEnemy ~= 0) then
                local d = GetDistance(MyEnemy,MyID)
                if (d ~= -1 and d <= GetV(V_ATTACKRANGE,MyID)) then
                                Attack (MyID,MyEnemy)
                else
                        MyEnemy = 0;
                end
                return
        end
                                                        
        object = GetMyEnemy (AttackMode)
        if (object == 0) then                                                
                return
        end

        MyEnemy = object

end




function OnSKILL_OBJECT_CMD_ST ()

        TraceAI ("OnSKILL_OBJECT_CMD_ST")

        if (GetDistance2 (MyID,MyEnemy) <= GetV (V_SKILLATTACKRANGE,MyID,MySkill)) then
                SkillObject (MyID,MySkillLevel,MySkill,MyEnemy)
                AutoSkillAttackTime[0] = GetTick ()
                MyState = IDLE_ST
                MySkill = 0
                MyEnemy = 0
                TraceAI ("SKILL_OBJECT_CMD_ST -> IDLE_ST : ENEMY_SKILLED_IN")
                return
        else
                local x, y = GetV (V_POSITION,MyEnemy)
                if (MyDestX ~= x or MyDestY ~= y) then                                        -- DESTCHANGED_IN
                        MyDestX, MyDestY = GetV (V_POSITION,MyEnemy);
                        local OwnerX, OwnerY = GetOwnerPosition (MyID)
                        if ( math.abs(OwnerX-MyDestX) < 14 and math.abs(OwnerY-MyDestY) < 14 ) then        -- [BUG_FIX]MOVE_IN_OWNER_SIGHT
                                Move (MyID,MyDestX,MyDestY)
                                TraceAI ("SKILL_OBJECT_CMD_ST -> SKILL_OBJECT_CMD_ST : DESTCHANGED_IN")
                                return
                        else
                                MyState = IDLE_ST
                                MyEnemy = 0
                                MySkill        = 0
                                TraceAI ("SKILL_OBJECT_CMD_ST -> IDLE_ST : ENEMY_OUTSIGHT_IN")
                                return
                        end
                end
        end        
end




function OnSKILL_AREA_CMD_ST ()

        TraceAI ("OnSKILL_AREA_CMD_ST")

        local x , y = GetV (V_POSITION,MyID)
        if (GetDistance(x,y,MyDestX,MyDestY) <= GetV(V_SKILLATTACKRANGE,MyID,MySkill)) then        -- DESTARRIVED_IN
                SkillGround (MyID,MySkillLevel,MySkill,MyDestX,MyDestY)
                MyState = IDLE_ST
                MySkill = 0
        end

end







function OnFOLLOW_CMD_ST ()

        TraceAI ("OnFOLLOW_CMD_ST")

        local ownerX, ownerY, myX, myY
        ownerX, ownerY = GetV (V_POSITION,MyOwner)
        myX, myY = GetV (V_POSITION,MyID)                                          
        
        local d = GetDistance (ownerX,ownerY,myX,myY)

        if ( d <= 3 and StayOutofActor() == false) then                                                                        
                return
        end

        AdvancedMove (MyOwner,3)
        
end



-------------- Function process  --------------------


function        GetMyEnemy (MODE)
        if(MoveTimer () == true) then
                MODE = 0
        end

        local result = 0
        local min_rank = 400
        local Attackers = {}
        local Attacker_index = 1
        local Enemys = {}
        local Enemy_index = 1

        if (ServerType == 0) then                        -- [PvE System]
                for i,v in ipairs(GetActors ()) do               
                        if (IsMonster(v) == 1 and v ~= MyOwner and v ~= MyID) then
                                Enemys[Enemy_index] = v
                                Enemy_index = Enemy_index + 1
                        elseif(GetV (V_TARGET,v) ~= 0 and MODE ~= 0 and v ~= MyOwner and v ~= MyID and FriendList[v] == nil) then
                                Attackers[Attacker_index] = v
                                Attacker_index = Attacker_index + 1
                        end
                end
        elseif (ServerType == 1) then                        -- [PvP System]
                for i,v in ipairs(GetActors ()) do
                        if (FriendList[v] == nil) then
                                Enemys[Enemy_index] = v
                                Enemy_index = Enemy_index + 1
                                if(GetV (V_TARGET,v) ~= 0 and MODE ~= 0 and v ~= MyOwner and v ~= MyID and IsMonster(v) ~= 1) then
                                        Attackers[Attacker_index] = v
                                        Attacker_index = Attacker_index + 1
                                end
                        end
                end
        end
        
        for i,v in ipairs(Enemys) do
                local dis = GetDistance2 (MyID,v)
                local rank = 400
                local target = GetV (V_TARGET,v)        --[AT_SYS]GET_PASSIVE_ENEMY
                local Attacked = 0

                if (IgnoreList[GetV (V_HOMUNTYPE,v)] == 1 and IsMonster(v)) then
                        rank = 400        
                elseif (target == 0 and MODE ~= 0 and (ServerType == 0 or IsMonster(v) == 1) and IgnoreList[GetV (V_HOMUNTYPE,v)] ~= 2) then
                        for p,a in ipairs(Attackers) do
                                local Atarget = GetV (V_TARGET,a)
                                if (Atarget == v) then
                                        Attacked = 1
                                        break;
                                end
                        end
                        if (Attacked == 0) then
                                rank = dis + 300
                        end
                elseif (target == MyID) then
                                rank = dis + 100
                elseif (target == MyOwner or (GetV (V_TARGET,MyOwner) == v and Attacked == 0 and target == 0)) then
                        rank = dis
                elseif (MyFriend ~= -1) then
                        for r,f in pairs(FriendList) do
                                if (target == r or (GetV (V_TARGET,r) == v and Attacked == 0 and target == 0)) then
                                        rank = dis + 200
                                        break;
                                end
                        end        
                end

                if (rank < min_rank) then               
                        result = v
                        min_rank = rank
                end        
        end

        if (result ~= 0) then
                if (GetV(V_HP,MyID) > GetV(V_MAXHP,MyID)*LowHPEsc or GetDistanceFromOwner(result) <= 4) then        -- [HP_SYS]HP_CHECK
                        if (result ~= MyEnemy and (MyState ~= ATTACK_ST or (MyState == ATTACK_ST and GetV (V_TARGET,MyEnemy) == 0))) then
                                MyEnemy = result
                                MyHP = GetV (V_HP,MyID)
                                MyState = CHASE_ST
                                return true
                        else
                                return allow
                        end
                end        
        end
        return false
end


function        GetMySavedFriend (myid)                                -- [SFD_SYS]ADD_GETMYSAVEDFRIEND_FUNCTION
        local result = 0
        local actors = GetActors ()
        local minRank = -1
        for i,s in ipairs(actors) do
                if (s ~= MyOwner and s ~= myid and IsMonster(s) == 0) then
                        if (FriendList[s] ~= nil) then
                                if (FriendList[s] > minRank) then
                                        result = s
                                        minRank = FriendList[s]
                                end
                        end
                end
        end

        return result
end


function        DamagedHPCounter ()

        local count = MyHP - GetV(V_HP,MyID)
        if (count > 0) then
                DamagedHP = DamagedHP + count
                MyHP = GetV(V_HP,MyID)
        elseif (count < 0) then
                MyHP = GetV(V_HP,MyID)
        end

        if (DamagedHP > GetV(V_MAXHP,MyID)*0.05) then
                if (AutoSkillConfig1[1] == 0) then
                        AutoSkillConsumeTime[1] = 1000+4000*(1-DamagedHP/GetV(V_MAXHP,MyID)*2)
                end
                return true
        else
                if (AutoSkillConfig1[1] == 0 and AutoSkillConsumeTime[1] ~= 5000) then
                        AutoSkillConsumeTime[1] = 5000
                end
                return false
        end
end


function        AdvancedMove (id,ran)

        local PositionX, PositionY = GetV (V_POSITION,id)
        local curX, curY = GetV (V_POSITION,MyID)
        local d = GetDistance (PositionX, PositionY, MyDestX, MyDestY)
        local OwnerX, OwnerY = GetOwnerPosition (MyID)

        if (GetV (V_MOTION,MyID) == MOTION_MOVE) then
                if (d > ran and GetV (V_MOTION,id) == 1) then
                        MyDestX, MyDestY = PositionX, PositionY
                elseif (GetDistance (curX, curY, MyDestX, MyDestY) == 14) then
                        MyDestX, MyDestY = PositionX, PositionY
                end
        elseif (GetTick () - AdvancedTimer >= 1000) then
                AdvancedTimer = GetTick ()
                MyDestX, MyDestY = PositionX, PositionY
                TraceAI (string.format("%d_DESTCHANGED_IN",id))
        else
                return
        end

        if (((d > ran or d == 0) and GetV (V_MOTION,id) ~= 1)) then
                MyDestX, MyDestY = GetV (V_POSITION,id);
                MyDestX = MyDestX + math.random(-ran,ran);
                MyDestY = MyDestY + math.random(-ran,ran);
        end
        if (MyDestX > OwnerX+13) then
                TraceAI ("R")
                MyDestX = OwnerX+13
        elseif (MyDestX < OwnerX-13) then
                TraceAI ("L")
                MyDestX = OwnerX-13
        end
        if (MyDestY > OwnerY+13) then
                TraceAI ("T")
                MyDestY = OwnerY+13
        elseif (MyDestY < OwnerY-13) then
                TraceAI ("B")
                MyDestY = OwnerY-13
        end

        local DDS = GetDistance(MyDestX,MyDestY,curX,curY)
        if (DDS > 14) then                                
                Move (MyID,math.floor(curX+(MyDestX-curX)*14/DDS),math.floor(curY+(MyDestY-curY)*14/DDS))
        else
                Move (MyID,MyDestX,MyDestY)
        end
        MoveTestTime = GetTick ()
end


function        StayOutofActor()
        if (GetV (V_MOTION,MyID) ~= 1) then
                local actors = GetActors ()
                local MyX, MyY = GetV (V_POSITION,MyID)
                for i,v in ipairs(actors) do
                        local VX, VY = GetV (V_POSITION,v);
                        if (MyX == VX and MyY == VY and v ~= MyID and GetV (V_MOTION,v) ~= 1) then
                                return true
                        end
                end
        end
        return false
end

function        MoveTimer ()
        if (GetV(V_HP,MyID) > GetV(V_MAXHP,MyID)*AutoFollow) then
                local d = GetDistanceFromOwner(MyID)        
                if (GetV (V_MOTION,MyOwner) == 1 and (d >= MoveDistance or d > 8)) then
                        if (MoveStartTime == 0) then
                                MoveStartTime = GetTick ()
                        end
                        MoveDistance = GetDistanceFromOwner(MyID)
                elseif (GetTick () - MoveStartTime <= 800) then
                        MoveStartTime = 0
                        MoveDistance = 0
                end

                if (GetV (V_MOTION,MyID) == 0 and GetV (V_MOTION,MyOwner) == 1 and GetTick () - MoveTestTime > 1000 and MoveTestTime ~= 0) then
                        MoveTestTime = 0
                        MoveStartTime = GetTick () - 1000
                elseif (GetV (V_MOTION,MyID) ~= 0) then
                        MoveTestTime = 0
                end

                if (GetTick () - MoveStartTime > 800 and MoveStartTime ~= 0) then
                        if (GetV (V_MOTION,MyOwner) == 1) then
                                MoveEndTime = GetTick ()
                        end

                        if (GetTick () - MoveEndTime > 500 or (GetV (V_MOTION,MyOwner) ~= 1 and MyState == ATTACK_ST)) then
                                MoveStartTime = 0
                                MoveDistance = 0
                        else
                                return true
                        end
                end
        end
        return false        
end

function        FreedomTimer (id,start)

        local IDX, IDY = GetV (V_POSITION,id)
        local MyX, MyY = GetV (V_POSITION,MyID)
        if (FreedomStartTime == 0 and math.abs(MyX - IDX) == 1 and MyY - IDY == 0) then
                return false
        end
        
        if (GetV(V_HP,MyID) == GetV(V_MAXHP,MyID) and GetV(V_SP,MyID) == GetV(V_MAXSP,MyID) and GetV(V_MOTION,id) == 6) then
                if (FreedomStartTime == 0) then
                        FreedomStartTime = GetTick() + math.random(0,start)
                end
        elseif (FreedomStartTime ~= 0) then
                FreedomStartTime = 0
                FreedomTime = 0
        end

        if (GetTick() - FreedomStartTime >= start and FreedomStartTime ~= 0) then
                return true
        else
                return false
        end
end

function        AutoSkillTimer (id)

        if (GetTick () - AutoSkillAttackTime[id] >= AutoSkillConsumeTime[id] and GetTick () - AutoSkillAttackTime[0] >= AutoSkillConsumeTime[0]) then
                AutoSkillAttackTime[id] = GetTick ()
                AutoSkillAttackTime[0] = GetTick ()
                return true
        else
                return false
        end
end

function        AutoSkillSPChecker (id,type)

        local MySP = GetV(V_SP,MyID)
        local MyMSP = GetV(V_MAXSP,MyID)
        local ASSP = AutoSkillSP[id]
        if ((type == "MIN" and MySP >= ASSP) or (type == "MAX" and MySP > MyMSP*AutoSkillConfig2[1])) then
                return true
        elseif (type == "MIX") then
                local SPStandby = AutoSkillSP[1]
                if (AutoSkillConfig1[2] == 1) then
                        SPStandby = SPStandby+AutoSkillSP[2]
                end
                if (AutoSkillConfig1[3] == 1) then
                        SPStandby = SPStandby+AutoSkillSP[3]
                end
                if (MySP >= SPStandby) then
                        return true
                end
        end

        return false
end

function        FreedomMove (rest)

        if (FreedomTime == 0) then
                FreedomTime = GetTick() + math.random(0,rest)
        elseif (GetTick() - FreedomTime >= rest) then
                FreedomStartTime = 0
                FreedomTime = 0
                return
        end

        if (GetTick() - FreedomDelayTime >= FreedomMoveDelayFrom) then
                MyDestX, MyDestY = GetV (V_POSITION,MyID);
                MyDestX = MyDestX + math.random(-FreedomDistance,FreedomDistance);
                MyDestY = MyDestY + math.random(-FreedomDistance,FreedomDistance);
                local OwnerX, OwnerY = GetOwnerPosition (MyID)
                if ( GetDistance (OwnerX,OwnerY,MyDestX,MyDestY) <= 12 ) then
                        FreedomDelayTime = GetTick () + math.random(0,FreedomMoveDelayTo);
                        Move (MyID,MyDestX,MyDestY)
                end
                return
        end
end


function        SaveMode ()

        local SM = io.open ( "./AI/USER_AI/SavedMode.lua", "w+" )
        SM:write ("AttackMode        = ",AttackMode,"\n","AutoSkill        = ",AutoSkill)
        SM:close ()
end


function        SaveFriendList ()

        local SL = io.open (FriendListName, "w+" )
        SL:write ("SavedFriend={")
        for i,s in pairs(SavedFriend) do
                SL:write ("[",i,"]=",s,",")
        end
        SL:write ("}")
        SL:close ()
end




function AI(myid)

        MyID = myid
        local msg        = GetMsg (myid)                        -- command
        local rmsg        = GetResMsg (myid)                -- reserved command

        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

        if(MyFriend ~= -1) then                                                -- [FD_SYS]FOLLOW_FRIEND
                if (ScoreTimer == 0) then
                        ScoreTimer = GetTick ()
                end

                if (GetTick () - ScoreTimer >= 30000) then
                        ScoreTimer = GetTick ()
                        if (FreedomTimer (MyFriend,FreedomRest*2) == true or FriendList[MyFriend] > 100000) then        -- [FD_SYS]ADD_SCORE_FOR_SAVEDFRIEND
                                FriendList[MyFriend] = FriendList[MyFriend] + ScoreGain*0.1
                        elseif (GetV (V_TARGET,MyEnemy) == FD) then
                                FriendList[MyFriend] = FriendList[MyFriend] + ScoreGain*1.5
                        else
                                FriendList[MyFriend] = FriendList[MyFriend] + ScoreGain
                        end
                        SavedFriend[MyFriend] = FriendList[MyFriend]
                        ScoreSaveNeed = 1
                end
        end

        if (ScoreSaveNeed == 1) then
                if (ScoreSaveTimer == 0) then
                        ScoreSaveTimer = GetTick ()
                end

                if (GetTick () - ScoreSaveTimer >= 120000) then
                        ScoreSaveTimer = GetTick ()

                        for i,s in pairs(SavedFriend) do                -- [FD_SYS]LESS_SCORE_FOR_SAVEDFRIEND
                                if (i ~= MyFriend) then
                                        local Score = s - ScoreLoss
                                        if (Score <= 0) then
                                                SavedFriend = nil
                                        else
                                                SavedFriend = Score
                                        end
                                end
                        end

                        SaveFriendList ()                                -- [FD_SYS]SAVE_FRIEND
                        ScoreSaveNeed = 0
                        TraceAI ("Score Saved")
                end
        end

        if (MyState == IDLE_ST) then
                OnIDLE_ST ()
        elseif (MyState == CHASE_ST) then                                       
                OnCHASE_ST ()
        elseif (MyState == ATTACK_ST) then
                OnATTACK_ST ()
        elseif (MyState == FOLLOW_ST) then
                OnFOLLOW_ST ()
        elseif (MyState == CHECK_ST) then
                OnCHECK_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

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.