WarOrder.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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 = 13
  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. ------------------------------------------------------
  132. -- 对外暴露接口
  133. ------------------------------------------------------
  134. function isDot(human)
  135. local isDot = false
  136. for orderType in pairs(orderNameMap) do
  137. if checkRed(human,orderType) == 1 then
  138. isDot = true
  139. break
  140. end
  141. end
  142. return isDot
  143. end
  144. function warOrderInfo(human,orderType)
  145. local orderName = orderNameMap[orderType]
  146. local cfg = OrderExcel[orderName]
  147. local langCfg = OrderExcel.desc
  148. local orderData = human.db.warOrder[orderName]
  149. if not cfg or not orderData then
  150. return
  151. end
  152. -- 获取配置表相关数据, 发送给客户端
  153. local normal = {}
  154. for _,v in pairs(cfg) do
  155. local cfgData = {
  156. idx = v.idx,
  157. process = v.process,
  158. }
  159. local content = {}
  160. local upgradeContent = {}
  161. if #v.content ~= 0 then
  162. for _,item in ipairs(v.content) do
  163. local data = {
  164. getway = {},
  165. suipian = {},
  166. equip = {},
  167. fuwen = {},
  168. }
  169. if not ItemDefine.isEquip(item[1]) then
  170. Grid.makeItem(data, item[1], item[2])
  171. end
  172. content[#content + 1] = data
  173. end
  174. end
  175. if #v.upgradeContent ~= 0 then
  176. for _,item in ipairs(v.upgradeContent) do
  177. local data = {
  178. getway = {},
  179. suipian = {},
  180. equip = {},
  181. fuwen = {},
  182. }
  183. if not ItemDefine.isEquip(item[1]) then
  184. Grid.makeItem(data, item[1], item[2])
  185. end
  186. upgradeContent[#upgradeContent + 1] = data
  187. end
  188. end
  189. cfgData.content = content
  190. cfgData.upgradeContent = upgradeContent
  191. normal[#normal+1] = cfgData
  192. end
  193. local language = ""
  194. local buyItem = genBuyItem()
  195. local buyId
  196. for _,v in pairs(langCfg) do
  197. if v.type == orderType then
  198. language = v.desc
  199. buyId = v.buyId
  200. break
  201. end
  202. end
  203. if buyId then
  204. BuyLogic.fontBuyItem(human,buyItem,buyId)
  205. end
  206. -------------------
  207. local finish = {}
  208. for lv in pairs(orderData.finish) do
  209. finish[#finish+1] = lv
  210. end
  211. local upgradeFinish = {}
  212. for lv in pairs(orderData.upgradeFinish) do
  213. upgradeFinish[#upgradeFinish+1] = lv
  214. end
  215. return {
  216. orderType = orderType,
  217. normal = normal,
  218. language = language,
  219. buyItem = buyItem,
  220. -- 自身的进度问题
  221. exp = orderData.exp,
  222. unlock = orderData.unlock,
  223. finish = finish,
  224. upgradeFinish = upgradeFinish,
  225. }
  226. end
  227. function warOrderReward(human,orderType)
  228. local orderName = orderNameMap[orderType]
  229. local cfg = OrderExcel[orderName]
  230. local orderData = human.db.warOrder[orderName]
  231. if not cfg or not orderData then
  232. return
  233. end
  234. local process = orderData.exp
  235. local itemMap = {}
  236. --local finish_copy = table.copy(orderData.finish)
  237. --local upgrade_finish_copy = table.copy(orderData.upgradeFinish)
  238. for _,v in pairs(cfg) do
  239. if process >= v.process then
  240. local isOk,isUpgradeOk = checkRewardByIdx(human,orderType,v.idx)
  241. if isOk then
  242. for _,item in ipairs(v.content) do
  243. itemMap[item[1]] = itemMap[item[1]] or 0
  244. itemMap[item[1]] = itemMap[item[1]] + item[2]
  245. end
  246. orderData.finish[v.idx] = 0
  247. end
  248. if isUpgradeOk then
  249. for _,item in ipairs(v.upgradeContent) do
  250. itemMap[item[1]] = itemMap[item[1]] or 0
  251. itemMap[item[1]] = itemMap[item[1]] + item[2]
  252. end
  253. orderData.upgradeFinish[v.idx] = 0
  254. end
  255. end
  256. end
  257. -- 检查是否有可领取的item
  258. if not next(itemMap) then
  259. return
  260. end
  261. local itemList = {}
  262. for id,count in pairs(itemMap) do
  263. itemList[#itemList+1] = {
  264. id,count
  265. }
  266. end
  267. BagLogic.addItemList(human,itemList,"war_order_get")
  268. -- 同步数据
  269. --orderData.finish = finish_copy
  270. --orderData.upgradeFinish = upgrade_finish_copy
  271. ------------------------------------------------
  272. local finish = {}
  273. for lv in pairs(orderData.finish) do
  274. finish[#finish+1] = lv
  275. end
  276. local upgradeFinish = {}
  277. for lv in pairs(orderData.upgradeFinish) do
  278. upgradeFinish[#upgradeFinish+1] = lv
  279. end
  280. isRed[orderType] = nil
  281. -- 通知外层红点取消
  282. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2005)
  283. return {
  284. orderType = orderType,
  285. exp = orderData.exp,
  286. unlock = orderData.unlock,
  287. finish = finish,
  288. upgradeFinish = upgradeFinish,
  289. isRed = 0,
  290. }
  291. end
  292. -- 解锁战令
  293. function warOrderUnlock(human,orderType)
  294. local orderName = orderNameMap[orderType]
  295. local orderData = human.db.warOrder[orderName]
  296. if not orderData then
  297. print(" invalid orderType,not found data ")
  298. return
  299. end
  300. -- 已经解锁
  301. if orderData.unlock ~= 0 then
  302. print(" invalid op, warOrder unlocked ")
  303. return
  304. end
  305. orderData.unlock = 1
  306. push2Client(human,orderType)
  307. return true
  308. end
  309. -- 触发战令增加经验
  310. function trigger(human,orderType,cnt)
  311. cnt = cnt or 1 --默认触发一次
  312. local orderName = orderNameMap[orderType]
  313. local orderData = human.db.warOrder[orderName]
  314. local exp = orderExpMap[orderType]
  315. orderData.exp = orderData.exp + (exp * cnt)
  316. -- 是否需要推送?
  317. push2Client(human,orderType)
  318. -- 通知外层红点变更
  319. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2005)
  320. end
  321. function getWarOrderInfo(human,orderType,net)
  322. local orderName = orderNameMap[orderType]
  323. local orderData = human.db.warOrder[orderName]
  324. net.type = orderType
  325. net.exp = orderData.exp
  326. net.unlock = orderData.unlock
  327. net.isRed = checkRed(human,orderType)
  328. local finishIdx = 0
  329. for lv in pairs(orderData.finish) do
  330. finishIdx = finishIdx + 1
  331. net.finish[finishIdx] = lv
  332. end
  333. net.finish[0] = finishIdx
  334. local upgradeFinishIdx = 0
  335. for lv in pairs(orderData.upgradeFinish) do
  336. upgradeFinishIdx = upgradeFinishIdx + 1
  337. net.upgradeFinish[upgradeFinishIdx] = lv
  338. end
  339. net.upgradeFinish[0] = upgradeFinishIdx
  340. end