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