NewLogic.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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(motherHeroBagIndex))
  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. local itemId = 178 --生命雨露
  132. local fatherHeroBagIndex = tonumber(tb[1]) or 0
  133. local motherHeroBagIndex = tonumber(tb[2]) or 0
  134. local fatherHeroGrid = human.db.heroBag[fatherHeroBagIndex]
  135. if not fatherHeroGrid then
  136. return
  137. end
  138. local motherHeroGrid = human.db.heroBag[motherHeroBagIndex]
  139. if not motherHeroGrid then
  140. return
  141. end
  142. local fatherHeroAttr = ObjHuman.getHeroAttrs(human, fatherHeroBagIndex)
  143. local motherHeroAttr = ObjHuman.getHeroAttrs(human, motherHeroBagIndex)
  144. local mergeInfo = {}
  145. local attrs = RoleDefine.PANEL_ATTR_KEY
  146. local sonHeroID = mergeHero(fatherHeroGrid.id, motherHeroGrid.id)
  147. if sonHeroID <= 0 then
  148. return
  149. end
  150. for key, value in pairs(attrs) do
  151. local param1 = fatherHeroAttr[key] or 0
  152. local param2 = motherHeroAttr[key] or 0
  153. attrs[key] = math.floor(((param1 + param2) / 4))
  154. end
  155. Log.write(Log.LOGID_TEST, "融合后的属性: " .. Json.Encode(attrs))
  156. local xLv = getxLv(fatherHeroGrid, motherHeroGrid)
  157. local cnt = math.floor(xLv / 2) + 1
  158. local heroSimple = {}
  159. local isHatch = 1
  160. Log.write(Log.LOGID_TEST, "xLv: " .. xLv)
  161. Log.write(Log.LOGID_TEST, "cnt: " .. cnt)
  162. local bagCnt = BagLogic.getItemCnt(human, itemId, true)
  163. if bagCnt < cnt then
  164. Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
  165. return
  166. end
  167. --使用道具
  168. ItemLogic.use(human, itemId, cnt)
  169. local outItems = {}
  170. local delHeroList = { [1] = fatherHeroBagIndex, [2] = motherHeroBagIndex }
  171. for heroIndex in pairs(delHeroList) do
  172. local heroID = HeroLogic.getHeroIdByIndex(human, heroIndex)
  173. HeroEquip.putOffQuick(human, heroID, heroIndex, true)
  174. FuwenLogic.putOffQuick(human, heroID, heroIndex, true)
  175. local inputIDList = { [0] = 1, [1] = heroID }
  176. local inputIndexList = { [0] = 1, [1] = heroIndex }
  177. outItems[#outItems + 1] = FenjieLogic.fenjie(human, FenjieLogic.FENJIE_DO_MERGE, inputIDList,
  178. inputIndexList, nil, "hero_merge")
  179. end
  180. BagLogic.sendItemGetList3(human, outItems, "tenStar_displace")
  181. -- 删除英雄
  182. -- HeroLogic.delHeroByIndex(human, fatherHeroBagIndex, "hero_merge")
  183. -- HeroLogic.delHeroByIndex(human, motherHeroBagIndex, "hero_merge")
  184. -- 记录融合英雄
  185. human.db.mergeInfo.heroInfo.heroID = sonHeroID
  186. human.db.mergeInfo.heroInfo.xLv = xLv
  187. human.db.mergeInfo.heroInfo.heroAttrs = attrs
  188. human.db.mergeInfo.startTime = os.time()
  189. human.db.mergeInfo.endTime = os.time() + getHatchTime(xLv)
  190. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = fatherHeroBagIndex
  191. human.db.mergeInfo.heroInfo.motherHeroBagIndex = motherHeroBagIndex
  192. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  193. heroSimple.name = cf and cf.name or ""
  194. if cf.grade >= 6 then
  195. heroSimple.name = "?????"
  196. end
  197. if getHatchTime(xLv) == 0 then
  198. isHatch = 3
  199. end
  200. mergeInfo.mergeTime = getHatchTime(xLv)
  201. mergeInfo.xLv = xLv
  202. mergeInfo.heroData = heroSimple
  203. mergeInfo.isHatch = isHatch
  204. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  205. mergeInfo.isTip = getTodayIsTip(human)
  206. Log.write(Log.LOGID_TEST, "融合 mergeInfo: " .. Json.Encode(mergeInfo))
  207. Broadcast.sendErr(human, Lang.MERGE_SUCCESS)
  208. msgRet.ret = MERGE_HERO_TYPE
  209. msgRet.tip = Json.Encode(mergeInfo)
  210. Msg.send(msgRet, human.fd)
  211. end
  212. return
  213. end
  214. -- 获取融合中的信息
  215. if type == QUERY_MERGE_INFO_TYPE then
  216. -- 初始化
  217. initMergeInfo(human)
  218. human.db.heroBag = human.db.heroBag or {}
  219. local mergeInfo = {}
  220. local mergeTime = 0
  221. local heroSimple = {}
  222. local xLv = human.db.mergeInfo.heroInfo.xLv or 0
  223. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  224. local isHatch = 2
  225. if sonHeroID == 0 then
  226. mergeInfo.mergeTime = mergeTime
  227. mergeInfo.xLv = xLv
  228. mergeInfo.heroData = heroSimple
  229. mergeInfo.isHatch = isHatch
  230. msgRet.ret = QUERY_MERGE_INFO_TYPE
  231. msgRet.tip = Json.Encode(mergeInfo)
  232. Msg.send(msgRet, human.fd)
  233. return
  234. end
  235. local mergeTime = human.db.mergeInfo.endTime - os.time()
  236. if mergeTime <= 0 then
  237. -- 孵化成功
  238. mergeTime = 0
  239. isHatch = 3
  240. else
  241. isHatch = 1
  242. end
  243. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  244. heroSimple.name = cf and cf.name or ""
  245. if cf.grade >= 6 then
  246. heroSimple.name = "?????"
  247. end
  248. mergeInfo.mergeTime = mergeTime
  249. mergeInfo.xLv = xLv
  250. mergeInfo.heroData = heroSimple
  251. mergeInfo.isHatch = isHatch
  252. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  253. mergeInfo.isTip = getTodayIsTip(human)
  254. msgRet.ret = QUERY_MERGE_INFO_TYPE
  255. msgRet.tip = Json.Encode(mergeInfo)
  256. Log.write(Log.LOGID_TEST, "融合中 msgRet: " .. Json.Encode(msgRet))
  257. Msg.send(msgRet, human.fd)
  258. return
  259. end
  260. -- 获取融合英雄
  261. if type == GET_MERGE_HERO_TYPE then
  262. local nowTime = os.time()
  263. local mergeInfo = {}
  264. local heroSimple = {}
  265. local xLv = human.db.mergeInfo.heroInfo.xLv or 0
  266. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  267. local hatchTime = human.db.mergeInfo.endTime - nowTime
  268. local isHatch = 2
  269. local heroIndex = 0
  270. local msgTyep = GET_MERGE_HERO_TYPE
  271. local heroNiceNet = {}
  272. if hatchTime <= 0 then
  273. -- 孵化成功
  274. hatchTime = 0
  275. heroIndex = hatchHero(human)
  276. local heroGrid = human.db.heroBag[heroIndex]
  277. if not heroGrid then return end
  278. heroSimple.general = heroSimple.general or {}
  279. HeroGrid.makeHeroSimple(heroSimple, heroGrid, heroIndex, human)
  280. for i = 1, 1 do
  281. local heroID = heroGrid.id or heroGrid.heroID
  282. local heroConfig = heroID or HeroExcel.hero[heroID]
  283. local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  284. HeroGrid.makeHeroNice(heroNiceNet, heroID, nil, isNew, heroIndex)
  285. end
  286. else
  287. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  288. heroSimple.name = cf and cf.name or ""
  289. if cf.grade >= 6 then
  290. heroSimple.name = "?????"
  291. end
  292. isHatch = 1
  293. msgTyep = QUERY_MERGE_INFO_TYPE
  294. end
  295. mergeInfo.mergeTime = hatchTime
  296. mergeInfo.xLv = xLv
  297. mergeInfo.heroData = heroSimple
  298. mergeInfo.isHatch = isHatch
  299. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  300. mergeInfo.isTip = getTodayIsTip(human)
  301. mergeInfo.heroNiceNet = heroNiceNet
  302. msgRet.ret = msgTyep
  303. msgRet.tip = Json.Encode(mergeInfo)
  304. Log.write(Log.LOGID_TEST, "获取英雄 ret: " .. Json.Encode(msgRet))
  305. Msg.send(msgRet, human.fd)
  306. return
  307. end
  308. -- 加速孵化
  309. if type == QUICK_HATCH_TYPE then
  310. local tb = Util.split(param, "|")
  311. local quickType = tonumber(tb[1]) or 0
  312. local cnt = tonumber(tb[2]) or 0
  313. local isHatch = 1
  314. if tb[1] and tb[2] then
  315. -- 初始化
  316. initMergeInfo(human)
  317. -- 剩余时间
  318. local nowTime = os.time()
  319. local hatchTime = human.db.mergeInfo.endTime - nowTime
  320. if hatchTime <= 0
  321. then
  322. Broadcast.sendErr(human, Lang.QUICK_HATCH_TIME_OUT)
  323. return
  324. end
  325. local itemSpeedTime = 0
  326. if quickType == 1 then
  327. local speedTime = (60 * 5 * cnt) -- 正常数量加速券的加速时间
  328. local lastSpeedTime = (60 * 5 * (cnt - 1)) --少一张加速券的加速时间
  329. local itemCnt = 0
  330. if hatchTime > lastSpeedTime and hatchTime <= speedTime then
  331. itemCnt = cnt
  332. elseif hatchTime > 0 and hatchTime <= lastSpeedTime then
  333. itemCnt = cnt - 1
  334. elseif hatchTime >= speedTime then
  335. itemCnt = cnt
  336. else
  337. itemCnt = 0
  338. end
  339. itemSpeedTime = (60 * 5 * itemCnt)
  340. local bagCnt = BagLogic.getItemCnt(human, 179, true)
  341. if bagCnt < itemCnt then
  342. Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
  343. return
  344. end
  345. --使用道具
  346. ItemLogic.use(human, 179, itemCnt)
  347. elseif quickType == 2 then
  348. local zuanshiCnt = doCalcNeedZuanshi(hatchTime)
  349. -- 判断消耗
  350. if not ObjHuman.checkRMB(human, zuanshiCnt) then
  351. return
  352. end
  353. itemSpeedTime = (30 * zuanshiCnt)
  354. -- 扣钻石
  355. ObjHuman.decZuanshi(human, -zuanshiCnt, "hero_merge")
  356. if tb[3] then
  357. human.db.isTip = human.db.isTip or 1
  358. human.db.isTip = tonumber(tb[3])
  359. end
  360. elseif quickType == 3 then
  361. human.db.adHatchRewardCnt = human.db.adHatchRewardCnt or 0
  362. if human.db.adHatchRewardCnt > 4 then
  363. Broadcast.sendErr(human, Lang.AD_DRAW_REWARD_LIMIT_ERROR)
  364. return
  365. end
  366. --加速30分钟
  367. itemSpeedTime = 30 * 60
  368. --增加今日观看次数
  369. human.db.adHatchRewardCnt = (human.db.adHatchRewardCnt or 0) + 1
  370. end
  371. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
  372. local hatchTime = human.db.mergeInfo.endTime - nowTime
  373. -- 孵化成功
  374. if hatchTime < 0 then
  375. hatchTime = 0
  376. isHatch = 3
  377. end
  378. local mergeInfo = {}
  379. local heroSimple = {}
  380. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  381. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  382. heroSimple.name = cf and cf.name or ""
  383. if cf.grade >= 6 then
  384. heroSimple.name = "?????"
  385. end
  386. mergeInfo.mergeTime = hatchTime
  387. mergeInfo.heroData = heroSimple
  388. mergeInfo.xLv = human.db.mergeInfo.heroInfo.xLv
  389. mergeInfo.isHatch = isHatch
  390. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  391. mergeInfo.isTip = getTodayIsTip(human)
  392. msgRet.ret = QUICK_HATCH_TYPE
  393. msgRet.tip = Json.Encode(mergeInfo)
  394. Log.write(Log.LOGID_TEST, "加速孵化 ret: " .. Json.Encode(msgRet))
  395. Msg.send(msgRet, human.fd)
  396. return
  397. end
  398. return
  399. end
  400. end
  401. -- 孵化英雄
  402. function hatchHero(human)
  403. Log.write(Log.LOGID_TEST, "孵化英雄id " .. human.db.mergeInfo.heroInfo.heroID)
  404. --添加英雄
  405. local heroIndex, fjlist = HeroLogic.addHero(human, human.db.mergeInfo.heroInfo.heroID, nil, 1,
  406. "hero_merge")
  407. Log.write(Log.LOGID_TEST, "孵化英雄成功 下标" .. heroIndex)
  408. local attrs = RoleDefine.PANEL_ATTR_KEY
  409. for key, value in pairs(attrs) do
  410. attrs[key] = 1
  411. end
  412. human.db.mergeInfo.startTime = 0
  413. human.db.mergeInfo.endTime = 0
  414. human.db.mergeInfo.heroInfo = {}
  415. human.db.mergeInfo.heroInfo.heroID = 0
  416. human.db.mergeInfo.heroInfo.xLv = 0
  417. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = 0
  418. human.db.mergeInfo.heroInfo.motherHeroBagIndex = 0
  419. human.db.mergeInfo.heroInfo.heroAttrs = attrs
  420. Log.write(Log.LOGID_TEST, "孵化重置 mergeInfo: " .. Json.Encode(human.db.mergeInfo))
  421. return heroIndex
  422. end
  423. -- 初始化融合信息
  424. function initMergeInfo(human)
  425. human.db.mergeInfo = human.db.mergeInfo or {}
  426. human.db.mergeInfo.startTime = human.db.mergeInfo.startTime or 0 --融合时间 时间戳
  427. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime or 0 --孵化时间 单位s
  428. human.db.mergeInfo.heroInfo = human.db.mergeInfo.heroInfo or {}
  429. human.db.mergeInfo.heroInfo.heroID = human.db.mergeInfo.heroInfo.heroID or 0
  430. human.db.mergeInfo.heroInfo.xLv = human.db.mergeInfo.heroInfo.xLv or 0
  431. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = human.db.mergeInfo.heroInfo.fatherHeroBagIndex or 0
  432. human.db.mergeInfo.heroInfo.motherHeroBagIndex = human.db.mergeInfo.heroInfo.motherHeroBagIndex or 0
  433. human.db.mergeInfo.heroInfo.heroAttrs = human.db.mergeInfo.heroInfo.heroAttrs or RoleDefine.PANEL_ATTR_KEY
  434. end
  435. -- 获取孵化时间 单位s
  436. function getHatchTime(xLv)
  437. local time = (xLv * 5) + (xLv - 1) * (xLv - 1) - 5
  438. if time < 0 then
  439. return 0
  440. end
  441. return time * 60
  442. end
  443. -- 计算需要钻石数量
  444. function doCalcNeedZuanshi(hatchTime)
  445. local cnt = 0
  446. if hatchTime > 0 then
  447. cnt = math.ceil(hatchTime / 30)
  448. end
  449. return cnt
  450. end
  451. -- 获取xlv
  452. function getxLv(fatherHeroGrid, motherHeroGrid)
  453. local fatherHeroXLv = fatherHeroGrid.xLv or 0
  454. local motherHeroXLv = motherHeroGrid.xLv or 0
  455. local params1 = math.max(fatherHeroXLv, motherHeroXLv)
  456. local params2 = math.floor((fatherHeroGrid.lv + motherHeroGrid.lv) / 200) + 1
  457. local xLv = params1 + params2
  458. if xLv > 50 then
  459. return 50
  460. end
  461. return xLv
  462. end
  463. -- 融合获取英雄ID
  464. function mergeHero(fatherHeroID, motherHeroID)
  465. local fatherHeroConfig = HeroExcel.hero[fatherHeroID]
  466. local motherHeroConfig = HeroExcel.hero[motherHeroID]
  467. if not fatherHeroConfig or not motherHeroConfig then
  468. return 0
  469. end
  470. --规则3 heroID + heroID
  471. for _, config in pairs(MergeRule[3].items) do
  472. if fatherHeroID == config[1] and motherHeroID == config[2] then
  473. return config[3]
  474. end
  475. end
  476. --规则2 种族 + heroID
  477. for _, config in pairs(MergeRule[2].items) do
  478. if fatherHeroConfig.camp == config[1] and motherHeroID == config[2] then
  479. return config[3]
  480. end
  481. end
  482. --规则1 种族 + 种族
  483. for _, config in pairs(MergeRule[1].items) do
  484. if fatherHeroConfig.camp == config[1] and motherHeroConfig.camp == config[2] then
  485. return config[3]
  486. end
  487. end
  488. return 0
  489. end
  490. -- 获取剩余融化孵化加速广告观看次数
  491. function getResetAdHatchCnt(human)
  492. local adHatchRewardCnt = human.db.adHatchRewardCnt or 0
  493. return math.max(AD_HATCH_RESET_FREECNT - adHatchRewardCnt, 0)
  494. end
  495. -- 获取是否今日不再提示
  496. function getTodayIsTip(human)
  497. local isTip = human.db.isTip or 1
  498. return tonumber(isTip)
  499. end