HeroLogic.lua 75 KB

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