NewLogic.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. local Msg = require("core.Msg")
  2. local Broadcast = require("broadcast.Broadcast")
  3. local Lang = require("common.Lang")
  4. local Json = require("common.Json")
  5. local WarOrder = require("shop.WarOrder")
  6. --[[
  7. BuyItem = {
  8. buyID : number -- buy配置表id
  9. region : string -- 区域 默认cn
  10. cost : number -- 价格
  11. icon : number -- 图标
  12. name : string -- 名称
  13. desc : string -- 描述
  14. zhekou : number -- 折扣价
  15. yuanjia : number -- 原价
  16. ttl : number -- 有效期
  17. }
  18. Item = {
  19. id : number
  20. count : number
  21. }
  22. Gift = {
  23. id : number -- 礼包ID
  24. startTimeStamp : number -- 开启时间戳(秒)
  25. restTime : number -- 剩余时间(秒)
  26. buyItem : Buyitem -- 礼包信息
  27. content : {item} -- 礼包内容
  28. }
  29. ]]
  30. ------------------------------- CG请求 -------------------------------
  31. --[[
  32. CG_WARORDER_INFO = {
  33. orderType = number -- 战令类型 1 勇士之证 2 恶魔之证 3 工会之证明 4 竞技之证
  34. }
  35. ]]
  36. local CG_WARORDER_INFO = 201 -- 战令信息请求
  37. --[[
  38. orderType = number -- 战令类型
  39. ]]
  40. local CG_WARORDER_REWARD = 202 -- 战令获取奖励
  41. ------------------------------- GC推送 -------------------------------
  42. --[[
  43. GC_GIFT_GENERATE = {
  44. gift = Gift
  45. }
  46. ]]
  47. local GC_GIFT_GENERATE = 10 -- 新增礼包推送
  48. --[[
  49. GC_QUERY_GIFT = {
  50. list = {Gift}
  51. }
  52. ]]
  53. local GC_QUERY_GIFT = 11 -- 登录推送礼包数据
  54. --[[
  55. BuyItem = {
  56. BuyItem = {
  57. {"buyID", 1, "int"}, -- 支付ID
  58. {"region", 1, "string"}, -- 货币类型 CN/HK等
  59. {"cost", 1, "double"}, -- 价格 当前价格
  60. {"icon", 1, "int"}, -- 图标
  61. {"name", 1, "string"}, -- 名称
  62. {"desc", 1, "string"}, -- 描述
  63. {"isFirst", 1, "byte"}, -- 是否首次购买
  64. {"doubleCnt", 1, "byte"}, -- 双倍次数
  65. {"actDoubleCnt",1, "byte"}, -- 活动双倍次数
  66. {"useDoubleCnt",1, "int"}, -- 当前消耗双倍次数
  67. {"buyCnt", 1, "int"}, -- 当前购买次数
  68. {"vipExp", 1, "int"}, -- 附赠vip经验
  69. {"zhekou", 1, "int"}, -- 折扣
  70. {"yuanjia", 1, "int"}, -- 原价
  71. }
  72. }
  73. normal = {
  74. idx number 等级
  75. process number 等级对应所需进度
  76. content [ItemGrid]array 普通战令等级奖励
  77. upgradeContent [ItemGrid]array 升级战令等级奖励
  78. }
  79. GC_WARORDER_INFO = {
  80. orderType = orderType, -- 战令类型
  81. normal = [normal]array, -- 普通配置
  82. language = string
  83. buyItem = BuyItem, -- 战令商品信息
  84. -- 自身的进度
  85. exp = orderData.exp, -- 当前经验
  86. unlock = orderData.unlock, -- 是否解锁升级版 0 表示未解锁 1 表示解锁
  87. finish = [number]array, -- 已经完成的普通版等级
  88. upgradeFinish = [number]array, -- 已经完成的升级版等级
  89. }
  90. ]]
  91. local GC_WARORDER_INFO = 12 -- 战令信息推送
  92. --[[
  93. GC_WARORDER_CHANGE = {
  94. orderType = number -- 战令类型
  95. exp = number -- 战令经验
  96. unlock = number -- 是否解锁升级版 0 表示未解锁 1 表示解锁
  97. finish = [number]array -- idx数组
  98. upgradeFinish = [number]array -- idx数组
  99. isRed = number -- 是否红点
  100. }
  101. ]]
  102. local GC_WARORDER_CHANGE = 13 -- 战令数据推送
  103. -----------------------------------------------------------------------
  104. local push = {
  105. [GC_GIFT_GENERATE] = true,
  106. [GC_QUERY_GIFT] = true,
  107. [GC_WARORDER_INFO] = true,
  108. [GC_WARORDER_CHANGE] = true,
  109. }
  110. local handler = {
  111. [CG_WARORDER_INFO] = function(human,param)
  112. local orderType = assert(tonumber(param),"invalid param")
  113. local data = WarOrder.warOrderInfo(human,orderType)
  114. if not data then
  115. -- 参数错误,报错
  116. return
  117. end
  118. PushClient(human,GC_WARORDER_INFO,data)
  119. end,
  120. [CG_WARORDER_REWARD] = function(human,param)
  121. local orderType = assert(tonumber(param),"invalid param")
  122. local data = WarOrder.warOrderReward(human,orderType)
  123. if not data then
  124. -- 参数错误,报错
  125. return
  126. end
  127. PushClient(human,GC_WARORDER_CHANGE,data)
  128. end,
  129. }
  130. function NewProto(human, type, paramJson)
  131. -- print("newProto:",type,param)
  132. -- local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  133. -- msgRet.ret = type
  134. -- msgRet.tip = "test data"
  135. -- Msg.send(msgRet,human.fd)
  136. local f = assert(handler[type],"invalid proto type")
  137. --local param = Json.Decode(paramJson)
  138. return f(human,paramJson)
  139. end
  140. -- 主动推送给客户端
  141. function PushClient(human,type,data)
  142. print("======= push to client type",type)
  143. if not push[type] then
  144. Broadcast.sendErr(human, Lang.DRILL_CHOOSE_MY_ERR_INDEX .. " type is " .. type)
  145. return
  146. end
  147. local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  148. msgRet.ret = type
  149. msgRet.tip = Json.Encode(data)
  150. print("============ send msg len is ",#msgRet.tip)
  151. Msg.send(msgRet,human.fd)
  152. end