HeroLogic.lua 68 KB

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