HeroLogic.lua 91 KB

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