HeroLogic.lua 67 KB

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