HeroLogic.lua 92 KB

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