HeroLogic.lua 72 KB

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