HeroLogic.lua 75 KB

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