HeroLogic.lua 67 KB

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