RelicLogic.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. --[[
  2. 数据库设计
  3. relic = {
  4. [camp] = {
  5. isLock = 1 -- 是否被锁住
  6. lv = 0 -- 等级
  7. exp = 0 -- 经验
  8. quality = 0 -- 品阶
  9. star = 0 -- 星
  10. tupoLv = 0 -- 突破等级
  11. lvAttr = {[key] = value}
  12. qualityAttr = {[key] = value}
  13. tupoAttr = {[key] = value}
  14. }
  15. }
  16. ]]
  17. local Msg = require("core.Msg")
  18. local RelicExcel = require("excel.relic")
  19. local HeroLogic = require("hero.HeroLogic")
  20. local HechengLogic = require("hecheng.HechengLogic")
  21. local FenjieLogic = require("hecheng.FenjieLogic")
  22. local Grid = require("bag.Grid")
  23. local Broadcast = require("broadcast.Broadcast")
  24. local Util = require("common.Util")
  25. local Lang = require("common.Lang")
  26. local function initDB(human)
  27. if human.db.relic then
  28. return
  29. end
  30. -- 初始化信息
  31. for i = 1,5 do
  32. human.db.relic[i] = {}
  33. human.db.relic[i].isLock = 1
  34. human.db.relic[i].lv = 1
  35. human.db.relic[i].exp = 0
  36. human.db.relic[i].quality = 0
  37. human.db.relic[i].star = 0
  38. human.db.relic[i].tupoLv = 0
  39. human.db.relic[i].lvAttr = {}
  40. human.db.relic[i].qualityAttr = {}
  41. human.db.relic[i].tupoAttr = {}
  42. end
  43. -- 第一阵营默认为已解锁状态
  44. human.db.relic[1].isLock = 0
  45. end
  46. local function getJinjieState(human,camp)
  47. initDB(human)
  48. local db = human.db.relic[camp]
  49. local nextQuality = db.quality + 1
  50. local config = RelicExcel.jinjie[nextQuality]
  51. if not config then
  52. return 0 -- 已达到最大阶数
  53. end
  54. if db.lv < config.needLv then
  55. return 1 -- 等级不够
  56. end
  57. -- 检查材料是否足够
  58. if human.db.jinbi < config.jinbi then
  59. return 2 -- 材料不足
  60. end
  61. local len = #config.item
  62. for i = 1,len do
  63. if BagLogic.getItemCnt(human, config.item[i][1]) < config.item[i][2] then
  64. return 2 -- 材料不足
  65. end
  66. end
  67. return 3 -- 可以进阶
  68. end
  69. -- 获取突破状态
  70. local function getTupoState(human,camp)
  71. initDB(human)
  72. local db = human.db.relic[camp]
  73. local nextTupo = db.tupoLv + 1
  74. local config = RelicExcel.tupo[nextTupo]
  75. if not config then
  76. return 0 -- 配置错误,或已达到最大等级
  77. end
  78. if db.quality < config.quality then
  79. return 1 -- 阶数不够
  80. end
  81. -- 检查材料是否足够
  82. if human.db.jinbi < config.jinbi then
  83. return 2 -- 材料不足
  84. end
  85. local len = #config.item
  86. for i = 1,len do
  87. if BagLogic.getItemCnt(human, config.item[i][1]) < config.item[i][2] then
  88. return 2 -- 材料不足
  89. end
  90. end
  91. return 3 -- 可以突破
  92. end
  93. local function getAttrTb(human,camp)
  94. initDB(human)
  95. local db = human.db.relic[camp]
  96. local attrTb = {}
  97. for k,v in pairs(db.lvAttr) do
  98. attrTb[k] = attrTb[k] or 0
  99. attrTb[k] = attrTb[k] + v
  100. end
  101. for k,v in pairs(db.qualityAttr) do
  102. attrTb[k] = attrTb[k] or 0
  103. attrTb[k] = attrTb[k] + v
  104. end
  105. for k,v in pairs(db.tupoAttr) do
  106. attrTb[k] = attrTb[k] or 0
  107. attrTb[k] = attrTb[k] + v
  108. end
  109. return attrTb
  110. end
  111. -- 界面查询
  112. function relicQuery(human,camp)
  113. -- 等级限制 todo
  114. if human.db.lv < 1 then
  115. return
  116. end
  117. -- 初始化数据
  118. initDB(human)
  119. if human.db.relic[camp].isLock ~= 1 then
  120. -- 未解锁
  121. unlockReturn(human,camp)
  122. else
  123. -- 已解锁
  124. lvUpReturn(human,camp)
  125. end
  126. end
  127. -- 未解锁界面返回
  128. function unlockReturn(human,camp)
  129. local msgRet = Msg.gc.GC_RELIC_UNLOCK_QUERY_RETURN
  130. for i = 1,5 do
  131. msgRet.lockMsg[i] = human.db.relic[i].isLock
  132. end
  133. msgRet.lockMsg[0] = 5
  134. HeroLogic.makeUpStarCond(msgRet.unlockNeed, RelicExcel.unlock[i].unlockNeed)
  135. Msg.send(msgRet,human.fd)
  136. end
  137. -- 解锁
  138. function unlockDo(human,camp,inputIDList,inputIndexList)
  139. -- 初始化数据
  140. initDB(human)
  141. local db = human.db.relic[camp]
  142. if db.isLock ~= 1 then
  143. return
  144. end
  145. if not HechengLogic.checkCond(human, inputIDList, inputIndexList, RelicExcel.unlock[camp].unlockNeed) then
  146. return
  147. end
  148. local fenjieList = FenjieLogic.fenjie(human, FenjieLogic.FENJIE_DO_JUEXING, inputIDList, inputIndexList)
  149. db.isLock = 0
  150. db.lv = 1
  151. local config = RelicExcel.lvup[db[camp].lv]
  152. local len = #config.attrAdd[camp]
  153. for i = 1,len do
  154. local key = config.attrAdd[camp][i][1]
  155. local value = config.attrAdd[camp][i][2]
  156. db.lvAttr[key] = db.lvAttr[key] or 0
  157. db.lvAttr[key] = db.lvAttr[key] + value
  158. end
  159. local msgRet = Msg.gc.GC_RELIC_UNLOCK_RETURN
  160. msgRet.camp = camp
  161. Msg.send(msgRet,human.fd)
  162. relicQuery(human,camp)
  163. end
  164. -- 升级界面返回
  165. function lvUpReturn(human,camp)
  166. local msgRet = Msg.gc.GC_RELIC_LVUP_QUERY_RETURN
  167. local db = human.db.relic
  168. for i = 1,5 do
  169. msgRet.lockMsg[i] = db[i].isLock
  170. end
  171. msgRet.lockMsg[0] = 5
  172. local config = RelicExcel.lvup[db[camp].lv]
  173. msgRet.lv = db[camp].lv
  174. msgRet.maxExp = config.exp
  175. msgRet.exp = db[camp].exp
  176. msgRet.jinbi = config.jinbi
  177. local len = #config.item
  178. for i = 1,len do
  179. Grid.makeItem(msgRet.item[i],config.item[i][1],config.item[i][2])
  180. end
  181. msgRet.item[0] = len
  182. local attrTb = getAttrTb(human,camp)
  183. local count = 0
  184. for k,v in pairs(attrTb) do
  185. count = count + 1
  186. msgRet.attr[count].key = k
  187. msgRet.attr[count].value = v
  188. end
  189. msgRet.attr[0] = count
  190. Msg.send(msgRet,human.fd)
  191. end
  192. -- 升级
  193. function lvUpDo(human,camp)
  194. -- 初始化数据
  195. initDB(human)
  196. -- 未解锁,返回
  197. local db = human.db.relic[camp]
  198. if db.isLock == 1 then
  199. return
  200. end
  201. -- 最大等级
  202. local maxLv = #RelicExcel.lvup
  203. -- 已经是最大等级
  204. if db.lv >= maxLv then
  205. return
  206. end
  207. local config = RelicExcel.lvup[db.lv]
  208. -- 检查材料是否足够
  209. if human.db.jinbi < config.jinbi then
  210. return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
  211. end
  212. local len = #config.item
  213. for i = 1,len do
  214. if BagLogic.getItemCnt(human, config.item[i][1]) < config.item[i][2] then
  215. local strName = ItemDefine.getValue(config.item[i][1], "name")
  216. return Broadcast.sendErr(human, Util.format(Lang.COMMON_NO_ITEM, strName))
  217. end
  218. end
  219. -- 扣除材料
  220. ObjHuman.updateJinbi(human, -config.jinbi, "relic_lvup")
  221. for i = 1,len do
  222. BagLogic.delItem(human, config.item[i][1], config.item[i][2], "relic_lvup")
  223. end
  224. -- 增加经验
  225. db.exp = db.exp + config.upExp
  226. if db.exp >= config.exp then
  227. db.exp = 0
  228. db.lv = db.lv + 1
  229. end
  230. local len = #RelicExcel.lvup[db.lv].attrAdd[camp]
  231. for i = 1,len do
  232. local key = RelicExcel.lvup[db.lv].attrAdd[camp][i][1]
  233. local value = RelicExcel.lvup[db.lv].attrAdd[camp][i][2]
  234. db.lvAttr[key] = db.lvAttr[key] or 0
  235. db.lvAttr[key] = db.lvAttr[key] + value
  236. end
  237. relicQuery(human,camp)
  238. end
  239. function jinjieQuery(human,camp)
  240. -- 初始化数据
  241. initDB(human)
  242. -- 未解锁,返回
  243. local db = human.db.relic[camp]
  244. if db.isLock == 1 then
  245. return
  246. end
  247. local nextQuality = db.quality + 1
  248. local config = RelicExcel.jinjie[nextQuality]
  249. if not config then
  250. return
  251. end
  252. local msgRet = Msg.gc.GC_RELIC_JINJIE_QUERY
  253. if config.tupo == 1 then
  254. local nextTupoLv = db.tupoLv + 1
  255. if nextTupoLv <= #RelicExcel.tupo then
  256. config = RelicExcel.tupo[nextTupoLv]
  257. end
  258. msgRet.unlockNeed[0] = 1
  259. HeroLogic.makeUpStarCond(msgRet.unlockNeed[1], config.unlockNeed)
  260. else
  261. msgRet.unlockNeed[0] = 0
  262. end
  263. msgRet.quality = db.quality
  264. msgRet.star = db.satr
  265. msgRet.tupoLv = db.tupoLv
  266. msgRet.jinbi = config.jinbi
  267. msgRet.needLv = config.needLv
  268. msgRet.canJinjie = getJinjieState(human,camp)
  269. msgRet.canTupo = getTupoState(human,camp)
  270. local count = 0
  271. local attrTb = getAttrTb(human,camp)
  272. for k,v in pairs(attrTb) do
  273. count = count + 1
  274. msgRet.attr[count].key = k
  275. msgRet.attr[count].value = v
  276. end
  277. msgRet.attr[0] = count
  278. local len = #config.item
  279. for i = 1,len do
  280. Grid.makeItem(msgRet.item[i],config.item[i][1],config.item[i][2])
  281. end
  282. msgRet.item[0] = len
  283. Msg.send(msgRet,human.fd)
  284. end
  285. -- 进阶预览
  286. function yulanQuery(human,camp)
  287. local config = RelicExcel.jinjie
  288. local msgRet = Msg.gc.GC_RELIC_JINJIE_YULAN_QUERY
  289. local len = #config
  290. for i = 1,len do
  291. msgRet.yulan[i].quality = i
  292. msgRet.yulan[i].desc = config[i].desc
  293. local attrLen = #RelicExcel.lvup[i].attr[camp]
  294. for j = 1,attrLen do
  295. count = count + 1
  296. local key = RelicExcel.lvup[i].attr[camp][j][1]
  297. local value = RelicExcel.lvup[i].attr[camp][j][2]
  298. msgRet.yulan[i].attr[count].key = k
  299. msgRet.yulan[i].attr[count].value = v
  300. end
  301. msgRet.attr[0] = count
  302. end
  303. msgRet.yulan[0] = len
  304. Msg.send(msgRet,human.fd)
  305. end
  306. -- 进阶
  307. function jinjieDo(human,camp)
  308. -- 初始化数据
  309. initDB(human)
  310. -- 未解锁,返回
  311. local db = human.db.relic[camp]
  312. if db.isLock == 1 then
  313. return
  314. end
  315. -- 已经是最大阶数
  316. local nextQuality = db.quality + 1
  317. local config = RelicExcel.jinjie[nextQuality]
  318. if not config then
  319. return
  320. end
  321. -- 需要等级不达标
  322. if db.lv < config.needLv then
  323. return
  324. end
  325. -- 需要突破等级不达标
  326. if db.tupoLv < config.needTupo then
  327. return
  328. end
  329. -- 检查材料是否足够
  330. if human.db.jinbi < config.jinbi then
  331. return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
  332. end
  333. local len = #config.item
  334. for i = 1,len do
  335. if BagLogic.getItemCnt(human, config.item[i][1]) < config.item[i][2] then
  336. local strName = ItemDefine.getValue(config.item[i][1], "name")
  337. return Broadcast.sendErr(human, Util.format(Lang.COMMON_NO_ITEM, strName))
  338. end
  339. end
  340. -- 扣除材料
  341. ObjHuman.updateJinbi(human, -config.jinbi, "relic_jinjie")
  342. for i = 1,len do
  343. BagLogic.delItem(human, config.item[i][1], config.item[i][2], "relic_jinjie")
  344. end
  345. -- 进阶
  346. db.quality = nextQuality
  347. db.satr = db.satr + 1
  348. local len = #config.attrAdd[camp]
  349. for i = 1,len do
  350. local key = config.attrAdd[camp][i][1]
  351. local value = config.attrAdd[camp][i][2]
  352. db.qualityAttr[key] = db.qualityAttr[key] or 0
  353. db.qualityAttr[key] = db.qualityAttr[key] + value
  354. end
  355. jinjieQuery(human,camp)
  356. end
  357. -- 突破
  358. function tupoDo(human,camp,inputIDList, inputIndexList)
  359. -- 初始化数据
  360. initDB(human)
  361. -- 未解锁,返回
  362. local db = human.db.relic[camp]
  363. if db.isLock == 1 then
  364. return
  365. end
  366. -- 已经是最大阶数
  367. local nextTupoLv = db.tupoLv + 1
  368. local config = RelicExcel.tupo[nextTupoLv]
  369. if not config then
  370. return
  371. end
  372. -- 需要品阶不达标
  373. if db.quality < config.quality then
  374. return
  375. end
  376. -- 检查材料是否足够
  377. if human.db.jinbi < config.jinbi then
  378. return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
  379. end
  380. local len = #config.item
  381. for i = 1,len do
  382. if BagLogic.getItemCnt(human, config.item[i][1]) < config.item[i][2] then
  383. local strName = ItemDefine.getValue(config.item[i][1], "name")
  384. return Broadcast.sendErr(human, Util.format(Lang.COMMON_NO_ITEM, strName))
  385. end
  386. end
  387. if not HechengLogic.checkCond(human, inputIDList, inputIndexList, RelicExcel.unlock[camp].unlockNeed) then
  388. return
  389. end
  390. local fenjieList = FenjieLogic.fenjie(human, FenjieLogic.FENJIE_DO_JUEXING, inputIDList, inputIndexList)
  391. -- 扣除材料
  392. ObjHuman.updateJinbi(human, -config.jinbi, "relic_jinjie")
  393. for i = 1,len do
  394. BagLogic.delItem(human, config.item[i][1], config.item[i][2], "relic_jinjie")
  395. end
  396. -- 进阶
  397. db.tupoLv = nextTupoLv
  398. db.satr = 0
  399. local msgRet = Msg.gc.GC_RELIC_TUPO_RETURN
  400. msgRet.camp = camp
  401. msgRet.lv = db.tupoLv
  402. local count = 0
  403. for k,v in pairs(db.tupoAttr) do
  404. count = count + 1
  405. msgRet.befAttr[count].key = k
  406. msgRet.befAttr[count].value = v
  407. end
  408. msgRet.befAttr[0] = count
  409. local len = #config.attrAdd[camp]
  410. for i = 1,len do
  411. local key = config.attrAdd[camp][i][1]
  412. local value = config.attrAdd[camp][i][2]
  413. db.tupoAttr[key] = db.tupoAttr[key] or 0
  414. db.tupoAttr[key] = db.tupoAttr[key] + value
  415. end
  416. count = 0
  417. for k,v in pairs(db.tupoAttr) do
  418. count = count + 1
  419. msgRet.aftAttr[count].key = k
  420. msgRet.aftAttr[count].value = v
  421. end
  422. msgRet.aftAttr[0] = count
  423. Msg.send(msgRet,human.fd)
  424. end
  425. -- 计算圣器属性
  426. function doCalcHero(human, grid, attrs)
  427. if not human then return end
  428. initDB(human)
  429. local heroConfig = HeroExcel.hero[grid.id]
  430. local relicCamp = human.db.relic[heroConfig.camp]
  431. for k,v in pairs(relicCamp.lvAttr) do
  432. RoleAttr.updateValue(k,v,attrs)
  433. end
  434. for k,v in pairs(relicCamp.qualityAttr) do
  435. RoleAttr.updateValue(k,v,attrs)
  436. end
  437. for k,v in pairs(relicCamp.tupoAttr) do
  438. RoleAttr.updateValue(k,v,attrs)
  439. end
  440. end