HeroSkinLogic.lua 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. --- 英雄皮肤
  2. local Grid = require("bag.Grid")
  3. local BuyExcel = require("excel.buy").buy
  4. local BagLogic = require("bag.BagLogic")
  5. local HeroSkinExcel = require("excel.present").heroSkin
  6. local SkinExcel = require("excel.skin").skin
  7. local SkinLogic = require("skin.SkinLogic")
  8. local HeadFrameExcel = require("excel.role").headFrame
  9. local RoleHeadLogic = require("role.RoleHeadLogic")
  10. local Msg = require("core.Msg")
  11. local Json = require("common.Json")
  12. local BuyLogic = require("topup.BuyLogic")
  13. local GC_SKIN_QUERY = 54
  14. local function genSkinUnit(human,id)
  15. local cfg = HeroSkinExcel[id]
  16. local buyCfg = BuyExcel[cfg.buyId]
  17. local region = human.region or "CN"
  18. local buyItem = {}
  19. BuyLogic.fontBuyItem(human, buyItem, cfg.buyId)
  20. local skinId = cfg.content[1]
  21. local skinCfg = SkinExcel[skinId]
  22. local attrs = {}
  23. for _,v in pairs(skinCfg.attrs) do
  24. attrs[#attrs + 1] = {
  25. key = v[1],
  26. value = v[2],
  27. }
  28. end
  29. local iconframeId = cfg.content[2]
  30. local iconframeCfg = HeadFrameExcel[iconframeId]
  31. local headNet = {}
  32. headNet.id = iconframeId
  33. headNet.desc = iconframeCfg.desc or ""
  34. headNet.keepTime = iconframeCfg.keepTime
  35. headNet.name = iconframeCfg.name or ""
  36. headNet.camp = iconframeCfg.camp or 0
  37. local len = #iconframeCfg.attrs
  38. headNet.attrs = {}
  39. for i = 1,len do
  40. headNet.attrs[i] = {
  41. key = iconframeCfg.attrs[i][1],
  42. value = iconframeCfg.attrs[i][2],
  43. }
  44. end
  45. return {
  46. id = id,
  47. buyItem = buyItem,
  48. skinData = {
  49. Id = skinId,
  50. attrs = attrs
  51. },
  52. Iconframe = headNet
  53. }
  54. end
  55. local function populateMsg(human, net, id)
  56. local cfg = HeroSkinExcel[id]
  57. local skinId = cfg.content[1]
  58. local skinCfg = SkinExcel[skinId]
  59. local iconframeId = cfg.content[2]
  60. local iconframeCfg = HeadFrameExcel[iconframeId]
  61. net.id = id
  62. net.skinId = skinId
  63. net.headId = iconframeId
  64. net.headDesc = iconframeCfg.desc or ""
  65. net.headKeepTime = iconframeCfg.keepTime
  66. net.headName = iconframeCfg.name or ""
  67. net.headCamp = iconframeCfg.camp or 0
  68. BuyLogic.fontBuyItem(human, net.buyItem, cfg.buyId)
  69. net.skinAttr[0] = #skinCfg.attrs
  70. for i, attrInfo in ipairs(skinCfg.attrs) do
  71. net.skinAttr[i].key = attrInfo[1]
  72. net.skinAttr[i].value = attrInfo[2]
  73. end
  74. net.headAttr[0] = #iconframeCfg.attrs
  75. for i, attrInfo in ipairs(iconframeCfg.attrs) do
  76. net.headAttr[i].key = attrInfo[1]
  77. net.headAttr[i].value = attrInfo[2]
  78. end
  79. end
  80. -----------------------------------------
  81. function query(human,panelId)
  82. local retLen = 0
  83. local ret = {}
  84. for id,cfg in pairs(HeroSkinExcel) do
  85. if cfg.panelId == panelId then
  86. -- ret[#ret+1] = genSkinUnit(human,id)
  87. retLen = retLen + 1
  88. ret[retLen] = id
  89. end
  90. end
  91. -- return {
  92. -- list = ret
  93. -- }
  94. local msgRet = Msg.gc.GC_SKIN_DATA_QUERY
  95. msgRet.ret = GC_SKIN_QUERY
  96. msgRet.isEnd = 0
  97. local len, msgMaxLen = 0, 20
  98. for _, id in ipairs(ret) do
  99. len = len + 1
  100. populateMsg(human, msgRet.skinData[len], id)
  101. if len >= msgMaxLen then
  102. msgRet.skinData[0] = len
  103. retLen = retLen - len
  104. if retLen <= 0 then
  105. msgRet.isEnd = 1
  106. return Msg.send(msgRet,human.fd)
  107. end
  108. Msg.send(msgRet,human.fd)
  109. len = 0
  110. end
  111. end
  112. if len > 0 then
  113. msgRet.skinData[0] = len
  114. msgRet.isEnd = 1
  115. Msg.send(msgRet,human.fd)
  116. end
  117. end
  118. function buy(human,buyId)
  119. local skinCfg
  120. for _,cfg in pairs(HeroSkinExcel) do
  121. if cfg.buyId == buyId then
  122. skinCfg = cfg
  123. break
  124. end
  125. end
  126. assert(skinCfg,"invalid buyId")
  127. -- 解锁皮肤和头像
  128. SkinLogic.skinUnlock(human,skinCfg.content[1]) --BagLogic.addItemList(human,skinCfg.content,"skin_buy")
  129. RoleHeadLogic.active(human,RoleHeadLogic.HEAD_TYPE_2,skinCfg.content[2])
  130. --刷新
  131. -- local data=query(human,skinCfg.panelId)
  132. -- RefreshClient(human,GC_SKIN_QUERY,data)
  133. query(human,skinCfg.panelId)
  134. end
  135. function RefreshClient(human,type,data)
  136. local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  137. msgRet.ret = type
  138. msgRet.tip = Json.Encode(data)
  139. Msg.send(msgRet,human.fd)
  140. end
  141. function SendSkinInfoByMoney(human, nMoney, nItemID)
  142. if not human or 0 >= nMoney then
  143. return
  144. end
  145. local ret = {}
  146. for id,cfg in pairs(HeroSkinExcel) do
  147. local nBuyID = cfg.buyId
  148. local tBuyCfg = BuyExcel[nBuyID]
  149. if tBuyCfg then
  150. local region = human.region or "CN"
  151. local nTrueMoney = tBuyCfg[region]
  152. if nMoney == nTrueMoney then
  153. ret[#ret+1] = genSkinUnit(human,id)
  154. end
  155. end
  156. end
  157. local data = {
  158. list = ret
  159. }
  160. local msgRet = Msg.gc.GC_ITEM_SKIN_INFO
  161. msgRet.nItemID = nItemID
  162. msgRet.data = Json.Encode(data)
  163. Msg.send(msgRet,human.fd)
  164. end
  165. function BuySkinBySuiPian(human, nSkinID, nItemID)
  166. local skinCfg
  167. for _,cfg in pairs(HeroSkinExcel) do
  168. if cfg.content[1] == nSkinID then
  169. skinCfg = cfg
  170. break
  171. end
  172. end
  173. assert(skinCfg,"invalid buyId")
  174. SkinLogic.skinUnlock(human,skinCfg.content[1]) --BagLogic.addItemList(human,skinCfg.content,"skin_buy")
  175. RoleHeadLogic.active(human,RoleHeadLogic.HEAD_TYPE_2,skinCfg.content[2])
  176. --刷新
  177. -- local data=query(human,skinCfg.panelId)
  178. -- RefreshClient(human,GC_SKIN_QUERY,data)
  179. query(human,skinCfg.panelId)
  180. BagLogic.delItem(human, nItemID, 1, "item_use")
  181. end