NewLogic.lua 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  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. --[[
  37. BuyItem = {
  38. buyID : number -- buy配置表id
  39. region : string -- 区域 默认cn
  40. cost : number -- 价格
  41. icon : number -- 图标
  42. name : string -- 名称
  43. desc : string -- 描述
  44. zhekou : number -- 折扣价
  45. yuanjia : number -- 原价
  46. ttl : number -- 有效期
  47. }
  48. Item = {
  49. id : number
  50. count : number
  51. }
  52. Gift = {
  53. id : number -- 礼包ID
  54. startTimeStamp : number -- 开启时间戳(秒)
  55. restTime : number -- 剩余时间(秒)
  56. buyItem : Buyitem -- 礼包信息
  57. content : {item} -- 礼包内容
  58. }
  59. attr = {
  60. key = number, --属性类型
  61. value = number, -- 属性值
  62. }
  63. SkinData = {
  64. id = number -- 皮肤id
  65. attrs = [attr]array
  66. }
  67. IconFrame = {
  68. id = number -- 头像框id
  69. desc = string
  70. keepTime = number
  71. name = string
  72. camp = number
  73. attrs = [attr]array
  74. }
  75. Skin = {
  76. id : number -- 皮肤配置ID
  77. buyItem : Buyitem -- 皮肤信息
  78. skinData :SkinData -- 皮肤内容
  79. Iconframe : IconFrame -- 头像框内容
  80. }
  81. ]]
  82. ------------------------------- CG请求 -------------------------------
  83. --[[
  84. CG_WARORDER_INFO = {
  85. orderType = number -- 战令类型 1 勇士之证 2 恶魔之证 3 工会之证明 4 竞技之证
  86. }
  87. ]]
  88. local CG_WARORDER_INFO = 101 -- 战令信息请求
  89. --[[
  90. orderType = number -- 战令类型
  91. ]]
  92. local CG_WARORDER_REWARD = 102 -- 战令获取奖励
  93. --[[
  94. panelId = number -- panelID
  95. ]]
  96. local CG_SKIN_QUREY = 103 -- 皮肤活动详情查询
  97. ------------------------------- GC推送 -------------------------------
  98. --[[
  99. GC_GIFT_GENERATE = {
  100. gift = Gift
  101. }
  102. ]]
  103. local GC_GIFT_GENERATE = 10 -- 新增礼包推送
  104. --[[
  105. GC_QUERY_GIFT = {
  106. list = {Gift}
  107. }
  108. ]]
  109. local GC_QUERY_GIFT = 11 -- 登录推送礼包数据
  110. --[[
  111. BuyItem = {
  112. BuyItem = {
  113. {"buyID", 1, "int"}, -- 支付ID
  114. {"region", 1, "string"}, -- 货币类型 CN/HK等
  115. {"cost", 1, "double"}, -- 价格 当前价格
  116. {"icon", 1, "int"}, -- 图标
  117. {"name", 1, "string"}, -- 名称
  118. {"desc", 1, "string"}, -- 描述
  119. {"isFirst", 1, "byte"}, -- 是否首次购买
  120. {"doubleCnt", 1, "byte"}, -- 双倍次数
  121. {"actDoubleCnt",1, "byte"}, -- 活动双倍次数
  122. {"useDoubleCnt",1, "int"}, -- 当前消耗双倍次数
  123. {"buyCnt", 1, "int"}, -- 当前购买次数
  124. {"vipExp", 1, "int"}, -- 附赠vip经验
  125. {"zhekou", 1, "int"}, -- 折扣
  126. {"yuanjia", 1, "int"}, -- 原价
  127. }
  128. }
  129. normal = {
  130. idx number 等级
  131. process number 等级对应所需进度
  132. content [ItemGrid]array 普通战令等级奖励
  133. upgradeContent [ItemGrid]array 升级战令等级奖励
  134. }
  135. GC_WARORDER_INFO = {
  136. orderType = orderType, -- 战令类型
  137. normal = [normal]array, -- 普通配置
  138. language = string
  139. buyItem = BuyItem, -- 战令商品信息
  140. -- 自身的进度
  141. exp = orderData.exp, -- 当前经验
  142. unlock = orderData.unlock, -- 是否解锁升级版 0 表示未解锁 1 表示解锁
  143. finish = [number]array, -- 已经完成的普通版等级
  144. upgradeFinish = [number]array, -- 已经完成的升级版等级
  145. }
  146. ]]
  147. local GC_WARORDER_INFO = 52 -- 战令信息推送
  148. --[[
  149. GC_WARORDER_CHANGE = {
  150. orderType = number -- 战令类型
  151. exp = number -- 战令经验
  152. unlock = number -- 是否解锁升级版 0 表示未解锁 1 表示解锁
  153. finish = [number]array -- idx数组
  154. upgradeFinish = [number]array -- idx数组
  155. isRed = number -- 是否红点
  156. }
  157. ]]
  158. local GC_WARORDER_CHANGE = 53 -- 战令数据推送
  159. --[[
  160. GC_SKIN_QUERY = {
  161. list = [skin]array -- 皮肤活动详情列表
  162. }
  163. ]]
  164. local GC_SKIN_QUERY = 54 -- 皮肤活动详情推送
  165. -----------------------------------------------------------------------
  166. local push = {
  167. [GC_GIFT_GENERATE] = true,
  168. [GC_QUERY_GIFT] = true,
  169. [GC_WARORDER_INFO] = true,
  170. [GC_WARORDER_CHANGE] = true,
  171. [GC_SKIN_QUERY] = true
  172. }
  173. local handler = {
  174. [CG_WARORDER_INFO] = function(human,param)
  175. local orderType = assert(tonumber(param),"invalid param")
  176. local data = WarOrder.warOrderInfo(human,orderType)
  177. if not data then
  178. -- 参数错误,报错
  179. return
  180. end
  181. PushClient(human,GC_WARORDER_INFO,data)
  182. end,
  183. [CG_WARORDER_REWARD] = function(human,param)
  184. local orderType = assert(tonumber(param),"invalid param")
  185. local data = WarOrder.warOrderReward(human,orderType)
  186. if not data then
  187. -- 参数错误,报错
  188. return
  189. end
  190. PushClient(human,GC_WARORDER_CHANGE,data)
  191. end,
  192. [CG_SKIN_QUREY] = function(human,param)
  193. local panelId = assert(tonumber(param),"invalid param")
  194. local heroSkinLogic = require"present.HeroSkinLogic"
  195. local data = heroSkinLogic.query(human,panelId)
  196. if not data then
  197. return
  198. end
  199. PushClient(human,GC_SKIN_QUERY,data)
  200. end,
  201. }
  202. --[[function NewProto(human, type, paramJson)
  203. -- print("newProto:",type,param)
  204. -- local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  205. -- msgRet.ret = type
  206. -- msgRet.tip = "test data"
  207. -- Msg.send(msgRet,human.fd)
  208. local f = assert(handler[type],"invalid proto type")
  209. --local param = Json.Decode(paramJson)
  210. return f(human,paramJson)
  211. end]]
  212. -- 主动推送给客户端
  213. function PushClient(human,type,data)
  214. if not push[type] then
  215. Broadcast.sendErr(human, Lang.DRILL_CHOOSE_MY_ERR_INDEX .. " type is " .. type)
  216. return
  217. end
  218. local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  219. msgRet.ret = type
  220. msgRet.tip = Json.Encode(data)
  221. Msg.send(msgRet,human.fd)
  222. end
  223. -----------------------------------------------------------
  224. function NewProto(human, type, param)
  225. -- print("newProto:",type,param)
  226. -- local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  227. -- msgRet.ret = type
  228. -- msgRet.tip = "test data"
  229. -- Msg.send(msgRet,human.fd)
  230. local f = handler[type]
  231. if f then
  232. return f(human,param)
  233. end
  234. local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  235. -- 观看广告获取召唤券
  236. if type == AD_DRAW_REWARD_TYPE then
  237. human.db.adRewardCnt = human.db.adRewardCnt or 0
  238. if human.db.adRewardCnt > 4 then
  239. Broadcast.sendErr(human, Lang.AD_DRAW_REWARD_LIMIT_ERROR)
  240. return
  241. end
  242. --增加今日观看次数
  243. human.db.adRewardCnt = (human.db.adRewardCnt or 0) + 1
  244. Log.write(Log.LOGID_TEST, "adRewardCnt: " .. human.db.adRewardCnt)
  245. -- 添加高级召唤卷
  246. BagLogic.addItem(human, 118, 1, "draw_ad_reward")
  247. msgRet.ret = AD_DRAW_REWARD_TYPE
  248. msgRet.tip = Lang.AD_DRAW_REWARD_SUCCESS
  249. Msg.send(msgRet, human.fd)
  250. return
  251. end
  252. -- 查询加速孵化需要的钻石
  253. if type == QUERY_QUICK_HATCH_ZUANSHI then
  254. -- 初始化
  255. initMergeInfo(human)
  256. local info = {}
  257. local nowTime = os.time
  258. local hatchTime = human.db.mergeInfo.endTime - nowTime
  259. info.zuanshi = doCalcNeedZuanshi(hatchTime)
  260. info.isTip = getTodayIsTip(human)
  261. msgRet.ret = QUERY_QUICK_HATCH_ZUANSHI
  262. msgRet.tip = Json.Encode(info)
  263. Msg.send(msgRet, human.fd)
  264. return
  265. end
  266. -- 获取融合前的信息
  267. if type == QUERY_MERGE_BEFORE_INFO_TYPE then
  268. local tb = Util.split(param, "|")
  269. if tb[1] and tb[2] then
  270. -- 初始化
  271. initMergeInfo(human)
  272. human.db.heroBag = human.db.heroBag or {}
  273. local fatherHeroBagIndex = tonumber(tb[1]) or 0
  274. local motherHeroBagIndex = tonumber(tb[2]) or 0
  275. Log.write(Log.LOGID_TEST, "查询融合前的 fatherHeroBagIndex: " .. fatherHeroBagIndex)
  276. Log.write(Log.LOGID_TEST, "查询融合前的 motherHeroBagIndex: " .. motherHeroBagIndex)
  277. local fatherHeroGrid = human.db.heroBag[fatherHeroBagIndex]
  278. if not fatherHeroGrid then
  279. Log.write(Log.LOGID_TEST, "查询融合前的 fatherHeroGrid: 不存在下标:" .. fatherHeroBagIndex)
  280. return
  281. end
  282. Log.write(Log.LOGID_TEST, "查询融合前的 fatherHeroGrid: " .. Json.Encode(fatherHeroGrid))
  283. local motherHeroGrid = human.db.heroBag[motherHeroBagIndex]
  284. if not motherHeroGrid then
  285. Log.write(Log.LOGID_TEST, "查询融合前的 motherHeroGrid: 不存在下标:" .. motherHeroBagIndex)
  286. return
  287. end
  288. Log.write(Log.LOGID_TEST, "查询融合前的 motherHeroGrid: " .. Json.Encode(motherHeroGrid))
  289. local mergeInfo = {}
  290. local heroSimple = {}
  291. local xLv = getxLv(fatherHeroGrid, motherHeroGrid)
  292. local cnt = math.floor(xLv / 2) + 1
  293. local isHatch = 2
  294. local mergeItem = {}
  295. local itemId = 178
  296. for k = 1, 1 do
  297. mergeItem[k] = mergeItem[k] or {}
  298. mergeItem[k].getway = mergeItem[k].getway or {}
  299. mergeItem[k].suipian = mergeItem[k].suipian or {}
  300. mergeItem[k].equip = mergeItem[k].equip or {}
  301. mergeItem[k].fuwen = mergeItem[k].fuwen or {}
  302. Grid.makeItem(mergeItem[k], itemId, cnt)
  303. end
  304. local sonHeroID = mergeHero(fatherHeroGrid.id, motherHeroGrid.id)
  305. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  306. heroSimple.name = cf and cf.name or ""
  307. if cf.grade >= 6 then
  308. heroSimple.name = "?????"
  309. end
  310. mergeInfo.mergeTime = 0
  311. mergeInfo.xLv = xLv
  312. mergeInfo.mergeItem = mergeItem
  313. mergeInfo.heroData = heroSimple
  314. mergeInfo.isHatch = isHatch
  315. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  316. mergeInfo.isTip = getTodayIsTip(human)
  317. Log.write(Log.LOGID_TEST, "查询融合前的 mergeInfo: " .. Json.Encode(mergeInfo))
  318. msgRet.ret = QUERY_MERGE_BEFORE_INFO_TYPE
  319. msgRet.tip = Json.Encode(mergeInfo)
  320. Msg.send(msgRet, human.fd)
  321. end
  322. return
  323. end
  324. -- 开始融合
  325. if type == MERGE_HERO_TYPE then
  326. local tb = Util.split(param, "|")
  327. if tb[1] and tb[2] then
  328. -- 初始化
  329. initMergeInfo(human)
  330. human.db.heroBag = human.db.heroBag or {}
  331. Log.write(Log.LOGID_TEST, "融合 human.db.heroBag: " .. Json.Encode(human.db.heroBag))
  332. local itemId = 178 --生命雨露
  333. local fatherHeroBagIndex = tonumber(tb[1]) or 0
  334. local motherHeroBagIndex = tonumber(tb[2]) or 0
  335. Log.write(Log.LOGID_TEST, "融合 fatherHeroBagIndex: " .. fatherHeroBagIndex)
  336. Log.write(Log.LOGID_TEST, "融合 motherHeroBagIndex: " .. motherHeroBagIndex)
  337. local fatherHeroGrid = human.db.heroBag[fatherHeroBagIndex]
  338. if not fatherHeroGrid then
  339. return
  340. end
  341. Log.write(Log.LOGID_TEST, "融合 fatherHeroGrid: " .. Json.Encode(fatherHeroGrid))
  342. local motherHeroGrid = human.db.heroBag[motherHeroBagIndex]
  343. if not motherHeroGrid then
  344. return
  345. end
  346. Log.write(Log.LOGID_TEST, "融合 motherHeroGrid: " .. Json.Encode(motherHeroGrid))
  347. local fatherHeroAttr = ObjHuman.getHeroAttrs(human, fatherHeroBagIndex)
  348. local motherHeroAttr = ObjHuman.getHeroAttrs(human, motherHeroBagIndex)
  349. local mergeInfo = {}
  350. local attrs = RoleDefine.PANEL_ATTR_KEY
  351. if fatherHeroGrid.lv < 100 or motherHeroGrid.lv < 100 then
  352. Broadcast.sendErr(human, Lang.MERGE_LV_NOT_ENOUGHT_FAIL)
  353. return
  354. end
  355. local sonHeroID = mergeHero(fatherHeroGrid.id, motherHeroGrid.id)
  356. if sonHeroID <= 0 then
  357. return
  358. end
  359. for key, value in pairs(attrs) do
  360. local param1 = fatherHeroAttr[key] or 0
  361. local param2 = motherHeroAttr[key] or 0
  362. attrs[key] = math.floor(((param1 + param2) / 4))
  363. end
  364. Log.write(Log.LOGID_TEST, "融合后的属性: " .. Json.Encode(attrs))
  365. local xLv = getxLv(fatherHeroGrid, motherHeroGrid)
  366. local cnt = math.floor(xLv / 2) + 1
  367. local heroSimple = {}
  368. local isHatch = 1
  369. Log.write(Log.LOGID_TEST, "xLv: " .. xLv)
  370. Log.write(Log.LOGID_TEST, "cnt: " .. cnt)
  371. local bagCnt = BagLogic.getItemCnt(human, itemId, true)
  372. if bagCnt < cnt then
  373. Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
  374. return
  375. end
  376. --使用道具
  377. ItemLogic.use(human, itemId, cnt)
  378. local delHeroList = { [1] = fatherHeroBagIndex, [2] = motherHeroBagIndex }
  379. for key, heroIndex in pairs(delHeroList) do
  380. local heroID = HeroLogic.getHeroIdByIndex(human, heroIndex)
  381. --脱装备
  382. HeroEquip.putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_WEAPON, false, true)
  383. HeroEquip.putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_CLOTH, false, true)
  384. HeroEquip.putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHOES, false, true)
  385. HeroEquip.putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHIPIN, false, true)
  386. HeroEquip.putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHENQI, false, true)
  387. --脱符文
  388. FuwenLogic.putOff(human, heroID, heroIndex, 1, false, true)
  389. FuwenLogic.putOff(human, heroID, heroIndex, 2, false, true)
  390. HeroLogic.delHeroByIndex(human, heroIndex, "hero_merge")
  391. end
  392. -- 记录融合英雄
  393. human.db.mergeInfo.heroInfo.heroID = sonHeroID
  394. human.db.mergeInfo.heroInfo.xLv = xLv
  395. human.db.mergeInfo.heroInfo.heroAttrs = attrs
  396. human.db.mergeInfo.startTime = os.time()
  397. human.db.mergeInfo.endTime = os.time() + getHatchTime(xLv)
  398. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = fatherHeroBagIndex
  399. human.db.mergeInfo.heroInfo.motherHeroBagIndex = motherHeroBagIndex
  400. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  401. heroSimple.name = cf and cf.name or ""
  402. if cf.grade >= 6 then
  403. heroSimple.name = "?????"
  404. end
  405. if getHatchTime(xLv) == 0 then
  406. isHatch = 3
  407. end
  408. mergeInfo.mergeTime = getHatchTime(xLv)
  409. mergeInfo.xLv = xLv
  410. mergeInfo.heroData = heroSimple
  411. mergeInfo.isHatch = isHatch
  412. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  413. mergeInfo.isTip = getTodayIsTip(human)
  414. Log.write(Log.LOGID_TEST, "融合 mergeInfo: " .. Json.Encode(mergeInfo))
  415. Broadcast.sendErr(human, Lang.MERGE_SUCCESS)
  416. msgRet.ret = MERGE_HERO_TYPE
  417. msgRet.tip = Json.Encode(mergeInfo)
  418. Msg.send(msgRet, human.fd)
  419. end
  420. return
  421. end
  422. -- 获取融合中的信息
  423. if type == QUERY_MERGE_INFO_TYPE then
  424. -- 初始化
  425. initMergeInfo(human)
  426. human.db.heroBag = human.db.heroBag or {}
  427. local mergeInfo = {}
  428. local mergeTime = 0
  429. local heroSimple = {}
  430. local xLv = human.db.mergeInfo.heroInfo.xLv or 0
  431. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  432. local isHatch = 2
  433. if sonHeroID == 0 then
  434. mergeInfo.mergeTime = mergeTime
  435. mergeInfo.xLv = xLv
  436. mergeInfo.heroData = heroSimple
  437. mergeInfo.isHatch = isHatch
  438. msgRet.ret = QUERY_MERGE_INFO_TYPE
  439. msgRet.tip = Json.Encode(mergeInfo)
  440. Msg.send(msgRet, human.fd)
  441. return
  442. end
  443. local mergeTime = human.db.mergeInfo.endTime - os.time()
  444. if mergeTime <= 0 then
  445. -- 孵化成功
  446. mergeTime = 0
  447. isHatch = 3
  448. else
  449. isHatch = 1
  450. end
  451. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  452. heroSimple.name = cf and cf.name or ""
  453. if cf.grade >= 6 then
  454. heroSimple.name = "?????"
  455. end
  456. mergeInfo.mergeTime = mergeTime
  457. mergeInfo.xLv = xLv
  458. mergeInfo.heroData = heroSimple
  459. mergeInfo.isHatch = isHatch
  460. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  461. mergeInfo.isTip = getTodayIsTip(human)
  462. msgRet.ret = QUERY_MERGE_INFO_TYPE
  463. msgRet.tip = Json.Encode(mergeInfo)
  464. Log.write(Log.LOGID_TEST, "融合中 msgRet: " .. Json.Encode(msgRet))
  465. Msg.send(msgRet, human.fd)
  466. return
  467. end
  468. -- 获取融合英雄
  469. if type == GET_MERGE_HERO_TYPE then
  470. local nowTime = os.time()
  471. local mergeInfo = {}
  472. local heroSimple = {}
  473. local xLv = human.db.mergeInfo.heroInfo.xLv or 0
  474. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  475. local hatchTime = human.db.mergeInfo.endTime - nowTime
  476. local isHatch = 2
  477. local heroIndex = 0
  478. local msgTyep = GET_MERGE_HERO_TYPE
  479. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  480. local heroNiceNet = {}
  481. if hatchTime <= 0 then
  482. -- 孵化成功
  483. hatchTime = 0
  484. heroIndex = hatchHero(human)
  485. local heroGrid = human.db.heroBag[heroIndex]
  486. if not heroGrid then return end
  487. heroSimple.general = heroSimple.general or {}
  488. HeroGrid.makeHeroSimple(heroSimple, heroGrid, heroIndex, human)
  489. local heroID = heroGrid.id or 0
  490. local isNew = not HeroBook.isGet(human, cf.id, cf.star)
  491. makeHeroNice(heroNiceNet, heroID, nil, isNew, heroIndex)
  492. else
  493. heroSimple.name = cf and cf.name or ""
  494. if cf.grade >= 6 then
  495. heroSimple.name = "?????"
  496. end
  497. isHatch = 1
  498. msgTyep = QUERY_MERGE_INFO_TYPE
  499. end
  500. mergeInfo.mergeTime = hatchTime
  501. mergeInfo.xLv = xLv
  502. mergeInfo.heroData = heroSimple
  503. mergeInfo.isHatch = isHatch
  504. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  505. mergeInfo.isTip = getTodayIsTip(human)
  506. mergeInfo.heroNiceNet = heroNiceNet
  507. msgRet.ret = msgTyep
  508. msgRet.tip = Json.Encode(mergeInfo)
  509. Log.write(Log.LOGID_TEST, "获取英雄 ret: " .. Json.Encode(msgRet))
  510. Msg.send(msgRet, human.fd)
  511. return
  512. end
  513. -- 加速孵化
  514. if type == QUICK_HATCH_TYPE then
  515. local tb = Util.split(param, "|")
  516. local quickType = tonumber(tb[1]) or 0
  517. local cnt = tonumber(tb[2]) or 0
  518. local isHatch = 1
  519. if tb[1] and tb[2] then
  520. -- 初始化
  521. initMergeInfo(human)
  522. -- 剩余时间
  523. local nowTime = os.time()
  524. local hatchTime = human.db.mergeInfo.endTime - nowTime
  525. if hatchTime <= 0
  526. then
  527. Broadcast.sendErr(human, Lang.QUICK_HATCH_TIME_OUT)
  528. return
  529. end
  530. local itemSpeedTime = 0
  531. if quickType == 1 then
  532. local speedTime = (60 * 5 * cnt) -- 正常数量加速券的加速时间
  533. local lastSpeedTime = (60 * 5 * (cnt - 1)) --少一张加速券的加速时间
  534. local itemCnt = 0
  535. if hatchTime > lastSpeedTime and hatchTime <= speedTime then
  536. itemCnt = cnt
  537. elseif hatchTime > 0 and hatchTime <= lastSpeedTime then
  538. itemCnt = cnt - 1
  539. elseif hatchTime >= speedTime then
  540. itemCnt = cnt
  541. else
  542. itemCnt = 0
  543. end
  544. itemSpeedTime = (60 * 5 * itemCnt)
  545. local bagCnt = BagLogic.getItemCnt(human, 179, true)
  546. if bagCnt < itemCnt then
  547. Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
  548. return
  549. end
  550. --使用道具
  551. ItemLogic.use(human, 179, cnt)
  552. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
  553. elseif quickType == 2 then
  554. local zuanshiCnt = doCalcNeedZuanshi(hatchTime)
  555. -- 判断消耗
  556. if not ObjHuman.checkRMB(human, zuanshiCnt) then
  557. return
  558. end
  559. itemSpeedTime = (30 * zuanshiCnt)
  560. -- 扣钻石
  561. ObjHuman.decZuanshi(human, -zuanshiCnt, "hero_merge")
  562. if tb[3] then
  563. human.db.isTip = human.db.isTip or 1
  564. human.db.isTip = tonumber(tb[3])
  565. end
  566. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
  567. elseif quickType == 3 then
  568. human.db.adHatchRewardCnt = human.db.adHatchRewardCnt or 0
  569. if human.db.adHatchRewardCnt > 4 then
  570. Broadcast.sendErr(human, Lang.AD_HATCH_REWARD_LIMIT_ERROR)
  571. return
  572. end
  573. --加速30分钟
  574. itemSpeedTime = 30 * 60
  575. --增加今日观看次数
  576. human.db.adHatchRewardCnt = (human.db.adHatchRewardCnt or 0) + 1
  577. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
  578. end
  579. local hatchTime = human.db.mergeInfo.endTime - nowTime
  580. -- 孵化成功
  581. if hatchTime < 0 then
  582. hatchTime = 0
  583. isHatch = 3
  584. end
  585. local mergeInfo = {}
  586. local heroSimple = {}
  587. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  588. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  589. heroSimple.name = cf and cf.name or ""
  590. if cf.grade >= 6 then
  591. heroSimple.name = "?????"
  592. end
  593. mergeInfo.mergeTime = hatchTime
  594. mergeInfo.heroData = heroSimple
  595. mergeInfo.xLv = human.db.mergeInfo.heroInfo.xLv
  596. mergeInfo.isHatch = isHatch
  597. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  598. mergeInfo.isTip = getTodayIsTip(human)
  599. msgRet.ret = QUICK_HATCH_TYPE
  600. msgRet.tip = Json.Encode(mergeInfo)
  601. Log.write(Log.LOGID_TEST, "加速孵化 ret: " .. Json.Encode(msgRet))
  602. Msg.send(msgRet, human.fd)
  603. return
  604. end
  605. return
  606. end
  607. end
  608. -- 孵化英雄
  609. function hatchHero(human)
  610. Log.write(Log.LOGID_TEST, "孵化英雄id " .. human.db.mergeInfo.heroInfo.heroID)
  611. --添加英雄
  612. local heroIndex, fjlist = HeroLogic.addHero(human, human.db.mergeInfo.heroInfo.heroID, nil, 1,
  613. "hero_merge")
  614. Log.write(Log.LOGID_TEST, "孵化英雄成功 下标" .. heroIndex)
  615. local attrs = RoleDefine.PANEL_ATTR_KEY
  616. for key, value in pairs(attrs) do
  617. attrs[key] = 1
  618. end
  619. human.db.mergeInfo.startTime = 0
  620. human.db.mergeInfo.endTime = 0
  621. human.db.mergeInfo.heroInfo = {}
  622. human.db.mergeInfo.heroInfo.heroID = 0
  623. human.db.mergeInfo.heroInfo.xLv = 0
  624. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = 0
  625. human.db.mergeInfo.heroInfo.motherHeroBagIndex = 0
  626. human.db.mergeInfo.heroInfo.heroAttrs = attrs
  627. Log.write(Log.LOGID_TEST, "孵化重置 mergeInfo: " .. Json.Encode(human.db.mergeInfo))
  628. return heroIndex
  629. end
  630. -- 初始化融合信息
  631. function initMergeInfo(human)
  632. human.db.mergeInfo = human.db.mergeInfo or {}
  633. human.db.mergeInfo.startTime = human.db.mergeInfo.startTime or 0 --融合时间 时间戳
  634. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime or 0 --孵化时间 单位s
  635. human.db.mergeInfo.heroInfo = human.db.mergeInfo.heroInfo or {}
  636. human.db.mergeInfo.heroInfo.heroID = human.db.mergeInfo.heroInfo.heroID or 0
  637. human.db.mergeInfo.heroInfo.xLv = human.db.mergeInfo.heroInfo.xLv or 0
  638. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = human.db.mergeInfo.heroInfo.fatherHeroBagIndex or 0
  639. human.db.mergeInfo.heroInfo.motherHeroBagIndex = human.db.mergeInfo.heroInfo.motherHeroBagIndex or 0
  640. human.db.mergeInfo.heroInfo.heroAttrs = human.db.mergeInfo.heroInfo.heroAttrs or RoleDefine.PANEL_ATTR_KEY
  641. end
  642. -- 获取孵化时间 单位s
  643. function getHatchTime(xLv)
  644. local time = (xLv * 5) + (xLv - 1) * (xLv - 1) - 5
  645. if time < 0 then
  646. return 0
  647. end
  648. return time * 60
  649. end
  650. -- 计算需要钻石数量
  651. function doCalcNeedZuanshi(hatchTime)
  652. local cnt = 0
  653. if hatchTime > 0 then
  654. cnt = math.ceil(hatchTime / 30)
  655. end
  656. return cnt
  657. end
  658. -- 获取xlv
  659. function getxLv(fatherHeroGrid, motherHeroGrid)
  660. local fatherHeroXLv = fatherHeroGrid.xLv or 0
  661. local motherHeroXLv = motherHeroGrid.xLv or 0
  662. local params1 = math.max(fatherHeroXLv, motherHeroXLv)
  663. local params2 = math.floor((fatherHeroGrid.lv + motherHeroGrid.lv) / 200) + 1
  664. local xLv = params1 + params2
  665. if xLv > 50 then
  666. return 50
  667. end
  668. return xLv
  669. end
  670. -- 融合获取英雄ID
  671. function mergeHero(fatherHeroID, motherHeroID)
  672. local fatherHeroConfig = HeroExcel.hero[fatherHeroID]
  673. local motherHeroConfig = HeroExcel.hero[motherHeroID]
  674. if not fatherHeroConfig or not motherHeroConfig then
  675. return 0
  676. end
  677. --规则3 heroID + heroID
  678. for _, config in pairs(MergeRule[3].items) do
  679. if fatherHeroID == config[1] and motherHeroID == config[2] then
  680. return config[3]
  681. end
  682. end
  683. --规则2 种族 + heroID
  684. for _, config in pairs(MergeRule[2].items) do
  685. if fatherHeroConfig.camp == config[1] and motherHeroID == config[2] then
  686. return config[3]
  687. end
  688. end
  689. --规则1 种族 + 种族
  690. for _, config in pairs(MergeRule[1].items) do
  691. if fatherHeroConfig.camp == config[1] and motherHeroConfig.camp == config[2] then
  692. return config[3]
  693. end
  694. end
  695. return 0
  696. end
  697. -- 获取剩余融化孵化加速广告观看次数
  698. function getResetAdHatchCnt(human)
  699. local adHatchRewardCnt = human.db.adHatchRewardCnt or 0
  700. return math.max(AD_HATCH_RESET_FREECNT - adHatchRewardCnt, 0)
  701. end
  702. -- 获取是否今日不再提示
  703. function getTodayIsTip(human)
  704. local isTip = human.db.isTip or 1
  705. return tonumber(isTip)
  706. end
  707. -- 封装客户端需要的json格式
  708. function makeHeroNice(net, id, cnt, isNew, index)
  709. net.heroSimple = net.heroSimple or {}
  710. net.itemData = net.itemData or {}
  711. net.heroStatic = net.heroStatic or {}
  712. net.attrs = net.attrs or {}
  713. net.attrsMax = net.attrsMax or {}
  714. if cnt then
  715. net.itemData[1] = net.itemData[1] or {}
  716. Grid.makeItem(net.itemData[1], id, cnt)
  717. end
  718. local heroConfig = HeroExcel.hero[id]
  719. local specialConfig = HeroExcel.specialHero[id]
  720. if heroConfig then
  721. net.heroSimple[1] = net.heroSimple[1] or {}
  722. net.heroStatic[1] = net.heroStatic[1] or {}
  723. makeHeroSimpleByID(net.heroSimple[1], id, index)
  724. makeHeroStatic(net.heroStatic[1], id)
  725. end
  726. net.body = specialConfig and (heroConfig and heroConfig.body or 0) or 0
  727. net.isNew = isNew and 1 or 0
  728. net.weightLv = heroConfig and heroConfig.grade or 0
  729. net.bubble = ""
  730. local attrsNum = 0
  731. local attrsMaxNum = 0
  732. if heroConfig then
  733. local bubble = PaomaExcel.bubble[heroConfig.id]
  734. net.bubble = bubble and bubble.drawCard or ""
  735. local heroGrid = HeroGrid.getCacheHeroGridTujian(id)
  736. for key = RoleDefine.ATK, RoleDefine.SPEED do
  737. local value = heroGrid.attrs[key]
  738. attrsNum = attrsNum + 1
  739. net.attrs[attrsNum] = net.attrs[attrsNum] or {}
  740. net.attrs[attrsNum].key = key
  741. net.attrs[attrsNum].value = value
  742. attrsMaxNum = attrsMaxNum + 1
  743. net.attrsMax[attrsMaxNum] = net.attrs[attrsMaxNum] or {}
  744. net.attrsMax[attrsMaxNum].key = key
  745. net.attrsMax[attrsMaxNum].value = HeroDefine.getTujianMaxValue(key)
  746. end
  747. end
  748. end
  749. -- 根据英雄id封装英雄信息heroSimple 额外处理
  750. function makeHeroSimpleByID(net, id, index, others, human, tujian)
  751. local star = others and others.star or nil
  752. local grid = HeroGrid.getCacheHeroGrid(id, star, others)
  753. makeHeroSimple(net, grid, index, human, others, tujian)
  754. end
  755. -- 填充英雄详细信息:静态 额外格式
  756. function makeHeroStatic(net, id, tuJian)
  757. net.skillList = net.skillList or {}
  758. net.beSkill = net.beSkill or {}
  759. local cf = id and HeroExcel.hero[id]
  760. if not cf then
  761. net.id = 0
  762. net.name = ""
  763. net.body = 0
  764. net.job = 0
  765. net.weightLv = 0
  766. net.normalAtkID = 0
  767. net.skillList[0] = 0
  768. net.beSkill[0] = 0
  769. net.skin = 0
  770. return
  771. end
  772. local star = cf.star
  773. if tuJian and tuJian == 1 then
  774. local tuJianConfig = HeroExcel.tujian[id]
  775. if tuJianConfig then
  776. local maxStarIndex = #tuJianConfig.star
  777. star = tuJianConfig.star[maxStarIndex]
  778. end
  779. end
  780. net.id = id
  781. net.name = cf.name
  782. net.body = cf.body
  783. net.job = cf.job
  784. net.weightLv = cf.grade
  785. local attrConfig = HeroDefine.getAttrConfig(id, star)
  786. net.normalAtkID = attrConfig.normalAtkID
  787. for i = 1, #attrConfig.skillList do
  788. net.skillList[i] = net.skillList[i] or {}
  789. makeSkillNet(net.skillList[i], attrConfig.skillList[i])
  790. end
  791. for i = 1, #attrConfig.beSkillList do
  792. net.beSkill[i] = net.beSkill[i] or {}
  793. makeSkillNet(net.beSkill[i], attrConfig.beSkillList[i])
  794. end
  795. net.skin = #cf.skin > 0 and 1 or 0
  796. end
  797. -- 封装英雄信息 额外处理
  798. function makeHeroSimple(net, grid, index, human, others, tuJian)
  799. local id = grid and (grid.id or grid.heroID)
  800. local cf = id and HeroExcel.hero[id]
  801. local star = grid and grid.star or (cf and cf.star or 1)
  802. local upStarConfig = HeroDefine.getNextAttrConfig(id, star)
  803. local jobConfig = cf and cf.job and HeroExcel.job[cf.job]
  804. local isGongMing = XingYaoGongMing.isGongMing(human, index)
  805. net.id = id or 0
  806. net.index = index or 0
  807. net.uuid = grid and grid.uuid or ""
  808. net.gl = cf and cf.gl or 0
  809. net.camp = cf and cf.camp or 0
  810. net.job = cf and cf.job or 0
  811. net.star = others and others.star or star --cf and cf.star or 0 星级调整 dxzeng
  812. net.icon = grid and grid.head or (cf and cf.head or 0)
  813. net.body = grid and grid.body or (cf and cf.body or 0)
  814. if grid and human and index then -- todo 皮肤这个以后可能还是需要继续整理
  815. local skinConf = SkinLogic.getHeroSkin(human, index)
  816. if skinConf then
  817. net.icon = skinConf.head
  818. net.body = skinConf.body
  819. end
  820. end
  821. net.up = upStarConfig == nil and 0 or 1 --是否能够升星
  822. net.lv = others and others.lv or (grid and grid.lv or 1)
  823. net.xLv = others and others.xLv or (grid and grid.xLv or 0)
  824. net.zhandouli = grid and grid.zhandouli or 0
  825. net.quality = grid and grid.quality or 0
  826. net.isLock = (grid and grid.isLock) and 1 or 0
  827. net.hp = others and others.hp or 0
  828. net.hpMax = others and others.hpMax or 0
  829. net.cnt = others and others.cnt or 1
  830. net.isget = HeroBook.isGetHero(human, id) or 0
  831. net.weightLv = cf and cf.grade or 0
  832. net.name = cf and cf.name or ""
  833. net.grade = cf and cf.grade or 0
  834. net.jobDesc = jobConfig and jobConfig.desc or ""
  835. net.label = cf and cf.label or ""
  836. net.order = cf and cf.order or 0
  837. net.isGongMing = isGongMing or 0
  838. net.general = net.general or {}
  839. --是否发送图鉴信息
  840. if tuJian then
  841. local tj = HeroExcel.tujian[id]
  842. if tj ~= nil then
  843. net.general[1] = net.general[1] or {}
  844. net.general[1].cm = tj.cm or 0
  845. net.general[1].kg = tj.kg or 0
  846. net.general[1].age = tj.age or 0
  847. net.general[1].cup = tj.cup or ""
  848. net.general[1].character = tj.character or ""
  849. net.general[1].interest = tj.interest or ""
  850. net.general[1].desc = tj.desc or ""
  851. end
  852. end
  853. end
  854. -- 获取技能信息
  855. function makeSkillNet(net, id)
  856. local skillConfig = SkillExcel.skill[id]
  857. if not skillConfig then return end
  858. net.id = id
  859. net.icon = skillConfig.icon
  860. net.name = skillConfig.name
  861. net.type = skillConfig.type
  862. net.desc = skillConfig.desc
  863. net.need = skillConfig.need or 0
  864. net.lv = skillConfig.skillLv or 0
  865. -- todo
  866. net.cd = net.cd or {}
  867. net.buff = net.buff or {}
  868. if #skillConfig.cd ~= 0 then
  869. net.cd[1] = net.cd[1] or {}
  870. net.cd[2] = net.cd[2] or {}
  871. net.cd[1] = skillConfig.cd[1]
  872. net.cd[2] = skillConfig.cd[2]
  873. end
  874. local len = #skillConfig.buffers
  875. for i = 1, len do
  876. local buffId = skillConfig.buffers[i][1]
  877. local buffConfig = BufferExcel.buffer[buffId]
  878. net.buff[i] = net.buff[i] or {}
  879. net.buff[i].id = buffId
  880. net.buff[i].name = buffConfig.name
  881. net.buff[i].desc = buffConfig.desc
  882. end
  883. net.lvUpDesc = skillConfig.lvUpDesc
  884. -- todo
  885. end