HeroLogic.lua 71 KB

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