YjTreasureLogic.lua 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. -- 遗迹探宝 --
  2. --开服第一天开启 单数天重置
  3. --
  4. local ObjHuman = require("core.ObjHuman")
  5. local RoleLogic = require("role.RoleLogic")
  6. local Util = require("common.Util")
  7. local Msg = require("core.Msg")
  8. local Broadcast = require("broadcast.Broadcast")
  9. local Lang = require("common.Lang")
  10. local BagLogic = require("bag.BagLogic")
  11. local CombatDefine = require("combat.CombatDefine")
  12. local HeroGrid = require("hero.HeroGrid")
  13. local YjTreasureExcel = require("excel.yjTreasure")
  14. local YjTreasureDBLogic = require("yjTreasure.YjTreasureDB")
  15. local Grid = require("bag.Grid")
  16. local ItemDefine = require("bag.ItemDefine")
  17. local CommonDB = require("common.CommonDB")
  18. local YjTreasureCombat = require("yjTreasure.YjTreasureCombat")
  19. local CombatLogic = require("combat.CombatLogic")
  20. local LiLianLogic = require("dailyTask.LiLianLogic")
  21. local MoshouLogic = require("moshou.MoshouLogic")
  22. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  23. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  24. local Timer = require("core.Timer")
  25. local MengxinLogic = require("present.MengxinLogic")
  26. local HeroGrowUp = require("absAct.HeroGrowUp")
  27. local Log = require("common.Log")
  28. local YunYingLogic = require("yunying.YunYingLogic")
  29. YJ_TREASURE_GRID_MAX = 25 --从左到右 从上到下 1-25个格子
  30. YJ_TREASURE_GRID_KONGDI = 1 --空地
  31. YJ_TREASURE_GRID_ITEM = 2 --道具
  32. YJ_TREASURE_GRID_YJSHOPER = 3 --遗迹商人
  33. YJ_TREASURE_GRID_TREASURE_SHOP = 4 --探险商店(格子内的商店)
  34. YJ_TREASURE_GRID_BUFF = 5 --buff
  35. YJ_TREASURE_GRID_SOUL = 6 --灵魂拷问
  36. YJ_TREASURE_GRID_QUESTION = 7 --答题
  37. YJ_TREASURE_GRID_DICE = 8 --骰子
  38. YJ_TREASURE_GRID_BOX = 9 --宝箱
  39. YJ_TREASURE_GRID_KEY = 10 --钥匙
  40. YJ_TREASURE_GRID_MONSTER = 11 --怪物
  41. YJ_TREASURE_GRID_BOSS = 12 --BOSS
  42. YJ_TREASURE_GRID_DOOR = 13 --跳转口
  43. YJ_YAOJI_CURE = 1 --生命药剂
  44. YJ_YAOJI_KILL = 2 --死亡药剂
  45. YJ_SHOP_YJSHOPER = 1 --神秘商人
  46. YJ_SHOP_TREASURE_SHOP = 2 --遗迹商店
  47. YJ_DICE_JINBI = 1 --好运骰子 金币
  48. YJ_DICE_ZUANSHI = 2 --好运骰子 钻石
  49. YJ_SHOP_ALLSHOP_SEND_MAX = 100 --探险商城商品列表展示上限
  50. YJ_TREASURE_POS_MAX = 5 --上阵英雄上限
  51. YJ_TREASURE_MONSTERS = 5 --怪物+boss
  52. YJ_TREASURE_BILLBOARD_SHOW = 1000 --该名次外的玩家显示未上榜
  53. YJ_TREASURE_QUICK_MAX = 10
  54. -- 获取结束时间
  55. local function YjTreasureLogic_GetEndTime()
  56. local nNowTime = os.time()
  57. local openDay = CommonDB.getServerOpenDay()
  58. if not openDay then
  59. openDay = 1
  60. end
  61. local tNowDate = os.date("*t", nNowTime)
  62. tNowDate.hour = 0
  63. tNowDate.min = 0
  64. tNowDate.sec = 0
  65. if openDay % 2 == 1 then
  66. tNowDate.day = tNowDate.day + 2
  67. else
  68. tNowDate.day = tNowDate.day + 1
  69. end
  70. local nEndTime = os.time(tNowDate)
  71. return nEndTime
  72. end
  73. function initAfterStart()
  74. local yjTime = CommonDB.getYjTreasureEndTime()
  75. if not yjTime then
  76. return
  77. end
  78. local now = os.time()
  79. if now >= (yjTime + 2 * 86400) then
  80. reset()
  81. end
  82. end
  83. function onZero()
  84. Timer.addLater(1, reset)
  85. end
  86. --重置
  87. function reset()
  88. local openDay = CommonDB.getServerOpenDay()
  89. if not openDay then
  90. return
  91. end
  92. if openDay % 2 ~= 1 then
  93. return
  94. end
  95. beforeReset()
  96. local yjTime = CommonDB.getYjTreasureEndTime()
  97. if not yjTime then
  98. return
  99. end
  100. for uuid, roledata in pairs(YjTreasureDBLogic.YJ_Uuid2Role) do
  101. roledata.objList = nil
  102. roledata.layerData = nil
  103. roledata.tansuo = nil
  104. roledata.allShop = nil
  105. roledata.killMonster = nil
  106. roledata.buff = nil
  107. roledata.sangdang = nil
  108. roledata.time = nil
  109. roledata.yaojis = nil
  110. YjTreasureDBLogic.updateUuid2Role(roledata)
  111. end
  112. CommonDB.setYjTreasureEndTime(os.time())
  113. --刷新排行榜
  114. YjTreasureDBLogic.YJ_Rank2Uuid = {}
  115. end
  116. function beforeReset()
  117. for uuid, human in pairs(ObjHuman.onlineUuid) do
  118. -- 结束战斗
  119. CombatLogic.clientFinish(human, CombatDefine.COMBAT_TYPE10)
  120. human.db.combatQuick[CombatDefine.COMBAT_TYPE10] = 0
  121. -- 推送退出遗迹界面
  122. Msg.send(Msg.gc.GC_YJTREASURE_OUT, human.fd)
  123. end
  124. end
  125. --离重置剩余时间
  126. function getLeftTime()
  127. local openDay = CommonDB.getServerOpenDay()
  128. if not openDay then
  129. return 0
  130. end
  131. local now = os.time()
  132. local nEndTime = YjTreasureLogic_GetEndTime()
  133. return nEndTime - now
  134. -- local nowStartTime = CommonDB.getYjTreasureEndTime()
  135. -- if openDay % 2 == 1 then --本轮活动第一天
  136. -- return nowStartTime + 86400 * 2 - now
  137. -- else --第二天
  138. -- return nowStartTime + 86400 - now
  139. -- end
  140. end
  141. function isOpen(human, sendErr)
  142. local openDay = CommonDB.getServerOpenDay()
  143. if not openDay then
  144. return Broadcast.sendErr(human, Lang.YJTREASURE_NOT_SET_OPEN_TIME)
  145. end
  146. -- if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_10011,sendErr) then
  147. -- return
  148. -- end
  149. if getLeftTime() < 1 then
  150. return
  151. end
  152. return true
  153. end
  154. local function makeHeroNet(net, obj, pos, human)
  155. local config = CombatLogic.getConfigByObj(obj)
  156. if obj.type == CombatDefine.COMBAT_OBJ_TYPE1 then
  157. HeroGrid.makeHeroSimple(net.heroSimple, obj, obj.bagIndex, human)
  158. else
  159. HeroGrid.makeHeroSimpleByMonsterID(net.heroSimple, obj.id, obj)
  160. end
  161. net.heroSimple.index = pos
  162. net.heroSimple.hpMax = YjTreasureDBLogic.getCombatObjHpMax(obj)
  163. net.heroSimple.hp = YjTreasureDBLogic.getCombatObjHp(obj)
  164. net.isFight = obj.isFight or 0
  165. end
  166. function makeYjGridDataNet(human, net, grid)
  167. net.type = grid.gridType
  168. local gridCnf = YjTreasureExcel.grid[grid.gridType]
  169. net.icon = gridCnf.icon
  170. net.item[0] = 0
  171. net.monster[0] = 0
  172. if grid.gridType == YJ_TREASURE_GRID_KONGDI then
  173. return
  174. end
  175. if grid.gridType == YJ_TREASURE_GRID_ITEM then
  176. net.item[0] = 1
  177. Grid.makeItem(net.item[1], grid.item.itemID, grid.item.itemCnt)
  178. end
  179. if grid.gridType == YJ_TREASURE_GRID_KEY then
  180. net.item[0] = 1
  181. Grid.makeItem(net.item[1], YjTreasureExcel.define[1].keyItemID, 1)
  182. end
  183. if grid.gridType == YJ_TREASURE_GRID_MONSTER or grid.gridType == YJ_TREASURE_GRID_BOSS then
  184. if grid.isOpen then
  185. net.monster[0] = 1
  186. for pos, obj in pairs(grid.monsterObjList) do
  187. if obj then
  188. makeHeroNet(net.monster[1], obj, pos, human)
  189. end
  190. end
  191. end
  192. end
  193. end
  194. function makeYjGridNet(human, net, index, grid)
  195. net.index = index
  196. net.gridData[0] = 0
  197. if grid.isOpen or grid.gridType == YJ_TREASURE_GRID_BOSS then
  198. net.gridData[0] = 1
  199. makeYjGridDataNet(human, net.gridData[1], grid)
  200. end
  201. end
  202. local function dabiaoIsGet(uuid, dabiaoID)
  203. local killMonsterData = YjTreasureDBLogic.getKillMonsterData(uuid)
  204. if not killMonsterData or not killMonsterData.getList then
  205. return
  206. end
  207. return killMonsterData.getList[dabiaoID]
  208. end
  209. local function getNeedKillMonsterCnt(uuid)
  210. local conf = YjTreasureExcel.daBiaoReward
  211. local killMonsterData = YjTreasureDBLogic.getKillMonsterData(uuid)
  212. if not killMonsterData then
  213. return conf[#conf].needCnt
  214. end
  215. local nowCnt = killMonsterData and killMonsterData.killCnt or 0
  216. for i = 1, #conf do
  217. if not dabiaoIsGet(uuid, i) then
  218. return conf[i].needCnt
  219. end
  220. end
  221. return conf[#conf].needCnt
  222. end
  223. local function getYaoJiCanUseByType(uuid, yaojiType)
  224. local myData = YjTreasureDBLogic.getRoleDataByUuid(uuid)
  225. if not myData then
  226. return 0
  227. end
  228. local defCnf = YjTreasureExcel.define[1]
  229. local yaojisData = myData.yaojis
  230. local nowCnt = yaojisData and yaojisData[yaojiType] and yaojisData[yaojiType].nowCnt or 0
  231. local useCnt = yaojisData and yaojisData[yaojiType] and yaojisData[yaojiType].useCnt or 0
  232. local yaoMax = defCnf.killYaoMax
  233. if yaojiType == YJ_YAOJI_CURE then
  234. yaoMax = defCnf.cureYaoMax
  235. else
  236. yaoMax = defCnf.killYaoMax
  237. end
  238. return yaoMax - useCnt > 0 and yaoMax - useCnt or 0
  239. end
  240. local function makeYjkillMonsterNet(net, uuid)
  241. local killMonsterData = YjTreasureDBLogic.getKillMonsterData(uuid)
  242. local conf = YjTreasureExcel.daBiaoReward
  243. local nowCnt = killMonsterData and killMonsterData.killCnt or 0
  244. local needCnt = getNeedKillMonsterCnt(uuid)
  245. net.state = 0
  246. if dabiaoIsGet(uuid, #conf) then
  247. if nowCnt > needCnt then
  248. nowCnt = needCnt
  249. end
  250. else
  251. if nowCnt >= needCnt then
  252. net.state = 1
  253. end
  254. end
  255. net.nowCnt = nowCnt
  256. net.needCnt = needCnt
  257. end
  258. function CG_YJTREASURE_QUERY(human, type)
  259. if not isOpen(human, true) then
  260. return
  261. end
  262. local defCnf = YjTreasureExcel.define[1]
  263. local myData = YjTreasureDBLogic.getRoleDataByUuid(human.db._id)
  264. if not myData or not myData.objList then
  265. return Msg.send(Msg.gc.GC_YJTREASURE_SAVE_QUERY, human.fd)
  266. end
  267. local layerData = myData.layerData
  268. if not layerData then
  269. return Broadcast.sendErr(human, Lang.YJTREASURE_NOT_SET_POSE)
  270. end
  271. local msgRet = Msg.gc.GC_YJTREASURE_QUERY
  272. msgRet.leftTime = getLeftTime()
  273. msgRet.nowLayer = layerData.layer
  274. msgRet.type = type and type or 0
  275. msgRet.heroList[0] = 0
  276. msgRet.layerMax = myData.layerMax or 0
  277. if myData.objList then
  278. for pos, obj in pairs(myData.objList) do
  279. msgRet.heroList[0] = msgRet.heroList[0] + 1
  280. local index = msgRet.heroList[0]
  281. makeHeroNet(msgRet.heroList[index], obj, pos, human)
  282. end
  283. end
  284. msgRet.isQuick = human.db.combatQuick[CombatDefine.COMBAT_TYPE10] or 0
  285. --require("common.Util").printTable(msgRet.heroList)
  286. msgRet.gridList[0] = 0
  287. if layerData.grids then
  288. for index = 1, YJ_TREASURE_GRID_MAX do
  289. local grid = layerData.grids[index]
  290. if grid then
  291. msgRet.gridList[0] = msgRet.gridList[0] + 1
  292. makeYjGridNet(human, msgRet.gridList[msgRet.gridList[0]], index, grid)
  293. end
  294. end
  295. end
  296. --require("common.Util").printTable(msgRet.gridList)
  297. makeYjkillMonsterNet(msgRet.killMonster, human.db._id)
  298. msgRet.yaojis[0] = YJ_YAOJI_KILL
  299. local yaojisData = myData.yaojis
  300. for yaoType = 1, YJ_YAOJI_KILL do
  301. local yaoItem = defCnf.cureYaoItem
  302. local nowCnt = yaojisData and yaojisData[yaoType] and yaojisData[yaoType].nowCnt or 0
  303. if yaoType == YJ_YAOJI_KILL then
  304. yaoItem = defCnf.killYaoItem
  305. end
  306. msgRet.yaojis[yaoType].yaojiType = yaoType
  307. Grid.makeItem(msgRet.yaojis[yaoType].item, yaoItem, nowCnt)
  308. msgRet.yaojis[yaoType].canUse = getYaoJiCanUseByType(human.db._id, yaoType)
  309. end
  310. --require("common.Util").printTable(msgRet.yaojis)
  311. msgRet.yjShoperCnt = myData.yjShoperCnt or 0
  312. msgRet.saodangMax = defCnf.saodangMax
  313. msgRet.saodangNow = myData.sangdang or 0
  314. local zhandouli = myData.rolebase.zhandouli
  315. local saodangNeed = 0
  316. if zhandouli < defCnf.saodangNeed then
  317. saodangNeed = defCnf.saodangNeed
  318. end
  319. msgRet.sangdangNeed = saodangNeed
  320. --Msg.trace(msgRet)
  321. Msg.send(msgRet, human.fd)
  322. end
  323. -- 是否跳过
  324. function getQuick(human, combatType)
  325. local myData = YjTreasureDBLogic.getRoleDataByUuid(human.db._id)
  326. if not myData or not myData.objList then
  327. return 0
  328. end
  329. local layerData = myData.layerData
  330. local nowLayer = layerData.layer
  331. if nowLayer < YJ_TREASURE_QUICK_MAX then
  332. return 0
  333. end
  334. return 1
  335. end
  336. --点击格子
  337. function CG_YJTREASURE_TOUCH_GRID(human, gridIndex)
  338. if not isOpen(human, true) then
  339. return
  340. end
  341. local myData = YjTreasureDBLogic.getRoleDataByUuid(human.db._id)
  342. if not myData then
  343. return Broadcast.sendErr(human, Lang.YJTREASURE_NOT_SET_POSE)
  344. end
  345. local layerData = myData.layerData
  346. if not layerData then
  347. return
  348. end
  349. local grids = layerData.grids
  350. local gridData = grids[gridIndex]
  351. if not gridData.isOpen then
  352. return Broadcast.sendErr(human, Lang.YJTREASURE_NOT_OPEN)
  353. end
  354. if gridData.gridType == YJ_TREASURE_GRID_TREASURE_SHOP then
  355. GC_YJTREASURE_TREASURESHOP(human, gridData)
  356. elseif gridData.gridType == YJ_TREASURE_GRID_SOUL then --
  357. GC_YJTREASURE_SOUL(human, gridIndex, gridData)
  358. elseif gridData.gridType == YJ_TREASURE_GRID_QUESTION then --
  359. GC_YJTREASURE_QUESTION(human, gridIndex, gridData, layerData.layer)
  360. elseif gridData.gridType == YJ_TREASURE_GRID_DICE then
  361. GC_YJTREASURE_DICE_QUERY(human)
  362. elseif gridData.gridType == YJ_TREASURE_GRID_BOX then
  363. GC_YJTREASURE_BOXREWARD(human)
  364. elseif gridData.gridType == YJ_TREASURE_GRID_KEY then
  365. getBoxRewardKey(human, gridIndex, grids)
  366. elseif gridData.gridType == YJ_TREASURE_GRID_DOOR then
  367. yjTreasure2NextLayer(human)
  368. end
  369. end
  370. --更新格子信息 grids[1].gridindex grids[1].gridData
  371. function GC_YJTREASURE_GRIDS_CHANGE(human, gridIndex, grid)
  372. local msgRet = Msg.gc.GC_YJTREASURE_GRIDS_CHANGE
  373. makeYjGridNet(human, msgRet.grid, gridIndex, grid)
  374. Msg.send(msgRet, human.fd)
  375. end
  376. local function getShopItemByAllShoperID(uuid, allShopID)
  377. local allShopData = YjTreasureDBLogic.getAllShopData(uuid)
  378. if not allShopData then
  379. return
  380. end
  381. return allShopData[allShopID]
  382. end
  383. local function makeYjShoperItemNet(net, uuid, allShopID, shopItem, conf)
  384. local itemID = conf.item[1]
  385. local itemCnt = conf.item[2]
  386. Grid.makeItem(net.item, itemID, itemCnt)
  387. net.allShopID = allShopID
  388. local needItemID = conf.buyCost[1]
  389. local needItemCnt = conf.buyCost[2]
  390. Grid.makeItem(net.needItem, needItemID, needItemCnt)
  391. net.discount = conf.discountShow
  392. net.isBuy = shopItem.isBuy and 1 or 0
  393. end
  394. --打开格子内商店界面
  395. function GC_YJTREASURE_TREASURESHOP(human, gridData)
  396. local msgRet = Msg.gc.GC_YJTREASURE_TREASURESHOP
  397. local treasureShop = gridData.treasureShop
  398. if not treasureShop then
  399. return
  400. end
  401. local treasureShopCnf = YjTreasureExcel.treasureShop
  402. msgRet.items[0] = #treasureShop
  403. for i = 1, #treasureShop do
  404. local allShopID = treasureShop[i]
  405. local shopItem = getShopItemByAllShoperID(human.db._id, allShopID)
  406. local shopConfID = shopItem.shopConfID
  407. local conf = treasureShopCnf[shopConfID]
  408. makeYjShoperItemNet(msgRet.items[i], human.db._id, allShopID, shopItem, conf)
  409. end
  410. -- Msg.trace(msgRet)
  411. Msg.send(msgRet, human.fd)
  412. end
  413. local function canBuyByAllShopID(human, allShopID, noSend)
  414. local allShopData = YjTreasureDBLogic.getAllShopData(human.db._id)
  415. if not allShopData or not allShopData[allShopID] then
  416. if not noSend then
  417. Broadcast.sendErr(human, Lang.YJTREASURE_ALLSHOPER_ERR)
  418. end
  419. return
  420. end
  421. if allShopData[allShopID].isBuy then
  422. if not noSend then
  423. Broadcast.sendErr(human, Lang.YJTREASURE_BUY_HAD)
  424. end
  425. return
  426. end
  427. return true
  428. end
  429. local function buyItemByAllShopID(human, allShopID)
  430. local shopConf = YjTreasureExcel.treasureShop
  431. local shopItem = getShopItemByAllShoperID(human.db._id, allShopID)
  432. if shopItem.shopType == YJ_TREASURE_GRID_YJSHOPER then
  433. shopConf = YjTreasureExcel.yjShoper
  434. end
  435. local shopConfID = shopItem.shopConfID
  436. local conf = shopConf[shopConfID]
  437. local needItemID = conf.buyCost[1]
  438. local needItemCnt = conf.buyCost[2]
  439. local nowCnt = BagLogic.getItemCnt(human, needItemID)
  440. if nowCnt < needItemCnt then
  441. return Broadcast.sendErr(human, Lang.YJTREASURE_BUY_NEED_ERR)
  442. end
  443. BagLogic.delItem(human, needItemID, needItemCnt, "yj_treasure")
  444. YjTreasureDBLogic.setShopItemBuy(human.db._id, allShopID)
  445. local itemID = conf.item[1]
  446. local itemCnt = conf.item[2]
  447. -- BagLogic.addItem(human,itemID,itemCnt,"yj_treasure")
  448. BagLogic.cleanMomentItemList()
  449. BagLogic.updateMomentItem(1, itemID, itemCnt)
  450. BagLogic.addMomentItemList(human, "yj_treasure")
  451. return true
  452. end
  453. --购买格子内商店商品
  454. function CG_YJTREASURE_TREASURESHOP_BUY(human, allShopID)
  455. if not canBuyByAllShopID(human, allShopID) then
  456. return
  457. end
  458. if not buyItemByAllShopID(human, allShopID) then
  459. return
  460. end
  461. local msgRet = Msg.gc.GC_YJTREASURE_TREASURESHOP_BUY
  462. msgRet.allShopID = allShopID
  463. Msg.send(msgRet, human.fd)
  464. end
  465. --灵魂拷问 打开界面
  466. function GC_YJTREASURE_SOUL(human, gridIndex, gridData)
  467. local soulID = gridData.soul
  468. if not soulID then
  469. soulID = YjTreasureDBLogic.makeSoul(human.db._id, gridIndex)
  470. end
  471. local soulCnf = YjTreasureExcel.soul[soulID]
  472. local msgRet = Msg.gc.GC_YJTREASURE_SOUL
  473. msgRet.soulID = soulID
  474. msgRet.soulquestion = soulCnf.question
  475. msgRet.select1 = soulCnf.answer1
  476. msgRet.select2 = soulCnf.answer2
  477. -- Msg.trace(msgRet)
  478. Msg.send(msgRet, human.fd)
  479. end
  480. --回答灵魂拷问
  481. function CG_YJTREASURE_SOUL_SELECT(human, gridIndex, answer)
  482. local layerData = YjTreasureDBLogic.getLayerDataByUuid(human.db._id)
  483. if not layerData or not layerData.grids then
  484. return
  485. end
  486. local gridData = layerData.grids[gridIndex]
  487. if not gridData then
  488. return
  489. end
  490. if gridData.gridType ~= YJ_TREASURE_GRID_SOUL then
  491. return
  492. end
  493. local soulID = gridData.soul
  494. if not soulID then
  495. return
  496. end
  497. local layerCnf = YjTreasureExcel.layer[layerData.layer]
  498. local soulRewards = layerCnf.soulRewards
  499. local totalWeight = 0
  500. for i = 1, #soulRewards do
  501. totalWeight = totalWeight + soulRewards[i][3]
  502. end
  503. local rand = math.random(1, totalWeight)
  504. local weight = 0
  505. local getList = {}
  506. for i = 1, #soulRewards do
  507. weight = weight + soulRewards[i][3]
  508. if rand <= weight then
  509. local itemID = soulRewards[i][1]
  510. local itemCnt = soulRewards[i][2]
  511. getList[#getList + 1] = {}
  512. getList[#getList][1] = itemID
  513. getList[#getList][2] = itemCnt
  514. BagLogic.addItem(human, itemID, itemCnt, "yj_treasure_kaowen")
  515. layerData.getItems = layerData.getItems or {}
  516. layerData.getItems[itemID] = (layerData.getItems[itemID] or 0) + itemCnt
  517. break
  518. end
  519. end
  520. gridData = YjTreasureDBLogic.gridTypeChange(human.db._id, layerData.grids, gridIndex, YJ_TREASURE_GRID_KONGDI, true)
  521. YjTreasureDBLogic.updateLayerData(human.db._id, layerData)
  522. local soulCnf = YjTreasureExcel.soul[soulID]
  523. local msgRet = Msg.gc.GC_YJTREASURE_SOUL_SELECT
  524. local tip = soulCnf.tips1
  525. if answer == 2 then
  526. tip = soulCnf.tips2
  527. end
  528. msgRet.tip = tip
  529. msgRet.items[0] = 0
  530. for k, v in ipairs(getList) do
  531. Grid.makeItem(msgRet.items[k], v[1], v[2])
  532. end
  533. msgRet.items[0] = #getList
  534. -- Msg.trace(msgRet)
  535. Msg.send(msgRet, human.fd)
  536. GC_YJTREASURE_GRIDS_CHANGE(human, gridIndex, gridData)
  537. end
  538. --博文强识 打开界面
  539. local function makeYjQuestionNet(net, questionID, answer)
  540. local questionCnf = YjTreasureExcel.question[questionID]
  541. net.questionID = questionID
  542. net.question = questionCnf.question
  543. net.select1 = questionCnf.select1
  544. net.select2 = questionCnf.select2
  545. net.select3 = questionCnf.select3
  546. net.select4 = questionCnf.select4
  547. net.rightSelect = questionCnf.rightSelect
  548. net.answer = answer and answer[questionID] or 0
  549. end
  550. function GC_YJTREASURE_QUESTION(human, gridIndex, gridData, layer)
  551. local questionData = gridData.question
  552. if not questionData then
  553. questionData = YjTreasureDBLogic.makeQuestion(human.db._id, gridIndex)
  554. end
  555. local msgRet = Msg.gc.GC_YJTREASURE_QUESTION
  556. msgRet.yjQuestions[0] = #questionData.list
  557. for i = 1, #questionData.list do
  558. makeYjQuestionNet(msgRet.yjQuestions[i], questionData.list[i], questionData.answer)
  559. end
  560. local layCnf = YjTreasureExcel.layer[layer]
  561. local questionReward = layCnf.questionReward
  562. msgRet.oneReward[0] = #questionReward
  563. for i = 1, #questionReward do
  564. Grid.makeItem(msgRet.oneReward[i], questionReward[i][1], questionReward[i][2])
  565. end
  566. msgRet.rightCnt = questionData.rightCnt or 0
  567. --Msg.trace(msgRet)
  568. Msg.send(msgRet, human.fd)
  569. end
  570. --博闻强识 回答问题
  571. function CG_YJTREASURE_QUESTION_SELECT(human, gridIndex, questionID, answer)
  572. local layerData = YjTreasureDBLogic.getLayerDataByUuid(human.db._id)
  573. if not layerData or not layerData.grids then
  574. return
  575. end
  576. local gridData = layerData.grids[gridIndex]
  577. if not gridData then
  578. return
  579. end
  580. if gridData.gridType ~= YJ_TREASURE_GRID_QUESTION then
  581. return
  582. end
  583. local questionCnf = YjTreasureExcel.question[questionID]
  584. if not questionCnf then
  585. return
  586. end
  587. local questionData = gridData.question
  588. if questionData and questionData.answer and questionData.answer[questionID] then
  589. return
  590. end
  591. questionData.answer = questionData.answer or {}
  592. questionData.answer[questionID] = answer
  593. if questionCnf.rightSelect == answer then
  594. questionData.rightCnt = (questionData.rightCnt or 0) + 1
  595. local layCnf = YjTreasureExcel.layer[layerData.layer]
  596. local questionReward = layCnf.questionReward
  597. for i = 1, #questionReward do
  598. local itemID = questionReward[i][1]
  599. local itemCnt = questionReward[i][2]
  600. gridData.getItems = gridData.getItems or {}
  601. gridData.getItems[itemID] = (gridData.getItems[itemID] or 0) + itemCnt
  602. layerData.getItems = layerData.getItems or {}
  603. layerData.getItems[itemID] = (layerData.getItems[itemID] or 0) + itemCnt
  604. end
  605. end
  606. if questionData.list[#questionData.list] == questionID then
  607. BagLogic.addItemList(human, gridData.getItems, "yj_treasure")
  608. gridData =
  609. YjTreasureDBLogic.gridTypeChange(human.db._id, layerData.grids, gridIndex, YJ_TREASURE_GRID_KONGDI, true)
  610. GC_YJTREASURE_GRIDS_CHANGE(human, gridIndex, gridData)
  611. end
  612. YjTreasureDBLogic.updateLayerData(human.db._id, layerData)
  613. local msgRet = Msg.gc.GC_YJTREASURE_QUESTION_SELECT
  614. msgRet.gridIndex = gridIndex
  615. msgRet.questionID = questionID
  616. msgRet.rightCnt = questionData.rightCnt or 0
  617. --Msg.trace(msgRet)
  618. Msg.send(msgRet, human.fd)
  619. end
  620. --好运骰子 打开界面
  621. function GC_YJTREASURE_DICE_QUERY(human)
  622. local defCnf = YjTreasureExcel.define[1]
  623. local msgRet = Msg.gc.GC_YJTREASURE_DICE_QUERY
  624. msgRet.zuanshi = defCnf.diceZuanShiCost
  625. msgRet.jinbi = defCnf.diceJinBiCost
  626. -- Msg.trace(msgRet)
  627. Msg.send(msgRet, human.fd)
  628. end
  629. --好运骰子 选择消耗
  630. function CG_YJTREASURE_DICE_USE(human, use, gridIndex)
  631. local layerData = YjTreasureDBLogic.getLayerDataByUuid(human.db._id)
  632. if not layerData or not layerData.grids then
  633. return
  634. end
  635. local gridData = layerData.grids[gridIndex]
  636. if not gridData then
  637. return
  638. end
  639. if gridData.gridType ~= YJ_TREASURE_GRID_DICE then
  640. return
  641. end
  642. local defCnf = YjTreasureExcel.define[1]
  643. if use == YJ_DICE_JINBI then
  644. if human.db.jinbi < defCnf.diceJinBiCost then
  645. return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
  646. end
  647. ObjHuman.updateJinbi(human, -defCnf.diceJinBiCost, "yj_treasure")
  648. else
  649. if not ObjHuman.checkRMB(human, defCnf.diceZuanShiCost) then
  650. return
  651. end
  652. ObjHuman.decZuanshi(human, -defCnf.diceZuanShiCost, "yj_treasure")
  653. end
  654. local totalWeight = 0
  655. for i = 1, #defCnf.diceWeight do
  656. totalWeight = totalWeight + defCnf.diceWeight[i][2]
  657. end
  658. local rand = math.random(1, totalWeight)
  659. local weight = 0
  660. local content = ""
  661. for i = 1, #defCnf.diceWeight do
  662. weight = weight + defCnf.diceWeight[i][2]
  663. if rand <= weight then
  664. local bei = defCnf.diceWeight[i][1]
  665. local itemID = nil
  666. local cnt = nil
  667. if use == YJ_DICE_JINBI then
  668. itemID = ItemDefine.ITEM_JINBI_ID
  669. cnt = defCnf.diceJinBiCost * bei
  670. ObjHuman.updateJinbi(human, cnt, "yj_treasure")
  671. else
  672. itemID = ItemDefine.ITEM_ZUANSHI_ID
  673. cnt = defCnf.diceZuanShiCost * bei
  674. ObjHuman.addZuanshi(human, cnt, "yj_treasure")
  675. end
  676. if cnt then
  677. local itemName = ItemDefine.getValue(itemID, "name")
  678. content = Util.format(Lang.YJTREASURE_DICE_GET, bei, itemName, cnt)
  679. layerData.getItems = layerData.getItems or {}
  680. layerData.getItems[itemID] = (layerData.getItems[itemID] or 0) + cnt
  681. end
  682. break
  683. end
  684. end
  685. gridData = YjTreasureDBLogic.gridTypeChange(human.db._id, layerData.grids, gridIndex, YJ_TREASURE_GRID_KONGDI, true)
  686. YjTreasureDBLogic.updateLayerData(human.db._id, layerData)
  687. local msgRet = Msg.gc.GC_YJTREASURE_DICE_USE
  688. msgRet.content = content
  689. Msg.send(msgRet, human.fd)
  690. GC_YJTREASURE_GRIDS_CHANGE(human, gridIndex, gridData)
  691. end
  692. --宝箱 打开界面
  693. function GC_YJTREASURE_BOXREWARD(human)
  694. local defCnf = YjTreasureExcel.define[1]
  695. local msgRet = Msg.gc.GC_YJTREASURE_BOXREWARD
  696. local boxReward = defCnf.boxReward
  697. msgRet.yjBoxReward[0] = #boxReward
  698. for i = 1, #boxReward do
  699. Grid.makeItem(msgRet.yjBoxReward[i], boxReward[i][1], boxReward[i][2])
  700. end
  701. Grid.makeItem(msgRet.need, defCnf.keyItemID, defCnf.keyNeed)
  702. -- Msg.trace(msgRet)
  703. Msg.send(msgRet, human.fd)
  704. end
  705. --宝箱 开启
  706. function CG_YJTREASURE_BOXREWARD_OPEN(human, gridIndex)
  707. local layerData = YjTreasureDBLogic.getLayerDataByUuid(human.db._id)
  708. if not layerData or not layerData.grids then
  709. return
  710. end
  711. local gridData = layerData.grids[gridIndex]
  712. if not gridData then
  713. return
  714. end
  715. if gridData.gridType ~= YJ_TREASURE_GRID_BOX then
  716. return
  717. end
  718. local myData = YjTreasureDBLogic.getRoleDataByUuid(human.db._id)
  719. local defCnf = YjTreasureExcel.define[1]
  720. local nowKey = BagLogic.getItemCnt(human, defCnf.keyItemID)
  721. local keyNeed = defCnf.keyNeed
  722. if keyNeed > nowKey then
  723. return Broadcast.sendErr(human, Lang.YJTREASURE_BOX_KEY_ERR)
  724. end
  725. BagLogic.delItem(human, defCnf.keyItemID, 1, "yj_treasure")
  726. local boxReward = defCnf.boxReward
  727. local totalWeight = 0
  728. for i = 1, #boxReward do
  729. totalWeight = totalWeight + boxReward[i][3]
  730. end
  731. local rand = math.random(1, totalWeight)
  732. local weight = 0
  733. BagLogic.cleanMomentItemList()
  734. for i = 1, #boxReward do
  735. weight = weight + boxReward[i][3]
  736. if rand <= weight then
  737. local itemID = boxReward[i][1]
  738. local itemCnt = boxReward[i][2]
  739. BagLogic.updateMomentItem(1, itemID, itemCnt)
  740. -- BagLogic.addItem(human,itemID,itemCnt,"yj_treasure")
  741. Broadcast.sendErr(human, Lang.YJTREASURE_BOX_OPEN)
  742. layerData.getItems = layerData.getItems or {}
  743. layerData.getItems[itemID] = (layerData.getItems[itemID] or 0) + itemCnt
  744. break
  745. end
  746. end
  747. BagLogic.addMomentItemList(human, "yj_treasure")
  748. gridData = YjTreasureDBLogic.gridTypeChange(human.db._id, layerData.grids, gridIndex, YJ_TREASURE_GRID_KONGDI, true)
  749. YjTreasureDBLogic.updateLayerData(human.db._id, layerData)
  750. GC_YJTREASURE_GRIDS_CHANGE(human, gridIndex, gridData)
  751. Msg.send(Msg.gc.GC_YJTREASURE_BOXREWARD_OPEN, human.fd)
  752. end
  753. --点击钥匙格子
  754. function getBoxRewardKey(human, gridIndex, grids)
  755. local defCnf = YjTreasureExcel.define[1]
  756. -- BagLogic.addItem(human,defCnf.keyItemID,1,"yj_treasure")
  757. BagLogic.cleanMomentItemList()
  758. BagLogic.updateMomentItem(1, defCnf.keyItemID, 1)
  759. BagLogic.addMomentItemList(human, "yj_treasure")
  760. YjTreasureDBLogic.gridTypeChange(human.db._id, grids, gridIndex, YJ_TREASURE_GRID_KONGDI, true)
  761. YjTreasureDBLogic.updateGridsData(human.db._id, grids)
  762. GC_YJTREASURE_GRIDS_CHANGE(human, gridIndex, grids[gridIndex])
  763. end
  764. --前往下一层
  765. function yjTreasure2NextLayer(human)
  766. local layerData = YjTreasureDBLogic.getLayerDataByUuid(human.db._id)
  767. local layCnf = YjTreasureExcel.layer
  768. local nowLayer = layerData.layer
  769. if nowLayer >= #layCnf then
  770. return Broadcast.sendErr(human, Lang.YJTREASURE_LAYER_ERR)
  771. end
  772. GC_YJTREASURE_GETITEMS(human)
  773. local roleData = YjTreasureDBLogic.getRoleDataByUuid(human.db._id)
  774. local layerMax = roleData.layerMax or 0
  775. if layerMax < nowLayer + 1 then
  776. roleData.layerMax = nowLayer + 1
  777. YjTreasureDBLogic.updateUuid2Role(roleData)
  778. end
  779. YjTreasureDBLogic.creatLayerDataByUuid(human.db._id, nowLayer + 1)
  780. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_16, nowLayer + 1)
  781. --TODO:记录遗迹探险
  782. --Log.write(Log.LOGID_OSS_BATTLE_RELIC, human.db._id, human.db.account, human.db.name, nowLayer + 1)
  783. Log.write(Log.LOGID_OSS_BATTLE_RELIC, human.db._id, human.db.newUniqueTag, human.db.name, nowLayer + 1)
  784. YunYingLogic.onCallBack(human, "YJTreasurePass", 1)
  785. CG_YJTREASURE_QUERY(human, 1)
  786. end
  787. --奖励收益弹窗
  788. function GC_YJTREASURE_GETITEMS(human, noSend)
  789. local roleData = YjTreasureDBLogic.getRoleDataByUuid(human.db._id)
  790. local layerData = YjTreasureDBLogic.getLayerDataByUuid(human.db._id)
  791. local layCnf = YjTreasureExcel.layer
  792. local nowLayer = layerData.layer
  793. if nowLayer >= #layCnf then
  794. Broadcast.sendErr(human, Lang.YJTREASURE_LAYER_ERR)
  795. end
  796. local msgRet = Msg.gc.GC_YJTREASURE_GETITEMS
  797. msgRet.getItems[0] = 0
  798. for itemID, itemCnt in pairs(roleData.item) do
  799. msgRet.getItems[0] = msgRet.getItems[0] + 1
  800. local index = msgRet.getItems[0]
  801. Grid.makeItem(msgRet.getItems[index], itemID, itemCnt)
  802. end
  803. Msg.send(msgRet, human.fd)
  804. end
  805. --点击神秘商人次数 获得权重商品 即进入全部商品列表
  806. function CG_YJTREASURE_YJSHOPER(human)
  807. local myData = YjTreasureDBLogic.getRoleDataByUuid(human.db._id)
  808. local yjShoperCnt = myData.yjShoperCnt or 0
  809. if yjShoperCnt < 1 then
  810. return Broadcast.sendErr(human, Lang.YJTREASURE_YJSHOPER_ERR)
  811. end
  812. myData.yjShoperCnt = yjShoperCnt - 1
  813. YjTreasureDBLogic.updateUuid2Role(myData)
  814. local allShopID, yjShoperCnfID = YjTreasureDBLogic.makeYjShoperItem(human.db._id)
  815. local yjShoperCnf = YjTreasureExcel.yjShoper[yjShoperCnfID]
  816. local msgRet = Msg.gc.GC_YJTREASURE_YJSHOPER
  817. local shopItem = getShopItemByAllShoperID(human.db._id, allShopID)
  818. makeYjShoperItemNet(msgRet.yjShoperItem, human.db._id, allShopID, shopItem, yjShoperCnf)
  819. msgRet.yjShoperCnt = myData.yjShoperCnt
  820. -- Msg.trace(msgRet)
  821. Msg.send(msgRet, human.fd)
  822. end
  823. --神秘商人商品购买
  824. function CG_YJTREASURE_YJSHOPER_BUY(human, allShopID)
  825. if not canBuyByAllShopID(human, allShopID) then
  826. return
  827. end
  828. if not buyItemByAllShopID(human, allShopID) then
  829. return
  830. end
  831. local msgRet = Msg.gc.GC_YJTREASURE_YJSHOPER_BUY
  832. msgRet.allShopID = allShopID
  833. Msg.send(msgRet, human.fd)
  834. end
  835. --探险商城(包含神秘商人和商店所出现的所有道具)
  836. --商品小于100个发送全部商品
  837. --商品大于100个,只发送未购买的
  838. function CG_YJTREASURE_ALLSHOP(human)
  839. local msgRet = Msg.gc.GC_YJTREASURE_ALLSHOP
  840. msgRet.itemList[0] = 0
  841. msgRet.isEnd = 0
  842. local allShopData = YjTreasureDBLogic.getAllShopData(human.db._id)
  843. if not allShopData then
  844. msgRet.isEnd = 1
  845. Msg.send(msgRet, human.fd)
  846. return
  847. end
  848. local treasureShopCnf = YjTreasureExcel.treasureShop
  849. local yjShoperCnf = YjTreasureExcel.yjShoper
  850. local count = 0
  851. for allShopID = 1, #allShopData do
  852. if msgRet.itemList[0] >= #msgRet.itemList then
  853. count = 0
  854. Msg.send(msgRet, human.fd)
  855. end
  856. local shopItem = allShopData[allShopID]
  857. local conf = treasureShopCnf[shopItem.shopConfID]
  858. if shopItem.shopType == YJ_SHOP_YJSHOPER then
  859. conf = yjShoperCnf[shopItem.shopConfID]
  860. end
  861. if #allShopData <= YJ_SHOP_ALLSHOP_SEND_MAX then
  862. count = count + 1
  863. local index = count
  864. makeYjShoperItemNet(msgRet.itemList[index], human.db._id, allShopID, shopItem, conf)
  865. else
  866. if not shopItem.isBuy then
  867. count = count + 1
  868. local index = count
  869. makeYjShoperItemNet(msgRet.itemList[index], human.db._id, allShopID, shopItem, conf)
  870. end
  871. end
  872. msgRet.itemList[0] = count
  873. end
  874. msgRet.isEnd = 1
  875. -- Msg.trace(msgRet)
  876. Msg.send(msgRet, human.fd)
  877. end
  878. --探险商城 购买
  879. function CG_YJTREASURE_ALLSHOP_BUY(human, allShopID)
  880. if not canBuyByAllShopID(human, allShopID) then
  881. return
  882. end
  883. if not buyItemByAllShopID(human, allShopID) then
  884. return
  885. end
  886. local msgRet = Msg.gc.GC_YJTREASURE_ALLSHOP_BUY
  887. msgRet.allShopID = allShopID
  888. Msg.send(msgRet, human.fd)
  889. end
  890. --buff 加成
  891. function CG_YJTREASURE_BUFF_QUERY(human)
  892. local buffData = YjTreasureDBLogic.getBuffData(human.db._id)
  893. if not buffData then
  894. return
  895. end
  896. local msgRet = Msg.gc.GC_YJTREASURE_BUFF_QUERY
  897. msgRet.attrs[0] = 0
  898. for key, value in pairs(buffData) do
  899. msgRet.attrs[0] = msgRet.attrs[0] + 1
  900. local index = msgRet.attrs[0]
  901. msgRet.attrs[index].attr.key = key
  902. msgRet.attrs[index].attr.value = value
  903. end
  904. -- Msg.trace(msgRet)
  905. Msg.send(msgRet, human.fd)
  906. end
  907. --点击目标奖励
  908. --有可领取时,可领奖励全领取,刷新消灭守卫信息
  909. --没有可领取时,返回列表信息
  910. function CG_YJTREASURE_DABIAOREWARD(human)
  911. local myData = YjTreasureDBLogic.getRoleDataByUuid(human.db._id)
  912. local nowCnt = myData.killMonster and myData.killMonster.killCnt or 0
  913. local daBiaoRewardCnf = YjTreasureExcel.daBiaoReward
  914. local totalReward = nil
  915. for i = 1, #daBiaoRewardCnf do
  916. if not dabiaoIsGet(human.db._id, i) then
  917. local needCnt = daBiaoRewardCnf[i].needCnt
  918. if nowCnt >= needCnt then
  919. myData.killMonster.getList = myData.killMonster.getList or {}
  920. myData.killMonster.getList[i] = i
  921. local reward = daBiaoRewardCnf[i].reward
  922. totalReward = totalReward or {}
  923. for i = 1, #reward do
  924. totalReward[reward[i][1]] = (totalReward[reward[i][1]] or 0) + reward[i][2]
  925. end
  926. end
  927. end
  928. end
  929. if totalReward then
  930. BagLogic.addItemList(human, totalReward, "yj_treasure")
  931. YjTreasureDBLogic.updateUuid2Role(myData)
  932. GC_YJTREASURE_DABIAOREWARD_CHANGE(human)
  933. else
  934. GC_YJTREASURE_DABIAOREWARD_QUERY(human)
  935. end
  936. end
  937. function GC_YJTREASURE_DABIAOREWARD_CHANGE(human)
  938. local msgRet = Msg.gc.GC_YJTREASURE_DABIAOREWARD_CHANGE
  939. makeYjkillMonsterNet(msgRet.killMonster, human.db._id)
  940. -- Msg.trace(msgRet)
  941. Msg.send(msgRet, human.fd)
  942. end
  943. function GC_YJTREASURE_DABIAOREWARD_QUERY(human)
  944. local daBiaoRewardCnf = YjTreasureExcel.daBiaoReward
  945. local msgRet = Msg.gc.GC_YJTREASURE_DABIAOREWARD_QUERY
  946. msgRet.dabiaoList[0] = #daBiaoRewardCnf
  947. for i = 1, #daBiaoRewardCnf do
  948. msgRet.dabiaoList[i].desc = daBiaoRewardCnf[i].name
  949. msgRet.dabiaoList[i].needCnt = daBiaoRewardCnf[i].needCnt
  950. msgRet.dabiaoList[i].isget = dabiaoIsGet(human.db._id, i) and 1 or 0
  951. local reward = daBiaoRewardCnf[i].reward
  952. msgRet.dabiaoList[i].items[0] = #reward
  953. for j = 1, #reward do
  954. Grid.makeItem(msgRet.dabiaoList[i].items[j], reward[j][1], reward[j][2])
  955. end
  956. end
  957. local killMonsterData = YjTreasureDBLogic.getKillMonsterData(human.db._id)
  958. msgRet.nowCnt = killMonsterData and killMonsterData.killCnt or 0
  959. --Msg.trace(msgRet)
  960. Msg.send(msgRet, human.fd)
  961. end
  962. --排行榜
  963. local function makeYjBoardNet(net, rank, uuid)
  964. net.rank = rank
  965. if rank > YJ_TREASURE_BILLBOARD_SHOW then
  966. net.rank = 0
  967. end
  968. local roleData = YjTreasureDBLogic.getRoleDataByUuid(uuid)
  969. RoleLogic.makeRoleBase(roleData.rolebase, net.roleBase)
  970. local layerData = YjTreasureDBLogic.getLayerDataByUuid(uuid)
  971. net.layer = layerData and layerData.layer or 0
  972. net.tansuo = roleData.tansuo or 0
  973. end
  974. function CG_YJTREASURE_BILLBOARD(human)
  975. local msgRet = Msg.gc.GC_YJTREASURE_BILLBOARD
  976. local rank2Uuid = YjTreasureDBLogic.getDBrank2Uuid()
  977. msgRet.yjBoard[0] = 0
  978. for i = 1, #rank2Uuid do
  979. if msgRet.yjBoard[0] < #msgRet.yjBoard then
  980. msgRet.yjBoard[0] = msgRet.yjBoard[0] + 1
  981. makeYjBoardNet(msgRet.yjBoard[i], i, rank2Uuid[i])
  982. end
  983. end
  984. local myRank = YjTreasureDBLogic.getRankByUuid(human.db._id)
  985. makeYjBoardNet(msgRet.myRank, myRank, human.db._id)
  986. -- Msg.trace(msgRet)
  987. Msg.send(msgRet, human.fd)
  988. end
  989. --使用药剂
  990. function CG_YJTREASURE_USE_YAOJI(human, yaojiType, index)
  991. local myData = YjTreasureDBLogic.getRoleDataByUuid(human.db._id)
  992. if not myData then
  993. return
  994. end
  995. local defCnf = YjTreasureExcel.define[1]
  996. local yaojisData = myData.yaojis
  997. local nowCnt = yaojisData and yaojisData[yaojiType] and yaojisData[yaojiType].nowCnt or 0
  998. local useCnt = yaojisData and yaojisData[yaojiType] and yaojisData[yaojiType].useCnt or 0
  999. local yaoMax = defCnf.killYaoMax
  1000. local content1 = Lang.YJTREASURE_YAOJI2_ERR_MAX
  1001. local content2 = Lang.YJTREASURE_YAOJI2_ERR_CNT
  1002. if yaojiType == YJ_YAOJI_CURE then
  1003. yaoMax = defCnf.cureYaoMax
  1004. content2 = Lang.YJTREASURE_YAOJI1_ERR_CNT
  1005. if useCnt >= yaoMax then
  1006. content1 = Lang.YJTREASURE_YAOJI1_ERR_MAX
  1007. return Broadcast.sendErr(human, content1)
  1008. end
  1009. end
  1010. if nowCnt < 1 then
  1011. return Broadcast.sendErr(human, content2)
  1012. end
  1013. if yaojiType == YJ_YAOJI_CURE then
  1014. local objList = myData.objList
  1015. if not objList[index] then
  1016. return
  1017. end
  1018. local obj = objList[index]
  1019. local hpMax = YjTreasureDBLogic.getCombatObjHpMax(obj)
  1020. local hp = YjTreasureDBLogic.getCombatObjHp(obj)
  1021. if hp == hpMax then
  1022. return Broadcast.sendErr(human, Lang.YJTREASURE_YAOJI_CURE_ERR1)
  1023. end
  1024. if hp <= 0 then
  1025. return Broadcast.sendErr(human, Lang.YJTREASURE_YAOJI_CURE_ERR2)
  1026. end
  1027. if obj then
  1028. myData.yaojis[yaojiType].nowCnt = nowCnt - 1
  1029. myData.yaojis[yaojiType].useCnt = useCnt + 1
  1030. myData.objList[index].hp = hp + math.floor(hpMax * 0.5)
  1031. if myData.objList[index].hp > hpMax then
  1032. myData.objList[index].hp = hpMax
  1033. end
  1034. YjTreasureDBLogic.updateUuid2Role(myData)
  1035. local msgRet = Msg.gc.GC_YJTREASURE_USE_YAOJI
  1036. msgRet.type = yaojiType
  1037. msgRet.canUse = getYaoJiCanUseByType(human.db._id, yaojiType)
  1038. makeHeroNet(msgRet.obj, obj, index, human)
  1039. Msg.send(msgRet, human.fd)
  1040. CG_YJTREASURE_QUERY(human, 1)
  1041. end
  1042. else
  1043. local gridsData = YjTreasureDBLogic.getGridsData(human.db._id)
  1044. local gridData = gridsData[index]
  1045. if not gridData then
  1046. return
  1047. end
  1048. if gridData.gridType ~= YJ_TREASURE_GRID_BOSS and gridData.gridType ~= YJ_TREASURE_GRID_MONSTER then
  1049. return
  1050. end
  1051. myData.yaojis[yaojiType].nowCnt = nowCnt - 1
  1052. myData.yaojis[yaojiType].useCnt = useCnt + 1
  1053. local monsterObjList = gridData.monsterObjList
  1054. local send = nil
  1055. for pos in pairs(monsterObjList) do
  1056. if monsterObjList[pos] then
  1057. monsterObjList[pos].hp = 0
  1058. YjTreasureDBLogic.updateGridsData(human.db._id, gridsData)
  1059. send = true
  1060. YjTreasureCombat.killMonsterOpenGrids(human, index)
  1061. end
  1062. end
  1063. if send then
  1064. Broadcast.sendErr(human, Lang.YJTREASURE_YAOJI_USE_OK)
  1065. CG_YJTREASURE_QUERY(human, 1)
  1066. LiLianLogic.onCallback(human, LiLianLogic.LILIAN_OUTID13, 1)
  1067. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE20, 1)
  1068. end
  1069. end
  1070. end
  1071. function yjYaoJiAdd(human, value, yaojiType)
  1072. if not isOpen(human) then
  1073. return
  1074. end
  1075. local myData = YjTreasureDBLogic.getRoleDataByUuid(human.db._id)
  1076. if not myData then
  1077. return
  1078. end
  1079. myData.yaojis = myData.yaojis or {}
  1080. myData.yaojis[yaojiType] = myData.yaojis[yaojiType] or {}
  1081. myData.yaojis[yaojiType].nowCnt = (myData.yaojis[yaojiType].nowCnt or 0) + value
  1082. YjTreasureDBLogic.updateUuid2Role(myData)
  1083. local defCnf = YjTreasureExcel.define[1]
  1084. local msgRet = Msg.gc.GC_YJTREASURE_YAOJI_ADD
  1085. local yaoItem = defCnf.cureYaoItem
  1086. local nowCnt = myData.yaojis[yaojiType].nowCnt
  1087. if yaojiType == YJ_YAOJI_KILL then
  1088. yaoItem = defCnf.killYaoItem
  1089. end
  1090. msgRet.yaoji.yaojiType = yaojiType
  1091. Grid.makeItem(msgRet.yaoji.item, yaoItem, nowCnt)
  1092. msgRet.yaoji.canUse = getYaoJiCanUseByType(human.db._id, yaojiType)
  1093. --Msg.trace(msgRet)
  1094. Msg.send(msgRet, human.fd)
  1095. end
  1096. --- 外部接口 ---
  1097. function getLayerMax(human)
  1098. local myData = YjTreasureDBLogic.getRoleDataByUuid(human.db._id)
  1099. if not myData then
  1100. return 0
  1101. end
  1102. return myData.layerMax or 0
  1103. end
  1104. function isDot(human)
  1105. if not isOpen(human, true) then
  1106. return
  1107. end
  1108. local myData = YjTreasureDBLogic.getRoleDataByUuid(human.db._id)
  1109. if not myData or not myData.objList then
  1110. return true
  1111. end
  1112. return
  1113. end