HeroLogic.lua 72 KB

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