HeroLogic.lua 72 KB

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