HeroLogic.lua 92 KB

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