HeroLogic.lua 70 KB

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