HeroLogic.lua 89 KB

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