HeroLogic.lua 87 KB

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