YjTreasureLogic.lua 42 KB

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