WarOrder.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. local OrderExcel = require("excel.warOrder")
  2. local Grid = require("bag.Grid")
  3. local ItemDefine = require("bag.ItemDefine")
  4. local BagLogic = require("bag.BagLogic")
  5. local BuyLogic = require("topup.BuyLogic")
  6. local Json = require("common.Json")
  7. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  8. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  9. ------------------------------------------------------
  10. -- 战令对应数据
  11. ------------------------------------------------------
  12. local battleOrder = 1
  13. local devilOrder = 2
  14. local clanOrder = 3
  15. local arenaOrder = 4
  16. local passBattleExp = 5
  17. local passDevilExp = 5
  18. local passClanBattleExp = 10
  19. local victoryArenaBattleExp = 2
  20. local orderExpMap = {
  21. [battleOrder] = passBattleExp,
  22. [devilOrder] = passDevilExp,
  23. [clanOrder] = passClanBattleExp,
  24. [arenaOrder] = victoryArenaBattleExp,
  25. }
  26. local orderNameMap = {
  27. [battleOrder] = "battleOrder",
  28. [devilOrder] = "devilOrder",
  29. [clanOrder] = "clanOrder",
  30. [arenaOrder] = "arenaOrder",
  31. }
  32. local GC_WARORDER_CHANGE = 53
  33. local isRed = {}
  34. ------------------------------------------------------
  35. -- local 函数
  36. ------------------------------------------------------
  37. --[[
  38. warOrder = {
  39. [battleOrder] = {
  40. unlock = number
  41. exp = number
  42. finish = {
  43. [lv] = number
  44. }
  45. upgradeFinish = {}
  46. }
  47. }
  48. ]]
  49. local function checkRewardByIdx(human,orderType,idx)
  50. local orderName = orderNameMap[orderType]
  51. local orderData = human.db.warOrder[orderName]
  52. local isUpgradeOk
  53. if orderData.unlock ~= 0 and not orderData.upgradeFinish[idx] then
  54. isUpgradeOk = true
  55. end
  56. return not orderData.finish[idx] , isUpgradeOk
  57. end
  58. local function checkRed(human,orderType)
  59. if isRed[orderType] then
  60. --return 1
  61. end
  62. local orderName = orderNameMap[orderType]
  63. local cfg = OrderExcel[orderName]
  64. local orderData = human.db.warOrder[orderName]
  65. local exp = orderData.exp
  66. local maxFinishIdx = 0
  67. for lv in ipairs(orderData.finish) do
  68. if maxFinishIdx <= lv then
  69. maxFinishIdx = lv
  70. end
  71. end
  72. local maxUpgradeFinishIdx = 0
  73. for lv in ipairs(orderData.upgradeFinish) do
  74. if maxUpgradeFinishIdx <= lv then
  75. maxUpgradeFinishIdx = lv
  76. end
  77. end
  78. local maxFinishIdx = (maxFinishIdx > maxUpgradeFinishIdx) and maxUpgradeFinishIdx or maxFinishIdx
  79. local maxExpIdx = 0
  80. for _,cfg in pairs(cfg) do
  81. if cfg.process <= exp and maxExpIdx <= cfg.idx then
  82. maxExpIdx = cfg.idx
  83. end
  84. end
  85. isRed[orderType] = maxFinishIdx < maxExpIdx
  86. return isRed[orderType] and 1 or 0
  87. end
  88. local function push2Client(human,orderType)
  89. local orderName = orderNameMap[orderType]
  90. local orderData = human.db.warOrder[orderName]
  91. local finish = {}
  92. for lv in pairs(orderData.finish) do
  93. finish[#finish+1] = lv
  94. end
  95. local upgradeFinish = {}
  96. for lv in pairs(orderData.upgradeFinish) do
  97. upgradeFinish[#upgradeFinish+1] = lv
  98. end
  99. local data = {
  100. orderType = orderType,
  101. exp = orderData.exp,
  102. unlock = orderData.unlock,
  103. finish = finish,
  104. upgradeFinish = upgradeFinish,
  105. isRed = checkRed(human,orderType),
  106. }
  107. -- 临时require 确保两个文件不会相互引用
  108. local newLogic = require "role.NewLogic"
  109. newLogic.PushClient(human,GC_WARORDER_CHANGE,data)
  110. end
  111. local function genBuyItem()
  112. return {
  113. buyID = 0,
  114. region = "",
  115. cost = 0,
  116. icon = 0,
  117. name = "",
  118. desc = "",
  119. isFirst = 0,
  120. doubleCnt = 0,
  121. actDoubleCnt = 0,
  122. buyCnt = 0,
  123. vipExp = 0,
  124. zhekou = 0,
  125. yuanjia = 0,
  126. }
  127. end
  128. ------------------------------------------------------
  129. -- 对外暴露接口
  130. ------------------------------------------------------
  131. function isDot(human)
  132. local isDot = false
  133. for orderType in pairs(orderNameMap) do
  134. if checkRed(human,orderType) == 1 then
  135. isDot = true
  136. break
  137. end
  138. end
  139. return isDot
  140. end
  141. function warOrderInfo(human,orderType)
  142. local orderName = orderNameMap[orderType]
  143. local cfg = OrderExcel[orderName]
  144. local langCfg = OrderExcel.desc
  145. local orderData = human.db.warOrder[orderName]
  146. if not cfg or not orderData then
  147. return
  148. end
  149. -- 获取配置表相关数据, 发送给客户端
  150. local normal = {}
  151. for _,v in pairs(cfg) do
  152. local cfgData = {
  153. idx = v.idx,
  154. process = v.process,
  155. }
  156. local content = {}
  157. local upgradeContent = {}
  158. if #v.content ~= 0 then
  159. for _,item in ipairs(v.content) do
  160. local data = {
  161. getway = {},
  162. suipian = {},
  163. equip = {},
  164. fuwen = {},
  165. }
  166. if not ItemDefine.isEquip(item[1]) then
  167. Grid.makeItem(data, item[1], item[2])
  168. end
  169. content[#content + 1] = data
  170. end
  171. end
  172. if #v.upgradeContent ~= 0 then
  173. for _,item in ipairs(v.upgradeContent) do
  174. local data = {
  175. getway = {},
  176. suipian = {},
  177. equip = {},
  178. fuwen = {},
  179. }
  180. if not ItemDefine.isEquip(item[1]) then
  181. Grid.makeItem(data, item[1], item[2])
  182. end
  183. upgradeContent[#upgradeContent + 1] = data
  184. end
  185. end
  186. cfgData.content = content
  187. cfgData.upgradeContent = upgradeContent
  188. normal[#normal+1] = cfgData
  189. end
  190. local language = ""
  191. local buyItem = genBuyItem()
  192. local buyId
  193. for _,v in pairs(langCfg) do
  194. if v.type == orderType then
  195. language = v.desc
  196. buyId = v.buyId
  197. break
  198. end
  199. end
  200. if buyId then
  201. BuyLogic.fontBuyItem(human,buyItem,buyId)
  202. end
  203. -------------------
  204. local finish = {}
  205. for lv in pairs(orderData.finish) do
  206. finish[#finish+1] = lv
  207. end
  208. local upgradeFinish = {}
  209. for lv in pairs(orderData.upgradeFinish) do
  210. upgradeFinish[#upgradeFinish+1] = lv
  211. end
  212. return {
  213. orderType = orderType,
  214. normal = normal,
  215. language = language,
  216. buyItem = buyItem,
  217. -- 自身的进度问题
  218. exp = orderData.exp,
  219. unlock = orderData.unlock,
  220. finish = finish,
  221. upgradeFinish = upgradeFinish,
  222. }
  223. end
  224. function warOrderReward(human,orderType)
  225. local orderName = orderNameMap[orderType]
  226. local cfg = OrderExcel[orderName]
  227. local orderData = human.db.warOrder[orderName]
  228. if not cfg or not orderData then
  229. return
  230. end
  231. local process = orderData.exp
  232. local itemMap = {}
  233. --local finish_copy = table.copy(orderData.finish)
  234. --local upgrade_finish_copy = table.copy(orderData.upgradeFinish)
  235. for _,v in pairs(cfg) do
  236. if process >= v.process then
  237. local isOk,isUpgradeOk = checkRewardByIdx(human,orderType,v.idx)
  238. if isOk then
  239. for _,item in ipairs(v.content) do
  240. itemMap[item[1]] = itemMap[item[1]] or 0
  241. itemMap[item[1]] = itemMap[item[1]] + item[2]
  242. end
  243. orderData.finish[v.idx] = 0
  244. end
  245. if isUpgradeOk then
  246. for _,item in ipairs(v.upgradeContent) do
  247. itemMap[item[1]] = itemMap[item[1]] or 0
  248. itemMap[item[1]] = itemMap[item[1]] + item[2]
  249. end
  250. orderData.upgradeFinish[v.idx] = 0
  251. end
  252. end
  253. end
  254. -- 检查是否有可领取的item
  255. if not next(itemMap) then
  256. return
  257. end
  258. local itemList = {}
  259. for id,count in pairs(itemMap) do
  260. itemList[#itemList+1] = {
  261. id,count
  262. }
  263. end
  264. BagLogic.addItemList(human,itemList,"war_order_get")
  265. -- 同步数据
  266. --orderData.finish = finish_copy
  267. --orderData.upgradeFinish = upgrade_finish_copy
  268. ------------------------------------------------
  269. local finish = {}
  270. for lv in pairs(orderData.finish) do
  271. finish[#finish+1] = lv
  272. end
  273. local upgradeFinish = {}
  274. for lv in pairs(orderData.upgradeFinish) do
  275. upgradeFinish[#upgradeFinish+1] = lv
  276. end
  277. isRed[orderType] = nil
  278. -- 通知外层红点取消
  279. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2005)
  280. return {
  281. orderType = orderType,
  282. exp = orderData.exp,
  283. unlock = orderData.unlock,
  284. finish = finish,
  285. upgradeFinish = upgradeFinish,
  286. isRed = 0,
  287. }
  288. end
  289. -- 解锁战令
  290. function warOrderUnlock(human,orderType)
  291. local orderName = orderNameMap[orderType]
  292. local orderData = human.db.warOrder[orderName]
  293. if not orderData then
  294. print(" invalid orderType,not found data ")
  295. return
  296. end
  297. -- 已经解锁
  298. if orderData.unlock ~= 0 then
  299. print(" invalid op, warOrder unlocked ")
  300. return
  301. end
  302. orderData.unlock = 1
  303. push2Client(human,orderType)
  304. return true
  305. end
  306. -- 触发战令增加经验
  307. function trigger(human,orderType)
  308. local orderName = orderNameMap[orderType]
  309. local orderData = human.db.warOrder[orderName]
  310. local exp = orderExpMap[orderType]
  311. orderData.exp = orderData.exp + exp
  312. -- 是否需要推送?
  313. push2Client(human,orderType)
  314. -- 通知外层红点变更
  315. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2005)
  316. end
  317. function getWarOrderInfo(human,orderType,net)
  318. local orderName = orderNameMap[orderType]
  319. local orderData = human.db.warOrder[orderName]
  320. net.type = orderType
  321. net.exp = orderData.exp
  322. net.unlock = orderData.unlock
  323. net.isRed = checkRed(human,orderType)
  324. local finishIdx = 0
  325. for lv in pairs(orderData.finish) do
  326. finishIdx = finishIdx + 1
  327. net.finish[finishIdx] = lv
  328. end
  329. net.finish[0] = finishIdx
  330. local upgradeFinishIdx = 0
  331. for lv in pairs(orderData.upgradeFinish) do
  332. upgradeFinishIdx = upgradeFinishIdx + 1
  333. net.upgradeFinish[upgradeFinishIdx] = lv
  334. end
  335. net.upgradeFinish[0] = upgradeFinishIdx
  336. end