HeroLogic.lua 94 KB

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