HeroLogic.lua 68 KB

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