HeroLogic.lua 71 KB

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