NewLogic.lua 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  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 = 10 -- 新增礼包推送
  105. --[[
  106. GC_QUERY_GIFT = {
  107. list = {Gift}
  108. }
  109. ]]
  110. local GC_QUERY_GIFT = 11 -- 登录推送礼包数据
  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. --脱符文
  389. FuwenLogic.putOff(human, heroID, heroIndex, 1, false, true)
  390. FuwenLogic.putOff(human, heroID, heroIndex, 2, false, true)
  391. HeroLogic.delHeroByIndex(human, heroIndex, "hero_merge")
  392. end
  393. -- 记录融合英雄
  394. human.db.mergeInfo.heroInfo.heroID = sonHeroID
  395. human.db.mergeInfo.heroInfo.xLv = xLv
  396. human.db.mergeInfo.heroInfo.heroAttrs = attrs
  397. human.db.mergeInfo.startTime = os.time()
  398. human.db.mergeInfo.endTime = os.time() + getHatchTime(xLv)
  399. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = fatherHeroBagIndex
  400. human.db.mergeInfo.heroInfo.motherHeroBagIndex = motherHeroBagIndex
  401. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  402. heroSimple.name = cf and cf.name or ""
  403. if cf.grade >= 6 then
  404. heroSimple.name = "?????"
  405. end
  406. if getHatchTime(xLv) == 0 then
  407. isHatch = 3
  408. end
  409. mergeInfo.mergeTime = getHatchTime(xLv)
  410. mergeInfo.xLv = xLv
  411. mergeInfo.heroData = heroSimple
  412. mergeInfo.isHatch = isHatch
  413. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  414. mergeInfo.isTip = getTodayIsTip(human)
  415. Log.write(Log.LOGID_TEST, "融合 mergeInfo: " .. Json.Encode(mergeInfo))
  416. Broadcast.sendErr(human, Lang.MERGE_SUCCESS)
  417. msgRet.ret = MERGE_HERO_TYPE
  418. msgRet.tip = Json.Encode(mergeInfo)
  419. Msg.send(msgRet, human.fd)
  420. end
  421. return
  422. end
  423. -- 获取融合中的信息
  424. if type == QUERY_MERGE_INFO_TYPE then
  425. -- 初始化
  426. initMergeInfo(human)
  427. human.db.heroBag = human.db.heroBag or {}
  428. local mergeInfo = {}
  429. local mergeTime = 0
  430. local heroSimple = {}
  431. local xLv = human.db.mergeInfo.heroInfo.xLv or 0
  432. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  433. local isHatch = 2
  434. if sonHeroID == 0 then
  435. mergeInfo.mergeTime = mergeTime
  436. mergeInfo.xLv = xLv
  437. mergeInfo.heroData = heroSimple
  438. mergeInfo.isHatch = isHatch
  439. msgRet.ret = QUERY_MERGE_INFO_TYPE
  440. msgRet.tip = Json.Encode(mergeInfo)
  441. Msg.send(msgRet, human.fd)
  442. return
  443. end
  444. local mergeTime = human.db.mergeInfo.endTime - os.time()
  445. if mergeTime <= 0 then
  446. -- 孵化成功
  447. mergeTime = 0
  448. isHatch = 3
  449. else
  450. isHatch = 1
  451. end
  452. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  453. heroSimple.name = cf and cf.name or ""
  454. if cf.grade >= 6 then
  455. heroSimple.name = "?????"
  456. end
  457. mergeInfo.mergeTime = mergeTime
  458. mergeInfo.xLv = xLv
  459. mergeInfo.heroData = heroSimple
  460. mergeInfo.isHatch = isHatch
  461. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  462. mergeInfo.isTip = getTodayIsTip(human)
  463. msgRet.ret = QUERY_MERGE_INFO_TYPE
  464. msgRet.tip = Json.Encode(mergeInfo)
  465. Log.write(Log.LOGID_TEST, "融合中 msgRet: " .. Json.Encode(msgRet))
  466. Msg.send(msgRet, human.fd)
  467. return
  468. end
  469. -- 获取融合英雄
  470. if type == GET_MERGE_HERO_TYPE then
  471. local nowTime = os.time()
  472. local mergeInfo = {}
  473. local heroSimple = {}
  474. local xLv = human.db.mergeInfo.heroInfo.xLv or 0
  475. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  476. local hatchTime = human.db.mergeInfo.endTime - nowTime
  477. local isHatch = 2
  478. local heroIndex = 0
  479. local msgTyep = GET_MERGE_HERO_TYPE
  480. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  481. local heroNiceNet = {}
  482. if hatchTime <= 0 then
  483. -- 孵化成功
  484. hatchTime = 0
  485. heroIndex = hatchHero(human)
  486. local heroGrid = human.db.heroBag[heroIndex]
  487. if not heroGrid then return end
  488. heroSimple.general = heroSimple.general or {}
  489. HeroGrid.makeHeroSimple(heroSimple, heroGrid, heroIndex, human)
  490. local heroID = heroGrid.id or 0
  491. local isNew = not HeroBook.isGet(human, cf.id, cf.star)
  492. makeHeroNice(heroNiceNet, heroID, nil, isNew, heroIndex)
  493. else
  494. heroSimple.name = cf and cf.name or ""
  495. if cf.grade >= 6 then
  496. heroSimple.name = "?????"
  497. end
  498. isHatch = 1
  499. msgTyep = QUERY_MERGE_INFO_TYPE
  500. end
  501. mergeInfo.mergeTime = hatchTime
  502. mergeInfo.xLv = xLv
  503. mergeInfo.heroData = heroSimple
  504. mergeInfo.isHatch = isHatch
  505. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  506. mergeInfo.isTip = getTodayIsTip(human)
  507. mergeInfo.heroNiceNet = heroNiceNet
  508. msgRet.ret = msgTyep
  509. msgRet.tip = Json.Encode(mergeInfo)
  510. Log.write(Log.LOGID_TEST, "获取英雄 ret: " .. Json.Encode(msgRet))
  511. Msg.send(msgRet, human.fd)
  512. return
  513. end
  514. -- 加速孵化
  515. if type == QUICK_HATCH_TYPE then
  516. local tb = Util.split(param, "|")
  517. local quickType = tonumber(tb[1]) or 0
  518. local cnt = tonumber(tb[2]) or 0
  519. local isHatch = 1
  520. if tb[1] and tb[2] then
  521. -- 初始化
  522. initMergeInfo(human)
  523. -- 剩余时间
  524. local nowTime = os.time()
  525. local hatchTime = human.db.mergeInfo.endTime - nowTime
  526. if hatchTime <= 0
  527. then
  528. Broadcast.sendErr(human, Lang.QUICK_HATCH_TIME_OUT)
  529. return
  530. end
  531. local itemSpeedTime = 0
  532. if quickType == 1 then
  533. local speedTime = (60 * 5 * cnt) -- 正常数量加速券的加速时间
  534. local lastSpeedTime = (60 * 5 * (cnt - 1)) --少一张加速券的加速时间
  535. local itemCnt = 0
  536. if hatchTime > lastSpeedTime and hatchTime <= speedTime then
  537. itemCnt = cnt
  538. elseif hatchTime > 0 and hatchTime <= lastSpeedTime then
  539. itemCnt = cnt - 1
  540. elseif hatchTime >= speedTime then
  541. itemCnt = cnt
  542. else
  543. itemCnt = 0
  544. end
  545. itemSpeedTime = (60 * 5 * itemCnt)
  546. local bagCnt = BagLogic.getItemCnt(human, 179, true)
  547. if bagCnt < itemCnt then
  548. Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
  549. return
  550. end
  551. --使用道具
  552. ItemLogic.use(human, 179, cnt)
  553. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
  554. elseif quickType == 2 then
  555. local zuanshiCnt = doCalcNeedZuanshi(hatchTime)
  556. -- 判断消耗
  557. if not ObjHuman.checkRMB(human, zuanshiCnt) then
  558. return
  559. end
  560. itemSpeedTime = (30 * zuanshiCnt)
  561. -- 扣钻石
  562. ObjHuman.decZuanshi(human, -zuanshiCnt, "hero_merge")
  563. if tb[3] then
  564. human.db.isTip = human.db.isTip or 1
  565. human.db.isTip = tonumber(tb[3])
  566. end
  567. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
  568. elseif quickType == 3 then
  569. human.db.adHatchRewardCnt = human.db.adHatchRewardCnt or 0
  570. if human.db.adHatchRewardCnt > 4 then
  571. Broadcast.sendErr(human, Lang.AD_HATCH_REWARD_LIMIT_ERROR)
  572. return
  573. end
  574. --加速30分钟
  575. itemSpeedTime = 30 * 60
  576. --增加今日观看次数
  577. human.db.adHatchRewardCnt = (human.db.adHatchRewardCnt or 0) + 1
  578. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
  579. end
  580. local hatchTime = human.db.mergeInfo.endTime - nowTime
  581. -- 孵化成功
  582. if hatchTime < 0 then
  583. hatchTime = 0
  584. isHatch = 3
  585. end
  586. local mergeInfo = {}
  587. local heroSimple = {}
  588. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  589. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  590. heroSimple.name = cf and cf.name or ""
  591. if cf.grade >= 6 then
  592. heroSimple.name = "?????"
  593. end
  594. mergeInfo.mergeTime = hatchTime
  595. mergeInfo.heroData = heroSimple
  596. mergeInfo.xLv = human.db.mergeInfo.heroInfo.xLv
  597. mergeInfo.isHatch = isHatch
  598. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  599. mergeInfo.isTip = getTodayIsTip(human)
  600. msgRet.ret = QUICK_HATCH_TYPE
  601. msgRet.tip = Json.Encode(mergeInfo)
  602. Log.write(Log.LOGID_TEST, "加速孵化 ret: " .. Json.Encode(msgRet))
  603. Msg.send(msgRet, human.fd)
  604. return
  605. end
  606. return
  607. end
  608. end
  609. -- 孵化英雄
  610. function hatchHero(human)
  611. Log.write(Log.LOGID_TEST, "孵化英雄id " .. human.db.mergeInfo.heroInfo.heroID)
  612. --添加英雄
  613. local heroIndex, fjlist = HeroLogic.addHero(human, human.db.mergeInfo.heroInfo.heroID, nil, 1,
  614. "hero_merge")
  615. Log.write(Log.LOGID_TEST, "孵化英雄成功 下标" .. heroIndex)
  616. local attrs = RoleDefine.PANEL_ATTR_KEY
  617. for key, value in pairs(attrs) do
  618. attrs[key] = 1
  619. end
  620. human.db.mergeInfo.startTime = 0
  621. human.db.mergeInfo.endTime = 0
  622. human.db.mergeInfo.heroInfo = {}
  623. human.db.mergeInfo.heroInfo.heroID = 0
  624. human.db.mergeInfo.heroInfo.xLv = 0
  625. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = 0
  626. human.db.mergeInfo.heroInfo.motherHeroBagIndex = 0
  627. human.db.mergeInfo.heroInfo.heroAttrs = attrs
  628. Log.write(Log.LOGID_TEST, "孵化重置 mergeInfo: " .. Json.Encode(human.db.mergeInfo))
  629. return heroIndex
  630. end
  631. -- 初始化融合信息
  632. function initMergeInfo(human)
  633. human.db.mergeInfo = human.db.mergeInfo or {}
  634. human.db.mergeInfo.startTime = human.db.mergeInfo.startTime or 0 --融合时间 时间戳
  635. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime or 0 --孵化时间 单位s
  636. human.db.mergeInfo.heroInfo = human.db.mergeInfo.heroInfo or {}
  637. human.db.mergeInfo.heroInfo.heroID = human.db.mergeInfo.heroInfo.heroID or 0
  638. human.db.mergeInfo.heroInfo.xLv = human.db.mergeInfo.heroInfo.xLv or 0
  639. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = human.db.mergeInfo.heroInfo.fatherHeroBagIndex or 0
  640. human.db.mergeInfo.heroInfo.motherHeroBagIndex = human.db.mergeInfo.heroInfo.motherHeroBagIndex or 0
  641. human.db.mergeInfo.heroInfo.heroAttrs = human.db.mergeInfo.heroInfo.heroAttrs or RoleDefine.PANEL_ATTR_KEY
  642. end
  643. -- 获取孵化时间 单位s
  644. function getHatchTime(xLv)
  645. local time = (xLv * 5) + (xLv - 1) * (xLv - 1) - 5
  646. if time < 0 then
  647. return 0
  648. end
  649. return time * 60
  650. end
  651. -- 计算需要钻石数量
  652. function doCalcNeedZuanshi(hatchTime)
  653. local cnt = 0
  654. if hatchTime > 0 then
  655. cnt = math.ceil(hatchTime / 30)
  656. end
  657. return cnt
  658. end
  659. -- 获取xlv
  660. function getxLv(fatherHeroGrid, motherHeroGrid)
  661. local fatherHeroXLv = fatherHeroGrid.xLv or 0
  662. local motherHeroXLv = motherHeroGrid.xLv or 0
  663. local params1 = math.max(fatherHeroXLv, motherHeroXLv)
  664. local params2 = math.floor((fatherHeroGrid.lv + motherHeroGrid.lv) / 200) + 1
  665. local xLv = params1 + params2
  666. if xLv > 50 then
  667. return 50
  668. end
  669. return xLv
  670. end
  671. -- 融合获取英雄ID
  672. function mergeHero(fatherHeroID, motherHeroID)
  673. local fatherHeroConfig = HeroExcel.hero[fatherHeroID]
  674. local motherHeroConfig = HeroExcel.hero[motherHeroID]
  675. if not fatherHeroConfig or not motherHeroConfig then
  676. return 0
  677. end
  678. --规则3 heroID + heroID
  679. for _, config in pairs(MergeRule[3].items) do
  680. if fatherHeroID == config[1] and motherHeroID == config[2] then
  681. return config[3]
  682. end
  683. end
  684. --规则2 种族 + heroID
  685. for _, config in pairs(MergeRule[2].items) do
  686. if fatherHeroConfig.camp == config[1] and motherHeroID == config[2] then
  687. return config[3]
  688. end
  689. end
  690. --规则1 种族 + 种族
  691. for _, config in pairs(MergeRule[1].items) do
  692. if fatherHeroConfig.camp == config[1] and motherHeroConfig.camp == config[2] then
  693. return config[3]
  694. end
  695. end
  696. return 0
  697. end
  698. -- 获取剩余融化孵化加速广告观看次数
  699. function getResetAdHatchCnt(human)
  700. local adHatchRewardCnt = human.db.adHatchRewardCnt or 0
  701. return math.max(AD_HATCH_RESET_FREECNT - adHatchRewardCnt, 0)
  702. end
  703. -- 获取是否今日不再提示
  704. function getTodayIsTip(human)
  705. local isTip = human.db.isTip or 1
  706. return tonumber(isTip)
  707. end
  708. -- 封装客户端需要的json格式
  709. function makeHeroNice(net, id, cnt, isNew, index)
  710. net.heroSimple = net.heroSimple or {}
  711. net.itemData = net.itemData or {}
  712. net.heroStatic = net.heroStatic or {}
  713. net.attrs = net.attrs or {}
  714. net.attrsMax = net.attrsMax or {}
  715. if cnt then
  716. net.itemData[1] = net.itemData[1] or {}
  717. Grid.makeItem(net.itemData[1], id, cnt)
  718. end
  719. local heroConfig = HeroExcel.hero[id]
  720. local specialConfig = HeroExcel.specialHero[id]
  721. if heroConfig then
  722. net.heroSimple[1] = net.heroSimple[1] or {}
  723. net.heroStatic[1] = net.heroStatic[1] or {}
  724. makeHeroSimpleByID(net.heroSimple[1], id, index)
  725. makeHeroStatic(net.heroStatic[1], id)
  726. end
  727. net.body = specialConfig and (heroConfig and heroConfig.body or 0) or 0
  728. net.isNew = isNew and 1 or 0
  729. net.weightLv = heroConfig and heroConfig.grade or 0
  730. net.bubble = ""
  731. local attrsNum = 0
  732. local attrsMaxNum = 0
  733. if heroConfig then
  734. local bubble = PaomaExcel.bubble[heroConfig.id]
  735. net.bubble = bubble and bubble.drawCard or ""
  736. local heroGrid = HeroGrid.getCacheHeroGridTujian(id)
  737. for key = RoleDefine.ATK, RoleDefine.SPEED do
  738. local value = heroGrid.attrs[key]
  739. attrsNum = attrsNum + 1
  740. net.attrs[attrsNum] = net.attrs[attrsNum] or {}
  741. net.attrs[attrsNum].key = key
  742. net.attrs[attrsNum].value = value
  743. attrsMaxNum = attrsMaxNum + 1
  744. net.attrsMax[attrsMaxNum] = net.attrs[attrsMaxNum] or {}
  745. net.attrsMax[attrsMaxNum].key = key
  746. net.attrsMax[attrsMaxNum].value = HeroDefine.getTujianMaxValue(key)
  747. end
  748. end
  749. end
  750. -- 根据英雄id封装英雄信息heroSimple 额外处理
  751. function makeHeroSimpleByID(net, id, index, others, human, tujian)
  752. local star = others and others.star or nil
  753. local grid = HeroGrid.getCacheHeroGrid(id, star, others)
  754. makeHeroSimple(net, grid, index, human, others, tujian)
  755. end
  756. -- 填充英雄详细信息:静态 额外格式
  757. function makeHeroStatic(net, id, tuJian)
  758. net.skillList = net.skillList or {}
  759. net.beSkill = net.beSkill or {}
  760. local cf = id and HeroExcel.hero[id]
  761. if not cf then
  762. net.id = 0
  763. net.name = ""
  764. net.body = 0
  765. net.job = 0
  766. net.weightLv = 0
  767. net.normalAtkID = 0
  768. net.skillList[0] = 0
  769. net.beSkill[0] = 0
  770. net.skin = 0
  771. return
  772. end
  773. local star = cf.star
  774. if tuJian and tuJian == 1 then
  775. local tuJianConfig = HeroExcel.tujian[id]
  776. if tuJianConfig then
  777. local maxStarIndex = #tuJianConfig.star
  778. star = tuJianConfig.star[maxStarIndex]
  779. end
  780. end
  781. net.id = id
  782. net.name = cf.name
  783. net.body = cf.body
  784. net.job = cf.job
  785. net.weightLv = cf.grade
  786. local attrConfig = HeroDefine.getAttrConfig(id, star)
  787. net.normalAtkID = attrConfig.normalAtkID
  788. for i = 1, #attrConfig.skillList do
  789. net.skillList[i] = net.skillList[i] or {}
  790. makeSkillNet(net.skillList[i], attrConfig.skillList[i])
  791. end
  792. for i = 1, #attrConfig.beSkillList do
  793. net.beSkill[i] = net.beSkill[i] or {}
  794. makeSkillNet(net.beSkill[i], attrConfig.beSkillList[i])
  795. end
  796. net.skin = #cf.skin > 0 and 1 or 0
  797. end
  798. -- 封装英雄信息 额外处理
  799. function makeHeroSimple(net, grid, index, human, others, tuJian)
  800. local id = grid and (grid.id or grid.heroID)
  801. local cf = id and HeroExcel.hero[id]
  802. local star = grid and grid.star or (cf and cf.star or 1)
  803. local upStarConfig = HeroDefine.getNextAttrConfig(id, star)
  804. local jobConfig = cf and cf.job and HeroExcel.job[cf.job]
  805. local isGongMing = XingYaoGongMing.isGongMing(human, index)
  806. net.id = id or 0
  807. net.index = index or 0
  808. net.uuid = grid and grid.uuid or ""
  809. net.gl = cf and cf.gl or 0
  810. net.camp = cf and cf.camp or 0
  811. net.job = cf and cf.job or 0
  812. net.star = others and others.star or star --cf and cf.star or 0 星级调整 dxzeng
  813. net.icon = grid and grid.head or (cf and cf.head or 0)
  814. net.body = grid and grid.body or (cf and cf.body or 0)
  815. if grid and human and index then -- todo 皮肤这个以后可能还是需要继续整理
  816. local skinConf = SkinLogic.getHeroSkin(human, index)
  817. if skinConf then
  818. net.icon = skinConf.head
  819. net.body = skinConf.body
  820. end
  821. end
  822. net.up = upStarConfig == nil and 0 or 1 --是否能够升星
  823. net.lv = others and others.lv or (grid and grid.lv or 1)
  824. net.xLv = others and others.xLv or (grid and grid.xLv or 0)
  825. net.zhandouli = grid and grid.zhandouli or 0
  826. net.quality = grid and grid.quality or 0
  827. net.isLock = (grid and grid.isLock) and 1 or 0
  828. net.hp = others and others.hp or 0
  829. net.hpMax = others and others.hpMax or 0
  830. net.cnt = others and others.cnt or 1
  831. net.isget = HeroBook.isGetHero(human, id) or 0
  832. net.weightLv = cf and cf.grade or 0
  833. net.name = cf and cf.name or ""
  834. net.grade = cf and cf.grade or 0
  835. net.jobDesc = jobConfig and jobConfig.desc or ""
  836. net.label = cf and cf.label or ""
  837. net.order = cf and cf.order or 0
  838. net.isGongMing = isGongMing or 0
  839. net.general = net.general or {}
  840. --是否发送图鉴信息
  841. if tuJian then
  842. local tj = HeroExcel.tujian[id]
  843. if tj ~= nil then
  844. net.general[1] = net.general[1] or {}
  845. net.general[1].cm = tj.cm or 0
  846. net.general[1].kg = tj.kg or 0
  847. net.general[1].age = tj.age or 0
  848. net.general[1].cup = tj.cup or ""
  849. net.general[1].character = tj.character or ""
  850. net.general[1].interest = tj.interest or ""
  851. net.general[1].desc = tj.desc or ""
  852. end
  853. end
  854. end
  855. -- 获取技能信息
  856. function makeSkillNet(net, id)
  857. local skillConfig = SkillExcel.skill[id]
  858. if not skillConfig then return end
  859. net.id = id
  860. net.icon = skillConfig.icon
  861. net.name = skillConfig.name
  862. net.type = skillConfig.type
  863. net.desc = skillConfig.desc
  864. net.need = skillConfig.need or 0
  865. net.lv = skillConfig.skillLv or 0
  866. -- todo
  867. net.cd = net.cd or {}
  868. net.buff = net.buff or {}
  869. if #skillConfig.cd ~= 0 then
  870. net.cd[1] = net.cd[1] or {}
  871. net.cd[2] = net.cd[2] or {}
  872. net.cd[1] = skillConfig.cd[1]
  873. net.cd[2] = skillConfig.cd[2]
  874. end
  875. local len = #skillConfig.buffers
  876. for i = 1, len do
  877. local buffId = skillConfig.buffers[i][1]
  878. local buffConfig = BufferExcel.buffer[buffId]
  879. net.buff[i] = net.buff[i] or {}
  880. net.buff[i].id = buffId
  881. net.buff[i].name = buffConfig.name
  882. net.buff[i].desc = buffConfig.desc
  883. end
  884. net.lvUpDesc = skillConfig.lvUpDesc
  885. -- todo
  886. end