YjTreasureLogic.lua 42 KB

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