YjTreasureLogic.lua 41 KB

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