HeroLogic.lua 71 KB

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