NewLogic.lua 36 KB

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