HeroLogic.lua 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092
  1. ---------------------------------------------------------------
  2. -- 英雄逻辑
  3. -- addHero 根据英雄id添加英雄
  4. -- addHeroByGrid 根据英雄grid添加英雄(注意grid没有被其它地方引用)
  5. -- delHeroByIndex 根据英雄下表删除英雄
  6. ---------------------------------------------------------------
  7. local HeroExcel = require("excel.hero")
  8. local UpNeedExcel = require("excel.upNeed")
  9. local TequanExcel = require("excel.qqTequan")
  10. local SkillExcel = require("excel.skill")
  11. local BufferExcel = require("excel.buffer")
  12. local SkinExcel = require("excel.skin")
  13. local EquipExcel = require("excel.equip")
  14. local Log = require("common.Log")
  15. local LogDefine = require("common.LogDefine")
  16. local Lang = require("common.Lang")
  17. local Util = require("common.Util")
  18. local Msg = require("core.Msg")
  19. local ObjHuman = require("core.ObjHuman")
  20. local Grid = require("bag.Grid")
  21. local BagLogic = require("bag.BagLogic")
  22. local ItemDefine = require("bag.ItemDefine")
  23. local Broadcast = require("broadcast.Broadcast")
  24. local BarTaskLogic = require("bar.BarTaskLogic")
  25. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  26. local RoleAttr = require("role.RoleAttr")
  27. local RoleDefine = require("role.RoleDefine")
  28. local RoleHeadLogic = require("role.RoleHeadLogic")
  29. local RoleDBLogic = require("role.RoleDBLogic")
  30. local HeroBook = require("hero.HeroBook")
  31. local HeroGrid = require("hero.HeroGrid")
  32. local HeroDefine = require("hero.HeroDefine")
  33. local HeroEquip = require("hero.HeroEquip")
  34. local CombatPosLogic = require("combat.CombatPosLogic")
  35. local CombatDefine = require("combat.CombatDefine")
  36. local SkinLogic = require("skin.SkinLogic")
  37. local FenjieLogic = require("hecheng.FenjieLogic")
  38. local MonthHecJuex = require("monthAct.MonthHecJuex")
  39. local JjcLogic = require("jjc.JjcLogic")
  40. local HechengLogic = require("hecheng.HechengLogic")
  41. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  42. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  43. local GuideLogic = require("guide.GuideLogic")
  44. local RoleLogic = require("role.RoleLogic")
  45. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  46. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  47. local TuiSongLiBao = require("present.TuiSongLiBao")
  48. local SuipianLogic = require("bag.SuipianLogic")
  49. local MoshouLogic = require("moshou.MoshouLogic")
  50. local LiLianLogic = require("dailyTask.LiLianLogic")
  51. local VipLogic = require("vip.VipLogic")
  52. local FuwenLogic = require("fuwen.FuwenLogic")
  53. local GlobalWorld = require("core.GlobalWorld")
  54. local SysParameter = require("common.SysParameter")
  55. local JibanLogic = require("combat.JibanLogic")
  56. local HeroLogic = require("hero.HeroLogic")
  57. local EquipLogic = require("equip.EquipLogic")
  58. local XingYaoGongMing = require("xingYaoMen.XingYaoGongMing")
  59. local HeroGrowUp = require("absAct.HeroGrowUp")
  60. local MengxinLogic = require("present.MengxinLogic")
  61. local Config = require("Config")
  62. local HeroLogLogic = require("absAct.HeroLogLogic")
  63. local ExclusiveTaskLogic = require("absAct.ExclusiveTaskLogic")
  64. local BingshuLogic = require("fuwen.BingshuLogic")
  65. local YunYingLogic = require("yunying.YunYingLogic")
  66. local BingshuLogic = require("fuwen.BingshuLogic")
  67. local Json = require("common.Json")
  68. HERO_MAX_STAR = 15 -- 目前英雄最大星级
  69. local HERO_RESET_FREECNT = 3 -- 每日重置次数
  70. local HERO_RESET_MAXSTAR = 9 -- 只能重置9星以下(包含9星)
  71. local CHONGSHENG_RETURN_STAR = 5 -- 重生返还x星本体碎片
  72. ----------------------------------- 结构体封装 --------------------------------------
  73. -- 获取技能信息
  74. function makeSkillNet(net, id)
  75. local skillConfig = SkillExcel.skill[id]
  76. if not skillConfig then return end
  77. net.id = id
  78. net.icon = skillConfig.icon
  79. net.name = skillConfig.name
  80. net.type = skillConfig.type
  81. net.desc = skillConfig.desc
  82. net.need = skillConfig.need or 0
  83. net.lv = skillConfig.skillLv or 0
  84. -- todo
  85. net.cd[0] = #skillConfig.cd
  86. if net.cd[0] ~= 0 then
  87. net.cd[1] = skillConfig.cd[1]
  88. net.cd[2] = skillConfig.cd[2]
  89. end
  90. local len = #skillConfig.buffers
  91. for i = 1, len do
  92. local buffId = skillConfig.buffers[i][1]
  93. local buffConfig = BufferExcel.buffer[buffId]
  94. net.buff[i].id = buffId
  95. net.buff[i].name = buffConfig.name
  96. net.buff[i].desc = buffConfig.desc
  97. end
  98. net.buff[0] = len
  99. net.lvUpDesc = skillConfig.lvUpDesc
  100. -- todo
  101. end
  102. -- 封装UpStarCond协议结构体
  103. function makeUpStarCond(net, cond)
  104. local ttype = cond[1]
  105. net.type = ttype
  106. if ttype == HechengLogic.COND_TYPE_HEROID then
  107. local heroID = cond[2]
  108. local heroConfig = HeroExcel.hero[heroID]
  109. local star = cond[4] or heroConfig.star
  110. net.id = heroID
  111. net.icon = heroConfig.head
  112. net.star = star
  113. net.camp = heroConfig.camp
  114. net.name = heroConfig.name
  115. net.grade = heroConfig.grade
  116. net.cnt = cond[3]
  117. elseif ttype == HechengLogic.COND_TYPE_CAMPSTAR then
  118. net.id = 0
  119. net.icon = 0
  120. net.name = ""
  121. net.grade = 0
  122. net.camp = cond[2]
  123. net.star = cond[3]
  124. net.cnt = cond[4]
  125. end
  126. end
  127. -------------------------------- 英雄属性计算 ------------------------------------------
  128. --等级加成
  129. local function lvAdd(lv, upAttrs, attrs)
  130. for _, upAttr in ipairs(upAttrs) do
  131. local key = upAttr[1]
  132. local value = upAttr[2]
  133. attrs[key] = attrs[key] + value * (lv - 1)
  134. end
  135. end
  136. --星級加成
  137. local function starAdd(star, atkStarRate, hpStarRate, attrs)
  138. attrs[RoleDefine.ATK] = attrs[RoleDefine.ATK] * (1 + atkStarRate / 10000)
  139. attrs[RoleDefine.HP] = attrs[RoleDefine.HP] * (1 + hpStarRate / 10000)
  140. end
  141. --阶数加成
  142. local function qualityAdd(heroConfig, quality, attrs)
  143. local qualityConfig = HeroExcel.quality[heroConfig.quality]
  144. local qualityEnd = quality + 1
  145. for i = 1, qualityEnd do
  146. for key, rateConfig in pairs(qualityConfig) do
  147. local rate = rateConfig[i]
  148. if rate then
  149. if key == RoleDefine.DEF or key == RoleDefine.SPEED then
  150. attrs[key] = attrs[key] + rate[1]
  151. else
  152. attrs[key] = attrs[key] * rate[1]
  153. end
  154. end
  155. end
  156. end
  157. end
  158. -- 伙伴基础
  159. function doCalcHero(grid, attrs)
  160. if not grid and attrs then return end
  161. local heroConfig = HeroExcel.hero[grid.id]
  162. local attrConfig = HeroDefine.getAttrConfig(grid.id, grid.star)
  163. if not attrConfig then
  164. assert(nil, "attrConfig is nil id " .. grid.id .. " star " .. grid.star)
  165. end
  166. for _, v in ipairs(attrConfig.attrs) do
  167. RoleAttr.updateValue(v[1], v[2], attrs)
  168. end
  169. lvAdd(grid.lv, attrConfig.up, attrs)
  170. starAdd(grid.star, attrConfig.atkStarRate, attrConfig.hpStarRate, attrs)
  171. qualityAdd(heroConfig, grid.quality, attrs)
  172. end
  173. -- 融合伙伴基础
  174. function doCalcMergeHero(grid, attrs)
  175. if not grid and attrs then return end
  176. local mergeHeroAttrs = grid.mergeHeroAttrs
  177. local heroConfig = HeroExcel.hero[grid.id]
  178. local attrConfig = HeroDefine.getAttrConfig(grid.id, grid.star)
  179. if not attrConfig then
  180. assert(nil, "attrConfig is nil id " .. grid.id .. " star " .. grid.star)
  181. end
  182. if type(mergeHeroAttrs) == "table" and next(mergeHeroAttrs) ~= nil then
  183. for k, v in pairs(mergeHeroAttrs) do
  184. RoleAttr.updateValue(k, v, attrs)
  185. end
  186. else
  187. for _, v in ipairs(attrConfig.attrs) do
  188. RoleAttr.updateValue(v[1], v[2], attrs)
  189. end
  190. end
  191. lvAdd(grid.lv, attrConfig.up, attrs)
  192. starAdd(grid.star, attrConfig.atkStarRate, attrConfig.hpStarRate, attrs)
  193. qualityAdd(heroConfig, grid.quality, attrs)
  194. end
  195. -- 时装
  196. function doCalcHeroSkin(skinID, attrs)
  197. local skinConfig = SkinExcel.skin[skinID]
  198. for _, v in ipairs(skinConfig.attrs) do
  199. RoleAttr.updateValue(v[1], v[2], attrs)
  200. end
  201. end
  202. -------------------------------------------------------------------------------------
  203. -------------------------------------------------------------------------------------
  204. local function sortZhanli(a, b)
  205. return a[2] > b[2]
  206. end
  207. -- 下发英雄背包列表
  208. function sendHeroBagList(human)
  209. local msgRet = Msg.gc.GC_HERO_BAG_LIST
  210. local cnt = 0
  211. human.maxZDL = {}
  212. human.maxZDL.maxHero = {}
  213. human.maxZDL.heroCnt = 0
  214. human.maxZDL.zhandouli = 0
  215. local list = {}
  216. for index = 1, human.db.heroBag[0] do
  217. local heroGrid = human.db.heroBag[index]
  218. if heroGrid then
  219. cnt = cnt + 1
  220. HeroGrid.makeHeroSimple(msgRet.list[cnt], heroGrid, index, human)
  221. if cnt >= HeroDefine.PAGE_HERO_COUNT then
  222. msgRet.list[0] = cnt
  223. Msg.send(msgRet, human.fd)
  224. cnt = 0
  225. end
  226. list[#list + 1] = { heroGrid.uuid or "", heroGrid.zhandouli or 0 }
  227. end
  228. end
  229. if cnt > 0 then
  230. msgRet.list[0] = cnt
  231. Msg.send(msgRet, human.fd)
  232. end
  233. if #list > 0 then
  234. table.sort(list, sortZhanli)
  235. local maxCnt = human.db.lv >= 100 and 6 or 5
  236. for i = 1, maxCnt do
  237. local heroDb = list[i]
  238. if heroDb then
  239. human.maxZDL.heroCnt = human.maxZDL.heroCnt + 1
  240. human.maxZDL.maxHero[heroDb[1]] = heroDb[2]
  241. human.maxZDL.zhandouli = human.maxZDL.zhandouli + heroDb[2]
  242. end
  243. end
  244. end
  245. print(" human onLogin maxZDL is : ", human.maxZDL.zhandouli)
  246. end
  247. -- 修正 玩家最高战力
  248. function checkChangeMaxZDL(human, heroGrid)
  249. if human.maxZDL and heroGrid.uuid then
  250. if human.maxZDL.maxHero[heroGrid.uuid] then
  251. human.maxZDL.maxHero[heroGrid.uuid] = heroGrid.zhandouli
  252. human.maxZDL.zhandouli = 0
  253. for _, v in pairs(human.maxZDL.maxHero) do
  254. human.maxZDL.zhandouli = human.maxZDL.zhandouli + v
  255. end
  256. else
  257. local maxCnt = human.db.lv >= 100 and 6 or 5
  258. if human.maxZDL.heroCnt < maxCnt then
  259. human.maxZDL.maxHero[heroGrid.uuid] = heroGrid.zhandouli
  260. human.maxZDL.zhandouli = human.maxZDL.zhandouli + heroGrid.zhandouli
  261. human.maxZDL.heroCnt = human.maxZDL.heroCnt + 1
  262. else
  263. local minZDL = 0
  264. local minUuid
  265. for thisUuid, v in pairs(human.maxZDL.maxHero) do
  266. minUuid = minZDL == 0 and thisUuid or minUuid
  267. minZDL = minZDL == 0 and v or minZDL
  268. if minZDL > v then
  269. minZDL = v
  270. minUuid = thisUuid
  271. end
  272. end
  273. if minZDL < heroGrid.zhandouli then
  274. human.maxZDL.maxHero[minUuid] = nil
  275. human.maxZDL.maxHero[heroGrid.uuid] = heroGrid.zhandouli
  276. human.maxZDL.zhandouli = human.maxZDL.zhandouli - minZDL + heroGrid.zhandouli
  277. end
  278. end
  279. end
  280. print(" checkChangeMaxZDL ", human.maxZDL.zhandouli)
  281. end
  282. end
  283. -- 发送英雄详细信息:静态,只是1个英雄的
  284. function sendHeroBagStatic(human, id, tuJian)
  285. local heroConfig = HeroExcel.hero[id]
  286. if not heroConfig then return end
  287. local msgRet = Msg.gc.GC_HERO_BAG_STATIC
  288. HeroGrid.makeHeroStatic(msgRet.heroStatic, id, tuJian)
  289. Msg.send(msgRet, human.fd)
  290. end
  291. -- 玩家身上动态数据
  292. function sendHeroGridDynamic(human, heroGrid, index, isQuery)
  293. if not isQuery then sendHeroBagUpdate(human, index) end
  294. local msgRet = Msg.gc.GC_HERO_BAG_DYNAMIC
  295. msgRet.index = index or 0
  296. msgRet.canLv = isHeroLvDot(human, heroGrid) == true and 1 or 0
  297. msgRet.canUp = isHeroUpDot(human, heroGrid) == true and 1 or 0
  298. msgRet.canEquip = HeroEquip.isEquipDot(human, heroGrid) == true and 1 or 0
  299. msgRet.canFuwen = FuwenLogic.isFuwenDot(human, heroGrid) == true and 1 or 0
  300. msgRet.canJueXing = isHeroJuexingDot(human, index, heroGrid) == true and 1 or 0
  301. local bingShuState = BingshuLogic.isBingShuDot(human, heroGrid)
  302. if bingShuState == -1 then
  303. msgRet.canBingShu = -1
  304. else
  305. msgRet.canBingShu = bingShuState == true and 1 or 0
  306. end
  307. HeroGrid.makeHeroDynamic(msgRet.heroDynamic, heroGrid, index, human)
  308. Msg.send(msgRet, human.fd)
  309. end
  310. -- 配置数据
  311. function sendHeroBagDynamicByID(human, heroID, star)
  312. local msgRet = Msg.gc.GC_HERO_BAG_DYNAMIC_BY_ID
  313. HeroGrid.makeHeroDynamicByID(msgRet.heroDynamic, heroID, star)
  314. Msg.send(msgRet, human.fd)
  315. end
  316. -- 发送英雄详细信息
  317. function sendHeroBagDynamic(human, id, index, isQuery)
  318. local heroGrid = getHeroGrid(human, id, index)
  319. if not heroGrid then return end
  320. sendHeroGridDynamic(human, heroGrid, index, isQuery)
  321. end
  322. -- 发送英雄添加/变化
  323. function sendHeroBagUpdate(human, index)
  324. local heroGrid = human.db.heroBag[index]
  325. if type(heroGrid) ~= "table" then return end
  326. local msgRet = Msg.gc.GC_HERO_BAG_ADD
  327. HeroGrid.makeHeroSimple(msgRet.data, heroGrid, index, human)
  328. Msg.send(msgRet, human.fd)
  329. end
  330. -- 发送英雄删除
  331. function sendHeroBagDel(human, index)
  332. local msgRet = Msg.gc.GC_HERO_BAG_DELETE
  333. msgRet.index = index
  334. Msg.send(msgRet, human.fd)
  335. end
  336. -- 背包容量查询
  337. function sendHeroBagCap(human)
  338. calcHeroBagCap(human)
  339. local nowBuyCnt = human.db.buyCapCnt or 0
  340. local msgRet = Msg.gc.GC_HERO_CAP_QUERY
  341. msgRet.cap = human.db.heroBag[0]
  342. msgRet.buyZuanshi = (nowBuyCnt + 1) * 100
  343. if nowBuyCnt >= HeroDefine.BUY_CAP_CNT then
  344. msgRet.buyZuanshi = -1 --达到上限
  345. end
  346. Msg.send(msgRet, human.fd)
  347. end
  348. -----------------------------------------------------------------------------------------
  349. -- 锁定英雄
  350. function lockHero(human, isLock, heroID, heroIndex)
  351. local heroGrid = human.db.heroBag[heroIndex]
  352. if heroGrid == nil or heroGrid.id ~= heroID then
  353. return
  354. end
  355. if isLock == 1 then
  356. heroGrid.isLock = true
  357. elseif isLock == 0 then
  358. heroGrid.isLock = nil
  359. end
  360. local msgRet = Msg.gc.GC_HERO_BAG_LOCK
  361. msgRet.heroID = heroID
  362. msgRet.heroIndex = heroIndex
  363. msgRet.type = heroGrid.isLock and 1 or 0
  364. Msg.send(msgRet, human.fd)
  365. end
  366. -- 返回英雄背包空余格子数
  367. function getEmptyCnt(human)
  368. local emptyCnt = 0
  369. for i = 1, human.db.heroBag[0] do
  370. if human.db.heroBag[i] == nil then
  371. emptyCnt = emptyCnt + 1
  372. end
  373. end
  374. return emptyCnt
  375. end
  376. -- 获得英雄背包第一个空格子下标
  377. function getEmptyIndex(human)
  378. for index = 1, human.db.heroBag[0] do
  379. local grid = human.db.heroBag[index]
  380. if grid == nil then
  381. return index
  382. end
  383. end
  384. end
  385. -- 新增英雄
  386. function addHero(human, id, star, cnt, logType, noSend)
  387. if cnt < 1 then return end
  388. local heroConfig = HeroExcel.hero[id]
  389. if not heroConfig then return end
  390. local xLv = 0
  391. local mergeHeroAttrs = nil
  392. if logType == "hero_merge" then
  393. human.db.mergeInfo = human.db.mergeInfo or {}
  394. human.db.mergeInfo.heroInfo.xLv = human.db.mergeInfo.heroInfo.xLv or 0
  395. human.db.mergeInfo.heroInfo.heroAttrs = human.db.mergeInfo.heroInfo.heroAttrs or RoleDefine.PANEL_ATTR_KEY
  396. xLv = human.db.mergeInfo.heroInfo.xLv
  397. mergeHeroAttrs = mergeHeroAttrs or {}
  398. for k, v in pairs(human.db.mergeInfo.heroInfo.heroAttrs) do
  399. mergeHeroAttrs[k] = v
  400. end
  401. Log.write(Log.LOGID_TEST, "添加融合英雄属性 heroAttrs : " .. Json.Encode(mergeHeroAttrs))
  402. end
  403. -- 某些英雄自动分解
  404. local isFenjie, fenjieList = FenjieLogic.autoFenjie(human, id, cnt, logType)
  405. if isFenjie then
  406. return nil, fenjieList
  407. end
  408. -- 先判断英雄背包是否满
  409. if getEmptyCnt(human) < cnt then
  410. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  411. end
  412. local heroIndex, uuid = nil
  413. for i = 1, cnt do
  414. local heroGrid = HeroGrid.createHeroGrid(id, star, xLv, mergeHeroAttrs)
  415. heroIndex = addHeroByGrid(human, heroGrid, logType, noSend)
  416. uuid = heroGrid.uuid
  417. end
  418. return heroIndex, uuid
  419. end
  420. -- 英雄添加日志
  421. function writeLogHeroAdd(human, logType, heroGrid)
  422. Log.write(Log.LOGID_OSS_HERO, human.db._id, human.db.account, human.db.name, human.db.lv,
  423. LogDefine.DEFINE[logType] + LogDefine.TYPE["hero"], heroGrid.id, 1, heroGrid.uuid, heroGrid.star)
  424. end
  425. -- 英雄删除日志
  426. function writeLogHeroDel(human, logType, heroGrid)
  427. Log.write(Log.LOGID_OSS_HERO, human.db._id, human.db.account, human.db.name, human.db.lv,
  428. LogDefine.DEFINE[logType] + LogDefine.TYPE["hero"], heroGrid.id, -1, heroGrid.uuid, heroGrid.star)
  429. end
  430. -- 新增英雄
  431. function addHeroByGrid(human, heroGrid, logType, noSend)
  432. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["hero"] then
  433. assert()
  434. end
  435. local heroConfig = HeroExcel.hero[heroGrid.id]
  436. if not heroConfig then return end
  437. -- 某些英雄自动分解
  438. local isFenjie, fenjieList = FenjieLogic.autoFenjie(human, heroGrid.id, 1, logType)
  439. if isFenjie then
  440. return nil, fenjieList
  441. end
  442. -- 先判断英雄背包是否满
  443. if getEmptyCnt(human) < 1 then
  444. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  445. end
  446. local emptyIndex = getEmptyIndex(human)
  447. if not emptyIndex then return end
  448. heroGrid.bagIndex = emptyIndex
  449. human.db.heroBag[emptyIndex] = heroGrid
  450. ObjHuman.doCalcHero(human, emptyIndex)
  451. if not noSend then
  452. sendHeroBagUpdate(human, emptyIndex)
  453. end
  454. onGetNewHero(human, heroGrid, logType, emptyIndex)
  455. writeLogHeroAdd(human, logType, heroGrid)
  456. checkChangeMaxZDL(human, heroGrid)
  457. return emptyIndex
  458. end
  459. local yunYingActParam = {}
  460. function onGetNewHero(human, heroGrid, logType, heroIndex)
  461. local heroConfig = HeroExcel.hero[heroGrid.id]
  462. local grade = heroConfig.grade
  463. HeroBook.onAddHero(human, heroGrid.id, heroGrid.star)
  464. RoleHeadLogic.onAddHero(human, heroGrid.id)
  465. -- 先知置换 和十星置换 不予计算活动
  466. if logType ~= "xianzhi_zhihuan" and logType ~= "tenStar_displace" then
  467. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_HERO)
  468. TuiSongLiBao.tuiSongLiBaoOnTask(human, TuiSongLiBao.TUISONGLIBAOTASK_STARS_HERO, heroConfig.star, nil)
  469. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE12, heroGrid.star)
  470. if grade == 4 then
  471. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_15, 1)
  472. end
  473. end
  474. XingYaoGongMing.onAddHero(human, heroGrid, heroIndex)
  475. HeroLogLogic.finishTaskCB(human, HeroLogLogic.HERO_LOG_TYPE_7, 1, heroGrid.id)
  476. for i in ipairs(yunYingActParam) do
  477. yunYingActParam[i] = nil
  478. end
  479. yunYingActParam[1] = logType
  480. yunYingActParam[2] = heroGrid.id
  481. yunYingActParam[3] = 1
  482. YunYingLogic.onCallBack(human, "onGetNewHeroAct", yunYingActParam)
  483. for i in ipairs(yunYingActParam) do
  484. yunYingActParam[i] = nil
  485. end
  486. yunYingActParam[1] = heroGrid.id
  487. yunYingActParam[2] = heroGrid.star
  488. yunYingActParam[3] = 1
  489. YunYingLogic.onCallBack(human, "onHeroStarChange", yunYingActParam)
  490. end
  491. -- 根据下标删除英雄
  492. function delHeroByIndex(human, index, logType, noSend)
  493. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["hero"] then
  494. assert()
  495. end
  496. if human.db.heroBag[index] == nil then
  497. return
  498. end
  499. SkinLogic.onDelHero(human, index)
  500. local heroGrid = human.db.heroBag[index]
  501. human.db.heroBag[index] = nil
  502. human.heroAttrs[index] = nil
  503. if not noSend then
  504. sendHeroBagDel(human, index)
  505. end
  506. -- 删除酒馆任务中的上战的英雄
  507. BarTaskLogic.heroIndexByDelForPos(human, index)
  508. -- 删除 默认出站队列中的 英雄
  509. CombatPosLogic.heroIndexByDelForPos(human, heroGrid.uuid)
  510. XingYaoGongMing.onDelHero(human, heroGrid, index)
  511. ObjHuman.doCalc(human)
  512. writeLogHeroDel(human, logType, heroGrid)
  513. end
  514. -- 英雄升级
  515. function heroLvUp(human, heroID, heroIndex)
  516. local heroGrid = human.db.heroBag[heroIndex]
  517. if heroGrid == nil or heroGrid.id ~= heroID then
  518. return
  519. end
  520. local heroConfig = HeroExcel.hero[heroID]
  521. if not heroConfig then return end
  522. if XingYaoGongMing.isGongMing(human, heroIndex, XingYaoGongMing.XYHERO_LV) then
  523. return
  524. end
  525. -- 判断等级上限
  526. local star = heroGrid.star
  527. local nowLv = heroGrid.lv
  528. local maxLv = HeroGrid.getMaxLv(star, heroGrid.quality)
  529. local upLv, needJinbi, needSoulCnt = HeroGrid.getLevelUpCnt(human, nowLv, maxLv)
  530. --print(" upLv, needJinbi, needSoulCnt", upLv, needJinbi, needSoulCnt)
  531. if upLv < 1 then return end
  532. -- 判断消耗材料
  533. if human.db.jinbi < needJinbi then
  534. return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
  535. end
  536. if BagLogic.getItemCnt(human, ItemDefine.ITEM_GREEN_EXP_ID) < needSoulCnt then
  537. local strName = ItemDefine.getValue(ItemDefine.ITEM_GREEN_EXP_ID, "name")
  538. return Broadcast.sendErr(human, Util.format(Lang.COMMON_NO_ITEM, strName))
  539. end
  540. -- 扣道具
  541. ObjHuman.updateJinbi(human, -needJinbi, "hero_up")
  542. BagLogic.delItem(human, ItemDefine.ITEM_GREEN_EXP_ID, needSoulCnt, "hero_up")
  543. -- 改db
  544. heroGrid.lv = nowLv + upLv
  545. ObjHuman.doCalcHero(human, heroIndex)
  546. sendHeroBagDynamic(human, heroID, heroIndex)
  547. local msgRet = Msg.gc.GC_HERO_LEVEL_UP
  548. msgRet.id = heroID
  549. msgRet.index = heroIndex
  550. Msg.send(msgRet, human.fd)
  551. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_HEROUP)
  552. refreshDot(human, heroGrid.uuid)
  553. if nowLv < 50 and heroGrid.lv >= 50 then
  554. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_6, 1)
  555. elseif nowLv < 100 and heroGrid.lv >= 100 then
  556. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_14, 1)
  557. elseif nowLv < 200 and heroGrid.lv >= 200 then
  558. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_20, 1)
  559. elseif nowLv < 145 and heroGrid.lv >= 145 then
  560. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_17, 1)
  561. elseif nowLv < 185 and heroGrid.lv >= 185 then
  562. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_18, 1)
  563. end
  564. XingYaoGongMing.onHeroLvUp(human, heroGrid, heroIndex)
  565. Log.write(Log.LOGID_OSS_HEROLVUP, human.db._id, human.db.account, human.db.name, heroGrid.uuid, nowLv, heroGrid.lv)
  566. checkChangeMaxZDL(human, heroGrid)
  567. end
  568. -- 英雄升阶查询
  569. function heroUpgradeQuery(human, heroID, heroIndex)
  570. local heroGrid = human.db.heroBag[heroIndex]
  571. if heroGrid == nil or heroGrid.id ~= heroID then
  572. return
  573. end
  574. local cf = HeroExcel.hero[heroID]
  575. if not cf then return end
  576. local star = cf.star
  577. local nextQuality = heroGrid.quality + 1
  578. local maxLv = HeroGrid.getMaxLv(heroGrid.star, nextQuality)
  579. local upcf = UpNeedExcel.upQuality[nextQuality]
  580. if not maxLv or not upcf then
  581. return Broadcast.sendErr(human, Lang.HERO_UPGRADE_ERR_FULL)
  582. end
  583. local nextHeroGrid = HeroGrid.getHeroGridCalcCache(heroGrid)
  584. nextHeroGrid.quality = nextQuality
  585. local nextAttrs = RoleAttr.calcHeroGrid(nextHeroGrid, heroIndex, human)
  586. local zhandouli = RoleAttr.calcZhandouli(nextAttrs)
  587. local msgRet = Msg.gc.GC_HERO_UPGRADE_QUERY
  588. msgRet.id = heroID
  589. msgRet.index = heroIndex
  590. local net = msgRet.data
  591. net.id = heroID
  592. net.maxLv = maxLv
  593. net.zhandouli = zhandouli
  594. net.attr[0] = 4
  595. net.attr[1].key = RoleDefine.ATK
  596. net.attr[1].value = nextAttrs[RoleDefine.ATK]
  597. net.attr[2].key = RoleDefine.HP
  598. net.attr[2].value = nextAttrs[RoleDefine.HP]
  599. net.attr[3].key = RoleDefine.SPEED
  600. net.attr[3].value = nextAttrs[RoleDefine.SPEED]
  601. net.attr[4].key = RoleDefine.DEF
  602. net.attr[4].value = nextAttrs[RoleDefine.DEF]
  603. net.needJinbi = upcf.money
  604. net.needItemCnt = upcf.jinjieshi
  605. --Msg.trace(msgRet)
  606. Msg.send(msgRet, human.fd)
  607. end
  608. -- 英雄升阶
  609. function heroUpgradeDo(human, heroID, heroIndex)
  610. local heroConfig = HeroExcel.hero[heroID]
  611. if not heroConfig then return end
  612. local heroGrid = human.db.heroBag[heroIndex]
  613. if heroGrid == nil or heroGrid.id ~= heroID then
  614. return
  615. end
  616. if XingYaoGongMing.isGongMing(human, heroIndex, XingYaoGongMing.XYHERO_LV) then
  617. return
  618. end
  619. local heroConfig = HeroExcel.hero[heroID]
  620. if not heroConfig then return end
  621. local star = heroGrid.star
  622. local maxQuality = HeroGrid.getMaxQuality(star)
  623. local nextQuality = heroGrid.quality + 1
  624. -- 判断阶数上限
  625. if heroGrid.quality >= maxQuality then
  626. return
  627. end
  628. local upcf = UpNeedExcel.upQuality[nextQuality]
  629. if not upcf then return end
  630. -- 判断消耗材料
  631. local needJinbi = upcf.money
  632. local needItemCnt = upcf.jinjieshi
  633. if human.db.jinbi < needJinbi then
  634. return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
  635. end
  636. local nowItemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID)
  637. if nowItemCnt < needItemCnt then
  638. local strName = ItemDefine.getValue(ItemDefine.ITEM_HERO_UPGRADE_ID, "name")
  639. return Broadcast.sendErr(human, Util.format(Lang.COMMON_NO_ITEM, strName))
  640. end
  641. -- 扣材料
  642. ObjHuman.updateJinbi(human, -needJinbi, "hero_upgrade")
  643. BagLogic.delItem(human, ItemDefine.ITEM_HERO_UPGRADE_ID, needItemCnt, "hero_upgrade")
  644. -- 改db
  645. heroGrid.quality = nextQuality
  646. ObjHuman.doCalcHero(human, heroIndex)
  647. sendHeroBagDynamic(human, heroID, heroIndex)
  648. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_UPGRADE)
  649. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_25, 1)
  650. local msgRet = Msg.gc.GC_HERO_UPGRADE_DO
  651. msgRet.id = heroID
  652. msgRet.index = heroIndex
  653. Msg.send(msgRet, human.fd)
  654. refreshDot(human, heroGrid.uuid)
  655. XingYaoGongMing.onHeroUpgrade(human, heroGrid, heroIndex)
  656. checkChangeMaxZDL(human, heroGrid)
  657. end
  658. -- 重算背包熔炼
  659. function calcHeroBagCap(human)
  660. local buyCnt = math.min(human.db.buyCapCnt or 0, HeroDefine.BUY_CAP_CNT)
  661. local heroBagCnt = HeroDefine.HERO_BAG_CNT
  662. heroBagCnt = heroBagCnt + (VipLogic.getPowerArgs(human, VipLogic.VIP_POWER12) or 0)
  663. heroBagCnt = heroBagCnt + HeroDefine.HERO_BAG_BUY_ADD_CNT * buyCnt -- 购买获得背包格子
  664. if human.db.blue ~= nil and human.db.blue.isAdd ~= nil then -- 特权
  665. local cnt = TequanExcel.tequan[2].privilege
  666. heroBagCnt = heroBagCnt + cnt
  667. end
  668. if human.db.yellow ~= nil and human.db.yellow.isAdd ~= nil then -- 特权
  669. local cnt = TequanExcel.tequan[1].privilege
  670. heroBagCnt = heroBagCnt + cnt
  671. end
  672. -- 封印之章特权
  673. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_1)
  674. if cjPrivilege then
  675. heroBagCnt = heroBagCnt + cjPrivilege
  676. end
  677. -- 特殊服务器处理
  678. -- vip需求砍掉之后,导致有的玩家英雄数量超过背包数量
  679. -- 经策划确认,140001-140021 服务器所有玩家增加背包数量300
  680. if Config.SVR_INDEX >= 140001 and Config.SVR_INDEX <= 140021 then
  681. heroBagCnt = heroBagCnt + 300
  682. end
  683. human.db.heroBag[0] = heroBagCnt
  684. end
  685. -- 购买英雄背包容量
  686. function buyHeroCap(human)
  687. -- 上限判断
  688. local nowBuyCnt = human.db.buyCapCnt or 0
  689. if nowBuyCnt >= HeroDefine.BUY_CAP_CNT then
  690. return Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
  691. end
  692. -- 判断消耗
  693. local needZuanshi = (nowBuyCnt + 1) * 100
  694. if not ObjHuman.checkRMB(human, needZuanshi) then
  695. return
  696. end
  697. -- 扣消耗
  698. ObjHuman.decZuanshi(human, -needZuanshi, "buy_hero_cap")
  699. -- 改db
  700. human.db.buyCapCnt = nowBuyCnt + 1
  701. sendHeroBagCap(human)
  702. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  703. end
  704. -- 最大觉醒
  705. function sendHeroJueXingMax(human, heroID, heroIndex)
  706. local heroConfig = HeroExcel.hero[heroID]
  707. if not heroConfig then return end
  708. local msgRet = Msg.gc.GC_HERO_JUEXING_QUERY_MAX
  709. msgRet.id = heroID
  710. msgRet.index = heroIndex
  711. Msg.send(msgRet, human.fd)
  712. end
  713. local JUEXING_SKILL_DIFF_LIST = {}
  714. function getSkillDiffList(cf1, cf2)
  715. local diffCnt = 0
  716. for i = 1, #cf2.skillList do
  717. local skillID1 = cf1.skillList[i]
  718. local skillID2 = cf2.skillList[i]
  719. if skillID1 ~= skillID2 then
  720. diffCnt = diffCnt + 1
  721. local tb = JUEXING_SKILL_DIFF_LIST[diffCnt] or {}
  722. JUEXING_SKILL_DIFF_LIST[diffCnt] = tb
  723. tb[1] = skillID1
  724. tb[2] = skillID2
  725. end
  726. end
  727. for i = 1, #cf2.beSkillList do
  728. local skillID1 = cf1.beSkillList[i]
  729. local skillID2 = cf2.beSkillList[i]
  730. if skillID1 ~= skillID2 then
  731. diffCnt = diffCnt + 1
  732. local tb = JUEXING_SKILL_DIFF_LIST[diffCnt] or {}
  733. JUEXING_SKILL_DIFF_LIST[diffCnt] = tb
  734. tb[1] = skillID1
  735. tb[2] = skillID2
  736. end
  737. end
  738. return diffCnt, JUEXING_SKILL_DIFF_LIST
  739. end
  740. -- 英雄觉醒预览
  741. local JUEXING_SPEED_UP = { [4] = 10 }
  742. local JUEXING_ATK_UP = { [5] = 40, [6] = 40, [7] = 40, [8] = 40, [9] = 40, [10] = 20, [11] = 20, [12] = 20 }
  743. local JUEXING_HP_UP = { [5] = 50, [6] = 50, [7] = 50, [8] = 50, [9] = 50, [10] = 30, [11] = 30, [12] = 30 }
  744. function heroJueXingQuery(human, heroID, heroIndex)
  745. local heroConfig = HeroExcel.hero[heroID]
  746. if not heroConfig then return end
  747. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  748. if not heroGrid then return end
  749. -- 判断是否达到开放等级
  750. local isFix, upStarNeedLv, upStarNeedWorldLv = isFixUpStarLv(human, heroGrid.star + 1)
  751. if not isFix then
  752. if upStarNeedLv and upStarNeedWorldLv and upStarNeedWorldLv > 0 then
  753. return Broadcast.sendErr(human, Util.format(Lang.HERO_JUEXING_ERR_HEROLV, upStarNeedLv, upStarNeedWorldLv))
  754. elseif upStarNeedLv then
  755. return Broadcast.sendErr(human, Util.format(Lang.HERO_JUEXING_ERR_HEROLV2, upStarNeedLv))
  756. end
  757. return
  758. end
  759. local attrConfig = HeroDefine.getAttrConfig(heroID, heroGrid.star)
  760. if not attrConfig then return end
  761. local nextAttrConfig = HeroDefine.getNextAttrConfig(heroID, heroGrid.star)
  762. if not nextAttrConfig then
  763. return sendHeroJueXingMax(human, heroID, heroIndex)
  764. end
  765. local msgRet = Msg.gc.GC_HERO_JUEXING_QUERY
  766. local dataNet = msgRet.data
  767. local maxQuality = HeroGrid.getMaxQuality(attrConfig.star)
  768. local nextMaxQuality = HeroGrid.getMaxQuality(nextAttrConfig.star)
  769. -- 判断是否达到开放等级
  770. local isFix, upStarNeedLv, upStarNeedWorldLv = isFixUpStarLv(human, heroGrid.star + 1)
  771. if not isFix then
  772. if upStarNeedLv and upStarNeedWorldLv and upStarNeedWorldLv > 0 then
  773. return Broadcast.sendErr(human, Util.format(Lang.HERO_JUEXING_ERR_HEROLV, upStarNeedLv, upStarNeedWorldLv))
  774. elseif upStarNeedLv then
  775. return Broadcast.sendErr(human, Util.format(Lang.HERO_JUEXING_ERR_HEROLV2, upStarNeedLv))
  776. end
  777. return
  778. end
  779. dataNet.id = heroID
  780. dataNet.index = heroIndex
  781. dataNet.star = heroGrid.star
  782. dataNet.nextStar = nextAttrConfig.star
  783. dataNet.maxLv = HeroGrid.getMaxLv(heroGrid.star, maxQuality)
  784. dataNet.nextMaxLv = HeroGrid.getMaxLv(nextAttrConfig.star, nextMaxQuality)
  785. -- 展示变化的技能
  786. local diffCnt, diffList = getSkillDiffList(attrConfig, nextAttrConfig)
  787. diffCnt = diffCnt > #dataNet.skillUp and #dataNet.skillUp or diffCnt
  788. dataNet.isAllSkillUp = (diffCnt > 1) and 1 or 0
  789. dataNet.skillUp[0] = diffCnt
  790. for i = 1, diffCnt do
  791. makeSkillNet(dataNet.skillUp[i], diffList[i][2])
  792. end
  793. dataNet.speedUp = JUEXING_SPEED_UP[heroConfig.star] or 0
  794. dataNet.atkUpRate = JUEXING_ATK_UP[heroConfig.star] or 0
  795. dataNet.hpUpRate = JUEXING_HP_UP[heroConfig.star] or 0
  796. dataNet.needItems[0] = #attrConfig.needItems
  797. for i = 1, dataNet.needItems[0] do
  798. local itemID = attrConfig.needItems[i][1]
  799. local itemCnt = attrConfig.needItems[i][2]
  800. Grid.makeItem(dataNet.needItems[i], itemID, itemCnt)
  801. end
  802. dataNet.needHeros[0] = 0
  803. for i = 1, #attrConfig.cond do
  804. dataNet.needHeros[0] = dataNet.needHeros[0] + 1
  805. local condNet = dataNet.needHeros[dataNet.needHeros[0]]
  806. makeUpStarCond(condNet, attrConfig.cond[i])
  807. end
  808. dataNet.needItemCnt = attrConfig.jinjieshi
  809. --Msg.trace(msgRet)
  810. Msg.send(msgRet, human.fd)
  811. end
  812. function fontJueXingHeroNet(net, heroGrid, index, human)
  813. local attrs = ObjHuman.getHeroAttrs(human, index)
  814. HeroGrid.makeHeroDynamic(net.dynamicData, heroGrid, index, human)
  815. HeroGrid.makeHeroSimple(net.simpleData, heroGrid, index, human)
  816. net.zhandouli = attrs[RoleDefine.ZHANDOULI] or 0
  817. net.atk = attrs[RoleDefine.ATK] or 0
  818. net.hp = attrs[RoleDefine.HP] or 0
  819. net.def = attrs[RoleDefine.DEF] or 0
  820. net.speed = attrs[RoleDefine.SPEED] or 0
  821. end
  822. -- 检查世界等级或者玩家等级是否满足条件
  823. -- 检查达到角色等级或者世界等级
  824. function isFixUpStarLv(human, targetStar)
  825. local config = HeroExcel.star[targetStar]
  826. if not config then
  827. return false
  828. end
  829. if config.upStarNeedLv >= 0 and human.db.lv >= config.upStarNeedLv then
  830. return true, config.upStarNeedLv, config.upStarNeedWorldLv
  831. end
  832. if config.upStarNeedWorldLv >= 0 and GlobalWorld.getWorldLv() >= config.upStarNeedWorldLv then
  833. return true, config.upStarNeedLv, config.upStarNeedWorldLv
  834. end
  835. return false, config.upStarNeedLv, config.upStarNeedWorldLv
  836. end
  837. -- 英雄觉醒
  838. local yunYingActParam = {}
  839. function heroJueXingDo(human, heroID, heroIndex, inputIDList, inputIndexList)
  840. local heroConfig = HeroExcel.hero[heroID]
  841. if not heroConfig then return end
  842. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  843. if not heroGrid then return end
  844. local attrConfig = HeroDefine.getAttrConfig(heroID, heroGrid.star)
  845. if not attrConfig then return end
  846. local nextAttrConfig = HeroDefine.getNextAttrConfig(heroID, heroGrid.star)
  847. if not nextAttrConfig then return end
  848. -- 判断是否达到开放等级
  849. local isFix, upStarNeedLv, upStarNeedWorldLv = isFixUpStarLv(human, heroGrid.star + 1)
  850. if not isFix then
  851. if upStarNeedLv and upStarNeedWorldLv and upStarNeedWorldLv > 0 then
  852. return Broadcast.sendErr(human, Util.format(Lang.HERO_JUEXING_ERR_HEROLV, upStarNeedLv, upStarNeedWorldLv))
  853. elseif upStarNeedLv then
  854. return Broadcast.sendErr(human, Util.format(Lang.HERO_JUEXING_ERR_HEROLV2, upStarNeedLv))
  855. end
  856. return
  857. end
  858. -- 判断消耗材料
  859. local needItemCnt = attrConfig.jinjieshi
  860. if not BagLogic.checkItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID, needItemCnt) then
  861. return
  862. end
  863. -- 额外材料
  864. for i = 1, #attrConfig.needItems do
  865. local itemID = attrConfig.needItems[i][1]
  866. local itemCnt = attrConfig.needItems[i][2]
  867. if not BagLogic.checkItemCnt(human, itemID, itemCnt) then
  868. return
  869. end
  870. end
  871. -- 英雄材料
  872. if not HechengLogic.checkCond(human, inputIDList, inputIndexList, attrConfig.cond) then
  873. return Broadcast.sendErr(human, Lang.HERO_JUEXING_CAILIAO_ERR)
  874. end
  875. -- 比较特别的情况。。
  876. for i = 1, inputIndexList[0] do
  877. if inputIndexList[i] == heroIndex then
  878. return -- 本体同时作为材料,骗分解材料
  879. end
  880. end
  881. -- 扣消耗
  882. BagLogic.delItem(human, ItemDefine.ITEM_HERO_UPGRADE_ID, needItemCnt, "hero_juexing")
  883. local fenjieList = FenjieLogic.fenjie(human, FenjieLogic.FENJIE_DO_JUEXING, inputIDList, inputIndexList)
  884. -- 额外材料
  885. for i = 1, #attrConfig.needItems do
  886. local itemID = attrConfig.needItems[i][1]
  887. local itemCnt = attrConfig.needItems[i][2]
  888. BagLogic.delItem(human, itemID, itemCnt, "hero_juexing")
  889. end
  890. local msgRet = Msg.gc.GC_HERO_JUEXING_DO
  891. msgRet.id = heroID
  892. msgRet.index = heroIndex
  893. msgRet.upStarNeedLv = upStarNeedLv
  894. msgRet.upStarNeedWorldLv = upStarNeedWorldLv
  895. fontJueXingHeroNet(msgRet.oldData, heroGrid, heroIndex, human)
  896. -- 继承英雄等级 阶数 装备 水晶
  897. writeLogHeroDel(human, "hero_juexing", heroGrid)
  898. heroGrid.star = nextAttrConfig.star
  899. onGetNewHero(human, heroGrid, "hero_juexing", heroIndex)
  900. ObjHuman.doCalcHero(human, heroIndex)
  901. sendHeroBagDynamic(human, heroGrid.id, heroIndex)
  902. writeLogHeroAdd(human, "hero_juexing", heroGrid)
  903. fontJueXingHeroNet(msgRet.newData, heroGrid, heroIndex, human)
  904. local diffCnt, diffList = getSkillDiffList(attrConfig, nextAttrConfig)
  905. diffCnt = diffCnt > #msgRet.skillUp and #msgRet.skillUp or diffCnt
  906. msgRet.isAllSkillUp = (diffCnt > 1) and 1 or 0
  907. msgRet.skillUp[0] = diffCnt
  908. for i = 1, diffCnt do
  909. makeSkillNet(msgRet.skillUp[i], diffList[i][2])
  910. end
  911. msgRet.itemList[0] = 0
  912. if fenjieList then
  913. for itemID, itemCnt in pairs(fenjieList) do
  914. if msgRet.itemList[0] >= #msgRet.itemList then
  915. break
  916. end
  917. msgRet.itemList[0] = msgRet.itemList[0] + 1
  918. Grid.makeItem(msgRet.itemList[msgRet.itemList[0]], itemID, itemCnt)
  919. end
  920. end
  921. --Msg.trace(msgRet)
  922. Msg.send(msgRet, human.fd)
  923. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE12, nextAttrConfig.star, heroGrid.id)
  924. local newstar = nextAttrConfig.star or 0
  925. local newcamp = heroConfig.camp or 0
  926. LiLianLogic.onCallback(human, LiLianLogic.LILIAN_OUTID24, 1, newcamp, newstar)
  927. if newstar == 5 then
  928. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_11, 1)
  929. end
  930. if newstar >= 5 then
  931. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_13, 1)
  932. end
  933. if newstar == 6 then
  934. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_16, 1)
  935. JibanLogic.onCallback(human, 2, newstar)
  936. end
  937. if newstar == 10 then
  938. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_23, 1)
  939. end
  940. checkChangeMaxZDL(human, heroGrid)
  941. HeroLogLogic.finishTaskCB(human, HeroLogLogic.HERO_LOG_TYPE_8, 1, heroID, newstar)
  942. for i in ipairs(yunYingActParam) do
  943. yunYingActParam[i] = nil
  944. end
  945. yunYingActParam[1] = heroID
  946. yunYingActParam[2] = newstar
  947. yunYingActParam[3] = 1
  948. YunYingLogic.onCallBack(human, "onHeroStarChange", yunYingActParam)
  949. end
  950. -- 英雄重生预览
  951. function heroChongShengQuery(human, heroID, heroIndex)
  952. local heroConfig = HeroExcel.hero[heroID]
  953. if not heroConfig then return end
  954. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  955. if not heroGrid then return end
  956. if heroGrid.isLock then
  957. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_LOCK)
  958. end
  959. local chongShengConfig = UpNeedExcel.chongSheng[heroGrid.star]
  960. if not chongShengConfig then -- 只能重生7-9星
  961. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  962. end
  963. -- 没有对应5星的存在
  964. local attrConfig = HeroDefine.getAttrConfig(heroID, CHONGSHENG_RETURN_STAR)
  965. if not attrConfig then
  966. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  967. end
  968. local suipianID = SuipianLogic.getSuipianIDbyHeroID(heroID)
  969. if not suipianID then -- 没有对应的本体碎片
  970. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_SUIPIANID)
  971. end
  972. local otherSuipianID = chongShengConfig.suipianIDs[heroConfig.camp]
  973. if not otherSuipianID then -- 阵容不对
  974. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  975. end
  976. local msgRet = Msg.gc.GC_HERO_CHONGSHENG_QUERY
  977. msgRet.id = heroID
  978. msgRet.index = heroIndex
  979. msgRet.needItemCnt = chongShengConfig.needItemCnt
  980. Grid.makeItem(msgRet.bentiSuipian, suipianID, chongShengConfig.bentiCnt)
  981. Grid.makeItem(msgRet.otherSuipian, otherSuipianID, chongShengConfig.suipianCnt)
  982. --Msg.trace(msgRet)
  983. Msg.send(msgRet, human.fd)
  984. end
  985. -- 英雄重生
  986. function heroChongShengDo(human, heroID, heroIndex)
  987. local heroConfig = HeroExcel.hero[heroID]
  988. if not heroConfig then return end
  989. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  990. if not heroGrid then return end
  991. if heroGrid.isLock then
  992. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_LOCK)
  993. end
  994. local chongShengConfig = UpNeedExcel.chongSheng[heroGrid.star]
  995. if not chongShengConfig then -- 只能重生7-9星
  996. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  997. end
  998. local attrConfig = HeroDefine.getAttrConfig(heroID, CHONGSHENG_RETURN_STAR)
  999. if not attrConfig then
  1000. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  1001. end
  1002. local suipianID = SuipianLogic.getSuipianIDbyHeroID(heroID)
  1003. if not suipianID then -- 没有对应的本体碎片
  1004. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_SUIPIANID)
  1005. end
  1006. local otherSuipianID = chongShengConfig.suipianIDs[heroConfig.camp]
  1007. if not otherSuipianID then -- 阵营不对
  1008. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  1009. end
  1010. local nowItemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_CHONGSHENG_ID)
  1011. local needItemCnt = chongShengConfig.needItemCnt
  1012. if nowItemCnt < needItemCnt then
  1013. local strName = ItemDefine.getValue(ItemDefine.ITEM_HERO_CHONGSHENG_ID, "name")
  1014. local strRet = Util.format(Lang.COMMON_NO_ITEM, strName)
  1015. return Broadcast.sendErr(human, strRet)
  1016. end
  1017. -- 删除材料
  1018. BagLogic.delItem(human, ItemDefine.ITEM_HERO_CHONGSHENG_ID, needItemCnt, "hero_chongsheng")
  1019. -- 重置到初始返还的材料
  1020. local upList = getResetReturnItems(heroGrid)
  1021. -- 先删除英雄
  1022. delHeroByIndex(human, heroIndex, "hero_chongsheng")
  1023. -- 返还装备
  1024. for i = 1, ItemDefine.EQUIP_MAX_CNT do
  1025. if i ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN and
  1026. heroGrid.equip and heroGrid.equip[i] then
  1027. local equipGrid = heroGrid.equip[i]
  1028. if equipGrid then
  1029. EquipLogic.addByEquipGrid(human, equipGrid, "hero_chongsheng")
  1030. end
  1031. end
  1032. end
  1033. -- 返还符文
  1034. for i = 1, 2 do
  1035. local fuwenGrid = heroGrid.fuwen and heroGrid.fuwen[i]
  1036. if fuwenGrid and fuwenGrid.id then
  1037. FuwenLogic.addByGrid(human, fuwenGrid, "hero_chongsheng")
  1038. end
  1039. end
  1040. -- 再给东西
  1041. BagLogic.addItem(human, suipianID, chongShengConfig.bentiCnt, "hero_chongsheng")
  1042. BagLogic.addItem(human, otherSuipianID, chongShengConfig.suipianCnt, "hero_chongsheng")
  1043. for itemID, itemCnt in pairs(upList) do
  1044. BagLogic.addItem(human, itemID, itemCnt, "hero_chongsheng")
  1045. end
  1046. -- 通知客户端
  1047. local msgRet = Msg.gc.GC_HERO_CHONGSHENG_DO
  1048. msgRet.list[0] = 2
  1049. Grid.makeItem(msgRet.list[1], suipianID, chongShengConfig.bentiCnt)
  1050. Grid.makeItem(msgRet.list[2], otherSuipianID, chongShengConfig.suipianCnt)
  1051. for itemID, itemCnt in pairs(upList) do
  1052. msgRet.list[0] = msgRet.list[0] + 1
  1053. Grid.makeItem(msgRet.list[msgRet.list[0]], itemID, itemCnt)
  1054. end
  1055. msgRet.list[0] = EquipLogic.makeEquipItem(human, msgRet.list, msgRet.list[0])
  1056. Msg.send(msgRet, human.fd)
  1057. checkChangeMaxZDL(human, heroGrid)
  1058. end
  1059. -- 回退
  1060. local HUITUI_HERO_LIST = {}
  1061. local HUITUI_ITEM_LIST = {}
  1062. function getHuituiReturns(heroGrid)
  1063. local heroConfig = HeroExcel.hero[heroGrid.id]
  1064. if not heroConfig then return end
  1065. local config = UpNeedExcel.huiTui[heroGrid.star]
  1066. if not config then return end
  1067. local targetID = heroGrid.id
  1068. if not targetID then return end
  1069. -- 13星无法升级,但可以回退
  1070. if heroGrid.star < 13 then
  1071. local upStarConfig = HeroDefine.getNextAttrConfig(heroGrid.id, heroGrid.star)
  1072. -- 不能升星的话也不能回退
  1073. if not upStarConfig then
  1074. return
  1075. end
  1076. end
  1077. Util.cleanTable(HUITUI_HERO_LIST)
  1078. Util.cleanTable(HUITUI_ITEM_LIST)
  1079. local maxLv = HeroGrid.getMaxLv(config.targetStar, heroGrid.quality)
  1080. local lv = heroGrid.lv
  1081. if heroGrid.oldLV then
  1082. lv = heroGrid.oldLV
  1083. end
  1084. local targetLv = math.min(lv, maxLv)
  1085. -- 升级 不将阶
  1086. for i = targetLv + 1, lv do
  1087. local upcf = UpNeedExcel.upLv[i]
  1088. if upcf then
  1089. HUITUI_ITEM_LIST[ItemDefine.ITEM_GREEN_EXP_ID] = (HUITUI_ITEM_LIST[ItemDefine.ITEM_GREEN_EXP_ID] or 0) +
  1090. upcf.soul
  1091. HUITUI_ITEM_LIST[ItemDefine.ITEM_JINBI_ID] = (HUITUI_ITEM_LIST[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  1092. end
  1093. end
  1094. -- 圣星文书
  1095. HUITUI_ITEM_LIST[ItemDefine.ITEM_HERO_UPGRADE_BOOK] = (HUITUI_ITEM_LIST[ItemDefine.ITEM_HERO_UPGRADE_BOOK] or 0) +
  1096. config.upBook
  1097. -- 进阶石
  1098. HUITUI_ITEM_LIST[ItemDefine.ITEM_HERO_UPGRADE_ID] = (HUITUI_ITEM_LIST[ItemDefine.ITEM_HERO_UPGRADE_ID] or 0) +
  1099. config.jinjieshi
  1100. -- 5星本体碎片数量
  1101. local fiveBentiID = heroGrid.id
  1102. local fiveBentiSuipianID = SuipianLogic.getSuipianIDbyHeroID(fiveBentiID)
  1103. HUITUI_ITEM_LIST[fiveBentiSuipianID] = (HUITUI_ITEM_LIST[fiveBentiSuipianID] or 0) + config.fiveBentiCnt
  1104. -- 5星同系碎片数量
  1105. local materialConfig = UpNeedExcel.huiTuiMaterial[heroConfig.camp]
  1106. HUITUI_ITEM_LIST[materialConfig.fiveHeroSuipian] = (HUITUI_ITEM_LIST[materialConfig.fiveHeroSuipian] or 0) +
  1107. config.fiveSuipianCnt
  1108. -- 9星傀儡数量
  1109. local nineHeroCnt = (HUITUI_HERO_LIST[9] and HUITUI_HERO_LIST[9][2] or 0) + config.nineHeroCnt
  1110. HUITUI_HERO_LIST[9] = { materialConfig.nineHero, nineHeroCnt }
  1111. -- 10星傀儡数量
  1112. local tenHeroCnt = (HUITUI_HERO_LIST[10] and HUITUI_HERO_LIST[10][2] or 0) + config.tenHeroCnt
  1113. HUITUI_HERO_LIST[10] = { materialConfig.tenHero, tenHeroCnt }
  1114. return config.targetStar, targetLv, config, HUITUI_ITEM_LIST, HUITUI_HERO_LIST
  1115. end
  1116. -- 回退查询
  1117. function sendHuituiQuery(human, heroID, heroIndex)
  1118. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1119. if not heroGrid then return end
  1120. local star, targetLv, config, items, heros = getHuituiReturns(heroGrid)
  1121. if not star then
  1122. return Broadcast.sendErr(human, Lang.HERO_HUITUI_ERR_STAR)
  1123. end
  1124. local msgRet = Msg.gc.GC_HERO_HUITUI_QUERY
  1125. msgRet.heroID = heroID
  1126. msgRet.heroIndex = heroIndex
  1127. HeroGrid.makeHeroSimple(msgRet.oldSimple, heroGrid, heroIndex, human)
  1128. local others = HeroGrid.createOthers(targetLv, nil, nil, star)
  1129. HeroGrid.makeHeroSimpleByID(msgRet.newSimple, heroID, heroIndex, others, nil, true)
  1130. HeroGrid.makeHeroSimpleByGeneral(msgRet.newSimple, heroID)
  1131. Grid.makeItem(msgRet.needItem, ItemDefine.ITEM_HERO_HUITUI_ID, config.needItemCnt)
  1132. msgRet.returnItems[0] = 0
  1133. for itemID, itemCnt in pairs(items) do
  1134. if msgRet.returnItems[0] >= #msgRet.returnItems then
  1135. break
  1136. end
  1137. if itemCnt > 0 then
  1138. msgRet.returnItems[0] = msgRet.returnItems[0] + 1
  1139. Grid.makeItem(msgRet.returnItems[msgRet.returnItems[0]], itemID, itemCnt)
  1140. end
  1141. end
  1142. msgRet.returnHeros[0] = 0
  1143. for star, v in pairs(heros) do
  1144. local rHeroID = v[1]
  1145. local rHeroCnt = v[2]
  1146. for i = 1, rHeroCnt do
  1147. if msgRet.returnHeros[0] >= #msgRet.returnHeros then
  1148. break
  1149. end
  1150. local others = HeroGrid.createOthers(1, nil, nil, star)
  1151. msgRet.returnHeros[0] = msgRet.returnHeros[0] + 1
  1152. local heroNet = msgRet.returnHeros[msgRet.returnHeros[0]]
  1153. HeroGrid.makeHeroSimpleByID(heroNet, rHeroID, nil, others, human)
  1154. HeroGrid.makeHeroSimpleByGeneral(heroNet, rHeroID)
  1155. heroNet.star = star
  1156. end
  1157. end
  1158. --Msg.trace(msgRet)
  1159. Msg.send(msgRet, human.fd)
  1160. end
  1161. -- 回退操作
  1162. function huituiHero(human, heroID, heroIndex)
  1163. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1164. if not heroGrid then return end
  1165. local star, targetLv, config, items, heros = getHuituiReturns(heroGrid)
  1166. if not star then
  1167. return Broadcast.sendErr(human, Lang.HERO_HUITUI_ERR_STAR)
  1168. end
  1169. if heroGrid.isLock then
  1170. return Broadcast.sendErr(human, Lang.HERO_HUITUI_ERR_LOCK)
  1171. end
  1172. local needHeroBagCnt = 0
  1173. for star, v in pairs(heros) do
  1174. local rHeroCnt = v[2]
  1175. needHeroBagCnt = needHeroBagCnt + rHeroCnt
  1176. end
  1177. -- 检查英雄背包空间
  1178. if getEmptyCnt(human) < needHeroBagCnt then
  1179. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  1180. end
  1181. if not BagLogic.checkItemCnt(human, ItemDefine.ITEM_HERO_HUITUI_ID, config.needItemCnt) then
  1182. return
  1183. end
  1184. BagLogic.delItem(human, ItemDefine.ITEM_HERO_HUITUI_ID, config.needItemCnt, "hero_huitui")
  1185. heroGrid.star = star
  1186. heroGrid.lv = targetLv
  1187. XingYaoGongMing.onDelHero(human, heroGrid, heroIndex)
  1188. ObjHuman.doCalcHero(human, heroIndex)
  1189. sendHeroBagDynamic(human, heroID, heroIndex)
  1190. writeLogHeroAdd(human, "hero_huitui", heroGrid)
  1191. for itemID, itemCnt in pairs(items) do
  1192. if itemCnt > 0 then
  1193. BagLogic.addItem(human, itemID, itemCnt, "hero_huitui")
  1194. end
  1195. end
  1196. for star, v in pairs(heros) do
  1197. local rHeroID = v[1]
  1198. local rHeroCnt = v[2]
  1199. if rHeroCnt > 0 then
  1200. addHero(human, rHeroID, star, rHeroCnt, "hero_huitui")
  1201. end
  1202. end
  1203. local msgRet = Msg.gc.GC_HERO_HUITUI
  1204. msgRet.heroID = heroID
  1205. msgRet.heroIndex = heroIndex
  1206. HeroGrid.makeHeroSimple(msgRet.newSimple, heroGrid, heroIndex, human)
  1207. msgRet.returnItems[0] = 0
  1208. for itemID, itemCnt in pairs(items) do
  1209. if msgRet.returnItems[0] >= #msgRet.returnItems then
  1210. break
  1211. end
  1212. if itemCnt > 0 then
  1213. msgRet.returnItems[0] = msgRet.returnItems[0] + 1
  1214. Grid.makeItem(msgRet.returnItems[msgRet.returnItems[0]], itemID, itemCnt)
  1215. end
  1216. end
  1217. msgRet.returnHeros[0] = 0
  1218. for star, v in pairs(heros) do
  1219. local rHeroID = v[1]
  1220. local rHeroCnt = v[2]
  1221. for i = 1, rHeroCnt do
  1222. if msgRet.returnHeros[0] >= #msgRet.returnHeros then
  1223. break
  1224. end
  1225. msgRet.returnHeros[0] = msgRet.returnHeros[0] + 1
  1226. local heroNet = msgRet.returnHeros[msgRet.returnHeros[0]]
  1227. HeroGrid.makeHeroSimpleByID(heroNet, rHeroID, nil, nil, human)
  1228. heroNet.star = star
  1229. end
  1230. end
  1231. --Msg.trace(msgRet)
  1232. Msg.send(msgRet, human.fd)
  1233. checkChangeMaxZDL(human, heroGrid)
  1234. end
  1235. function getHeroGrid(human, heroID, heroIndex)
  1236. if not heroID then return end
  1237. if not heroIndex then return end
  1238. local heroGrid = human.db.heroBag[heroIndex]
  1239. if type(heroGrid) ~= "table" or heroGrid.id ~= heroID then
  1240. return
  1241. end
  1242. return heroGrid
  1243. end
  1244. -- 根据uuid 获取heroGrid
  1245. function getHeroGridByUuid(human, uuid)
  1246. if not uuid or uuid == "" or uuid == "0" then return end
  1247. for index = 1, human.db.heroBag[0] do
  1248. local heroGrid = human.db.heroBag[index]
  1249. if heroGrid and type(heroGrid) == "table" then
  1250. if heroGrid.uuid == uuid then
  1251. return heroGrid
  1252. end
  1253. end
  1254. end
  1255. return nil
  1256. end
  1257. -- 获取下标英雄id
  1258. function getHeroIdByIndex(human, heroIndex)
  1259. if heroIndex <= 0 then
  1260. return
  1261. end
  1262. local heroGrid = human.db.heroBag[heroIndex]
  1263. if heroGrid == nil then
  1264. return
  1265. end
  1266. return heroGrid.id
  1267. end
  1268. function makeHeroShare(msg, heroGrid, bagIndex, human)
  1269. if type(heroGrid) ~= "table" then return end
  1270. local heroConfig = HeroExcel.hero[heroGrid.id]
  1271. if not heroConfig then return end
  1272. msg.uuid = human.db._id
  1273. msg.heroIndex = bagIndex
  1274. HeroGrid.makeHeroSimple(msg.heroSimple, heroGrid, bagIndex, human)
  1275. HeroGrid.makeHeroStatic(msg.heroStatic, heroGrid.id)
  1276. HeroGrid.makeHeroDynamic(msg.heroDynamic, heroGrid, bagIndex, human)
  1277. -- 装备信息
  1278. msg.equips[0] = 0
  1279. for i = 1, ItemDefine.EQUIP_MAX_CNT do
  1280. local equipGrid = heroGrid.equip and heroGrid.equip[i]
  1281. if equipGrid then
  1282. msg.equips[0] = msg.equips[0] + 1
  1283. local equipNet = msg.equips[msg.equips[0]]
  1284. Grid.makeItem(equipNet, equipGrid.id, 1, heroGrid.shuijingAttrID, equipGrid)
  1285. end
  1286. end
  1287. -- 符文
  1288. msg.fuWens[0] = 0
  1289. for i = 1, 2 do
  1290. local fuwenData = heroGrid.fuwen and heroGrid.fuwen[i]
  1291. if fuwenData and fuwenData.id then
  1292. msg.fuWens[0] = msg.fuWens[0] + 1
  1293. local fuwenNet = msg.fuWens[msg.fuWens[0]]
  1294. fuwenNet.pos = i
  1295. Grid.makeItem(fuwenNet.fuwen, fuwenData.id, 1, nil, fuwenData, i, 0)
  1296. end
  1297. end
  1298. return true
  1299. end
  1300. function makeHeroShareMonster(msg, monsterID, mosnterLv)
  1301. local others = HeroGrid.createOthers(mosnterLv)
  1302. msg.uuid = ""
  1303. msg.heroIndex = 0
  1304. HeroGrid.makeHeroSimpleByMonsterID(msg.heroSimple, monsterID, others)
  1305. HeroGrid.makeHeroStatic(msg.heroStatic, monsterID)
  1306. HeroGrid.makeHeroDynamicByID(msg.heroDynamic, monsterID)
  1307. msg.equips[0] = 0
  1308. msg.fuWens[0] = 0
  1309. end
  1310. function getHeroShareGrid(uuid, heroIndex)
  1311. local fakeHuman = ObjHuman.onlineUuid[uuid]
  1312. if not fakeHuman then
  1313. local db = RoleDBLogic.getDb(uuid, RoleLogic.getCombatField())
  1314. if not db then
  1315. return
  1316. end
  1317. fakeHuman = { db = db }
  1318. end
  1319. local bagIndex = heroIndex
  1320. local heroGrid = bagIndex and fakeHuman.db.heroBag[bagIndex]
  1321. return heroGrid, bagIndex, fakeHuman
  1322. end
  1323. function shareData(human, uuid, heroIndex)
  1324. local msgRet = Msg.gc.GC_HERO_SHARE_DATA
  1325. local heroGrid, bagIndex, fakeHuman = getHeroShareGrid(uuid, heroIndex)
  1326. if heroGrid then
  1327. if not makeHeroShare(msgRet.data, heroGrid, bagIndex, fakeHuman) then
  1328. return
  1329. end
  1330. else
  1331. local monsterID, mosnterLv = JjcLogic.getHeroShareMonster(uuid, heroIndex)
  1332. if not monsterID then return end
  1333. makeHeroShareMonster(msgRet.data, monsterID, mosnterLv)
  1334. end
  1335. Msg.send(msgRet, human.fd)
  1336. end
  1337. -- 获取英雄背包中 最大等级的英雄
  1338. function getHeroBagMaxLev(human)
  1339. local maxLv = 1
  1340. for index, heroGrid in pairs(human.db.heroBag) do
  1341. if index ~= 0 and heroGrid.lv > maxLv then
  1342. maxLv = heroGrid.lv
  1343. end
  1344. end
  1345. return maxLv
  1346. end
  1347. -- 获取英雄背包中 最大星级的英雄
  1348. function getHeroBagMaxFuNeng(human)
  1349. local maxStar = 0
  1350. for index, heroGrid in pairs(human.db.heroBag) do
  1351. if index ~= 0 and heroGrid.id then
  1352. local heroConfig = HeroExcel.hero[heroGrid.id]
  1353. if heroConfig and heroConfig.star > 10 then
  1354. local star = heroConfig.star - 10
  1355. if star > maxStar then
  1356. maxStar = star
  1357. end
  1358. if maxStar >= HERO_MAX_STAR - 10 then
  1359. return maxStar
  1360. end
  1361. end
  1362. end
  1363. end
  1364. return maxStar
  1365. end
  1366. -- 战力最高的6个英雄战力和
  1367. local function sortCombat(a, b)
  1368. return a.zhandouli > b.zhandouli
  1369. end
  1370. local HeroSortTable = {}
  1371. function getHerosZDL(human)
  1372. Util.cleanTable(HeroSortTable)
  1373. local len = 0
  1374. for index, heroGrid in pairs(human.db.heroBag) do
  1375. if index ~= 0 then
  1376. len = len + 1
  1377. HeroSortTable[len] = heroGrid
  1378. end
  1379. end
  1380. if len > 1 then
  1381. table.sort(HeroSortTable, sortCombat)
  1382. end
  1383. local zhandouli = 0
  1384. for i = 1, 6 do
  1385. local grid = HeroSortTable[i]
  1386. zhandouli = zhandouli + (grid and grid.zhandouli or 0)
  1387. end
  1388. return zhandouli
  1389. end
  1390. --
  1391. function getHeroMaxZDL(human, camp)
  1392. local zhandouli = 0
  1393. local maxGrid = nil
  1394. for index, heroGrid in pairs(human.db.heroBag) do
  1395. if index ~= 0 then
  1396. local heroConfig = heroGrid and HeroExcel.hero[heroGrid.id]
  1397. if heroConfig and ((camp or 0) == 0 or heroConfig.camp == camp)
  1398. and heroGrid.zhandouli > zhandouli then
  1399. zhandouli = heroGrid.zhandouli
  1400. maxGrid = heroGrid
  1401. end
  1402. end
  1403. end
  1404. return zhandouli, maxGrid
  1405. end
  1406. -- 武将系统红点
  1407. function isDot(human)
  1408. if human.db.lv < 9 then
  1409. return false
  1410. end
  1411. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  1412. if not combatHero then return end
  1413. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  1414. local uuid = combatHero[i]
  1415. local heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  1416. if heroGrid then
  1417. if isHeroDot(human, heroGrid) then
  1418. return true
  1419. end
  1420. if HeroBook.isDot(human) == 1 then
  1421. return true
  1422. end
  1423. end
  1424. end
  1425. end
  1426. -- 某个伙伴是否有红点
  1427. function isHeroDot(human, heroGrid)
  1428. if not heroGrid then return end
  1429. if human.db.lv < 9 then
  1430. return false
  1431. end
  1432. -- 装备
  1433. if HeroEquip.isEquipDot(human, heroGrid) then
  1434. return true
  1435. end
  1436. if FuwenLogic.isFuwenDot(human, heroGrid) then
  1437. return true
  1438. end
  1439. -- 升级/进阶
  1440. if isHeroLevelDot(human, heroGrid) and
  1441. not XingYaoGongMing.isGongMing(human, heroIndex) then
  1442. return true
  1443. end
  1444. --
  1445. if isHeroJuexingDot(human, heroGrid.bagIndex, heroGrid) then
  1446. return true
  1447. end
  1448. if BingshuLogic.isBingShuDot(human, heroGrid) then
  1449. return
  1450. end
  1451. end
  1452. -- 升级判定
  1453. function isHeroLvDot(human, heroGrid)
  1454. if human.db.lv < 9 then
  1455. return false
  1456. end
  1457. local heroConfig = HeroExcel.hero[heroGrid.id]
  1458. if not heroConfig then return end
  1459. local lv = heroGrid and heroGrid.lv or 1
  1460. local star = heroConfig and heroConfig.star or 0
  1461. local quality = heroGrid and heroGrid.quality or 0
  1462. local maxLv = HeroGrid.getMaxLv(heroGrid.star, quality)
  1463. if lv < maxLv then -- 升级
  1464. local conf = UpNeedExcel.upLv[lv + 1]
  1465. if not conf then return end
  1466. if human.db.jinbi < conf.money then return end
  1467. if BagLogic.getItemCnt(human, ItemDefine.ITEM_GREEN_EXP_ID) < conf.soul then
  1468. return
  1469. end
  1470. return true
  1471. end
  1472. end
  1473. -- 进阶判断
  1474. function isHeroUpDot(human, heroGrid)
  1475. if human.db.lv < 9 then
  1476. return false
  1477. end
  1478. local heroConfig = HeroExcel.hero[heroGrid.id]
  1479. if not heroConfig then return end
  1480. local lv = heroGrid and heroGrid.lv or 1
  1481. local star = heroGrid and heroGrid.star or 0
  1482. local quality = heroGrid and heroGrid.quality or 0
  1483. -- 进阶
  1484. local maxQuality = HeroGrid.getMaxQuality(star)
  1485. if quality >= maxQuality then
  1486. return
  1487. end
  1488. local maxLv = HeroGrid.getMaxLv(heroGrid.star, maxQuality)
  1489. if lv < maxLv then
  1490. return
  1491. end
  1492. local conf = UpNeedExcel.upQuality[quality + 1]
  1493. if not conf then return end
  1494. if human.db.jinbi < conf.money then return end
  1495. if BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID) < conf.jinjieshi then
  1496. return
  1497. end
  1498. return true
  1499. end
  1500. -- 升级/进阶判断
  1501. function isHeroLevelDot(human, heroGrid)
  1502. if human.db.lv < 9 then
  1503. return false
  1504. end
  1505. if isHeroLvDot(human, heroGrid) then -- 升级
  1506. return true
  1507. end
  1508. if isHeroUpDot(human, heroGrid) then -- 进阶判断
  1509. return true
  1510. end
  1511. end
  1512. -- 升星/觉醒红点
  1513. function isHeroJuexingDot(human, heroIndex, heroGrid)
  1514. if human.db.lv < 9 then
  1515. return
  1516. end
  1517. local heroConfig = HeroExcel.hero[heroGrid.id]
  1518. if not heroConfig then return end
  1519. local attrConfig = HeroDefine.getAttrConfig(heroGrid.id, heroGrid.star)
  1520. if not attrConfig then return end
  1521. local nextAttrConfig = HeroDefine.getNextAttrConfig(heroGrid.id, heroGrid.star)
  1522. if not nextAttrConfig then
  1523. return sendHeroJueXingMax(human, heroGrid.id, heroIndex)
  1524. end
  1525. -- 角色等级/世界等级是否可以
  1526. local isFix = isFixUpStarLv(human, heroGrid.star + 1)
  1527. if not isFix then return end
  1528. -- 判断消耗材料
  1529. local needItemCnt = attrConfig.jinjieshi
  1530. if BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID) < needItemCnt then
  1531. return
  1532. end
  1533. -- 额外材料
  1534. for i = 1, #attrConfig.needItems do
  1535. local itemID = attrConfig.needItems[i][1]
  1536. local itemCnt = attrConfig.needItems[i][2]
  1537. if BagLogic.getItemCnt(human, itemID) < itemCnt then
  1538. return
  1539. end
  1540. end
  1541. local without = {}
  1542. without[heroIndex] = true
  1543. for _, cond in ipairs(attrConfig.cond) do
  1544. local ctype = cond[1]
  1545. local needCnt = cond[3]
  1546. if not needCnt then return end
  1547. if ctype == HechengLogic.COND_TYPE_CAMPSTAR then
  1548. needCnt = cond[4]
  1549. end
  1550. for i = 1, needCnt do
  1551. local index = selectJuexingGrid(human, ctype, cond, without)
  1552. if not index then return end
  1553. without[index] = true
  1554. end
  1555. end
  1556. return true
  1557. end
  1558. -- 查找升星材料
  1559. function selectJuexingGrid(human, ctype, cond, without)
  1560. for index, heroGrid in pairs(human.db.heroBag) do
  1561. if index ~= 0 and not without[index] and
  1562. isFixJuexingCond(heroGrid, ctype, cond) then
  1563. return index
  1564. end
  1565. end
  1566. end
  1567. -- 是否满足材料需求
  1568. function isFixJuexingCond(grid, ctype, cond)
  1569. local heroConfig = HeroExcel.hero[grid.id]
  1570. if not heroConfig then return end
  1571. if ctype == HechengLogic.COND_TYPE_HEROID then
  1572. local needConfig = HeroExcel.hero[cond[2]]
  1573. if not needConfig then return end
  1574. local needStar = cond[4] or needConfig.star
  1575. if grid.id == cond[2] and needStar == grid.star then
  1576. return true
  1577. end
  1578. elseif ctype == HechengLogic.COND_TYPE_CAMPSTAR then
  1579. if cond[2] ~= 0 and cond[2] ~= heroConfig.camp then
  1580. return
  1581. end
  1582. if cond[3] ~= grid.star then
  1583. return
  1584. end
  1585. return true
  1586. end
  1587. end
  1588. function sendBagDots(human)
  1589. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  1590. local msgRet = Msg.gc.GC_HERO_BAG_DOTS
  1591. msgRet.list[0] = 0
  1592. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  1593. local uuid = combatHero and combatHero[i]
  1594. local heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  1595. if heroGrid then
  1596. msgRet.list[0] = msgRet.list[0] + 1
  1597. local net = msgRet.list[msgRet.list[0]]
  1598. net.bagIndex = heroGrid.bagIndex
  1599. net.isDot = isHeroDot(human, heroGrid) and 1 or 0
  1600. end
  1601. end
  1602. --Msg.trace(msgRet)
  1603. msgRet.bookDot = HeroBook.isDot(human)
  1604. Msg.send(msgRet, human.fd)
  1605. refreshDot(human)
  1606. end
  1607. function refreshDot(human, uuid)
  1608. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  1609. if not combatHero then return end
  1610. local isFind = nil
  1611. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  1612. if uuid == nil or combatHero[i] == uuid then
  1613. isFind = true
  1614. break
  1615. end
  1616. end
  1617. if not isFind then return end
  1618. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_301)
  1619. end
  1620. -- 今日英雄重置剩余次数
  1621. function getResetLeftCnt(human)
  1622. local heroResetCnt = human.db.heroResetCnt or 0
  1623. return math.max(HERO_RESET_FREECNT - heroResetCnt, 0)
  1624. end
  1625. -- 重置返还材料
  1626. local RESET_RETURN_ITEMS = {}
  1627. function getResetReturnItems(heroGrid)
  1628. Util.cleanTable(RESET_RETURN_ITEMS)
  1629. -- 升级
  1630. local lv = heroGrid.lv
  1631. if heroGrid.oldLV then
  1632. lv = heroGrid.oldLV
  1633. end
  1634. for i = 2, lv do
  1635. local upcf = UpNeedExcel.upLv[i]
  1636. if upcf then
  1637. RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] or 0) +
  1638. upcf.soul
  1639. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) +
  1640. upcf.money
  1641. end
  1642. end
  1643. -- 升阶
  1644. local quality = heroGrid.quality
  1645. if heroGrid.oldQuality then
  1646. quality = heroGrid.oldQuality
  1647. end
  1648. -- 升阶
  1649. for i = 1, quality do
  1650. local upcf = UpNeedExcel.upQuality[i]
  1651. if upcf then
  1652. RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] or 0) +
  1653. upcf.jinjieshi
  1654. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) +
  1655. upcf.money
  1656. end
  1657. end
  1658. -- 升星材料
  1659. for i = 1, heroGrid.star do
  1660. local attrConfig = HeroDefine.getAttrConfig(heroGrid.id, i)
  1661. if attrConfig then
  1662. if attrConfig.jinjieshi > 0 then RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] or 0) +
  1663. attrConfig.jinjieshi end
  1664. for j = 1, #attrConfig.needItems do
  1665. RESET_RETURN_ITEMS[attrConfig.needItems[j][1]] = (RESET_RETURN_ITEMS[attrConfig.needItems[j][1]] or 0) +
  1666. attrConfig.needItems[j][2]
  1667. end
  1668. end
  1669. end
  1670. -- 护符/水晶材料
  1671. local maxCnt = 100 -- 防止死循环
  1672. local equipID = heroGrid.equip and heroGrid.equip[ItemDefine.EQUIP_SUBTYPE_SHUIJIN]
  1673. while equipID do
  1674. maxCnt = maxCnt - 1
  1675. if maxCnt < 0 then
  1676. assert()
  1677. end
  1678. local eupcf = EquipExcel.shuijingUpNeed[equipID]
  1679. if not eupcf then break end
  1680. local preEquipID = eupcf.prevID
  1681. equipID = preEquipID
  1682. if preEquipID > 0 then
  1683. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) +
  1684. eupcf.money
  1685. RESET_RETURN_ITEMS[ItemDefine.ITEM_SHUIJING_UPLEVEL_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_SHUIJING_UPLEVEL_ID] or 0) +
  1686. eupcf.jinghua
  1687. end
  1688. end
  1689. return RESET_RETURN_ITEMS
  1690. end
  1691. function getRealResetReturnItems(heroGrid)
  1692. Util.cleanTable(RESET_RETURN_ITEMS)
  1693. -- 升级
  1694. local lv = heroGrid.lv
  1695. if heroGrid.oldLV then
  1696. lv = heroGrid.oldLV
  1697. end
  1698. for i = 2, lv do
  1699. local upcf = UpNeedExcel.upLv[i]
  1700. if upcf then
  1701. RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] or 0) +
  1702. upcf.soul
  1703. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) +
  1704. upcf.money
  1705. end
  1706. end
  1707. -- 升阶
  1708. local quality = heroGrid.quality
  1709. if heroGrid.oldQuality then
  1710. quality = heroGrid.oldQuality
  1711. end
  1712. -- 升阶
  1713. for i = 1, quality do
  1714. local upcf = UpNeedExcel.upQuality[i]
  1715. if upcf then
  1716. RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] or 0) +
  1717. upcf.jinjieshi
  1718. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) +
  1719. upcf.money
  1720. end
  1721. end
  1722. return RESET_RETURN_ITEMS
  1723. end
  1724. -- 重置花费
  1725. function getResetNeedZuanshi(lv)
  1726. if lv > 100 then
  1727. return 50
  1728. end
  1729. return 0
  1730. end
  1731. -- 重置查询
  1732. function resetHeroQuery(human, heroID, heroIndex)
  1733. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1734. if not heroGrid then return end
  1735. if XingYaoGongMing.isGongMing(human, heroIndex, XingYaoGongMing.XYHERO_RESET) then
  1736. return
  1737. end
  1738. local heroConfig = HeroExcel.hero[heroGrid.id]
  1739. if not heroConfig then return end
  1740. if heroConfig.star > HERO_RESET_MAXSTAR then
  1741. return Broadcast.sendErr(human, Util.format(Lang.HERO_RESET_ERR_STAR, HERO_RESET_MAXSTAR + 1))
  1742. end
  1743. ObjHuman.updateDaily(human)
  1744. --[[if getResetLeftCnt(human) < 1 then
  1745. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_CNT)
  1746. end--]]
  1747. local list = getRealResetReturnItems(heroGrid)
  1748. local msgRet = Msg.gc.GC_HERO_RESET_QUERY
  1749. msgRet.heroID = heroID
  1750. msgRet.heroIndex = heroIndex
  1751. msgRet.needZuanshi = getResetNeedZuanshi(heroGrid.lv)
  1752. msgRet.maxFreeCnt = HERO_RESET_FREECNT
  1753. msgRet.leftFreeCnt = getResetLeftCnt(human)
  1754. msgRet.items[0] = 0
  1755. for itemID, itemCnt in pairs(list) do
  1756. if msgRet.items[0] >= #msgRet.items then
  1757. break
  1758. end
  1759. msgRet.items[0] = msgRet.items[0] + 1
  1760. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  1761. end
  1762. if msgRet.items[0] < 1 then
  1763. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_NONE)
  1764. end
  1765. -- Msg.trace(msgRet)
  1766. Msg.send(msgRet, human.fd)
  1767. end
  1768. -- 英雄重置
  1769. function resetHero(human, heroID, heroIndex)
  1770. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1771. if not heroGrid then return end
  1772. if XingYaoGongMing.isGongMing(human, heroIndex, XingYaoGongMing.XYHERO_RESET) then
  1773. return
  1774. end
  1775. local heroConfig = HeroExcel.hero[heroGrid.id]
  1776. if not heroConfig then return end
  1777. if heroConfig.star > HERO_RESET_MAXSTAR then
  1778. return Broadcast.sendErr(human, Util.format(Lang.HERO_RESET_ERR_STAR, HERO_RESET_MAXSTAR + 1))
  1779. end
  1780. local list = getRealResetReturnItems(heroGrid)
  1781. if not next(list) then
  1782. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_NONE)
  1783. end
  1784. if getResetLeftCnt(human) < 1 then
  1785. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_CNT)
  1786. end
  1787. local needZuanshi = getResetNeedZuanshi(heroGrid.lv)
  1788. if not ObjHuman.checkRMB(human, needZuanshi) then
  1789. return
  1790. end
  1791. ObjHuman.decZuanshi(human, -needZuanshi, "hero_reset")
  1792. human.db.heroResetCnt = (human.db.heroResetCnt or 0) + 1
  1793. heroGrid.lv = 1
  1794. heroGrid.quality = 0
  1795. if heroGrid.equip and heroGrid.equip[ItemDefine.EQUIP_SUBTYPE_SHUIJIN] then
  1796. heroGrid.equip[ItemDefine.EQUIP_SUBTYPE_SHUIJIN] = nil
  1797. heroGrid.shuijingAttrID = nil
  1798. end
  1799. for itemID, itemCnt in pairs(list) do
  1800. BagLogic.addItem(human, itemID, itemCnt, "hero_reset")
  1801. end
  1802. HeroEquip.putOffQuick(human, heroID, heroIndex, true)
  1803. FuwenLogic.putOffQuick(human, heroID, heroIndex, true)
  1804. XingYaoGongMing.onDelHero(human, heroGrid, heroIndex)
  1805. heroGrid.fuwen = nil
  1806. ObjHuman.doCalcHero(human, heroIndex)
  1807. sendHeroBagDynamic(human, heroID, heroIndex)
  1808. refreshDot(human, heroGrid.uuid)
  1809. local msgRet = Msg.gc.GC_HERO_RESET
  1810. msgRet.heroID = heroID
  1811. msgRet.heroIndex = heroIndex
  1812. msgRet.items[0] = 0
  1813. for itemID, itemCnt in pairs(list) do
  1814. if msgRet.items[0] >= #msgRet.items then
  1815. break
  1816. end
  1817. if not ItemDefine.isEquip(itemID) then
  1818. msgRet.items[0] = msgRet.items[0] + 1
  1819. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  1820. end
  1821. end
  1822. msgRet.items[0] = EquipLogic.makeEquipItem(human, msgRet.items, msgRet.items[0])
  1823. Msg.send(msgRet, human.fd)
  1824. checkChangeMaxZDL(human, heroGrid)
  1825. end