PetsEquipProxy.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local PetsEquipProxy = class("PetsEquipProxy", RemoteProxy)
  3. PetsEquipProxy.NAME = global.ProxyTable.PetsEquipProxy
  4. function PetsEquipProxy:ctor()
  5. PetsEquipProxy.super.ctor(self)
  6. self:clear()
  7. end
  8. function PetsEquipProxy:clear()
  9. local PetsEquipVO = requireVO("remote/PetsEquipVO")
  10. self.VOdata = PetsEquipVO.new()
  11. self.ItemBelongType = global.MMO.ITEM_FROM_BELONG_PETEQUIP
  12. self._petsData = {}
  13. self._attrByPetIdx = {}
  14. self._curSelectPetIdx = nil
  15. end
  16. function PetsEquipProxy:GetPetsData(...)
  17. return self._petsData
  18. end
  19. function PetsEquipProxy:GetEquipDataByPos(petIdx, pos)
  20. if not petIdx or not pos then
  21. return nil
  22. end
  23. local data = self.VOdata:GetDataByPos(petIdx, pos)
  24. return data
  25. end
  26. function PetsEquipProxy:GetEquipDataByMakeIndex(makeIndex)
  27. local data = self.VOdata:GetData()
  28. return data[makeIndex]
  29. end
  30. function PetsEquipProxy:GetAllEquipData()
  31. local data = self.VOdata:GetData()
  32. return data
  33. end
  34. function PetsEquipProxy:ClearEquipData()
  35. self.VOdata:ClearData()
  36. end
  37. function PetsEquipProxy:GetAttrByIdx(petIdx, attrId)
  38. if not petIdx or not attrId then
  39. return
  40. end
  41. if self._attrByPetIdx[petIdx] and next(self._attrByPetIdx[petIdx]) then
  42. return self._attrByPetIdx[petIdx][attrId]
  43. end
  44. end
  45. function PetsEquipProxy:GetSelectPetIdx(...)
  46. return self._curSelectPetIdx
  47. end
  48. function PetsEquipProxy:AddEquipData(item, petIdx)
  49. local posData = self:GetEquipDataByPos(petIdx, item.Where)
  50. if posData then
  51. self.VOdata:DelEquipData(posData, petIdx)
  52. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  53. ItemManagerProxy:SetItemBelong(posData.MakeIndex, nil)
  54. end
  55. self.VOdata:AddEquipData(item, petIdx)
  56. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  57. ItemManagerProxy:SetItemBelong(item.MakeIndex, self.ItemBelongType)
  58. end
  59. function PetsEquipProxy:DelEquipData(item, petIdx)
  60. local MakeIndex = item.MakeIndex
  61. local item = self:GetEquipDataByMakeIndex(MakeIndex)
  62. if item then
  63. self.VOdata:DelEquipData(item, petIdx)
  64. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  65. ItemManagerProxy:SetItemBelong(item.MakeIndex, nil)
  66. end
  67. end
  68. function PetsEquipProxy:TakeBackPetByIdx(petIdx)
  69. for i, pet in ipairs(self._petsData) do
  70. if pet and pet.Idx == petIdx then
  71. table.remove(self._petsData, i)
  72. break
  73. end
  74. end
  75. self.VOdata:ClearDataByPetIdx(petIdx)
  76. if self._curSelectPetIdx and self._curSelectPetIdx == petIdx then
  77. self._curSelectPetIdx = nil
  78. end
  79. end
  80. function PetsEquipProxy:RequestRecallPets(petIdx, param)
  81. LuaSendMsg(global.MsgType.MSG_CS_RECALL_PETS_REQUEST, petIdx, param or 0, 0, 0)
  82. end
  83. function PetsEquipProxy:RequestPetsEquipByIdx(petIdx)
  84. LuaSendMsg(global.MsgType.MSG_CS_PETS_WAER_EQUIP_REQUEST, petIdx, 0, 0, 0)
  85. end
  86. function PetsEquipProxy:RequestPetsEquipTakeOn(makeIndex, pos, ItemName, petsIdx)
  87. LuaSendMsg(global.MsgType.MSG_CS_PETS_TAKEON_ITEM_REQUEST, makeIndex, pos, petsIdx, 0, ItemName, string.len(ItemName))
  88. end
  89. function PetsEquipProxy:RequestPetsEquipTakeOff(data, petsIdx)
  90. local name = data.Name
  91. local pos = data.Where
  92. local MakeIndex = data.MakeIndex
  93. LuaSendMsg(global.MsgType.MSG_CS_PETS_TAKEOFF_ITEM_REQUEST, MakeIndex, pos, petsIdx, 0, name, string.len(name))
  94. end
  95. function PetsEquipProxy:handle_MSG_SC_PETS_TAKEON_FAIL(msg)
  96. local header = msg:GetHeader()
  97. local data = {}
  98. data.bRole = true
  99. data.isSuccess = false
  100. data.header = header
  101. -- dump(data,"MSG_SC_PETS_TAKEON_FAIL_______________")
  102. end
  103. function PetsEquipProxy:handle_MSG_SC_PETS_TAKEON_SUCCESS(msg)
  104. local header = msg:GetHeader()
  105. local data = {}
  106. data.bRole = true
  107. data.isSuccess = true
  108. data.header = header
  109. local petsIdx = header.param3 -- 宠物编号
  110. -- dump(data, "MSG_SC_PETS_TAKEON_SUCCESS_______________")
  111. end
  112. function PetsEquipProxy:handle_MSG_SC_PETS_TAKEOFF_SUCCESS(msg)
  113. local header = msg:GetHeader()
  114. local petsIdx = header.param3 -- 宠物编号
  115. -- dump(header,"handle_MSG_SC_PETS_TAKEOFF_SUCCESS___")
  116. end
  117. function PetsEquipProxy:handle_MSG_SC_PETS_TAKEOFF_FAIL(msg)
  118. local header = msg:GetHeader()
  119. local data = {}
  120. data.bRole = true
  121. data.isSuccess = false
  122. data.header = header
  123. -- dump(header,"handle_MSG_SC_PETS_TAKEOFF_FAIL__")
  124. end
  125. function PetsEquipProxy:InitPetsEquipData(petIdx, data)
  126. for k, equip in pairs(data) do
  127. if equip and equip ~= "" then
  128. equip = ChangeItemServersSendDatas(equip)
  129. self:AddEquipData(equip, petIdx)
  130. end
  131. end
  132. end
  133. function PetsEquipProxy:handle_MSG_SC_PETS_EQUIP_INFO(msg)
  134. local jsonData = ParseRawMsgToJson(msg)
  135. local header = msg:GetHeader()
  136. local petIdx = header.recog --宠物编号
  137. -- dump(jsonData,"MSG_SC_PETS_EQUIP_INFO_______")
  138. if not jsonData or next(jsonData) == nil then
  139. return
  140. end
  141. self:InitPetsEquipData(petIdx, jsonData)
  142. end
  143. function PetsEquipProxy:handle_MSG_SC_USER_PETS_DATA_INFO(msg)
  144. local msgLen = msg:GetDataLength()
  145. local dataString = msg:GetData():ReadString(msgLen)
  146. -- print(dataString,"pets_____________Info")
  147. local function ParseStrToList(str)
  148. local dataList = string.split(str, ";")
  149. for _, data in ipairs(dataList) do
  150. if data and string.len(data) > 0 then
  151. local petParams = string.split(data, ",")
  152. if next(petParams) and petParams[3] then
  153. local pet = {}
  154. pet.Idx = tonumber(petParams[1])
  155. pet.Name = petParams[2]
  156. pet.Appr = tonumber(petParams[3])
  157. table.insert(self._petsData, pet)
  158. end
  159. end
  160. end
  161. end
  162. ParseStrToList(dataString)
  163. end
  164. function PetsEquipProxy:handle_MSG_SC_PETS_ADD_ITEM(msg)
  165. local header = msg:GetHeader()
  166. local recog = header.recog
  167. local petIdx = header.param2
  168. local data = ParseRawMsgToJson(msg)
  169. -- print("------------------------------------")
  170. -- print(" into here to add Pets item")
  171. -- print("------------------------------------")
  172. if not recog or not data or next(data) == nil or not petIdx then
  173. return
  174. end
  175. data = ChangeItemServersSendDatas(data)
  176. data.Where = recog
  177. -- dump(data)
  178. -- print("穿戴宠物ID-----------------"..petIdx)
  179. self:AddEquipData(data, petIdx)
  180. end
  181. function PetsEquipProxy:handle_MSG_SC_PETS_DEL_EQUIP(msg)
  182. local header = msg:GetHeader()
  183. local recog = header.recog --位置
  184. local petIdx = header.param2
  185. local data = ParseRawMsgToJson(msg)
  186. -- print("------------------------------------")
  187. -- print(" into here to DEL Pets item")
  188. -- print("------------------------------------")
  189. if not recog or not data or next(data) == nil or not petIdx then
  190. return
  191. end
  192. data = ChangeItemServersSendDatas(data)
  193. data.Where = recog
  194. -- dump(data)
  195. -- print("脱下宠物ID-----------------"..petIdx)
  196. self:DelEquipData(data, petIdx)
  197. end
  198. function PetsEquipProxy:handle_MSG_SC_PET_PROPERTIES(msg)
  199. local data = ParseRawMsgToJson(msg)
  200. --宠物id
  201. local header = msg:GetHeader()
  202. local petIdx = header.recog
  203. if not petIdx then
  204. return
  205. end
  206. if not self._attrByPetIdx[petIdx] then
  207. self._attrByPetIdx[petIdx] = {}
  208. end
  209. local PShowAttType = GUIFunction:PShowAttType()
  210. local _attr = {}
  211. _attr[PShowAttType.Min_DEF] = data.ac1 --物防
  212. _attr[PShowAttType.Max_DEF] = data.ac2 --
  213. _attr[PShowAttType.Min_MDF] = data.mac1 --魔防
  214. _attr[PShowAttType.Max_MDF] = data.mac2
  215. _attr[PShowAttType.Min_ATK] = data.dc1 --物理
  216. _attr[PShowAttType.Max_ATK] = data.dc2
  217. _attr[PShowAttType.Min_MAT] = data.mc1 --魔法
  218. _attr[PShowAttType.Max_MAT] = data.mc2
  219. _attr[PShowAttType.Min_Daoshu] = data.sc1 --道术
  220. _attr[PShowAttType.Max_Daoshu] = data.sc2
  221. _attr[PShowAttType.HP] = data.hp --生命
  222. _attr[PShowAttType.MP] = data.maxmp --魔法
  223. _attr[PShowAttType.Weight] = data.weight--当前重量
  224. _attr[PShowAttType.Max_Weight] = data.maxweight--玩家最大负重
  225. _attr[PShowAttType.Wear_Weight] = data.wearweight--穿戴负重
  226. _attr[PShowAttType.Max_Wear_Weight] = data.maxwearweight--最大穿戴负重
  227. _attr[PShowAttType.Hand_Weight] = data.handweight--腕力
  228. _attr[PShowAttType.Max_Hand_Weight] = data.maxhandweight--当前最大可穿戴腕力
  229. _attr[PShowAttType.Anti_Magic] = data.antimagic
  230. _attr[PShowAttType.Hit_Point] = data.hitPoint
  231. _attr[PShowAttType.Speed_Point] = data.SpeedPoint
  232. _attr[PShowAttType.Anti_Posion] = data.AntiPoison
  233. _attr[PShowAttType.Posion_Recover] = data.PoisonRecover
  234. _attr[PShowAttType.Health_Recover] = data.HealthRecover
  235. _attr[PShowAttType.Spell_Recover] = data.SpellRecover
  236. _attr[PShowAttType.Hit_Speed] = data.HitSpeed
  237. _attr[PShowAttType.Block_Rate] = data.GedangRate
  238. _attr[PShowAttType.Block_Value] = data.GedangPower
  239. _attr[PShowAttType.Double_Rate] = data.BjRate
  240. _attr[PShowAttType.Double_Damage] = data.BjPoint
  241. _attr[PShowAttType.Defence] = data.Abil23
  242. _attr[PShowAttType.Double_Defence] = data.Abil24
  243. _attr[PShowAttType.More_Damage] = data.Abil25
  244. _attr[PShowAttType.ATK_Defence] = data.Abil26
  245. _attr[PShowAttType.MAT_Defence] = data.Abil27
  246. _attr[PShowAttType.Ignore_Defence] = data.Abil28
  247. _attr[PShowAttType.Bounce_Damage] = data.Abil29
  248. _attr[PShowAttType.Health_Add] = data.Abil30
  249. _attr[PShowAttType.Magice_Add] = data.Abil31
  250. _attr[PShowAttType.More_Item] = data.Abil32
  251. _attr[PShowAttType.Less_Item] = data.Abil33
  252. _attr[PShowAttType.Vampire] = data.Abil34
  253. _attr[PShowAttType.A_M_D_Add] = data.Abil35
  254. _attr[PShowAttType.Defence_Add] = data.Abil36
  255. _attr[PShowAttType.MDefence_Add] = data.Abil37
  256. _attr[PShowAttType.God_Damage] = data.Abil38
  257. _attr[PShowAttType.Lucky] = data.Abil39
  258. _attr[PShowAttType.Monster_Damage_Value] = data.Abil40
  259. _attr[PShowAttType.Monster_Damage_Per] = data.Abil41
  260. _attr[PShowAttType.Anger_Recover] = data.Abil42
  261. _attr[PShowAttType.Combine_Skill_Damage] = data.Abil43
  262. _attr[PShowAttType.Monster_DropItem] = data.Abil44
  263. _attr[PShowAttType.No_Palsy] = data.Abil45
  264. _attr[PShowAttType.No_Protect] = data.Abil46
  265. _attr[PShowAttType.No_Rebirth] = data.Abil47
  266. _attr[PShowAttType.No_ALL] = data.Abil48
  267. _attr[PShowAttType.No_Charm] = data.Abil49
  268. _attr[PShowAttType.No_Fire] = data.Abil50
  269. _attr[PShowAttType.No_Ice] = data.Abil51
  270. _attr[PShowAttType.No_Web] = data.Abil52
  271. _attr[PShowAttType.Att_UnKonw] = data.Abil53
  272. _attr[PShowAttType.More_A_Damage] = data.Abil54
  273. _attr[PShowAttType.Less_A_Damage] = data.Abil55
  274. _attr[PShowAttType.More_M_Damage] = data.Abil56
  275. _attr[PShowAttType.Less_M_Damage] = data.Abil57
  276. _attr[PShowAttType.More_D_Damage] = data.Abil58
  277. _attr[PShowAttType.Less_D_Damage] = data.Abil59
  278. _attr[PShowAttType.More_Health_Per] = data.Abil60
  279. _attr[PShowAttType.HP_Recover] = data.Abil61
  280. _attr[PShowAttType.MP_Recover] = data.Abil62
  281. _attr[PShowAttType.Drop_Rate] = data.Abil65
  282. _attr[PShowAttType.Exp_Add_Rate] = data.Abil66
  283. _attr[PShowAttType.Damage_Rate_Add] = data.Abil67
  284. _attr[PShowAttType.Damage_Human] = data.Abil68
  285. _attr[PShowAttType.Ice_Rate] = data.Abil69
  286. _attr[PShowAttType.Defen_Ice] = data.Abil70
  287. _attr[PShowAttType.Sec_Recovery_HP] = data.Abil71
  288. _attr[PShowAttType.Mon_Bj_Power_Rate] = data.Abil72
  289. _attr[PShowAttType.DC_Add_Rate] = data.Abil73
  290. local monPKV = data.FaMeMonPK or 0
  291. local abil74 = data.Abil74 or 0
  292. _attr[PShowAttType.Monster_Damage] = abil74 + monPKV
  293. _attr[PShowAttType.Monster_Damage_Percent]= data.Abil75
  294. _attr[PShowAttType.PK_Damage_Add_Percent] = data.Abil76
  295. local pk = data.FaMePK or 0
  296. local abil77 = data.Abil77 or 0
  297. _attr[PShowAttType.PK_Damage_Dec_Percent] = abil77 + pk
  298. _attr[PShowAttType.Penetrate] = data.Abil78
  299. _attr[PShowAttType.Death_Hit_Percent] = data.Abil79
  300. _attr[PShowAttType.Death_Hit_Value] = data.Abil80
  301. _attr[PShowAttType.Monster_Suck_HP_Rate] = data.Abil81
  302. _attr[PShowAttType.Monster_Vampire] = data.Abil82
  303. _attr[PShowAttType.Less_Monster_Damage] = data.Abil83
  304. _attr[PShowAttType.Drug_Recover] = data.Abil84
  305. _attr[PShowAttType.Ignore_Def_Dec] = data.Abil85
  306. _attr[PShowAttType.Fire_Hit_Dec_Rate] = data.Abil86
  307. _attr[PShowAttType.Ergum_Hit_Dec_Rate] = data.Abil87
  308. _attr[PShowAttType.Hit_Plus_Dec_Rate] = data.Abil88
  309. _attr[PShowAttType.Health_Add_WPer] = data.Abil89
  310. _attr[PShowAttType.Death_Hit_Dec_Percent] = data.Abil90
  311. _attr[PShowAttType.Sec_Recovery_MP] = data.Abil91
  312. if data.CustAbil then
  313. for i,v in ipairs(data.CustAbil) do
  314. _attr[v[1]] = v[2]
  315. end
  316. end
  317. self._attrByPetIdx[petIdx] = _attr
  318. end
  319. function PetsEquipProxy:handle_MSG_SC_PETS_SELECTED_ORBACK(msg)
  320. local header = msg:GetHeader()
  321. local recog = header.recog
  322. local isBack = header.param2 and header.param2 == 1
  323. if isBack and recog then -- 收回
  324. self:TakeBackPetByIdx(recog)
  325. else -- 当前选中
  326. self._curSelectPetIdx = recog
  327. end
  328. end
  329. function PetsEquipProxy:onRegister()
  330. PetsEquipProxy.super.onRegister(self)
  331. end
  332. function PetsEquipProxy:RegisterMsgHandler()
  333. PetsEquipProxy.super.RegisterMsgHandler(self)
  334. local msgType = global.MsgType
  335. --初始化装备信息
  336. LuaRegisterMsgHandler(msgType.MSG_SC_PETS_EQUIP_INFO, handler(self, self.handle_MSG_SC_PETS_EQUIP_INFO))
  337. -- 装备穿上确认-成功
  338. LuaRegisterMsgHandler(msgType.MSG_SC_PETS_TAKEON_SUCCESS, handler(self, self.handle_MSG_SC_PETS_TAKEON_SUCCESS))
  339. -- 装备穿上确认-失败
  340. LuaRegisterMsgHandler(msgType.MSG_SC_PETS_TAKEON_FAIL, handler(self, self.handle_MSG_SC_PETS_TAKEON_FAIL))
  341. -- 装备脱下确认-成功
  342. LuaRegisterMsgHandler(msgType.MSG_SC_PETS_TAKEOFF_SUCCESS, handler(self, self.handle_MSG_SC_PETS_TAKEOFF_SUCCESS))
  343. -- 装备脱下确认-失败
  344. LuaRegisterMsgHandler(msgType.MSG_SC_PETS_TAKEOFF_FAIL, handler(self, self.handle_MSG_SC_PETS_TAKEOFF_FAIL))
  345. -- 宠物信息下发
  346. LuaRegisterMsgHandler(msgType.MSG_SC_USER_PETS_DATA_INFO, handler(self, self.handle_MSG_SC_USER_PETS_DATA_INFO))
  347. -- 宠物装备增加
  348. LuaRegisterMsgHandler(msgType.MSG_SC_PETS_ADD_ITEM, handler(self, self.handle_MSG_SC_PETS_ADD_ITEM))
  349. -- 宠物装备删除(脱下)
  350. LuaRegisterMsgHandler(msgType.MSG_SC_PETS_DEL_EQUIP, handler(self, self.handle_MSG_SC_PETS_DEL_EQUIP))
  351. -- 宠物属性下发
  352. LuaRegisterMsgHandler(msgType.MSG_SC_PET_PROPERTIES, handler(self, self.handle_MSG_SC_PET_PROPERTIES))
  353. -- 下发当前选中/收回宠物
  354. LuaRegisterMsgHandler(msgType.MSG_SC_PETS_SELECTED_ORBACK, handler(self, self.handle_MSG_SC_PETS_SELECTED_ORBACK))
  355. end
  356. return PetsEquipProxy