WarOrder.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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 nBuy = orderData.unlock
  66. local exp = orderData.exp
  67. local maxFinishIdx = 0
  68. for lv in ipairs(orderData.finish) do
  69. if maxFinishIdx <= lv then
  70. maxFinishIdx = lv
  71. end
  72. end
  73. local maxUpgradeFinishIdx = 0
  74. for lv in ipairs(orderData.upgradeFinish) do
  75. if maxUpgradeFinishIdx <= lv then
  76. maxUpgradeFinishIdx = lv
  77. end
  78. end
  79. if 1 == nBuy then
  80. maxFinishIdx = (maxFinishIdx > maxUpgradeFinishIdx) and maxUpgradeFinishIdx or maxFinishIdx
  81. end
  82. local maxExpIdx = 0
  83. for _,cfg in pairs(cfg) do
  84. if cfg.process <= exp and maxExpIdx <= cfg.idx then
  85. maxExpIdx = cfg.idx
  86. end
  87. end
  88. isRed[orderType] = maxFinishIdx < maxExpIdx
  89. return isRed[orderType] and 1 or 0
  90. end
  91. local function push2Client(human,orderType)
  92. local orderName = orderNameMap[orderType]
  93. local orderData = human.db.warOrder[orderName]
  94. local finish = {}
  95. for lv in pairs(orderData.finish) do
  96. finish[#finish+1] = lv
  97. end
  98. local upgradeFinish = {}
  99. for lv in pairs(orderData.upgradeFinish) do
  100. upgradeFinish[#upgradeFinish+1] = lv
  101. end
  102. local data = {
  103. orderType = orderType,
  104. exp = orderData.exp,
  105. unlock = orderData.unlock,
  106. finish = finish,
  107. upgradeFinish = upgradeFinish,
  108. isRed = checkRed(human,orderType),
  109. }
  110. -- 临时require 确保两个文件不会相互引用
  111. local newLogic = require "role.NewLogic"
  112. newLogic.PushClient(human,GC_WARORDER_CHANGE,data)
  113. end
  114. local function genBuyItem()
  115. return {
  116. buyID = 0,
  117. region = "",
  118. cost = 0,
  119. icon = 0,
  120. name = "",
  121. desc = "",
  122. isFirst = 0,
  123. doubleCnt = 0,
  124. actDoubleCnt = 0,
  125. buyCnt = 0,
  126. vipExp = 0,
  127. zhekou = 0,
  128. yuanjia = 0,
  129. }
  130. end
  131. --某个战令奖励是否已经领完, 返回false表示没有,true表示已经领完
  132. local function isGetAllAward(human,orderType)
  133. local warOrder = human.db.warOrder
  134. if not warOrder then
  135. return false
  136. end
  137. local orderName = orderNameMap[orderType]
  138. local cfg = OrderExcel[orderName]
  139. local orderData = warOrder[orderName]
  140. if not cfg or not orderData then
  141. return false
  142. end
  143. local allNum = #cfg
  144. local isGetAll = true
  145. --普通奖励
  146. local commonNum = 0
  147. local commonRecord = orderData.finish
  148. for k in pairs(commonRecord or {}) do
  149. commonNum = commonNum + 1
  150. end
  151. if commonNum < allNum then
  152. isGetAll = false
  153. return isGetAll
  154. end
  155. --进阶奖励
  156. local upgradeNum = 0
  157. local upgradeRecord = orderData.upgradeFinish
  158. for k in pairs(upgradeRecord or {}) do
  159. upgradeNum = upgradeNum + 1
  160. end
  161. if upgradeNum < allNum then
  162. isGetAll = false
  163. end
  164. return isGetAll
  165. end
  166. ------------------------------------------------------
  167. -- 对外暴露接口
  168. ------------------------------------------------------
  169. function isDot(human)
  170. local isDot = false
  171. for orderType in pairs(orderNameMap) do
  172. if checkRed(human,orderType) == 1 then
  173. isDot = true
  174. break
  175. end
  176. end
  177. return isDot
  178. end
  179. --判断是否显示入口, 返回true表示显示, false表示不显示, 领完四个类型战令的奖励就关闭
  180. function isOpen(human)
  181. for orderType in pairs(orderNameMap) do
  182. if not isGetAllAward(human,orderType) then
  183. return true
  184. end
  185. end
  186. return false
  187. end
  188. function warOrderInfo(human,orderType)
  189. local orderName = orderNameMap[orderType]
  190. local cfg = OrderExcel[orderName]
  191. local langCfg = OrderExcel.desc
  192. local orderData = human.db.warOrder[orderName]
  193. if not cfg or not orderData then
  194. return
  195. end
  196. -- 获取配置表相关数据, 发送给客户端
  197. local normal = {}
  198. for _,v in pairs(cfg) do
  199. local cfgData = {
  200. idx = v.idx,
  201. process = v.process,
  202. }
  203. local content = {}
  204. local upgradeContent = {}
  205. if #v.content ~= 0 then
  206. for _,item in ipairs(v.content) do
  207. local data = {
  208. getway = {},
  209. suipian = {},
  210. equip = {},
  211. fuwen = {},
  212. }
  213. if not ItemDefine.isEquip(item[1]) then
  214. Grid.makeItem(data, item[1], item[2])
  215. end
  216. content[#content + 1] = data
  217. end
  218. end
  219. if #v.upgradeContent ~= 0 then
  220. for _,item in ipairs(v.upgradeContent) do
  221. local data = {
  222. getway = {},
  223. suipian = {},
  224. equip = {},
  225. fuwen = {},
  226. }
  227. if not ItemDefine.isEquip(item[1]) then
  228. Grid.makeItem(data, item[1], item[2])
  229. end
  230. upgradeContent[#upgradeContent + 1] = data
  231. end
  232. end
  233. cfgData.content = content
  234. cfgData.upgradeContent = upgradeContent
  235. normal[#normal+1] = cfgData
  236. end
  237. local language = ""
  238. local buyItem = genBuyItem()
  239. local buyId
  240. for _,v in pairs(langCfg) do
  241. if v.type == orderType then
  242. language = v.desc
  243. buyId = v.buyId
  244. break
  245. end
  246. end
  247. if buyId then
  248. BuyLogic.fontBuyItem(human,buyItem,buyId)
  249. end
  250. -------------------
  251. local finish = {}
  252. for lv in pairs(orderData.finish) do
  253. finish[#finish+1] = lv
  254. end
  255. local upgradeFinish = {}
  256. for lv in pairs(orderData.upgradeFinish) do
  257. upgradeFinish[#upgradeFinish+1] = lv
  258. end
  259. return {
  260. orderType = orderType,
  261. normal = normal,
  262. language = language,
  263. buyItem = buyItem,
  264. -- 自身的进度问题
  265. exp = orderData.exp,
  266. unlock = orderData.unlock,
  267. finish = finish,
  268. upgradeFinish = upgradeFinish,
  269. }
  270. end
  271. function warOrderReward(human,orderType)
  272. local orderName = orderNameMap[orderType]
  273. local cfg = OrderExcel[orderName]
  274. local orderData = human.db.warOrder[orderName]
  275. if not cfg or not orderData then
  276. return
  277. end
  278. local process = orderData.exp
  279. local itemMap = {}
  280. --local finish_copy = table.copy(orderData.finish)
  281. --local upgrade_finish_copy = table.copy(orderData.upgradeFinish)
  282. local allAwardCnt = 0
  283. for _,v in pairs(cfg) do
  284. allAwardCnt = allAwardCnt + 1
  285. if process >= v.process then
  286. local isOk,isUpgradeOk = checkRewardByIdx(human,orderType,v.idx)
  287. if isOk then
  288. for _,item in ipairs(v.content) do
  289. itemMap[item[1]] = itemMap[item[1]] or 0
  290. itemMap[item[1]] = itemMap[item[1]] + item[2]
  291. end
  292. orderData.finish[v.idx] = 0
  293. end
  294. if isUpgradeOk then
  295. for _,item in ipairs(v.upgradeContent) do
  296. itemMap[item[1]] = itemMap[item[1]] or 0
  297. itemMap[item[1]] = itemMap[item[1]] + item[2]
  298. end
  299. orderData.upgradeFinish[v.idx] = 0
  300. end
  301. end
  302. end
  303. -- 检查是否有可领取的item
  304. if not next(itemMap) then
  305. return
  306. end
  307. local itemList = {}
  308. for id,count in pairs(itemMap) do
  309. itemList[#itemList+1] = {
  310. id,count
  311. }
  312. end
  313. BagLogic.addItemList(human,itemList,"war_order_get")
  314. -- 同步数据
  315. --orderData.finish = finish_copy
  316. --orderData.upgradeFinish = upgrade_finish_copy
  317. ------------------------------------------------
  318. local finish = {}
  319. for lv in pairs(orderData.finish) do
  320. finish[#finish+1] = lv
  321. end
  322. local upgradeFinish = {}
  323. for lv in pairs(orderData.upgradeFinish) do
  324. upgradeFinish[#upgradeFinish+1] = lv
  325. end
  326. isRed[orderType] = nil
  327. -- 通知外层红点取消
  328. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2005)
  329. --判断是否领完奖励要关闭入口显示了
  330. if #finish >= allAwardCnt and #upgradeFinish >= allAwardCnt then
  331. RoleSystemLogic.isClose(human, RoleSystemDefine.ROLE_SYS_ID_2005)
  332. end
  333. return {
  334. orderType = orderType,
  335. exp = orderData.exp,
  336. unlock = orderData.unlock,
  337. finish = finish,
  338. upgradeFinish = upgradeFinish,
  339. isRed = 0,
  340. }
  341. end
  342. -- 解锁战令
  343. function warOrderUnlock(human,orderType)
  344. local orderName = orderNameMap[orderType]
  345. local orderData = human.db.warOrder[orderName]
  346. if not orderData then
  347. print(" invalid orderType,not found data ")
  348. return
  349. end
  350. -- 已经解锁
  351. if orderData.unlock ~= 0 then
  352. print(" invalid op, warOrder unlocked ")
  353. return
  354. end
  355. orderData.unlock = 1
  356. push2Client(human,orderType)
  357. return true
  358. end
  359. -- 触发战令增加经验
  360. function trigger(human,orderType,cnt)
  361. cnt = cnt or 1 --默认触发一次
  362. local orderName = orderNameMap[orderType]
  363. local orderData = human.db.warOrder[orderName]
  364. local exp = orderExpMap[orderType]
  365. orderData.exp = orderData.exp + (exp * cnt)
  366. -- 是否需要推送?
  367. push2Client(human,orderType)
  368. -- 通知外层红点变更
  369. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2005)
  370. end
  371. function getWarOrderInfo(human,orderType,net)
  372. local orderName = orderNameMap[orderType]
  373. local orderData = human.db.warOrder[orderName]
  374. net.type = orderType
  375. net.exp = orderData.exp
  376. net.unlock = orderData.unlock
  377. net.isRed = checkRed(human,orderType)
  378. local finishIdx = 0
  379. for lv in pairs(orderData.finish) do
  380. finishIdx = finishIdx + 1
  381. net.finish[finishIdx] = lv
  382. end
  383. net.finish[0] = finishIdx
  384. local upgradeFinishIdx = 0
  385. for lv in pairs(orderData.upgradeFinish) do
  386. upgradeFinishIdx = upgradeFinishIdx + 1
  387. net.upgradeFinish[upgradeFinishIdx] = lv
  388. end
  389. net.upgradeFinish[0] = upgradeFinishIdx
  390. end