HeroLogic.lua 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924
  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 EquipLogic = require("equip.EquipLogic")
  57. local XingYaoGongMing = require("xingYaoMen.XingYaoGongMing")
  58. local HeroGrowUp = require("absAct.HeroGrowUp")
  59. local MengxinLogic = require("present.MengxinLogic")
  60. local Config = require("Config")
  61. local HeroLogLogic = require("absAct.HeroLogLogic")
  62. local ExclusiveTaskLogic = require("absAct.ExclusiveTaskLogic")
  63. local YunYingLogic = require("yunying.YunYingLogic")
  64. local BingshuLogic = require("fuwen.BingshuLogic")
  65. local GiftLogic = require("topup.GiftLogic")
  66. local HeroMiddleLogic = require("hero.HeroMiddleLogic")
  67. local CommonDefine = require("common.CommonDefine")
  68. local HeroExclusiveWeapon = require("hero.HeroExclusiveWeapon")
  69. local TriggerDefine = require("trigger.TriggerDefine")
  70. local TriggerLogic = require("trigger.TriggerLogic")
  71. local HeroPubLogic = require("hero.HeroPubLogic")
  72. local WinnerRelicLogic = require("winnerRelic.WinnerRelicLogic")
  73. local GodsAreaNS = require("godsArea.GodsAreaNS")
  74. local Abs365CardLogic = require("absAct.Abs365CardLogic")
  75. local HeroSeed = require("hero.HeroSeed")
  76. HERO_MAX_STAR = 15 -- 目前英雄最大星级
  77. local HERO_RESET_FREECNT = 10 -- 每日重置次数
  78. local HERO_RESET_MAXSTAR = 9 -- 只能重置9星以下(包含9星)
  79. local CHONGSHENG_RETURN_STAR = 5 -- 重生返还x星本体碎片
  80. -- 用于弹窗礼包类型
  81. local Upgrade_HERO_EVENT = 3
  82. ----------------------------------- 结构体封装 --------------------------------------
  83. -- 获取技能信息
  84. function makeSkillNet(net, id)
  85. local skillConfig = SkillExcel.skill[id]
  86. if not skillConfig then return end
  87. net.id = id
  88. net.icon = skillConfig.icon
  89. net.name = skillConfig.name
  90. net.type = skillConfig.type
  91. net.desc = skillConfig.desc
  92. net.need = skillConfig.need or 0
  93. net.lv = skillConfig.skillLv or 0
  94. -- todo
  95. net.cd[0] = #skillConfig.cd
  96. if net.cd[0] ~= 0 then
  97. net.cd[1] = skillConfig.cd[1]
  98. net.cd[2] = skillConfig.cd[2]
  99. end
  100. local len = #skillConfig.buffers
  101. for i = 1,len do
  102. local buffId = skillConfig.buffers[i][1]
  103. local buffConfig = BufferExcel.buffer[buffId]
  104. net.buff[i].id = buffId
  105. net.buff[i].name = buffConfig.name
  106. net.buff[i].desc = buffConfig.desc
  107. end
  108. net.buff[0] = len
  109. net.lvUpDesc = skillConfig.lvUpDesc
  110. -- todo
  111. end
  112. -- 封装UpStarCond协议结构体
  113. function makeUpStarCond(net, cond)
  114. local ttype = cond[1]
  115. net.type = ttype
  116. if ttype == HechengLogic.COND_TYPE_HEROID then
  117. local heroID = cond[2]
  118. local heroConfig = HeroExcel.hero[heroID]
  119. local star = cond[4] or heroConfig.star
  120. net.id = heroID
  121. net.icon = heroConfig.head
  122. net.star = star
  123. net.camp = heroConfig.camp
  124. net.name = heroConfig.name
  125. net.grade = heroConfig.grade
  126. net.cnt = cond[3]
  127. elseif ttype == HechengLogic.COND_TYPE_CAMPSTAR then
  128. net.id = 0
  129. net.icon = 0
  130. net.name = ""
  131. net.grade = 0
  132. net.camp = cond[2]
  133. net.star = cond[3]
  134. net.cnt = cond[4]
  135. end
  136. end
  137. -------------------------------- 英雄属性计算 ------------------------------------------
  138. --等级加成
  139. local function lvAdd(lv, upAttrs, attrs)
  140. for _, upAttr in ipairs(upAttrs) do
  141. local key = upAttr[1]
  142. local value = upAttr[2]
  143. attrs[key] = attrs[key] + value * (lv - 1)
  144. end
  145. end
  146. --星級加成
  147. local function starAdd(star, atkStarRate, hpStarRate, attrs)
  148. attrs[RoleDefine.ATK] = attrs[RoleDefine.ATK] * (1 + atkStarRate/10000)
  149. attrs[RoleDefine.HP] = attrs[RoleDefine.HP] * (1 + hpStarRate/10000)
  150. end
  151. --阶数加成
  152. local function qualityAdd(heroConfig, quality, attrs)
  153. local qualityConfig = HeroExcel.quality[heroConfig.quality]
  154. local qualityEnd = quality + 1
  155. for i = 1, qualityEnd do
  156. for key, rateConfig in pairs(qualityConfig) do
  157. local rate = rateConfig[i]
  158. if rate then
  159. if key == RoleDefine.DEF or key == RoleDefine.SPEED then
  160. attrs[key] = attrs[key] + rate[1]
  161. else
  162. attrs[key] = attrs[key] * rate[1]
  163. end
  164. end
  165. end
  166. end
  167. end
  168. -- 伙伴基础
  169. function doCalcHero(grid, attrs)
  170. if not grid and attrs then return end
  171. local heroConfig = HeroExcel.hero[grid.id]
  172. local attrConfig = HeroDefine.getAttrConfig(grid.id, grid.star)
  173. if not attrConfig then
  174. assert(nil, "attrConfig is nil id "..grid.id.." star "..grid.star)
  175. end
  176. for _,v in ipairs(attrConfig.attrs) do
  177. RoleAttr.updateValue(v[1], v[2], attrs)
  178. end
  179. lvAdd(grid.lv, attrConfig.up, attrs)
  180. starAdd(grid.star, attrConfig.atkStarRate, attrConfig.hpStarRate, attrs)
  181. qualityAdd(heroConfig, grid.quality, attrs)
  182. end
  183. -- 时装
  184. function doCalcHeroSkin(skinID, attrs)
  185. --[[local skinConfig = SkinExcel.skin[skinID]
  186. for _, v in ipairs(skinConfig.attrs) do
  187. RoleAttr.updateValue(v[1], v[2], attrs)
  188. end]]
  189. end
  190. -------------------------------------------------------------------------------------
  191. -------------------------------------------------------------------------------------
  192. local function sortZhanli(a, b)
  193. return a[2] > b[2]
  194. end
  195. function TransformHeroEquipAttr(human)
  196. for index = 1, human.db.heroBag[0] do
  197. local heroGrid = human.db.heroBag[index]
  198. if heroGrid and heroGrid.lv >= 2 then
  199. for i = 1, ItemDefine.EQUIP_MAX_CNT do
  200. local equipGrid = heroGrid.equip and heroGrid.equip[i]
  201. if equipGrid then
  202. if equipGrid.attr then
  203. local _, attrInfo = next(equipGrid.attr)
  204. if type(attrInfo) == "table" then
  205. return
  206. end
  207. equipGrid.attr = EquipLogic.AttrHashToArray(equipGrid.attr)
  208. end
  209. if equipGrid.washAttr then
  210. equipGrid.washAttr = EquipLogic.AttrHashToArray(equipGrid.washAttr)
  211. end
  212. end
  213. end
  214. end
  215. end
  216. end
  217. -- 下发英雄背包列表
  218. function sendHeroBagList(human)
  219. local msgRet = Msg.gc.GC_HERO_BAG_LIST
  220. local cnt = 0
  221. human.maxZDL = {}
  222. human.maxZDL.maxHero = {}
  223. human.maxZDL.heroCnt = 0
  224. human.maxZDL.zhandouli = 0
  225. local list = {}
  226. for index = 1, human.db.heroBag[0] do
  227. local heroGrid = human.db.heroBag[index]
  228. if heroGrid then
  229. -- 对皮肤进行一下检测
  230. -- if heroGrid.body then
  231. -- local nHeroID = heroGrid.id or heroGrid.heroID
  232. -- local tHeroCof = HeroExcel.hero[heroGrid.heroID]
  233. -- if tHeroCof and heroGrid.body ~= tHeroCof.body then
  234. -- local tSkinCof = SkillExcel.skin[heroGrid.body]
  235. -- if tSkinCof then
  236. -- if tSkinCof.heroId ~= heroGrid.heroID then
  237. -- print("[sendHeroBagList] 玩家当前英雄身体数据不正确 heroID = "..heroGrid.heroID.." OldBodyID = "..heroGrid.body.." NewBodyID = "..tHeroCof.body)
  238. -- heroGrid.body = tHeroCof.body
  239. -- end
  240. -- end
  241. -- else
  242. -- print("[sendHeroBagList] 不存在对应的配置 nHeroID = "..nHeroID)
  243. -- end
  244. -- end
  245. cnt = cnt + 1
  246. HeroGrid.makeHeroSimple(msgRet.list[cnt], heroGrid, index, human)
  247. if cnt >= HeroDefine.PAGE_HERO_COUNT then
  248. msgRet.list[0] = cnt
  249. Msg.send(msgRet, human.fd)
  250. cnt = 0
  251. end
  252. list[#list + 1] = {heroGrid.uuid or "", heroGrid.zhandouli or 0}
  253. end
  254. end
  255. if cnt > 0 then
  256. msgRet.list[0] = cnt
  257. Msg.send(msgRet, human.fd)
  258. end
  259. if #list > 0 then
  260. table.sort( list , sortZhanli )
  261. local maxCnt = human.db.lv >= 100 and 6 or 5
  262. for i = 1 , maxCnt do
  263. local heroDb = list[i]
  264. if heroDb then
  265. human.maxZDL.heroCnt = human.maxZDL.heroCnt + 1
  266. human.maxZDL.maxHero[heroDb[1]] = heroDb[2]
  267. human.maxZDL.zhandouli = human.maxZDL.zhandouli + heroDb[2]
  268. end
  269. end
  270. end
  271. SkinLogic.OnLoginCheckEquipSkin(human)
  272. print(" human onLogin maxZDL is : ", human.maxZDL.zhandouli)
  273. end
  274. -- 修正 玩家最高战力
  275. function checkChangeMaxZDL(human, heroGrid)
  276. if human.maxZDL and heroGrid.uuid then
  277. if human.maxZDL.maxHero[heroGrid.uuid] then
  278. human.maxZDL.maxHero[heroGrid.uuid] = heroGrid.zhandouli
  279. human.maxZDL.zhandouli = 0
  280. for _, v in pairs(human.maxZDL.maxHero) do
  281. human.maxZDL.zhandouli = human.maxZDL.zhandouli + v
  282. end
  283. else
  284. local maxCnt = human.db.lv >= 100 and 6 or 5
  285. if human.maxZDL.heroCnt < maxCnt then
  286. human.maxZDL.maxHero[heroGrid.uuid] = heroGrid.zhandouli
  287. human.maxZDL.zhandouli = human.maxZDL.zhandouli + heroGrid.zhandouli
  288. human.maxZDL.heroCnt = human.maxZDL.heroCnt + 1
  289. else
  290. local minZDL = 0
  291. local minUuid
  292. for thisUuid, v in pairs(human.maxZDL.maxHero) do
  293. minUuid = minZDL == 0 and thisUuid or minUuid
  294. minZDL = minZDL == 0 and v or minZDL
  295. if minZDL > v then
  296. minZDL = v
  297. minUuid = thisUuid
  298. end
  299. end
  300. if minZDL < heroGrid.zhandouli then
  301. human.maxZDL.maxHero[minUuid] = nil
  302. human.maxZDL.maxHero[heroGrid.uuid] = heroGrid.zhandouli
  303. human.maxZDL.zhandouli = human.maxZDL.zhandouli - minZDL + heroGrid.zhandouli
  304. end
  305. end
  306. end
  307. print(" checkChangeMaxZDL ", human.maxZDL.zhandouli)
  308. end
  309. end
  310. -- 发送英雄详细信息:静态,只是1个英雄的
  311. function sendHeroBagStatic(human, id, tuJian)
  312. local heroConfig = HeroExcel.hero[id]
  313. if not heroConfig then return end
  314. local msgRet = Msg.gc.GC_HERO_BAG_STATIC
  315. HeroGrid.makeHeroStatic(msgRet.heroStatic, id, tuJian)
  316. Msg.send(msgRet, human.fd)
  317. end
  318. -- 玩家身上动态数据
  319. function sendHeroGridDynamic(human, heroGrid, index, isQuery)
  320. if not isQuery then sendHeroBagUpdate(human, index) end
  321. local msgRet = Msg.gc.GC_HERO_BAG_DYNAMIC
  322. msgRet.index = index or 0
  323. msgRet.canLv = isHeroLvDot(human, heroGrid) == true and 1 or 0
  324. msgRet.canUp = isHeroUpDot(human, heroGrid) == true and 1 or 0
  325. msgRet.canEquip = HeroEquip.isEquipDot(human, heroGrid) == true and 1 or 0
  326. msgRet.canFuwen = FuwenLogic.isFuwenDot(human, heroGrid) == true and 1 or 0
  327. msgRet.canJueXing = isHeroJuexingDot(human, index, heroGrid) == true and 1 or 0
  328. msgRet.canWeapon = HeroExclusiveWeapon.isWeaponDot(human, heroGrid) == true and 1 or 0
  329. msgRet.canSeed = HeroSeed.isSeedDot(human, heroGrid) == true and 1 or 0
  330. local bingShuState = BingshuLogic.isBingShuDot(human, heroGrid)
  331. if bingShuState == -1 then
  332. msgRet.canBingShu = -1
  333. else
  334. msgRet.canBingShu = bingShuState == true and 1 or 0
  335. end
  336. HeroGrid.makeHeroDynamic(msgRet.heroDynamic, heroGrid, index, human)
  337. Msg.send(msgRet, human.fd)
  338. end
  339. -- 配置数据
  340. function sendHeroBagDynamicByID(human, heroID, star)
  341. local msgRet = Msg.gc.GC_HERO_BAG_DYNAMIC_BY_ID
  342. HeroGrid.makeHeroDynamicByID(msgRet.heroDynamic, heroID, star)
  343. Msg.send(msgRet, human.fd)
  344. end
  345. -- 发送英雄详细信息
  346. function sendHeroBagDynamic(human, id, index, isQuery)
  347. local heroGrid = getHeroGrid(human, id, index)
  348. if not heroGrid then return end
  349. sendHeroGridDynamic(human, heroGrid, index, isQuery)
  350. end
  351. -- 发送英雄添加/变化
  352. function sendHeroBagUpdate(human, index)
  353. local heroGrid = human.db.heroBag[index]
  354. if type(heroGrid) ~= "table" then return end
  355. local msgRet = Msg.gc.GC_HERO_BAG_ADD
  356. HeroGrid.makeHeroSimple(msgRet.data, heroGrid, index, human)
  357. Msg.send(msgRet, human.fd)
  358. end
  359. -- 发送英雄删除
  360. function sendHeroBagDel(human, index)
  361. local msgRet = Msg.gc.GC_HERO_BAG_DELETE
  362. msgRet.index = index
  363. Msg.send(msgRet, human.fd)
  364. end
  365. -- 背包容量查询
  366. function sendHeroBagCap(human)
  367. calcHeroBagCap(human)
  368. local nowBuyCnt = human.db.buyCapCnt or 0
  369. local msgRet = Msg.gc.GC_HERO_CAP_QUERY
  370. msgRet.cap = human.db.heroBag[0]
  371. msgRet.buyZuanshi = (nowBuyCnt + 1) * 100
  372. if nowBuyCnt >= HeroDefine.BUY_CAP_CNT then
  373. msgRet.buyZuanshi = -1 --达到上限
  374. end
  375. Msg.send(msgRet, human.fd)
  376. end
  377. -----------------------------------------------------------------------------------------
  378. -- 锁定英雄
  379. function lockHero(human, isLock, heroID, heroIndex)
  380. local heroGrid = human.db.heroBag[heroIndex]
  381. if heroGrid == nil or heroGrid.id ~= heroID then
  382. return
  383. end
  384. if isLock == 1 then
  385. heroGrid.isLock = true
  386. elseif isLock == 0 then
  387. heroGrid.isLock = nil
  388. end
  389. local msgRet = Msg.gc.GC_HERO_BAG_LOCK
  390. msgRet.heroID = heroID
  391. msgRet.heroIndex = heroIndex
  392. msgRet.type = heroGrid.isLock and 1 or 0
  393. Msg.send(msgRet, human.fd)
  394. end
  395. -- 返回英雄背包空余格子数
  396. function getEmptyCnt(human)
  397. local emptyCnt = 0
  398. for i = 1, human.db.heroBag[0] do
  399. if human.db.heroBag[i] == nil then
  400. emptyCnt = emptyCnt + 1
  401. end
  402. end
  403. return emptyCnt
  404. end
  405. -- 获得英雄背包第一个空格子下标
  406. function getEmptyIndex(human)
  407. for index = 1, human.db.heroBag[0]do
  408. local grid = human.db.heroBag[index]
  409. if grid == nil then
  410. return index
  411. end
  412. end
  413. end
  414. -- 新增英雄
  415. function addHero(human, id, star, cnt, logType, noSend)
  416. if cnt < 1 then return end
  417. local heroConfig = HeroExcel.hero[id]
  418. if not heroConfig then return end
  419. -- 某些英雄自动分解
  420. local isFenjie, fenjieList = FenjieLogic.autoFenjie(human, id, cnt, logType)
  421. if isFenjie then
  422. return nil, fenjieList
  423. end
  424. -- 先判断英雄背包是否满
  425. if getEmptyCnt(human) < cnt then
  426. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  427. end
  428. local heroIndex, uuid = nil
  429. for i = 1, cnt do
  430. local heroGrid = HeroGrid.createHeroGrid(id,star)
  431. -- 判断英雄是否已经穿戴了皮肤,如果有应该同步
  432. local skinLogic = require"skin.SkinLogic"
  433. local skinOn = skinLogic.checkHeroSkinById(human,id)
  434. if skinOn then
  435. heroGrid.skinOn = skinOn
  436. end
  437. heroIndex = addHeroByGrid(human, heroGrid, logType, noSend)
  438. uuid = heroGrid.uuid
  439. end
  440. return heroIndex, uuid
  441. end
  442. -- 英雄添加日志
  443. function writeLogHeroAdd(human, logType, heroGrid)
  444. -- Log.write(Log.LOGID_OSS_HERO, human.db._id, human.db.account, human.db.name, human.db.lv,
  445. -- LogDefine.DEFINE[logType] + LogDefine.TYPE["hero"] , heroGrid.id, 1, heroGrid.uuid, heroGrid.star)
  446. Log.write(Log.LOGID_OSS_HERO, human.db._id, human.db.newUniqueTag, human.db.name, human.db.lv,
  447. LogDefine.DEFINE[logType] + LogDefine.TYPE["hero"] , heroGrid.id, 1, heroGrid.uuid, heroGrid.star)
  448. end
  449. -- 英雄删除日志
  450. function writeLogHeroDel(human, logType, heroGrid)
  451. -- Log.write(Log.LOGID_OSS_HERO, human.db._id, human.db.account, human.db.name, human.db.lv,
  452. -- LogDefine.DEFINE[logType] + LogDefine.TYPE["hero"] , heroGrid.id, -1, heroGrid.uuid, heroGrid.star)
  453. Log.write(Log.LOGID_OSS_HERO, human.db._id, human.db.newUniqueTag, human.db.name, human.db.lv,
  454. LogDefine.DEFINE[logType] + LogDefine.TYPE["hero"] , heroGrid.id, -1, heroGrid.uuid, heroGrid.star)
  455. end
  456. -- 新增英雄
  457. function addHeroByGrid(human, heroGrid, logType, noSend)
  458. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["hero"] then
  459. assert()
  460. end
  461. local heroConfig = HeroExcel.hero[heroGrid.id]
  462. if not heroConfig then return end
  463. -- 某些英雄自动分解
  464. local isFenjie, fenjieList = FenjieLogic.autoFenjie(human, heroGrid.id, 1, logType)
  465. if isFenjie then
  466. return nil, fenjieList
  467. end
  468. -- 先判断英雄背包是否满
  469. if getEmptyCnt(human) < 1 then
  470. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  471. end
  472. local emptyIndex = getEmptyIndex(human)
  473. if not emptyIndex then return end
  474. heroGrid.bagIndex = emptyIndex
  475. human.db.heroBag[emptyIndex] = heroGrid
  476. ObjHuman.doCalcHero(human, emptyIndex)
  477. if not noSend then
  478. sendHeroBagUpdate(human, emptyIndex)
  479. end
  480. onGetNewHero(human, heroGrid, logType, emptyIndex)
  481. writeLogHeroAdd(human, logType, heroGrid)
  482. checkChangeMaxZDL(human, heroGrid)
  483. if heroConfig.grade >= HeroDefine.HERO_SSR_GRADE then
  484. HeroPubLogic.UpdateHero(human, HeroPubLogic.HERO_OP_ADD, heroGrid.id, heroGrid.uuid)
  485. end
  486. return emptyIndex
  487. end
  488. local yunYingActParam = {}
  489. function onGetNewHero(human, heroGrid, logType, heroIndex)
  490. local heroConfig = HeroExcel.hero[heroGrid.id]
  491. local grade = heroConfig.grade
  492. HeroBook.onAddHero(human, heroGrid.id, heroGrid.star)
  493. RoleHeadLogic.onAddHero(human, heroGrid.id)
  494. -- 先知置换 和十星置换 不予计算活动
  495. if logType ~= "xianzhi_zhihuan" and logType ~= "tenStar_displace" then
  496. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_HERO)
  497. TuiSongLiBao.tuiSongLiBaoOnTask(human, TuiSongLiBao.TUISONGLIBAOTASK_STARS_HERO, heroConfig.star, nil)
  498. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE12, heroGrid.star)
  499. if grade == 4 then
  500. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_15,1)
  501. end
  502. end
  503. XingYaoGongMing.onAddHero(human,heroGrid,heroIndex)
  504. HeroLogLogic.finishTaskCB(human, HeroLogLogic.HERO_LOG_TYPE_7, 1, heroGrid.id)
  505. for i in ipairs(yunYingActParam) do
  506. yunYingActParam[i] = nil
  507. end
  508. yunYingActParam[1] = logType
  509. yunYingActParam[2] = heroGrid.id
  510. yunYingActParam[3] = 1
  511. YunYingLogic.onCallBack(human, "onGetNewHeroAct", yunYingActParam)
  512. for i in ipairs(yunYingActParam) do
  513. yunYingActParam[i] = nil
  514. end
  515. yunYingActParam[1] = heroGrid.id
  516. yunYingActParam[2] = heroGrid.star
  517. yunYingActParam[3] = 1
  518. YunYingLogic.onCallBack(human, "onHeroStarChange", yunYingActParam)
  519. -- 获取新英雄
  520. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_GETPOINTHERO, human.db._id, 1, heroGrid.star, heroGrid.id)
  521. end
  522. -- 根据下标删除英雄
  523. function delHeroByIndex(human, index, logType, noSend)
  524. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["hero"] then
  525. assert()
  526. end
  527. if human.db.heroBag[index] == nil then
  528. return
  529. end
  530. --SkinLogic.onDelHero(human, index)
  531. local heroGrid = human.db.heroBag[index]
  532. human.db.heroBag[index] = nil
  533. human.heroAttrs[index] = nil
  534. if not noSend then
  535. sendHeroBagDel(human, index)
  536. end
  537. -- 删除酒馆任务中的上战的英雄
  538. BarTaskLogic.heroIndexByDelForPos(human, index)
  539. -- 删除 默认出站队列中的 英雄
  540. CombatPosLogic.heroIndexByDelForPos(human, heroGrid.uuid)
  541. XingYaoGongMing.onDelHero(human,heroGrid,index)
  542. ObjHuman.doCalc(human)
  543. writeLogHeroDel(human, logType, heroGrid)
  544. local heroConfig = HeroExcel.hero[heroGrid.id]
  545. if heroConfig.grade >= HeroDefine.HERO_SSR_GRADE then
  546. HeroPubLogic.UpdateHero(human, HeroPubLogic.HERO_OP_DEL, heroGrid.id, heroGrid.uuid)
  547. end
  548. GodsAreaNS.UpdateHeroData(human, heroGrid.uuid, 0)
  549. end
  550. -- 英雄升级
  551. function heroLvUp(human, heroID, heroIndex)
  552. local heroGrid = human.db.heroBag[heroIndex]
  553. if heroGrid == nil or heroGrid.id ~= heroID then
  554. return
  555. end
  556. local heroConfig = HeroExcel.hero[heroID]
  557. if not heroConfig then return end
  558. if XingYaoGongMing.isGongMing(human,heroIndex,XingYaoGongMing.XYHERO_LV) then
  559. return
  560. end
  561. -- 判断等级上限
  562. local star = heroGrid.star
  563. local nowLv = heroGrid.lv
  564. local maxLv = HeroGrid.getMaxLv(star, heroGrid.quality)
  565. if nowLv >= maxLv then
  566. return
  567. end
  568. -- local upLv, needJinbi, needSoulCnt = HeroGrid.getLevelUpCnt(human, nowLv, maxLv)
  569. -- 改为一次只能升一级
  570. -- local upLv, needJinbi, needSoulCnt = HeroGrid.getLevelUpCnt(human, nowLv, nowLv+1)
  571. -- 新修改:10级前一次最高升5级,10级后一次只能升1级
  572. local upLv, needJinbi, needSoulCnt = 0,0,0
  573. if nowLv < 10 then
  574. upLv, needJinbi, needSoulCnt = HeroGrid.getLevelUpCnt(human, nowLv, maxLv)
  575. else
  576. upLv, needJinbi, needSoulCnt = HeroGrid.getLevelUpCnt(human, nowLv, nowLv+1)
  577. end
  578. --print(" upLv, needJinbi, needSoulCnt", upLv, needJinbi, needSoulCnt)
  579. if upLv < 1 then return end
  580. -- 判断消耗材料
  581. if human.db.jinbi < needJinbi then
  582. return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
  583. end
  584. if BagLogic.getItemCnt(human, ItemDefine.ITEM_GREEN_EXP_ID) < needSoulCnt then
  585. local strName = ItemDefine.getValue(ItemDefine.ITEM_GREEN_EXP_ID, "name")
  586. return Broadcast.sendErr(human, Util.format(Lang.COMMON_NO_ITEM, strName))
  587. end
  588. -- 扣道具
  589. ObjHuman.updateJinbi(human, -needJinbi, "hero_up")
  590. BagLogic.delItem(human, ItemDefine.ITEM_GREEN_EXP_ID, needSoulCnt, "hero_up")
  591. -- 改db
  592. heroGrid.lv = nowLv + upLv
  593. ObjHuman.doCalcHero(human, heroIndex)
  594. sendHeroBagDynamic(human, heroID, heroIndex)
  595. local msgRet = Msg.gc.GC_HERO_LEVEL_UP
  596. msgRet.id = heroID
  597. msgRet.index = heroIndex
  598. Msg.send(msgRet, human.fd)
  599. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_HEROUP)
  600. refreshDot(human, heroGrid.uuid)
  601. if nowLv < 50 and heroGrid.lv >= 50 then
  602. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_6,1)
  603. elseif nowLv < 100 and heroGrid.lv >= 100 then
  604. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_14,1)
  605. elseif nowLv < 200 and heroGrid.lv >= 200 then
  606. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_20,1)
  607. elseif nowLv < 145 and heroGrid.lv >= 145 then
  608. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_17,1)
  609. elseif nowLv < 185 and heroGrid.lv >= 185 then
  610. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_18,1)
  611. end
  612. XingYaoGongMing.onHeroLvUp(human,heroGrid,heroIndex)
  613. --Log.write(Log.LOGID_OSS_HEROLVUP, human.db._id, human.db.account, human.db.name, heroGrid.uuid, nowLv, heroGrid.lv)
  614. Log.write(Log.LOGID_OSS_HEROLVUP, human.db._id, human.db.newUniqueTag, human.db.name, heroGrid.uuid, nowLv, heroGrid.lv)
  615. checkChangeMaxZDL(human, heroGrid)
  616. GodsAreaNS.UpdateHeroData(human, heroGrid.uuid, 1)
  617. end
  618. -- 英雄升阶查询
  619. function heroUpgradeQuery(human, heroID, heroIndex)
  620. local heroGrid = human.db.heroBag[heroIndex]
  621. if heroGrid == nil or heroGrid.id ~= heroID then
  622. return
  623. end
  624. local cf = HeroExcel.hero[heroID]
  625. if not cf then return end
  626. local star = cf.star
  627. local nextQuality = heroGrid.quality + 1
  628. local maxLv = HeroGrid.getMaxLv(heroGrid.star, nextQuality)
  629. local upcf = UpNeedExcel.upQuality[nextQuality]
  630. if not maxLv or not upcf then
  631. return Broadcast.sendErr(human, Lang.HERO_UPGRADE_ERR_FULL)
  632. end
  633. local nextHeroGrid = HeroGrid.getHeroGridCalcCache(heroGrid)
  634. nextHeroGrid.quality = nextQuality
  635. local nextAttrs = RoleAttr.calcHeroGrid(nextHeroGrid, heroIndex, human)
  636. local zhandouli = RoleAttr.calcZhandouli(nextAttrs)
  637. local msgRet = Msg.gc.GC_HERO_UPGRADE_QUERY
  638. msgRet.id = heroID
  639. msgRet.index = heroIndex
  640. local net = msgRet.data
  641. net.id = heroID
  642. net.maxLv = maxLv
  643. net.zhandouli = zhandouli
  644. net.attr[0] = 4
  645. net.attr[1].key = RoleDefine.ATK
  646. net.attr[1].value = nextAttrs[RoleDefine.ATK]
  647. net.attr[2].key = RoleDefine.HP
  648. net.attr[2].value = nextAttrs[RoleDefine.HP]
  649. net.attr[3].key = RoleDefine.SPEED
  650. net.attr[3].value = nextAttrs[RoleDefine.SPEED]
  651. net.attr[4].key = RoleDefine.DEF
  652. net.attr[4].value = nextAttrs[RoleDefine.DEF]
  653. net.needJinbi = upcf.money
  654. net.needItemCnt = upcf.jinjieshi
  655. --Msg.trace(msgRet)
  656. Msg.send(msgRet, human.fd)
  657. end
  658. -- 英雄升阶
  659. function heroUpgradeDo(human, heroID, heroIndex)
  660. local heroConfig = HeroExcel.hero[heroID]
  661. if not heroConfig then return end
  662. local heroGrid = human.db.heroBag[heroIndex]
  663. if heroGrid == nil or heroGrid.id ~= heroID then
  664. return
  665. end
  666. if XingYaoGongMing.isGongMing(human,heroIndex,XingYaoGongMing.XYHERO_LV) then
  667. return
  668. end
  669. local heroConfig = HeroExcel.hero[heroID]
  670. if not heroConfig then return end
  671. local star = heroGrid.star
  672. local maxQuality = HeroGrid.getMaxQuality(star)
  673. local nextQuality = heroGrid.quality + 1
  674. -- 判断阶数上限
  675. if heroGrid.quality >= maxQuality then
  676. return
  677. end
  678. local upcf = UpNeedExcel.upQuality[nextQuality]
  679. if not upcf then return end
  680. -- 判断消耗材料
  681. local needJinbi = upcf.money
  682. local needItemCnt = upcf.jinjieshi
  683. if human.db.jinbi < needJinbi then
  684. return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
  685. end
  686. local nowItemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID)
  687. if nowItemCnt < needItemCnt then
  688. local strName = ItemDefine.getValue(ItemDefine.ITEM_HERO_UPGRADE_ID, "name")
  689. return Broadcast.sendErr(human, Util.format(Lang.COMMON_NO_ITEM, strName))
  690. end
  691. -- 扣材料
  692. ObjHuman.updateJinbi(human, -needJinbi, "hero_upgrade")
  693. BagLogic.delItem(human, ItemDefine.ITEM_HERO_UPGRADE_ID, needItemCnt, "hero_upgrade")
  694. -- 改db
  695. heroGrid.quality = nextQuality
  696. ObjHuman.doCalcHero(human, heroIndex)
  697. sendHeroBagDynamic(human, heroID, heroIndex)
  698. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_UPGRADE)
  699. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_25,1)
  700. local msgRet = Msg.gc.GC_HERO_UPGRADE_DO
  701. msgRet.id = heroID
  702. msgRet.index = heroIndex
  703. Msg.send(msgRet, human.fd)
  704. refreshDot(human, heroGrid.uuid)
  705. XingYaoGongMing.onHeroUpgrade(human,heroGrid,heroIndex)
  706. checkChangeMaxZDL(human, heroGrid)
  707. end
  708. -- 重算背包熔炼
  709. function calcHeroBagCap(human)
  710. local buyCnt = math.min(human.db.buyCapCnt or 0, HeroDefine.BUY_CAP_CNT)
  711. local heroBagCnt = HeroDefine.HERO_BAG_CNT
  712. heroBagCnt = heroBagCnt + (VipLogic.getPowerArgs(human, VipLogic.VIP_POWER12) or 0)
  713. heroBagCnt = heroBagCnt + HeroDefine.HERO_BAG_BUY_ADD_CNT * buyCnt -- 购买获得背包格子
  714. if human.db.blue ~= nil and human.db.blue.isAdd ~= nil then -- 特权
  715. local cnt = TequanExcel.tequan[2].privilege
  716. heroBagCnt = heroBagCnt + cnt
  717. end
  718. if human.db.yellow ~= nil and human.db.yellow.isAdd ~= nil then -- 特权
  719. local cnt = TequanExcel.tequan[1].privilege
  720. heroBagCnt = heroBagCnt + cnt
  721. end
  722. -- 封印之章特权
  723. local cjPrivilege = ChengjiuLogic.checkPrivilege(human,ChengjiuDefine.PRIVILEGE_TYPE_1)
  724. if cjPrivilege then
  725. heroBagCnt = heroBagCnt + cjPrivilege
  726. end
  727. -- 特殊服务器处理
  728. -- vip需求砍掉之后,导致有的玩家英雄数量超过背包数量
  729. -- 经策划确认,140001-140021 服务器所有玩家增加背包数量300
  730. if Config.SVR_INDEX >= 140001 and Config.SVR_INDEX <= 140021 then
  731. heroBagCnt = heroBagCnt + 300
  732. end
  733. human.db.heroBag[0] = heroBagCnt
  734. end
  735. -- 购买英雄背包容量
  736. function buyHeroCap(human)
  737. -- 上限判断
  738. local nowBuyCnt = human.db.buyCapCnt or 0
  739. if nowBuyCnt >= HeroDefine.BUY_CAP_CNT then
  740. return Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
  741. end
  742. -- 判断消耗
  743. local needZuanshi = (nowBuyCnt + 1) * 100
  744. if not ObjHuman.checkRMB(human, needZuanshi) then
  745. return
  746. end
  747. -- 扣消耗
  748. ObjHuman.decZuanshi(human, -needZuanshi, "buy_hero_cap")
  749. -- 改db
  750. human.db.buyCapCnt = nowBuyCnt + 1
  751. sendHeroBagCap(human)
  752. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  753. end
  754. -- 最大觉醒
  755. function sendHeroJueXingMax(human, heroID, heroIndex)
  756. local heroConfig = HeroExcel.hero[heroID]
  757. if not heroConfig then return end
  758. local msgRet = Msg.gc.GC_HERO_JUEXING_QUERY_MAX
  759. msgRet.id = heroID
  760. msgRet.index = heroIndex
  761. Msg.send(msgRet, human.fd)
  762. end
  763. local JUEXING_SKILL_DIFF_LIST = {}
  764. function getSkillDiffList(cf1, cf2)
  765. local diffCnt = 0
  766. for i = 1, #cf2.skillList do
  767. local skillID1 = cf1.skillList[i]
  768. local skillID2 = cf2.skillList[i]
  769. if skillID1 ~= skillID2 then
  770. diffCnt = diffCnt + 1
  771. local tb = JUEXING_SKILL_DIFF_LIST[diffCnt] or {}
  772. JUEXING_SKILL_DIFF_LIST[diffCnt] = tb
  773. tb[1] = skillID1
  774. tb[2] = skillID2
  775. end
  776. end
  777. for i = 1, #cf2.beSkillList do
  778. local skillID1 = cf1.beSkillList[i]
  779. local skillID2 = cf2.beSkillList[i]
  780. if skillID1 ~= skillID2 then
  781. diffCnt = diffCnt + 1
  782. local tb = JUEXING_SKILL_DIFF_LIST[diffCnt] or {}
  783. JUEXING_SKILL_DIFF_LIST[diffCnt] = tb
  784. tb[1] = skillID1
  785. tb[2] = skillID2
  786. end
  787. end
  788. return diffCnt, JUEXING_SKILL_DIFF_LIST
  789. end
  790. -- 英雄升星 16~20的额外条件表, 升到 key 星, 背包中还额外需要有 value[2] 个星级为 value[1] 的英雄
  791. local upStarExtraCond = {
  792. [16] = {11, 10},
  793. [17] = {11, 15},
  794. [18] = {12, 10},
  795. [19] = {12, 15},
  796. [20] = {13, 10},
  797. }
  798. -- 升级额外条件检测
  799. local function upStarExtraCondCheck(human, nextStar)
  800. local extraCond = upStarExtraCond[nextStar]
  801. if not extraCond then
  802. return true
  803. end
  804. local starCond = extraCond[1]
  805. local numCond = extraCond[2]
  806. local numCorrect = CalcStarHeroCnt(human, starCond)
  807. if numCorrect < numCond then
  808. return Broadcast.sendErr(human, Util.format(Lang.HERO_UPSTAR_EXTRA_COND, starCond, numCond))
  809. end
  810. return true
  811. end
  812. -- 英雄觉醒(升星)预览
  813. local JUEXING_SPEED_UP = {[4]=10}
  814. local JUEXING_ATK_UP = {[5]=40,[6]=40,[7]=40,[8]=40,[9]=40,[10]=20,[11]=20,[12]=20}
  815. local JUEXING_HP_UP = {[5]=50,[6]=50,[7]=50,[8]=50,[9]=50,[10]=30,[11]=30,[12]=30}
  816. function heroJueXingQuery(human, heroID, heroIndex)
  817. local heroConfig = HeroExcel.hero[heroID]
  818. if not heroConfig then return end
  819. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  820. if not heroGrid 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. local attrConfig = HeroDefine.getAttrConfig(heroID, heroGrid.star)
  832. if not attrConfig then return end
  833. local nextAttrConfig = HeroDefine.getNextAttrConfig(heroID, heroGrid.star)
  834. if not nextAttrConfig then
  835. return sendHeroJueXingMax(human, heroID, heroIndex)
  836. end
  837. -- 额外条件判断
  838. -- if not upStarExtraCondCheck(human, nextAttrConfig.star) then
  839. -- return
  840. -- end
  841. local msgRet = Msg.gc.GC_HERO_JUEXING_QUERY
  842. local dataNet = msgRet.data
  843. local maxQuality = HeroGrid.getMaxQuality(attrConfig.star)
  844. local nextMaxQuality = HeroGrid.getMaxQuality(nextAttrConfig.star)
  845. -- 判断是否达到开放等级
  846. local isFix, upStarNeedLv, upStarNeedWorldLv = isFixUpStarLv(human, heroGrid.star+1)
  847. if not isFix then
  848. if upStarNeedLv and upStarNeedWorldLv and upStarNeedWorldLv > 0 then
  849. return Broadcast.sendErr(human, Util.format(Lang.HERO_JUEXING_ERR_HEROLV, upStarNeedLv, upStarNeedWorldLv))
  850. elseif upStarNeedLv then
  851. return Broadcast.sendErr(human, Util.format(Lang.HERO_JUEXING_ERR_HEROLV2, upStarNeedLv))
  852. end
  853. return
  854. end
  855. dataNet.id = heroID
  856. dataNet.index = heroIndex
  857. dataNet.star = heroGrid.star
  858. dataNet.nextStar = nextAttrConfig.star
  859. dataNet.maxLv = HeroGrid.getMaxLv(heroGrid.star, maxQuality)
  860. dataNet.nextMaxLv = HeroGrid.getMaxLv(nextAttrConfig.star, nextMaxQuality)
  861. -- 展示变化的技能
  862. local diffCnt, diffList = getSkillDiffList(attrConfig, nextAttrConfig)
  863. diffCnt = diffCnt > #dataNet.skillUp and #dataNet.skillUp or diffCnt
  864. dataNet.isAllSkillUp = (diffCnt > 1) and 1 or 0
  865. dataNet.skillUp[0] = diffCnt
  866. for i=1, diffCnt do
  867. makeSkillNet(dataNet.skillUp[i], diffList[i][2])
  868. end
  869. dataNet.speedUp = JUEXING_SPEED_UP[heroConfig.star] or 0
  870. dataNet.atkUpRate = JUEXING_ATK_UP[heroConfig.star] or 0
  871. dataNet.hpUpRate = JUEXING_HP_UP[heroConfig.star] or 0
  872. dataNet.needItems[0] = #attrConfig.needItems
  873. for i = 1, dataNet.needItems[0] do
  874. local itemID = attrConfig.needItems[i][1]
  875. local itemCnt = attrConfig.needItems[i][2]
  876. Grid.makeItem(dataNet.needItems[i], itemID, itemCnt)
  877. end
  878. dataNet.needHeros[0] = 0
  879. for i = 1, #attrConfig.cond do
  880. dataNet.needHeros[0] = dataNet.needHeros[0] + 1
  881. local condNet = dataNet.needHeros[dataNet.needHeros[0]]
  882. makeUpStarCond(condNet, attrConfig.cond[i])
  883. end
  884. dataNet.needItemCnt = attrConfig.jinjieshi
  885. --Msg.trace(msgRet)
  886. Msg.send(msgRet, human.fd)
  887. end
  888. function fontJueXingHeroNet(net, heroGrid, index, human)
  889. local attrs = ObjHuman.getHeroAttrs(human, index)
  890. HeroGrid.makeHeroDynamic(net.dynamicData, heroGrid, index, human)
  891. HeroGrid.makeHeroSimple(net.simpleData, heroGrid, index, human)
  892. net.zhandouli = attrs[RoleDefine.ZHANDOULI] or 0
  893. net.atk = attrs[RoleDefine.ATK] or 0
  894. net.hp = attrs[RoleDefine.HP] or 0
  895. net.def = attrs[RoleDefine.DEF] or 0
  896. net.speed = attrs[RoleDefine.SPEED] or 0
  897. end
  898. -- 检查世界等级或者玩家等级是否满足条件
  899. -- 检查达到角色等级或者世界等级
  900. function isFixUpStarLv(human, targetStar)
  901. local config = HeroExcel.star[targetStar]
  902. if not config then
  903. return false
  904. end
  905. if config.upStarNeedLv >= 0 and human.db.lv >= config.upStarNeedLv then
  906. return true, config.upStarNeedLv, config.upStarNeedWorldLv
  907. end
  908. if config.upStarNeedWorldLv >= 0 and GlobalWorld.getWorldLv() >= config.upStarNeedWorldLv then
  909. return true, config.upStarNeedLv, config.upStarNeedWorldLv
  910. end
  911. return false, config.upStarNeedLv, config.upStarNeedWorldLv
  912. end
  913. -- 英雄觉醒(升星)
  914. local yunYingActParam = {}
  915. function heroJueXingDo(human, heroID, heroIndex, inputIDList, inputIndexList)
  916. local heroConfig = HeroExcel.hero[heroID]
  917. if not heroConfig then return end
  918. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  919. if not heroGrid then return end
  920. local attrConfig = HeroDefine.getAttrConfig(heroID, heroGrid.star)
  921. if not attrConfig then return end
  922. local nextAttrConfig = HeroDefine.getNextAttrConfig(heroID, heroGrid.star)
  923. if not nextAttrConfig then return end
  924. -- 判断是否达到开放等级
  925. local isFix, upStarNeedLv, upStarNeedWorldLv = isFixUpStarLv(human, heroGrid.star+1)
  926. if not isFix then
  927. if upStarNeedLv and upStarNeedWorldLv and upStarNeedWorldLv > 0 then
  928. return Broadcast.sendErr(human, Util.format(Lang.HERO_JUEXING_ERR_HEROLV, upStarNeedLv, upStarNeedWorldLv))
  929. elseif upStarNeedLv then
  930. return Broadcast.sendErr(human, Util.format(Lang.HERO_JUEXING_ERR_HEROLV2, upStarNeedLv))
  931. end
  932. return
  933. end
  934. -- 额外条件判断
  935. if not upStarExtraCondCheck(human, nextAttrConfig.star) then
  936. return
  937. end
  938. -- 判断消耗材料
  939. local needItemCnt = attrConfig.jinjieshi
  940. if not BagLogic.checkItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID, needItemCnt) then
  941. return
  942. end
  943. -- 额外材料
  944. for i = 1, #attrConfig.needItems do
  945. local itemID = attrConfig.needItems[i][1]
  946. local itemCnt = attrConfig.needItems[i][2]
  947. if not BagLogic.checkItemCnt(human, itemID, itemCnt) then
  948. return
  949. end
  950. end
  951. -- 英雄材料
  952. if not HechengLogic.checkCond(human, inputIDList, inputIndexList, attrConfig.cond) then
  953. return Broadcast.sendErr(human, Lang.HERO_JUEXING_CAILIAO_ERR)
  954. end
  955. -- 比较特别的情况。。
  956. for i = 1, inputIndexList[0] do
  957. if inputIndexList[i] == heroIndex then
  958. return -- 本体同时作为材料,骗分解材料
  959. end
  960. end
  961. -- 扣消耗
  962. BagLogic.delItem(human, ItemDefine.ITEM_HERO_UPGRADE_ID, needItemCnt, "hero_juexing")
  963. local fenjieList = FenjieLogic.fenjie(human, FenjieLogic.FENJIE_DO_JUEXING, inputIDList, inputIndexList)
  964. -- 额外材料
  965. for i = 1, #attrConfig.needItems do
  966. local itemID = attrConfig.needItems[i][1]
  967. local itemCnt = attrConfig.needItems[i][2]
  968. BagLogic.delItem(human, itemID, itemCnt, "hero_juexing")
  969. end
  970. local msgRet = Msg.gc.GC_HERO_JUEXING_DO
  971. msgRet.id = heroID
  972. msgRet.index = heroIndex
  973. msgRet.upStarNeedLv = upStarNeedLv
  974. msgRet.upStarNeedWorldLv = upStarNeedWorldLv
  975. fontJueXingHeroNet(msgRet.oldData, heroGrid, heroIndex, human)
  976. -- 继承英雄等级 阶数 装备 水晶
  977. writeLogHeroDel(human, "hero_juexing", heroGrid)
  978. heroGrid.star = nextAttrConfig.star
  979. onGetNewHero(human, heroGrid, "hero_juexing", heroIndex)
  980. ObjHuman.doCalcHero(human, heroIndex)
  981. sendHeroBagDynamic(human, heroGrid.id, heroIndex)
  982. writeLogHeroAdd(human, "hero_juexing", heroGrid)
  983. fontJueXingHeroNet(msgRet.newData, heroGrid, heroIndex, human)
  984. local diffCnt, diffList = getSkillDiffList(attrConfig, nextAttrConfig)
  985. diffCnt = diffCnt > #msgRet.skillUp and #msgRet.skillUp or diffCnt
  986. msgRet.isAllSkillUp = (diffCnt > 1) and 1 or 0
  987. msgRet.skillUp[0] = diffCnt
  988. for i=1, diffCnt do
  989. makeSkillNet(msgRet.skillUp[i], diffList[i][2])
  990. end
  991. BagLogic.BagLogic_GetAllSendInfo(human, msgRet.itemList, fenjieList, CommonDefine.COMMON_SEND_PRIZE_TYPE_KEYVAL)
  992. -- if fenjieList then
  993. -- for itemID, itemCnt in pairs(fenjieList) do
  994. -- if msgRet.itemList[0] >= #msgRet.itemList then
  995. -- break
  996. -- end
  997. -- msgRet.itemList[0] = msgRet.itemList[0] + 1
  998. -- Grid.makeItem(msgRet.itemList[msgRet.itemList[0]], itemID, itemCnt)
  999. -- end
  1000. -- end
  1001. --Msg.trace(msgRet)
  1002. Msg.send(msgRet, human.fd)
  1003. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE12, nextAttrConfig.star,heroGrid.id)
  1004. local newstar = nextAttrConfig.star or 0
  1005. local newcamp = heroConfig.camp or 0
  1006. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID24,1,newcamp,newstar)
  1007. if newstar == 5 then
  1008. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_11,1)
  1009. end
  1010. if newstar >= 5 then
  1011. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_13,1)
  1012. end
  1013. if newstar == 6 then
  1014. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_16,1)
  1015. JibanLogic.onCallback(human,2,newstar)
  1016. end
  1017. if newstar == 10 then
  1018. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_23,1)
  1019. end
  1020. checkChangeMaxZDL(human, heroGrid)
  1021. HeroLogLogic.finishTaskCB(human, HeroLogLogic.HERO_LOG_TYPE_8, 1, heroID, newstar)
  1022. -- 弹窗礼包相关触发
  1023. if human.db.heroLevelUpgrade < heroGrid.star then
  1024. human.db.heroLevelUpgrade = heroGrid.star
  1025. GiftLogic.trigger(human,Upgrade_HERO_EVENT,{star = heroGrid.star})
  1026. end
  1027. for i in ipairs(yunYingActParam) do
  1028. yunYingActParam[i] = nil
  1029. end
  1030. yunYingActParam[1] = heroID
  1031. yunYingActParam[2] = newstar
  1032. yunYingActParam[3] = 1
  1033. YunYingLogic.onCallBack(human, "onHeroStarChange", yunYingActParam)
  1034. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_GETHERO, human.db._id, 1, newstar)
  1035. TriggerLogic.PublishEvent(TriggerDefine.HERO_YINGHUN_JINHUA, human.db._id, 1)
  1036. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_GETPOINTHERO, human.db._id, 1, newstar, heroID)
  1037. if heroConfig.grade >= HeroDefine.HERO_SSR_GRADE then
  1038. HeroPubLogic.UpdateHero(human, HeroPubLogic.HERO_OP_UPSTAR, heroID, heroGrid.uuid)
  1039. end
  1040. GodsAreaNS.UpdateHeroData(human, heroGrid.uuid, 1)
  1041. end
  1042. --返还宝石
  1043. function returnGem(gemData)
  1044. if not gemData then
  1045. return
  1046. end
  1047. local calCnt = function(level)
  1048. local cnt = 0
  1049. for i=level, 1, -1 do
  1050. cnt = cnt + math.ceil(i/3)
  1051. end
  1052. return cnt
  1053. end
  1054. local num = 0
  1055. for _, v in pairs(gemData) do
  1056. num = num + calCnt(v.lv)
  1057. end
  1058. return num
  1059. end
  1060. -- 英雄重生预览
  1061. function heroChongShengQuery(human, heroID, heroIndex)
  1062. local heroConfig = HeroExcel.hero[heroID]
  1063. if not heroConfig then return end
  1064. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1065. if not heroGrid then return end
  1066. if heroGrid.isLock then
  1067. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_LOCK)
  1068. end
  1069. local chongShengConfig = UpNeedExcel.chongSheng[heroGrid.star]
  1070. if not chongShengConfig then -- 只能重生7-9星
  1071. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  1072. end
  1073. -- 没有对应5星的存在
  1074. local attrConfig = HeroDefine.getAttrConfig(heroID, CHONGSHENG_RETURN_STAR)
  1075. if not attrConfig then
  1076. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  1077. end
  1078. local suipianID = SuipianLogic.getSuipianIDbyHeroID(heroID)
  1079. if not suipianID then -- 没有对应的本体碎片
  1080. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_SUIPIANID)
  1081. end
  1082. local otherSuipianID = chongShengConfig.suipianIDs[heroConfig.camp]
  1083. if not otherSuipianID then -- 阵容不对
  1084. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  1085. end
  1086. local msgRet = Msg.gc.GC_HERO_CHONGSHENG_QUERY
  1087. msgRet.id = heroID
  1088. msgRet.index = heroIndex
  1089. msgRet.needItemCnt = chongShengConfig.needItemCnt
  1090. Grid.makeItem(msgRet.bentiSuipian, suipianID, chongShengConfig.bentiCnt)
  1091. Grid.makeItem(msgRet.otherSuipian, otherSuipianID, chongShengConfig.suipianCnt)
  1092. --Msg.trace(msgRet)
  1093. --宝石返回
  1094. local gemCnt = returnGem(heroGrid.gem)
  1095. -- if gemCnt and gemCnt > 0 then
  1096. -- Grid.makeItem(msgRet.gemVec, gemId, gemCnt)
  1097. -- end
  1098. local gemId = HeroDefine.HEROJOBTOGEM[heroConfig.job] or 0
  1099. gemCnt = gemCnt or 0
  1100. Grid.makeItem(msgRet.gemVec, gemId, gemCnt)
  1101. Msg.send(msgRet, human.fd)
  1102. end
  1103. function getHeroMaxStarCtn(human)
  1104. local heroBag = human.db.heroBag
  1105. local maxStar = 0
  1106. local starHeroCnt = 0
  1107. for _,grid in ipairs(heroBag) do
  1108. if grid.star > maxStar then
  1109. maxStar = grid.star
  1110. starHeroCnt = 1
  1111. elseif grid.star == maxStar then
  1112. starHeroCnt = starHeroCnt + 1
  1113. end
  1114. end
  1115. return maxStar,starHeroCnt
  1116. end
  1117. -- 英雄重生
  1118. function heroChongShengDo(human, heroID, heroIndex)
  1119. local heroConfig = HeroExcel.hero[heroID]
  1120. if not heroConfig then return end
  1121. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1122. if not heroGrid then return end
  1123. if heroGrid.isLock then
  1124. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_LOCK)
  1125. end
  1126. local chongShengConfig = UpNeedExcel.chongSheng[heroGrid.star]
  1127. if not chongShengConfig then -- 只能重生7-9星
  1128. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  1129. end
  1130. local attrConfig = HeroDefine.getAttrConfig(heroID, CHONGSHENG_RETURN_STAR)
  1131. if not attrConfig then
  1132. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  1133. end
  1134. local suipianID = SuipianLogic.getSuipianIDbyHeroID(heroID)
  1135. if not suipianID then -- 没有对应的本体碎片
  1136. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_SUIPIANID)
  1137. end
  1138. local otherSuipianID = chongShengConfig.suipianIDs[heroConfig.camp]
  1139. if not otherSuipianID then -- 阵营不对
  1140. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  1141. end
  1142. local nowItemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_CHONGSHENG_ID)
  1143. local needItemCnt = chongShengConfig.needItemCnt
  1144. if nowItemCnt < needItemCnt then
  1145. local strName = ItemDefine.getValue(ItemDefine.ITEM_HERO_CHONGSHENG_ID, "name")
  1146. local strRet = Util.format(Lang.COMMON_NO_ITEM, strName)
  1147. return Broadcast.sendErr(human, strRet)
  1148. end
  1149. -- 删除材料
  1150. BagLogic.delItem(human, ItemDefine.ITEM_HERO_CHONGSHENG_ID, needItemCnt, "hero_chongsheng")
  1151. -- 重置到初始返还的材料
  1152. local upList = getResetReturnItems(heroGrid)
  1153. -- 先删除英雄
  1154. delHeroByIndex(human, heroIndex, "hero_chongsheng")
  1155. -- 返还装备
  1156. for i = 1, ItemDefine.EQUIP_MAX_CNT do
  1157. if i ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN and
  1158. heroGrid.equip and heroGrid.equip[i] then
  1159. local equipGrid = heroGrid.equip[i]
  1160. if equipGrid then
  1161. equipGrid.putUuid = nil
  1162. EquipLogic.addByEquipGrid(human, equipGrid, "hero_chongsheng")
  1163. end
  1164. end
  1165. end
  1166. -- 返还符文
  1167. for i = 1, 2 do
  1168. local fuwenGrid = heroGrid.fuwen and heroGrid.fuwen[i]
  1169. if fuwenGrid and fuwenGrid.id then
  1170. FuwenLogic.addByGrid(human, fuwenGrid, "hero_chongsheng")
  1171. end
  1172. end
  1173. --宝石返还
  1174. local gemCnt = returnGem(heroGrid.gem)
  1175. if gemCnt and gemCnt > 0 then
  1176. local gemId = HeroDefine.HEROJOBTOGEM[heroConfig.job] or 0
  1177. BagLogic.addItem(human, gemId, gemCnt, "hero_chongsheng")
  1178. end
  1179. -- 再给东西
  1180. BagLogic.addItem(human, suipianID, chongShengConfig.bentiCnt, "hero_chongsheng")
  1181. BagLogic.addItem(human, otherSuipianID, chongShengConfig.suipianCnt, "hero_chongsheng")
  1182. for itemID, itemCnt in pairs(upList) do
  1183. BagLogic.addItem(human, itemID, itemCnt, "hero_chongsheng")
  1184. end
  1185. -- 通知客户端
  1186. local msgRet = Msg.gc.GC_HERO_CHONGSHENG_DO
  1187. msgRet.list[0] = 2
  1188. Grid.makeItem(msgRet.list[1], suipianID, chongShengConfig.bentiCnt)
  1189. Grid.makeItem(msgRet.list[2], otherSuipianID, chongShengConfig.suipianCnt)
  1190. --宝石
  1191. if gemCnt and gemCnt > 0 then
  1192. local gemId = HeroDefine.HEROJOBTOGEM[heroConfig.job] or 0
  1193. msgRet.list[0] = msgRet.list[0] + 1
  1194. Grid.makeItem(msgRet.list[3], gemId, gemCnt)
  1195. end
  1196. for itemID, itemCnt in pairs(upList) do
  1197. msgRet.list[0] = msgRet.list[0] + 1
  1198. Grid.makeItem(msgRet.list[msgRet.list[0]], itemID, itemCnt)
  1199. end
  1200. msgRet.list[0] = EquipLogic.makeEquipItem(human, msgRet.list, msgRet.list[0])
  1201. Msg.send(msgRet, human.fd)
  1202. checkChangeMaxZDL(human, heroGrid)
  1203. end
  1204. -- 回退
  1205. local HUITUI_HERO_LIST = {}
  1206. local HUITUI_ITEM_LIST = {}
  1207. function getHuituiReturns(heroGrid)
  1208. local heroConfig = HeroExcel.hero[heroGrid.id]
  1209. if not heroConfig then return end
  1210. local config = UpNeedExcel.huiTui[heroGrid.star]
  1211. if not config then return end
  1212. local targetID = heroGrid.id
  1213. if not targetID then return end
  1214. -- 13星无法升级,但可以回退
  1215. if heroGrid.star < 13 then
  1216. local upStarConfig = HeroDefine.getNextAttrConfig(heroGrid.id, heroGrid.star)
  1217. -- 不能升星的话也不能回退
  1218. if not upStarConfig then
  1219. return
  1220. end
  1221. end
  1222. Util.cleanTable(HUITUI_HERO_LIST)
  1223. Util.cleanTable(HUITUI_ITEM_LIST)
  1224. local maxLv = HeroGrid.getMaxLv(config.targetStar, heroGrid.quality)
  1225. local lv = heroGrid.lv
  1226. if heroGrid.oldLV then
  1227. lv = heroGrid.oldLV
  1228. end
  1229. local targetLv = math.min(lv, maxLv)
  1230. -- 升级 不将阶
  1231. for i = targetLv + 1, lv do
  1232. local upcf = UpNeedExcel.upLv[i]
  1233. if upcf then
  1234. HUITUI_ITEM_LIST[ItemDefine.ITEM_GREEN_EXP_ID] = (HUITUI_ITEM_LIST[ItemDefine.ITEM_GREEN_EXP_ID] or 0) + upcf.soul
  1235. HUITUI_ITEM_LIST[ItemDefine.ITEM_JINBI_ID] = (HUITUI_ITEM_LIST[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  1236. end
  1237. end
  1238. -- 圣星文书
  1239. HUITUI_ITEM_LIST[ItemDefine.ITEM_HERO_UPGRADE_BOOK] = (HUITUI_ITEM_LIST[ItemDefine.ITEM_HERO_UPGRADE_BOOK] or 0) + config.upBook
  1240. -- 进阶石
  1241. HUITUI_ITEM_LIST[ItemDefine.ITEM_HERO_UPGRADE_ID] = (HUITUI_ITEM_LIST[ItemDefine.ITEM_HERO_UPGRADE_ID] or 0) + config.jinjieshi
  1242. -- 5星本体碎片数量
  1243. local fiveBentiID = heroGrid.id
  1244. local fiveBentiSuipianID = SuipianLogic.getSuipianIDbyHeroID(fiveBentiID)
  1245. HUITUI_ITEM_LIST[fiveBentiSuipianID] = (HUITUI_ITEM_LIST[fiveBentiSuipianID] or 0) + config.fiveBentiCnt
  1246. -- 5星同系碎片数量
  1247. local materialConfig = UpNeedExcel.huiTuiMaterial[heroConfig.camp]
  1248. HUITUI_ITEM_LIST[materialConfig.fiveHeroSuipian] = (HUITUI_ITEM_LIST[materialConfig.fiveHeroSuipian] or 0) + config.fiveSuipianCnt
  1249. -- 9星傀儡数量
  1250. local nineHeroCnt = (HUITUI_HERO_LIST[9] and HUITUI_HERO_LIST[9][2] or 0) + config.nineHeroCnt
  1251. HUITUI_HERO_LIST[9] = {materialConfig.nineHero, nineHeroCnt}
  1252. -- 10星傀儡数量
  1253. local tenHeroCnt = (HUITUI_HERO_LIST[10] and HUITUI_HERO_LIST[10][2] or 0) + config.tenHeroCnt
  1254. HUITUI_HERO_LIST[10] = {materialConfig.tenHero, tenHeroCnt}
  1255. return config.targetStar, targetLv, config, HUITUI_ITEM_LIST, HUITUI_HERO_LIST
  1256. end
  1257. -- 回退查询
  1258. function sendHuituiQuery(human, heroID, heroIndex)
  1259. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1260. if not heroGrid then return end
  1261. local star, targetLv, config, items, heros = getHuituiReturns(heroGrid)
  1262. if not star then
  1263. return Broadcast.sendErr(human, Lang.HERO_HUITUI_ERR_STAR)
  1264. end
  1265. local msgRet = Msg.gc.GC_HERO_HUITUI_QUERY
  1266. msgRet.heroID = heroID
  1267. msgRet.heroIndex = heroIndex
  1268. HeroGrid.makeHeroSimple(msgRet.oldSimple, heroGrid, heroIndex, human)
  1269. local others = HeroGrid.createOthers(targetLv, nil,nil, star)
  1270. HeroGrid.makeHeroSimpleByID(msgRet.newSimple, heroID, heroIndex, others, nil, true)
  1271. HeroGrid.makeHeroSimpleByGeneral(msgRet.newSimple, heroID)
  1272. Grid.makeItem(msgRet.needItem, ItemDefine.ITEM_HERO_HUITUI_ID, config.needItemCnt)
  1273. msgRet.returnItems[0] = 0
  1274. for itemID, itemCnt in pairs(items) do
  1275. if msgRet.returnItems[0] >= #msgRet.returnItems then
  1276. break
  1277. end
  1278. if itemCnt > 0 then
  1279. msgRet.returnItems[0] = msgRet.returnItems[0] + 1
  1280. Grid.makeItem(msgRet.returnItems[msgRet.returnItems[0]], itemID, itemCnt)
  1281. end
  1282. end
  1283. --专属武器材料
  1284. local weaponReturnItem = HeroExclusiveWeapon.CalcLevelCostItem(human, heroID, heroIndex)
  1285. if weaponReturnItem then
  1286. for itemID, itemCnt in pairs(weaponReturnItem) do
  1287. if msgRet.returnItems[0] >= #msgRet.returnItems then
  1288. break
  1289. end
  1290. if itemCnt > 0 then
  1291. msgRet.returnItems[0] = msgRet.returnItems[0] + 1
  1292. Grid.makeItem(msgRet.returnItems[msgRet.returnItems[0]], itemID, itemCnt)
  1293. end
  1294. end
  1295. end
  1296. -- 英雄种子返还材料
  1297. local seedReturnItem = HeroSeed.CalcReturnItem(human, heroGrid)
  1298. if seedReturnItem then
  1299. for _, itemInfo in ipairs(seedReturnItem) do
  1300. if msgRet.returnItems[0] >= #msgRet.returnItems then
  1301. break
  1302. end
  1303. msgRet.returnItems[0] = msgRet.returnItems[0] + 1
  1304. Grid.makeItem(msgRet.returnItems[msgRet.returnItems[0]], itemInfo[1], itemInfo[2])
  1305. end
  1306. end
  1307. msgRet.returnHeros[0] = 0
  1308. for star, v in pairs(heros) do
  1309. local rHeroID = v[1]
  1310. local rHeroCnt = v[2]
  1311. for i = 1, rHeroCnt do
  1312. if msgRet.returnHeros[0] >= #msgRet.returnHeros then
  1313. break
  1314. end
  1315. local others = HeroGrid.createOthers(1, nil,nil, star)
  1316. msgRet.returnHeros[0] = msgRet.returnHeros[0] + 1
  1317. local heroNet = msgRet.returnHeros[msgRet.returnHeros[0]]
  1318. HeroGrid.makeHeroSimpleByID(heroNet, rHeroID, nil, others, human)
  1319. HeroGrid.makeHeroSimpleByGeneral(heroNet, rHeroID)
  1320. heroNet.star = star
  1321. end
  1322. end
  1323. --Msg.trace(msgRet)
  1324. Msg.send(msgRet, human.fd)
  1325. end
  1326. -- 回退操作
  1327. function huituiHero(human, heroID, heroIndex)
  1328. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1329. if not heroGrid then return end
  1330. local star, targetLv, config, items, heros = getHuituiReturns(heroGrid)
  1331. if not star then
  1332. return Broadcast.sendErr(human, Lang.HERO_HUITUI_ERR_STAR)
  1333. end
  1334. if heroGrid.isLock then
  1335. return Broadcast.sendErr(human, Lang.HERO_HUITUI_ERR_LOCK)
  1336. end
  1337. local needHeroBagCnt = 0
  1338. for star, v in pairs(heros) do
  1339. local rHeroCnt = v[2]
  1340. needHeroBagCnt = needHeroBagCnt + rHeroCnt
  1341. end
  1342. -- 检查英雄背包空间
  1343. if getEmptyCnt(human) < needHeroBagCnt then
  1344. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  1345. end
  1346. if not BagLogic.checkItemCnt(human, ItemDefine.ITEM_HERO_HUITUI_ID, config.needItemCnt) then
  1347. return
  1348. end
  1349. if heroGrid.relic then
  1350. WinnerRelicLogic.WinnerRelic_CancelWinner(human, heroGrid, heroIndex)
  1351. heroGrid.relic = {}
  1352. end
  1353. BagLogic.delItem(human, ItemDefine.ITEM_HERO_HUITUI_ID, config.needItemCnt, "hero_huitui")
  1354. --专属武器材料
  1355. local weaponReturnItem = HeroExclusiveWeapon.CalcLevelCostItem(human, heroID, heroIndex)
  1356. if weaponReturnItem then
  1357. for itemID, itemCnt in pairs(weaponReturnItem) do
  1358. items[itemID] = items[itemID] or 0
  1359. items[itemID] = items[itemID] + itemCnt
  1360. end
  1361. --重置专属武器等级
  1362. HeroExclusiveWeapon.SetHeroWeaponLv(human, heroID, heroIndex, 0)
  1363. end
  1364. -- 英雄种子返还材料
  1365. local seedReturnItem = HeroSeed.CalcReturnItem(human, heroGrid)
  1366. if seedReturnItem then
  1367. for _, itemInfo in ipairs(seedReturnItem) do
  1368. local itemId = itemInfo[1]
  1369. local itemCnt = itemInfo[2]
  1370. items[itemId] = (items[itemId] or 0) + itemCnt
  1371. end
  1372. -- 重置英雄所有种子等级
  1373. HeroSeed.ResetSeedLv(human, heroGrid)
  1374. end
  1375. heroGrid.star = star
  1376. heroGrid.lv = targetLv
  1377. XingYaoGongMing.onDelHero(human,heroGrid,heroIndex)
  1378. ObjHuman.doCalcHero(human, heroIndex)
  1379. sendHeroBagDynamic(human, heroID, heroIndex)
  1380. writeLogHeroAdd(human, "hero_huitui", heroGrid)
  1381. for itemID, itemCnt in pairs(items) do
  1382. if itemCnt > 0 then
  1383. BagLogic.addItem(human, itemID, itemCnt, "hero_huitui")
  1384. end
  1385. end
  1386. for star,v in pairs(heros) do
  1387. local rHeroID = v[1]
  1388. local rHeroCnt = v[2]
  1389. if rHeroCnt > 0 then
  1390. addHero(human, rHeroID,star, rHeroCnt, "hero_huitui")
  1391. end
  1392. end
  1393. local msgRet = Msg.gc.GC_HERO_HUITUI
  1394. msgRet.heroID = heroID
  1395. msgRet.heroIndex = heroIndex
  1396. HeroGrid.makeHeroSimple(msgRet.newSimple, heroGrid, heroIndex, human)
  1397. msgRet.returnItems[0] = 0
  1398. for itemID, itemCnt in pairs(items) do
  1399. if msgRet.returnItems[0] >= #msgRet.returnItems then
  1400. break
  1401. end
  1402. if itemCnt > 0 then
  1403. msgRet.returnItems[0] = msgRet.returnItems[0] + 1
  1404. Grid.makeItem(msgRet.returnItems[msgRet.returnItems[0]], itemID, itemCnt)
  1405. end
  1406. end
  1407. msgRet.returnHeros[0] = 0
  1408. for star,v in pairs(heros) do
  1409. local rHeroID = v[1]
  1410. local rHeroCnt = v[2]
  1411. for i = 1, rHeroCnt do
  1412. if msgRet.returnHeros[0] >= #msgRet.returnHeros then
  1413. break
  1414. end
  1415. msgRet.returnHeros[0] = msgRet.returnHeros[0] + 1
  1416. local heroNet = msgRet.returnHeros[msgRet.returnHeros[0]]
  1417. HeroGrid.makeHeroSimpleByID(heroNet, rHeroID, nil, nil, human)
  1418. heroNet.star = star
  1419. end
  1420. end
  1421. --Msg.trace(msgRet)
  1422. Msg.send(msgRet, human.fd)
  1423. checkChangeMaxZDL(human, heroGrid)
  1424. -- 更新酒馆数据
  1425. local heroConfig = HeroExcel.hero[heroID]
  1426. if heroConfig.grade >= HeroDefine.HERO_SSR_GRADE then
  1427. HeroPubLogic.UpdateHero(human, HeroPubLogic.HERO_OP_RETURN, heroGrid.id, heroGrid.uuid)
  1428. end
  1429. GodsAreaNS.UpdateHeroData(human, heroGrid.uuid, 1)
  1430. end
  1431. function getHeroListById(human,heroId)
  1432. local heroDBBag = human.db.heroBag
  1433. local list = {}
  1434. for idx,grid in pairs(heroDBBag) do
  1435. if type(grid) == "table" and grid.id == heroId then
  1436. list[#list+1] = idx
  1437. end
  1438. end
  1439. return list
  1440. end
  1441. function getHeroGrid(human, heroID, heroIndex)
  1442. if not heroID then return end
  1443. if not heroIndex then return end
  1444. local heroGrid = human.db.heroBag[heroIndex]
  1445. if type(heroGrid) ~= "table" or heroGrid.id ~= heroID then
  1446. return
  1447. end
  1448. return heroGrid
  1449. end
  1450. -- 根据uuid 获取heroGrid
  1451. function getHeroGridByUuid(human, uuid)
  1452. if not uuid or uuid == "" or uuid == "0" then return end
  1453. for index = 1, human.db.heroBag[0] do
  1454. local heroGrid = human.db.heroBag[index]
  1455. if heroGrid and type(heroGrid) == "table" then
  1456. if heroGrid.uuid == uuid then
  1457. return heroGrid, index
  1458. end
  1459. end
  1460. end
  1461. return nil
  1462. end
  1463. -- 获取下标英雄id
  1464. function getHeroIdByIndex(human, heroIndex)
  1465. if heroIndex <= 0 then
  1466. return
  1467. end
  1468. local heroGrid = human.db.heroBag[heroIndex]
  1469. if heroGrid == nil then
  1470. return
  1471. end
  1472. return heroGrid.id
  1473. end
  1474. function makeHeroShare(msg, heroGrid, bagIndex, human)
  1475. if type(heroGrid) ~= "table" then return end
  1476. local heroConfig = HeroExcel.hero[heroGrid.id]
  1477. if not heroConfig then return end
  1478. msg.uuid = human.db._id
  1479. msg.heroIndex = bagIndex
  1480. HeroGrid.makeHeroSimple(msg.heroSimple, heroGrid, bagIndex, human)
  1481. HeroGrid.makeHeroStatic(msg.heroStatic, heroGrid.id)
  1482. HeroGrid.makeHeroDynamic(msg.heroDynamic, heroGrid, bagIndex, human)
  1483. -- 装备信息
  1484. msg.equips[0] = 0
  1485. for i = 1, ItemDefine.EQUIP_MAX_CNT do
  1486. local equipGrid = heroGrid.equip and heroGrid.equip[i]
  1487. if equipGrid then
  1488. msg.equips[0] = msg.equips[0] + 1
  1489. local equipNet = msg.equips[msg.equips[0]]
  1490. Grid.makeItem(equipNet, equipGrid.id, 1, heroGrid.shuijingAttrID, equipGrid)
  1491. end
  1492. end
  1493. -- 符文
  1494. msg.fuWens[0] = 0
  1495. for i = 1, 2 do
  1496. local fuwenData = heroGrid.fuwen and heroGrid.fuwen[i]
  1497. if fuwenData and fuwenData.id then
  1498. msg.fuWens[0] = msg.fuWens[0] + 1
  1499. local fuwenNet = msg.fuWens[msg.fuWens[0]]
  1500. fuwenNet.pos = i
  1501. Grid.makeItem(fuwenNet.fuwen, fuwenData.id, 1, nil, fuwenData, i,0)
  1502. end
  1503. end
  1504. return true
  1505. end
  1506. function makeHeroShareMonster(msg, monsterID, mosnterLv)
  1507. local others = HeroGrid.createOthers(mosnterLv)
  1508. msg.uuid = ""
  1509. msg.heroIndex = 0
  1510. HeroGrid.makeHeroSimpleByMonsterID(msg.heroSimple, monsterID, others)
  1511. HeroGrid.makeHeroStatic(msg.heroStatic, monsterID)
  1512. HeroGrid.makeHeroDynamicByID(msg.heroDynamic, monsterID)
  1513. msg.equips[0] = 0
  1514. msg.fuWens[0] = 0
  1515. end
  1516. function getHeroShareGrid(uuid, heroIndex)
  1517. local fakeHuman = ObjHuman.onlineUuid[uuid]
  1518. if not fakeHuman then
  1519. local db = RoleDBLogic.getDb(uuid, RoleLogic.getCombatField())
  1520. if not db then
  1521. return
  1522. end
  1523. fakeHuman = {db = db}
  1524. end
  1525. local bagIndex = heroIndex
  1526. local heroGrid = bagIndex and fakeHuman.db.heroBag[bagIndex]
  1527. return heroGrid, bagIndex, fakeHuman
  1528. end
  1529. function shareData(human, uuid, heroIndex, nChatType, nServerIndex)
  1530. print("[shareData] 获取跨服数据开始 uuid = "..uuid.." heroIndex = "..heroIndex.." nChatType = "..nChatType.." nServerIndex = "..nServerIndex)
  1531. if -1 >= nChatType or -1 >= nServerIndex then
  1532. local msgRet = Msg.gc.GC_HERO_SHARE_DATA
  1533. local heroGrid, bagIndex, fakeHuman = getHeroShareGrid(uuid, heroIndex)
  1534. if heroGrid then
  1535. if not makeHeroShare(msgRet.data, heroGrid, bagIndex, fakeHuman) then
  1536. return
  1537. end
  1538. else
  1539. local monsterID, mosnterLv = JjcLogic.getHeroShareMonster(uuid, heroIndex)
  1540. if not monsterID then return end
  1541. makeHeroShareMonster(msgRet.data, monsterID, mosnterLv)
  1542. end
  1543. Msg.send(msgRet, human.fd)
  1544. else
  1545. print("[shareData] 获取跨服数据开始 uuid = "..uuid.." heroIndex = "..heroIndex.." nChatType = "..nChatType.." nServerIndex = "..nServerIndex)
  1546. HeroMiddleLogic.HeroMiddleLogic_QueryHeroData_LW(human, uuid, heroIndex, nChatType, nServerIndex)
  1547. end
  1548. end
  1549. -- 获取英雄背包中 最大等级的英雄
  1550. function getHeroBagMaxLev(human)
  1551. local maxLv = 1
  1552. for index,heroGrid in pairs(human.db.heroBag) do
  1553. if index ~= 0 and heroGrid.lv > maxLv then
  1554. maxLv = heroGrid.lv
  1555. end
  1556. end
  1557. return maxLv
  1558. end
  1559. -- 获取英雄背包中 最大星级的英雄
  1560. function getHeroBagMaxFuNeng(human)
  1561. local maxStar = 0
  1562. for index,heroGrid in pairs(human.db.heroBag) do
  1563. if index ~= 0 and heroGrid.id then
  1564. local heroConfig = HeroExcel.hero[heroGrid.id]
  1565. if heroConfig and heroConfig.star > 10 then
  1566. local star = heroConfig.star - 10
  1567. if star > maxStar then
  1568. maxStar = star
  1569. end
  1570. if maxStar >= HERO_MAX_STAR - 10 then
  1571. return maxStar
  1572. end
  1573. end
  1574. end
  1575. end
  1576. return maxStar
  1577. end
  1578. -- 战力最高的6个英雄战力和
  1579. local function sortCombat(a, b)
  1580. return a.zhandouli > b.zhandouli
  1581. end
  1582. local HeroSortTable = {}
  1583. function getHerosZDL(human)
  1584. Util.cleanTable(HeroSortTable)
  1585. local len = 0
  1586. for index,heroGrid in pairs(human.db.heroBag) do
  1587. if index ~= 0 then
  1588. len = len + 1
  1589. HeroSortTable[len] = heroGrid
  1590. end
  1591. end
  1592. if len > 1 then
  1593. table.sort(HeroSortTable, sortCombat)
  1594. end
  1595. local zhandouli = 0
  1596. for i = 1, 6 do
  1597. local grid = HeroSortTable[i]
  1598. zhandouli = zhandouli + (grid and grid.zhandouli or 0)
  1599. end
  1600. return zhandouli
  1601. end
  1602. --
  1603. function getHeroMaxZDL(human, camp)
  1604. local zhandouli = 0
  1605. local maxGrid = nil
  1606. for index,heroGrid in pairs(human.db.heroBag) do
  1607. if index ~= 0 then
  1608. local heroConfig = heroGrid and HeroExcel.hero[heroGrid.id]
  1609. if heroConfig and ((camp or 0) == 0 or heroConfig.camp == camp)
  1610. and heroGrid.zhandouli > zhandouli then
  1611. zhandouli = heroGrid.zhandouli
  1612. maxGrid = heroGrid
  1613. end
  1614. end
  1615. end
  1616. return zhandouli, maxGrid
  1617. end
  1618. -- 武将系统红点
  1619. function isDot(human)
  1620. if human.db.lv < 9 then
  1621. return false
  1622. end
  1623. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  1624. if not combatHero then return end
  1625. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  1626. local uuid = combatHero[i]
  1627. local heroGrid = getHeroGridByUuid(human, uuid)
  1628. if heroGrid then
  1629. if isHeroDot(human, heroGrid) then
  1630. return true
  1631. end
  1632. -- if HeroBook.isDot(human) == 1 then
  1633. -- return true
  1634. -- end
  1635. end
  1636. end
  1637. end
  1638. -- 某个伙伴是否有红点
  1639. function isHeroDot(human, heroGrid)
  1640. if not heroGrid then return end
  1641. if human.db.lv < 9 then
  1642. return false
  1643. end
  1644. -- 装备
  1645. if HeroEquip.isEquipDot(human, heroGrid) then
  1646. return true
  1647. end
  1648. if FuwenLogic.isFuwenDot(human, heroGrid) then
  1649. return true
  1650. end
  1651. -- 升级/进阶
  1652. if isHeroLevelDot(human, heroGrid) and
  1653. not XingYaoGongMing.isGongMing(human,heroIndex) then
  1654. return true
  1655. end
  1656. --
  1657. if isHeroJuexingDot(human, heroGrid.bagIndex, heroGrid) then
  1658. return true
  1659. end
  1660. if BingshuLogic.isBingShuDot(human, heroGrid) then
  1661. return true
  1662. end
  1663. -- 专属武器
  1664. if HeroExclusiveWeapon.isWeaponDot(human, heroGrid) then
  1665. return true
  1666. end
  1667. -- 英雄种子
  1668. if HeroSeed.isSeedDot(human, heroGrid) then
  1669. return true
  1670. end
  1671. end
  1672. -- 升级判定
  1673. function isHeroLvDot(human, heroGrid)
  1674. if human.db.lv < 9 then
  1675. return false
  1676. end
  1677. local heroConfig = HeroExcel.hero[heroGrid.id]
  1678. if not heroConfig then return end
  1679. local lv = heroGrid and heroGrid.lv or 1
  1680. local star = heroConfig and heroConfig.star or 0
  1681. local quality = heroGrid and heroGrid.quality or 0
  1682. local maxLv = HeroGrid.getMaxLv(heroGrid.star, quality)
  1683. if lv < maxLv then -- 升级
  1684. local conf = UpNeedExcel.upLv[lv + 1]
  1685. if not conf then return end
  1686. if human.db.jinbi < conf.money then return end
  1687. if BagLogic.getItemCnt(human, ItemDefine.ITEM_GREEN_EXP_ID) < conf.soul then
  1688. return
  1689. end
  1690. return true
  1691. end
  1692. end
  1693. -- 进阶判断
  1694. function isHeroUpDot(human, heroGrid)
  1695. if human.db.lv < 9 then
  1696. return false
  1697. end
  1698. local heroConfig = HeroExcel.hero[heroGrid.id]
  1699. if not heroConfig then return end
  1700. local lv = heroGrid and heroGrid.lv or 1
  1701. local star = heroGrid and heroGrid.star or 0
  1702. local quality = heroGrid and heroGrid.quality or 0
  1703. -- 进阶
  1704. local maxQuality = HeroGrid.getMaxQuality(star)
  1705. if quality >= maxQuality then
  1706. --print("[isHeroUpDot] 当前quality 大于 总的星级 quality = "..quality.." maxQuality = "..maxQuality)
  1707. return
  1708. end
  1709. local maxLv = HeroGrid.getMaxLv(heroGrid.star, maxQuality)
  1710. if lv >= maxLv then
  1711. --print("[isHeroUpDot] 当前等级 大于 最大等级 lv = "..lv.." maxLv = "..maxLv)
  1712. return
  1713. end
  1714. local nNowMaxLv = HeroGrid.getNowQualityMaxLv(star, quality)
  1715. if lv < nNowMaxLv then
  1716. --print("[isHeroUpDot] 当前等级 还未到达可升的最大等级 lv = "..lv.." nNowMaxLv = "..nNowMaxLv)
  1717. return
  1718. end
  1719. --print("[isHeroUpDot] id = "..heroGrid.id.." lv = "..lv.." star = "
  1720. --..star.." quality = "..quality.." maxQuality = "..maxQuality.." maxLv = "..maxLv)
  1721. local conf = UpNeedExcel.upQuality[quality + 1]
  1722. if not conf then
  1723. --print("[isHeroUpDot] 不存在下一星级配置 nextquality = "..quality + 1)
  1724. return
  1725. end
  1726. if human.db.jinbi < conf.money then
  1727. --print("[isHeroUpDot] 玩家金币不足 jinbi = "..human.db.jinbi.." nNeedMoney = "..conf.money)
  1728. return
  1729. end
  1730. if BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID) < conf.jinjieshi then
  1731. --print("[isHeroUpDot] 玩家进阶道具不足 jinjieshi = "..BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID)
  1732. -- .." nNeedjinjieshi = "..conf.jinjieshi)
  1733. return
  1734. end
  1735. return true
  1736. end
  1737. -- 升级/进阶判断
  1738. function isHeroLevelDot(human, heroGrid)
  1739. if human.db.lv < 9 then
  1740. return false
  1741. end
  1742. if isHeroLvDot(human, heroGrid) then -- 升级
  1743. return true
  1744. end
  1745. if isHeroUpDot(human, heroGrid) then -- 进阶判断
  1746. return true
  1747. end
  1748. end
  1749. -- 升星/觉醒红点
  1750. function isHeroJuexingDot(human, heroIndex, heroGrid)
  1751. if human.db.lv < 9 then
  1752. return
  1753. end
  1754. local heroConfig = HeroExcel.hero[heroGrid.id]
  1755. if not heroConfig then return end
  1756. local attrConfig = HeroDefine.getAttrConfig(heroGrid.id, heroGrid.star)
  1757. if not attrConfig then return end
  1758. local nextAttrConfig = HeroDefine.getNextAttrConfig(heroGrid.id, heroGrid.star)
  1759. if not nextAttrConfig then
  1760. return sendHeroJueXingMax(human, heroGrid.id, heroIndex)
  1761. end
  1762. -- 角色等级/世界等级是否可以
  1763. local isFix = isFixUpStarLv(human, heroGrid.star+1)
  1764. if not isFix then return end
  1765. -- 判断消耗材料
  1766. local needItemCnt = attrConfig.jinjieshi
  1767. if BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID) < needItemCnt then
  1768. return
  1769. end
  1770. -- 额外材料
  1771. for i = 1, #attrConfig.needItems do
  1772. local itemID = attrConfig.needItems[i][1]
  1773. local itemCnt = attrConfig.needItems[i][2]
  1774. if BagLogic.getItemCnt(human, itemID) < itemCnt then
  1775. return
  1776. end
  1777. end
  1778. local without = {}
  1779. without[heroIndex] = true
  1780. for _, cond in ipairs(attrConfig.cond) do
  1781. local ctype = cond[1]
  1782. local needCnt = cond[3]
  1783. if not needCnt then return end
  1784. if ctype == HechengLogic.COND_TYPE_CAMPSTAR then
  1785. needCnt = cond[4]
  1786. end
  1787. for i = 1, needCnt do
  1788. local index = selectJuexingGrid(human, ctype, cond, without)
  1789. if not index then return end
  1790. without[index] = true
  1791. end
  1792. end
  1793. return true
  1794. end
  1795. -- 查找升星材料
  1796. function selectJuexingGrid(human, ctype, cond, without)
  1797. for index,heroGrid in pairs(human.db.heroBag) do
  1798. if index ~= 0 and not without[index] and
  1799. isFixJuexingCond(heroGrid, ctype, cond) then
  1800. return index
  1801. end
  1802. end
  1803. end
  1804. -- 是否满足材料需求
  1805. function isFixJuexingCond(grid, ctype, cond)
  1806. local heroConfig = HeroExcel.hero[grid.id]
  1807. if not heroConfig then return end
  1808. if ctype == HechengLogic.COND_TYPE_HEROID then
  1809. local needConfig = HeroExcel.hero[cond[2]]
  1810. if not needConfig then return end
  1811. local needStar = cond[4] or needConfig.star
  1812. if grid.id == cond[2] and needStar == grid.star then
  1813. return true
  1814. end
  1815. elseif ctype == HechengLogic.COND_TYPE_CAMPSTAR then
  1816. if cond[2] ~= 0 and cond[2] ~= heroConfig.camp then
  1817. return
  1818. end
  1819. if cond[3] ~= grid.star then
  1820. return
  1821. end
  1822. return true
  1823. end
  1824. end
  1825. function sendBagDots(human)
  1826. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  1827. local msgRet = Msg.gc.GC_HERO_BAG_DOTS
  1828. msgRet.list[0] = 0
  1829. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  1830. local uuid = combatHero and combatHero[i]
  1831. local heroGrid = getHeroGridByUuid(human, uuid)
  1832. if heroGrid then
  1833. msgRet.list[0] = msgRet.list[0] + 1
  1834. local net = msgRet.list[msgRet.list[0]]
  1835. net.bagIndex = heroGrid.bagIndex
  1836. net.isDot = isHeroDot(human, heroGrid) and 1 or 0
  1837. end
  1838. end
  1839. --Msg.trace(msgRet)
  1840. local redDotTag = HeroBook.isDot(human)
  1841. msgRet.bookDot = redDotTag or 0
  1842. Msg.send(msgRet, human.fd)
  1843. refreshDot(human)
  1844. end
  1845. function refreshDot(human, uuid)
  1846. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  1847. if not combatHero then return end
  1848. local isFind = nil
  1849. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  1850. if uuid == nil or combatHero[i] == uuid then
  1851. isFind = true
  1852. break
  1853. end
  1854. end
  1855. if not isFind then return end
  1856. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_301)
  1857. end
  1858. -- 今日英雄重置剩余次数
  1859. function getResetLeftCnt(human)
  1860. local heroResetCnt = human.db.heroResetCnt or 0
  1861. return math.max(HERO_RESET_FREECNT - heroResetCnt, 0)
  1862. end
  1863. -- 重置返还材料
  1864. local RESET_RETURN_ITEMS = {}
  1865. function getResetReturnItems(heroGrid)
  1866. Util.cleanTable(RESET_RETURN_ITEMS)
  1867. -- 升级
  1868. local lv = heroGrid.lv
  1869. if heroGrid.oldLV then
  1870. lv = heroGrid.oldLV
  1871. end
  1872. for i = 2, lv do
  1873. local upcf = UpNeedExcel.upLv[i]
  1874. if upcf then
  1875. RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] or 0) + upcf.soul
  1876. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  1877. end
  1878. end
  1879. -- 升阶
  1880. local quality = heroGrid.quality
  1881. if heroGrid.oldQuality then
  1882. quality = heroGrid.oldQuality
  1883. end
  1884. -- 升阶
  1885. for i = 1, quality do
  1886. local upcf = UpNeedExcel.upQuality[i]
  1887. if upcf then
  1888. RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] or 0) + upcf.jinjieshi
  1889. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  1890. end
  1891. end
  1892. -- 升星材料
  1893. for i = 1,heroGrid.star-1 do
  1894. local attrConfig = HeroDefine.getAttrConfig(heroGrid.id, i)
  1895. if attrConfig then
  1896. if attrConfig.jinjieshi > 0 then
  1897. RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] or 0) + attrConfig.jinjieshi
  1898. end
  1899. for j = 1,#attrConfig.needItems do
  1900. RESET_RETURN_ITEMS[attrConfig.needItems[j][1]] = (RESET_RETURN_ITEMS[attrConfig.needItems[j][1]] or 0) + attrConfig.needItems[j][2]
  1901. end
  1902. end
  1903. end
  1904. -- 护符/水晶材料
  1905. local maxCnt = 100 -- 防止死循环
  1906. local equipID = heroGrid.equip and heroGrid.equip[ItemDefine.EQUIP_SUBTYPE_SHUIJIN]
  1907. while equipID do
  1908. maxCnt = maxCnt - 1
  1909. if maxCnt < 0 then
  1910. assert()
  1911. end
  1912. local eupcf = EquipExcel.shuijingUpNeed[equipID]
  1913. if not eupcf then break end
  1914. local preEquipID = eupcf.prevID
  1915. equipID = preEquipID
  1916. if preEquipID > 0 then
  1917. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + eupcf.money
  1918. RESET_RETURN_ITEMS[ItemDefine.ITEM_SHUIJING_UPLEVEL_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_SHUIJING_UPLEVEL_ID] or 0) + eupcf.jinghua
  1919. end
  1920. end
  1921. return RESET_RETURN_ITEMS
  1922. end
  1923. function getRealResetReturnItems(heroGrid)
  1924. Util.cleanTable(RESET_RETURN_ITEMS)
  1925. -- 升级
  1926. local lv = heroGrid.lv
  1927. if heroGrid.oldLV then
  1928. lv = heroGrid.oldLV
  1929. end
  1930. for i = 2, lv do
  1931. local upcf = UpNeedExcel.upLv[i]
  1932. if upcf then
  1933. RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] or 0) + upcf.soul
  1934. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  1935. end
  1936. end
  1937. -- 升阶
  1938. local quality = heroGrid.quality
  1939. if heroGrid.oldQuality then
  1940. quality = heroGrid.oldQuality
  1941. end
  1942. -- 升阶
  1943. for i = 1, quality do
  1944. local upcf = UpNeedExcel.upQuality[i]
  1945. if upcf then
  1946. RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] or 0) + upcf.jinjieshi
  1947. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  1948. end
  1949. end
  1950. return RESET_RETURN_ITEMS
  1951. end
  1952. -- 重置花费
  1953. function getResetNeedZuanshi(lv)
  1954. if lv > 100 then
  1955. return 50
  1956. end
  1957. return 0
  1958. end
  1959. -- 重置查询
  1960. function resetHeroQuery(human, heroID, heroIndex)
  1961. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1962. if not heroGrid then return end
  1963. if XingYaoGongMing.isGongMing(human,heroIndex,XingYaoGongMing.XYHERO_RESET) then
  1964. return
  1965. end
  1966. local heroConfig = HeroExcel.hero[heroGrid.id]
  1967. if not heroConfig then return end
  1968. if heroConfig.star > HERO_RESET_MAXSTAR then
  1969. return Broadcast.sendErr(human, Util.format(Lang.HERO_RESET_ERR_STAR, HERO_RESET_MAXSTAR + 1))
  1970. end
  1971. ObjHuman.updateDaily(human)
  1972. --[[if getResetLeftCnt(human) < 1 then
  1973. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_CNT)
  1974. end--]]
  1975. local list = getRealResetReturnItems(heroGrid)
  1976. local msgRet = Msg.gc.GC_HERO_RESET_QUERY
  1977. msgRet.heroID = heroID
  1978. msgRet.heroIndex = heroIndex
  1979. msgRet.needZuanshi = getResetNeedZuanshi(heroGrid.lv)
  1980. msgRet.maxFreeCnt = HERO_RESET_FREECNT
  1981. msgRet.leftFreeCnt = getResetLeftCnt(human)
  1982. msgRet.items[0] = 0
  1983. for itemID, itemCnt in pairs(list) do
  1984. if msgRet.items[0] >= #msgRet.items then
  1985. break
  1986. end
  1987. msgRet.items[0] = msgRet.items[0] + 1
  1988. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  1989. end
  1990. if msgRet.items[0] < 1 then
  1991. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_NONE)
  1992. end
  1993. -- Msg.trace(msgRet)
  1994. Msg.send(msgRet, human.fd)
  1995. end
  1996. -- 英雄重置
  1997. function resetHero(human, heroID, heroIndex)
  1998. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1999. if not heroGrid then return end
  2000. if XingYaoGongMing.isGongMing(human,heroIndex,XingYaoGongMing.XYHERO_RESET) then
  2001. return
  2002. end
  2003. local heroConfig = HeroExcel.hero[heroGrid.id]
  2004. if not heroConfig then return end
  2005. if heroConfig.star > HERO_RESET_MAXSTAR then
  2006. return Broadcast.sendErr(human, Util.format(Lang.HERO_RESET_ERR_STAR, HERO_RESET_MAXSTAR + 1))
  2007. end
  2008. local list = getRealResetReturnItems(heroGrid)
  2009. if not next(list) then
  2010. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_NONE)
  2011. end
  2012. if getResetLeftCnt(human) < 1 then
  2013. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_CNT)
  2014. end
  2015. local needZuanshi = getResetNeedZuanshi(heroGrid.lv)
  2016. if not ObjHuman.checkRMB(human, needZuanshi) then
  2017. return
  2018. end
  2019. ObjHuman.decZuanshi(human, -needZuanshi, "hero_reset")
  2020. human.db.heroResetCnt = (human.db.heroResetCnt or 0) + 1
  2021. heroGrid.lv = 1
  2022. heroGrid.quality = 0
  2023. if heroGrid.equip and heroGrid.equip[ItemDefine.EQUIP_SUBTYPE_SHUIJIN] then
  2024. heroGrid.equip[ItemDefine.EQUIP_SUBTYPE_SHUIJIN] = nil
  2025. heroGrid.shuijingAttrID = nil
  2026. end
  2027. for itemID, itemCnt in pairs(list) do
  2028. BagLogic.addItem(human, itemID, itemCnt, "hero_reset")
  2029. end
  2030. HeroEquip.putOffQuick(human, heroID, heroIndex, true)
  2031. FuwenLogic.putOffQuick(human, heroID, heroIndex, true)
  2032. XingYaoGongMing.onDelHero(human,heroGrid,heroIndex)
  2033. heroGrid.fuwen = nil
  2034. if heroGrid.relic then
  2035. WinnerRelicLogic.WinnerRelic_CancelWinner(human, heroGrid, heroIndex)
  2036. heroGrid.relic = {}
  2037. end
  2038. ObjHuman.doCalcHero(human,heroIndex)
  2039. sendHeroBagDynamic(human, heroID, heroIndex)
  2040. refreshDot(human, heroGrid.uuid)
  2041. local msgRet = Msg.gc.GC_HERO_RESET
  2042. msgRet.heroID = heroID
  2043. msgRet.heroIndex = heroIndex
  2044. msgRet.items[0] = 0
  2045. for itemID, itemCnt in pairs(list) do
  2046. if msgRet.items[0] >= #msgRet.items then
  2047. break
  2048. end
  2049. if not ItemDefine.isEquip(itemID) then
  2050. msgRet.items[0] = msgRet.items[0] + 1
  2051. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  2052. end
  2053. end
  2054. msgRet.items[0] = EquipLogic.makeEquipItem(human, msgRet.items, msgRet.items[0])
  2055. Msg.send(msgRet, human.fd)
  2056. checkChangeMaxZDL(human, heroGrid)
  2057. end
  2058. -- 对所有英雄操作一次装备皮肤
  2059. function AllHeroEquipSkin(human)
  2060. if not human then
  2061. return
  2062. end
  2063. local nHeroLen = human.db.heroBag[0]
  2064. if 0 >= nHeroLen then
  2065. return
  2066. end
  2067. local tEquipSkin = {}
  2068. for i = 1, nHeroLen, 1 do
  2069. local heroGrid = human.db.heroBag[i]
  2070. if heroGrid then
  2071. local nID = heroGrid.id
  2072. -- 不存在去查表
  2073. if not tEquipSkin[nID] then
  2074. local bHaveSkin = false
  2075. local skinOn = SkinLogic.checkHeroSkinById(human, nID)
  2076. if skinOn then
  2077. heroGrid.skinOn = skinOn
  2078. bHaveSkin = true
  2079. else
  2080. skinOn = -1
  2081. end
  2082. tEquipSkin[nID] = {bHaveSkin = bHaveSkin, skinOn = skinOn}
  2083. else
  2084. if true == tEquipSkin[nID].bHaveSkin then
  2085. heroGrid.skinOn = tEquipSkin[nID].skinOn
  2086. end
  2087. end
  2088. end
  2089. end
  2090. end
  2091. -- 统计英雄背包中, 每类SSR, UR英雄的最高星级
  2092. function GetHeroMaxStarList(human)
  2093. local noCalcHeroList = {}
  2094. local maxStarList = {}
  2095. for index = 1, human.db.heroBag[0] do
  2096. local heroGrid = human.db.heroBag[index]
  2097. if heroGrid and not noCalcHeroList[heroGrid.id] then
  2098. local heroId = heroGrid.id
  2099. local heroCfg = HeroExcel.hero[heroId]
  2100. if heroCfg.grade < HeroDefine.HERO_SSR_GRADE then
  2101. noCalcHeroList[heroId] = 1
  2102. else
  2103. if not maxStarList[heroId] then
  2104. maxStarList[heroId] = {
  2105. uuid = heroGrid.uuid,
  2106. star = heroGrid.star
  2107. }
  2108. else
  2109. if heroGrid.star > maxStarList[heroId].star then
  2110. maxStarList[heroId].uuid = heroGrid.uuid
  2111. maxStarList[heroId].star = heroGrid.star
  2112. end
  2113. end
  2114. end
  2115. end
  2116. end
  2117. return maxStarList
  2118. end
  2119. -- 统计背包中符合星级条件的英雄数量
  2120. function CalcStarHeroCnt(human, starCond, excludeList)
  2121. local correctNum = 0
  2122. for index = 1, human.db.heroBag[0] do
  2123. local heroGrid = human.db.heroBag[index]
  2124. if heroGrid and heroGrid.star >= starCond and (not excludeList or not excludeList[heroGrid.uuid]) then
  2125. correctNum = correctNum + 1
  2126. end
  2127. end
  2128. return correctNum
  2129. end
  2130. -- 获取背包中同Id最高星级的英雄
  2131. function GetMaxStarHero(human, heroId)
  2132. local heroCfg = HeroExcel.hero[heroId]
  2133. if heroCfg.grade < HeroDefine.HERO_SSR_GRADE then
  2134. return
  2135. end
  2136. local posList = getHeroListById(human, heroId)
  2137. if #posList == 0 then
  2138. return
  2139. end
  2140. local herouuid
  2141. local maxStar = 0
  2142. for _, pos in ipairs(posList) do
  2143. local heroGrid = human.db.heroBag[pos]
  2144. if maxStar == 0 then
  2145. maxStar = heroGrid.star
  2146. herouuid = heroGrid.uuid
  2147. end
  2148. if heroGrid.star > maxStar then
  2149. maxStar = heroGrid.star
  2150. herouuid = heroGrid.uuid
  2151. end
  2152. end
  2153. return maxStar, herouuid
  2154. end
  2155. function heroJueXingOneClickQuery(human)
  2156. local tMsgData = Msg.gc.GC_HERO_JUEXIN_ONECLICK_QUERY
  2157. tMsgData.bOneClick = 1
  2158. local bOpen = Abs365CardLogic.IsBuyCard(human)
  2159. if 0 == bOpen then
  2160. print("[heroJueXingOneClickQuery] 未购买365卡直接返回")
  2161. tMsgData.bOneClick = 0
  2162. Msg.send(tMsgData, human.fd)
  2163. return
  2164. end
  2165. Msg.send(tMsgData, human.fd)
  2166. print("[heroJueXingOneClickQuery] 回复协议结束")
  2167. end
  2168. local function HeroLogic_CheckOneClickHero(human, tHero, tHeroInfo)
  2169. local tCheckHero = {}
  2170. local nHeroLen = tHero[0]
  2171. -- 先检测英雄
  2172. if nHeroLen % 2 ~= 0 then
  2173. print("[heroJueXingOneClickDo] 英雄长度不正确 nHeroLen = "..nHeroLen)
  2174. return false
  2175. end
  2176. -- 消耗材料检查
  2177. local nJinJieShiNum, tExtraItem = 0, {}
  2178. for i = 1, nHeroLen, 2 do
  2179. local nHeroID, nHeroIndex = tHero[i], tHero[i+1]
  2180. if not tCheckHero[nHeroID] then
  2181. tCheckHero[nHeroID] = 1
  2182. else
  2183. print("[heroJueXingOneClickDo] 存在重复的英雄ID nHeroID = "..nHeroID)
  2184. return false
  2185. end
  2186. -- 英雄是否存在
  2187. local heroGrid = getHeroGrid(human, nHeroID, nHeroIndex)
  2188. if not heroGrid then
  2189. return false
  2190. end
  2191. local attrConfig = HeroDefine.getAttrConfig(nHeroID, heroGrid.star)
  2192. if not attrConfig then
  2193. return false
  2194. end
  2195. local nextAttrConfig = HeroDefine.getNextAttrConfig(nHeroID, heroGrid.star)
  2196. if not nextAttrConfig then
  2197. return false
  2198. end
  2199. -- 判断是否达到开放等级
  2200. local isFix, upStarNeedLv, upStarNeedWorldLv = isFixUpStarLv(human, heroGrid.star+1)
  2201. if not isFix then
  2202. if upStarNeedLv and upStarNeedWorldLv and upStarNeedWorldLv > 0 then
  2203. return Broadcast.sendErr(human, Util.format(Lang.HERO_JUEXING_ERR_HEROLV, upStarNeedLv, upStarNeedWorldLv))
  2204. elseif upStarNeedLv then
  2205. return Broadcast.sendErr(human, Util.format(Lang.HERO_JUEXING_ERR_HEROLV2, upStarNeedLv))
  2206. end
  2207. return false
  2208. end
  2209. -- 累加材料
  2210. nJinJieShiNum = nJinJieShiNum + attrConfig.jinjieshi
  2211. for j = 1, #attrConfig.needItems do
  2212. local itemID = attrConfig.needItems[j][1]
  2213. local itemCnt = attrConfig.needItems[j][2]
  2214. if not tExtraItem[itemID] then
  2215. tExtraItem[itemID] = 0
  2216. end
  2217. tExtraItem[itemID] = tExtraItem[itemID] + itemCnt
  2218. end
  2219. local tData = {
  2220. nHeroID = nHeroID,
  2221. nHeroIndex = nHeroIndex,
  2222. tInputIDList = {},
  2223. tInputIndexList = {}
  2224. }
  2225. table.insert(tHeroInfo, tData)
  2226. end
  2227. return true, nJinJieShiNum, tExtraItem
  2228. end
  2229. function heroJueXingOneClickDo(human, tHeroData)
  2230. local nAllLen = tHeroData[0]
  2231. if 0 >= nAllLen then
  2232. return
  2233. end
  2234. print("[heroJueXingOneClickDo] 开始进入协议")
  2235. local tHero, tInputIDList, tInputIndexList = {}, {}, {}
  2236. local nBeginLen, nForNum, nGuiShuIndex = 1, 0, 1
  2237. tHero[0] = 0
  2238. tInputIDList[0] = 0
  2239. tInputIndexList[0] = 0
  2240. local tCheckIndex = {}
  2241. while nBeginLen < nAllLen do
  2242. if nForNum >= 200 then
  2243. print("[heroJueXingOneClickDo] 解析数据失败")
  2244. return
  2245. end
  2246. nForNum = nForNum + 1
  2247. local nHeroID, nHeroIndex = tHeroData[nBeginLen], tHeroData[nBeginLen + 1]
  2248. if not tCheckIndex[nHeroIndex] then
  2249. tCheckIndex[nHeroIndex] = true
  2250. else
  2251. print("[heroJueXingOneClickDo] 存在重复的英雄Index nHeroIndex = "..nHeroIndex)
  2252. return
  2253. end
  2254. tHero[0] = tHero[0] + 2
  2255. table.insert(tHero, nHeroID)
  2256. table.insert(tHero, nHeroIndex)
  2257. nBeginLen = nBeginLen + 2
  2258. local nIDLen = tHeroData[nBeginLen]
  2259. if not nIDLen or nBeginLen + nIDLen > nAllLen then
  2260. break
  2261. end
  2262. -- 处理消耗的HeroID
  2263. table.insert(tInputIDList, nGuiShuIndex)
  2264. table.insert(tInputIDList, nIDLen)
  2265. tInputIDList[0] = tInputIDList[0] + 2
  2266. for i = nBeginLen + 1, nBeginLen + nIDLen, 1 do
  2267. tInputIDList[0] = tInputIDList[0] + 1
  2268. table.insert(tInputIDList, tHeroData[i])
  2269. end
  2270. -- 处理消耗的HeroIndex
  2271. nBeginLen = nBeginLen + nIDLen + 1
  2272. if nBeginLen > nAllLen then
  2273. break
  2274. end
  2275. local nHeroIndexLen = tHeroData[nBeginLen]
  2276. if not nHeroIndexLen then
  2277. print("[heroJueXingOneClickDo] 不存在对应的nHeroIndexLen nBeginLen = "..nBeginLen)
  2278. return
  2279. end
  2280. table.insert(tInputIndexList, nGuiShuIndex)
  2281. table.insert(tInputIndexList, nHeroIndexLen)
  2282. tInputIndexList[0] = tInputIndexList[0] + 2
  2283. for i = nBeginLen + 1, nBeginLen + nHeroIndexLen, 1 do
  2284. local nIndex = tHeroData[i]
  2285. if not tCheckIndex[nIndex] then
  2286. tCheckIndex[nIndex] = true
  2287. else
  2288. print("[heroJueXingOneClickDo] 存在重复的英雄Index nHeroIndex = "..nIndex)
  2289. return
  2290. end
  2291. tInputIndexList[0] = tInputIndexList[0] + 1
  2292. table.insert(tInputIndexList, nIndex)
  2293. end
  2294. nBeginLen = nBeginLen + nHeroIndexLen + 1
  2295. nGuiShuIndex = nGuiShuIndex + 1
  2296. end
  2297. print("[heroJueXingOneClickDo] 解析上传数据完成")
  2298. local tHeroInfo = {}
  2299. local nHeroLen, nInputIDLen, nInputIndexLen = tHero[0], tInputIDList[0], tInputIndexList[0]
  2300. if 0 >= nHeroLen or 0 >= nInputIDLen or 0 >= nInputIndexLen then
  2301. print("[heroJueXingOneClickDo] 上传的数据长度不正确")
  2302. return
  2303. end
  2304. -- 先检测英雄
  2305. local bRet, nJinJieShiNum, tExtraItem = HeroLogic_CheckOneClickHero(human, tHero, tHeroInfo)
  2306. if false == bRet or not nJinJieShiNum or not tExtraItem then
  2307. print("[heroJueXingOneClickDo] 英雄检查不通过")
  2308. return
  2309. end
  2310. print("[heroJueXingOneClickDo] 检测英雄 完成")
  2311. -- 检查消耗材料是否足够
  2312. if not BagLogic.checkItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID, nJinJieShiNum) then
  2313. print("[heroJueXingOneClickDo] 英雄消耗材料不足 nJinJieShiNum = "..nJinJieShiNum)
  2314. return
  2315. end
  2316. print("[heroJueXingOneClickDo] 检查消耗材料是否足够 完成")
  2317. -- 检查消耗额外材料
  2318. for itemID, itemCnt in pairs(tExtraItem) do
  2319. if not BagLogic.checkItemCnt(human, itemID, itemCnt) then
  2320. print("[heroJueXingOneClickDo] 英雄消耗额外材料不足 itemID = "..itemID.." itemCnt = "..itemCnt)
  2321. return
  2322. end
  2323. end
  2324. print("[heroJueXingOneClickDo] 检查消耗额外材料 完成")
  2325. -- 统计消耗的英雄ID
  2326. local i, nLen = 1, 0
  2327. while i < nInputIDLen do
  2328. if nLen >= 100 then
  2329. print("[heroJueXingOneClickDo] 循环次数不正确,死循环返回")
  2330. return
  2331. end
  2332. nLen = nLen + 1
  2333. local nIndex = tInputIDList[i]
  2334. i = i + 1
  2335. local nHeroIDLen = tInputIDList[i]
  2336. if not tHeroInfo[nIndex] then
  2337. print("[heroJueXingOneClickDo] 英雄ID 下标 与上传的英雄信息数量不同 nIndex = "..nIndex)
  2338. return
  2339. end
  2340. local tHeroInputIDList = tHeroInfo[nIndex].tInputIDList
  2341. for j = i + 1, i + nHeroIDLen, 1 do
  2342. local nID = tInputIDList[j]
  2343. table.insert(tHeroInputIDList, nID)
  2344. end
  2345. tHeroInputIDList[0] = nHeroIDLen
  2346. i = i + nHeroIDLen + 1
  2347. end
  2348. print("[heroJueXingOneClickDo] 统计消耗的英雄ID 完成")
  2349. -- 统计消耗的英雄Index
  2350. i = 1
  2351. nLen = 0
  2352. while i < nInputIndexLen do
  2353. if nLen >= 100 then
  2354. print("[heroJueXingOneClickDo] 循环次数不正确,死循环返回")
  2355. return
  2356. end
  2357. nLen = nLen + 1
  2358. local nIndex = tInputIndexList[i]
  2359. i = i + 1
  2360. local nHeroIndexLen = tInputIndexList[i]
  2361. if not tHeroInfo[nIndex] then
  2362. print("[heroJueXingOneClickDo] 英雄下标 与上传的英雄信息数量不同 nIndex = "..nIndex)
  2363. return
  2364. end
  2365. local tHeroInputIndexList = tHeroInfo[nIndex].tInputIndexList
  2366. for j = i + 1, i + nHeroIndexLen, 1 do
  2367. local nID = tInputIndexList[j]
  2368. table.insert(tHeroInputIndexList, nID)
  2369. end
  2370. tHeroInputIndexList[0] = nHeroIndexLen
  2371. i = i + nHeroIndexLen + 1
  2372. end
  2373. print("[heroJueXingOneClickDo] 统计消耗的英雄Index 完成")
  2374. -- table.print_lua_table(tHeroInfo)
  2375. -- 检查升级数据是否有问题
  2376. for _, v in ipairs(tHeroInfo) do
  2377. local nHeroID, nHeroIndex = v.nHeroID, v.nHeroIndex
  2378. local heroGrid = getHeroGrid(human, nHeroID, nHeroIndex)
  2379. if not heroGrid then
  2380. print("[heroJueXingOneClickDo] 获取不到对应的英雄 heroGrid nHeroID = "..nHeroID.." nHeroIndex = "..nHeroIndex)
  2381. return
  2382. end
  2383. local attrConfig = HeroDefine.getAttrConfig(nHeroID, heroGrid.star)
  2384. if not attrConfig then
  2385. print("[heroJueXingOneClickDo] 获取不到对应的英雄attr属性 heroGrid nHeroID = "..nHeroID.." nHeroIndex = "..nHeroIndex)
  2386. return
  2387. end
  2388. if not HechengLogic.checkCond(human, v.tInputIDList, v.tInputIndexList, attrConfig.cond) then
  2389. return Broadcast.sendErr(human, Lang.HERO_JUEXING_CAILIAO_ERR)
  2390. end
  2391. end
  2392. print("[heroJueXingOneClickDo] 进入扣材料阶段")
  2393. -- 扣消耗
  2394. BagLogic.delItem(human, ItemDefine.ITEM_HERO_UPGRADE_ID, nJinJieShiNum, "hero_juexing")
  2395. -- 额外材料
  2396. for itemID, itemCnt in pairs(tExtraItem) do
  2397. BagLogic.delItem(human, itemID, itemCnt, "hero_juexing")
  2398. end
  2399. print("[heroJueXingOneClickDo] 开始正式合成英雄")
  2400. local tMsgData = Msg.gc.GC_HERO_JUEXING_ONECLICK_DO
  2401. tMsgData.tHeroList[0] = #tHeroInfo
  2402. for j, v in ipairs(tHeroInfo) do
  2403. -- 下面的数据已经在上面检查过了
  2404. local heroGrid = getHeroGrid(human, v.nHeroID, v.nHeroIndex)
  2405. local isFix, upStarNeedLv, upStarNeedWorldLv = isFixUpStarLv(human, heroGrid.star+1)
  2406. local nextAttrConfig = HeroDefine.getNextAttrConfig(v.nHeroID, heroGrid.star)
  2407. local attrConfig = HeroDefine.getAttrConfig(v.nHeroID, heroGrid.star)
  2408. local fenjieList = FenjieLogic.fenjie(human, FenjieLogic.FENJIE_DO_JUEXING, v.tInputIDList, v.tInputIndexList)
  2409. local tData = tMsgData.tHeroList[j]
  2410. tData.id = v.nHeroID
  2411. tData.index = v.nHeroIndex
  2412. fontJueXingHeroNet(tData.oldData, heroGrid, v.nHeroIndex, human)
  2413. -- 继承英雄等级 阶数 装备 水晶
  2414. writeLogHeroDel(human, "hero_juexing", heroGrid)
  2415. heroGrid.star = nextAttrConfig.star
  2416. onGetNewHero(human, heroGrid, "hero_juexing", v.nHeroIndex)
  2417. ObjHuman.doCalcHero(human, v.nHeroIndex)
  2418. sendHeroBagDynamic(human, heroGrid.id, v.nHeroIndex)
  2419. writeLogHeroAdd(human, "hero_juexing", heroGrid)
  2420. fontJueXingHeroNet(tData.newData, heroGrid, v.nHeroIndex, human)
  2421. local diffCnt, diffList = getSkillDiffList(attrConfig, nextAttrConfig)
  2422. diffCnt = diffCnt > #tData.skillUp and #tData.skillUp or diffCnt
  2423. tData.isAllSkillUp = (diffCnt > 1) and 1 or 0
  2424. tData.skillUp[0] = diffCnt
  2425. for k = 1, diffCnt do
  2426. makeSkillNet(tData.skillUp[k], diffList[k][2])
  2427. end
  2428. BagLogic.BagLogic_GetAllSendInfo(human, tData.itemList, fenjieList, CommonDefine.COMMON_SEND_PRIZE_TYPE_KEYVAL)
  2429. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE12, nextAttrConfig.star,heroGrid.id)
  2430. local heroConfig = HeroExcel.hero[v.nHeroID]
  2431. local newstar = nextAttrConfig.star or 0
  2432. local newcamp = heroConfig.camp or 0
  2433. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID24,1,newcamp,newstar)
  2434. if newstar == 5 then
  2435. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_11,1)
  2436. end
  2437. if newstar >= 5 then
  2438. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_13,1)
  2439. end
  2440. if newstar == 6 then
  2441. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_16,1)
  2442. JibanLogic.onCallback(human,2,newstar)
  2443. end
  2444. if newstar == 10 then
  2445. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_23,1)
  2446. end
  2447. checkChangeMaxZDL(human, heroGrid)
  2448. HeroLogLogic.finishTaskCB(human, HeroLogLogic.HERO_LOG_TYPE_8, 1, v.nHeroID, newstar)
  2449. -- 弹窗礼包相关触发
  2450. if human.db.heroLevelUpgrade < heroGrid.star then
  2451. human.db.heroLevelUpgrade = heroGrid.star
  2452. GiftLogic.trigger(human,Upgrade_HERO_EVENT,{star = heroGrid.star})
  2453. end
  2454. for j in ipairs(yunYingActParam) do
  2455. yunYingActParam[j] = nil
  2456. end
  2457. yunYingActParam[1] = v.nHeroID
  2458. yunYingActParam[2] = newstar
  2459. yunYingActParam[3] = 1
  2460. YunYingLogic.onCallBack(human, "onHeroStarChange", yunYingActParam)
  2461. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_GETHERO, human.db._id, 1, newstar)
  2462. TriggerLogic.PublishEvent(TriggerDefine.HERO_YINGHUN_JINHUA, human.db._id, 1)
  2463. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_GETPOINTHERO, human.db._id, 1, newstar, v.nHeroID)
  2464. if heroConfig.grade >= HeroDefine.HERO_SSR_GRADE then
  2465. HeroPubLogic.UpdateHero(human, HeroPubLogic.HERO_OP_UPSTAR, v.nHeroID, heroGrid.uuid)
  2466. end
  2467. GodsAreaNS.UpdateHeroData(human, heroGrid.uuid, 1)
  2468. end
  2469. print("[heroJueXingOneClickDo] 正式合成英雄结束")
  2470. Msg.send(tMsgData, human.fd)
  2471. print("[heroJueXingOneClickDo] 发送协议完成")
  2472. -- HechengLogic.hechengQuery(human, 0)
  2473. end