NewLogic.lua 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. local Msg = require("core.Msg")
  2. local Broadcast = require("broadcast.Broadcast")
  3. local Lang = require("common.Lang")
  4. local Grid = require("bag.Grid")
  5. local MergeRule = require("excel.mergeConfig").rule
  6. local BagLogic = require("bag.BagLogic")
  7. local Log = require("common.Log")
  8. local Util = require("common.Util")
  9. local ItemLogic = require("bag.ItemLogic")
  10. local HeroLogic = require("hero.HeroLogic")
  11. local HeroExcel = require("excel.hero")
  12. local RoleDefine = require("role.RoleDefine")
  13. local ObjHuman = require("core.ObjHuman")
  14. local HeroGrid = require("hero.HeroGrid")
  15. local Json = require("common.Json")
  16. local FenjieLogic = require("hecheng.FenjieLogic")
  17. local HeroBook = require("hero.HeroBook")
  18. local FuwenLogic = require("fuwen.FuwenLogic")
  19. local HeroEquip = require("hero.HeroEquip")
  20. AD_DRAW_REWARD_TYPE = 10 --观看广告领取召唤券
  21. QUERY_MERGE_INFO_TYPE = 11 --获取融合信息
  22. HATCH_SCCUESS_TYPE = 12 -- 孵化成功
  23. MERGE_HERO_TYPE = 13 --融合
  24. QUICK_HATCH_TYPE = 14 --加速
  25. QUERY_MERGE_BEFORE_INFO_TYPE = 15 --获取融合前信息
  26. GET_MERGE_HERO_TYPE = 16 --获取融合英雄
  27. QUERY_QUICK_HATCH_ZUANSHI = 17 --查询加速孵化需要的钻石
  28. AD_HATCH_RESET_FREECNT = 4 --看广告加速孵化次数
  29. function NewProto(human, type, param)
  30. -- print("newProto:",type,param)
  31. -- local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  32. -- msgRet.ret = type
  33. -- msgRet.tip = "test data"
  34. -- Msg.send(msgRet,human.fd)
  35. local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  36. -- 观看广告获取召唤券
  37. if type == AD_DRAW_REWARD_TYPE then
  38. human.db.adRewardCnt = human.db.adRewardCnt or 0
  39. if human.db.adRewardCnt > 4 then
  40. Broadcast.sendErr(human, Lang.AD_DRAW_REWARD_LIMIT_ERROR)
  41. return
  42. end
  43. --增加今日观看次数
  44. human.db.adRewardCnt = (human.db.adRewardCnt or 0) + 1
  45. Log.write(Log.LOGID_TEST, "adRewardCnt: " .. human.db.adRewardCnt)
  46. -- 添加高级召唤卷
  47. BagLogic.addItem(human, 118, 1, "draw_ad_reward")
  48. msgRet.ret = AD_DRAW_REWARD_TYPE
  49. msgRet.tip = Lang.AD_DRAW_REWARD_SUCCESS
  50. Msg.send(msgRet, human.fd)
  51. Broadcast.sendErr(human, Lang.AD_DRAW_REWARD_SUCCESS)
  52. return
  53. end
  54. -- 查询加速孵化需要的钻石
  55. if type == QUERY_QUICK_HATCH_ZUANSHI then
  56. -- 初始化
  57. initMergeInfo(human)
  58. local info = {}
  59. local nowTime = os.time
  60. local hatchTime = human.db.mergeInfo.endTime - nowTime
  61. info.zuanshi = doCalcNeedZuanshi(hatchTime)
  62. info.isTip = getTodayIsTip(human)
  63. msgRet.ret = QUERY_QUICK_HATCH_ZUANSHI
  64. msgRet.tip = Json.Encode(info)
  65. Msg.send(msgRet, human.fd)
  66. return
  67. end
  68. -- 获取融合前的信息
  69. if type == QUERY_MERGE_BEFORE_INFO_TYPE then
  70. local tb = Util.split(param, "|")
  71. if tb[1] and tb[2] then
  72. -- 初始化
  73. initMergeInfo(human)
  74. human.db.heroBag = human.db.heroBag or {}
  75. local fatherHeroBagIndex = tonumber(tb[1]) or 0
  76. local motherHeroBagIndex = tonumber(tb[2]) or 0
  77. Log.write(Log.LOGID_TEST, "查询融合前的 fatherHeroBagIndex: " .. fatherHeroBagIndex)
  78. Log.write(Log.LOGID_TEST, "查询融合前的 motherHeroBagIndex: " .. motherHeroBagIndex)
  79. local fatherHeroGrid = human.db.heroBag[fatherHeroBagIndex]
  80. if not fatherHeroGrid then
  81. return
  82. end
  83. Log.write(Log.LOGID_TEST, "查询融合前的 fatherHeroGrid: " .. Json.Encode(fatherHeroGrid))
  84. local motherHeroGrid = human.db.heroBag[motherHeroBagIndex]
  85. if not motherHeroGrid then
  86. return
  87. end
  88. Log.write(Log.LOGID_TEST, "查询融合前的 motherHeroGrid: " .. Json.Encode(motherHeroGrid))
  89. local mergeInfo = {}
  90. local heroSimple = {}
  91. local xLv = getxLv(fatherHeroGrid, motherHeroGrid)
  92. local cnt = math.floor(xLv / 2) + 1
  93. local isHatch = 2
  94. local mergeItem = {}
  95. local itemId = 178
  96. for k = 1, 1 do
  97. mergeItem[k] = mergeItem[k] or {}
  98. mergeItem[k].getway = mergeItem[k].getway or {}
  99. mergeItem[k].suipian = mergeItem[k].suipian or {}
  100. mergeItem[k].equip = mergeItem[k].equip or {}
  101. mergeItem[k].fuwen = mergeItem[k].fuwen or {}
  102. Grid.makeItem(mergeItem[k], itemId, cnt)
  103. end
  104. local sonHeroID = mergeHero(fatherHeroGrid.id, motherHeroGrid.id)
  105. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  106. heroSimple.name = cf and cf.name or ""
  107. if cf.grade >= 6 then
  108. heroSimple.name = "?????"
  109. end
  110. mergeInfo.mergeTime = 0
  111. mergeInfo.xLv = xLv
  112. mergeInfo.mergeItem = mergeItem
  113. mergeInfo.heroData = heroSimple
  114. mergeInfo.isHatch = isHatch
  115. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  116. mergeInfo.isTip = getTodayIsTip(human)
  117. Log.write(Log.LOGID_TEST, "查询融合前的 mergeInfo: " .. Json.Encode(mergeInfo))
  118. msgRet.ret = QUERY_MERGE_BEFORE_INFO_TYPE
  119. msgRet.tip = Json.Encode(mergeInfo)
  120. Msg.send(msgRet, human.fd)
  121. end
  122. return
  123. end
  124. -- 开始融合
  125. if type == MERGE_HERO_TYPE then
  126. local tb = Util.split(param, "|")
  127. if tb[1] and tb[2] then
  128. -- 初始化
  129. initMergeInfo(human)
  130. human.db.heroBag = human.db.heroBag or {}
  131. Log.write(Log.LOGID_TEST, "融合 human.db.heroBag: " .. Json.Encode(human.db.heroBag))
  132. local itemId = 178 --生命雨露
  133. local fatherHeroBagIndex = tonumber(tb[1]) or 0
  134. local motherHeroBagIndex = tonumber(tb[2]) or 0
  135. Log.write(Log.LOGID_TEST, "融合 fatherHeroBagIndex: " .. fatherHeroBagIndex)
  136. Log.write(Log.LOGID_TEST, "融合 motherHeroBagIndex: " .. motherHeroBagIndex)
  137. local fatherHeroGrid = human.db.heroBag[fatherHeroBagIndex]
  138. if not fatherHeroGrid then
  139. return
  140. end
  141. Log.write(Log.LOGID_TEST, "融合 fatherHeroGrid: " .. Json.Encode(fatherHeroGrid))
  142. local motherHeroGrid = human.db.heroBag[motherHeroBagIndex]
  143. if not motherHeroGrid then
  144. return
  145. end
  146. Log.write(Log.LOGID_TEST, "融合 motherHeroGrid: " .. Json.Encode(motherHeroGrid))
  147. local fatherHeroAttr = ObjHuman.getHeroAttrs(human, fatherHeroBagIndex)
  148. local motherHeroAttr = ObjHuman.getHeroAttrs(human, motherHeroBagIndex)
  149. local mergeInfo = {}
  150. local attrs = RoleDefine.PANEL_ATTR_KEY
  151. local sonHeroID = mergeHero(fatherHeroGrid.id, motherHeroGrid.id)
  152. if sonHeroID <= 0 then
  153. return
  154. end
  155. for key, value in pairs(attrs) do
  156. local param1 = fatherHeroAttr[key] or 0
  157. local param2 = motherHeroAttr[key] or 0
  158. attrs[key] = math.floor(((param1 + param2) / 4))
  159. end
  160. Log.write(Log.LOGID_TEST, "融合后的属性: " .. Json.Encode(attrs))
  161. local xLv = getxLv(fatherHeroGrid, motherHeroGrid)
  162. local cnt = math.floor(xLv / 2) + 1
  163. local heroSimple = {}
  164. local isHatch = 1
  165. Log.write(Log.LOGID_TEST, "xLv: " .. xLv)
  166. Log.write(Log.LOGID_TEST, "cnt: " .. cnt)
  167. local bagCnt = BagLogic.getItemCnt(human, itemId, true)
  168. if bagCnt < cnt then
  169. Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
  170. return
  171. end
  172. --使用道具
  173. ItemLogic.use(human, itemId, cnt)
  174. local delHeroList = { [1] = fatherHeroBagIndex, [2] = motherHeroBagIndex }
  175. for key, heroIndex in pairs(delHeroList) do
  176. local heroID = HeroLogic.getHeroIdByIndex(human, heroIndex)
  177. HeroEquip.putOffQuick(human, heroID, heroIndex, true)
  178. FuwenLogic.putOffQuick(human, heroID, heroIndex, true)
  179. HeroLogic.delHeroByIndex(human, heroIndex, "hero_merge")
  180. end
  181. -- 记录融合英雄
  182. human.db.mergeInfo.heroInfo.heroID = sonHeroID
  183. human.db.mergeInfo.heroInfo.xLv = xLv
  184. human.db.mergeInfo.heroInfo.heroAttrs = attrs
  185. human.db.mergeInfo.startTime = os.time()
  186. human.db.mergeInfo.endTime = os.time() + getHatchTime(xLv)
  187. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = fatherHeroBagIndex
  188. human.db.mergeInfo.heroInfo.motherHeroBagIndex = motherHeroBagIndex
  189. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  190. heroSimple.name = cf and cf.name or ""
  191. if cf.grade >= 6 then
  192. heroSimple.name = "?????"
  193. end
  194. if getHatchTime(xLv) == 0 then
  195. isHatch = 3
  196. end
  197. mergeInfo.mergeTime = getHatchTime(xLv)
  198. mergeInfo.xLv = xLv
  199. mergeInfo.heroData = heroSimple
  200. mergeInfo.isHatch = isHatch
  201. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  202. mergeInfo.isTip = getTodayIsTip(human)
  203. Log.write(Log.LOGID_TEST, "融合 mergeInfo: " .. Json.Encode(mergeInfo))
  204. Broadcast.sendErr(human, Lang.MERGE_SUCCESS)
  205. msgRet.ret = MERGE_HERO_TYPE
  206. msgRet.tip = Json.Encode(mergeInfo)
  207. Msg.send(msgRet, human.fd)
  208. end
  209. return
  210. end
  211. -- 获取融合中的信息
  212. if type == QUERY_MERGE_INFO_TYPE then
  213. -- 初始化
  214. initMergeInfo(human)
  215. human.db.heroBag = human.db.heroBag or {}
  216. local mergeInfo = {}
  217. local mergeTime = 0
  218. local heroSimple = {}
  219. local xLv = human.db.mergeInfo.heroInfo.xLv or 0
  220. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  221. local isHatch = 2
  222. if sonHeroID == 0 then
  223. mergeInfo.mergeTime = mergeTime
  224. mergeInfo.xLv = xLv
  225. mergeInfo.heroData = heroSimple
  226. mergeInfo.isHatch = isHatch
  227. msgRet.ret = QUERY_MERGE_INFO_TYPE
  228. msgRet.tip = Json.Encode(mergeInfo)
  229. Msg.send(msgRet, human.fd)
  230. return
  231. end
  232. local mergeTime = human.db.mergeInfo.endTime - os.time()
  233. if mergeTime <= 0 then
  234. -- 孵化成功
  235. mergeTime = 0
  236. isHatch = 3
  237. else
  238. isHatch = 1
  239. end
  240. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  241. heroSimple.name = cf and cf.name or ""
  242. if cf.grade >= 6 then
  243. heroSimple.name = "?????"
  244. end
  245. mergeInfo.mergeTime = mergeTime
  246. mergeInfo.xLv = xLv
  247. mergeInfo.heroData = heroSimple
  248. mergeInfo.isHatch = isHatch
  249. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  250. mergeInfo.isTip = getTodayIsTip(human)
  251. msgRet.ret = QUERY_MERGE_INFO_TYPE
  252. msgRet.tip = Json.Encode(mergeInfo)
  253. Log.write(Log.LOGID_TEST, "融合中 msgRet: " .. Json.Encode(msgRet))
  254. Msg.send(msgRet, human.fd)
  255. return
  256. end
  257. -- 获取融合英雄
  258. if type == GET_MERGE_HERO_TYPE then
  259. local nowTime = os.time()
  260. local mergeInfo = {}
  261. local heroSimple = {}
  262. local xLv = human.db.mergeInfo.heroInfo.xLv or 0
  263. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  264. local hatchTime = human.db.mergeInfo.endTime - nowTime
  265. local isHatch = 2
  266. local heroIndex = 0
  267. local msgTyep = GET_MERGE_HERO_TYPE
  268. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  269. local heroNiceNet = {
  270. itemData = {},
  271. heroStatic = {
  272. [1] = {
  273. skillList = {
  274. [1] = {
  275. cd = {
  276. [1] = {},
  277. [2] = {}
  278. },
  279. buff = {
  280. [1] = {},
  281. [2] = {},
  282. [3] = {},
  283. [4] = {},
  284. [5] = {},
  285. }
  286. },
  287. [2] = {
  288. cd = {
  289. [1] = {},
  290. [2] = {}
  291. },
  292. buff = {
  293. [1] = {},
  294. [2] = {},
  295. [3] = {},
  296. [4] = {},
  297. [5] = {},
  298. }
  299. },
  300. },
  301. beSkill = {
  302. [1] = {
  303. cd = {
  304. [1] = {},
  305. [2] = {}
  306. },
  307. buff = {
  308. [1] = {},
  309. [2] = {},
  310. [3] = {},
  311. [4] = {},
  312. [5] = {},
  313. }
  314. },
  315. [2] = {
  316. cd = {
  317. [1] = {},
  318. [2] = {}
  319. },
  320. buff = {
  321. [1] = {},
  322. [2] = {},
  323. [3] = {},
  324. [4] = {},
  325. [5] = {},
  326. }
  327. },
  328. [3] = {
  329. cd = {
  330. [1] = {},
  331. [2] = {}
  332. },
  333. buff = {
  334. [1] = {},
  335. [2] = {},
  336. [3] = {},
  337. [4] = {},
  338. [5] = {},
  339. }
  340. },
  341. }
  342. },
  343. [2] = {
  344. skillList = {
  345. [1] = {},
  346. [2] = {},
  347. },
  348. beSkill = {
  349. [1] = {},
  350. [2] = {},
  351. [3] = {},
  352. }
  353. },
  354. },
  355. heroSimple = {
  356. [1] = {
  357. general = {}
  358. },
  359. [2] = {
  360. general = {}
  361. }
  362. },
  363. attrs = {
  364. [1] = {},
  365. [2] = {},
  366. [3] = {},
  367. [4] = {},
  368. },
  369. attrsMax = {
  370. [1] = {},
  371. [2] = {},
  372. [3] = {},
  373. [4] = {},
  374. }
  375. }
  376. if hatchTime <= 0 then
  377. -- 孵化成功
  378. hatchTime = 0
  379. heroIndex = hatchHero(human)
  380. local heroGrid = human.db.heroBag[heroIndex]
  381. if not heroGrid then return end
  382. heroSimple.general = heroSimple.general or {}
  383. HeroGrid.makeHeroSimple(heroSimple, heroGrid, heroIndex, human)
  384. local heroID = heroGrid.id or 0
  385. local isNew = not HeroBook.isGet(human, cf.id, cf.star)
  386. HeroGrid.makeHeroNiceToJson(heroNiceNet, heroID, nil, isNew, heroIndex)
  387. else
  388. heroSimple.name = cf and cf.name or ""
  389. if cf.grade >= 6 then
  390. heroSimple.name = "?????"
  391. end
  392. isHatch = 1
  393. msgTyep = QUERY_MERGE_INFO_TYPE
  394. end
  395. mergeInfo.mergeTime = hatchTime
  396. mergeInfo.xLv = xLv
  397. mergeInfo.heroData = heroSimple
  398. mergeInfo.isHatch = isHatch
  399. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  400. mergeInfo.isTip = getTodayIsTip(human)
  401. mergeInfo.heroNiceNet = heroNiceNet
  402. msgRet.ret = msgTyep
  403. msgRet.tip = Json.Encode(mergeInfo)
  404. Log.write(Log.LOGID_TEST, "获取英雄 ret: " .. Json.Encode(msgRet))
  405. Msg.send(msgRet, human.fd)
  406. return
  407. end
  408. -- 加速孵化
  409. if type == QUICK_HATCH_TYPE then
  410. local tb = Util.split(param, "|")
  411. local quickType = tonumber(tb[1]) or 0
  412. local cnt = tonumber(tb[2]) or 0
  413. local isHatch = 1
  414. if tb[1] and tb[2] then
  415. -- 初始化
  416. initMergeInfo(human)
  417. -- 剩余时间
  418. local nowTime = os.time()
  419. local hatchTime = human.db.mergeInfo.endTime - nowTime
  420. if hatchTime <= 0
  421. then
  422. Broadcast.sendErr(human, Lang.QUICK_HATCH_TIME_OUT)
  423. return
  424. end
  425. local itemSpeedTime = 0
  426. if quickType == 1 then
  427. local speedTime = (60 * 5 * cnt) -- 正常数量加速券的加速时间
  428. local lastSpeedTime = (60 * 5 * (cnt - 1)) --少一张加速券的加速时间
  429. local itemCnt = 0
  430. if hatchTime > lastSpeedTime and hatchTime <= speedTime then
  431. itemCnt = cnt
  432. elseif hatchTime > 0 and hatchTime <= lastSpeedTime then
  433. itemCnt = cnt - 1
  434. elseif hatchTime >= speedTime then
  435. itemCnt = cnt
  436. else
  437. itemCnt = 0
  438. end
  439. itemSpeedTime = (60 * 5 * itemCnt)
  440. local bagCnt = BagLogic.getItemCnt(human, 179, true)
  441. if bagCnt < itemCnt then
  442. Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
  443. return
  444. end
  445. --使用道具
  446. ItemLogic.use(human, 179, itemCnt)
  447. elseif quickType == 2 then
  448. local zuanshiCnt = doCalcNeedZuanshi(hatchTime)
  449. -- 判断消耗
  450. if not ObjHuman.checkRMB(human, zuanshiCnt) then
  451. return
  452. end
  453. itemSpeedTime = (30 * zuanshiCnt)
  454. -- 扣钻石
  455. ObjHuman.decZuanshi(human, -zuanshiCnt, "hero_merge")
  456. if tb[3] then
  457. human.db.isTip = human.db.isTip or 1
  458. human.db.isTip = tonumber(tb[3])
  459. end
  460. elseif quickType == 3 then
  461. human.db.adHatchRewardCnt = human.db.adHatchRewardCnt or 0
  462. if human.db.adHatchRewardCnt > 4 then
  463. Broadcast.sendErr(human, Lang.AD_DRAW_REWARD_LIMIT_ERROR)
  464. return
  465. end
  466. --加速30分钟
  467. itemSpeedTime = 30 * 60
  468. --增加今日观看次数
  469. human.db.adHatchRewardCnt = (human.db.adHatchRewardCnt or 0) + 1
  470. end
  471. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
  472. local hatchTime = human.db.mergeInfo.endTime - nowTime
  473. -- 孵化成功
  474. if hatchTime < 0 then
  475. hatchTime = 0
  476. isHatch = 3
  477. end
  478. local mergeInfo = {}
  479. local heroSimple = {}
  480. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  481. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  482. heroSimple.name = cf and cf.name or ""
  483. if cf.grade >= 6 then
  484. heroSimple.name = "?????"
  485. end
  486. mergeInfo.mergeTime = hatchTime
  487. mergeInfo.heroData = heroSimple
  488. mergeInfo.xLv = human.db.mergeInfo.heroInfo.xLv
  489. mergeInfo.isHatch = isHatch
  490. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  491. mergeInfo.isTip = getTodayIsTip(human)
  492. msgRet.ret = QUICK_HATCH_TYPE
  493. msgRet.tip = Json.Encode(mergeInfo)
  494. Log.write(Log.LOGID_TEST, "加速孵化 ret: " .. Json.Encode(msgRet))
  495. Msg.send(msgRet, human.fd)
  496. return
  497. end
  498. return
  499. end
  500. end
  501. -- 孵化英雄
  502. function hatchHero(human)
  503. Log.write(Log.LOGID_TEST, "孵化英雄id " .. human.db.mergeInfo.heroInfo.heroID)
  504. --添加英雄
  505. local heroIndex, fjlist = HeroLogic.addHero(human, human.db.mergeInfo.heroInfo.heroID, nil, 1,
  506. "hero_merge")
  507. Log.write(Log.LOGID_TEST, "孵化英雄成功 下标" .. heroIndex)
  508. local attrs = RoleDefine.PANEL_ATTR_KEY
  509. for key, value in pairs(attrs) do
  510. attrs[key] = 1
  511. end
  512. human.db.mergeInfo.startTime = 0
  513. human.db.mergeInfo.endTime = 0
  514. human.db.mergeInfo.heroInfo = {}
  515. human.db.mergeInfo.heroInfo.heroID = 0
  516. human.db.mergeInfo.heroInfo.xLv = 0
  517. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = 0
  518. human.db.mergeInfo.heroInfo.motherHeroBagIndex = 0
  519. human.db.mergeInfo.heroInfo.heroAttrs = attrs
  520. Log.write(Log.LOGID_TEST, "孵化重置 mergeInfo: " .. Json.Encode(human.db.mergeInfo))
  521. return heroIndex
  522. end
  523. -- 初始化融合信息
  524. function initMergeInfo(human)
  525. human.db.mergeInfo = human.db.mergeInfo or {}
  526. human.db.mergeInfo.startTime = human.db.mergeInfo.startTime or 0 --融合时间 时间戳
  527. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime or 0 --孵化时间 单位s
  528. human.db.mergeInfo.heroInfo = human.db.mergeInfo.heroInfo or {}
  529. human.db.mergeInfo.heroInfo.heroID = human.db.mergeInfo.heroInfo.heroID or 0
  530. human.db.mergeInfo.heroInfo.xLv = human.db.mergeInfo.heroInfo.xLv or 0
  531. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = human.db.mergeInfo.heroInfo.fatherHeroBagIndex or 0
  532. human.db.mergeInfo.heroInfo.motherHeroBagIndex = human.db.mergeInfo.heroInfo.motherHeroBagIndex or 0
  533. human.db.mergeInfo.heroInfo.heroAttrs = human.db.mergeInfo.heroInfo.heroAttrs or RoleDefine.PANEL_ATTR_KEY
  534. end
  535. -- 获取孵化时间 单位s
  536. function getHatchTime(xLv)
  537. local time = (xLv * 5) + (xLv - 1) * (xLv - 1) - 5
  538. if time < 0 then
  539. return 0
  540. end
  541. return time * 60
  542. end
  543. -- 计算需要钻石数量
  544. function doCalcNeedZuanshi(hatchTime)
  545. local cnt = 0
  546. if hatchTime > 0 then
  547. cnt = math.ceil(hatchTime / 30)
  548. end
  549. return cnt
  550. end
  551. -- 获取xlv
  552. function getxLv(fatherHeroGrid, motherHeroGrid)
  553. local fatherHeroXLv = fatherHeroGrid.xLv or 0
  554. local motherHeroXLv = motherHeroGrid.xLv or 0
  555. local params1 = math.max(fatherHeroXLv, motherHeroXLv)
  556. local params2 = math.floor((fatherHeroGrid.lv + motherHeroGrid.lv) / 200) + 1
  557. local xLv = params1 + params2
  558. if xLv > 50 then
  559. return 50
  560. end
  561. return xLv
  562. end
  563. -- 融合获取英雄ID
  564. function mergeHero(fatherHeroID, motherHeroID)
  565. local fatherHeroConfig = HeroExcel.hero[fatherHeroID]
  566. local motherHeroConfig = HeroExcel.hero[motherHeroID]
  567. if not fatherHeroConfig or not motherHeroConfig then
  568. return 0
  569. end
  570. --规则3 heroID + heroID
  571. for _, config in pairs(MergeRule[3].items) do
  572. if fatherHeroID == config[1] and motherHeroID == config[2] then
  573. return config[3]
  574. end
  575. end
  576. --规则2 种族 + heroID
  577. for _, config in pairs(MergeRule[2].items) do
  578. if fatherHeroConfig.camp == config[1] and motherHeroID == config[2] then
  579. return config[3]
  580. end
  581. end
  582. --规则1 种族 + 种族
  583. for _, config in pairs(MergeRule[1].items) do
  584. if fatherHeroConfig.camp == config[1] and motherHeroConfig.camp == config[2] then
  585. return config[3]
  586. end
  587. end
  588. return 0
  589. end
  590. -- 获取剩余融化孵化加速广告观看次数
  591. function getResetAdHatchCnt(human)
  592. local adHatchRewardCnt = human.db.adHatchRewardCnt or 0
  593. return math.max(AD_HATCH_RESET_FREECNT - adHatchRewardCnt, 0)
  594. end
  595. -- 获取是否今日不再提示
  596. function getTodayIsTip(human)
  597. local isTip = human.db.isTip or 1
  598. return tonumber(isTip)
  599. end