WarOrder.lua 12 KB

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