HeroLogic.lua 75 KB

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