HeroSkinLogic.lua 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. len = 0
  109. end
  110. end
  111. if len > 0 then
  112. msgRet.skinData[0] = len
  113. msgRet.isEnd = 1
  114. Msg.send(msgRet,human.fd)
  115. end
  116. end
  117. function buy(human,buyId)
  118. local skinCfg
  119. for _,cfg in pairs(HeroSkinExcel) do
  120. if cfg.buyId == buyId then
  121. skinCfg = cfg
  122. break
  123. end
  124. end
  125. assert(skinCfg,"invalid buyId")
  126. -- 解锁皮肤和头像
  127. SkinLogic.skinUnlock(human,skinCfg.content[1]) --BagLogic.addItemList(human,skinCfg.content,"skin_buy")
  128. RoleHeadLogic.active(human,RoleHeadLogic.HEAD_TYPE_2,skinCfg.content[2])
  129. --刷新
  130. -- local data=query(human,skinCfg.panelId)
  131. -- RefreshClient(human,GC_SKIN_QUERY,data)
  132. query(human,skinCfg.panelId)
  133. end
  134. function RefreshClient(human,type,data)
  135. local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  136. msgRet.ret = type
  137. msgRet.tip = Json.Encode(data)
  138. Msg.send(msgRet,human.fd)
  139. end
  140. function SendSkinInfoByMoney(human, nMoney, nItemID)
  141. if not human or 0 >= nMoney then
  142. return
  143. end
  144. local ret = {}
  145. for id,cfg in pairs(HeroSkinExcel) do
  146. local nBuyID = cfg.buyId
  147. local tBuyCfg = BuyExcel[nBuyID]
  148. if tBuyCfg then
  149. local region = human.region or "CN"
  150. local nTrueMoney = tBuyCfg[region]
  151. if nMoney == nTrueMoney then
  152. ret[#ret+1] = genSkinUnit(human,id)
  153. end
  154. end
  155. end
  156. local data = {
  157. list = ret
  158. }
  159. local msgRet = Msg.gc.GC_ITEM_SKIN_INFO
  160. msgRet.nItemID = nItemID
  161. msgRet.data = Json.Encode(data)
  162. Msg.send(msgRet,human.fd)
  163. end
  164. function BuySkinBySuiPian(human, nSkinID, nItemID)
  165. local skinCfg
  166. for _,cfg in pairs(HeroSkinExcel) do
  167. if cfg.content[1] == nSkinID then
  168. skinCfg = cfg
  169. break
  170. end
  171. end
  172. assert(skinCfg,"invalid buyId")
  173. SkinLogic.skinUnlock(human,skinCfg.content[1]) --BagLogic.addItemList(human,skinCfg.content,"skin_buy")
  174. RoleHeadLogic.active(human,RoleHeadLogic.HEAD_TYPE_2,skinCfg.content[2])
  175. --刷新
  176. -- local data=query(human,skinCfg.panelId)
  177. -- RefreshClient(human,GC_SKIN_QUERY,data)
  178. query(human,skinCfg.panelId)
  179. BagLogic.delItem(human, nItemID, 1, "item_use")
  180. end