| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817 |
- local netActorController = class("netActorController")
- netActorController.NAME = "netActorController"
- local actorUtils = requireProxy( "actorUtils" )
- -- 状态队列
- local ACTION_CACHE =
- {
- WALK = 1, -- 走
- RUN = 2, -- 跑
- RIDE_RUN = 3, -- 坐骑 跑
- STUCK = 4, -- 受击
- SKILL_ACTION = 5, -- 魔法 纯动作
- SKILL_MAGIC = 6, -- 魔法 纯魔法 -- 无用
- SKILL_ACTION_MAGIC = 7, -- 魔法 动作 + 魔法
- DASH = 8, -- 野蛮
- ONDASH = 9, -- 被野蛮,被推开
- SBYS = 10, -- 十步一杀
- QLS = 11, -- 擒龙手
- SNEAK = 12, -- 潜行
- ZXC = 27, -- 追心刺
- }
- function netActorController:ctor()
- self.mHandleOnActCompleted = {}
- self.mHandleOnActBegin = {}
- self.mNextActionCache = {}
- end
- function netActorController:destory()
- end
- function netActorController:Init()
- end
- function netActorController:Cleanup(cleanHandler)
- if cleanHandler == nil then
- cleanHandler = true
- end
- if cleanHandler then
- self.mHandleOnActCompleted = {}
- self.mHandleOnActBegin = {}
- end
- self.mNextActionCache = {}
- end
- -----------------------------------------------------------------------------
- function netActorController:AddHandleOnActCompleted(func)
- table.insert(self.mHandleOnActCompleted, func)
- end
- function netActorController:AddHandleOnActBegin(func)
- table.insert(self.mHandleOnActBegin, func)
- end
- -----------------------------------------------------------------------------
- function netActorController:handleActionBegin(actor, act)
- -- Action begin handle.
- for k, v in pairs(self.mHandleOnActBegin) do
- v(actor, act)
- end
- end
- function netActorController:handleActionCompleted(actor, act)
- -- Action completion handle.
- for k, v in pairs(self.mHandleOnActCompleted) do
- v(actor, act)
- end
- --重置加速
- if actor:GetIsSpeedup() then
- actor:SetIsSpeedup(false)
- actor:dirtyAnimFlag()
- end
- if actor:GetIsFullSpeedup() then
- actor:SetIsFullSpeedup(false)
- actor:dirtyAnimFlag()
- end
- if actor:GetIsMoreFullSpeedup() then
- actor:SetIsMoreFullSpeedup(false)
- actor:dirtyAnimFlag()
- end
- if actor:GetIsMoreSpeedRate() then
- actor:SetIsMoreSpeedRate(false)
- actor:dirtyAnimFlag()
- end
- --确认
- actor:SetConfirmed(true)
- local isIdleAction = false
- local nextActionCache = self.mNextActionCache[actor:GetID()]
- if nextActionCache and nextActionCache[1] then
- local nextAction = table.remove(nextActionCache, 1)
- if nextActionCache[1] ~= nil and nextActionCache[1].act ~= ACTION_CACHE.STUCK then
- actor:SetIsSpeedup(true)
- actor:SetIsMoreSpeedRate(CHECK_SETTING(global.MMO.SETTING_IDX_MORE_FAST) == 1)
- -- 堆积的太多,更快的加速
- if nextActionCache[2] ~= nil and nextActionCache[3] ~= nil then
- actor:SetIsFullSpeedup(true)
- actor:SetIsMoreFullSpeedup(CHECK_SETTING(global.MMO.SETTING_IDX_MORE_FAST) == 1)
- end
- end
- if nextAction.act == ACTION_CACHE.STUCK then
- actor:SetAction(global.MMO.ACTION_STUCK)
- elseif nextAction.act == ACTION_CACHE.WALK then
- actor:SetMoveTo(nextAction.pos)
- actor:SetAction(global.MMO.ACTION_WALK)
- actor:SetConfirmed(true)
- elseif nextAction.act == ACTION_CACHE.SNEAK then
- actor:SetMoveTo(nextAction.pos)
- actor:SetAction(global.MMO.ACTION_ASSASSIN_SNEAK)
- actor:SetConfirmed(true)
- elseif nextAction.act == ACTION_CACHE.RUN then
- actor:SetMoveTo(nextAction.pos)
- actor:SetAction(global.MMO.ACTION_RUN)
- actor:SetConfirmed(true)
- elseif nextAction.act == ACTION_CACHE.RIDE_RUN then
- actor:SetMoveTo(nextAction.pos)
- actor:SetAction(global.MMO.ACTION_RIDE_RUN)
- actor:SetConfirmed(true)
- elseif nextAction.act == ACTION_CACHE.SKILL_ACTION then
- local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
- SkillProxy:actorEnterAction(nextAction.jsonData, nextAction.isMagic)
- local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
- SkillProxy:requestSkillPresent(nextAction.jsonData, 1)
- if nextAction.skillStage == 2 then
- local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
- SkillProxy:requestSkillPresent(nextAction.jsonData, 2)
- end
- actor.skillStage = nextAction.skillStage
- actor.skillID = nextAction.jsonData.MagicID
- elseif nextAction.act == ACTION_CACHE.SKILL_ACTION_MAGIC then
- local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
- SkillProxy:actorEnterAction(nextAction.jsonData, nextAction.isMagic)
- SkillProxy:requestSkillPresent(nextAction.jsonData, 3)
-
- elseif nextAction.act == ACTION_CACHE.DASH then
- local msgHdr = nextAction.msgHdr
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
- local dir = msgHdr.param3
- local time = msgHdr.recog * 0.001
- local sMapX = 0
- local sMapY = 0
- if H16Bit(msgHdr.param1) > 0 and H16Bit(msgHdr.param2) > 0 then
- mapX = L16Bit(msgHdr.param1)
- mapY = H16Bit(msgHdr.param1)
- sMapX = L16Bit(msgHdr.param2)
- sMapY = H16Bit(msgHdr.param2)
- end
- if ((mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY())) and time > 0 then
- actorUtils.actorDash(actor, mapX, mapY, sMapX, sMapY, dir, time)
- else
- isIdleAction = true
- end
- elseif nextAction.act == ACTION_CACHE.ONDASH then
- local msgHdr = nextAction.msgHdr
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
- local dir = msgHdr.param3
- local time = msgHdr.recog
- local moveTime = L16Bit(time) * 0.001
- local idleTime = math.min(H16Bit(time) * 0.001, 5)
- local sMapX = 0
- local sMapY = 0
- if H16Bit(msgHdr.param1) > 0 and H16Bit(msgHdr.param2) > 0 then
- mapX = L16Bit(msgHdr.param1)
- mapY = H16Bit(msgHdr.param1)
- sMapX = L16Bit(msgHdr.param2)
- sMapY = H16Bit(msgHdr.param2)
- end
- if ((mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY())) and moveTime > 0 then
- actorUtils.actorOnDash(actor, mapX, mapY, sMapX, sMapY, dir, moveTime, idleTime)
- else
- isIdleAction = true
- end
-
- elseif nextAction.act == ACTION_CACHE.SBYS then
- local msgHdr = nextAction.msgHdr
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
- local dir = msgHdr.param3
- if (mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) then
- actorUtils.actorSBYS(actor, mapX, mapY, dir)
- else
- isIdleAction = true
- end
- elseif nextAction.act == ACTION_CACHE.QLS then
- local msgHdr = nextAction.msgHdr
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
- local dir = msgHdr.param3
- if (mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) then
- actorUtils.actorQLS(actor, mapX, mapY, dir)
- else
- isIdleAction = true
- end
- elseif nextAction.act == ACTION_CACHE.ZXC then
- local msgHdr = nextAction.msgHdr
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
- local dir = H16Bit(msgHdr.param3) == 0 and L16Bit(msgHdr.param3) or L16Bit(msgHdr.param3)
- local time = msgHdr.recog * 0.001
- if ((mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY())) and time > 0 then
- actorUtils.actorZhuiXinCi(actor, mapX, mapY, dir, time)
- else
- isIdleAction = true
- end
-
- else
- isIdleAction = true
- end
- elseif act == global.MMO.ACTION_DIE or act == global.MMO.ACTION_DEATH then
- elseif act == global.MMO.ACTION_CAVE then
- else
- isIdleAction = true
- end
- if isIdleAction then
- --移动优化
- if act == global.MMO.ACTION_WALK or act == global.MMO.ACTION_RUN or act == global.MMO.ACTION_RIDE_RUN or act == global.MMO.ACTION_ASSASSIN_SNEAK then
- actor:setPosition(actor.mTargePos.x, actor.mTargePos.y)
- end
- actor:SetAction(global.MMO.ACTION_IDLE)
- end
- end
- function netActorController:handleActionProcess(actor)
- end
- -----------------------------------------------------------------------------
- function netActorController:handleActorOutOfView(actor)
- self.mNextActionCache[actor:GetID()] = nil
- end
- function netActorController:handle_Die(actor, msgHdr, msgData)
- self:SyncLatestPosition(actor, false)
- self.mNextActionCache[actor:GetID()] = nil
- -- 死亡时不拉坐标了,会闪现
- global.actorManager:SetActorMapXY(actor, msgHdr.param1, msgHdr.param2)
- actor:stopAnimToFrame(nil)
- actor:SetAction(global.MMO.ACTION_DIE, true)
- end
- function netActorController:handle_DeathSkeleton(actor, msgHdr, msgData)
- self:SyncLatestPosition(actor, false)
- self.mNextActionCache[actor:GetID()] = nil
- -- 死亡时不拉坐标了,会闪现
- global.actorManager:SetActorMapXY(actor, msgHdr.param1, msgHdr.param2)
- actor:stopAnimToFrame(nil)
- actor:SetAction(global.MMO.ACTION_DEATH, true)
- end
- function netActorController:handle_Revive(actor, jsonData)
- self.mNextActionCache[actor:GetID()] = nil
- -- feature
- if jsonData.Hp and jsonData.MaxHp then
- actor:SetHPHUD(jsonData.Hp, jsonData.MaxHp)
- end
- -- To map grid position
- local actorPos = global.sceneManager:MapPos2WorldPos(jsonData.X, jsonData.Y, true)
- local action = actor:IsMonster() and global.MMO.ACTION_BORN or global.MMO.ACTION_IDLE
- actor:SetConfirmed(true)
- actor:SetIsArrived(true)
- actor:stopAnimToFrame(nil)
- actor:setPosition(actorPos.x, actorPos.y)
- actor:SetDirection(jsonData.Dir)
- actor:SetAction(action, true)
- actor:dirtyAnimFlag()
- global.actorManager:SetActorMapXY(actor, jsonData.X, jsonData.Y)
- local noticeData = {}
- noticeData.actor = actor
- noticeData.actorID = jsonData.UserID
- global.Facade:sendNotification(global.NoticeTable.ActorRevive, noticeData)
- end
- function netActorController:handleActorSitdown(actor, jsonData)
- -- 死亡状态无法切换
- if actor:IsDie() or actor:IsDeath() then
- return nil
- end
- if global.MMO.ACTION_IDLE == actor:GetAction() then
- actor:SetDirection(jsonData.Dir)
- actor:SetAction(global.MMO.ACTION_SITDOWN)
- else
- -- Another action is running
- local netAct = {}
- netAct.act = ACTION_CACHE.SITDOWN
- netAct.Dir = jsonData.Dir
- if self.mNextActionCache[actor:GetID()] == nil then
- self.mNextActionCache[actor:GetID()] = {}
- end
- table.insert(self.mNextActionCache[actor:GetID()], netAct)
- end
- self:CheckFastCurrentAction(actor)
- end
- function netActorController:handleActorMining(actor, jsonData)
- -- 死亡状态无法切换
- if actor:IsDie() or actor:IsDeath() then
- return nil
- end
- if global.MMO.ACTION_IDLE == actor:GetAction() then
- actor:SetDirection(jsonData.Dir)
- actor:SetAction(global.MMO.ACTION_MINING)
- else
- -- Another action is running
- local netAct = {}
- netAct.act = ACTION_CACHE.MINING
- netAct.Dir = jsonData.Dir
- if self.mNextActionCache[actor:GetID()] == nil then
- self.mNextActionCache[actor:GetID()] = {}
- end
- table.insert(self.mNextActionCache[actor:GetID()], netAct)
- end
- self:CheckFastCurrentAction(actor)
- end
- function netActorController:handle_MSG_SC_ACTOR_WALK(actor, msgHdr)
- -- 死亡状态无法切换
- if actor:IsDie() or actor:IsDeath() then
- return nil
- end
- local p = { x = msgHdr.param1, y = msgHdr.param2 }
- if global.MMO.ACTION_IDLE == actor:GetAction() then
- local act = global.MMO.ACTION_WALK
- if actor:GetValueByKey(global.MMO.ACT_SNEAK) then
- act = global.MMO.ACTION_ASSASSIN_SNEAK
- end
- actor:SetMoveTo(p)
- actor:SetAction(act)
- actor:SetConfirmed(true)
- else
- -- Another action is running
- local act = ACTION_CACHE.WALK
- if actor:GetValueByKey(global.MMO.ACT_SNEAK) then
- act = ACTION_CACHE.SNEAK
- end
- local netAct = {}
- netAct.act = act
- netAct.pos = p
- if self.mNextActionCache[actor:GetID()] == nil then
- self.mNextActionCache[actor:GetID()] = {}
- end
- table.insert(self.mNextActionCache[actor:GetID()], netAct)
- end
- self:CheckFastCurrentAction(actor)
- end
- function netActorController:handle_MSG_SC_ACTOR_RUN(actor, msgHdr)
- -- 死亡状态无法切换
- if actor:IsDie() or actor:IsDeath() then
- return nil
- end
- local p = { x = msgHdr.param1, y = msgHdr.param2 }
- if global.MMO.ACTION_IDLE == actor:GetAction() then
- actor:SetMoveTo(p)
- actor:SetAction(global.MMO.ACTION_RUN)
- actor:SetConfirmed(true)
- else
- -- Another action is running
- local netAct = {}
- netAct.act = ACTION_CACHE.RUN
- netAct.pos = p
- if self.mNextActionCache[actor:GetID()] == nil then
- self.mNextActionCache[actor:GetID()] = {}
- end
- table.insert(self.mNextActionCache[actor:GetID()], netAct)
- end
- self:CheckFastCurrentAction(actor)
- end
- function netActorController:handle_MSG_SC_ACTOR_RIDE_RUN(actor, msgHdr)
- -- 死亡状态无法切换
- if actor:IsDie() or actor:IsDeath() then
- return nil
- end
- local p = { x = msgHdr.param1, y = msgHdr.param2 }
- if global.MMO.ACTION_IDLE == actor:GetAction() then
- actor:SetMoveTo(p)
- actor:SetAction(global.MMO.ACTION_RIDE_RUN)
- actor:SetConfirmed(true)
- else
- -- Another action is running
- local netAct = {}
- netAct.act = ACTION_CACHE.RIDE_RUN
- netAct.pos = p
- if self.mNextActionCache[actor:GetID()] == nil then
- self.mNextActionCache[actor:GetID()] = {}
- end
- table.insert(self.mNextActionCache[actor:GetID()], netAct)
- end
- self:CheckFastCurrentAction(actor)
- end
- function netActorController:handle_MSG_SC_ACTOR_STUCK(actor)
- -- 死亡状态无法切换
- if actor:IsDie() or actor:IsDeath() then
- return nil
- end
- -- 受击弯腰,只保留一个
- if global.MMO.ACTION_IDLE == actor:GetAction() then
- actor:SetAction(global.MMO.ACTION_STUCK)
- else
- if self.mNextActionCache[actor:GetID()] == nil then
- self.mNextActionCache[actor:GetID()] = {}
- end
- local found = false
- for i, v in ipairs(self.mNextActionCache[actor:GetID()]) do
- if v.act == ACTION_CACHE.STUCK then
- found = true
- break
- end
- end
- if not found then
- local netAct = {}
- netAct.act = ACTION_CACHE.STUCK
- table.insert(self.mNextActionCache[actor:GetID()], netAct)
- end
- end
- self:CheckFastCurrentAction(actor)
- end
- function netActorController:handle_MSG_SC_NET_PLAYER_ATTACK(actor, msgHdr, jsonData)
- -- 死亡状态无法切换
- if actor:IsDie() or actor:IsDeath() then
- return nil
- end
- if actor:IsMonster() and msgHdr.param3 > 0 then
- return nil
- end
- if global.MMO.ACTION_IDLE == actor:GetAction() then
- local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
- SkillProxy:actorEnterAction(jsonData, false)
- SkillProxy:requestSkillPresent(jsonData, 3)
- else
- -- Another action is running
- local netAct = {}
- netAct.act = ACTION_CACHE.SKILL_ACTION_MAGIC
- netAct.msgHdr = msgHdr
- netAct.jsonData = jsonData
- netAct.isMagic = false
- if self.mNextActionCache[actor:GetID()] == nil then
- self.mNextActionCache[actor:GetID()] = {}
- end
- table.insert(self.mNextActionCache[actor:GetID()], netAct)
- end
- self:CheckFastCurrentAction(actor)
- end
- function netActorController:handle_MSG_SC_PLAYER_SKILL_LAUNCH_SUCCESS(actor, msgHdr, jsonData)
- -- 死亡状态无法切换
- if actor:IsDie() or actor:IsDeath() then
- return nil
- end
- if global.MMO.ACTION_IDLE == actor:GetAction() then
- local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
- SkillProxy:actorEnterAction(jsonData, true)
- SkillProxy:requestSkillPresent(jsonData, 1)
- actor.skillStage = 1
- actor.skillID = jsonData.MagicID
- else
- -- Another action is running
- local netAct = {}
- netAct.act = ACTION_CACHE.SKILL_ACTION
- netAct.jsonData = jsonData
- netAct.msgHdr = msgHdr
- netAct.isMagic = true
- netAct.skillStage = 1
- if self.mNextActionCache[actor:GetID()] == nil then
- self.mNextActionCache[actor:GetID()] = {}
- end
- table.insert(self.mNextActionCache[actor:GetID()], netAct)
- end
- self:CheckFastCurrentAction(actor)
- end
- function netActorController:handle_MSG_SC_PLAYER_SKILL_MAGIC_SUCCESS(actor, msgHdr, jsonData)
- -- 死亡状态无法切换
- if actor:IsDie() or actor:IsDeath() then
- return nil
- end
- if global.MMO.ACTION_IDLE == actor:GetAction() then
- local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
- SkillProxy:requestSkillPresent(jsonData, 2)
- elseif (global.MMO.ACTION_ATTACK == actor:GetAction() or global.MMO.ACTION_SKILL == actor:GetAction() or CheckInSkillAction(actor:GetAction())) and actor.skillStage == 1 and actor.skillID == jsonData.MagicID then
- actor.skillStage = 2
- local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
- SkillProxy:requestSkillPresent(jsonData, 2)
- else
- -- Another action is running
- if self.mNextActionCache[actor:GetID()] == nil then
- self.mNextActionCache[actor:GetID()] = {}
- end
- if jsonData.showSkillMaigc then
- local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
- SkillProxy:requestSkillPresent(jsonData, 3)
- else
- for i, v in ipairs(self.mNextActionCache[actor:GetID()]) do
- if v.act == ACTION_CACHE.SKILL_ACTION and v.skillStage == 1 then
- v.msgHdr = msgHdr
- v.jsonData = jsonData
- v.skillStage = 2
- break
- end
- end
- end
- end
- end
- function netActorController:handle_MSG_SC_PLAYER_SKILL_27_SUCCESS(actor, msgHdr)
- -- 野蛮
- if actor:IsDie() or actor:IsDeath() then
- return nil
- end
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
- local dir = H16Bit(msgHdr.param3) == 0 and L16Bit(msgHdr.param3) or L16Bit(msgHdr.param3)
- local time = msgHdr.recog * 0.001
- local skillId = H16Bit(msgHdr.param3) > 0 and H16Bit(msgHdr.param3) or 0
- local sMapX = 0
- local sMapY = 0
- if H16Bit(msgHdr.param1) > 0 and H16Bit(msgHdr.param2) > 0 then
- mapX = L16Bit(msgHdr.param1)
- mapY = H16Bit(msgHdr.param1)
- sMapX = L16Bit(msgHdr.param2)
- sMapY = H16Bit(msgHdr.param2)
- end
- if skillId == 0 then
- if global.MMO.ACTION_IDLE == actor:GetAction() then
- if (mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) and time > 0 then
- actorUtils.actorDash(actor, mapX, mapY, sMapX, sMapY, dir, time)
- else
- --执行野蛮失败撞墙动作
- actor:SetAction(global.MMO.ACTION_DASH_FAIL)
- end
- else
- if (mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) and time > 0 then
- -- Another action is running
- local netAct = {}
- netAct.act = ACTION_CACHE.DASH
- netAct.msgHdr = msgHdr
- if self.mNextActionCache[actor:GetID()] == nil then
- self.mNextActionCache[actor:GetID()] = {}
- end
- table.insert(self.mNextActionCache[actor:GetID()], netAct)
- end
- end
- else
- if global.MMO.ACTION_IDLE == actor:GetAction() then
- if (mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) and time > 0 then
- actorUtils.actorZhuiXinCi(actor, mapX, mapY, dir)
- end
- else
- -- Another action is running
- local netAct = {}
- netAct.act = ACTION_CACHE.ZXC
- netAct.msgHdr = msgHdr
- if self.mNextActionCache[actor:GetID()] == nil then
- self.mNextActionCache[actor:GetID()] = {}
- end
- table.insert(self.mNextActionCache[actor:GetID()], netAct)
- end
- end
- self:CheckFastCurrentAction(actor)
- end
- function netActorController:handle_MSG_SC_PLAYER_SKILL_27_BACKSTEP(actor, msgHdr)
- -- 被野蛮,被推开
- if actor:IsDie() or actor:IsDeath() then
- return nil
- end
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
- local dir = msgHdr.param3
- local time = msgHdr.recog
- local moveTime = L16Bit(time) * 0.001
- local idleTime = math.min(H16Bit(time) * 0.001, 5)
- local sMapX = 0
- local sMapY = 0
- if H16Bit(msgHdr.param1) > 0 and H16Bit(msgHdr.param2) > 0 then
- mapX = L16Bit(msgHdr.param1)
- mapY = H16Bit(msgHdr.param1)
- sMapX = L16Bit(msgHdr.param2)
- sMapY = H16Bit(msgHdr.param2)
- end
- if global.MMO.ACTION_IDLE == actor:GetAction() then
- if (mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) and moveTime > 0 then
- actorUtils.actorOnDash(actor, mapX, mapY, sMapX, sMapY, dir, moveTime, idleTime)
- end
- else
- -- Another action is running
- local netAct = {}
- netAct.act = ACTION_CACHE.ONDASH
- netAct.msgHdr = msgHdr
- if self.mNextActionCache[actor:GetID()] == nil then
- self.mNextActionCache[actor:GetID()] = {}
- end
- table.insert(self.mNextActionCache[actor:GetID()], netAct)
- end
- self:CheckFastCurrentAction(actor)
- end
- function netActorController:handle_MSG_SC_PLAYER_SKILL_82_SUCCESS(actor, msgHdr)
- -- 十步一杀 瞬移
- if actor:IsDie() or actor:IsDeath() then
- return nil
- end
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
- local dir = msgHdr.param3
- if global.MMO.ACTION_IDLE == actor:GetAction() then
- if( mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) then
- actorUtils.actorSBYS(actor, mapX, mapY, dir)
- end
- else
- -- Another action is running
- local netAct = {}
- netAct.act = ACTION_CACHE.SBYS
- netAct.msgHdr = msgHdr
- if self.mNextActionCache[actor:GetID()] == nil then
- self.mNextActionCache[actor:GetID()] = {}
- end
- table.insert(self.mNextActionCache[actor:GetID()], netAct)
- end
- self:CheckFastCurrentAction(actor)
- end
- function netActorController:handle_MSG_SC_PLAYER_SKILL_71_SUCCESS(actor, msgHdr)
- -- 擒龙手 瞬移
- if actor:IsDie() or actor:IsDeath() then
- return nil
- end
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
- local dir = msgHdr.param3
- if global.MMO.ACTION_IDLE == actor:GetAction() then
- if (mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) then
- actorUtils.actorQLS(actor, mapX, mapY, dir)
- end
- else
- -- Another action is running
- local netAct = {}
- netAct.act = ACTION_CACHE.QLS
- netAct.msgHdr = msgHdr
- if self.mNextActionCache[actor:GetID()] == nil then
- self.mNextActionCache[actor:GetID()] = {}
- end
- table.insert(self.mNextActionCache[actor:GetID()], netAct)
- end
- self:CheckFastCurrentAction(actor)
- end
- function netActorController:handle_Move_Force(actor, jsonData)
- self.mNextActionCache[actor:GetID()] = nil
- local posOfAccepted = global.sceneManager:MapPos2WorldPos(jsonData.mapX, jsonData.mapY, true)
- actor:SetAction(global.MMO.ACTION_IDLE, true)
- actor.mIsArrived = true
- actor.mIsConfirmed = true
- actor:SetDirection(jsonData.dir)
- actor:setPosition(posOfAccepted.x, posOfAccepted.y)
- global.actorManager:SetActorMapXY(actor, jsonData.mapX, jsonData.mapY)
- end
- function netActorController:handle_FlyIn(actor, msgHdr)
- self.mNextActionCache[actor:GetID()] = nil
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
- local dir = msgHdr.param3
- local posOfAccepted = global.sceneManager:MapPos2WorldPos(mapX, mapY, true)
- actor:SetAction(global.MMO.ACTION_IDLE, true)
- actor:SetIsArrived(true)
- actor:SetConfirmed(true)
- actor:SetDirection(dir)
- actor:setPosition(posOfAccepted.x, posOfAccepted.y)
- global.actorManager:SetActorMapXY( actor, mapX, mapY )
- end
- function netActorController:handle_FlyIn2(actor, msgHdr)
- self.mNextActionCache[actor:GetID()] = nil
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
- local dir = msgHdr.param3
- local posOfAccepted = global.sceneManager:MapPos2WorldPos(mapX, mapY, true)
- actor:SetAction(global.MMO.ACTION_IDLE, true)
- actor:SetIsArrived(true)
- actor:SetConfirmed(true)
- actor:SetDirection(dir)
- actor:setPosition(posOfAccepted.x, posOfAccepted.y)
- global.actorManager:SetActorMapXY( actor, mapX, mapY )
- end
- function netActorController:cleanupCacheByActorID(actorID)
- self.mNextActionCache[actorID] = nil
- end
- function netActorController:SyncLatestPosition(actor, updateCurrPosition)
- local p1 = self.mNextActionCache[actor:GetID()]
- if p1 == nil then p1 = {} end
- local lastMoveAct = nil
- for k, v in pairs(p1) do
- local netAct = v
- if ACTION_CACHE.WALK == netAct.act or ACTION_CACHE.RUN == netAct.act or ACTION_CACHE.RIDE_RUN == netAct.act then
- lastMoveAct = netAct
- end
- end
- if lastMoveAct then
- local mapX = lastMoveAct.pos.x
- local mapY = lastMoveAct.pos.y
- local targetPos = global.sceneManager:MapPos2WorldPos(mapX, mapY, true)
- actor:setPosition(targetPos.x, targetPos.y)
- global.actorManager:SetActorMapXY(actor, mapX, mapY)
- elseif updateCurrPosition then
- if actor.mCurrentActT > 0.0001 then
- actor:SetCurrActTime(0)
- local mapX = actor:GetMapX()
- local mapY = actor:GetMapY()
- local targetPos = global.sceneManager:MapPos2WorldPos(mapX, mapY, true)
- actor:setPosition(targetPos.x, targetPos.y)
- end
- end
- -- reset state
- actor:SetIsArrived(true)
- actor:SetConfirmed(true)
- end
- function netActorController:CheckFastCurrentAction(actor)
- -- if not ((actor:IsPlayer() or actor:IsMonster())) then
- -- return
- -- end
- -- if global.MMO.ACTION_IDLE == actor:GetAction() then
- -- return
- -- end
- end
- function netActorController:handle_ActorMapXYChange(actor, mapX, mapY)
- global.Facade:sendNotification(global.NoticeTable.ActorMapXYChange, { actor = actor, actorID = actor:GetID() })
- end
- function netActorController:handle_MSG_SC_NET_MONSTER_BORN(actor, msgHdr, msgData)
- end
- function netActorController:handle_MSG_SC_NET_MONSTER_CAVE(actor, msgHdr, msgData)
- end
- return netActorController
|