HeroLogic.lua 72 KB

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