HeroLogic.lua 66 KB

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