HeroLogic.lua 92 KB

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