| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457 |
- local gameMapController = class("gameMapController")
- gameMapController.NAME = "gameMapController"
- local optionsUtils = requireProxy("optionsUtils")
- local cjson = require("cjson")
- local fireSet = {
- [4] = 27, -- 困魔咒
- [5] = 36, -- 正常火墙
- }
- -- 转换race, 这些是守卫
- local convertDefenderRace =
- {
- [11] = 1,
- [55] = 1,
- [110] = 1,
- [111] = 1,
- [112] = 1,
- }
- local function converActorData(msgHdr, jsonData)
- -- 为了服务器下发的数据包更小,同时为了客户端的逻辑改动更小,将受到的数据转化一下
- ---------------------------------------------------------------------------
- -- json数组 -> json对象
- jsonData.RaceServer = jsonData.rs
- if jsonData.info then
- jsonData.UserID = jsonData.info[1]
- jsonData.Name = jsonData.info[2]
- jsonData.sex = jsonData.info[3]
- jsonData.Hair = jsonData.info[4]
- jsonData.Job = jsonData.info[5]
- end
- if jsonData.sp then
- jsonData.WalkCurrSpeed = jsonData.sp[1]
- jsonData.RunCurrSpeed = jsonData.sp[2]
- jsonData.AttackCurrSpeed = jsonData.sp[3]
- jsonData.MagicCurrSpeed = jsonData.sp[4]
- end
- if jsonData.id then
- jsonData.clothID = jsonData.id[1]
- jsonData.weaponID = jsonData.id[2]
- jsonData.Cap = jsonData.id[3]
- jsonData.clothEff = jsonData.id[4]
- jsonData.weaponEff = jsonData.id[5]
- jsonData.shieldID = jsonData.id[6]
- jsonData.shieldEffect = jsonData.id[7]
- end
- if jsonData.wex then --左武器外观ID
- jsonData.leftWeaponID = jsonData.wex
- end
- if jsonData.wfex then --左武器外观特效
- jsonData.leftWeaponEff = jsonData.wfex
- end
- if jsonData.horse then
- jsonData.mountID = jsonData.horse[1]
- jsonData.mountEff = jsonData.horse[2]
- jsonData.mountCloth = jsonData.horse[3]
- jsonData.doubleTag = jsonData.horse[4]
- jsonData.doubleUserId = jsonData.horse[5]
- end
- if jsonData.cg then
- jsonData.ShenMiRen = bit.band(bit.rshift(jsonData.cg, 0), 1)
- jsonData.RangeCanFindMe = bit.band(bit.rshift(jsonData.cg, 1), 1)
- jsonData.OffLine = bit.band(bit.rshift(jsonData.cg, 2), 1)
- end
- if jsonData.state then
- jsonData.Group = jsonData.state[1]
- jsonData.stallname = jsonData.state[2]
- jsonData.castlename = jsonData.state[3]
- jsonData.Candle = tonumber(jsonData.state[4])
- end
- if jsonData.guild then
- jsonData.GuildID = jsonData.guild[1]
- jsonData.GuildName = jsonData.guild[2]
- jsonData.Rank = jsonData.guild[3]
- jsonData.RankName = jsonData.guild[4]
- end
- if jsonData.ms then
- jsonData.MasterId = jsonData.ms[1]
- end
- if jsonData.ow then
- jsonData.OwnerID = jsonData.ow[1]
- jsonData.OwnerName = jsonData.ow[2]
- end
- if jsonData.data then
- jsonData.nLevel = jsonData.data[1]
- jsonData.Hp = jsonData.data[2]
- jsonData.MaxHp = jsonData.data[3]
- jsonData.Color = jsonData.data[4]
- jsonData.StoneMode = jsonData.data[5]
- jsonData.pklv = jsonData.data[6]
- jsonData.Through = jsonData.data[7]
- jsonData.ActionType = jsonData.data[8]
- jsonData.Mp = jsonData.data[9]
- jsonData.MaxMp = jsonData.data[10]
- end
- if jsonData.NoShow and jsonData.NoShow ~= "" then
- local paramArray = string.split(jsonData.NoShow,"#")
- jsonData.noShowName = tonumber(paramArray[1])
- jsonData.noShowHPBar = tonumber(paramArray[2])
- end
- if jsonData.csd then
- jsonData.gmData = jsonData.csd
- end
- ---------------------------------------------------------------------------
- ---------------------------------------------------------------------------
- -- 消息头数据
- -- race & raceImg
- local recog = msgHdr.recog
- jsonData.race = L16Bit(recog)
- jsonData.raceImg = H16Bit(recog)
- -- nActorId
- local param1 = msgHdr.param1
- jsonData.nActorId = param1
- -- x y
- local param2 = msgHdr.param2
- jsonData.X = L16Bit(param2)
- jsonData.Y = H16Bit(param2)
-
- -- dir & type
- local param3 = msgHdr.param3
- jsonData.type = L16Bit(param3)
- jsonData.Dir = H16Bit(param3)
- ---------------------------------------------------------------------------
-
- ---------------------------------------------------------------------------
- -- 守卫,客户端通过RaceServer动态改变race
- if jsonData.RaceServer and convertDefenderRace[jsonData.RaceServer] then
- jsonData.race = global.MMO.ACTOR_RACE_DEFENDER
- end
- ---------------------------------------------------------------------------
-
-
- ---------------------------------------------------------------------------
- local cs = jsonData.cs or 0
- local caved = bit.band(bit.rshift(cs, 0), 1) == 1 -- 洞穴,被隐藏
- local skeleton = bit.band(bit.rshift(cs, 1), 1) == 1 -- 死亡,骨头
- local die = bit.band(bit.rshift(cs, 2), 1) == 1 -- 死亡,躺下
- jsonData.caved = caved
- jsonData.skeleton = skeleton
- jsonData.die = die
- ---------------------------------------------------------------------------
- return jsonData
- end
- function gameMapController:ctor()
- self.mNetActorMap = {}
- self.mBoundaryL = nil
- self.mBoundaryR = nil
- self.mBoundaryT = nil
- self.mBoundaryB = nil
- self.mViewCentOffset = cc.p( 0.0, 0.0 )
- self.mCamera = nil
- self.mViewSize = nil
- self.mFollowActorPos = cc.p( 0.0, 0.0 )
- self.mNetMsgHandle = {}
- self:Init()
- self:RegisterMsgHandler()
- end
- function gameMapController:destory()
- if gameMapController.instance then
- gameMapController.instance = nil
- end
- end
- function gameMapController:Inst()
- if not gameMapController.instance then
- gameMapController.instance = gameMapController.new()
- end
- return gameMapController.instance
- end
- -----------------------------------------------------------------------------
- function gameMapController:Init()
- self:initMapScrollFollow()
- end
- -----------------------------------------------------------------------------
- function gameMapController:initMapScrollFollow()
- local winSize = global.Director:getWinSize()
- self.mFullScreenSize = cc.p( winSize.width, winSize.height )
- self.mHalfScreenSize = cc.pMul( self.mFullScreenSize, 0.5 )
- local pcOffset = cc.p(-22, -80)
- if global.isWinPlayMode and SL:GetMetaValue("GAME_DATA", "PCMapCenterOffset") then
- local valueList = string.split(SL:GetMetaValue("GAME_DATA", "PCMapCenterOffset"), "|")
- if tonumber(valueList[1]) and tonumber(valueList[2]) then
- pcOffset = cc.p(tonumber(valueList[1]), tonumber(valueList[2]))
- end
- end
- local offset = global.isWinPlayMode and pcOffset or cc.p(0.0, 0.0)
- self:SetViewCenterOffset( offset.x, offset.y )
- end
- -----------------------------------------------------------------------------
- function gameMapController:SetViewCamera( camera )
- self.mCamera = camera
- if self.mCamera then
- self.mCamera:retain()
- end
- end
- -----------------------------------------------------------------------------
- function gameMapController:GetViewCamera()
- return self.mCamera
- end
- -----------------------------------------------------------------------------
- function gameMapController:SetViewSize( size )
- self.mViewSize = size
- end
- -----------------------------------------------------------------------------
- function gameMapController:GetViewSize()
- if self.mViewSize then
- return self.mViewSize
- end
- local size = global.Director:getWinSize()
- if self.mCamera then
- local scaleX, scaleY = CalcCameraZoom(self.mCamera)
- size.width = math.ceil(size.width * scaleX)
- size.height = math.ceil(size.height * scaleY)
- end
- self.mViewSize = size
-
- return self.mViewSize
- end
- -----------------------------------------------------------------------------
- function gameMapController:SetViewCenterOffset( x, y )
- self.mViewCentOffset.x = x
- self.mViewCentOffset.y = y
- global.sceneManager:SetViewCenterOffset( self.mViewCentOffset.x, self.mViewCentOffset.y )
- end
- function gameMapController:GetViewCenterOffset()
- return self.mViewCentOffset
- end
- -----------------------------------------------------------------------------
- function gameMapController:followMainPlayer()
- if not global.gamePlayerController:GetMainPlayer() then return end
- if not self.mBoundaryB then return end
- local mainPlayer = global.gamePlayerController:GetMainPlayer()
- local playerPos = mainPlayer:getPosition()
- if self.mFollowActorPos.x == playerPos.x and self.mFollowActorPos.y == playerPos.y then
- return
- end
- self.mFollowActorPos.x = playerPos.x
- self.mFollowActorPos.y = playerPos.y
- if self.mCamera then
- local tempPos = cc.pAdd( playerPos, self.mViewCentOffset )
- self.mCamera:setPosition( tempPos )
- end
- end
- -----------------------------------------------------------------------------
- function gameMapController:calcMapFollowParam( width, height )
- self.mBoundaryL = self.mHalfScreenSize.x
- self.mBoundaryR = math.max(width - self.mHalfScreenSize.x, 0)
- self.mBoundaryT = -self.mHalfScreenSize.y
- self.mBoundaryB = math.min(-(height - self.mHalfScreenSize.y), 0)
- end
- -----------------------------------------------------------------------------
- function gameMapController:Cleanup()
- self:CleanupActor(true)
- self.mNetActorMap = {}
- if self.mCamera then
- self.mCamera:autorelease()
- self.mCamera = nil
- end
- end
- -----------------------------------------------------------------------------
- function gameMapController:CleanupActor(cleanMainPlayer)
- global.npcManager:Cleanup()
- global.playerManager:Cleanup()
- global.monsterManager:Cleanup( false )
- global.dropItemManager:Cleanup()
- global.sceneEffectManager:Cleanup()
- global.netMonsterController:Cleanup( false )
- global.netPlayerController:Cleanup( false )
- -- clean up
- if global.gamePlayerController:GetMainPlayer() then
- local mainPlayer = global.gamePlayerController:GetMainPlayer()
- if not cleanMainPlayer then
- self.mNetActorMap[mainPlayer:GetID()] = nil
- end
- -- remove actors trace
- local noticeData = {
- actorID = nil,
- }
- local mapData = global.sceneManager:GetMapData2DPtr()
- for k,v in pairs(self.mNetActorMap) do
- noticeData.actor = v
- noticeData.actorID = v:GetID()
- global.Facade:sendNotification(global.NoticeTable.ActorOutOfView, noticeData )
- end
- self.mNetActorMap = {}
- -- release all actor
- global.actorManager:RemoveAllActor( (not cleanMainPlayer) and mainPlayer:GetID() or 0 )
- -- keep trace main player
- if not cleanMainPlayer then
- global.playerManager:SetMainPlayerID( mainPlayer:GetID() )
- global.playerManager:AddPlayer( mainPlayer )
- self.mNetActorMap[mainPlayer:GetID()] = mainPlayer
- else
- global.gamePlayerController:CleanupMainPlayer()
- global.playerManager:CleanupMainPlayer()
- end
- end
- end
- -----------------------------------------------------------------------------
- function gameMapController:handle_MSG_SC_MAP_ACTOR_CLEANUP( msg )
- self:CleanupActor( false )
- return 1
- end
- -----------------------------------------------------------------------------
- function gameMapController:handleMessage(msg)
- local msgHdr = msg:GetHeader()
- local msgLen = msg:GetDataLength()
- local msgData = (msgLen > 0 and msg:GetData():ReadString(msgLen) or "")
- if self.mNetMsgHandle[msgHdr.msgId] then
- self.mNetMsgHandle[msgHdr.msgId](msgHdr, msgData)
- end
- end
- -----------------------------------------------------------------------------
- function gameMapController:Tick( dt )
- self:followMainPlayer()
- end
- -----------------------------------------------------------------------------
- function gameMapController:handle_MSG_SC_CREATE_MAIN_PLAYER( msg )
- -- 创建主玩家
- local msgHdr = msg:GetHeader()
- local msgLen = msg:GetDataLength()
- local msgData = (msgLen > 0 and msg:GetData():ReadString(msgLen) or "")
-
- self:handle_InOfView(msgHdr, msgData)
- local AuthProxy = global.Facade:retrieveProxy(global.ProxyTable.AuthProxy)
- AuthProxy:RequestIsCloudLogin() --进入游戏上报云手机信息
- end
- -----------------------------------------------------------------------------
- function gameMapController:refreshActor( actor, msgHdr, jsonData, action, stopAnimFrame )
- -- set actor property
- SetActorProperty( actor, jsonData )
- actor:SetAction( action, true )
- actor:stopAnimToFrame( stopAnimFrame )
- actor:dirtyAnimFlag()
- -- refresh pos
- local actorPos = cc.p(0,0)
- local mapX = jsonData.X
- local mapY = jsonData.Y
- actorPos = global.sceneManager:MapPos2WorldPos( mapX, mapY, true )
- actor:setPosition( actorPos.x, actorPos.y )
- global.actorManager:SetActorMapXY( actor, mapX, mapY )
- -- 非主玩家,强刷坐标时清理动作队列
- if actor:IsMonster() then
- global.netMonsterController:cleanupCacheByActorID(actor:GetID())
- elseif actor:IsPlayer() and not actor:IsMainPlayer() then
- global.netPlayerController:cleanupCacheByActorID(actor:GetID())
- end
- end
- -----------------------------------------------------------------------------
- function gameMapController:handle_InOfView(msgHdr, msgData)
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- converActorData(msgHdr, jsonData)
- local actorID = jsonData.UserID
- if not actorID then
- return nil
- end
- -- 初始action
- local action = global.MMO.ACTION_IDLE
- local stopAnimFrame = nil
- if jsonData.StoneMode == 1 then
- -- 1:祖玛雕像的石化状态
- action = global.MMO.ACTION_BORN
- stopAnimFrame = 1
- elseif jsonData.caved == true then
- -- 触龙神/食人花在地下隐藏状态
- action = global.MMO.ACTION_CAVE
- stopAnimFrame = 1
- elseif jsonData.skeleton == true then
- -- 死亡, 骨头
- action = global.MMO.ACTION_DEATH
- elseif jsonData.die == true then
- action = global.MMO.ACTION_DIE
- stopAnimFrame = -1
- end
- local actor = global.actorManager:GetActor( actorID )
- if actor then
- print("--------------- IN OF VIEW, ACTOR IS EXIST, 联系SFY", actorID, actor:GetName(), msgHdr.msgId)
- -- if msgHdr.msgId == global.MsgType.MSG_SC_CREATE_MAIN_PLAYER and actor:IsPlayer() then
- -- global.playerManager:SetMainPlayerID( actorID )
- -- global.gamePlayerController:BindMainActor( actor )
- -- global.actorManager:UpdateLockFrameT()
- -- end
- -- if actor:IsWall() and jsonData.Dir then
- -- stopAnimFrame = jsonData.Dir + 1
- -- end
- -- -- 城墙怪特殊,服务器先发死亡后发出生,导致状态不对,但是又要显示站立的模型,这儿要特殊处理
- -- if actor:IsWall() and (actor:IsDeath() or actor:IsDie()) then
- -- action = global.MMO.ACTION_DEATH
- -- end
-
- -- self:refreshActor( actor, msgHdr, jsonData, action, stopAnimFrame )
- -- SetActorName(actor, jsonData)
- -- global.Facade:sendNotification( global.NoticeTable.DelayRefreshHUDLabel, { actor = actor, actorID = actorID, hudParam = jsonData } )
- -- global.Facade:sendNotification( global.NoticeTable.DelayRefreshHUDTitle, { actor = actor, actorID = actorID, hudParam = jsonData } )
- -- if actor:IsWall() then
- -- -- 城墙怪,如果是死亡状态,模型使用站立
- -- if (actor:IsDeath() or actor:IsDie()) then
- -- actor:SetAnimAct(global.MMO.ANIM_IDLE)
- -- end
- -- actor:updateAnimation()
- -- actor:SetKeyValue(global.MMO.Is_Wall, true)
- -- end
- return actor
- end
-
- local race = jsonData.race
- local isPlayer = false
- local isNpc = false
- local isMonster = false
- -- 0:player;1:hero;150:humanoid
- if race == 0 or race == 1 or race == 150 then
- isPlayer = true
- elseif race == 50 then
- isNpc = true
- else
- isMonster = true
- end
- local initParam = {
- actorID = actorID,
- mapX = jsonData.X or 0,
- mapY = jsonData.Y or 0,
- action = action,
- dir = jsonData.Dir or 0,
- clothID = jsonData.clothID,
- }
- local actor = nil
- local race = jsonData.race
- -- 0:player;1:hero;150:humanoid
- if isPlayer then
- actor = global.netPlayerController:AddNetPlayerToWorld( initParam )
- elseif isNpc then
- actor = global.netNpcController:AddNetNpcToWorld( initParam )
- else
- actor = global.netMonsterController:AddNetMonsterToWorld( initParam )
- end
- if nil == actor then
- return nil
- end
- -- 主玩家,绑定创建
- if msgHdr.msgId == global.MsgType.MSG_SC_CREATE_MAIN_PLAYER and actor:IsPlayer() then
- global.playerManager:SetMainPlayerID( actorID )
- global.gamePlayerController:BindMainActor( actor )
- global.actorManager:UpdateLockFrameT()
- end
- ------------------------------------------------------------
- -- 是城墙
- if actor:IsWall() then
- if jsonData.Dir then
- stopAnimFrame = jsonData.Dir + 1
- end
- actor:SetKeyValue(global.MMO.Is_Wall, true)
- end
- -- restore actor data
- self:refreshActor( actor, msgHdr, jsonData, action, stopAnimFrame )
- -- 是沙巴克大门
- if actor:IsGate() then
- if jsonData.Dir then
- local isOpen = jsonData.Dir >= 3
- actor:setGateOpenState(isOpen)
- end
- actor:SetKeyValue(global.MMO.Is_Gate, true)
- end
- if actor:IsMonster() then
- -- Add to monster manager
- global.monsterManager:AddMonster( actor )
- elseif actor:IsPlayer() then
- -- Add to player manager
- global.playerManager:AddPlayer( actor )
- elseif actor:IsNPC() then
- -- Add to npc manager
- global.npcManager:AddNpc( actor )
- end
- -- Track Npc, NetPlayer, monster....
- self.mNetActorMap[actorID] = actor
- local noticeData = {
- actorID = actorID,
- actor = actor,
- hudParam = jsonData,
- }
- global.Facade:sendNotification(global.NoticeTable.ActorInOfView, noticeData)
- if jsonData.Effect then
- global.ActorEffectManager:ActorEffectRefresh({action = 1, items = jsonData.Effect})
- end
- self:refreshHorse(actor, jsonData)
- SLBridge:onLUAEvent(LUA_EVENT_ACTOR_IN_OF_VIEW, {id = actorID})
- return actor
- end
- function gameMapController:handle_DeathFallDown(msgHdr, msgData)
- if msgData == "" then
- return nil
- end
- local actorID = msgData
- local actor = global.actorManager:GetActor(actorID)
- if nil == actor then
- return nil
- end
- if actor:IsPlayer() then
- if actor:IsMainPlayer() then
- global.gamePlayerController:handle_Die(actor, msgHdr)
- global.Facade:sendNotification(global.NoticeTable.Audio_Play_BGM, {type = global.MMO.SND_TYPE_BGM_DIE})
- local PlayerPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
- PlayerPropertyProxy:setAlive(false)
- else
- global.netPlayerController:handle_Die(actor, msgHdr)
- SLBridge:onLUAEvent(LUA_EVENT_NET_PLAYER_DIE, {id = actorID})
- end
- global.Facade:sendNotification(global.NoticeTable.ActorPlayerDie, {actorID = actorID, actor = actor})
- global.Facade:sendNotification(global.NoticeTable.Audio_Play, {type = global.MMO.SND_TYPE_PLAYER_DIE, index=actor:GetSexID()})
- elseif actor:IsMonster() then
- global.netMonsterController:handle_Die(actor, msgHdr)
- global.Facade:sendNotification(global.NoticeTable.ActorMonsterDie, {actorID = actorID, actor = actor})
- local clothID = actor:GetAnimationID()
- global.Facade:sendNotification(global.NoticeTable.Audio_Play, {type = global.MMO.SND_TYPE_MON_DIE, index = clothID})
- SLBridge:onLUAEvent(LUA_EVENT_MONSTER_DIE, {id = actorID})
- end
- global.Facade:sendNotification(global.NoticeTable.ActorDie, {actorID = actorID, actor = actor})
- end
- function gameMapController:handle_DeathSkeleton(msgHdr, msgData)
- if msgData == "" then
- return nil
- end
- local actorID = msgData
- local actor = global.actorManager:GetActor(actorID)
- if nil == actor then
- return nil
- end
-
- -- monster only.
- if actor:IsMonster() then
- global.netMonsterController:handle_DeathSkeleton(actor, msgHdr)
- global.Facade:sendNotification(global.NoticeTable.ActorMonsterDeath, {actorID = actorID, actor = actor})
- end
- end
- function gameMapController:handle_Revive(msgHdr, msgData)
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actor = global.actorManager:GetActor( jsonData.UserID )
- if nil == actor then
- return nil
- end
- if actor:IsPlayer() then
- if actor:IsMainPlayer() then
- global.gamePlayerController:handle_Revive(actor, jsonData)
- else
- global.netPlayerController:handle_Revive(actor, jsonData)
- SLBridge:onLUAEvent(LUA_EVENT_NET_PLAYER_REVIVE, {id = actor:GetID()})
- end
- elseif actor:IsMonster() then
- global.netMonsterController:handle_Revive(actor, jsonData)
- SLBridge:onLUAEvent(LUA_EVENT_MONSTER_REVIVE, {id = actor:GetID()})
- end
- end
- function gameMapController:handle_OutOfView(msgHdr, msgData)
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actorID = jsonData.UserID
- local actor = global.actorManager:GetActor( actorID )
- if nil == actor then
- return nil
- end
-
- if nil == self.mNetActorMap[actorID] then
- return nil
- end
- self.mNetActorMap[actorID] = nil
- -- Remove from monster manager
- if actor:IsMonster() then
- global.monsterManager:RmvMonster( actorID )
- global.netMonsterController:handleActorOutOfView( actor )
- elseif actor:IsPlayer() then
- if actor:IsMainPlayer() then
- -- effect
- local mainPlayer = global.gamePlayerController:GetMainPlayer()
- if mainPlayer and msgHdr.recog ~= 1 then
- global.Facade:sendNotification(global.NoticeTable.ActorFlyOut, mainPlayer, 0)
- end
- return 1
- end
- -- 恢复攻击状态和护身
- actor:SetDamage()
- actor:SetHuShen()
- global.playerManager:RmvPlayer( actorID )
- global.netPlayerController:handleActorOutOfView( actor )
- elseif actor:IsNPC() then
- global.npcManager:RmvNpc( actorID )
- end
- local noticeData = {
- actor = actor,
- actorID = actorID,
- msgID = msgHdr.msgId,
- recog = msgHdr.recog
- }
- global.Facade:sendNotification(global.NoticeTable.ActorOutOfView, noticeData)
- SLBridge:onLUAEvent(LUA_EVENT_ACTOR_OUT_OF_VIEW, {id = actorID})
- return global.actorManager:RemoveActor( actorID )
- end
- function gameMapController:handle_FlyIn(msgHdr, msgData)
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
- local dir = msgHdr.param3
- local effectType = msgHdr.recog
- local noShow = effectType == 1
- -- dump(msgHdr, "___handle_FlyIn")
- -- dump(msgData)
- -- audio
- global.Facade:sendNotification( global.NoticeTable.Audio_Play, {type = global.MMO.SND_TYPE_FLY_IN} )
- -- effect
- if not noShow then
- local effectId = effectType > 1 and effectType
- global.Facade:sendNotification( global.NoticeTable.ActorFlyIn, {x = mapX, y = mapY}, effectId or 0)
- end
- -- 如果有actor,强行刷坐标
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actor = global.actorManager:GetActor(jsonData.UserID)
- if not actor then
- return nil
- end
- -- 主玩家不需要强拉坐标,切地图时已经带了坐标
- if actor:IsPlayer() and actor:IsMainPlayer() then
- return nil
- end
- if actor:IsMonster() then
- global.netMonsterController:handle_FlyIn(actor, msgHdr )
-
- elseif actor:IsPlayer() then
- global.netPlayerController:handle_FlyIn(actor, msgHdr )
- end
- global.Facade:sendNotification(global.NoticeTable.ActorMoveForce, {actorID = jsonData.UserID, actor = actor})
- end
- function gameMapController:handle_FlyIn2(msgHdr, msgData)
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
- local dir = msgHdr.param3
- local effectType = msgHdr.recog
- local noShow = effectType == 1
- -- audio
- global.Facade:sendNotification( global.NoticeTable.Audio_Play, {type = global.MMO.SND_TYPE_FLY_IN} )
- -- effect
- if not noShow then
- local effectId = effectType > 1 and effectType
- global.Facade:sendNotification( global.NoticeTable.ActorFlyIn, {x = mapX, y = mapY}, effectId or 1)
- end
- -- 如果有actor,强行刷坐标
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actor = global.actorManager:GetActor(jsonData.UserID)
- if not actor then
- return nil
- end
- -- 主玩家不需要强拉坐标,切地图时已经带了坐标
- if actor:IsPlayer() and actor:IsMainPlayer() then
- return nil
- end
- if actor:IsMonster() then
- global.netMonsterController:handle_FlyIn2(actor, msgHdr )
-
- elseif actor:IsPlayer() then
- global.netPlayerController:handle_FlyIn2(actor, msgHdr )
- end
- global.Facade:sendNotification(global.NoticeTable.ActorMoveForce, {actorID = jsonData.UserID, actor = actor})
- end
- function gameMapController:handle_FlyOut(msgHdr, msgData)
- local effectType = msgHdr.recog
- local noShow = effectType == 1
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actor = global.actorManager:GetActor(jsonData.UserID)
- if not actor then
- return nil
- end
- -- audio
- global.Facade:sendNotification(global.NoticeTable.Audio_Play, {type = global.MMO.SND_TYPE_FLY_OUT})
-
- -- effect
- if not noShow then
- local effectId = effectType > 1 and effectType
- global.Facade:sendNotification(global.NoticeTable.ActorFlyOut, actor, effectId or 0)
- end
- end
- function gameMapController:handle_FlyOut2(msgHdr, msgData)
- local effectType = msgHdr.recog
- local noShow = effectType == 1
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actor = global.actorManager:GetActor(jsonData.UserID)
- if not actor then
- return nil
- end
- -- audio
- global.Facade:sendNotification(global.NoticeTable.Audio_Play, {type = global.MMO.SND_TYPE_FLY_OUT})
-
- -- effect
- if not noShow then
- local effectId = effectType > 1 and effectType
- global.Facade:sendNotification(global.NoticeTable.ActorFlyOut, actor, effectId or 1)
- end
- end
- function gameMapController:handle_FeatureChanged(header, msgData)
- if msgData == "" then
- return nil
- end
- local actor = global.actorManager:GetActor( msgData )
- if nil == actor then
- print( "illegal actorID in handle_MSG_SC_ACTOR_FEATURE_CHANGED", msgData )
- return nil
- end
- local ftype = header.recog
- local value = header.param1
- local value1 = header.param2
- if ftype == global.MMO.ACTOR_FTCHANGE_CLOTH then
- if actor:IsMonster() then
- actor:SetClothID(value)
- global.Facade:sendNotification(global.NoticeTable.DelayDirtyFeature, {actorID = actor:GetID(), actor = actor})
- return
- end
- -- 衣服
- local actorAttr = GetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE) or {}
- actorAttr.clothID = value
- SetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE, actorAttr)
- global.Facade:sendNotification( global.NoticeTable.DelayActorFeatureChange, actorAttr )
- elseif ftype == global.MMO.ACTOR_FTCHANGE_CLOTH_EFF then
- -- 衣服特效/翅膀 ???
- local actorAttr = GetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE) or {}
- actorAttr.clothEff = value
- SetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE, actorAttr)
- global.Facade:sendNotification( global.NoticeTable.DelayActorFeatureChange, actorAttr )
- elseif ftype == global.MMO.ACTOR_FTCHANGE_WEAPON then
- -- 武器
- local actorAttr = GetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE) or {}
- actorAttr.weaponID = value
- if value1 then --左手武器
- actorAttr.leftWeaponID = value1
- end
- SetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE, actorAttr)
- global.Facade:sendNotification( global.NoticeTable.DelayActorFeatureChange, actorAttr )
- elseif ftype == global.MMO.ACTOR_FTCHANGE_WEAPON_EFF then
- -- 武器特效
- local actorAttr = GetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE) or {}
- actorAttr.weaponEff = value
- if value1 then --左手武器
- actorAttr.leftWeaponEff = value1
- end
- SetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE, actorAttr)
- global.Facade:sendNotification( global.NoticeTable.DelayActorFeatureChange, actorAttr )
- elseif ftype == global.MMO.ACTOR_FTCHANGE_HAIR then
- -- 发型
- local actorAttr = GetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE) or {}
- actorAttr.Hair = value
- SetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE, actorAttr)
- global.Facade:sendNotification( global.NoticeTable.DelayActorFeatureChange, actorAttr )
- elseif ftype == global.MMO.ACTOR_FTCHANGE_CAP then
- -- 斗笠
- local actorAttr = GetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE) or {}
- actorAttr.Cap = value
- SetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE, actorAttr)
- global.Facade:sendNotification( global.NoticeTable.DelayActorFeatureChange, actorAttr )
- elseif ftype == global.MMO.ACTOR_FTCHANGE_TEAMSTATE then
- -- 组队状态
- local lastGroup = actor:GetTeamState()
- actor:SetTeamState(value)
- if actor:IsPlayer() and actor:IsMainPlayer() and actor:GetTeamState() == 0 then
- local TeamProxy = global.Facade:retrieveProxy(global.ProxyTable.TeamProxy)
- TeamProxy:ClearTeamMember()
- SLBridge:onLUAEvent(LUA_EVENT_TEAM_MEMBER_UPDATE)
- SLBridge:onLUAEvent(LUA_EVENT_LEAVETEAM, actor:GetName())
- end
- --
- if actor:IsPlayer() then
- if lastGroup ~= value then
- if global.gamePlayerController:GetMainPlayerID() == actor:GetID() then
- SL:onLUAEvent(LUA_EVENT_PLAYER_TEAM_STATUS_CHANGE)
- else
- SL:onLUAEvent(LUA_EVENT_NET_PLAYER_TEAM_STATUS_CHANGE, {id = actor:GetID()})
- end
- end
- end
- elseif ftype == global.MMO.ACTOR_FTCHANGE_SEX then
- -- sex
- actor:SetSexID(value)
- actor:dirtyHair()
- actor:dirtyCloth()
- local actorAttr = GetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE) or {}
- global.Facade:sendNotification( global.NoticeTable.DelayActorFeatureChange, actorAttr )
-
- elseif ftype == global.MMO.ACTOR_FTCHANGE_SHIELD then
- --盾牌 盾牌特效
- local actorAttr = GetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE) or {}
- actorAttr.shieldID = value
- actorAttr.shieldEffect = value1
- SetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE, actorAttr)
- global.Facade:sendNotification( global.NoticeTable.DelayActorFeatureChange, actorAttr )
- end
- return 1
- end
- function gameMapController:handle_Walk(msgHdr, msgData)
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actorID = jsonData.UserID
- local actor = global.actorManager:GetActor( actorID )
- if nil == actor then
- return nil
- end
- if actor:IsMonster() then
- local mainPlayerID = global.gamePlayerController:GetMainPlayerID()
- if actor:GetMasterID() == mainPlayerID then --宝宝触发
- ssr.ssrBridge:OnPetActionBegin(actorID, 1, actor:GetMapX(), actor:GetMapY(), actor:GetName())
- end
- return global.netMonsterController:handle_MSG_SC_ACTOR_WALK(actor, msgHdr )
- elseif actor:IsPlayer() then
- return global.netPlayerController:handle_MSG_SC_ACTOR_WALK(actor, msgHdr )
- end
- end
- function gameMapController:handle_Run(msgHdr, msgData, isRunOne)
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actorID = jsonData.UserID
- local actor = global.actorManager:GetActor( actorID )
- if nil == actor then
- return nil
- end
- actor:SetKeyValue(global.MMO.IS_RUN_ONE, isRunOne)
- if actor:IsMonster() then
- local mainPlayerID = global.gamePlayerController:GetMainPlayerID()
- if actor:GetMasterID() == mainPlayerID then --宝宝触发
- ssr.ssrBridge:OnPetActionBegin(actorID, 2, actor:GetMapX(), actor:GetMapY(), actor:GetName())
- end
- return global.netMonsterController:handle_MSG_SC_ACTOR_RUN(actor, msgHdr )
- elseif actor:IsPlayer() then
- return global.netPlayerController:handle_MSG_SC_ACTOR_RUN(actor, msgHdr )
- end
- end
- function gameMapController:handle_RideRun(msgHdr, msgData)
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actorID = jsonData.UserID
- local actor = global.actorManager:GetActor( actorID )
- if nil == actor then
- return nil
- end
- if actor:IsPlayer() then
- return global.netPlayerController:handle_MSG_SC_ACTOR_RIDE_RUN(actor, msgHdr )
- end
- end
- function gameMapController:handle_Turn(msgHdr, msgData)
- if msgData == "" then
- return nil
- end
- local actorID = msgData
- local actor = global.actorManager:GetActor( actorID )
- if nil == actor then
- return nil
- end
- local dir = msgHdr.recog
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
-
- if actor:GetMapX() ~= mapX or actor:GetMapY() ~= mapY then
- local pos = global.sceneManager:MapPos2WorldPos( mapX, mapY, true )
- if actor.GetRaceServer and actor:GetRaceServer() ~= global.MMO.ACTOR_SERVER_RACE_KNIEF then
- actor:setPosition( pos.x, pos.y )
- actor:SetDirection( dir )
- else
- SetActorAttrByID(actorID, global.MMO.ACTOR_ATTR_DIR, dir)
- end
- else
- actor:SetDirection(dir)
- end
- global.actorManager:SetActorMapXY( actor, mapX, mapY )
-
- actor:dirtyAnimFlag()
- global.BuffManager:UpdateBuffSfxDir(actorID)
- global.ActorEffectManager:UpdateEffectDir(actor, actorID)
- end
- function gameMapController:handle_PickCorpse( msgHdr, msgData )
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actorID = jsonData.UserID
- local actor = global.actorManager:GetActor( actorID )
- if nil == actor then
- return nil
- end
- local ret = -3
- if actor:IsPlayer() then
- if not actor:IsMainPlayer() then
- if msgHdr.param1 == 1 then
- --挖矿
- ret = global.netPlayerController:handleActorMining( actor, jsonData )
- else
- --挖尸体
- ret = global.netPlayerController:handleActorSitdown( actor, jsonData )
- end
- end
- if msgHdr.param2 >= 1 then
- if actor:IsMainPlayer() then
- --挖矿 起灰特效
- local present =
- {
- skillID = 999,
- launchX = actor:GetMapX(),
- launchY = actor:GetMapY(),
- hitX = actor:GetMapX(),
- hitY = actor:GetMapY(),
- dir = actor:GetDirection(),
- skillStage = 3,
- launcherID = actor:GetID()
- }
- global.Facade:sendNotification(global.NoticeTable.RequestSkillPresent, present)
- -- 挖矿 起灰音效
- global.Facade:sendNotification(global.NoticeTable.Audio_Play, {type=global.MMO.SND_TYPE_MINING_DROP})
- end
-
- --挖矿 广播土堆
- local item =
- {
- id = msgHdr.param3,
- type = global.MMO.EFFECT_TYPE_MINING_HIT,
- x = actor:GetMapX(),
- y = actor:GetMapY(),
- param = msgHdr.param2,
- }
- self:addSpecialEffect( item )
- end
- end
- end
- function gameMapController:handle_RefreshHP( msgHdr, msgData )
- if msgData == "" then
- return false
- end
- local newArray = string.split( msgData,"|" )
- local dataStrArray = string.split(newArray[1] or "","&")
- local actorID = dataStrArray[1]
- local HP = tonumber(dataStrArray[2]) or 0
- local maxHP = tonumber(dataStrArray[3]) or 0
- local MP = tonumber(dataStrArray[4]) or 0
- local maxMP = tonumber(dataStrArray[5]) or 0
- local actor = global.actorManager:GetActor( actorID )
- if not actor then
- --自己的英雄不在视野内也要刷新血量
- local HeroPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
- local HeroID = HeroPropertyProxy:GetRoleUID()
- if HeroID and HeroID == actorID then
- HeroPropertyProxy:SetRoleMana(HP, maxHP, MP, maxMP)
- end
- return false
- end
- local power = newArray[2]
- -- 1 受击
- local unAattack = L16Bit(msgHdr.recog) == 1
- -- 飘字类型
- local throwType = msgHdr.param2
- -- 飘字的值
- local throwPower = tonumber(power) or msgHdr.param3
- local nData = {
- actorID = actorID,
- HP = HP,
- maxHP = maxHP,
- MP = MP,
- maxMP = maxMP,
- isDamage = false,
- unAattack = unAattack,
- level = msgHdr.param1, -- 等级
- }
- if unAattack then
- nData.huShen = H16Bit(msgHdr.recog)
- end
- local oldHP = actor:GetHP() or 0
- local oldMP = actor:GetMP() or 0
- global.Facade:sendNotification(global.NoticeTable.RefreshActorHP, nData)
- JudgeIsRefreshTargetHP(nData)
- -- 飘字
- if throwType > 0 then
- if throwType == 110 then
- local changeHp = HP - oldHP
- local hpTypeID = changeHp > 0 and 4 or (changeHp < 0 and 1 or 0)
- if hpTypeID > 0 then
- global.Facade:sendNotification(global.NoticeTable.ShowThrowDamage, {Id = hpTypeID, UserID = actorID, Power = math.abs(changeHp)})
- end
- local changeMp = MP - oldMP
- local mpTypeID = changeMp > 0 and 12 or (changeMp < 0 and 11 or 0)
- if mpTypeID > 0 then
- global.Facade:sendNotification(global.NoticeTable.ShowThrowDamage, {Id = mpTypeID, UserID = actorID, Power = math.abs(changeMp)})
- end
- else
- global.Facade:sendNotification(global.NoticeTable.ShowThrowDamage, {Id = throwType, UserID = actorID, Power = throwPower})
- end
- end
- end
- function gameMapController:handle_Damage(msgHdr, msgData)
- if msgData == "" then
- return false
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return false
- end
- local actorID = jsonData.UserID
- local actor = global.actorManager:GetActor(actorID)
- if not actor then
- return false
- end
- local HP = jsonData.Hp or 0
- local maxHP = jsonData.MaxHp or 0
- local MP = jsonData.Mp or 0
- local maxMP = jsonData.MaxMp or 0
- local nData = {
- actorID = actorID,
- HP = HP,
- maxHP = maxHP,
- MP = MP,
- maxMP = maxMP,
- isDamage = true,
- unAattack = true,
- huShen = H16Bit(msgHdr.recog)
- }
- -- 飘字类型
- local throwType = L16Bit(msgHdr.recog)
-
- -- 飘字的值
- local throwPower = tonumber(jsonData.Damage) or msgHdr.param1
-
- -- 后仰
- local struck = 1 -- 默认后仰
- local struchRules = jsonData.Struck or 0
- local isMain = (actor:IsPlayer() and actor:IsMainPlayer()) or false
- -- 以前是后端判断, 改成前端自行判断
- if (isMain and CheckBit(struchRules, 0)) or ((actor:IsPlayer() or actor:IsHero()) and CheckBit(struchRules, 1)) or (actor:IsMonster() and CheckBit(struchRules, 2)) then
- struck = 0
- end
- if struck == 1 then -- 后仰状态
- self:handle_Stuck(msgHdr, msgData)
- end
- -- 音效 ????
- global.Facade:sendNotification(global.NoticeTable.Audio_Play, {type = global.MMO.SND_TYPE_SCREAM, index = jsonData.Weapon, param = actorID})
- if jsonData.Magic ~= 1 then
- global.Facade:sendNotification(global.NoticeTable.Audio_Play, {type = global.MMO.SND_TYPE_STUCK, index = jsonData.Weapon, param = actorID})
- end
- global.Facade:sendNotification(global.NoticeTable.RefreshActorHP, nData)
- JudgeIsRefreshTargetHP(nData)
- -- 飘字
- if throwType > 0 then
- global.Facade:sendNotification(global.NoticeTable.ShowThrowDamage, {Id = throwType, UserID = actorID, Power = throwPower, TargetID = jsonData.AttackUserID})
- end
- -- 刷新内力值
- local data = {
- curInternalForce = jsonData.InternalForce,
- maxInternalForce = jsonData.MaxInternalForce
- }
- if next(data) then
- data.actorID = actorID
- global.Facade:sendNotification(global.NoticeTable.RefreshActorIForce, data)
- end
- global.Facade:sendNotification(global.NoticeTable.AutoFightBack, {attackActorID = jsonData.AttackUserID, actorID = actorID})
- end
- -- 护身状态掉蓝由服务端直接通知反击
- function gameMapController:handle_MSG_SC_FIGHT_BACK_ID(msg)
- local header = msg:GetHeader()
- local msgLen = msg:GetDataLength()
- if msgLen <= 0 then
- return
- end
-
- local attackActorID = msg:GetData():ReadString(msgLen)
- local actor = global.actorManager:GetActor(attackActorID)
- if not actor then
- return
- end
- if not actor:IsPlayer() then
- return
- end
- global.Facade:sendNotification(global.NoticeTable.AutoFightBack, {attackActorID = attackActorID})
- end
- function gameMapController:handle_Stuck( msgHdr, msgData )
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actorID = jsonData.UserID
- local actor = global.actorManager:GetActor( actorID )
- if nil == actor or actor:IsDie() then
- return nil
- end
- if actor:IsMonster() then
- return global.netMonsterController:handle_MSG_SC_ACTOR_STUCK( actor )
- elseif actor:IsPlayer() then
- if actor:IsMainPlayer() then
- return global.gamePlayerController:handle_MSG_SC_ACTOR_STUCK( actor )
- else
- return global.netPlayerController:handle_MSG_SC_ACTOR_STUCK( actor )
- end
- end
- end
- function gameMapController:handle_RefreshSpeed( msgHdr, msgData )
- if msgData == "" then
- return nil
- end
- -- recog 走
- -- param1 跑
- -- param2 攻击
- -- param3 施法
- -- Str UserID
- local header = msgHdr
- local actorID = msgData
- local actor = global.actorManager:GetActor(actorID)
- if not actor then
- return nil
- end
- print("速度改变 ", actorID, header.recog, header.param1, header.param2, header.param3)
- -- 走速度
- if header.recog > 0 then
- if actor:IsPlayer() and actor:IsMainPlayer() then
- actor:SetWalkSpeed(actor:GetWalkStepTime() / (header.recog * 0.001 + global.MMO.NETWORK_DELAY))
- else
- actor:SetWalkSpeed(actor:GetWalkStepTime() / (header.recog * 0.001 + global.ConstantConfig.NetPlayerDelayTime * 0.001))
- end
- end
- -- 跑速度
- if header.param1 > 0 then
- if actor:IsPlayer() and actor:IsMainPlayer() then
- actor:SetRunSpeed(actor:GetRunStepTime() / (header.param1 * 0.001 + global.MMO.NETWORK_DELAY))
- else
- actor:SetRunSpeed(actor:GetRunStepTime() / (header.param1 * 0.001 + global.ConstantConfig.NetPlayerDelayTime * 0.001))
- end
- end
- -- 攻击速度
- -- 飞扬ios数据流量放火墙往相反方向跑出现空气墙,增加网络延迟误差
- local delay = SL:GetMetaValue("GAME_DATA", "attack_network_delay") == 1 and global.MMO.NETWORK_DELAY or 0
- if header.param2 > 0 then
- actor:SetAttackSpeed(actor:GetAttackStepTime() / (header.param2 * 0.001 + delay))
- end
- -- 魔法速度
- if header.param3 > 0 then
- actor:SetMagicSpeed(actor:GetMagicStepTime() / (header.param3 * 0.001 + delay))
- end
- -- 同步主玩家锁帧时间
- if actor:IsPlayer() and actor:IsMainPlayer() then
- global.actorManager:UpdateLockFrameT()
- end
- end
- function gameMapController:handle_RefreshMonsterSpeed( msgHdr, msgData )
- if msgData == "" then
- return nil
- end
- local header = msgHdr
- local actorID = msgData
- local actor = global.actorManager:GetActor(actorID)
- if not actor then
- return nil
- end
- print("怪物速度改变 ", actorID, header.recog, header.param1)
- -- 走速度
- if header.recog > 0 then
- actor:SetWalkSpeed(actor:GetWalkStepTime() / (header.recog * 0.001 + global.MMO.NETWORK_DELAY))
- end
- -- 攻击速度
- if header.param1 > 0 then
- actor:SetAttackSpeed(actor:GetAttackStepTime() / (header.recog * 0.001))
- end
- end
- function gameMapController:handle_RefreshName(msgHdr, msgData)
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
-
- local actorID = jsonData.UserID
- local actor = global.actorManager:GetActor( actorID )
- if not actor then
- return nil
- end
- local guildID = actor:IsPlayer() and actor:GetGuildID() or nil
- SetActorProperty(actor, jsonData)
- SetActorName(actor, jsonData)
- global.Facade:sendNotification( global.NoticeTable.DelayRefreshHUDLabel, { actor = actor, actorID = actorID, hudParam = jsonData } )
- global.Facade:sendNotification( global.NoticeTable.DelayRefreshHUDTitle, { actor = actor, actorID = actorID, hudParam = jsonData } )
- local newGuildID = actor:IsPlayer() and actor:GetGuildID() or nil
- if guildID ~= newGuildID then
- local guilds = {}
- if guildID and guildID ~= "" then
- guilds[guildID] = true
- end
- if newGuildID and newGuildID ~= "" then
- guilds[newGuildID] = true
- end
-
- if next(guilds) then
- global.Facade:sendNotification( global.NoticeTable.RefreshGuildActorColor, {guilds=guilds} )
- end
- end
- end
- function gameMapController:handle_Sell(header, msgData)
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actorID = jsonData.userid
- local actor = global.actorManager:GetActor( actorID )
- if not actor then
- return -1
- end
- local sellStatus = jsonData.open
-
- actor:SetAction(global.MMO.ACTION_IDLE)
- if sellStatus == 1 then
- local pos = global.sceneManager:MapPos2WorldPos( jsonData.x, jsonData.y, true )
- actor:setPosition( pos.x, pos.y )
- actor:SetDirection( jsonData.dir )
- actor:dirtyAnimFlag()
- global.actorManager:SetActorMapXY( actor, jsonData.x, jsonData.y, true )
- end
- --摆摊状态 (0, 1)
- actor:SetSellStatus(sellStatus)
- --摊位名字
- actor:SetStallName(jsonData.stallname)
- if actorID == global.gamePlayerController:GetMainPlayerID() then
- local StallProxy = global.Facade:retrieveProxy(global.ProxyTable.StallProxy)
- StallProxy:SetMyTradingStatus(sellStatus == 1)
- if sellStatus == 0 then --取消摆摊
- StallProxy:CleanMySellData() --返回摆摊物品
- end
- end
- global.Facade:sendNotification(global.NoticeTable.Layer_StallLayer_StatusChange, {status = sellStatus, userid = actorID})
- global.Facade:sendNotification(global.NoticeTable.PlayerStallStatucChange, {actorID = actorID, actor = actor})
- global.Facade:sendNotification(global.NoticeTable.RefreshActorBooth, {actorID = actorID, actor = actor})
- if actorID == global.gamePlayerController:GetMainPlayerID() then
- SLBridge:onLUAEvent(LUA_EVENT_PLAYER_STALL_STATUS_CHANGE)
- else
- SLBridge:onLUAEvent(LUA_EVENT_NET_PLAYER_STALL_STATUS_CHANGE, {id = actorID})
- end
- end
- function gameMapController:handle_MSG_SC_NET_MONSTER_BORN(msg)
- local msgLen = msg:GetDataLength()
- if msgLen <= 0 then
- return
- end
- local msgHdr = msg:GetHeader()
- local msgData = msg:GetData():ReadString(msgLen)
- local actorID = msgData
- local actor = global.actorManager:GetActor( actorID )
- if not actor then
- print("[出生 20] 没有发现ACTOR", actorID)
- return nil
- end
- if not actor:IsMonster() then
- return nil
- end
- global.netMonsterController:handle_MSG_SC_NET_MONSTER_BORN(actor, msgHdr, msgData)
- end
- function gameMapController:handle_MSG_SC_NET_MONSTER_CAVE(msg)
- local msgLen = msg:GetDataLength()
- if msgLen <= 0 then
- return
- end
- local msgHdr = msg:GetHeader()
- local msgData = msg:GetData():ReadString(msgLen)
- local actorID = msgData
- local actor = global.actorManager:GetActor( actorID )
- if not actor then
- print("[钻回 21] 没有发现ACTOR", actorID)
- return nil
- end
- if not actor:IsMonster() then
- return nil
- end
- global.netMonsterController:handle_MSG_SC_NET_MONSTER_CAVE(actor, msgHdr, msgData)
- end
- function gameMapController:handle_Icons(msgHdr, msgData)
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actorID = jsonData.UserID
- local actor = global.actorManager:GetActor( actorID )
- if not actor then
- return nil
- end
- SetActorAttrByID( actorID, global.MMO.ACTOR_ATTR_HUDICONS, jsonData.icons or {} )
- global.Facade:sendNotification( global.NoticeTable.DelayRefreshHUDTitle, { actor = actor, actorID = actorID } )
- end
- function gameMapController:handle_Title(msgHdr, msgData)
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actorID = jsonData.UserID
- local actor = global.actorManager:GetActor( actorID )
- if not actor then
- return nil
- end
- SetActorAttrByID( actorID, global.MMO.ACTOR_ATTR_HUDTITLE, jsonData.title or {} )
- global.Facade:sendNotification( global.NoticeTable.DelayRefreshHUDTitle, { actor = actor, actorID = actorID } )
- end
- -- 挖矿
- function gameMapController:handle_AutoMining(msgHdr, msgData)
- local mainPlayer = global.gamePlayerController:GetMainPlayer()
- if not mainPlayer then
- return
- end
- local inputProxy = global.Facade:retrieveProxy( global.ProxyTable.PlayerInputProxy )
- local x = msgHdr.param1
- local y = msgHdr.param2
- local dest = cc.p(x, y)
- local src = cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY())
- local dir = inputProxy:calcMapDirection(dest, src)
- local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
- autoProxy:SetAutoMining(dir,dest)
- local mapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
- local mapID = mapProxy:GetMapID()
- local movePos =
- {
- mapID = mapID,
- x = dest.x,
- y = dest.y,
- type = global.MMO.INPUT_MOVE_TYPE_AUTOMOVE,
- }
- global.Facade:sendNotification(global.NoticeTable.InputMove, movePos)
- end
- -- actor 转生
- function gameMapController:handle_ActorReLevel(msgHdr, msgData)
-
- if not msgData then
- return false
- end
- local actor = global.actorManager:GetActor(msgData)
- if not actor then
- return false
- end
- if not actor:IsPlayer() then
- return false
- end
- actor:SetReLevel(msgHdr.recog)
- end
- -----------------------------------------------------------------------------
- --- 开门 关门
- function gameMapController:handle_MSG_SC_OPEN_DOOR_NOTICE(msg)
- local header = msg:GetHeader()
- global.sceneManager:openDoor( header.param1, header.param2 )
- end
- function gameMapController:handle_MSG_SC_CLOSE_DOOR_NOTICE(msg)
- local header = msg:GetHeader()
- global.sceneManager:closeDoor( header.param1, header.param2 )
- end
- -----------------------------------------------------------------------------
- -----------------------------------------------------------------------------
- -- 场景特效
- function gameMapController:handle_MSG_SC_MAP_ADD_SPECIAL_EFFECT( msg )
- local jsonData = ParseRawMsgToJson(msg)
- if not jsonData then
- return nil
- end
- local len = #jsonData
- local data = nil
- local item = nil
- for i = 1, len do
- data = jsonData[i]
- local item =
- {
- id = data.Id,
- type = data.Type,
- x = data.X,
- y = data.Y,
- param = data.Param,
- sfxId = data.EffId,
- TopType = data.TopType,
- DuranceID = data.DuranceID or global.gamePlayerController:GetMainPlayerID()
- }
- if item.TopType == 2 then
- SL:AddMapSpecialEffect(item.id, SL:GetMetaValue("MAP_ID"), item.sfxId, item.x, item.y, true, item.TopType)
- else
- self:addSpecialEffect( item )
- end
- end
- end
- function gameMapController:handle_MSG_SC_MAP_RMV_SPECIAL_EFFECT( msg )
- local jsonData = ParseRawMsgToJson(msg)
- if not jsonData then
- return nil
- end
- local len = #jsonData
- local data = nil
- local actorID = nil
- for i = 1, len do
- data = jsonData[i]
- actorID = data.Id
- local sfxActor = self.mNetActorMap[actorID]
- if (sfxActor) then
- -- notice
- global.Facade:sendNotification(global.NoticeTable.ActorEffectOutOfView, {actorID = actorID, actor = sfxActor})
- end
- self.mNetActorMap[actorID] = nil
- global.sceneEffectManager:RmvSceneEffect( actorID )
- global.actorManager:RemoveActor( actorID )
-
- local sceneImprisonEffectProxy = global.Facade:retrieveProxy(global.ProxyTable.SceneImprisonEffectProxy)
- sceneImprisonEffectProxy:RmImprison( actorID )
- end
- end
- function gameMapController:addSpecialEffect( item )
- local isInit = true
- local actorID = item.id
- local needLight = false
- -- find it
- local sfxActor = global.actorManager:GetActor( actorID )
- if nil ~= sfxActor then
- sfxActor:GetNode():setVisible( true )
- isInit = false
- -----lightID
- if not sfxActor:GetLightID() then
- needLight = true
- end
- else
- -- New special effect actor
- local paramSfx = {}
- paramSfx.type = global.MMO.EFFECT_TYPE_NORMAL
- local limitCount = 200
- local actorCount = global.actorManager:GetActorNum()
- local isBehind = false
- local isFront = false
- local effectRace = item.type
- if fireSet[effectRace] then
- paramSfx.sfxId = fireSet[effectRace]
- paramSfx.isLoop = true
- isBehind = (actorCount>limitCount)
- paramSfx.type = global.MMO.EFFECT_TYPE_FIRE
- -----lightID
- needLight = true
- local sfxId = item.sfxId and tonumber(item.sfxId)
- if sfxId and sfxId > 0 then
- paramSfx.sfxId = sfxId
- end
- elseif effectRace == 1 then -- 僵尸2 出生洞
- paramSfx.sfxId = global.MMO.SFX_MONSTER_BORN1
- paramSfx.isLoop = false
- isBehind = true
- elseif effectRace == global.MMO.EFFECT_TYPE_MINING_HIT then
- -- 土(静态特效)(ps: 以前是挖矿 sfxid:999)
- paramSfx.type = global.MMO.EFFECT_TYPE_MINING_HIT
- paramSfx.sfxId = 2208
- paramSfx.isLoop = true
- paramSfx.param = item.param
- isBehind = true
- elseif effectRace == 27 or effectRace == 50 then
- -- 传送门
- paramSfx.sfxId = global.MMO.SFX_PORTAL
- paramSfx.isLoop = true
- isBehind = true
- paramSfx.type = global.MMO.EFFECT_TYPE_PORTAL
- needLight = true
- elseif effectRace == global.MMO.EFFECT_TYPE_SFX then
- -- 通用特效
- paramSfx.type = global.MMO.EFFECT_TYPE_SFX
- paramSfx.sfxId = item.sfxId
- paramSfx.isLoop = true
- isBehind = item.TopType == 0
- isFront = item.TopType == 1
- elseif effectRace == global.MMO.EFFECT_TYPE_EMPTY then
- -- 禁锢 设置动态阻挡
- paramSfx.type = global.MMO.EFFECT_TYPE_EMPTY
- paramSfx.sfxId = item.sfxId
- paramSfx.isLoop = true
- paramSfx.DuranceID = item.DuranceID
- isBehind = false
- else
- return -1
- end
- sfxActor = global.actorManager:CreateActor( actorID, global.MMO.ACTOR_SEFFECT, paramSfx, isBehind ,isFront)
-
- if nil == sfxActor then
- return -1
- end
- end
- -- To map grid position.
- local mapX = item.x
- local mapY = item.y
- local actorPos = global.sceneManager:MapPos2WorldPos( mapX, mapY, true )
- sfxActor:setPosition( actorPos.x, actorPos.y )
- global.actorManager:SetActorMapXY( sfxActor, mapX, mapY )
- -- feature
- global.Facade:sendNotification( global.NoticeTable.DelayDirtyFeature, {actorID = actorID, actor = sfxActor})
- if isInit then
- -- Track effect.
- self.mNetActorMap[actorID] = sfxActor
- global.sceneEffectManager:AddSceneEffect( sfxActor )
- end
- global.Facade:sendNotification(global.NoticeTable.ActorEffectInOfView, {actorID = actorID, actor = sfxActor, needLight = needLight})
- end
- -- 场景添加特效
- function gameMapController:addEffectToMap( animID, mapX, mapY )
- if not animID or not mapX or not mapY then
- return
- end
- -- 播放特效
- local sfxAnim = global.FrameAnimManager:CreateSFXAnim(animID)
- if not sfxAnim then
- return
- end
- local root = global.sceneGraphCtl:GetSceneNode( global.MMO.NODE_SKILL_BEHIND )
- local sfxParent = root:getChildByName("MAP_SFX_PARENT")
- if not sfxParent then
- sfxParent = cc.Node:create()
- sfxParent:setName("MAP_SFX_PARENT")
- root:addChild( sfxParent, 999 )
- end
- sfxParent:addChild(sfxAnim, animID)
- local sfxPos = global.sceneManager:MapPos2WorldPos( mapX, mapY )
- sfxAnim:setPosition( sfxPos.x, sfxPos.y)
- sfxAnim:Play(0, 0)
- local function removeEvent()
- sfxAnim:removeFromParent()
- end
- sfxAnim:SetAnimEventCallback( removeEvent )
- end
- -----------------------------------------------------------------------------
- -- 掉落物
- function gameMapController:addDropItem( item )
- local id = item.Id
- local Idx = item.Idx
- local code = global.dropItemController:AddDropItemToWorld( item )
- if code == 2 then -- refresh drop item ownerID
- global.Facade:sendNotification(global.NoticeTable.RefreshDropItem, id)
- return nil
- elseif code ~= 1 then
- return nil
- end
- -- Track Npc, NetPlayer, monster....
- local dropItem = global.actorManager:GetActor( id )
- self.mNetActorMap[ id ] = dropItem
- -- type index
- dropItem:SetTypeIndex( Idx )
- local noticeData = {
- actorID = id,
- color = item.Color or 255,
- jipin = item.jipin,
- count = item.cnt,
- itemName = item.Name,
- }
- global.Facade:sendNotification(global.NoticeTable.DropItemInOfView, noticeData)
- global.Facade:sendNotification(global.NoticeTable.DelayDirtyFeature, {actorID = id, actor = dropItem})
- SLBridge:onLUAEvent(LUA_EVENT_DROPITEM_IN_OF_VIEW, {actorID = id, item = item})
- end
- function gameMapController:rmvDropItem( id )
- -- Drop item
- if nil == id then
- return nil
- end
- local it = self.mNetActorMap[id]
- if nil == it then
- return nil
- end
- self.mNetActorMap[id] = nil
- global.Facade:sendNotification(global.NoticeTable.DropItemOutOfView, {actorID = id})
- global.dropItemController:RmvDroItemFromWorld( id )
- SLBridge:onLUAEvent(LUA_EVENT_DROPITEM_OUT_OF_VIEW, {actorID = id})
- end
- function gameMapController:handle_MSG_SC_MAP_ITEM_DROP_BATCH( msg )
- local jsonData = ParseRawMsgToJson( msg )
- if not jsonData or next(jsonData) == nil then
- return nil
- end
- local len = #jsonData
- local item = nil
- for i = 1, len do
- item = jsonData[i]
- self:addDropItem(item)
- end
- end
- function gameMapController:handle_MSG_SC_MAP_ITEM_REMOVE_BATCH( msg )
- local jsonData = ParseRawMsgToJson( msg )
- if not jsonData or next(jsonData) == nil then
- return nil
- end
- local len = #jsonData
- local item = nil
- local itemID = nil
- for i = 1, len do
- item = jsonData[i]
- itemID = tonumber(item.Id)
- self:rmvDropItem( itemID )
- end
- end
- -----------------------------------------------------------------------------
- -----------------------------------------------------------------------------
- --移动特效、足迹
- function gameMapController:handle_MSG_SC_ACTOR_MOVE_EFF(msg)
- local msgLen = msg:GetDataLength()
- if msgLen <= 0 then
- return
- end
- local msgHdr = msg:GetHeader()
- local userid = msg:GetData():ReadString(msgLen)
- local effID = msgHdr.recog
- local skipWalk = msgHdr.param1
- local actor = global.actorManager:GetActor(userid)
- if not actor then
- return
- end
- if actor:IsPlayer() then
- actor:SetMoveEff(effID)
- actor:SetEffSkipWalkSwitch(skipWalk)
- end
- end
- -----------------------------------------------------------------------------
- -- 强制移动
- function gameMapController:handle_MSG_SC_NET_PLAYER_MOVE_FORCE(msg)
- local msgLen = msg:GetDataLength()
- if msgLen <= 0 then
- return
- end
- local msgData = msg:GetData():ReadString(msgLen)
- if msgData == "" then
- return nil
- end
- local jsonData = cjson.decode(msgData)
- if not jsonData then
- return nil
- end
- local actor = global.actorManager:GetActor(jsonData.UserID)
- if not actor then
- return nil
- end
- local msgHdr = msg:GetHeader()
- local mapX = msgHdr.param1
- local mapY = msgHdr.param2
- local dir = msgHdr.param3
- local data = {
- mapX = msgHdr.param1,
- mapY = msgHdr.param2,
- dir = msgHdr.param3
- }
- if actor:IsPlayer() then
- if actor:IsMainPlayer() then
- global.gamePlayerController:handle_Move_Force(actor,data)
- else
- global.netPlayerController:handle_Move_Force(actor, data)
- end
- else
- global.netMonsterController:handle_Move_Force(actor, data)
- end
- global.Facade:sendNotification(global.NoticeTable.ActorMoveForce, {actorID = jsonData.UserID, actor = actor})
- end
- ----------------------------------------------------------------------------
- function gameMapController:handle_MSG_SC_OPENHEALTH( msg )
- local msgLen = msg:GetDataLength()
- local msgData = (msgLen > 0 and msg:GetData():ReadString(msgLen) or "")
- local actorID = msgData
- dump(msgData,"handle_MSG_SC_OPENHEALTH")
- if not actorID then
- return
- end
- local actor = global.actorManager:GetActor( actorID )
- if nil == actor or 0 == actor then
- return
- end
- actor:setVisibleServerHpLabel(true)
- optionsUtils:InitHUDVisibleValue(actor, global.MMO.HUD_HMPLabel_VISIBLE)
- optionsUtils:refreshHUDHMpLabelVisible(actor)
- end
- function gameMapController:handle_MSG_SC_CLOSEHEALTH( msg )
- local msgLen = msg:GetDataLength()
- local msgData = (msgLen > 0 and msg:GetData():ReadString(msgLen) or "")
- local actorID = msgData
- dump(msgData,"handle_MSG_SC_CLOSEHEALTH")
- if not actorID then
- return
- end
- local actor = global.actorManager:GetActor( actorID )
- if nil == actor or 0 == actor then
- return
- end
- actor:setVisibleServerHpLabel(false)
-
- optionsUtils:InitHUDVisibleValue(actor, global.MMO.HUD_HMPLabel_VISIBLE)
- optionsUtils:refreshHUDHMpLabelVisible(actor)
- end
- -----------------------------------------------------------------------------
- -- 技能
- function gameMapController:handle_MSG_SC_PLAYER_SKILL_LAUNCH_SUCCESS(msg)
- local msgHdr = msg:GetHeader()
- local jsonData = ParseRawMsgToJson(msg)
- if not jsonData then
- return -1
- end
- local actorID = jsonData.UserID
- -- can't find actor
- local actor = global.actorManager:GetActor( actorID )
- if nil == actor then
- return
- end
- -- ignore main player
- if actor:IsPlayer() and actor:IsMainPlayer() then
- return
- end
- if actor:IsMonster() then
- global.netMonsterController:handle_MSG_SC_PLAYER_SKILL_LAUNCH_SUCCESS(actor, msgHdr, jsonData)
- elseif actor:IsPlayer() then
- global.netPlayerController:handle_MSG_SC_PLAYER_SKILL_LAUNCH_SUCCESS(actor, msgHdr, jsonData)
- end
- end
- function gameMapController:handle_MSG_SC_NET_PLAYER_ATTACK(msg)
- local msgHdr = msg:GetHeader()
- local jsonData = ParseRawMsgToJson(msg)
- if not jsonData then
- return -1
- end
- local actorID = jsonData.UserID
- -- can't find actor
- local actor = global.actorManager:GetActor( actorID )
- if nil == actor then
- return
- end
- -- ignore main player
- if actor:IsPlayer() and actor:IsMainPlayer() then
- return
- end
- if actor:IsMonster() then
- global.netMonsterController:handle_MSG_SC_NET_PLAYER_ATTACK(actor, msgHdr, jsonData)
- elseif actor:IsPlayer() then
- global.netPlayerController:handle_MSG_SC_NET_PLAYER_ATTACK(actor, msgHdr, jsonData)
- end
- end
- function gameMapController:handle_MSG_SC_PLAYER_SKILL_MAGIC_SUCCESS(msg)
- local msgHdr = msg:GetHeader()
- local jsonData = ParseRawMsgToJson(msg)
- if not jsonData then
- return -1
- end
- local actorID = jsonData.UserID
- -- can't find actor
- local actor = global.actorManager:GetActor( actorID )
- if nil == actor then
- return
- end
- jsonData.showSkillMaigc = msgHdr.recog == 1
- if actor:IsMonster() then
- global.netMonsterController:handle_MSG_SC_PLAYER_SKILL_MAGIC_SUCCESS(actor, msgHdr, jsonData)
- elseif actor:IsPlayer() then
- if actor:IsMainPlayer() then
- global.gamePlayerController:handle_MSG_SC_PLAYER_SKILL_MAGIC_SUCCESS(actor, msgHdr, jsonData)
- else
- global.netPlayerController:handle_MSG_SC_PLAYER_SKILL_MAGIC_SUCCESS(actor, msgHdr, jsonData)
- end
- end
- end
- function gameMapController:handle_MSG_SC_MAINPLAYER_MAGIC(msg)
- local header = msg:GetHeader()
- local x = header.param1
- local y = header.param2
- local sfxID = header.param3
- local offset = global.MMO.PLAYER_AVATAR_OFFSET
- local dest = global.sceneManager:MapPos2WorldPos(x, y, true)
- local root = global.sceneGraphCtl:GetSceneNode(global.MMO.NODE_SKILL)
- local sfx = global.FrameAnimManager:CreateSkillEffAnim(sfxID, 0)
- root:addChild(sfx)
- sfx:setLocalZOrder(sfxID)
- sfx:Play(0, 0, true)
- sfx:setPosition(cc.pAdd(dest, offset))
- sfx:SetAnimEventCallback(
- function(_, eventType)
- sfx:removeFromParent()
- sfx = nil
- end
- )
- end
- -----------------------------------------------------------------------------
- ----------------------------------刷新骑马 BEGIN----------------------------------
- function gameMapController:refreshHorse( actor,jsonData )
- if not actor or not actor:IsPlayer() then
- return
- end
- local isMainHorse = jsonData.mountID and jsonData.mountID > 0
- local actorid = {
- [1] = isMainHorse and jsonData.UserID or jsonData.doubleUserId,
- [2] = not isMainHorse and jsonData.UserID or jsonData.doubleUserId
- }
- for i,v in ipairs(actorid) do
- local actor = v and global.actorManager:GetActor(v) or nil
- if actor then
- actor:SetKeyValue(global.MMO.HORSE_MAIN, actorid[1])
- actor:SetKeyValue(global.MMO.HORSE_COPILOT, actorid[2])
- actor:SetDoubleHorse( jsonData.doubleTag )
- local data = {
- mountID = jsonData.mountID,
- mountEff = jsonData.mountEff,
- mountCloth = jsonData.mountCloth,
- hairID = actor:GetAnimationHairID()
- }
- local buffData =
- {
- actorID = actor:GetID(),
- buffID = global.MMO.BUFF_ID_HORSE,
- param = {
- feature = data,
- }
- }
- global.Facade:sendNotification(global.NoticeTable.AddBuffEntity, buffData)
- end
- end
- end
- ----------------------------------刷新骑马 END----------------------------------
- --------------------------------------------------------------------------------
- --- gm数据更新
- function gameMapController:MSG_SC_ACTOR_GMDATA_UPDATE(msg)
- local msgLen = msg:GetDataLength()
- if msgLen <= 0 then
- return
- end
- local msgData = msg:GetData():ReadString(msgLen)
- local slices = string.split(msgData, "|")
- local actorID = slices[1]
- local actor = global.actorManager:GetActor(actorID)
- if not actor or not (actor:IsPlayer() or actor:IsMonster()) then
- return
- end
- local items = {}
- for i = 2, 6 do
- items[i-1] = tonumber(slices[i])
- end
- actor:SetGMData(items)
- -- SL 广播
- SLBridge:onLUAEvent(LUA_EVENT_ACTOR_GMDATA_UPDATE, {id = actorID, data = actor:GetGMData()})
- end
- -- 玩家内力值更新
- function gameMapController:handle_MSG_SC_ACTOR_INTERNAL_FORCE_UPDATE(msg)
- local header = msg:GetHeader()
- local msgLen = msg:GetDataLength()
- if msgLen <= 0 then
- return
- end
- local actorID = msg:GetData():ReadString(msgLen)
- local actor = global.actorManager:GetActor(actorID)
- if not actor then
- return
- end
- if not (actor:IsPlayer() or actor:IsHero()) then
- return
- end
- local maxForce = header.recog
- local curForce = header.param1
- actor:SetNGHUD(curForce, maxForce)
- end
- -----------------------------------------------------------------------------
- -----------------------------------------------------------------------------
- -----------------------------------------------------------------------------
- function gameMapController:RegisterMsgHandler()
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_CREATE_MAIN_PLAYER, handler( self, self.handle_MSG_SC_CREATE_MAIN_PLAYER) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_PLAYER_IN_OF_VIEW, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_PLAYER_FLY_IN, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_PLAYER_FLY_IN_2, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_ACTOR_BUFF_INIT, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_ACTOR_BUFF_ADD, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_ACTOR_BUFF_RMV, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_ACTOR_EFFECT_UPDATE, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_PLAYER_FEATURE_CHANGED, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_PLAYER_WALK, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_PLAYER_RUN, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_PLAYER_RIDE_RUN, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_ACTOR_TURN, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_WALKEX, handler( self, self.handleMessage) )
-
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_PLAYER_HP_MP, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_DAMAGE_HP, handler( self, self.handleMessage) )
-
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_ACTOR_REFRESH_ACTOR_SPEED, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_REFRESH_MONSTER_SPEED, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_MONSTER_BORN, handler( self, self.handle_MSG_SC_NET_MONSTER_BORN) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_MONSTER_CAVE, handler( self, self.handle_MSG_SC_NET_MONSTER_CAVE) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_ACTOR_NAME, handler( self, self.handleMessage) ) -- 角色头顶数据(名子、称号等)
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_SELL_NOTICE, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_ACTION_PICK_CORPSE, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_ACTOR_DEATH_FALL_DOWN, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_ACTOR_DEATH_SKELETON, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_PLAYER_REVIVE, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_PLAYER_OUT_OF_VIEW, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_PLAYER_FLY_OUT, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_PLAYER_FLY_OUT_2, handler( self, self.handleMessage) )
-
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_ACTOR_ICONS_UPDATE, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_ACTOR_TITLE_UPDATE, handler( self, self.handleMessage) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SM_ACTOR_AUTO_MINING, handler( self, self.handleMessage) )
-
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_ACTOR_RELEVEL, handler( self, self.handleMessage) )
- -----------------------------------------------------------------------------
- -- main player
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_MAP_ACTOR_CLEANUP, handler( self, self.handle_MSG_SC_MAP_ACTOR_CLEANUP) )
- -----------------------------------------------------------------------------
- -----------------------------------------------------------------------------
- -- scene effect
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_MAP_ADD_SPECIAL_EFFECT, handler( self, self.handle_MSG_SC_MAP_ADD_SPECIAL_EFFECT) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_MAP_RMV_SPECIAL_EFFECT, handler( self, self.handle_MSG_SC_MAP_RMV_SPECIAL_EFFECT) )
- -----------------------------------------------------------------------------
- -----------------------------------------------------------------------------
- -- drop item
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_MAP_ITEM_DROP_BATCH, handler( self, self.handle_MSG_SC_MAP_ITEM_DROP_BATCH) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_MAP_ITEM_REMOVE_BATCH, handler( self, self.handle_MSG_SC_MAP_ITEM_REMOVE_BATCH) )
- -----------------------------------------------------------------------------
- -----------------------------------------------------------------------------
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_OPEN_DOOR_NOTICE, handler( self, self.handle_MSG_SC_OPEN_DOOR_NOTICE) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_CLOSE_DOOR_NOTICE, handler( self, self.handle_MSG_SC_CLOSE_DOOR_NOTICE) )
- -----------------------------------------------------------------------------
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_OPENHEALTH, handler( self, self.handle_MSG_SC_OPENHEALTH) )
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_CLOSEHEALTH, handler( self, self.handle_MSG_SC_CLOSEHEALTH) )
- -----------------------------------------------------------------------------
- -----------------------------------------------------------------------------
- -- 技能释放成功,进入释放动作
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_PLAYER_SKILL_LAUNCH_SUCCESS,handler(self, self.handle_MSG_SC_PLAYER_SKILL_LAUNCH_SUCCESS))
- -- 攻击成功,进入攻击动作+播放攻击特效
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_PLAYER_ATTACK, handler(self, self.handle_MSG_SC_NET_PLAYER_ATTACK))
- -- 技能释放成功,播放释放特效
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_PLAYER_SKILL_MAGIC_SUCCESS, handler(self, self.handle_MSG_SC_PLAYER_SKILL_MAGIC_SUCCESS))
- -- 地图某个位置播放一个特效
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_MAINPLAYER_MAGIC, handler(self, self.handle_MSG_SC_MAINPLAYER_MAGIC))
- -----------------------------------------------------------------------------
-
- -----------------------------------------------------------------------------
- -- 移动特效、足迹
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_ACTOR_MOVE_EFF, handler(self, self.handle_MSG_SC_ACTOR_MOVE_EFF))
- -----------------------------------------------------------------------------
-
- -----------------------------------------------------------------------------
- -- 强制移动
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_PLAYER_MOVE_FORCE, handler(self, self.handle_MSG_SC_NET_PLAYER_MOVE_FORCE))
- ------------------------------------------------------------------------------
- -----------------------------------------------------------------------------
- -- gmdata 更新
- LuaRegisterMsgHandler( global.MsgType.MSG_SC_ACTOR_GMDATA_UPDATE, handler(self, self.MSG_SC_ACTOR_GMDATA_UPDATE))
- -- 内力值 更新
- LuaRegisterMsgHandler(global.MsgType.MSG_SC_ACTOR_INTERNAL_FORCE_UPDATE, handler(self, self.handle_MSG_SC_ACTOR_INTERNAL_FORCE_UPDATE))
- -- 通知反击 特殊
- LuaRegisterMsgHandler(global.MsgType.MSG_SC_FIGHT_BACK_ID, handler(self, self.handle_MSG_SC_FIGHT_BACK_ID))
- ------------------------------------------------------------------------------
- -- in of view
- self.mNetMsgHandle[global.MsgType.MSG_SC_NET_PLAYER_IN_OF_VIEW] = function(msgHdr, msgData)
- self:handle_InOfView(msgHdr, msgData)
- end
- -- fly in effect
- self.mNetMsgHandle[global.MsgType.MSG_SC_NET_PLAYER_FLY_IN] = function(msgHdr, msgData)
- self:handle_FlyIn(msgHdr, msgData)
- end
- self.mNetMsgHandle[global.MsgType.MSG_SC_NET_PLAYER_FLY_IN_2] = function(msgHdr, msgData)
- self:handle_FlyIn2(msgHdr, msgData)
- end
-
- -- feature changed
- self.mNetMsgHandle[global.MsgType.MSG_SC_PLAYER_FEATURE_CHANGED] = function(msgHdr, msgData)
- self:handle_FeatureChanged(msgHdr, msgData)
- end
- -- walk
- self.mNetMsgHandle[global.MsgType.MSG_SC_NET_PLAYER_WALK] = function(msgHdr, msgData)
- self:handle_Walk(msgHdr, msgData)
- end
- -- run
- self.mNetMsgHandle[global.MsgType.MSG_SC_NET_PLAYER_RUN] = function(msgHdr, msgData)
- self:handle_Run(msgHdr, msgData)
- end
- -- 跑一格
- self.mNetMsgHandle[global.MsgType.MSG_SC_WALKEX] = function(msgHdr, msgData)
- self:handle_Run(msgHdr, msgData, true)
- end
- -- rile run
- self.mNetMsgHandle[global.MsgType.MSG_SC_NET_PLAYER_RIDE_RUN] = function(msgHdr, msgData)
- self:handle_RideRun(msgHdr, msgData)
- end
- -- turn
- self.mNetMsgHandle[global.MsgType.MSG_SC_NET_ACTOR_TURN] = function(msgHdr, msgData)
- self:handle_Turn(msgHdr, msgData)
- end
- -- refresh hp
- self.mNetMsgHandle[global.MsgType.MSG_SC_PLAYER_HP_MP] = function(msgHdr, msgData)
- self:handle_RefreshHP(msgHdr, msgData)
- end
- -- damage hp
- self.mNetMsgHandle[global.MsgType.MSG_SC_DAMAGE_HP] = function(msgHdr, msgData)
- self:handle_Damage(msgHdr, msgData)
- end
- -- refresh speed
- self.mNetMsgHandle[global.MsgType.MSG_SC_ACTOR_REFRESH_ACTOR_SPEED] = function(msgHdr, msgData)
- self:handle_RefreshSpeed(msgHdr, msgData)
- end
- -- refresh monster speed
- self.mNetMsgHandle[global.MsgType.MSG_SC_REFRESH_MONSTER_SPEED] = function(msgHdr, msgData)
- self:handle_RefreshMonsterSpeed(msgHdr, msgData)
- end
- -- refresh name
- self.mNetMsgHandle[global.MsgType.MSG_SC_ACTOR_NAME] = function(msgHdr, msgData)
- self:handle_RefreshName(msgHdr, msgData)
- end
- -- sell
- self.mNetMsgHandle[global.MsgType.MSG_SC_SELL_NOTICE] = function(msgHdr, msgData)
- self:handle_Sell(msgHdr, msgData)
- end
- -- pick corpse
- self.mNetMsgHandle[global.MsgType.MSG_SC_ACTION_PICK_CORPSE] = function(msgHdr, msgData)
- self:handle_PickCorpse(msgHdr, msgData)
- end
- -- death fall down
- self.mNetMsgHandle[global.MsgType.MSG_SC_NET_ACTOR_DEATH_FALL_DOWN] = function(msgHdr, msgData)
- self:handle_DeathFallDown(msgHdr, msgData)
- end
- self.mNetMsgHandle[global.MsgType.MSG_SC_NET_ACTOR_DEATH_SKELETON] = function(msgHdr, msgData)
- self:handle_DeathSkeleton(msgHdr, msgData)
- end
- -- death fall down
- self.mNetMsgHandle[global.MsgType.MSG_SC_NET_PLAYER_REVIVE] = function(msgHdr, msgData)
- self:handle_Revive(msgHdr, msgData)
- end
- -- out of view
- self.mNetMsgHandle[global.MsgType.MSG_SC_NET_PLAYER_OUT_OF_VIEW] = function(msgHdr, msgData)
- self:handle_OutOfView(msgHdr, msgData)
- end
- -- fly out effect
- self.mNetMsgHandle[global.MsgType.MSG_SC_NET_PLAYER_FLY_OUT] = function(msgHdr, msgData)
- self:handle_FlyOut(msgHdr, msgData)
- end
- self.mNetMsgHandle[global.MsgType.MSG_SC_NET_PLAYER_FLY_OUT_2] = function(msgHdr, msgData)
- self:handle_FlyOut2(msgHdr, msgData)
- end
- -- buff update
- self.mNetMsgHandle[global.MsgType.MSG_SC_ACTOR_BUFF_INIT] = function(msgHdr, msgData)
- global.BuffManager:handleBuffInit(msgHdr, msgData)
- end
- self.mNetMsgHandle[global.MsgType.MSG_SC_ACTOR_BUFF_ADD] = function(msgHdr, msgData)
- global.BuffManager:handleBuffAdd(msgHdr, msgData)
- end
- self.mNetMsgHandle[global.MsgType.MSG_SC_ACTOR_BUFF_RMV] = function(msgHdr, msgData)
- global.BuffManager:handleBuffRmv(msgHdr, msgData)
- end
- -- actor icons
- self.mNetMsgHandle[global.MsgType.MSG_SC_ACTOR_ICONS_UPDATE] = function(msgHdr, msgData)
- self:handle_Icons(msgHdr, msgData)
- end
- -- actor title
- self.mNetMsgHandle[global.MsgType.MSG_SC_ACTOR_TITLE_UPDATE] = function(msgHdr, msgData)
- self:handle_Title(msgHdr, msgData)
- end
- -- actor effect
- self.mNetMsgHandle[global.MsgType.MSG_SC_ACTOR_EFFECT_UPDATE] = function(msgHdr, msgData)
- global.ActorEffectManager:handle_ActorEffectUpdate(msgHdr, msgData)
- end
- -- actor auto mining
- self.mNetMsgHandle[global.MsgType.MSG_SM_ACTOR_AUTO_MINING] = function(msgHdr, msgData)
- self:handle_AutoMining(msgHdr, msgData)
- end
- -- actor relevel
- self.mNetMsgHandle[global.MsgType.MSG_SC_ACTOR_RELEVEL] = function(msgHdr, msgData)
- self:handle_ActorReLevel(msgHdr, msgData)
- end
- end
- return gameMapController
|