HeroLogic.lua 72 KB

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