HeroLogic.lua 89 KB

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