NewLogic.lua 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  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. local PaomaExcel = require("excel.paoma")
  21. local HeroDefine = require("hero.HeroDefine")
  22. local SkinLogic = require("skin.SkinLogic")
  23. local XingYaoGongMing = require("xingYaoMen.XingYaoGongMing")
  24. local SkillExcel = require("excel.skill")
  25. local BufferExcel = require("excel.buffer")
  26. AD_DRAW_REWARD_TYPE = 10 --观看广告领取召唤券
  27. QUERY_MERGE_INFO_TYPE = 11 --获取融合信息
  28. HATCH_SCCUESS_TYPE = 12 -- 孵化成功
  29. MERGE_HERO_TYPE = 13 --融合
  30. QUICK_HATCH_TYPE = 14 --加速
  31. QUERY_MERGE_BEFORE_INFO_TYPE = 15 --获取融合前信息
  32. GET_MERGE_HERO_TYPE = 16 --获取融合英雄
  33. QUERY_QUICK_HATCH_ZUANSHI = 17 --查询加速孵化需要的钻石
  34. AD_HATCH_RESET_FREECNT = 4 --看广告加速孵化次数
  35. function NewProto(human, type, param)
  36. -- print("newProto:",type,param)
  37. -- local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  38. -- msgRet.ret = type
  39. -- msgRet.tip = "test data"
  40. -- Msg.send(msgRet,human.fd)
  41. local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  42. -- 观看广告获取召唤券
  43. if type == AD_DRAW_REWARD_TYPE then
  44. human.db.adRewardCnt = human.db.adRewardCnt or 0
  45. if human.db.adRewardCnt > 4 then
  46. Broadcast.sendErr(human, Lang.AD_DRAW_REWARD_LIMIT_ERROR)
  47. return
  48. end
  49. --增加今日观看次数
  50. human.db.adRewardCnt = (human.db.adRewardCnt or 0) + 1
  51. Log.write(Log.LOGID_TEST, "adRewardCnt: " .. human.db.adRewardCnt)
  52. -- 添加高级召唤卷
  53. BagLogic.addItem(human, 118, 1, "draw_ad_reward")
  54. msgRet.ret = AD_DRAW_REWARD_TYPE
  55. msgRet.tip = Lang.AD_DRAW_REWARD_SUCCESS
  56. Msg.send(msgRet, human.fd)
  57. return
  58. end
  59. -- 查询加速孵化需要的钻石
  60. if type == QUERY_QUICK_HATCH_ZUANSHI then
  61. -- 初始化
  62. initMergeInfo(human)
  63. local info = {}
  64. local nowTime = os.time
  65. local hatchTime = human.db.mergeInfo.endTime - nowTime
  66. info.zuanshi = doCalcNeedZuanshi(hatchTime)
  67. info.isTip = getTodayIsTip(human)
  68. msgRet.ret = QUERY_QUICK_HATCH_ZUANSHI
  69. msgRet.tip = Json.Encode(info)
  70. Msg.send(msgRet, human.fd)
  71. return
  72. end
  73. -- 获取融合前的信息
  74. if type == QUERY_MERGE_BEFORE_INFO_TYPE then
  75. local tb = Util.split(param, "|")
  76. if tb[1] and tb[2] then
  77. -- 初始化
  78. initMergeInfo(human)
  79. human.db.heroBag = human.db.heroBag or {}
  80. local fatherHeroBagIndex = tonumber(tb[1]) or 0
  81. local motherHeroBagIndex = tonumber(tb[2]) or 0
  82. Log.write(Log.LOGID_TEST, "查询融合前的 fatherHeroBagIndex: " .. fatherHeroBagIndex)
  83. Log.write(Log.LOGID_TEST, "查询融合前的 motherHeroBagIndex: " .. motherHeroBagIndex)
  84. local fatherHeroGrid = human.db.heroBag[fatherHeroBagIndex]
  85. if not fatherHeroGrid then
  86. Log.write(Log.LOGID_TEST, "查询融合前的 fatherHeroGrid: 不存在下标:" .. fatherHeroBagIndex)
  87. return
  88. end
  89. Log.write(Log.LOGID_TEST, "查询融合前的 fatherHeroGrid: " .. Json.Encode(fatherHeroGrid))
  90. local motherHeroGrid = human.db.heroBag[motherHeroBagIndex]
  91. if not motherHeroGrid then
  92. Log.write(Log.LOGID_TEST, "查询融合前的 motherHeroGrid: 不存在下标:" .. motherHeroBagIndex)
  93. return
  94. end
  95. Log.write(Log.LOGID_TEST, "查询融合前的 motherHeroGrid: " .. Json.Encode(motherHeroGrid))
  96. local mergeInfo = {}
  97. local heroSimple = {}
  98. local xLv = getxLv(fatherHeroGrid, motherHeroGrid)
  99. local cnt = math.floor(xLv / 2) + 1
  100. local isHatch = 2
  101. local mergeItem = {}
  102. local itemId = 178
  103. for k = 1, 1 do
  104. mergeItem[k] = mergeItem[k] or {}
  105. mergeItem[k].getway = mergeItem[k].getway or {}
  106. mergeItem[k].suipian = mergeItem[k].suipian or {}
  107. mergeItem[k].equip = mergeItem[k].equip or {}
  108. mergeItem[k].fuwen = mergeItem[k].fuwen or {}
  109. Grid.makeItem(mergeItem[k], itemId, cnt)
  110. end
  111. local sonHeroID = mergeHero(fatherHeroGrid.id, motherHeroGrid.id)
  112. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  113. heroSimple.name = cf and cf.name or ""
  114. if cf.grade >= 6 then
  115. heroSimple.name = "?????"
  116. end
  117. mergeInfo.mergeTime = 0
  118. mergeInfo.xLv = xLv
  119. mergeInfo.mergeItem = mergeItem
  120. mergeInfo.heroData = heroSimple
  121. mergeInfo.isHatch = isHatch
  122. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  123. mergeInfo.isTip = getTodayIsTip(human)
  124. Log.write(Log.LOGID_TEST, "查询融合前的 mergeInfo: " .. Json.Encode(mergeInfo))
  125. msgRet.ret = QUERY_MERGE_BEFORE_INFO_TYPE
  126. msgRet.tip = Json.Encode(mergeInfo)
  127. Msg.send(msgRet, human.fd)
  128. end
  129. return
  130. end
  131. -- 开始融合
  132. if type == MERGE_HERO_TYPE then
  133. local tb = Util.split(param, "|")
  134. if tb[1] and tb[2] then
  135. -- 初始化
  136. initMergeInfo(human)
  137. human.db.heroBag = human.db.heroBag or {}
  138. Log.write(Log.LOGID_TEST, "融合 human.db.heroBag: " .. Json.Encode(human.db.heroBag))
  139. local itemId = 178 --生命雨露
  140. local fatherHeroBagIndex = tonumber(tb[1]) or 0
  141. local motherHeroBagIndex = tonumber(tb[2]) or 0
  142. Log.write(Log.LOGID_TEST, "融合 fatherHeroBagIndex: " .. fatherHeroBagIndex)
  143. Log.write(Log.LOGID_TEST, "融合 motherHeroBagIndex: " .. motherHeroBagIndex)
  144. local fatherHeroGrid = human.db.heroBag[fatherHeroBagIndex]
  145. if not fatherHeroGrid then
  146. return
  147. end
  148. Log.write(Log.LOGID_TEST, "融合 fatherHeroGrid: " .. Json.Encode(fatherHeroGrid))
  149. local motherHeroGrid = human.db.heroBag[motherHeroBagIndex]
  150. if not motherHeroGrid then
  151. return
  152. end
  153. Log.write(Log.LOGID_TEST, "融合 motherHeroGrid: " .. Json.Encode(motherHeroGrid))
  154. local fatherHeroAttr = ObjHuman.getHeroAttrs(human, fatherHeroBagIndex)
  155. local motherHeroAttr = ObjHuman.getHeroAttrs(human, motherHeroBagIndex)
  156. local mergeInfo = {}
  157. local attrs = RoleDefine.PANEL_ATTR_KEY
  158. local sonHeroID = mergeHero(fatherHeroGrid.id, motherHeroGrid.id)
  159. if sonHeroID <= 0 then
  160. return
  161. end
  162. for key, value in pairs(attrs) do
  163. local param1 = fatherHeroAttr[key] or 0
  164. local param2 = motherHeroAttr[key] or 0
  165. attrs[key] = math.floor(((param1 + param2) / 4))
  166. end
  167. Log.write(Log.LOGID_TEST, "融合后的属性: " .. Json.Encode(attrs))
  168. local xLv = getxLv(fatherHeroGrid, motherHeroGrid)
  169. local cnt = math.floor(xLv / 2) + 1
  170. local heroSimple = {}
  171. local isHatch = 1
  172. Log.write(Log.LOGID_TEST, "xLv: " .. xLv)
  173. Log.write(Log.LOGID_TEST, "cnt: " .. cnt)
  174. local bagCnt = BagLogic.getItemCnt(human, itemId, true)
  175. if bagCnt < cnt then
  176. Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
  177. return
  178. end
  179. --使用道具
  180. ItemLogic.use(human, itemId, cnt)
  181. local delHeroList = { [1] = fatherHeroBagIndex, [2] = motherHeroBagIndex }
  182. for key, heroIndex in pairs(delHeroList) do
  183. local heroID = HeroLogic.getHeroIdByIndex(human, heroIndex)
  184. HeroEquip.putOffQuick(human, heroID, heroIndex, true)
  185. FuwenLogic.putOffQuick(human, heroID, heroIndex, true)
  186. HeroLogic.delHeroByIndex(human, heroIndex, "hero_merge")
  187. end
  188. -- 记录融合英雄
  189. human.db.mergeInfo.heroInfo.heroID = sonHeroID
  190. human.db.mergeInfo.heroInfo.xLv = xLv
  191. human.db.mergeInfo.heroInfo.heroAttrs = attrs
  192. human.db.mergeInfo.startTime = os.time()
  193. human.db.mergeInfo.endTime = os.time() + getHatchTime(xLv)
  194. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = fatherHeroBagIndex
  195. human.db.mergeInfo.heroInfo.motherHeroBagIndex = motherHeroBagIndex
  196. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  197. heroSimple.name = cf and cf.name or ""
  198. if cf.grade >= 6 then
  199. heroSimple.name = "?????"
  200. end
  201. if getHatchTime(xLv) == 0 then
  202. isHatch = 3
  203. end
  204. mergeInfo.mergeTime = getHatchTime(xLv)
  205. mergeInfo.xLv = xLv
  206. mergeInfo.heroData = heroSimple
  207. mergeInfo.isHatch = isHatch
  208. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  209. mergeInfo.isTip = getTodayIsTip(human)
  210. Log.write(Log.LOGID_TEST, "融合 mergeInfo: " .. Json.Encode(mergeInfo))
  211. Broadcast.sendErr(human, Lang.MERGE_SUCCESS)
  212. msgRet.ret = MERGE_HERO_TYPE
  213. msgRet.tip = Json.Encode(mergeInfo)
  214. Msg.send(msgRet, human.fd)
  215. end
  216. return
  217. end
  218. -- 获取融合中的信息
  219. if type == QUERY_MERGE_INFO_TYPE then
  220. -- 初始化
  221. initMergeInfo(human)
  222. human.db.heroBag = human.db.heroBag or {}
  223. local mergeInfo = {}
  224. local mergeTime = 0
  225. local heroSimple = {}
  226. local xLv = human.db.mergeInfo.heroInfo.xLv or 0
  227. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  228. local isHatch = 2
  229. if sonHeroID == 0 then
  230. mergeInfo.mergeTime = mergeTime
  231. mergeInfo.xLv = xLv
  232. mergeInfo.heroData = heroSimple
  233. mergeInfo.isHatch = isHatch
  234. msgRet.ret = QUERY_MERGE_INFO_TYPE
  235. msgRet.tip = Json.Encode(mergeInfo)
  236. Msg.send(msgRet, human.fd)
  237. return
  238. end
  239. local mergeTime = human.db.mergeInfo.endTime - os.time()
  240. if mergeTime <= 0 then
  241. -- 孵化成功
  242. mergeTime = 0
  243. isHatch = 3
  244. else
  245. isHatch = 1
  246. end
  247. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  248. heroSimple.name = cf and cf.name or ""
  249. if cf.grade >= 6 then
  250. heroSimple.name = "?????"
  251. end
  252. mergeInfo.mergeTime = mergeTime
  253. mergeInfo.xLv = xLv
  254. mergeInfo.heroData = heroSimple
  255. mergeInfo.isHatch = isHatch
  256. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  257. mergeInfo.isTip = getTodayIsTip(human)
  258. msgRet.ret = QUERY_MERGE_INFO_TYPE
  259. msgRet.tip = Json.Encode(mergeInfo)
  260. Log.write(Log.LOGID_TEST, "融合中 msgRet: " .. Json.Encode(msgRet))
  261. Msg.send(msgRet, human.fd)
  262. return
  263. end
  264. -- 获取融合英雄
  265. if type == GET_MERGE_HERO_TYPE then
  266. local nowTime = os.time()
  267. local mergeInfo = {}
  268. local heroSimple = {}
  269. local xLv = human.db.mergeInfo.heroInfo.xLv or 0
  270. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  271. local hatchTime = human.db.mergeInfo.endTime - nowTime
  272. local isHatch = 2
  273. local heroIndex = 0
  274. local msgTyep = GET_MERGE_HERO_TYPE
  275. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  276. local heroNiceNet = {}
  277. if hatchTime <= 0 then
  278. -- 孵化成功
  279. hatchTime = 0
  280. heroIndex = hatchHero(human)
  281. local heroGrid = human.db.heroBag[heroIndex]
  282. if not heroGrid then return end
  283. heroSimple.general = heroSimple.general or {}
  284. HeroGrid.makeHeroSimple(heroSimple, heroGrid, heroIndex, human)
  285. local heroID = heroGrid.id or 0
  286. local isNew = not HeroBook.isGet(human, cf.id, cf.star)
  287. makeHeroNice(heroNiceNet, heroID, nil, isNew, heroIndex)
  288. else
  289. heroSimple.name = cf and cf.name or ""
  290. if cf.grade >= 6 then
  291. heroSimple.name = "?????"
  292. end
  293. isHatch = 1
  294. msgTyep = QUERY_MERGE_INFO_TYPE
  295. end
  296. mergeInfo.mergeTime = hatchTime
  297. mergeInfo.xLv = xLv
  298. mergeInfo.heroData = heroSimple
  299. mergeInfo.isHatch = isHatch
  300. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  301. mergeInfo.isTip = getTodayIsTip(human)
  302. mergeInfo.heroNiceNet = heroNiceNet
  303. msgRet.ret = msgTyep
  304. msgRet.tip = Json.Encode(mergeInfo)
  305. Log.write(Log.LOGID_TEST, "获取英雄 ret: " .. Json.Encode(msgRet))
  306. Msg.send(msgRet, human.fd)
  307. return
  308. end
  309. -- 加速孵化
  310. if type == QUICK_HATCH_TYPE then
  311. local tb = Util.split(param, "|")
  312. local quickType = tonumber(tb[1]) or 0
  313. local cnt = tonumber(tb[2]) or 0
  314. local isHatch = 1
  315. if tb[1] and tb[2] then
  316. -- 初始化
  317. initMergeInfo(human)
  318. -- 剩余时间
  319. local nowTime = os.time()
  320. local hatchTime = human.db.mergeInfo.endTime - nowTime
  321. if hatchTime <= 0
  322. then
  323. Broadcast.sendErr(human, Lang.QUICK_HATCH_TIME_OUT)
  324. return
  325. end
  326. local itemSpeedTime = 0
  327. if quickType == 1 then
  328. local speedTime = (60 * 5 * cnt) -- 正常数量加速券的加速时间
  329. local lastSpeedTime = (60 * 5 * (cnt - 1)) --少一张加速券的加速时间
  330. local itemCnt = 0
  331. if hatchTime > lastSpeedTime and hatchTime <= speedTime then
  332. itemCnt = cnt
  333. elseif hatchTime > 0 and hatchTime <= lastSpeedTime then
  334. itemCnt = cnt - 1
  335. elseif hatchTime >= speedTime then
  336. itemCnt = cnt
  337. else
  338. itemCnt = 0
  339. end
  340. itemSpeedTime = (60 * 5 * itemCnt)
  341. local bagCnt = BagLogic.getItemCnt(human, 179, true)
  342. if bagCnt < itemCnt then
  343. Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
  344. return
  345. end
  346. --使用道具
  347. ItemLogic.use(human, 179, itemCnt)
  348. elseif quickType == 2 then
  349. local zuanshiCnt = doCalcNeedZuanshi(hatchTime)
  350. -- 判断消耗
  351. if not ObjHuman.checkRMB(human, zuanshiCnt) then
  352. return
  353. end
  354. itemSpeedTime = (30 * zuanshiCnt)
  355. -- 扣钻石
  356. ObjHuman.decZuanshi(human, -zuanshiCnt, "hero_merge")
  357. if tb[3] then
  358. human.db.isTip = human.db.isTip or 1
  359. human.db.isTip = tonumber(tb[3])
  360. end
  361. elseif quickType == 3 then
  362. human.db.adHatchRewardCnt = human.db.adHatchRewardCnt or 0
  363. if human.db.adHatchRewardCnt > 4 then
  364. Broadcast.sendErr(human, Lang.AD_HATCH_REWARD_LIMIT_ERROR)
  365. return
  366. end
  367. --加速30分钟
  368. itemSpeedTime = 30 * 60
  369. --增加今日观看次数
  370. human.db.adHatchRewardCnt = (human.db.adHatchRewardCnt or 0) + 1
  371. end
  372. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
  373. local hatchTime = human.db.mergeInfo.endTime - nowTime
  374. -- 孵化成功
  375. if hatchTime < 0 then
  376. hatchTime = 0
  377. isHatch = 3
  378. end
  379. local mergeInfo = {}
  380. local heroSimple = {}
  381. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  382. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  383. heroSimple.name = cf and cf.name or ""
  384. if cf.grade >= 6 then
  385. heroSimple.name = "?????"
  386. end
  387. mergeInfo.mergeTime = hatchTime
  388. mergeInfo.heroData = heroSimple
  389. mergeInfo.xLv = human.db.mergeInfo.heroInfo.xLv
  390. mergeInfo.isHatch = isHatch
  391. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  392. mergeInfo.isTip = getTodayIsTip(human)
  393. msgRet.ret = QUICK_HATCH_TYPE
  394. msgRet.tip = Json.Encode(mergeInfo)
  395. Log.write(Log.LOGID_TEST, "加速孵化 ret: " .. Json.Encode(msgRet))
  396. Msg.send(msgRet, human.fd)
  397. return
  398. end
  399. return
  400. end
  401. end
  402. -- 孵化英雄
  403. function hatchHero(human)
  404. Log.write(Log.LOGID_TEST, "孵化英雄id " .. human.db.mergeInfo.heroInfo.heroID)
  405. --添加英雄
  406. local heroIndex, fjlist = HeroLogic.addHero(human, human.db.mergeInfo.heroInfo.heroID, nil, 1,
  407. "hero_merge")
  408. Log.write(Log.LOGID_TEST, "孵化英雄成功 下标" .. heroIndex)
  409. local attrs = RoleDefine.PANEL_ATTR_KEY
  410. for key, value in pairs(attrs) do
  411. attrs[key] = 1
  412. end
  413. human.db.mergeInfo.startTime = 0
  414. human.db.mergeInfo.endTime = 0
  415. human.db.mergeInfo.heroInfo = {}
  416. human.db.mergeInfo.heroInfo.heroID = 0
  417. human.db.mergeInfo.heroInfo.xLv = 0
  418. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = 0
  419. human.db.mergeInfo.heroInfo.motherHeroBagIndex = 0
  420. human.db.mergeInfo.heroInfo.heroAttrs = attrs
  421. Log.write(Log.LOGID_TEST, "孵化重置 mergeInfo: " .. Json.Encode(human.db.mergeInfo))
  422. return heroIndex
  423. end
  424. -- 初始化融合信息
  425. function initMergeInfo(human)
  426. human.db.mergeInfo = human.db.mergeInfo or {}
  427. human.db.mergeInfo.startTime = human.db.mergeInfo.startTime or 0 --融合时间 时间戳
  428. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime or 0 --孵化时间 单位s
  429. human.db.mergeInfo.heroInfo = human.db.mergeInfo.heroInfo or {}
  430. human.db.mergeInfo.heroInfo.heroID = human.db.mergeInfo.heroInfo.heroID or 0
  431. human.db.mergeInfo.heroInfo.xLv = human.db.mergeInfo.heroInfo.xLv or 0
  432. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = human.db.mergeInfo.heroInfo.fatherHeroBagIndex or 0
  433. human.db.mergeInfo.heroInfo.motherHeroBagIndex = human.db.mergeInfo.heroInfo.motherHeroBagIndex or 0
  434. human.db.mergeInfo.heroInfo.heroAttrs = human.db.mergeInfo.heroInfo.heroAttrs or RoleDefine.PANEL_ATTR_KEY
  435. end
  436. -- 获取孵化时间 单位s
  437. function getHatchTime(xLv)
  438. local time = (xLv * 5) + (xLv - 1) * (xLv - 1) - 5
  439. if time < 0 then
  440. return 0
  441. end
  442. return time * 60
  443. end
  444. -- 计算需要钻石数量
  445. function doCalcNeedZuanshi(hatchTime)
  446. local cnt = 0
  447. if hatchTime > 0 then
  448. cnt = math.ceil(hatchTime / 30)
  449. end
  450. return cnt
  451. end
  452. -- 获取xlv
  453. function getxLv(fatherHeroGrid, motherHeroGrid)
  454. local fatherHeroXLv = fatherHeroGrid.xLv or 0
  455. local motherHeroXLv = motherHeroGrid.xLv or 0
  456. local params1 = math.max(fatherHeroXLv, motherHeroXLv)
  457. local params2 = math.floor((fatherHeroGrid.lv + motherHeroGrid.lv) / 200) + 1
  458. local xLv = params1 + params2
  459. if xLv > 50 then
  460. return 50
  461. end
  462. return xLv
  463. end
  464. -- 融合获取英雄ID
  465. function mergeHero(fatherHeroID, motherHeroID)
  466. local fatherHeroConfig = HeroExcel.hero[fatherHeroID]
  467. local motherHeroConfig = HeroExcel.hero[motherHeroID]
  468. if not fatherHeroConfig or not motherHeroConfig then
  469. return 0
  470. end
  471. --规则3 heroID + heroID
  472. for _, config in pairs(MergeRule[3].items) do
  473. if fatherHeroID == config[1] and motherHeroID == config[2] then
  474. return config[3]
  475. end
  476. end
  477. --规则2 种族 + heroID
  478. for _, config in pairs(MergeRule[2].items) do
  479. if fatherHeroConfig.camp == config[1] and motherHeroID == config[2] then
  480. return config[3]
  481. end
  482. end
  483. --规则1 种族 + 种族
  484. for _, config in pairs(MergeRule[1].items) do
  485. if fatherHeroConfig.camp == config[1] and motherHeroConfig.camp == config[2] then
  486. return config[3]
  487. end
  488. end
  489. return 0
  490. end
  491. -- 获取剩余融化孵化加速广告观看次数
  492. function getResetAdHatchCnt(human)
  493. local adHatchRewardCnt = human.db.adHatchRewardCnt or 0
  494. return math.max(AD_HATCH_RESET_FREECNT - adHatchRewardCnt, 0)
  495. end
  496. -- 获取是否今日不再提示
  497. function getTodayIsTip(human)
  498. local isTip = human.db.isTip or 1
  499. return tonumber(isTip)
  500. end
  501. -- 封装客户端需要的json格式
  502. function makeHeroNice(net, id, cnt, isNew, index)
  503. net.heroSimple = net.heroSimple or {}
  504. net.itemData = net.itemData or {}
  505. net.heroStatic = net.heroStatic or {}
  506. net.attrs = net.attrs or {}
  507. net.attrsMax = net.attrsMax or {}
  508. if cnt then
  509. net.itemData[1] = net.itemData[1] or {}
  510. Grid.makeItem(net.itemData[1], id, cnt)
  511. end
  512. local heroConfig = HeroExcel.hero[id]
  513. local specialConfig = HeroExcel.specialHero[id]
  514. if heroConfig then
  515. net.heroSimple[1] = net.heroSimple[1] or {}
  516. net.heroStatic[1] = net.heroStatic[1] or {}
  517. makeHeroSimpleByID(net.heroSimple[1], id, index)
  518. makeHeroStatic(net.heroStatic[1], id)
  519. end
  520. net.body = specialConfig and (heroConfig and heroConfig.body or 0) or 0
  521. net.isNew = isNew and 1 or 0
  522. net.weightLv = heroConfig and heroConfig.grade or 0
  523. net.bubble = ""
  524. local attrsNum = 0
  525. local attrsMaxNum = 0
  526. if heroConfig then
  527. local bubble = PaomaExcel.bubble[heroConfig.id]
  528. net.bubble = bubble and bubble.drawCard or ""
  529. local heroGrid = HeroGrid.getCacheHeroGridTujian(id)
  530. for key = RoleDefine.ATK, RoleDefine.SPEED do
  531. local value = heroGrid.attrs[key]
  532. attrsNum = attrsNum + 1
  533. net.attrs[attrsNum] = net.attrs[attrsNum] or {}
  534. net.attrs[attrsNum].key = key
  535. net.attrs[attrsNum].value = value
  536. attrsMaxNum = attrsMaxNum + 1
  537. net.attrsMax[attrsMaxNum] = net.attrs[attrsMaxNum] or {}
  538. net.attrsMax[attrsMaxNum].key = key
  539. net.attrsMax[attrsMaxNum].value = HeroDefine.getTujianMaxValue(key)
  540. end
  541. end
  542. end
  543. -- 根据英雄id封装英雄信息heroSimple 额外处理
  544. function makeHeroSimpleByID(net, id, index, others, human, tujian)
  545. local star = others and others.star or nil
  546. local grid = HeroGrid.getCacheHeroGrid(id, star, others)
  547. makeHeroSimple(net, grid, index, human, others, tujian)
  548. end
  549. -- 填充英雄详细信息:静态 额外格式
  550. function makeHeroStatic(net, id, tuJian)
  551. net.skillList = net.skillList or {}
  552. net.beSkill = net.beSkill or {}
  553. local cf = id and HeroExcel.hero[id]
  554. if not cf then
  555. net.id = 0
  556. net.name = ""
  557. net.body = 0
  558. net.job = 0
  559. net.weightLv = 0
  560. net.normalAtkID = 0
  561. net.skillList[0] = 0
  562. net.beSkill[0] = 0
  563. net.skin = 0
  564. return
  565. end
  566. local star = cf.star
  567. if tuJian and tuJian == 1 then
  568. local tuJianConfig = HeroExcel.tujian[id]
  569. if tuJianConfig then
  570. local maxStarIndex = #tuJianConfig.star
  571. star = tuJianConfig.star[maxStarIndex]
  572. end
  573. end
  574. net.id = id
  575. net.name = cf.name
  576. net.body = cf.body
  577. net.job = cf.job
  578. net.weightLv = cf.grade
  579. local attrConfig = HeroDefine.getAttrConfig(id, star)
  580. net.normalAtkID = attrConfig.normalAtkID
  581. for i = 1, #attrConfig.skillList do
  582. net.skillList[i] = net.skillList[i] or {}
  583. makeSkillNet(net.skillList[i], attrConfig.skillList[i])
  584. end
  585. for i = 1, #attrConfig.beSkillList do
  586. net.beSkill[i] = net.beSkill[i] or {}
  587. makeSkillNet(net.beSkill[i], attrConfig.beSkillList[i])
  588. end
  589. net.skin = #cf.skin > 0 and 1 or 0
  590. end
  591. -- 封装英雄信息 额外处理
  592. function makeHeroSimple(net, grid, index, human, others, tuJian)
  593. local id = grid and (grid.id or grid.heroID)
  594. local cf = id and HeroExcel.hero[id]
  595. local star = grid and grid.star or (cf and cf.star or 1)
  596. local upStarConfig = HeroDefine.getNextAttrConfig(id, star)
  597. local jobConfig = cf and cf.job and HeroExcel.job[cf.job]
  598. local isGongMing = XingYaoGongMing.isGongMing(human, index)
  599. net.id = id or 0
  600. net.index = index or 0
  601. net.uuid = grid and grid.uuid or ""
  602. net.gl = cf and cf.gl or 0
  603. net.camp = cf and cf.camp or 0
  604. net.job = cf and cf.job or 0
  605. net.star = others and others.star or star --cf and cf.star or 0 星级调整 dxzeng
  606. net.icon = grid and grid.head or (cf and cf.head or 0)
  607. net.body = grid and grid.body or (cf and cf.body or 0)
  608. if grid and human and index then -- todo 皮肤这个以后可能还是需要继续整理
  609. local skinConf = SkinLogic.getHeroSkin(human, index)
  610. if skinConf then
  611. net.icon = skinConf.head
  612. net.body = skinConf.body
  613. end
  614. end
  615. net.up = upStarConfig == nil and 0 or 1 --是否能够升星
  616. net.lv = others and others.lv or (grid and grid.lv or 1)
  617. net.xLv = others and others.xLv or (grid and grid.xLv or 0)
  618. net.zhandouli = grid and grid.zhandouli or 0
  619. net.quality = grid and grid.quality or 0
  620. net.isLock = (grid and grid.isLock) and 1 or 0
  621. net.hp = others and others.hp or 0
  622. net.hpMax = others and others.hpMax or 0
  623. net.cnt = others and others.cnt or 1
  624. net.isget = HeroBook.isGetHero(human, id) or 0
  625. net.weightLv = cf and cf.grade or 0
  626. net.name = cf and cf.name or ""
  627. net.grade = cf and cf.grade or 0
  628. net.jobDesc = jobConfig and jobConfig.desc or ""
  629. net.label = cf and cf.label or ""
  630. net.order = cf and cf.order or 0
  631. net.isGongMing = isGongMing or 0
  632. net.general = net.general or {}
  633. --是否发送图鉴信息
  634. if tuJian then
  635. local tj = HeroExcel.tujian[id]
  636. if tj ~= nil then
  637. net.general[1] = net.general[1] or {}
  638. net.general[1].cm = tj.cm or 0
  639. net.general[1].kg = tj.kg or 0
  640. net.general[1].age = tj.age or 0
  641. net.general[1].cup = tj.cup or ""
  642. net.general[1].character = tj.character or ""
  643. net.general[1].interest = tj.interest or ""
  644. net.general[1].desc = tj.desc or ""
  645. end
  646. end
  647. end
  648. -- 获取技能信息
  649. function makeSkillNet(net, id)
  650. local skillConfig = SkillExcel.skill[id]
  651. if not skillConfig then return end
  652. net.id = id
  653. net.icon = skillConfig.icon
  654. net.name = skillConfig.name
  655. net.type = skillConfig.type
  656. net.desc = skillConfig.desc
  657. net.need = skillConfig.need or 0
  658. net.lv = skillConfig.skillLv or 0
  659. -- todo
  660. net.cd = net.cd or {}
  661. net.buff = net.buff or {}
  662. if #skillConfig.cd ~= 0 then
  663. net.cd[1] = net.cd[1] or {}
  664. net.cd[2] = net.cd[2] or {}
  665. net.cd[1] = skillConfig.cd[1]
  666. net.cd[2] = skillConfig.cd[2]
  667. end
  668. local len = #skillConfig.buffers
  669. for i = 1, len do
  670. local buffId = skillConfig.buffers[i][1]
  671. local buffConfig = BufferExcel.buffer[buffId]
  672. net.buff[i] = net.buff[i] or {}
  673. net.buff[i].id = buffId
  674. net.buff[i].name = buffConfig.name
  675. net.buff[i].desc = buffConfig.desc
  676. end
  677. net.lvUpDesc = skillConfig.lvUpDesc
  678. -- todo
  679. end