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 YunYingLogic = require("yunying.YunYingLogic")
  65. local BingshuLogic = require("fuwen.BingshuLogic")
  66. local GiftLogic = require("topup.GiftLogic")
  67. local HeroMiddleLogic = require("hero.HeroMiddleLogic")
  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, nChatType, nServerIndex)
  1377. print("[shareData] 获取跨服数据开始 uuid = "..uuid.." heroIndex = "..heroIndex.." nChatType = "..nChatType.." nServerIndex = "..nServerIndex)
  1378. if -1 >= nChatType or -1 >= nServerIndex then
  1379. local msgRet = Msg.gc.GC_HERO_SHARE_DATA
  1380. local heroGrid, bagIndex, fakeHuman = getHeroShareGrid(uuid, heroIndex)
  1381. if heroGrid then
  1382. if not makeHeroShare(msgRet.data, heroGrid, bagIndex, fakeHuman) then
  1383. return
  1384. end
  1385. else
  1386. local monsterID, mosnterLv = JjcLogic.getHeroShareMonster(uuid, heroIndex)
  1387. if not monsterID then return end
  1388. makeHeroShareMonster(msgRet.data, monsterID, mosnterLv)
  1389. end
  1390. Msg.send(msgRet, human.fd)
  1391. else
  1392. print("[shareData] 获取跨服数据开始 uuid = "..uuid.." heroIndex = "..heroIndex.." nChatType = "..nChatType.." nServerIndex = "..nServerIndex)
  1393. HeroMiddleLogic.HeroMiddleLogic_QueryHeroData_LW(human, uuid, heroIndex, nChatType, nServerIndex)
  1394. end
  1395. end
  1396. -- 获取英雄背包中 最大等级的英雄
  1397. function getHeroBagMaxLev(human)
  1398. local maxLv = 1
  1399. for index,heroGrid in pairs(human.db.heroBag) do
  1400. if index ~= 0 and heroGrid.lv > maxLv then
  1401. maxLv = heroGrid.lv
  1402. end
  1403. end
  1404. return maxLv
  1405. end
  1406. -- 获取英雄背包中 最大星级的英雄
  1407. function getHeroBagMaxFuNeng(human)
  1408. local maxStar = 0
  1409. for index,heroGrid in pairs(human.db.heroBag) do
  1410. if index ~= 0 and heroGrid.id then
  1411. local heroConfig = HeroExcel.hero[heroGrid.id]
  1412. if heroConfig and heroConfig.star > 10 then
  1413. local star = heroConfig.star - 10
  1414. if star > maxStar then
  1415. maxStar = star
  1416. end
  1417. if maxStar >= HERO_MAX_STAR - 10 then
  1418. return maxStar
  1419. end
  1420. end
  1421. end
  1422. end
  1423. return maxStar
  1424. end
  1425. -- 战力最高的6个英雄战力和
  1426. local function sortCombat(a, b)
  1427. return a.zhandouli > b.zhandouli
  1428. end
  1429. local HeroSortTable = {}
  1430. function getHerosZDL(human)
  1431. Util.cleanTable(HeroSortTable)
  1432. local len = 0
  1433. for index,heroGrid in pairs(human.db.heroBag) do
  1434. if index ~= 0 then
  1435. len = len + 1
  1436. HeroSortTable[len] = heroGrid
  1437. end
  1438. end
  1439. if len > 1 then
  1440. table.sort(HeroSortTable, sortCombat)
  1441. end
  1442. local zhandouli = 0
  1443. for i = 1, 6 do
  1444. local grid = HeroSortTable[i]
  1445. zhandouli = zhandouli + (grid and grid.zhandouli or 0)
  1446. end
  1447. return zhandouli
  1448. end
  1449. --
  1450. function getHeroMaxZDL(human, camp)
  1451. local zhandouli = 0
  1452. local maxGrid = nil
  1453. for index,heroGrid in pairs(human.db.heroBag) do
  1454. if index ~= 0 then
  1455. local heroConfig = heroGrid and HeroExcel.hero[heroGrid.id]
  1456. if heroConfig and ((camp or 0) == 0 or heroConfig.camp == camp)
  1457. and heroGrid.zhandouli > zhandouli then
  1458. zhandouli = heroGrid.zhandouli
  1459. maxGrid = heroGrid
  1460. end
  1461. end
  1462. end
  1463. return zhandouli, maxGrid
  1464. end
  1465. -- 武将系统红点
  1466. function isDot(human)
  1467. if human.db.lv < 9 then
  1468. return false
  1469. end
  1470. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  1471. if not combatHero then return end
  1472. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  1473. local uuid = combatHero[i]
  1474. local heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  1475. if heroGrid then
  1476. if isHeroDot(human, heroGrid) then
  1477. return true
  1478. end
  1479. if HeroBook.isDot(human) == 1 then
  1480. return true
  1481. end
  1482. end
  1483. end
  1484. end
  1485. -- 某个伙伴是否有红点
  1486. function isHeroDot(human, heroGrid)
  1487. if not heroGrid then return end
  1488. if human.db.lv < 9 then
  1489. return false
  1490. end
  1491. -- 装备
  1492. if HeroEquip.isEquipDot(human, heroGrid) then
  1493. return true
  1494. end
  1495. if FuwenLogic.isFuwenDot(human, heroGrid) then
  1496. return true
  1497. end
  1498. -- 升级/进阶
  1499. if isHeroLevelDot(human, heroGrid) and
  1500. not XingYaoGongMing.isGongMing(human,heroIndex) then
  1501. return true
  1502. end
  1503. --
  1504. if isHeroJuexingDot(human, heroGrid.bagIndex, heroGrid) then
  1505. return true
  1506. end
  1507. if BingshuLogic.isBingShuDot(human, heroGrid) then
  1508. return
  1509. end
  1510. end
  1511. -- 升级判定
  1512. function isHeroLvDot(human, heroGrid)
  1513. if human.db.lv < 9 then
  1514. return false
  1515. end
  1516. local heroConfig = HeroExcel.hero[heroGrid.id]
  1517. if not heroConfig then return end
  1518. local lv = heroGrid and heroGrid.lv or 1
  1519. local star = heroConfig and heroConfig.star or 0
  1520. local quality = heroGrid and heroGrid.quality or 0
  1521. local maxLv = HeroGrid.getMaxLv(heroGrid.star, quality)
  1522. if lv < maxLv then -- 升级
  1523. local conf = UpNeedExcel.upLv[lv + 1]
  1524. if not conf then return end
  1525. if human.db.jinbi < conf.money then return end
  1526. if BagLogic.getItemCnt(human, ItemDefine.ITEM_GREEN_EXP_ID) < conf.soul then
  1527. return
  1528. end
  1529. return true
  1530. end
  1531. end
  1532. -- 进阶判断
  1533. function isHeroUpDot(human, heroGrid)
  1534. if human.db.lv < 9 then
  1535. return false
  1536. end
  1537. local heroConfig = HeroExcel.hero[heroGrid.id]
  1538. if not heroConfig then return end
  1539. local lv = heroGrid and heroGrid.lv or 1
  1540. local star = heroGrid and heroGrid.star or 0
  1541. local quality = heroGrid and heroGrid.quality or 0
  1542. -- 进阶
  1543. local maxQuality = HeroGrid.getMaxQuality(star)
  1544. if quality >= maxQuality then
  1545. return
  1546. end
  1547. local maxLv = HeroGrid.getMaxLv(heroGrid.star, maxQuality)
  1548. if lv < maxLv then
  1549. return
  1550. end
  1551. local conf = UpNeedExcel.upQuality[quality + 1]
  1552. if not conf then return end
  1553. if human.db.jinbi < conf.money then return end
  1554. if BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID) < conf.jinjieshi then
  1555. return
  1556. end
  1557. return true
  1558. end
  1559. -- 升级/进阶判断
  1560. function isHeroLevelDot(human, heroGrid)
  1561. if human.db.lv < 9 then
  1562. return false
  1563. end
  1564. if isHeroLvDot(human, heroGrid) then -- 升级
  1565. return true
  1566. end
  1567. if isHeroUpDot(human, heroGrid) then -- 进阶判断
  1568. return true
  1569. end
  1570. end
  1571. -- 升星/觉醒红点
  1572. function isHeroJuexingDot(human, heroIndex, heroGrid)
  1573. if human.db.lv < 9 then
  1574. return
  1575. end
  1576. local heroConfig = HeroExcel.hero[heroGrid.id]
  1577. if not heroConfig then return end
  1578. local attrConfig = HeroDefine.getAttrConfig(heroGrid.id, heroGrid.star)
  1579. if not attrConfig then return end
  1580. local nextAttrConfig = HeroDefine.getNextAttrConfig(heroGrid.id, heroGrid.star)
  1581. if not nextAttrConfig then
  1582. return sendHeroJueXingMax(human, heroGrid.id, heroIndex)
  1583. end
  1584. -- 角色等级/世界等级是否可以
  1585. local isFix = isFixUpStarLv(human, heroGrid.star+1)
  1586. if not isFix then return end
  1587. -- 判断消耗材料
  1588. local needItemCnt = attrConfig.jinjieshi
  1589. if BagLogic.getItemCnt(human, ItemDefine.ITEM_HERO_UPGRADE_ID) < needItemCnt then
  1590. return
  1591. end
  1592. -- 额外材料
  1593. for i = 1, #attrConfig.needItems do
  1594. local itemID = attrConfig.needItems[i][1]
  1595. local itemCnt = attrConfig.needItems[i][2]
  1596. if BagLogic.getItemCnt(human, itemID) < itemCnt then
  1597. return
  1598. end
  1599. end
  1600. local without = {}
  1601. without[heroIndex] = true
  1602. for _, cond in ipairs(attrConfig.cond) do
  1603. local ctype = cond[1]
  1604. local needCnt = cond[3]
  1605. if not needCnt then return end
  1606. if ctype == HechengLogic.COND_TYPE_CAMPSTAR then
  1607. needCnt = cond[4]
  1608. end
  1609. for i = 1, needCnt do
  1610. local index = selectJuexingGrid(human, ctype, cond, without)
  1611. if not index then return end
  1612. without[index] = true
  1613. end
  1614. end
  1615. return true
  1616. end
  1617. -- 查找升星材料
  1618. function selectJuexingGrid(human, ctype, cond, without)
  1619. for index,heroGrid in pairs(human.db.heroBag) do
  1620. if index ~= 0 and not without[index] and
  1621. isFixJuexingCond(heroGrid, ctype, cond) then
  1622. return index
  1623. end
  1624. end
  1625. end
  1626. -- 是否满足材料需求
  1627. function isFixJuexingCond(grid, ctype, cond)
  1628. local heroConfig = HeroExcel.hero[grid.id]
  1629. if not heroConfig then return end
  1630. if ctype == HechengLogic.COND_TYPE_HEROID then
  1631. local needConfig = HeroExcel.hero[cond[2]]
  1632. if not needConfig then return end
  1633. local needStar = cond[4] or needConfig.star
  1634. if grid.id == cond[2] and needStar == grid.star then
  1635. return true
  1636. end
  1637. elseif ctype == HechengLogic.COND_TYPE_CAMPSTAR then
  1638. if cond[2] ~= 0 and cond[2] ~= heroConfig.camp then
  1639. return
  1640. end
  1641. if cond[3] ~= grid.star then
  1642. return
  1643. end
  1644. return true
  1645. end
  1646. end
  1647. function sendBagDots(human)
  1648. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  1649. local msgRet = Msg.gc.GC_HERO_BAG_DOTS
  1650. msgRet.list[0] = 0
  1651. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  1652. local uuid = combatHero and combatHero[i]
  1653. local heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  1654. if heroGrid then
  1655. msgRet.list[0] = msgRet.list[0] + 1
  1656. local net = msgRet.list[msgRet.list[0]]
  1657. net.bagIndex = heroGrid.bagIndex
  1658. net.isDot = isHeroDot(human, heroGrid) and 1 or 0
  1659. end
  1660. end
  1661. --Msg.trace(msgRet)
  1662. msgRet.bookDot = HeroBook.isDot(human)
  1663. Msg.send(msgRet, human.fd)
  1664. refreshDot(human)
  1665. end
  1666. function refreshDot(human, uuid)
  1667. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  1668. if not combatHero then return end
  1669. local isFind = nil
  1670. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  1671. if uuid == nil or combatHero[i] == uuid then
  1672. isFind = true
  1673. break
  1674. end
  1675. end
  1676. if not isFind then return end
  1677. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_301)
  1678. end
  1679. -- 今日英雄重置剩余次数
  1680. function getResetLeftCnt(human)
  1681. local heroResetCnt = human.db.heroResetCnt or 0
  1682. return math.max(HERO_RESET_FREECNT - heroResetCnt, 0)
  1683. end
  1684. -- 重置返还材料
  1685. local RESET_RETURN_ITEMS = {}
  1686. function getResetReturnItems(heroGrid)
  1687. Util.cleanTable(RESET_RETURN_ITEMS)
  1688. -- 升级
  1689. local lv = heroGrid.lv
  1690. if heroGrid.oldLV then
  1691. lv = heroGrid.oldLV
  1692. end
  1693. for i = 2, lv do
  1694. local upcf = UpNeedExcel.upLv[i]
  1695. if upcf then
  1696. RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] or 0) + upcf.soul
  1697. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  1698. end
  1699. end
  1700. -- 升阶
  1701. local quality = heroGrid.quality
  1702. if heroGrid.oldQuality then
  1703. quality = heroGrid.oldQuality
  1704. end
  1705. -- 升阶
  1706. for i = 1, quality do
  1707. local upcf = UpNeedExcel.upQuality[i]
  1708. if upcf then
  1709. RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] or 0) + upcf.jinjieshi
  1710. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  1711. end
  1712. end
  1713. -- 升星材料
  1714. for i = 1,heroGrid.star do
  1715. local attrConfig = HeroDefine.getAttrConfig(heroGrid.id, i)
  1716. if attrConfig then
  1717. 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
  1718. for j = 1,#attrConfig.needItems do
  1719. RESET_RETURN_ITEMS[attrConfig.needItems[j][1]] = (RESET_RETURN_ITEMS[attrConfig.needItems[j][1]] or 0) + attrConfig.needItems[j][2]
  1720. end
  1721. end
  1722. end
  1723. -- 护符/水晶材料
  1724. local maxCnt = 100 -- 防止死循环
  1725. local equipID = heroGrid.equip and heroGrid.equip[ItemDefine.EQUIP_SUBTYPE_SHUIJIN]
  1726. while equipID do
  1727. maxCnt = maxCnt - 1
  1728. if maxCnt < 0 then
  1729. assert()
  1730. end
  1731. local eupcf = EquipExcel.shuijingUpNeed[equipID]
  1732. if not eupcf then break end
  1733. local preEquipID = eupcf.prevID
  1734. equipID = preEquipID
  1735. if preEquipID > 0 then
  1736. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + eupcf.money
  1737. RESET_RETURN_ITEMS[ItemDefine.ITEM_SHUIJING_UPLEVEL_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_SHUIJING_UPLEVEL_ID] or 0) + eupcf.jinghua
  1738. end
  1739. end
  1740. return RESET_RETURN_ITEMS
  1741. end
  1742. function getRealResetReturnItems(heroGrid)
  1743. Util.cleanTable(RESET_RETURN_ITEMS)
  1744. -- 升级
  1745. local lv = heroGrid.lv
  1746. if heroGrid.oldLV then
  1747. lv = heroGrid.oldLV
  1748. end
  1749. for i = 2, lv do
  1750. local upcf = UpNeedExcel.upLv[i]
  1751. if upcf then
  1752. RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_GREEN_EXP_ID] or 0) + upcf.soul
  1753. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  1754. end
  1755. end
  1756. -- 升阶
  1757. local quality = heroGrid.quality
  1758. if heroGrid.oldQuality then
  1759. quality = heroGrid.oldQuality
  1760. end
  1761. -- 升阶
  1762. for i = 1, quality do
  1763. local upcf = UpNeedExcel.upQuality[i]
  1764. if upcf then
  1765. RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_HERO_UPGRADE_ID] or 0) + upcf.jinjieshi
  1766. RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] = (RESET_RETURN_ITEMS[ItemDefine.ITEM_JINBI_ID] or 0) + upcf.money
  1767. end
  1768. end
  1769. return RESET_RETURN_ITEMS
  1770. end
  1771. -- 重置花费
  1772. function getResetNeedZuanshi(lv)
  1773. if lv > 100 then
  1774. return 50
  1775. end
  1776. return 0
  1777. end
  1778. -- 重置查询
  1779. function resetHeroQuery(human, heroID, heroIndex)
  1780. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1781. if not heroGrid then return end
  1782. if XingYaoGongMing.isGongMing(human,heroIndex,XingYaoGongMing.XYHERO_RESET) then
  1783. return
  1784. end
  1785. local heroConfig = HeroExcel.hero[heroGrid.id]
  1786. if not heroConfig then return end
  1787. if heroConfig.star > HERO_RESET_MAXSTAR then
  1788. return Broadcast.sendErr(human, Util.format(Lang.HERO_RESET_ERR_STAR, HERO_RESET_MAXSTAR + 1))
  1789. end
  1790. ObjHuman.updateDaily(human)
  1791. --[[if getResetLeftCnt(human) < 1 then
  1792. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_CNT)
  1793. end--]]
  1794. local list = getRealResetReturnItems(heroGrid)
  1795. local msgRet = Msg.gc.GC_HERO_RESET_QUERY
  1796. msgRet.heroID = heroID
  1797. msgRet.heroIndex = heroIndex
  1798. msgRet.needZuanshi = getResetNeedZuanshi(heroGrid.lv)
  1799. msgRet.maxFreeCnt = HERO_RESET_FREECNT
  1800. msgRet.leftFreeCnt = getResetLeftCnt(human)
  1801. msgRet.items[0] = 0
  1802. for itemID, itemCnt in pairs(list) do
  1803. if msgRet.items[0] >= #msgRet.items then
  1804. break
  1805. end
  1806. msgRet.items[0] = msgRet.items[0] + 1
  1807. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  1808. end
  1809. if msgRet.items[0] < 1 then
  1810. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_NONE)
  1811. end
  1812. -- Msg.trace(msgRet)
  1813. Msg.send(msgRet, human.fd)
  1814. end
  1815. -- 英雄重置
  1816. function resetHero(human, heroID, heroIndex)
  1817. local heroGrid = getHeroGrid(human, heroID, heroIndex)
  1818. if not heroGrid then return end
  1819. if XingYaoGongMing.isGongMing(human,heroIndex,XingYaoGongMing.XYHERO_RESET) then
  1820. return
  1821. end
  1822. local heroConfig = HeroExcel.hero[heroGrid.id]
  1823. if not heroConfig then return end
  1824. if heroConfig.star > HERO_RESET_MAXSTAR then
  1825. return Broadcast.sendErr(human, Util.format(Lang.HERO_RESET_ERR_STAR, HERO_RESET_MAXSTAR + 1))
  1826. end
  1827. local list = getRealResetReturnItems(heroGrid)
  1828. if not next(list) then
  1829. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_NONE)
  1830. end
  1831. if getResetLeftCnt(human) < 1 then
  1832. return Broadcast.sendErr(human, Lang.HERO_RESET_ERR_CNT)
  1833. end
  1834. local needZuanshi = getResetNeedZuanshi(heroGrid.lv)
  1835. if not ObjHuman.checkRMB(human, needZuanshi) then
  1836. return
  1837. end
  1838. ObjHuman.decZuanshi(human, -needZuanshi, "hero_reset")
  1839. human.db.heroResetCnt = (human.db.heroResetCnt or 0) + 1
  1840. heroGrid.lv = 1
  1841. heroGrid.quality = 0
  1842. if heroGrid.equip and heroGrid.equip[ItemDefine.EQUIP_SUBTYPE_SHUIJIN] then
  1843. heroGrid.equip[ItemDefine.EQUIP_SUBTYPE_SHUIJIN] = nil
  1844. heroGrid.shuijingAttrID = nil
  1845. end
  1846. for itemID, itemCnt in pairs(list) do
  1847. BagLogic.addItem(human, itemID, itemCnt, "hero_reset")
  1848. end
  1849. HeroEquip.putOffQuick(human, heroID, heroIndex, true)
  1850. FuwenLogic.putOffQuick(human, heroID, heroIndex, true)
  1851. XingYaoGongMing.onDelHero(human,heroGrid,heroIndex)
  1852. heroGrid.fuwen = nil
  1853. ObjHuman.doCalcHero(human,heroIndex)
  1854. sendHeroBagDynamic(human, heroID, heroIndex)
  1855. refreshDot(human, heroGrid.uuid)
  1856. local msgRet = Msg.gc.GC_HERO_RESET
  1857. msgRet.heroID = heroID
  1858. msgRet.heroIndex = heroIndex
  1859. msgRet.items[0] = 0
  1860. for itemID, itemCnt in pairs(list) do
  1861. if msgRet.items[0] >= #msgRet.items then
  1862. break
  1863. end
  1864. if not ItemDefine.isEquip(itemID) then
  1865. msgRet.items[0] = msgRet.items[0] + 1
  1866. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  1867. end
  1868. end
  1869. msgRet.items[0] = EquipLogic.makeEquipItem(human, msgRet.items, msgRet.items[0])
  1870. Msg.send(msgRet, human.fd)
  1871. checkChangeMaxZDL(human, heroGrid)
  1872. end
  1873. -- 对所有英雄操作一次装备皮肤
  1874. function AllHeroEquipSkin(human)
  1875. if not human then
  1876. return
  1877. end
  1878. local nHeroLen = human.db.heroBag[0]
  1879. if 0 >= nHeroLen then
  1880. return
  1881. end
  1882. local tEquipSkin = {}
  1883. for i = 1, nHeroLen, 1 do
  1884. local heroGrid = human.db.heroBag[i]
  1885. if heroGrid then
  1886. local nID = heroGrid.id
  1887. -- 不存在去查表
  1888. if not tEquipSkin[nID] then
  1889. local bHaveSkin = false
  1890. local skinOn = SkinLogic.checkHeroSkinById(human, nID)
  1891. if skinOn then
  1892. heroGrid.skinOn = skinOn
  1893. bHaveSkin = true
  1894. else
  1895. skinOn = -1
  1896. end
  1897. tEquipSkin[nID] = {bHaveSkin = bHaveSkin, skinOn = skinOn}
  1898. else
  1899. if true == tEquipSkin[nID].bHaveSkin then
  1900. heroGrid.skinOn = tEquipSkin[nID].skinOn
  1901. end
  1902. end
  1903. end
  1904. end
  1905. end