NewLogic.lua 30 KB

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