HeroLogic.lua 93 KB

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