HeroLogic.lua 90 KB

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