HeroLogic.lua 74 KB

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