NewLogic.lua 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  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. heroSkinLogic.query(human,panelId)
  202. end,
  203. }
  204. --[[function NewProto(human, type, paramJson)
  205. -- print("newProto:",type,param)
  206. -- local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  207. -- msgRet.ret = type
  208. -- msgRet.tip = "test data"
  209. -- Msg.send(msgRet,human.fd)
  210. local f = assert(handler[type],"invalid proto type")
  211. --local param = Json.Decode(paramJson)
  212. return f(human,paramJson)
  213. end]]
  214. -- 主动推送给客户端
  215. function PushClient(human,type,data)
  216. if not push[type] then
  217. Broadcast.sendErr(human, Lang.DRILL_CHOOSE_MY_ERR_INDEX .. " type is " .. type)
  218. return
  219. end
  220. local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  221. msgRet.ret = type
  222. msgRet.tip = Json.Encode(data)
  223. Msg.send(msgRet,human.fd)
  224. end
  225. -----------------------------------------------------------
  226. function NewProto(human, type, param)
  227. -- print("newProto:",type,param)
  228. -- local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  229. -- msgRet.ret = type
  230. -- msgRet.tip = "test data"
  231. -- Msg.send(msgRet,human.fd)
  232. local f = handler[type]
  233. if f then
  234. return f(human,param)
  235. end
  236. local msgRet = Msg.gc.GC_ROLE_CHANGE_BASEINFO
  237. -- 观看广告获取召唤券
  238. if type == AD_DRAW_REWARD_TYPE then
  239. human.db.adRewardCnt = human.db.adRewardCnt or 0
  240. if human.db.adRewardCnt > 4 then
  241. Broadcast.sendErr(human, Lang.AD_DRAW_REWARD_LIMIT_ERROR)
  242. return
  243. end
  244. --增加今日观看次数
  245. human.db.adRewardCnt = (human.db.adRewardCnt or 0) + 1
  246. Log.write(Log.LOGID_TEST, "adRewardCnt: " .. human.db.adRewardCnt)
  247. -- 添加高级召唤卷
  248. BagLogic.addItem(human, 118, 1, "draw_ad_reward")
  249. msgRet.ret = AD_DRAW_REWARD_TYPE
  250. msgRet.tip = Lang.AD_DRAW_REWARD_SUCCESS
  251. Msg.send(msgRet, human.fd)
  252. return
  253. end
  254. -- 查询加速孵化需要的钻石
  255. if type == QUERY_QUICK_HATCH_ZUANSHI then
  256. -- 初始化
  257. initMergeInfo(human)
  258. local info = {}
  259. local nowTime = os.time
  260. local hatchTime = human.db.mergeInfo.endTime - nowTime
  261. info.zuanshi = doCalcNeedZuanshi(hatchTime)
  262. info.isTip = getTodayIsTip(human)
  263. msgRet.ret = QUERY_QUICK_HATCH_ZUANSHI
  264. msgRet.tip = Json.Encode(info)
  265. Msg.send(msgRet, human.fd)
  266. return
  267. end
  268. -- 获取融合前的信息
  269. if type == QUERY_MERGE_BEFORE_INFO_TYPE then
  270. local tb = Util.split(param, "|")
  271. if tb[1] and tb[2] then
  272. -- 初始化
  273. initMergeInfo(human)
  274. human.db.heroBag = human.db.heroBag or {}
  275. local fatherHeroBagIndex = tonumber(tb[1]) or 0
  276. local motherHeroBagIndex = tonumber(tb[2]) or 0
  277. Log.write(Log.LOGID_TEST, "查询融合前的 fatherHeroBagIndex: " .. fatherHeroBagIndex)
  278. Log.write(Log.LOGID_TEST, "查询融合前的 motherHeroBagIndex: " .. motherHeroBagIndex)
  279. local fatherHeroGrid = human.db.heroBag[fatherHeroBagIndex]
  280. if not fatherHeroGrid then
  281. Log.write(Log.LOGID_TEST, "查询融合前的 fatherHeroGrid: 不存在下标:" .. fatherHeroBagIndex)
  282. return
  283. end
  284. Log.write(Log.LOGID_TEST, "查询融合前的 fatherHeroGrid: " .. Json.Encode(fatherHeroGrid))
  285. local motherHeroGrid = human.db.heroBag[motherHeroBagIndex]
  286. if not motherHeroGrid then
  287. Log.write(Log.LOGID_TEST, "查询融合前的 motherHeroGrid: 不存在下标:" .. motherHeroBagIndex)
  288. return
  289. end
  290. Log.write(Log.LOGID_TEST, "查询融合前的 motherHeroGrid: " .. Json.Encode(motherHeroGrid))
  291. local mergeInfo = {}
  292. local heroSimple = {}
  293. local xLv = getxLv(fatherHeroGrid, motherHeroGrid)
  294. local cnt = math.floor(xLv / 2) + 1
  295. local isHatch = 2
  296. local mergeItem = {}
  297. local itemId = 178
  298. for k = 1, 1 do
  299. mergeItem[k] = mergeItem[k] or {}
  300. mergeItem[k].getway = mergeItem[k].getway or {}
  301. mergeItem[k].suipian = mergeItem[k].suipian or {}
  302. mergeItem[k].equip = mergeItem[k].equip or {}
  303. mergeItem[k].fuwen = mergeItem[k].fuwen or {}
  304. Grid.makeItem(mergeItem[k], itemId, cnt)
  305. end
  306. local sonHeroID = mergeHero(fatherHeroGrid.id, motherHeroGrid.id)
  307. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  308. heroSimple.name = cf and cf.name or ""
  309. if cf.grade >= 6 then
  310. heroSimple.name = "?????"
  311. end
  312. mergeInfo.mergeTime = 0
  313. mergeInfo.xLv = xLv
  314. mergeInfo.mergeItem = mergeItem
  315. mergeInfo.heroData = heroSimple
  316. mergeInfo.isHatch = isHatch
  317. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  318. mergeInfo.isTip = getTodayIsTip(human)
  319. Log.write(Log.LOGID_TEST, "查询融合前的 mergeInfo: " .. Json.Encode(mergeInfo))
  320. msgRet.ret = QUERY_MERGE_BEFORE_INFO_TYPE
  321. msgRet.tip = Json.Encode(mergeInfo)
  322. Msg.send(msgRet, human.fd)
  323. end
  324. return
  325. end
  326. -- 开始融合
  327. if type == MERGE_HERO_TYPE then
  328. local tb = Util.split(param, "|")
  329. if tb[1] and tb[2] then
  330. -- 初始化
  331. initMergeInfo(human)
  332. human.db.heroBag = human.db.heroBag or {}
  333. Log.write(Log.LOGID_TEST, "融合 human.db.heroBag: " .. Json.Encode(human.db.heroBag))
  334. local itemId = 178 --生命雨露
  335. local fatherHeroBagIndex = tonumber(tb[1]) or 0
  336. local motherHeroBagIndex = tonumber(tb[2]) or 0
  337. Log.write(Log.LOGID_TEST, "融合 fatherHeroBagIndex: " .. fatherHeroBagIndex)
  338. Log.write(Log.LOGID_TEST, "融合 motherHeroBagIndex: " .. motherHeroBagIndex)
  339. local fatherHeroGrid = human.db.heroBag[fatherHeroBagIndex]
  340. if not fatherHeroGrid then
  341. return
  342. end
  343. Log.write(Log.LOGID_TEST, "融合 fatherHeroGrid: " .. Json.Encode(fatherHeroGrid))
  344. local motherHeroGrid = human.db.heroBag[motherHeroBagIndex]
  345. if not motherHeroGrid then
  346. return
  347. end
  348. Log.write(Log.LOGID_TEST, "融合 motherHeroGrid: " .. Json.Encode(motherHeroGrid))
  349. local fatherHeroAttr = ObjHuman.getHeroAttrs(human, fatherHeroBagIndex)
  350. local motherHeroAttr = ObjHuman.getHeroAttrs(human, motherHeroBagIndex)
  351. local mergeInfo = {}
  352. local attrs = RoleDefine.PANEL_ATTR_KEY
  353. if fatherHeroGrid.lv < 100 or motherHeroGrid.lv < 100 then
  354. Broadcast.sendErr(human, Lang.MERGE_LV_NOT_ENOUGHT_FAIL)
  355. return
  356. end
  357. local sonHeroID = mergeHero(fatherHeroGrid.id, motherHeroGrid.id)
  358. if sonHeroID <= 0 then
  359. return
  360. end
  361. for key, value in pairs(attrs) do
  362. local param1 = fatherHeroAttr[key] or 0
  363. local param2 = motherHeroAttr[key] or 0
  364. attrs[key] = math.floor(((param1 + param2) / 4))
  365. end
  366. Log.write(Log.LOGID_TEST, "融合后的属性: " .. Json.Encode(attrs))
  367. local xLv = getxLv(fatherHeroGrid, motherHeroGrid)
  368. local cnt = math.floor(xLv / 2) + 1
  369. local heroSimple = {}
  370. local isHatch = 1
  371. Log.write(Log.LOGID_TEST, "xLv: " .. xLv)
  372. Log.write(Log.LOGID_TEST, "cnt: " .. cnt)
  373. local bagCnt = BagLogic.getItemCnt(human, itemId, true)
  374. if bagCnt < cnt then
  375. Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
  376. return
  377. end
  378. --使用道具
  379. ItemLogic.use(human, itemId, cnt)
  380. local delHeroList = { [1] = fatherHeroBagIndex, [2] = motherHeroBagIndex }
  381. for key, heroIndex in pairs(delHeroList) do
  382. local heroID = HeroLogic.getHeroIdByIndex(human, heroIndex)
  383. --脱装备
  384. HeroEquip.putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_WEAPON, false, true)
  385. HeroEquip.putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_CLOTH, false, true)
  386. HeroEquip.putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHOES, false, true)
  387. HeroEquip.putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHIPIN, false, true)
  388. -- HeroEquip.putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHENQI, false, true)
  389. HeroEquip.putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_RING, false, true)
  390. HeroEquip.putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_AMULET, false, true)
  391. --脱符文
  392. FuwenLogic.putOff(human, heroID, heroIndex, 1, false, true)
  393. FuwenLogic.putOff(human, heroID, heroIndex, 2, false, true)
  394. HeroLogic.delHeroByIndex(human, heroIndex, "hero_merge")
  395. end
  396. -- 记录融合英雄
  397. human.db.mergeInfo.heroInfo.heroID = sonHeroID
  398. human.db.mergeInfo.heroInfo.xLv = xLv
  399. human.db.mergeInfo.heroInfo.heroAttrs = attrs
  400. human.db.mergeInfo.startTime = os.time()
  401. human.db.mergeInfo.endTime = os.time() + getHatchTime(xLv)
  402. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = fatherHeroBagIndex
  403. human.db.mergeInfo.heroInfo.motherHeroBagIndex = motherHeroBagIndex
  404. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  405. heroSimple.name = cf and cf.name or ""
  406. if cf.grade >= 6 then
  407. heroSimple.name = "?????"
  408. end
  409. if getHatchTime(xLv) == 0 then
  410. isHatch = 3
  411. end
  412. mergeInfo.mergeTime = getHatchTime(xLv)
  413. mergeInfo.xLv = xLv
  414. mergeInfo.heroData = heroSimple
  415. mergeInfo.isHatch = isHatch
  416. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  417. mergeInfo.isTip = getTodayIsTip(human)
  418. Log.write(Log.LOGID_TEST, "融合 mergeInfo: " .. Json.Encode(mergeInfo))
  419. Broadcast.sendErr(human, Lang.MERGE_SUCCESS)
  420. msgRet.ret = MERGE_HERO_TYPE
  421. msgRet.tip = Json.Encode(mergeInfo)
  422. Msg.send(msgRet, human.fd)
  423. end
  424. return
  425. end
  426. -- 获取融合中的信息
  427. if type == QUERY_MERGE_INFO_TYPE then
  428. -- 初始化
  429. initMergeInfo(human)
  430. human.db.heroBag = human.db.heroBag or {}
  431. local mergeInfo = {}
  432. local mergeTime = 0
  433. local heroSimple = {}
  434. local xLv = human.db.mergeInfo.heroInfo.xLv or 0
  435. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  436. local isHatch = 2
  437. if sonHeroID == 0 then
  438. mergeInfo.mergeTime = mergeTime
  439. mergeInfo.xLv = xLv
  440. mergeInfo.heroData = heroSimple
  441. mergeInfo.isHatch = isHatch
  442. msgRet.ret = QUERY_MERGE_INFO_TYPE
  443. msgRet.tip = Json.Encode(mergeInfo)
  444. Msg.send(msgRet, human.fd)
  445. return
  446. end
  447. local mergeTime = human.db.mergeInfo.endTime - os.time()
  448. if mergeTime <= 0 then
  449. -- 孵化成功
  450. mergeTime = 0
  451. isHatch = 3
  452. else
  453. isHatch = 1
  454. end
  455. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  456. heroSimple.name = cf and cf.name or ""
  457. if cf.grade >= 6 then
  458. heroSimple.name = "?????"
  459. end
  460. mergeInfo.mergeTime = mergeTime
  461. mergeInfo.xLv = xLv
  462. mergeInfo.heroData = heroSimple
  463. mergeInfo.isHatch = isHatch
  464. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  465. mergeInfo.isTip = getTodayIsTip(human)
  466. msgRet.ret = QUERY_MERGE_INFO_TYPE
  467. msgRet.tip = Json.Encode(mergeInfo)
  468. Log.write(Log.LOGID_TEST, "融合中 msgRet: " .. Json.Encode(msgRet))
  469. Msg.send(msgRet, human.fd)
  470. return
  471. end
  472. -- 获取融合英雄
  473. if type == GET_MERGE_HERO_TYPE then
  474. local nowTime = os.time()
  475. local mergeInfo = {}
  476. local heroSimple = {}
  477. local xLv = human.db.mergeInfo.heroInfo.xLv or 0
  478. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  479. local hatchTime = human.db.mergeInfo.endTime - nowTime
  480. local isHatch = 2
  481. local heroIndex = 0
  482. local msgTyep = GET_MERGE_HERO_TYPE
  483. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  484. local heroNiceNet = {}
  485. if hatchTime <= 0 then
  486. -- 孵化成功
  487. hatchTime = 0
  488. heroIndex = hatchHero(human)
  489. local heroGrid = human.db.heroBag[heroIndex]
  490. if not heroGrid then return end
  491. heroSimple.general = heroSimple.general or {}
  492. HeroGrid.makeHeroSimple(heroSimple, heroGrid, heroIndex, human)
  493. local heroID = heroGrid.id or 0
  494. local isNew = not HeroBook.isGet(human, cf.id, cf.star)
  495. makeHeroNice(heroNiceNet, heroID, nil, isNew, heroIndex)
  496. else
  497. heroSimple.name = cf and cf.name or ""
  498. if cf.grade >= 6 then
  499. heroSimple.name = "?????"
  500. end
  501. isHatch = 1
  502. msgTyep = QUERY_MERGE_INFO_TYPE
  503. end
  504. mergeInfo.mergeTime = hatchTime
  505. mergeInfo.xLv = xLv
  506. mergeInfo.heroData = heroSimple
  507. mergeInfo.isHatch = isHatch
  508. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  509. mergeInfo.isTip = getTodayIsTip(human)
  510. mergeInfo.heroNiceNet = heroNiceNet
  511. msgRet.ret = msgTyep
  512. msgRet.tip = Json.Encode(mergeInfo)
  513. Log.write(Log.LOGID_TEST, "获取英雄 ret: " .. Json.Encode(msgRet))
  514. Msg.send(msgRet, human.fd)
  515. return
  516. end
  517. -- 加速孵化
  518. if type == QUICK_HATCH_TYPE then
  519. local tb = Util.split(param, "|")
  520. local quickType = tonumber(tb[1]) or 0
  521. local cnt = tonumber(tb[2]) or 0
  522. local isHatch = 1
  523. if tb[1] and tb[2] then
  524. -- 初始化
  525. initMergeInfo(human)
  526. -- 剩余时间
  527. local nowTime = os.time()
  528. local hatchTime = human.db.mergeInfo.endTime - nowTime
  529. if hatchTime <= 0
  530. then
  531. Broadcast.sendErr(human, Lang.QUICK_HATCH_TIME_OUT)
  532. return
  533. end
  534. local itemSpeedTime = 0
  535. if quickType == 1 then
  536. local speedTime = (60 * 5 * cnt) -- 正常数量加速券的加速时间
  537. local lastSpeedTime = (60 * 5 * (cnt - 1)) --少一张加速券的加速时间
  538. local itemCnt = 0
  539. if hatchTime > lastSpeedTime and hatchTime <= speedTime then
  540. itemCnt = cnt
  541. elseif hatchTime > 0 and hatchTime <= lastSpeedTime then
  542. itemCnt = cnt - 1
  543. elseif hatchTime >= speedTime then
  544. itemCnt = cnt
  545. else
  546. itemCnt = 0
  547. end
  548. itemSpeedTime = (60 * 5 * itemCnt)
  549. local bagCnt = BagLogic.getItemCnt(human, 179, true)
  550. if bagCnt < itemCnt then
  551. Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
  552. return
  553. end
  554. --使用道具
  555. ItemLogic.use(human, 179, cnt)
  556. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
  557. elseif quickType == 2 then
  558. local zuanshiCnt = doCalcNeedZuanshi(hatchTime)
  559. -- 判断消耗
  560. if not ObjHuman.checkRMB(human, zuanshiCnt) then
  561. return
  562. end
  563. itemSpeedTime = (30 * zuanshiCnt)
  564. -- 扣钻石
  565. ObjHuman.decZuanshi(human, -zuanshiCnt, "hero_merge")
  566. if tb[3] then
  567. human.db.isTip = human.db.isTip or 1
  568. human.db.isTip = tonumber(tb[3])
  569. end
  570. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
  571. elseif quickType == 3 then
  572. human.db.adHatchRewardCnt = human.db.adHatchRewardCnt or 0
  573. if human.db.adHatchRewardCnt > 4 then
  574. Broadcast.sendErr(human, Lang.AD_HATCH_REWARD_LIMIT_ERROR)
  575. return
  576. end
  577. --加速30分钟
  578. itemSpeedTime = 30 * 60
  579. --增加今日观看次数
  580. human.db.adHatchRewardCnt = (human.db.adHatchRewardCnt or 0) + 1
  581. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
  582. end
  583. local hatchTime = human.db.mergeInfo.endTime - nowTime
  584. -- 孵化成功
  585. if hatchTime < 0 then
  586. hatchTime = 0
  587. isHatch = 3
  588. end
  589. local mergeInfo = {}
  590. local heroSimple = {}
  591. local sonHeroID = human.db.mergeInfo.heroInfo.heroID or 0
  592. local cf = sonHeroID and HeroExcel.hero[sonHeroID]
  593. heroSimple.name = cf and cf.name or ""
  594. if cf.grade >= 6 then
  595. heroSimple.name = "?????"
  596. end
  597. mergeInfo.mergeTime = hatchTime
  598. mergeInfo.heroData = heroSimple
  599. mergeInfo.xLv = human.db.mergeInfo.heroInfo.xLv
  600. mergeInfo.isHatch = isHatch
  601. mergeInfo.adHatchRewardCnt = getResetAdHatchCnt(human)
  602. mergeInfo.isTip = getTodayIsTip(human)
  603. msgRet.ret = QUICK_HATCH_TYPE
  604. msgRet.tip = Json.Encode(mergeInfo)
  605. Log.write(Log.LOGID_TEST, "加速孵化 ret: " .. Json.Encode(msgRet))
  606. Msg.send(msgRet, human.fd)
  607. return
  608. end
  609. return
  610. end
  611. end
  612. -- 孵化英雄
  613. function hatchHero(human)
  614. Log.write(Log.LOGID_TEST, "孵化英雄id " .. human.db.mergeInfo.heroInfo.heroID)
  615. --添加英雄
  616. local heroIndex, fjlist = HeroLogic.addHero(human, human.db.mergeInfo.heroInfo.heroID, nil, 1,
  617. "hero_merge")
  618. Log.write(Log.LOGID_TEST, "孵化英雄成功 下标" .. heroIndex)
  619. local attrs = RoleDefine.PANEL_ATTR_KEY
  620. for key, value in pairs(attrs) do
  621. attrs[key] = 1
  622. end
  623. human.db.mergeInfo.startTime = 0
  624. human.db.mergeInfo.endTime = 0
  625. human.db.mergeInfo.heroInfo = {}
  626. human.db.mergeInfo.heroInfo.heroID = 0
  627. human.db.mergeInfo.heroInfo.xLv = 0
  628. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = 0
  629. human.db.mergeInfo.heroInfo.motherHeroBagIndex = 0
  630. human.db.mergeInfo.heroInfo.heroAttrs = attrs
  631. Log.write(Log.LOGID_TEST, "孵化重置 mergeInfo: " .. Json.Encode(human.db.mergeInfo))
  632. return heroIndex
  633. end
  634. -- 初始化融合信息
  635. function initMergeInfo(human)
  636. human.db.mergeInfo = human.db.mergeInfo or {}
  637. human.db.mergeInfo.startTime = human.db.mergeInfo.startTime or 0 --融合时间 时间戳
  638. human.db.mergeInfo.endTime = human.db.mergeInfo.endTime or 0 --孵化时间 单位s
  639. human.db.mergeInfo.heroInfo = human.db.mergeInfo.heroInfo or {}
  640. human.db.mergeInfo.heroInfo.heroID = human.db.mergeInfo.heroInfo.heroID or 0
  641. human.db.mergeInfo.heroInfo.xLv = human.db.mergeInfo.heroInfo.xLv or 0
  642. human.db.mergeInfo.heroInfo.fatherHeroBagIndex = human.db.mergeInfo.heroInfo.fatherHeroBagIndex or 0
  643. human.db.mergeInfo.heroInfo.motherHeroBagIndex = human.db.mergeInfo.heroInfo.motherHeroBagIndex or 0
  644. human.db.mergeInfo.heroInfo.heroAttrs = human.db.mergeInfo.heroInfo.heroAttrs or RoleDefine.PANEL_ATTR_KEY
  645. end
  646. -- 获取孵化时间 单位s
  647. function getHatchTime(xLv)
  648. local time = (xLv * 5) + (xLv - 1) * (xLv - 1) - 5
  649. if time < 0 then
  650. return 0
  651. end
  652. return time * 60
  653. end
  654. -- 计算需要钻石数量
  655. function doCalcNeedZuanshi(hatchTime)
  656. local cnt = 0
  657. if hatchTime > 0 then
  658. cnt = math.ceil(hatchTime / 30)
  659. end
  660. return cnt
  661. end
  662. -- 获取xlv
  663. function getxLv(fatherHeroGrid, motherHeroGrid)
  664. local fatherHeroXLv = fatherHeroGrid.xLv or 0
  665. local motherHeroXLv = motherHeroGrid.xLv or 0
  666. local params1 = math.max(fatherHeroXLv, motherHeroXLv)
  667. local params2 = math.floor((fatherHeroGrid.lv + motherHeroGrid.lv) / 200) + 1
  668. local xLv = params1 + params2
  669. if xLv > 50 then
  670. return 50
  671. end
  672. return xLv
  673. end
  674. -- 融合获取英雄ID
  675. function mergeHero(fatherHeroID, motherHeroID)
  676. local fatherHeroConfig = HeroExcel.hero[fatherHeroID]
  677. local motherHeroConfig = HeroExcel.hero[motherHeroID]
  678. if not fatherHeroConfig or not motherHeroConfig then
  679. return 0
  680. end
  681. --规则3 heroID + heroID
  682. for _, config in pairs(MergeRule[3].items) do
  683. if fatherHeroID == config[1] and motherHeroID == config[2] then
  684. return config[3]
  685. end
  686. end
  687. --规则2 种族 + heroID
  688. for _, config in pairs(MergeRule[2].items) do
  689. if fatherHeroConfig.camp == config[1] and motherHeroID == config[2] then
  690. return config[3]
  691. end
  692. end
  693. --规则1 种族 + 种族
  694. for _, config in pairs(MergeRule[1].items) do
  695. if fatherHeroConfig.camp == config[1] and motherHeroConfig.camp == config[2] then
  696. return config[3]
  697. end
  698. end
  699. return 0
  700. end
  701. -- 获取剩余融化孵化加速广告观看次数
  702. function getResetAdHatchCnt(human)
  703. local adHatchRewardCnt = human.db.adHatchRewardCnt or 0
  704. return math.max(AD_HATCH_RESET_FREECNT - adHatchRewardCnt, 0)
  705. end
  706. -- 获取是否今日不再提示
  707. function getTodayIsTip(human)
  708. local isTip = human.db.isTip or 1
  709. return tonumber(isTip)
  710. end
  711. -- 封装客户端需要的json格式
  712. function makeHeroNice(net, id, cnt, isNew, index)
  713. net.heroSimple = net.heroSimple or {}
  714. net.itemData = net.itemData or {}
  715. net.heroStatic = net.heroStatic or {}
  716. net.attrs = net.attrs or {}
  717. net.attrsMax = net.attrsMax or {}
  718. if cnt then
  719. net.itemData[1] = net.itemData[1] or {}
  720. Grid.makeItem(net.itemData[1], id, cnt)
  721. end
  722. local heroConfig = HeroExcel.hero[id]
  723. local specialConfig = HeroExcel.specialHero[id]
  724. if heroConfig then
  725. net.heroSimple[1] = net.heroSimple[1] or {}
  726. net.heroStatic[1] = net.heroStatic[1] or {}
  727. makeHeroSimpleByID(net.heroSimple[1], id, index)
  728. makeHeroStatic(net.heroStatic[1], id)
  729. end
  730. net.body = specialConfig and (heroConfig and heroConfig.body or 0) or 0
  731. net.isNew = isNew and 1 or 0
  732. net.weightLv = heroConfig and heroConfig.grade or 0
  733. net.bubble = ""
  734. local attrsNum = 0
  735. local attrsMaxNum = 0
  736. if heroConfig then
  737. local bubble = PaomaExcel.bubble[heroConfig.id]
  738. net.bubble = bubble and bubble.drawCard or ""
  739. local heroGrid = HeroGrid.getCacheHeroGridTujian(id)
  740. for key = RoleDefine.ATK, RoleDefine.SPEED do
  741. local value = heroGrid.attrs[key]
  742. attrsNum = attrsNum + 1
  743. net.attrs[attrsNum] = net.attrs[attrsNum] or {}
  744. net.attrs[attrsNum].key = key
  745. net.attrs[attrsNum].value = value
  746. attrsMaxNum = attrsMaxNum + 1
  747. net.attrsMax[attrsMaxNum] = net.attrs[attrsMaxNum] or {}
  748. net.attrsMax[attrsMaxNum].key = key
  749. net.attrsMax[attrsMaxNum].value = HeroDefine.getTujianMaxValue(key)
  750. end
  751. end
  752. end
  753. -- 根据英雄id封装英雄信息heroSimple 额外处理
  754. function makeHeroSimpleByID(net, id, index, others, human, tujian)
  755. local star = others and others.star or nil
  756. local grid = HeroGrid.getCacheHeroGrid(id, star, others)
  757. makeHeroSimple(net, grid, index, human, others, tujian)
  758. end
  759. -- 填充英雄详细信息:静态 额外格式
  760. function makeHeroStatic(net, id, tuJian)
  761. net.skillList = net.skillList or {}
  762. net.beSkill = net.beSkill or {}
  763. local cf = id and HeroExcel.hero[id]
  764. if not cf then
  765. net.id = 0
  766. net.name = ""
  767. net.body = 0
  768. net.job = 0
  769. net.weightLv = 0
  770. net.normalAtkID = 0
  771. net.skillList[0] = 0
  772. net.beSkill[0] = 0
  773. net.skin = 0
  774. return
  775. end
  776. local star = cf.star
  777. if tuJian and tuJian == 1 then
  778. local tuJianConfig = HeroExcel.tujian[id]
  779. if tuJianConfig then
  780. local maxStarIndex = #tuJianConfig.star
  781. star = tuJianConfig.star[maxStarIndex]
  782. end
  783. end
  784. net.id = id
  785. net.name = cf.name
  786. net.body = cf.body
  787. net.job = cf.job
  788. net.weightLv = cf.grade
  789. local attrConfig = HeroDefine.getAttrConfig(id, star)
  790. net.normalAtkID = attrConfig.normalAtkID
  791. for i = 1, #attrConfig.skillList do
  792. net.skillList[i] = net.skillList[i] or {}
  793. makeSkillNet(net.skillList[i], attrConfig.skillList[i])
  794. end
  795. for i = 1, #attrConfig.beSkillList do
  796. net.beSkill[i] = net.beSkill[i] or {}
  797. makeSkillNet(net.beSkill[i], attrConfig.beSkillList[i])
  798. end
  799. net.skin = #cf.skin > 0 and 1 or 0
  800. end
  801. -- 封装英雄信息 额外处理
  802. function makeHeroSimple(net, grid, index, human, others, tuJian)
  803. local id = grid and (grid.id or grid.heroID)
  804. local cf = id and HeroExcel.hero[id]
  805. local star = grid and grid.star or (cf and cf.star or 1)
  806. local upStarConfig = HeroDefine.getNextAttrConfig(id, star)
  807. local jobConfig = cf and cf.job and HeroExcel.job[cf.job]
  808. local isGongMing = XingYaoGongMing.isGongMing(human, index)
  809. net.id = id or 0
  810. net.index = index or 0
  811. net.uuid = grid and grid.uuid or ""
  812. net.gl = cf and cf.gl or 0
  813. net.camp = cf and cf.camp or 0
  814. net.job = cf and cf.job or 0
  815. net.star = others and others.star or star --cf and cf.star or 0 星级调整 dxzeng
  816. net.icon = grid and grid.head or (cf and cf.head or 0)
  817. net.body = grid and grid.body or (cf and cf.body or 0)
  818. if grid and human and index then -- todo 皮肤这个以后可能还是需要继续整理
  819. local skinConf = SkinLogic.getHeroSkin(human, index)
  820. if skinConf then
  821. net.icon = skinConf.head
  822. net.body = skinConf.body
  823. end
  824. end
  825. net.up = upStarConfig == nil and 0 or 1 --是否能够升星
  826. net.lv = others and others.lv or (grid and grid.lv or 1)
  827. net.xLv = others and others.xLv or (grid and grid.xLv or 0)
  828. net.zhandouli = grid and grid.zhandouli or 0
  829. net.quality = grid and grid.quality or 0
  830. net.isLock = (grid and grid.isLock) and 1 or 0
  831. net.hp = others and others.hp or 0
  832. net.hpMax = others and others.hpMax or 0
  833. net.cnt = others and others.cnt or 1
  834. net.isget = HeroBook.isGetHero(human, id) or 0
  835. net.weightLv = cf and cf.grade or 0
  836. net.name = cf and cf.name or ""
  837. net.grade = cf and cf.grade or 0
  838. net.jobDesc = jobConfig and jobConfig.desc or ""
  839. net.label = cf and cf.label or ""
  840. net.order = cf and cf.order or 0
  841. net.isGongMing = isGongMing or 0
  842. net.general = net.general or {}
  843. --是否发送图鉴信息
  844. if tuJian then
  845. local tj = HeroExcel.tujian[id]
  846. if tj ~= nil then
  847. net.general[1] = net.general[1] or {}
  848. net.general[1].cm = tj.cm or 0
  849. net.general[1].kg = tj.kg or 0
  850. net.general[1].age = tj.age or 0
  851. net.general[1].cup = tj.cup or ""
  852. net.general[1].character = tj.character or ""
  853. net.general[1].interest = tj.interest or ""
  854. net.general[1].desc = tj.desc or ""
  855. end
  856. end
  857. end
  858. -- 获取技能信息
  859. function makeSkillNet(net, id)
  860. local skillConfig = SkillExcel.skill[id]
  861. if not skillConfig then return end
  862. net.id = id
  863. net.icon = skillConfig.icon
  864. net.name = skillConfig.name
  865. net.type = skillConfig.type
  866. net.desc = skillConfig.desc
  867. net.need = skillConfig.need or 0
  868. net.lv = skillConfig.skillLv or 0
  869. -- todo
  870. net.cd = net.cd or {}
  871. net.buff = net.buff or {}
  872. if #skillConfig.cd ~= 0 then
  873. net.cd[1] = net.cd[1] or {}
  874. net.cd[2] = net.cd[2] or {}
  875. net.cd[1] = skillConfig.cd[1]
  876. net.cd[2] = skillConfig.cd[2]
  877. end
  878. local len = #skillConfig.buffers
  879. for i = 1, len do
  880. local buffId = skillConfig.buffers[i][1]
  881. local buffConfig = BufferExcel.buffer[buffId]
  882. net.buff[i] = net.buff[i] or {}
  883. net.buff[i].id = buffId
  884. net.buff[i].name = buffConfig.name
  885. net.buff[i].desc = buffConfig.desc
  886. end
  887. net.lvUpDesc = skillConfig.lvUpDesc
  888. -- todo
  889. end