YjTreasureLogic.lua 43 KB

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