WarOrder.lua 14 KB

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