HorseProxy.lua 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local HorseProxy = class("HorseProxy", RemoteProxy)
  3. HorseProxy.NAME = global.ProxyTable.HorseProxy
  4. local optionsUtils = requireProxy("optionsUtils")
  5. function HorseProxy:ctor()
  6. HorseProxy.super.ctor( self )
  7. end
  8. -- 是否能施法
  9. function HorseProxy:IsLaunch( skillID )
  10. local player = global.gamePlayerController:GetMainPlayer()
  11. if player and player:GetHorseMasterID() then
  12. if SL:GetMetaValue("GAME_DATA", "off_horse_launch") == 1 then
  13. return false
  14. end
  15. --魔法盾除外
  16. if skillID ~= 31 then
  17. return false
  18. end
  19. end
  20. return true
  21. end
  22. -- 请求下马
  23. function HorseProxy:RequestHorseDown()
  24. if SL:GetMetaValue("GAME_DATA", "horse_down") == 1 then
  25. LuaSendMsg(global.MsgType.MSG_CS_HROSEDOWN)
  26. return true
  27. end
  28. return false
  29. end
  30. -- 邀请上马
  31. function HorseProxy:RequestHorseUpInvite(uid)
  32. LuaSendMsg(global.MsgType.MSG_CS_HORSE_INVITE,0,0,0,0,uid,string.len(uid))
  33. end
  34. -- 同意上马邀请
  35. function HorseProxy:RequestHorseUpInviteAgree(uid)
  36. LuaSendMsg( global.MsgType.MSG_CS_HORSE_AGREE,0,0,0,0,uid,string.len(uid))
  37. end
  38. -- 显示气泡
  39. function HorseProxy:ShowHorseInviteBubbleTips( isShow,uid)
  40. local callback = function()
  41. self:RequestHorseUpInviteAgree(uid)
  42. self:ShowHorseInviteBubbleTips(false)
  43. end
  44. local data = {}
  45. data.id = 14
  46. data.status = isShow == true
  47. data.callback = callback
  48. global.Facade:sendNotification(global.NoticeTable.BubbleTipsStatusChange, data)
  49. end
  50. --------------服务端返回的数据--------------------------------------
  51. -- 邀请上马
  52. function HorseProxy:handle_MSG_SC_HORSE_INVITE(msg)
  53. local msgLen = msg:GetDataLength()
  54. if msgLen > 0 then
  55. local dataString = msg:GetData():ReadString( msgLen)
  56. local actor = global.playerManager:FindOnePlayerInCurrViewFieldById(dataString)
  57. if actor then
  58. local str = string.format(GET_STRING(310000800),actor:GetName())
  59. ShowSystemTips(str)
  60. end
  61. self:ShowHorseInviteBubbleTips(true,dataString)
  62. end
  63. end
  64. -- 上马 参数1:外观,参数2:特效,字符串:|分割,|前是马主,后面是副驾
  65. function HorseProxy:handle_MSG_SC_HORSE_UP(msg)
  66. local msgHdr = msg:GetHeader()
  67. local msgLen = msg:GetDataLength()
  68. if msgLen > 0 then
  69. local dataString = msg:GetData():ReadString(msgLen)
  70. local horseid = string.split(dataString or "", "|")
  71. for i,id in ipairs(horseid) do
  72. if id and id ~= "" then
  73. local actor = global.actorManager:GetActor(id)
  74. if actor then
  75. actor:SetDoubleHorse(msgHdr.param2)
  76. actor:SetKeyValue(global.MMO.HORSE_MAIN, horseid[1])
  77. actor:SetKeyValue(global.MMO.HORSE_COPILOT, horseid[2])
  78. local buffData =
  79. {
  80. actorID = actor:GetID(),
  81. buffID = global.MMO.BUFF_ID_HORSE,
  82. param = {
  83. feature = {
  84. mountID = msgHdr.recog,
  85. mountEff = msgHdr.param1,
  86. mountCloth = msgHdr.param3,
  87. hairID = actor:GetAnimationHairID()
  88. },
  89. }
  90. }
  91. global.Facade:sendNotification(global.NoticeTable.AddBuffEntity, buffData)
  92. end
  93. end
  94. end
  95. end
  96. end
  97. -- 下马 参数1:方向,参数2:坐标X,参数3:坐标Y,字符串,玩家id
  98. function HorseProxy:handle_MSG_SC_HORSE_DOWN(msg)
  99. local msgLen = msg:GetDataLength()
  100. local jsondata = ParseRawMsgToJson(msg)
  101. if jsondata and jsondata.UserID then
  102. local actor = global.playerManager:FindOnePlayerInCurrViewFieldById(jsondata.UserID)
  103. if actor then
  104. local msgHdr = msg:GetHeader()
  105. local actorid = {
  106. actor:GetValueByKey(global.MMO.HORSE_MAIN),
  107. actor:GetValueByKey(global.MMO.HORSE_COPILOT)
  108. }
  109. local isMainHorse = jsondata.UserID == actorid[1]
  110. for i,v in ipairs(actorid) do
  111. local actor = v and global.playerManager:FindOnePlayerInCurrViewFieldById(v) or nil
  112. if actor then
  113. local isExit = v == jsondata.UserID
  114. actor:SetKeyValue(global.MMO.HORSE_COPILOT, nil)
  115. if isMainHorse or isExit then
  116. actor:SetDoubleHorse()
  117. actor:SetKeyValue(global.MMO.HORSE_MAIN, nil)
  118. end
  119. if isExit then
  120. local posOfAccepted = global.sceneManager:MapPos2WorldPos(msgHdr.param1, msgHdr.param2, true)
  121. if not actor:IsDie() and not actor:IsDeath() then
  122. actor:SetAction(global.MMO.ACTION_IDLE, true)
  123. global.actorManager:SetActorMapXY( actor, msgHdr.param1, msgHdr.param2 )
  124. actor:SetDirection(msgHdr.recog)
  125. actor:setPosition(posOfAccepted.x, posOfAccepted.y)
  126. end
  127. end
  128. local buffData =
  129. {
  130. actorID = actor:GetID(),
  131. buffID = global.MMO.BUFF_ID_HORSE,
  132. param = {
  133. isExit = isExit,
  134. feature = {
  135. mountID = actor:GetMonsterFeatureID(),
  136. mountEff = actor:GetMonsterEffectID(),
  137. mountCloth = actor:GetMonsterClothID(),
  138. hairID = actor:GetAnimationHairID(),
  139. isDown = actorid[2] and true or false
  140. }
  141. }
  142. }
  143. global.Facade:sendNotification(global.NoticeTable.AddBuffEntity, buffData)
  144. end
  145. end
  146. end
  147. end
  148. end
  149. function HorseProxy:RegisterMsgHandler()
  150. HorseProxy.super.RegisterMsgHandler(self)
  151. local msgType = global.MsgType
  152. LuaRegisterMsgHandler(msgType.MSG_SC_HORSE_UP, handler(self, self.handle_MSG_SC_HORSE_UP))
  153. LuaRegisterMsgHandler(msgType.MSG_SC_HORSE_DOWN, handler(self, self.handle_MSG_SC_HORSE_DOWN))
  154. LuaRegisterMsgHandler(msgType.MSG_SC_HORSE_INVITE, handler(self, self.handle_MSG_SC_HORSE_INVITE))
  155. end
  156. return HorseProxy