HeroLogic.lua 95 KB

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