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