HeroLogic.lua 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004
  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. GiftLogic.trigger(human, GiftLogic.GIFT_HERO_UPGRADE_STAR_DAILY, {currentVal = heroGrid.star}, GiftLogic.GIFT_SEC_TYPE1)
  1079. end
  1080. for i in ipairs(yunYingActParam) do
  1081. yunYingActParam[i] = nil
  1082. end
  1083. yunYingActParam[1] = heroID
  1084. yunYingActParam[2] = newstar
  1085. yunYingActParam[3] = 1
  1086. YunYingLogic.onCallBack(human, "onHeroStarChange", yunYingActParam)
  1087. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_GETHERO, human.db._id, 1, newstar)
  1088. TriggerLogic.PublishEvent(TriggerDefine.HERO_YINGHUN_JINHUA, human.db._id, 1)
  1089. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_GETPOINTHERO, human.db._id, 1, newstar, heroID)
  1090. if heroConfig.grade >= HeroDefine.HERO_SSR_GRADE then
  1091. HeroPubLogic.UpdateHero(human, HeroPubLogic.HERO_OP_UPSTAR, heroID, heroGrid.uuid)
  1092. end
  1093. GodsAreaNS.UpdateHeroData(human, heroGrid.uuid, 1)
  1094. AnotherWorldBattleNS.HeroDataUpdate(human, heroGrid.uuid)
  1095. end
  1096. --返还宝石
  1097. function returnGem(gemData)
  1098. if not gemData then
  1099. return
  1100. end
  1101. local calCnt = function(level)
  1102. local cnt = 0
  1103. for i=level, 1, -1 do
  1104. cnt = cnt + math.ceil(i/3)
  1105. end
  1106. return cnt
  1107. end
  1108. local num = 0
  1109. for _, v in pairs(gemData) do
  1110. num = num + calCnt(v.lv)
  1111. end
  1112. return num
  1113. end
  1114. -- 英雄重生预览
  1115. function heroChongShengQuery(human, heroID, heroIndex)
  1116. local heroConfig = HeroExcel.hero[heroID]
  1117. if not heroConfig then return end
  1118. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1119. if not heroGrid then return end
  1120. if heroGrid.isLock then
  1121. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_LOCK)
  1122. end
  1123. local chongShengConfig = UpNeedExcel.chongSheng[heroGrid.star]
  1124. if not chongShengConfig then -- 只能重生7-9星
  1125. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  1126. end
  1127. -- 没有对应5星的存在
  1128. local attrConfig = HeroDefine.getAttrConfig(heroID, CHONGSHENG_RETURN_STAR)
  1129. if not attrConfig then
  1130. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  1131. end
  1132. local suipianID = SuipianLogic.getSuipianIDbyHeroID(heroID)
  1133. if not suipianID then -- 没有对应的本体碎片
  1134. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_SUIPIANID)
  1135. end
  1136. local otherSuipianID = chongShengConfig.suipianIDs[heroConfig.camp]
  1137. if not otherSuipianID then -- 阵容不对
  1138. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  1139. end
  1140. local msgRet = Msg.gc.GC_HERO_CHONGSHENG_QUERY
  1141. msgRet.id = heroID
  1142. msgRet.index = heroIndex
  1143. msgRet.needItemCnt = chongShengConfig.needItemCnt
  1144. Grid.makeItem(msgRet.bentiSuipian, suipianID, chongShengConfig.bentiCnt)
  1145. Grid.makeItem(msgRet.otherSuipian, otherSuipianID, chongShengConfig.suipianCnt)
  1146. --Msg.trace(msgRet)
  1147. --宝石返回
  1148. local gemCnt = returnGem(heroGrid.gem)
  1149. -- if gemCnt and gemCnt > 0 then
  1150. -- Grid.makeItem(msgRet.gemVec, gemId, gemCnt)
  1151. -- end
  1152. local gemId = HeroDefine.HEROJOBTOGEM[heroConfig.job] or 0
  1153. gemCnt = gemCnt or 0
  1154. Grid.makeItem(msgRet.gemVec, gemId, gemCnt)
  1155. Msg.send(msgRet, human.fd)
  1156. end
  1157. function getHeroMaxStarCtn(human)
  1158. local heroBag = human.db.heroBag
  1159. local maxStar = 0
  1160. local starHeroCnt = 0
  1161. for _,grid in ipairs(heroBag) do
  1162. if grid.star > maxStar then
  1163. maxStar = grid.star
  1164. starHeroCnt = 1
  1165. elseif grid.star == maxStar then
  1166. starHeroCnt = starHeroCnt + 1
  1167. end
  1168. end
  1169. return maxStar,starHeroCnt
  1170. end
  1171. -- 英雄重生
  1172. function heroChongShengDo(human, heroID, heroIndex)
  1173. local heroConfig = HeroExcel.hero[heroID]
  1174. if not heroConfig then return end
  1175. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1176. if not heroGrid then return end
  1177. if heroGrid.isLock then
  1178. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_LOCK)
  1179. end
  1180. local chongShengConfig = UpNeedExcel.chongSheng[heroGrid.star]
  1181. if not chongShengConfig then -- 只能重生7-9星
  1182. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  1183. end
  1184. local attrConfig = HeroDefine.getAttrConfig(heroID, CHONGSHENG_RETURN_STAR)
  1185. if not attrConfig then
  1186. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  1187. end
  1188. local suipianID = SuipianLogic.getSuipianIDbyHeroID(heroID)
  1189. if not suipianID then -- 没有对应的本体碎片
  1190. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_SUIPIANID)
  1191. end
  1192. local otherSuipianID = chongShengConfig.suipianIDs[heroConfig.camp]
  1193. if not otherSuipianID then -- 阵营不对
  1194. return Broadcast.sendErr(human, Lang.HERO_CHONGSHENG_ERR_ID)
  1195. end
  1196. local nowItemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_CHONGSHENG_ID)
  1197. local needItemCnt = chongShengConfig.needItemCnt
  1198. if nowItemCnt < needItemCnt then
  1199. local strName = ItemDefine.getValue(ItemDefine.ITEM_HERO_CHONGSHENG_ID, "name")
  1200. local strRet = Util.format(Lang.COMMON_NO_ITEM, strName)
  1201. return Broadcast.sendErr(human, strRet)
  1202. end
  1203. -- 删除材料
  1204. BagLogic.delItem(human, ItemDefine.ITEM_HERO_CHONGSHENG_ID, needItemCnt, "hero_chongsheng")
  1205. -- 重置到初始返还的材料
  1206. local upList = getResetReturnItems(heroGrid)
  1207. -- 先删除英雄
  1208. delHeroByIndex(human, heroIndex, "hero_chongsheng")
  1209. -- 返还装备
  1210. for i = 1, ItemDefine.EQUIP_MAX_CNT do
  1211. if i ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN and
  1212. heroGrid.equip and heroGrid.equip[i] then
  1213. local equipGrid = heroGrid.equip[i]
  1214. if equipGrid then
  1215. equipGrid.putUuid = nil
  1216. EquipLogic.addByEquipGrid(human, equipGrid, "hero_chongsheng")
  1217. end
  1218. end
  1219. end
  1220. -- 返还符文
  1221. for i = 1, 2 do
  1222. local fuwenGrid = heroGrid.fuwen and heroGrid.fuwen[i]
  1223. if fuwenGrid and fuwenGrid.id then
  1224. FuwenLogic.addByGrid(human, fuwenGrid, "hero_chongsheng")
  1225. end
  1226. end
  1227. --宝石返还
  1228. local gemCnt = returnGem(heroGrid.gem)
  1229. if gemCnt and gemCnt > 0 then
  1230. local gemId = HeroDefine.HEROJOBTOGEM[heroConfig.job] or 0
  1231. BagLogic.addItem(human, gemId, gemCnt, "hero_chongsheng")
  1232. end
  1233. -- 再给东西
  1234. BagLogic.addItem(human, suipianID, chongShengConfig.bentiCnt, "hero_chongsheng")
  1235. BagLogic.addItem(human, otherSuipianID, chongShengConfig.suipianCnt, "hero_chongsheng")
  1236. for itemID, itemCnt in pairs(upList) do
  1237. BagLogic.addItem(human, itemID, itemCnt, "hero_chongsheng")
  1238. end
  1239. -- 通知客户端
  1240. local msgRet = Msg.gc.GC_HERO_CHONGSHENG_DO
  1241. msgRet.list[0] = 2
  1242. Grid.makeItem(msgRet.list[1], suipianID, chongShengConfig.bentiCnt)
  1243. Grid.makeItem(msgRet.list[2], otherSuipianID, chongShengConfig.suipianCnt)
  1244. --宝石
  1245. if gemCnt and gemCnt > 0 then
  1246. local gemId = HeroDefine.HEROJOBTOGEM[heroConfig.job] or 0
  1247. msgRet.list[0] = msgRet.list[0] + 1
  1248. Grid.makeItem(msgRet.list[3], gemId, gemCnt)
  1249. end
  1250. for itemID, itemCnt in pairs(upList) do
  1251. msgRet.list[0] = msgRet.list[0] + 1
  1252. Grid.makeItem(msgRet.list[msgRet.list[0]], itemID, itemCnt)
  1253. end
  1254. msgRet.list[0] = EquipLogic.makeEquipItem(human, msgRet.list, msgRet.list[0])
  1255. Msg.send(msgRet, human.fd)
  1256. checkChangeMaxZDL(human, heroGrid)
  1257. end
  1258. -- 回退
  1259. local HUITUI_HERO_LIST = {}
  1260. local HUITUI_ITEM_LIST = {}
  1261. function getHuituiReturns(heroGrid)
  1262. local heroConfig = HeroExcel.hero[heroGrid.id]
  1263. if not heroConfig then return end
  1264. local config = UpNeedExcel.huiTui[heroGrid.star]
  1265. if not config then return end
  1266. local targetID = heroGrid.id
  1267. if not targetID then return end
  1268. -- 13星无法升级,但可以回退
  1269. if heroGrid.star < 13 then
  1270. local upStarConfig = HeroDefine.getNextAttrConfig(heroGrid.id, heroGrid.star)
  1271. -- 不能升星的话也不能回退
  1272. if not upStarConfig then
  1273. return
  1274. end
  1275. end
  1276. Util.cleanTable(HUITUI_HERO_LIST)
  1277. Util.cleanTable(HUITUI_ITEM_LIST)
  1278. local maxLv = HeroGrid.getMaxLv(config.targetStar, heroGrid.quality)
  1279. local lv = heroGrid.lv
  1280. if heroGrid.oldLV then
  1281. lv = heroGrid.oldLV
  1282. end
  1283. local targetLv = math.min(lv, maxLv)
  1284. -- 升级 不将阶
  1285. for i = targetLv + 1, lv do
  1286. local upcf = UpNeedExcel.upLv[i]
  1287. if upcf then
  1288. HUITUI_ITEM_LIST[ItemDefine.ITEM_GREEN_EXP_ID] = (HUITUI_ITEM_LIST[ItemDefine.ITEM_GREEN_EXP_ID] or 0) + upcf.soul
  1289. HUITUI_ITEM_LIST[ItemDefine.ITEM_JINBI_ID] = (HUITUI_ITEM_LIST[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  1290. end
  1291. end
  1292. -- 圣星文书
  1293. HUITUI_ITEM_LIST[ItemDefine.ITEM_HERO_UPGRADE_BOOK] = (HUITUI_ITEM_LIST[ItemDefine.ITEM_HERO_UPGRADE_BOOK] or 0) + config.upBook
  1294. -- 进阶石
  1295. HUITUI_ITEM_LIST[ItemDefine.ITEM_HERO_UPGRADE_ID] = (HUITUI_ITEM_LIST[ItemDefine.ITEM_HERO_UPGRADE_ID] or 0) + config.jinjieshi
  1296. -- 5星本体碎片数量
  1297. local fiveBentiID = heroGrid.id
  1298. local fiveBentiSuipianID = SuipianLogic.getSuipianIDbyHeroID(fiveBentiID)
  1299. HUITUI_ITEM_LIST[fiveBentiSuipianID] = (HUITUI_ITEM_LIST[fiveBentiSuipianID] or 0) + config.fiveBentiCnt
  1300. -- 5星同系碎片数量
  1301. local materialConfig = UpNeedExcel.huiTuiMaterial[heroConfig.camp]
  1302. HUITUI_ITEM_LIST[materialConfig.fiveHeroSuipian] = (HUITUI_ITEM_LIST[materialConfig.fiveHeroSuipian] or 0) + config.fiveSuipianCnt
  1303. -- 9星傀儡数量
  1304. local nineHeroCnt = (HUITUI_HERO_LIST[9] and HUITUI_HERO_LIST[9][2] or 0) + config.nineHeroCnt
  1305. HUITUI_HERO_LIST[9] = {materialConfig.nineHero, nineHeroCnt}
  1306. -- 10星傀儡数量
  1307. local tenHeroCnt = (HUITUI_HERO_LIST[10] and HUITUI_HERO_LIST[10][2] or 0) + config.tenHeroCnt
  1308. HUITUI_HERO_LIST[10] = {materialConfig.tenHero, tenHeroCnt}
  1309. return config.targetStar, targetLv, config, HUITUI_ITEM_LIST, HUITUI_HERO_LIST
  1310. end
  1311. -- 回退查询
  1312. function sendHuituiQuery(human, heroID, heroIndex)
  1313. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1314. if not heroGrid then return end
  1315. local star, targetLv, config, items, heros = getHuituiReturns(heroGrid)
  1316. if not star then
  1317. return Broadcast.sendErr(human, Lang.HERO_HUITUI_ERR_STAR)
  1318. end
  1319. local msgRet = Msg.gc.GC_HERO_HUITUI_QUERY
  1320. msgRet.heroID = heroID
  1321. msgRet.heroIndex = heroIndex
  1322. HeroGrid.makeHeroSimple(msgRet.oldSimple, heroGrid, heroIndex, human)
  1323. local others = HeroGrid.createOthers(targetLv, nil,nil, star)
  1324. HeroGrid.makeHeroSimpleByID(msgRet.newSimple, heroID, heroIndex, others, nil, true)
  1325. HeroGrid.makeHeroSimpleByGeneral(msgRet.newSimple, heroID)
  1326. Grid.makeItem(msgRet.needItem, ItemDefine.ITEM_HERO_HUITUI_ID, config.needItemCnt)
  1327. msgRet.returnItems[0] = 0
  1328. for itemID, itemCnt in pairs(items) do
  1329. if msgRet.returnItems[0] >= #msgRet.returnItems then
  1330. break
  1331. end
  1332. if itemCnt > 0 then
  1333. msgRet.returnItems[0] = msgRet.returnItems[0] + 1
  1334. Grid.makeItem(msgRet.returnItems[msgRet.returnItems[0]], itemID, itemCnt)
  1335. end
  1336. end
  1337. --专属武器材料
  1338. local weaponReturnItem = HeroExclusiveWeapon.CalcLevelCostItem(human, heroID, heroIndex)
  1339. if weaponReturnItem then
  1340. for itemID, itemCnt in pairs(weaponReturnItem) do
  1341. if msgRet.returnItems[0] >= #msgRet.returnItems then
  1342. break
  1343. end
  1344. if itemCnt > 0 then
  1345. msgRet.returnItems[0] = msgRet.returnItems[0] + 1
  1346. Grid.makeItem(msgRet.returnItems[msgRet.returnItems[0]], itemID, itemCnt)
  1347. end
  1348. end
  1349. end
  1350. -- 英雄种子返还材料
  1351. local seedReturnItem = HeroSeed.CalcReturnItem(human, heroGrid)
  1352. if seedReturnItem then
  1353. for _, itemInfo in ipairs(seedReturnItem) do
  1354. if msgRet.returnItems[0] >= #msgRet.returnItems then
  1355. break
  1356. end
  1357. msgRet.returnItems[0] = msgRet.returnItems[0] + 1
  1358. Grid.makeItem(msgRet.returnItems[msgRet.returnItems[0]], itemInfo[1], itemInfo[2])
  1359. end
  1360. end
  1361. msgRet.returnHeros[0] = 0
  1362. for star, v in pairs(heros) do
  1363. local rHeroID = v[1]
  1364. local rHeroCnt = v[2]
  1365. for i = 1, rHeroCnt do
  1366. if msgRet.returnHeros[0] >= #msgRet.returnHeros then
  1367. break
  1368. end
  1369. local others = HeroGrid.createOthers(1, nil,nil, star)
  1370. msgRet.returnHeros[0] = msgRet.returnHeros[0] + 1
  1371. local heroNet = msgRet.returnHeros[msgRet.returnHeros[0]]
  1372. HeroGrid.makeHeroSimpleByID(heroNet, rHeroID, nil, others, human)
  1373. HeroGrid.makeHeroSimpleByGeneral(heroNet, rHeroID)
  1374. heroNet.star = star
  1375. end
  1376. end
  1377. --Msg.trace(msgRet)
  1378. Msg.send(msgRet, human.fd)
  1379. end
  1380. -- 回退操作
  1381. function huituiHero(human, heroID, heroIndex)
  1382. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1383. if not heroGrid then return end
  1384. local star, targetLv, config, items, heros = getHuituiReturns(heroGrid)
  1385. if not star then
  1386. return Broadcast.sendErr(human, Lang.HERO_HUITUI_ERR_STAR)
  1387. end
  1388. if heroGrid.isLock then
  1389. return Broadcast.sendErr(human, Lang.HERO_HUITUI_ERR_LOCK)
  1390. end
  1391. local needHeroBagCnt = 0
  1392. for star, v in pairs(heros) do
  1393. local rHeroCnt = v[2]
  1394. needHeroBagCnt = needHeroBagCnt + rHeroCnt
  1395. end
  1396. -- 检查英雄背包空间
  1397. if getEmptyCnt(human) < needHeroBagCnt then
  1398. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  1399. end
  1400. if not BagLogic.checkItemCnt(human, ItemDefine.ITEM_HERO_HUITUI_ID, config.needItemCnt) then
  1401. return
  1402. end
  1403. if heroGrid.relic then
  1404. WinnerRelicLogic.WinnerRelic_CancelWinner(human, heroGrid, heroIndex)
  1405. heroGrid.relic = {}
  1406. end
  1407. BagLogic.delItem(human, ItemDefine.ITEM_HERO_HUITUI_ID, config.needItemCnt, "hero_huitui")
  1408. --专属武器材料
  1409. local weaponReturnItem = HeroExclusiveWeapon.CalcLevelCostItem(human, heroID, heroIndex)
  1410. if weaponReturnItem then
  1411. for itemID, itemCnt in pairs(weaponReturnItem) do
  1412. items[itemID] = items[itemID] or 0
  1413. items[itemID] = items[itemID] + itemCnt
  1414. end
  1415. --重置专属武器等级
  1416. HeroExclusiveWeapon.SetHeroWeaponLv(human, heroID, heroIndex, 0)
  1417. end
  1418. -- 英雄种子返还材料
  1419. local seedReturnItem = HeroSeed.CalcReturnItem(human, heroGrid)
  1420. if seedReturnItem then
  1421. for _, itemInfo in ipairs(seedReturnItem) do
  1422. local itemId = itemInfo[1]
  1423. local itemCnt = itemInfo[2]
  1424. items[itemId] = (items[itemId] or 0) + itemCnt
  1425. end
  1426. -- 重置英雄所有种子等级
  1427. HeroSeed.ResetSeedLv(human, heroGrid)
  1428. end
  1429. heroGrid.star = star
  1430. heroGrid.lv = targetLv
  1431. XingYaoGongMing.onDelHero(human,heroGrid,heroIndex)
  1432. ObjHuman.doCalcHero(human, heroIndex)
  1433. sendHeroBagDynamic(human, heroID, heroIndex)
  1434. writeLogHeroAdd(human, "hero_huitui", heroGrid)
  1435. for itemID, itemCnt in pairs(items) do
  1436. if itemCnt > 0 then
  1437. BagLogic.addItem(human, itemID, itemCnt, "hero_huitui")
  1438. end
  1439. end
  1440. for star,v in pairs(heros) do
  1441. local rHeroID = v[1]
  1442. local rHeroCnt = v[2]
  1443. if rHeroCnt > 0 then
  1444. addHero(human, rHeroID,star, rHeroCnt, "hero_huitui")
  1445. end
  1446. end
  1447. local msgRet = Msg.gc.GC_HERO_HUITUI
  1448. msgRet.heroID = heroID
  1449. msgRet.heroIndex = heroIndex
  1450. HeroGrid.makeHeroSimple(msgRet.newSimple, heroGrid, heroIndex, human)
  1451. msgRet.returnItems[0] = 0
  1452. for itemID, itemCnt in pairs(items) do
  1453. if msgRet.returnItems[0] >= #msgRet.returnItems then
  1454. break
  1455. end
  1456. if itemCnt > 0 then
  1457. msgRet.returnItems[0] = msgRet.returnItems[0] + 1
  1458. Grid.makeItem(msgRet.returnItems[msgRet.returnItems[0]], itemID, itemCnt)
  1459. end
  1460. end
  1461. msgRet.returnHeros[0] = 0
  1462. for star,v in pairs(heros) do
  1463. local rHeroID = v[1]
  1464. local rHeroCnt = v[2]
  1465. for i = 1, rHeroCnt do
  1466. if msgRet.returnHeros[0] >= #msgRet.returnHeros then
  1467. break
  1468. end
  1469. msgRet.returnHeros[0] = msgRet.returnHeros[0] + 1
  1470. local heroNet = msgRet.returnHeros[msgRet.returnHeros[0]]
  1471. HeroGrid.makeHeroSimpleByID(heroNet, rHeroID, nil, nil, human)
  1472. heroNet.star = star
  1473. end
  1474. end
  1475. --Msg.trace(msgRet)
  1476. Msg.send(msgRet, human.fd)
  1477. checkChangeMaxZDL(human, heroGrid)
  1478. -- 更新酒馆数据
  1479. local heroConfig = HeroExcel.hero[heroID]
  1480. if heroConfig.grade >= HeroDefine.HERO_SSR_GRADE then
  1481. HeroPubLogic.UpdateHero(human, HeroPubLogic.HERO_OP_RETURN, heroGrid.id, heroGrid.uuid)
  1482. end
  1483. GodsAreaNS.UpdateHeroData(human, heroGrid.uuid, 1)
  1484. AnotherWorldBattleNS.HeroDataUpdate(human, heroGrid.uuid)
  1485. end
  1486. function getHeroListById(human,heroId)
  1487. local heroDBBag = human.db.heroBag
  1488. local list = {}
  1489. for idx,grid in pairs(heroDBBag) do
  1490. if type(grid) == "table" and grid.id == heroId then
  1491. list[#list+1] = idx
  1492. end
  1493. end
  1494. return list
  1495. end
  1496. function getHeroGrid(human, heroID, heroIndex)
  1497. if not heroID then return end
  1498. if not heroIndex then return end
  1499. local heroGrid = human.db.heroBag[heroIndex]
  1500. if type(heroGrid) ~= "table" or heroGrid.id ~= heroID then
  1501. return
  1502. end
  1503. return heroGrid
  1504. end
  1505. -- 根据uuid 获取heroGrid
  1506. function getHeroGridByUuid(human, uuid)
  1507. if not uuid or uuid == "" or uuid == "0" then return end
  1508. for index = 1, human.db.heroBag[0] do
  1509. local heroGrid = human.db.heroBag[index]
  1510. if heroGrid and type(heroGrid) == "table" then
  1511. if heroGrid.uuid == uuid then
  1512. return heroGrid, index
  1513. end
  1514. end
  1515. end
  1516. return nil
  1517. end
  1518. -- 获取下标英雄id
  1519. function getHeroIdByIndex(human, heroIndex)
  1520. if heroIndex <= 0 then
  1521. return
  1522. end
  1523. local heroGrid = human.db.heroBag[heroIndex]
  1524. if heroGrid == nil then
  1525. return
  1526. end
  1527. return heroGrid.id
  1528. end
  1529. function makeHeroShare(msg, heroGrid, bagIndex, human)
  1530. if type(heroGrid) ~= "table" then return end
  1531. local heroConfig = HeroExcel.hero[heroGrid.id]
  1532. if not heroConfig then return end
  1533. msg.uuid = human.db._id
  1534. msg.heroIndex = bagIndex
  1535. HeroGrid.makeHeroSimple(msg.heroSimple, heroGrid, bagIndex, human)
  1536. HeroGrid.makeHeroStatic(msg.heroStatic, heroGrid.id)
  1537. HeroGrid.makeHeroDynamic(msg.heroDynamic, heroGrid, bagIndex, human)
  1538. -- 装备信息
  1539. msg.equips[0] = 0
  1540. for i = 1, ItemDefine.EQUIP_MAX_CNT do
  1541. local equipGrid = heroGrid.equip and heroGrid.equip[i]
  1542. if equipGrid then
  1543. msg.equips[0] = msg.equips[0] + 1
  1544. local equipNet = msg.equips[msg.equips[0]]
  1545. Grid.makeItem(equipNet, equipGrid.id, 1, heroGrid.shuijingAttrID, equipGrid)
  1546. end
  1547. end
  1548. -- 符文
  1549. msg.fuWens[0] = 0
  1550. for i = 1, 2 do
  1551. local fuwenData = heroGrid.fuwen and heroGrid.fuwen[i]
  1552. if fuwenData and fuwenData.id then
  1553. msg.fuWens[0] = msg.fuWens[0] + 1
  1554. local fuwenNet = msg.fuWens[msg.fuWens[0]]
  1555. fuwenNet.pos = i
  1556. Grid.makeItem(fuwenNet.fuwen, fuwenData.id, 1, nil, fuwenData, i,0)
  1557. end
  1558. end
  1559. return true
  1560. end
  1561. function makeHeroShareMonster(msg, monsterID, mosnterLv)
  1562. local others = HeroGrid.createOthers(mosnterLv)
  1563. msg.uuid = ""
  1564. msg.heroIndex = 0
  1565. HeroGrid.makeHeroSimpleByMonsterID(msg.heroSimple, monsterID, others)
  1566. HeroGrid.makeHeroStatic(msg.heroStatic, monsterID)
  1567. HeroGrid.makeHeroDynamicByID(msg.heroDynamic, monsterID)
  1568. msg.equips[0] = 0
  1569. msg.fuWens[0] = 0
  1570. end
  1571. function getHeroShareGrid(uuid, heroIndex)
  1572. local fakeHuman = ObjHuman.onlineUuid[uuid]
  1573. if not fakeHuman then
  1574. local db = RoleDBLogic.getDb(uuid, RoleLogic.getCombatField())
  1575. if not db then
  1576. return
  1577. end
  1578. fakeHuman = {db = db}
  1579. end
  1580. local bagIndex = heroIndex
  1581. local heroGrid = bagIndex and fakeHuman.db.heroBag[bagIndex]
  1582. return heroGrid, bagIndex, fakeHuman
  1583. end
  1584. function shareData(human, uuid, heroIndex, nChatType, nServerIndex)
  1585. print("[shareData] 获取跨服数据开始 uuid = "..uuid.." heroIndex = "..heroIndex.." nChatType = "..nChatType.." nServerIndex = "..nServerIndex)
  1586. if -1 >= nChatType or -1 >= nServerIndex then
  1587. local msgRet = Msg.gc.GC_HERO_SHARE_DATA
  1588. local heroGrid, bagIndex, fakeHuman = getHeroShareGrid(uuid, heroIndex)
  1589. if heroGrid then
  1590. if not makeHeroShare(msgRet.data, heroGrid, bagIndex, fakeHuman) then
  1591. return
  1592. end
  1593. else
  1594. local monsterID, mosnterLv = JjcLogic.getHeroShareMonster(uuid, heroIndex)
  1595. if not monsterID then return end
  1596. makeHeroShareMonster(msgRet.data, monsterID, mosnterLv)
  1597. end
  1598. Msg.send(msgRet, human.fd)
  1599. else
  1600. print("[shareData] 获取跨服数据开始 uuid = "..uuid.." heroIndex = "..heroIndex.." nChatType = "..nChatType.." nServerIndex = "..nServerIndex)
  1601. HeroMiddleLogic.HeroMiddleLogic_QueryHeroData_LW(human, uuid, heroIndex, nChatType, nServerIndex)
  1602. end
  1603. end
  1604. -- 获取英雄背包中 最大等级的英雄
  1605. function getHeroBagMaxLev(human)
  1606. local maxLv = 1
  1607. for index,heroGrid in pairs(human.db.heroBag) do
  1608. if index ~= 0 and heroGrid.lv > maxLv then
  1609. maxLv = heroGrid.lv
  1610. end
  1611. end
  1612. return maxLv
  1613. end
  1614. -- 获取英雄背包中 最大星级的英雄
  1615. function getHeroBagMaxFuNeng(human)
  1616. local maxStar = 0
  1617. for index,heroGrid in pairs(human.db.heroBag) do
  1618. if index ~= 0 and heroGrid.id then
  1619. local heroConfig = HeroExcel.hero[heroGrid.id]
  1620. if heroConfig and heroConfig.star > 10 then
  1621. local star = heroConfig.star - 10
  1622. if star > maxStar then
  1623. maxStar = star
  1624. end
  1625. if maxStar >= HERO_MAX_STAR - 10 then
  1626. return maxStar
  1627. end
  1628. end
  1629. end
  1630. end
  1631. return maxStar
  1632. end
  1633. -- 战力最高的6个英雄战力和
  1634. local function sortCombat(a, b)
  1635. return a.zhandouli > b.zhandouli
  1636. end
  1637. local HeroSortTable = {}
  1638. function getHerosZDL(human)
  1639. Util.cleanTable(HeroSortTable)
  1640. local len = 0
  1641. for index,heroGrid in pairs(human.db.heroBag) do
  1642. if index ~= 0 then
  1643. len = len + 1
  1644. HeroSortTable[len] = heroGrid
  1645. end
  1646. end
  1647. if len > 1 then
  1648. table.sort(HeroSortTable, sortCombat)
  1649. end
  1650. local zhandouli = 0
  1651. for i = 1, 6 do
  1652. local grid = HeroSortTable[i]
  1653. zhandouli = zhandouli + (grid and grid.zhandouli or 0)
  1654. end
  1655. return zhandouli
  1656. end
  1657. --
  1658. function getHeroMaxZDL(human, camp)
  1659. local zhandouli = 0
  1660. local maxGrid = nil
  1661. for index,heroGrid in pairs(human.db.heroBag) do
  1662. if index ~= 0 then
  1663. local heroConfig = heroGrid and HeroExcel.hero[heroGrid.id]
  1664. if heroConfig and ((camp or 0) == 0 or heroConfig.camp == camp)
  1665. and heroGrid.zhandouli > zhandouli then
  1666. zhandouli = heroGrid.zhandouli
  1667. maxGrid = heroGrid
  1668. end
  1669. end
  1670. end
  1671. return zhandouli, maxGrid
  1672. end
  1673. -- 武将系统红点
  1674. function isDot(human)
  1675. if human.db.lv < 9 then
  1676. return false
  1677. end
  1678. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  1679. if not combatHero then return end
  1680. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  1681. local uuid = combatHero[i]
  1682. local heroGrid = getHeroGridByUuid(human, uuid)
  1683. if heroGrid then
  1684. if isHeroDot(human, heroGrid) then
  1685. return true
  1686. end
  1687. -- if HeroBook.isDot(human) == 1 then
  1688. -- return true
  1689. -- end
  1690. end
  1691. end
  1692. end
  1693. -- 某个伙伴是否有红点
  1694. function isHeroDot(human, heroGrid)
  1695. if not heroGrid then return end
  1696. if human.db.lv < 9 then
  1697. return false
  1698. end
  1699. -- 装备
  1700. if HeroEquip.isEquipDot(human, heroGrid) then
  1701. return true
  1702. end
  1703. if FuwenLogic.isFuwenDot(human, heroGrid) then
  1704. return true
  1705. end
  1706. -- 升级/进阶
  1707. if isHeroLevelDot(human, heroGrid) and
  1708. not XingYaoGongMing.isGongMing(human,heroIndex) then
  1709. return true
  1710. end
  1711. --
  1712. if isHeroJuexingDot(human, heroGrid.bagIndex, heroGrid) then
  1713. return true
  1714. end
  1715. if BingshuLogic.isBingShuDot(human, heroGrid) then
  1716. return true
  1717. end
  1718. -- 专属武器
  1719. if HeroExclusiveWeapon.isWeaponDot(human, heroGrid) then
  1720. return true
  1721. end
  1722. -- 英雄种子
  1723. if HeroSeed.isSeedDot(human, heroGrid) then
  1724. return true
  1725. end
  1726. end
  1727. -- 升级判定
  1728. function isHeroLvDot(human, heroGrid)
  1729. if human.db.lv < 9 then
  1730. return false
  1731. end
  1732. local heroConfig = HeroExcel.hero[heroGrid.id]
  1733. if not heroConfig then return end
  1734. local lv = heroGrid and heroGrid.lv or 1
  1735. local star = heroConfig and heroConfig.star or 0
  1736. local quality = heroGrid and heroGrid.quality or 0
  1737. local maxLv = HeroGrid.getMaxLv(heroGrid.star, quality)
  1738. if lv < maxLv then -- 升级
  1739. local conf = UpNeedExcel.upLv[lv + 1]
  1740. if not conf then return end
  1741. if human.db.jinbi < conf.money then return end
  1742. if BagLogic.getItemCnt(human, ItemDefine.ITEM_GREEN_EXP_ID) < conf.soul then
  1743. return
  1744. end
  1745. return true
  1746. end
  1747. end
  1748. -- 进阶判断
  1749. function isHeroUpDot(human, heroGrid)
  1750. if human.db.lv < 9 then
  1751. return false
  1752. end
  1753. local heroConfig = HeroExcel.hero[heroGrid.id]
  1754. if not heroConfig then return end
  1755. local lv = heroGrid and heroGrid.lv or 1
  1756. local star = heroGrid and heroGrid.star or 0
  1757. local quality = heroGrid and heroGrid.quality or 0
  1758. -- 进阶
  1759. local maxQuality = HeroGrid.getMaxQuality(star)
  1760. if quality >= maxQuality then
  1761. --print("[isHeroUpDot] 当前quality 大于 总的星级 quality = "..quality.." maxQuality = "..maxQuality)
  1762. return
  1763. end
  1764. local maxLv = HeroGrid.getMaxLv(heroGrid.star, maxQuality)
  1765. if lv >= maxLv then
  1766. --print("[isHeroUpDot] 当前等级 大于 最大等级 lv = "..lv.." maxLv = "..maxLv)
  1767. return
  1768. end
  1769. local nNowMaxLv = HeroGrid.getNowQualityMaxLv(star, quality)
  1770. if lv < nNowMaxLv then
  1771. --print("[isHeroUpDot] 当前等级 还未到达可升的最大等级 lv = "..lv.." nNowMaxLv = "..nNowMaxLv)
  1772. return
  1773. end
  1774. --print("[isHeroUpDot] id = "..heroGrid.id.." lv = "..lv.." star = "
  1775. --..star.." quality = "..quality.." maxQuality = "..maxQuality.." maxLv = "..maxLv)
  1776. local conf = UpNeedExcel.upQuality[quality + 1]
  1777. if not conf then
  1778. --print("[isHeroUpDot] 不存在下一星级配置 nextquality = "..quality + 1)
  1779. return
  1780. end
  1781. if human.db.jinbi < conf.money then
  1782. --print("[isHeroUpDot] 玩家金币不足 jinbi = "..human.db.jinbi.." nNeedMoney = "..conf.money)
  1783. return
  1784. end
  1785. if BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID) < conf.jinjieshi then
  1786. --print("[isHeroUpDot] 玩家进阶道具不足 jinjieshi = "..BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID)
  1787. -- .." nNeedjinjieshi = "..conf.jinjieshi)
  1788. return
  1789. end
  1790. return true
  1791. end
  1792. -- 升级/进阶判断
  1793. function isHeroLevelDot(human, heroGrid)
  1794. if human.db.lv < 9 then
  1795. return false
  1796. end
  1797. if isHeroLvDot(human, heroGrid) then -- 升级
  1798. return true
  1799. end
  1800. if isHeroUpDot(human, heroGrid) then -- 进阶判断
  1801. return true
  1802. end
  1803. end
  1804. -- 升星/觉醒红点
  1805. function isHeroJuexingDot(human, heroIndex, heroGrid)
  1806. if human.db.lv < 9 then
  1807. return
  1808. end
  1809. local heroConfig = HeroExcel.hero[heroGrid.id]
  1810. if not heroConfig then return end
  1811. local attrConfig = HeroDefine.getAttrConfig(heroGrid.id, heroGrid.star)
  1812. if not attrConfig then return end
  1813. local nextAttrConfig = HeroDefine.getNextAttrConfig(heroGrid.id, heroGrid.star)
  1814. if not nextAttrConfig then
  1815. return sendHeroJueXingMax(human, heroGrid.id, heroIndex)
  1816. end
  1817. -- 角色等级/世界等级是否可以
  1818. local isFix = isFixUpStarLv(human, heroGrid.star+1)
  1819. if not isFix then return end
  1820. -- 判断消耗材料
  1821. local needItemCnt = attrConfig.jinjieshi
  1822. if BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID) < needItemCnt then
  1823. return
  1824. end
  1825. -- 额外材料
  1826. for i = 1, #attrConfig.needItems do
  1827. local itemID = attrConfig.needItems[i][1]
  1828. local itemCnt = attrConfig.needItems[i][2]
  1829. if BagLogic.getItemCnt(human, itemID) < itemCnt then
  1830. return
  1831. end
  1832. end
  1833. local without = {}
  1834. without[heroIndex] = true
  1835. for _, cond in ipairs(attrConfig.cond) do
  1836. local ctype = cond[1]
  1837. local needCnt = cond[3]
  1838. if not needCnt then return end
  1839. if ctype == HechengLogic.COND_TYPE_CAMPSTAR then
  1840. needCnt = cond[4]
  1841. end
  1842. for i = 1, needCnt do
  1843. local index = selectJuexingGrid(human, ctype, cond, without)
  1844. if not index then return end
  1845. without[index] = true
  1846. end
  1847. end
  1848. return true
  1849. end
  1850. -- 查找升星材料
  1851. function selectJuexingGrid(human, ctype, cond, without)
  1852. for index,heroGrid in pairs(human.db.heroBag) do
  1853. if index ~= 0 and not without[index] and
  1854. isFixJuexingCond(heroGrid, ctype, cond) then
  1855. return index
  1856. end
  1857. end
  1858. end
  1859. -- 是否满足材料需求
  1860. function isFixJuexingCond(grid, ctype, cond)
  1861. local heroConfig = HeroExcel.hero[grid.id]
  1862. if not heroConfig then return end
  1863. if ctype == HechengLogic.COND_TYPE_HEROID then
  1864. local needConfig = HeroExcel.hero[cond[2]]
  1865. if not needConfig then return end
  1866. local needStar = cond[4] or needConfig.star
  1867. if grid.id == cond[2] and needStar == grid.star then
  1868. return true
  1869. end
  1870. elseif ctype == HechengLogic.COND_TYPE_CAMPSTAR then
  1871. if cond[2] ~= 0 and cond[2] ~= heroConfig.camp then
  1872. return
  1873. end
  1874. if cond[3] ~= grid.star then
  1875. return
  1876. end
  1877. return true
  1878. end
  1879. end
  1880. function sendBagDots(human)
  1881. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  1882. local msgRet = Msg.gc.GC_HERO_BAG_DOTS
  1883. msgRet.list[0] = 0
  1884. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  1885. local uuid = combatHero and combatHero[i]
  1886. local heroGrid = getHeroGridByUuid(human, uuid)
  1887. if heroGrid then
  1888. msgRet.list[0] = msgRet.list[0] + 1
  1889. local net = msgRet.list[msgRet.list[0]]
  1890. net.bagIndex = heroGrid.bagIndex
  1891. net.isDot = isHeroDot(human, heroGrid) and 1 or 0
  1892. end
  1893. end
  1894. --Msg.trace(msgRet)
  1895. local redDotTag = HeroBook.isDot(human)
  1896. msgRet.bookDot = redDotTag or 0
  1897. Msg.send(msgRet, human.fd)
  1898. refreshDot(human)
  1899. end
  1900. function refreshDot(human, uuid)
  1901. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  1902. if not combatHero then return end
  1903. local isFind = nil
  1904. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  1905. if uuid == nil or combatHero[i] == uuid then
  1906. isFind = true
  1907. break
  1908. end
  1909. end
  1910. if not isFind then return end
  1911. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_301)
  1912. end
  1913. -- 今日英雄重置剩余次数
  1914. function getResetLeftCnt(human)
  1915. local heroResetCnt = human.db.heroResetCnt or 0
  1916. return math.max(HERO_RESET_FREECNT - heroResetCnt, 0)
  1917. end
  1918. -- 重置返还材料
  1919. local RESET_RETURN_ITEMS = {}
  1920. function getResetReturnItems(heroGrid)
  1921. Util.cleanTable(RESET_RETURN_ITEMS)
  1922. -- 升级
  1923. local lv = heroGrid.lv
  1924. if heroGrid.oldLV then
  1925. lv = heroGrid.oldLV
  1926. end
  1927. for i = 2, lv do
  1928. local upcf = UpNeedExcel.upLv[i]
  1929. if upcf then
  1930. RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] or 0) + upcf.soul
  1931. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  1932. end
  1933. end
  1934. -- 升阶
  1935. local quality = heroGrid.quality
  1936. if heroGrid.oldQuality then
  1937. quality = heroGrid.oldQuality
  1938. end
  1939. -- 升阶
  1940. for i = 1, quality do
  1941. local upcf = UpNeedExcel.upQuality[i]
  1942. if upcf then
  1943. RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] or 0) + upcf.jinjieshi
  1944. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  1945. end
  1946. end
  1947. -- 升星材料
  1948. for i = 1,heroGrid.star-1 do
  1949. local attrConfig = HeroDefine.getAttrConfig(heroGrid.id, i)
  1950. if attrConfig then
  1951. if attrConfig.jinjieshi > 0 then
  1952. RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] or 0) + attrConfig.jinjieshi
  1953. end
  1954. for j = 1,#attrConfig.needItems do
  1955. RESET_RETURN_ITEMS[attrConfig.needItems[j][1]] = (RESET_RETURN_ITEMS[attrConfig.needItems[j][1]] or 0) + attrConfig.needItems[j][2]
  1956. end
  1957. end
  1958. end
  1959. -- 护符/水晶材料
  1960. local maxCnt = 100 -- 防止死循环
  1961. local equipID = heroGrid.equip and heroGrid.equip[ItemDefine.EQUIP_SUBTYPE_SHUIJIN]
  1962. while equipID do
  1963. maxCnt = maxCnt - 1
  1964. if maxCnt < 0 then
  1965. assert()
  1966. end
  1967. local eupcf = EquipExcel.shuijingUpNeed[equipID]
  1968. if not eupcf then break end
  1969. local preEquipID = eupcf.prevID
  1970. equipID = preEquipID
  1971. if preEquipID > 0 then
  1972. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + eupcf.money
  1973. RESET_RETURN_ITEMS[ItemDefine.ITEM_SHUIJING_UPLEVEL_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_SHUIJING_UPLEVEL_ID] or 0) + eupcf.jinghua
  1974. end
  1975. end
  1976. return RESET_RETURN_ITEMS
  1977. end
  1978. function getRealResetReturnItems(heroGrid)
  1979. Util.cleanTable(RESET_RETURN_ITEMS)
  1980. -- 升级
  1981. local lv = heroGrid.lv
  1982. if heroGrid.oldLV then
  1983. lv = heroGrid.oldLV
  1984. end
  1985. for i = 2, lv do
  1986. local upcf = UpNeedExcel.upLv[i]
  1987. if upcf then
  1988. RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] or 0) + upcf.soul
  1989. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  1990. end
  1991. end
  1992. -- 升阶
  1993. local quality = heroGrid.quality
  1994. if heroGrid.oldQuality then
  1995. quality = heroGrid.oldQuality
  1996. end
  1997. -- 升阶
  1998. for i = 1, quality do
  1999. local upcf = UpNeedExcel.upQuality[i]
  2000. if upcf then
  2001. RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] or 0) + upcf.jinjieshi
  2002. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  2003. end
  2004. end
  2005. return RESET_RETURN_ITEMS
  2006. end
  2007. -- 重置花费
  2008. function getResetNeedZuanshi(lv)
  2009. if lv > 100 then
  2010. return 50
  2011. end
  2012. return 0
  2013. end
  2014. -- 重置查询
  2015. function resetHeroQuery(human, heroID, heroIndex)
  2016. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  2017. if not heroGrid then return end
  2018. if XingYaoGongMing.isGongMing(human,heroIndex,XingYaoGongMing.XYHERO_RESET) then
  2019. return
  2020. end
  2021. local heroConfig = HeroExcel.hero[heroGrid.id]
  2022. if not heroConfig then return end
  2023. if heroConfig.star > HERO_RESET_MAXSTAR then
  2024. return Broadcast.sendErr(human, Util.format(Lang.HERO_RESET_ERR_STAR, HERO_RESET_MAXSTAR + 1))
  2025. end
  2026. ObjHuman.updateDaily(human)
  2027. --[[if getResetLeftCnt(human) < 1 then
  2028. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_CNT)
  2029. end--]]
  2030. local list = getRealResetReturnItems(heroGrid)
  2031. local msgRet = Msg.gc.GC_HERO_RESET_QUERY
  2032. msgRet.heroID = heroID
  2033. msgRet.heroIndex = heroIndex
  2034. msgRet.needZuanshi = getResetNeedZuanshi(heroGrid.lv)
  2035. msgRet.maxFreeCnt = HERO_RESET_FREECNT
  2036. msgRet.leftFreeCnt = getResetLeftCnt(human)
  2037. msgRet.items[0] = 0
  2038. for itemID, itemCnt in pairs(list) do
  2039. if msgRet.items[0] >= #msgRet.items then
  2040. break
  2041. end
  2042. msgRet.items[0] = msgRet.items[0] + 1
  2043. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  2044. end
  2045. if msgRet.items[0] < 1 then
  2046. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_NONE)
  2047. end
  2048. -- Msg.trace(msgRet)
  2049. Msg.send(msgRet, human.fd)
  2050. end
  2051. -- 英雄重置
  2052. function resetHero(human, heroID, heroIndex)
  2053. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  2054. if not heroGrid then return end
  2055. if XingYaoGongMing.isGongMing(human,heroIndex,XingYaoGongMing.XYHERO_RESET) then
  2056. return
  2057. end
  2058. local heroConfig = HeroExcel.hero[heroGrid.id]
  2059. if not heroConfig then return end
  2060. if heroConfig.star > HERO_RESET_MAXSTAR then
  2061. return Broadcast.sendErr(human, Util.format(Lang.HERO_RESET_ERR_STAR, HERO_RESET_MAXSTAR + 1))
  2062. end
  2063. local list = getRealResetReturnItems(heroGrid)
  2064. if not next(list) then
  2065. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_NONE)
  2066. end
  2067. if getResetLeftCnt(human) < 1 then
  2068. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_CNT)
  2069. end
  2070. local needZuanshi = getResetNeedZuanshi(heroGrid.lv)
  2071. if not ObjHuman.checkRMB(human, needZuanshi) then
  2072. return
  2073. end
  2074. ObjHuman.decZuanshi(human, -needZuanshi, "hero_reset")
  2075. human.db.heroResetCnt = (human.db.heroResetCnt or 0) + 1
  2076. heroGrid.lv = 1
  2077. heroGrid.quality = 0
  2078. if heroGrid.equip and heroGrid.equip[ItemDefine.EQUIP_SUBTYPE_SHUIJIN] then
  2079. heroGrid.equip[ItemDefine.EQUIP_SUBTYPE_SHUIJIN] = nil
  2080. heroGrid.shuijingAttrID = nil
  2081. end
  2082. for itemID, itemCnt in pairs(list) do
  2083. BagLogic.addItem(human, itemID, itemCnt, "hero_reset")
  2084. end
  2085. HeroEquip.putOffQuick(human, heroID, heroIndex, true)
  2086. FuwenLogic.putOffQuick(human, heroID, heroIndex, true)
  2087. XingYaoGongMing.onDelHero(human,heroGrid,heroIndex)
  2088. heroGrid.fuwen = nil
  2089. if heroGrid.relic then
  2090. WinnerRelicLogic.WinnerRelic_CancelWinner(human, heroGrid, heroIndex)
  2091. heroGrid.relic = {}
  2092. end
  2093. ObjHuman.doCalcHero(human,heroIndex)
  2094. sendHeroBagDynamic(human, heroID, heroIndex)
  2095. refreshDot(human, heroGrid.uuid)
  2096. local msgRet = Msg.gc.GC_HERO_RESET
  2097. msgRet.heroID = heroID
  2098. msgRet.heroIndex = heroIndex
  2099. msgRet.items[0] = 0
  2100. for itemID, itemCnt in pairs(list) do
  2101. if msgRet.items[0] >= #msgRet.items then
  2102. break
  2103. end
  2104. if not ItemDefine.isEquip(itemID) then
  2105. msgRet.items[0] = msgRet.items[0] + 1
  2106. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  2107. end
  2108. end
  2109. msgRet.items[0] = EquipLogic.makeEquipItem(human, msgRet.items, msgRet.items[0])
  2110. Msg.send(msgRet, human.fd)
  2111. checkChangeMaxZDL(human, heroGrid)
  2112. end
  2113. -- 对所有英雄操作一次装备皮肤
  2114. function AllHeroEquipSkin(human)
  2115. if not human then
  2116. return
  2117. end
  2118. local nHeroLen = human.db.heroBag[0]
  2119. if 0 >= nHeroLen then
  2120. return
  2121. end
  2122. local tEquipSkin = {}
  2123. for i = 1, nHeroLen, 1 do
  2124. local heroGrid = human.db.heroBag[i]
  2125. if heroGrid then
  2126. local nID = heroGrid.id
  2127. -- 不存在去查表
  2128. if not tEquipSkin[nID] then
  2129. local bHaveSkin = false
  2130. local skinOn = SkinLogic.checkHeroSkinById(human, nID)
  2131. if skinOn then
  2132. heroGrid.skinOn = skinOn
  2133. bHaveSkin = true
  2134. else
  2135. skinOn = -1
  2136. end
  2137. tEquipSkin[nID] = {bHaveSkin = bHaveSkin, skinOn = skinOn}
  2138. else
  2139. if true == tEquipSkin[nID].bHaveSkin then
  2140. heroGrid.skinOn = tEquipSkin[nID].skinOn
  2141. end
  2142. end
  2143. end
  2144. end
  2145. end
  2146. -- 统计英雄背包中, 每类SSR, UR英雄的最高星级
  2147. function GetHeroMaxStarList(human)
  2148. local noCalcHeroList = {}
  2149. local maxStarList = {}
  2150. for index = 1, human.db.heroBag[0] do
  2151. local heroGrid = human.db.heroBag[index]
  2152. if heroGrid and not noCalcHeroList[heroGrid.id] then
  2153. local heroId = heroGrid.id
  2154. local heroCfg = HeroExcel.hero[heroId]
  2155. if heroCfg.grade < HeroDefine.HERO_SSR_GRADE then
  2156. noCalcHeroList[heroId] = 1
  2157. else
  2158. if not maxStarList[heroId] then
  2159. maxStarList[heroId] = {
  2160. uuid = heroGrid.uuid,
  2161. star = heroGrid.star
  2162. }
  2163. else
  2164. if heroGrid.star > maxStarList[heroId].star then
  2165. maxStarList[heroId].uuid = heroGrid.uuid
  2166. maxStarList[heroId].star = heroGrid.star
  2167. end
  2168. end
  2169. end
  2170. end
  2171. end
  2172. return maxStarList
  2173. end
  2174. -- 统计背包中符合星级条件的英雄数量
  2175. function CalcStarHeroCnt(human, starCond, excludeList)
  2176. local correctNum = 0
  2177. for index = 1, human.db.heroBag[0] do
  2178. local heroGrid = human.db.heroBag[index]
  2179. if heroGrid and heroGrid.star >= starCond and (not excludeList or not excludeList[heroGrid.uuid]) then
  2180. correctNum = correctNum + 1
  2181. end
  2182. end
  2183. return correctNum
  2184. end
  2185. -- 获取背包中同Id最高星级的英雄
  2186. function GetMaxStarHero(human, heroId)
  2187. local heroCfg = HeroExcel.hero[heroId]
  2188. if heroCfg.grade < HeroDefine.HERO_SSR_GRADE then
  2189. return
  2190. end
  2191. local posList = getHeroListById(human, heroId)
  2192. if #posList == 0 then
  2193. return
  2194. end
  2195. local herouuid
  2196. local maxStar = 0
  2197. for _, pos in ipairs(posList) do
  2198. local heroGrid = human.db.heroBag[pos]
  2199. if maxStar == 0 then
  2200. maxStar = heroGrid.star
  2201. herouuid = heroGrid.uuid
  2202. end
  2203. if heroGrid.star > maxStar then
  2204. maxStar = heroGrid.star
  2205. herouuid = heroGrid.uuid
  2206. end
  2207. end
  2208. return maxStar, herouuid
  2209. end
  2210. function heroJueXingOneClickQuery(human)
  2211. local tMsgData = Msg.gc.GC_HERO_JUEXIN_ONECLICK_QUERY
  2212. tMsgData.bOneClick = 1
  2213. local bOpen = Abs365CardLogic.IsBuyCard(human)
  2214. if 0 == bOpen then
  2215. print("[heroJueXingOneClickQuery] 未购买365卡直接返回")
  2216. tMsgData.bOneClick = 0
  2217. Msg.send(tMsgData, human.fd)
  2218. return
  2219. end
  2220. Msg.send(tMsgData, human.fd)
  2221. print("[heroJueXingOneClickQuery] 回复协议结束")
  2222. end
  2223. local function HeroLogic_CheckOneClickHero(human, tHero, tHeroInfo)
  2224. local tCheckHero = {}
  2225. local nHeroLen = tHero[0]
  2226. -- 先检测英雄
  2227. if nHeroLen % 2 ~= 0 then
  2228. print("[heroJueXingOneClickDo] 英雄长度不正确 nHeroLen = "..nHeroLen)
  2229. return false
  2230. end
  2231. -- 消耗材料检查
  2232. local nJinJieShiNum, tExtraItem = 0, {}
  2233. for i = 1, nHeroLen, 2 do
  2234. local nHeroID, nHeroIndex = tHero[i], tHero[i+1]
  2235. if not tCheckHero[nHeroID] then
  2236. tCheckHero[nHeroID] = 1
  2237. else
  2238. print("[heroJueXingOneClickDo] 存在重复的英雄ID nHeroID = "..nHeroID)
  2239. return false
  2240. end
  2241. -- 英雄是否存在
  2242. local heroGrid = getHeroGrid(human, nHeroID, nHeroIndex)
  2243. if not heroGrid then
  2244. return false
  2245. end
  2246. local attrConfig = HeroDefine.getAttrConfig(nHeroID, heroGrid.star)
  2247. if not attrConfig then
  2248. return false
  2249. end
  2250. local nextAttrConfig = HeroDefine.getNextAttrConfig(nHeroID, heroGrid.star)
  2251. if not nextAttrConfig then
  2252. return false
  2253. end
  2254. -- 判断是否达到开放等级
  2255. local isFix, upStarNeedLv, upStarNeedWorldLv = isFixUpStarLv(human, heroGrid.star+1)
  2256. if not isFix then
  2257. if upStarNeedLv and upStarNeedWorldLv and upStarNeedWorldLv > 0 then
  2258. return Broadcast.sendErr(human, Util.format(Lang.HERO_JUEXING_ERR_HEROLV, upStarNeedLv, upStarNeedWorldLv))
  2259. elseif upStarNeedLv then
  2260. return Broadcast.sendErr(human, Util.format(Lang.HERO_JUEXING_ERR_HEROLV2, upStarNeedLv))
  2261. end
  2262. return false
  2263. end
  2264. -- 累加材料
  2265. nJinJieShiNum = nJinJieShiNum + attrConfig.jinjieshi
  2266. for j = 1, #attrConfig.needItems do
  2267. local itemID = attrConfig.needItems[j][1]
  2268. local itemCnt = attrConfig.needItems[j][2]
  2269. if not tExtraItem[itemID] then
  2270. tExtraItem[itemID] = 0
  2271. end
  2272. tExtraItem[itemID] = tExtraItem[itemID] + itemCnt
  2273. end
  2274. local tData = {
  2275. nHeroID = nHeroID,
  2276. nHeroIndex = nHeroIndex,
  2277. tInputIDList = {},
  2278. tInputIndexList = {}
  2279. }
  2280. table.insert(tHeroInfo, tData)
  2281. end
  2282. return true, nJinJieShiNum, tExtraItem
  2283. end
  2284. function heroJueXingOneClickDo(human, tHeroData)
  2285. local nAllLen = tHeroData[0]
  2286. if 0 >= nAllLen then
  2287. return
  2288. end
  2289. print("[heroJueXingOneClickDo] 开始进入协议")
  2290. local tHero, tInputIDList, tInputIndexList = {}, {}, {}
  2291. local nBeginLen, nForNum, nGuiShuIndex = 1, 0, 1
  2292. tHero[0] = 0
  2293. tInputIDList[0] = 0
  2294. tInputIndexList[0] = 0
  2295. local tCheckIndex = {}
  2296. while nBeginLen < nAllLen do
  2297. if nForNum >= 200 then
  2298. print("[heroJueXingOneClickDo] 解析数据失败")
  2299. return
  2300. end
  2301. nForNum = nForNum + 1
  2302. local nHeroID, nHeroIndex = tHeroData[nBeginLen], tHeroData[nBeginLen + 1]
  2303. if not tCheckIndex[nHeroIndex] then
  2304. tCheckIndex[nHeroIndex] = true
  2305. else
  2306. print("[heroJueXingOneClickDo] 存在重复的英雄Index nHeroIndex = "..nHeroIndex)
  2307. return
  2308. end
  2309. tHero[0] = tHero[0] + 2
  2310. table.insert(tHero, nHeroID)
  2311. table.insert(tHero, nHeroIndex)
  2312. nBeginLen = nBeginLen + 2
  2313. local nIDLen = tHeroData[nBeginLen]
  2314. if not nIDLen or nBeginLen + nIDLen > nAllLen then
  2315. break
  2316. end
  2317. -- 处理消耗的HeroID
  2318. table.insert(tInputIDList, nGuiShuIndex)
  2319. table.insert(tInputIDList, nIDLen)
  2320. tInputIDList[0] = tInputIDList[0] + 2
  2321. for i = nBeginLen + 1, nBeginLen + nIDLen, 1 do
  2322. tInputIDList[0] = tInputIDList[0] + 1
  2323. table.insert(tInputIDList, tHeroData[i])
  2324. end
  2325. -- 处理消耗的HeroIndex
  2326. nBeginLen = nBeginLen + nIDLen + 1
  2327. if nBeginLen > nAllLen then
  2328. break
  2329. end
  2330. local nHeroIndexLen = tHeroData[nBeginLen]
  2331. if not nHeroIndexLen then
  2332. print("[heroJueXingOneClickDo] 不存在对应的nHeroIndexLen nBeginLen = "..nBeginLen)
  2333. return
  2334. end
  2335. table.insert(tInputIndexList, nGuiShuIndex)
  2336. table.insert(tInputIndexList, nHeroIndexLen)
  2337. tInputIndexList[0] = tInputIndexList[0] + 2
  2338. for i = nBeginLen + 1, nBeginLen + nHeroIndexLen, 1 do
  2339. local nIndex = tHeroData[i]
  2340. if not tCheckIndex[nIndex] then
  2341. tCheckIndex[nIndex] = true
  2342. else
  2343. print("[heroJueXingOneClickDo] 存在重复的英雄Index nHeroIndex = "..nIndex)
  2344. return
  2345. end
  2346. tInputIndexList[0] = tInputIndexList[0] + 1
  2347. table.insert(tInputIndexList, nIndex)
  2348. end
  2349. nBeginLen = nBeginLen + nHeroIndexLen + 1
  2350. nGuiShuIndex = nGuiShuIndex + 1
  2351. end
  2352. print("[heroJueXingOneClickDo] 解析上传数据完成")
  2353. local tHeroInfo = {}
  2354. local nHeroLen, nInputIDLen, nInputIndexLen = tHero[0], tInputIDList[0], tInputIndexList[0]
  2355. if 0 >= nHeroLen or 0 >= nInputIDLen or 0 >= nInputIndexLen then
  2356. print("[heroJueXingOneClickDo] 上传的数据长度不正确")
  2357. return
  2358. end
  2359. -- 先检测英雄
  2360. local bRet, nJinJieShiNum, tExtraItem = HeroLogic_CheckOneClickHero(human, tHero, tHeroInfo)
  2361. if false == bRet or not nJinJieShiNum or not tExtraItem then
  2362. print("[heroJueXingOneClickDo] 英雄检查不通过")
  2363. return
  2364. end
  2365. print("[heroJueXingOneClickDo] 检测英雄 完成")
  2366. -- 检查消耗材料是否足够
  2367. if not BagLogic.checkItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID, nJinJieShiNum) then
  2368. print("[heroJueXingOneClickDo] 英雄消耗材料不足 nJinJieShiNum = "..nJinJieShiNum)
  2369. return
  2370. end
  2371. print("[heroJueXingOneClickDo] 检查消耗材料是否足够 完成")
  2372. -- 检查消耗额外材料
  2373. for itemID, itemCnt in pairs(tExtraItem) do
  2374. if not BagLogic.checkItemCnt(human, itemID, itemCnt) then
  2375. print("[heroJueXingOneClickDo] 英雄消耗额外材料不足 itemID = "..itemID.." itemCnt = "..itemCnt)
  2376. return
  2377. end
  2378. end
  2379. print("[heroJueXingOneClickDo] 检查消耗额外材料 完成")
  2380. -- 统计消耗的英雄ID
  2381. local i, nLen = 1, 0
  2382. while i < nInputIDLen do
  2383. if nLen >= 100 then
  2384. print("[heroJueXingOneClickDo] 循环次数不正确,死循环返回")
  2385. return
  2386. end
  2387. nLen = nLen + 1
  2388. local nIndex = tInputIDList[i]
  2389. i = i + 1
  2390. local nHeroIDLen = tInputIDList[i]
  2391. if not tHeroInfo[nIndex] then
  2392. print("[heroJueXingOneClickDo] 英雄ID 下标 与上传的英雄信息数量不同 nIndex = "..nIndex)
  2393. return
  2394. end
  2395. local tHeroInputIDList = tHeroInfo[nIndex].tInputIDList
  2396. for j = i + 1, i + nHeroIDLen, 1 do
  2397. local nID = tInputIDList[j]
  2398. table.insert(tHeroInputIDList, nID)
  2399. end
  2400. tHeroInputIDList[0] = nHeroIDLen
  2401. i = i + nHeroIDLen + 1
  2402. end
  2403. print("[heroJueXingOneClickDo] 统计消耗的英雄ID 完成")
  2404. -- 统计消耗的英雄Index
  2405. i = 1
  2406. nLen = 0
  2407. while i < nInputIndexLen do
  2408. if nLen >= 100 then
  2409. print("[heroJueXingOneClickDo] 循环次数不正确,死循环返回")
  2410. return
  2411. end
  2412. nLen = nLen + 1
  2413. local nIndex = tInputIndexList[i]
  2414. i = i + 1
  2415. local nHeroIndexLen = tInputIndexList[i]
  2416. if not tHeroInfo[nIndex] then
  2417. print("[heroJueXingOneClickDo] 英雄下标 与上传的英雄信息数量不同 nIndex = "..nIndex)
  2418. return
  2419. end
  2420. local tHeroInputIndexList = tHeroInfo[nIndex].tInputIndexList
  2421. for j = i + 1, i + nHeroIndexLen, 1 do
  2422. local nID = tInputIndexList[j]
  2423. table.insert(tHeroInputIndexList, nID)
  2424. end
  2425. tHeroInputIndexList[0] = nHeroIndexLen
  2426. i = i + nHeroIndexLen + 1
  2427. end
  2428. print("[heroJueXingOneClickDo] 统计消耗的英雄Index 完成")
  2429. -- table.print_lua_table(tHeroInfo)
  2430. -- 检查升级数据是否有问题
  2431. for _, v in ipairs(tHeroInfo) do
  2432. local nHeroID, nHeroIndex = v.nHeroID, v.nHeroIndex
  2433. local heroGrid = getHeroGrid(human, nHeroID, nHeroIndex)
  2434. if not heroGrid then
  2435. print("[heroJueXingOneClickDo] 获取不到对应的英雄 heroGrid nHeroID = "..nHeroID.." nHeroIndex = "..nHeroIndex)
  2436. return
  2437. end
  2438. local attrConfig = HeroDefine.getAttrConfig(nHeroID, heroGrid.star)
  2439. if not attrConfig then
  2440. print("[heroJueXingOneClickDo] 获取不到对应的英雄attr属性 heroGrid nHeroID = "..nHeroID.." nHeroIndex = "..nHeroIndex)
  2441. return
  2442. end
  2443. if not HechengLogic.checkCond(human, v.tInputIDList, v.tInputIndexList, attrConfig.cond) then
  2444. return Broadcast.sendErr(human, Lang.HERO_JUEXING_CAILIAO_ERR)
  2445. end
  2446. end
  2447. print("[heroJueXingOneClickDo] 进入扣材料阶段")
  2448. -- 扣消耗
  2449. BagLogic.delItem(human, ItemDefine.ITEM_HERO_UPGRADE_ID, nJinJieShiNum, "hero_juexing")
  2450. -- 额外材料
  2451. for itemID, itemCnt in pairs(tExtraItem) do
  2452. BagLogic.delItem(human, itemID, itemCnt, "hero_juexing")
  2453. end
  2454. print("[heroJueXingOneClickDo] 开始正式合成英雄")
  2455. local tMsgData = Msg.gc.GC_HERO_JUEXING_ONECLICK_DO
  2456. tMsgData.tHeroList[0] = #tHeroInfo
  2457. for j, v in ipairs(tHeroInfo) do
  2458. -- 下面的数据已经在上面检查过了
  2459. local heroGrid = getHeroGrid(human, v.nHeroID, v.nHeroIndex)
  2460. local isFix, upStarNeedLv, upStarNeedWorldLv = isFixUpStarLv(human, heroGrid.star+1)
  2461. local nextAttrConfig = HeroDefine.getNextAttrConfig(v.nHeroID, heroGrid.star)
  2462. local attrConfig = HeroDefine.getAttrConfig(v.nHeroID, heroGrid.star)
  2463. local fenjieList = FenjieLogic.fenjie(human, FenjieLogic.FENJIE_DO_JUEXING, v.tInputIDList, v.tInputIndexList)
  2464. local tData = tMsgData.tHeroList[j]
  2465. tData.id = v.nHeroID
  2466. tData.index = v.nHeroIndex
  2467. fontJueXingHeroNet(tData.oldData, heroGrid, v.nHeroIndex, human)
  2468. -- 继承英雄等级 阶数 装备 水晶
  2469. writeLogHeroDel(human, "hero_juexing", heroGrid)
  2470. heroGrid.star = nextAttrConfig.star
  2471. onGetNewHero(human, heroGrid, "hero_juexing", v.nHeroIndex)
  2472. ObjHuman.doCalcHero(human, v.nHeroIndex)
  2473. sendHeroBagDynamic(human, heroGrid.id, v.nHeroIndex)
  2474. writeLogHeroAdd(human, "hero_juexing", heroGrid)
  2475. fontJueXingHeroNet(tData.newData, heroGrid, v.nHeroIndex, human)
  2476. local diffCnt, diffList = getSkillDiffList(attrConfig, nextAttrConfig)
  2477. diffCnt = diffCnt > #tData.skillUp and #tData.skillUp or diffCnt
  2478. tData.isAllSkillUp = (diffCnt > 1) and 1 or 0
  2479. tData.skillUp[0] = diffCnt
  2480. for k = 1, diffCnt do
  2481. makeSkillNet(tData.skillUp[k], diffList[k][2])
  2482. end
  2483. BagLogic.BagLogic_GetAllSendInfo(human, tData.itemList, fenjieList, CommonDefine.COMMON_SEND_PRIZE_TYPE_KEYVAL)
  2484. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE12, nextAttrConfig.star,heroGrid.id)
  2485. local heroConfig = HeroExcel.hero[v.nHeroID]
  2486. local newstar = nextAttrConfig.star or 0
  2487. local newcamp = heroConfig.camp or 0
  2488. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID24,1,newcamp,newstar)
  2489. if newstar == 5 then
  2490. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_11,1)
  2491. end
  2492. if newstar >= 5 then
  2493. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_13,1)
  2494. end
  2495. if newstar == 6 then
  2496. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_16,1)
  2497. JibanLogic.onCallback(human,2,newstar)
  2498. end
  2499. if newstar == 10 then
  2500. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_23,1)
  2501. end
  2502. checkChangeMaxZDL(human, heroGrid)
  2503. HeroLogLogic.finishTaskCB(human, HeroLogLogic.HERO_LOG_TYPE_8, 1, v.nHeroID, newstar)
  2504. -- 弹窗礼包相关触发
  2505. if human.db.heroLevelUpgrade < heroGrid.star then
  2506. human.db.heroLevelUpgrade = heroGrid.star
  2507. GiftLogic.trigger(human,Upgrade_HERO_EVENT,{star = heroGrid.star})
  2508. GiftLogic.trigger(human, GiftLogic.GIFT_HERO_UPGRADE_STAR_DAILY, {currentVal = heroGrid.star}, GiftLogic.GIFT_SEC_TYPE1)
  2509. end
  2510. for j in ipairs(yunYingActParam) do
  2511. yunYingActParam[j] = nil
  2512. end
  2513. yunYingActParam[1] = v.nHeroID
  2514. yunYingActParam[2] = newstar
  2515. yunYingActParam[3] = 1
  2516. YunYingLogic.onCallBack(human, "onHeroStarChange", yunYingActParam)
  2517. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_GETHERO, human.db._id, 1, newstar)
  2518. TriggerLogic.PublishEvent(TriggerDefine.HERO_YINGHUN_JINHUA, human.db._id, 1)
  2519. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_GETPOINTHERO, human.db._id, 1, newstar, v.nHeroID)
  2520. if heroConfig.grade >= HeroDefine.HERO_SSR_GRADE then
  2521. HeroPubLogic.UpdateHero(human, HeroPubLogic.HERO_OP_UPSTAR, v.nHeroID, heroGrid.uuid)
  2522. end
  2523. GodsAreaNS.UpdateHeroData(human, heroGrid.uuid, 1)
  2524. end
  2525. print("[heroJueXingOneClickDo] 正式合成英雄结束")
  2526. Msg.send(tMsgData, human.fd)
  2527. print("[heroJueXingOneClickDo] 发送协议完成")
  2528. -- HechengLogic.hechengQuery(human, 0)
  2529. end