NewLogic.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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. },
  344. heroSimple = {
  345. [1] = {
  346. general = {}
  347. },
  348. },
  349. attrs = {
  350. [1] = {},
  351. [2] = {},
  352. [3] = {},
  353. [4] = {},
  354. },
  355. attrsMax = {
  356. [1] = {},
  357. [2] = {},
  358. [3] = {},
  359. [4] = {},
  360. }
  361. }
  362. if hatchTime <= 0 then
  363. -- 孵化成功
  364. hatchTime = 0
  365. heroIndex = hatchHero(human)
  366. local heroGrid = human.db.heroBag[heroIndex]
  367. if not heroGrid then return end
  368. heroSimple.general = heroSimple.general or {}
  369. HeroGrid.makeHeroSimple(heroSimple, heroGrid, heroIndex, human)
  370. local heroID = heroGrid.id or 0
  371. local isNew = not HeroBook.isGet(human, cf.id, cf.star)
  372. HeroGrid.makeHeroNiceToJson(heroNiceNet, heroID, nil, isNew, heroIndex)
  373. else
  374. heroSimple.name = cf and cf.name or ""
  375. if cf.grade >= 6 then
  376. heroSimple.name = "?????"
  377. end
  378. isHatch = 1
  379. msgTyep = QUERY_MERGE_INFO_TYPE
  380. end
  381. mergeInfo.mergeTime = hatchTime
  382. mergeInfo.xLv = xLv
  383. mergeInfo.heroData = heroSimple
  384. mergeInfo.isHatch = isHatch
  385. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  386. mergeInfo.isTip = getTodayIsTip(human)
  387. mergeInfo.heroNiceNet = heroNiceNet
  388. msgRet.ret = msgTyep
  389. msgRet.tip = Json.Encode(mergeInfo)
  390. Log.write(Log.LOGID_TEST, "获取英雄 ret: " .. Json.Encode(msgRet))
  391. Msg.send(msgRet, human.fd)
  392. return
  393. end
  394. -- 加速孵化
  395. if type == QUICK_HATCH_TYPE then
  396. local tb = Util.split(param, "|")
  397. local quickType = tonumber(tb[1]) or 0
  398. local cnt = tonumber(tb[2]) or 0
  399. local isHatch = 1
  400. if tb[1] and tb[2] then
  401. -- 初始化
  402. initMergeInfo(human)
  403. -- 剩余时间
  404. local nowTime = os.time()
  405. local hatchTime = human.db.mergeInfo.endTime - nowTime
  406. if hatchTime <= 0
  407. then
  408. Broadcast.sendErr(human, Lang.QUICK_HATCH_TIME_OUT)
  409. return
  410. end
  411. local itemSpeedTime = 0
  412. if quickType == 1 then
  413. local speedTime = (60 * 5 * cnt) -- 正常数量加速券的加速时间
  414. local lastSpeedTime = (60 * 5 * (cnt - 1)) --少一张加速券的加速时间
  415. local itemCnt = 0
  416. if hatchTime > lastSpeedTime and hatchTime <= speedTime then
  417. itemCnt = cnt
  418. elseif hatchTime > 0 and hatchTime <= lastSpeedTime then
  419. itemCnt = cnt - 1
  420. elseif hatchTime >= speedTime then
  421. itemCnt = cnt
  422. else
  423. itemCnt = 0
  424. end
  425. itemSpeedTime = (60 * 5 * itemCnt)
  426. local bagCnt = BagLogic.getItemCnt(human, 179, true)
  427. if bagCnt < itemCnt then
  428. Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
  429. return
  430. end
  431. --使用道具
  432. ItemLogic.use(human, 179, itemCnt)
  433. elseif quickType == 2 then
  434. local zuanshiCnt = doCalcNeedZuanshi(hatchTime)
  435. -- 判断消耗
  436. if not ObjHuman.checkRMB(human, zuanshiCnt) then
  437. return
  438. end
  439. itemSpeedTime = (30 * zuanshiCnt)
  440. -- 扣钻石
  441. ObjHuman.decZuanshi(human, -zuanshiCnt, "hero_merge")
  442. if tb[3] then
  443. human.db.isTip = human.db.isTip or 1
  444. human.db.isTip = tonumber(tb[3])
  445. end
  446. elseif quickType == 3 then
  447. human.db.adHatchRewardCnt = human.db.adHatchRewardCnt or 0
  448. if human.db.adHatchRewardCnt > 4 then
  449. Broadcast.sendErr(human, Lang.AD_HATCH_REWARD_LIMIT_ERROR)
  450. return
  451. end
  452. --加速30分钟
  453. itemSpeedTime = 30 * 60
  454. --增加今日观看次数
  455. human.db.adHatchRewardCnt = (human.db.adHatchRewardCnt or 0) + 1
  456. end
  457. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
  458. local hatchTime = human.db.mergeInfo.endTime - nowTime
  459. -- 孵化成功
  460. if hatchTime < 0 then
  461. hatchTime = 0
  462. isHatch = 3
  463. end
  464. local mergeInfo = {}
  465. local heroSimple = {}
  466. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  467. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  468. heroSimple.name = cf and cf.name or ""
  469. if cf.grade >= 6 then
  470. heroSimple.name = "?????"
  471. end
  472. mergeInfo.mergeTime = hatchTime
  473. mergeInfo.heroData = heroSimple
  474. mergeInfo.xLv = human.db.mergeInfo.heroInfo.xLv
  475. mergeInfo.isHatch = isHatch
  476. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  477. mergeInfo.isTip = getTodayIsTip(human)
  478. msgRet.ret = QUICK_HATCH_TYPE
  479. msgRet.tip = Json.Encode(mergeInfo)
  480. Log.write(Log.LOGID_TEST, "加速孵化 ret: " .. Json.Encode(msgRet))
  481. Msg.send(msgRet, human.fd)
  482. return
  483. end
  484. return
  485. end
  486. end
  487. -- 孵化英雄
  488. function hatchHero(human)
  489. Log.write(Log.LOGID_TEST, "孵化英雄id " .. human.db.mergeInfo.heroInfo.heroID)
  490. --添加英雄
  491. local heroIndex, fjlist = HeroLogic.addHero(human, human.db.mergeInfo.heroInfo.heroID, nil, 1,
  492. "hero_merge")
  493. Log.write(Log.LOGID_TEST, "孵化英雄成功 下标" .. heroIndex)
  494. local attrs = RoleDefine.PANEL_ATTR_KEY
  495. for key, value in pairs(attrs) do
  496. attrs[key] = 1
  497. end
  498. human.db.mergeInfo.startTime = 0
  499. human.db.mergeInfo.endTime = 0
  500. human.db.mergeInfo.heroInfo = {}
  501. human.db.mergeInfo.heroInfo.heroID = 0
  502. human.db.mergeInfo.heroInfo.xLv = 0
  503. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = 0
  504. human.db.mergeInfo.heroInfo.motherHeroBagIndex = 0
  505. human.db.mergeInfo.heroInfo.heroAttrs = attrs
  506. Log.write(Log.LOGID_TEST, "孵化重置 mergeInfo: " .. Json.Encode(human.db.mergeInfo))
  507. return heroIndex
  508. end
  509. -- 初始化融合信息
  510. function initMergeInfo(human)
  511. human.db.mergeInfo = human.db.mergeInfo or {}
  512. human.db.mergeInfo.startTime = human.db.mergeInfo.startTime or 0 --融合时间 时间戳
  513. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime or 0 --孵化时间 单位s
  514. human.db.mergeInfo.heroInfo = human.db.mergeInfo.heroInfo or {}
  515. human.db.mergeInfo.heroInfo.heroID = human.db.mergeInfo.heroInfo.heroID or 0
  516. human.db.mergeInfo.heroInfo.xLv = human.db.mergeInfo.heroInfo.xLv or 0
  517. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = human.db.mergeInfo.heroInfo.fatherHeroBagIndex or 0
  518. human.db.mergeInfo.heroInfo.motherHeroBagIndex = human.db.mergeInfo.heroInfo.motherHeroBagIndex or 0
  519. human.db.mergeInfo.heroInfo.heroAttrs = human.db.mergeInfo.heroInfo.heroAttrs or RoleDefine.PANEL_ATTR_KEY
  520. end
  521. -- 获取孵化时间 单位s
  522. function getHatchTime(xLv)
  523. local time = (xLv * 5) + (xLv - 1) * (xLv - 1) - 5
  524. if time < 0 then
  525. return 0
  526. end
  527. return time * 60
  528. end
  529. -- 计算需要钻石数量
  530. function doCalcNeedZuanshi(hatchTime)
  531. local cnt = 0
  532. if hatchTime > 0 then
  533. cnt = math.ceil(hatchTime / 30)
  534. end
  535. return cnt
  536. end
  537. -- 获取xlv
  538. function getxLv(fatherHeroGrid, motherHeroGrid)
  539. local fatherHeroXLv = fatherHeroGrid.xLv or 0
  540. local motherHeroXLv = motherHeroGrid.xLv or 0
  541. local params1 = math.max(fatherHeroXLv, motherHeroXLv)
  542. local params2 = math.floor((fatherHeroGrid.lv + motherHeroGrid.lv) / 200) + 1
  543. local xLv = params1 + params2
  544. if xLv > 50 then
  545. return 50
  546. end
  547. return xLv
  548. end
  549. -- 融合获取英雄ID
  550. function mergeHero(fatherHeroID, motherHeroID)
  551. local fatherHeroConfig = HeroExcel.hero[fatherHeroID]
  552. local motherHeroConfig = HeroExcel.hero[motherHeroID]
  553. if not fatherHeroConfig or not motherHeroConfig then
  554. return 0
  555. end
  556. --规则3 heroID + heroID
  557. for _, config in pairs(MergeRule[3].items) do
  558. if fatherHeroID == config[1] and motherHeroID == config[2] then
  559. return config[3]
  560. end
  561. end
  562. --规则2 种族 + heroID
  563. for _, config in pairs(MergeRule[2].items) do
  564. if fatherHeroConfig.camp == config[1] and motherHeroID == config[2] then
  565. return config[3]
  566. end
  567. end
  568. --规则1 种族 + 种族
  569. for _, config in pairs(MergeRule[1].items) do
  570. if fatherHeroConfig.camp == config[1] and motherHeroConfig.camp == config[2] then
  571. return config[3]
  572. end
  573. end
  574. return 0
  575. end
  576. -- 获取剩余融化孵化加速广告观看次数
  577. function getResetAdHatchCnt(human)
  578. local adHatchRewardCnt = human.db.adHatchRewardCnt or 0
  579. return math.max(AD_HATCH_RESET_FREECNT - adHatchRewardCnt, 0)
  580. end
  581. -- 获取是否今日不再提示
  582. function getTodayIsTip(human)
  583. local isTip = human.db.isTip or 1
  584. return tonumber(isTip)
  585. end