|
|
@@ -0,0 +1,357 @@
|
|
|
+-- 天元系统
|
|
|
+
|
|
|
+local Lang = require("common.Lang")
|
|
|
+local Msg = require("core.Msg")
|
|
|
+local BagLogic = require("bag.BagLogic")
|
|
|
+local HeroLogic = require("hero.HeroLogic")
|
|
|
+local ObjHuman = require("core.ObjHuman")
|
|
|
+local Grid = require("bag.Grid")
|
|
|
+local RoleAttr = require("role.RoleAttr")
|
|
|
+local HeroTianYuanCfg = require("excel.heroTianYuan")
|
|
|
+local Broadcast = require("broadcast.Broadcast")
|
|
|
+local RoleDefine = require("role.RoleDefine")
|
|
|
+
|
|
|
+
|
|
|
+local LOGTAG = "HeroTianYuan" --日志标识
|
|
|
+
|
|
|
+
|
|
|
+local function initData(heroGrid)
|
|
|
+ heroGrid.tianYuanData = {
|
|
|
+ pointIdx = 0,
|
|
|
+ stage = 0,
|
|
|
+ }
|
|
|
+end
|
|
|
+
|
|
|
+local function updateData(heroGrid, newPointIdx, newStage)
|
|
|
+ if not heroGrid.tianYuanData then
|
|
|
+ initData(heroGrid)
|
|
|
+ end
|
|
|
+
|
|
|
+ if newPointIdx then
|
|
|
+ heroGrid.tianYuanData.pointIdx = newPointIdx
|
|
|
+ end
|
|
|
+
|
|
|
+ if newStage then
|
|
|
+ heroGrid.tianYuanData.stage = newStage
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+-- 系统开启条件检查
|
|
|
+local function openCheck(human, heroID, heroIndex)
|
|
|
+ local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
|
|
|
+ if not heroGrid then
|
|
|
+ return Broadcast.sendErr(human, Lang.FUWEN_HERO_GRID_ERR)
|
|
|
+ end
|
|
|
+
|
|
|
+ local varCfg = HeroTianYuanCfg.var[1]
|
|
|
+ if heroGrid.star < varCfg.unLockCondStar then
|
|
|
+ return Broadcast.sendErr(human, Lang.HEROPUB_STAR_NOT_ENOUGH)
|
|
|
+ end
|
|
|
+
|
|
|
+ return true
|
|
|
+end
|
|
|
+
|
|
|
+-- 获取正确的消耗道具信息
|
|
|
+local function getTargetItem(nowStage, nowPointIdx, maxStage)
|
|
|
+ local varCfg = HeroTianYuanCfg.var[1]
|
|
|
+ local targetStageCfgIdx = nowStage
|
|
|
+
|
|
|
+ local item
|
|
|
+ if nowPointIdx < varCfg.pointMaxNum then
|
|
|
+ if targetStageCfgIdx <= 0 then
|
|
|
+ targetStageCfgIdx = 1
|
|
|
+ end
|
|
|
+
|
|
|
+ item = HeroTianYuanCfg.upGrade[targetStageCfgIdx].pointCost[1]
|
|
|
+ else
|
|
|
+ targetStageCfgIdx = math.min((targetStageCfgIdx+1), maxStage)
|
|
|
+
|
|
|
+ item = HeroTianYuanCfg.upGrade[targetStageCfgIdx].stageCost[1]
|
|
|
+ end
|
|
|
+
|
|
|
+ return item
|
|
|
+end
|
|
|
+
|
|
|
+local function transformData(targetList, sourceArr, mul)
|
|
|
+ mul = mul or 1
|
|
|
+ for _, tb in ipairs(sourceArr) do
|
|
|
+ local id = tb[1]
|
|
|
+ local val = tb[2]
|
|
|
+ targetList[id] = (targetList[id] or 0) + val * mul
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+-- 统计数据, dataType: 1-加成属性, 2-消耗道具
|
|
|
+local function calcData(nowStage, nowPointIdx, dataType)
|
|
|
+ if nowStage <= 0 and nowPointIdx <= 0 then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local dataList = {}
|
|
|
+ local maxPointNum = HeroTianYuanCfg.var[1].pointMaxNum
|
|
|
+
|
|
|
+ for i = 1, nowStage do
|
|
|
+ local cfg = HeroTianYuanCfg.upGrade[i]
|
|
|
+ local sourceData = cfg.pointCost
|
|
|
+
|
|
|
+ -- 天元点
|
|
|
+ local pointNum = 0
|
|
|
+ if i == nowStage and nowPointIdx > 0 then
|
|
|
+ pointNum = nowPointIdx
|
|
|
+ elseif i ~= nowStage then
|
|
|
+ pointNum = maxPointNum
|
|
|
+ end
|
|
|
+
|
|
|
+ if pointNum > 0 then
|
|
|
+ if dataType == 1 then
|
|
|
+ sourceData = cfg.pointAttrs
|
|
|
+ end
|
|
|
+ transformData(dataList, sourceData, pointNum)
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 天元突破
|
|
|
+ sourceData = cfg.stageCost
|
|
|
+ if dataType == 1 then
|
|
|
+ sourceData = cfg.stageAttrs
|
|
|
+ end
|
|
|
+ transformData(dataList, sourceData)
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 0 ~ 1重的天元点
|
|
|
+ local pointNum = nowPointIdx
|
|
|
+ if nowStage >= 1 then
|
|
|
+ pointNum = maxPointNum
|
|
|
+ end
|
|
|
+
|
|
|
+ local stageOneCfg = HeroTianYuanCfg.upGrade[1]
|
|
|
+ local sourceData = stageOneCfg.pointCost
|
|
|
+ if dataType == 1 then
|
|
|
+ sourceData = stageOneCfg.pointAttrs
|
|
|
+ end
|
|
|
+ transformData(dataList, sourceData, pointNum)
|
|
|
+
|
|
|
+ return dataList
|
|
|
+end
|
|
|
+
|
|
|
+-- 更新战力
|
|
|
+local function updatePower(human, heroID, heroIndex)
|
|
|
+ RoleAttr.cleanHeroAttrCache(human)
|
|
|
+ RoleAttr.doCalc(human)
|
|
|
+ HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
|
|
|
+ ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI)
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+-- 英雄天元红点检测
|
|
|
+function isTianYuanDot(human, heroGrid)
|
|
|
+ local varCfg = HeroTianYuanCfg.var[1]
|
|
|
+ if heroGrid.star < varCfg.unLockCondStar then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ local tianYuanData = heroGrid.tianYuanData
|
|
|
+ local nowPointIdx = tianYuanData and tianYuanData.pointIdx or 0
|
|
|
+ local nowStage = tianYuanData and tianYuanData.stage or 0
|
|
|
+ local maxStage = #HeroTianYuanCfg.upGrade
|
|
|
+
|
|
|
+ if nowStage >= maxStage and nowPointIdx >= varCfg.pointMaxNum then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ local item = getTargetItem(nowStage, nowPointIdx, maxStage)
|
|
|
+ if BagLogic.getItemCnt(human, item[1]) < item[2] then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ return true
|
|
|
+end
|
|
|
+
|
|
|
+-- 计算返还材料
|
|
|
+function CalcReturnItem(human, heroGrid)
|
|
|
+ if not heroGrid or not heroGrid.tianYuanData then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local nowStage = heroGrid.tianYuanData.stage or 0
|
|
|
+ local nowPointIdx = heroGrid.tianYuanData.pointIdx or 0
|
|
|
+ local itemList = calcData(nowStage, nowPointIdx, 2)
|
|
|
+
|
|
|
+ return itemList
|
|
|
+end
|
|
|
+
|
|
|
+-- 重置英雄天元数据
|
|
|
+function ResetTianYuanData(human, heroGrid)
|
|
|
+ if not heroGrid or not heroGrid.tianYuanData then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ heroGrid.tianYuanData = nil
|
|
|
+end
|
|
|
+
|
|
|
+-- 英雄天元加成
|
|
|
+function doCalcHero(human, heroGrid, tatgetAttrs)
|
|
|
+ if not heroGrid or not heroGrid.tianYuanData then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local nowStage = heroGrid.tianYuanData.stage or 0
|
|
|
+ local nowPointIdx = heroGrid.tianYuanData.pointIdx or 0
|
|
|
+ local sourceAttrs = calcData(nowStage, nowPointIdx, 1)
|
|
|
+
|
|
|
+ for attrId, attrVal in pairs(sourceAttrs or {}) do
|
|
|
+ RoleAttr.updateValue(attrId, attrVal, tatgetAttrs)
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+-- 查询英雄天元信息
|
|
|
+function HeroTianYuan_Query(human, heroID, heroIndex)
|
|
|
+ local res = openCheck(human, heroID, heroIndex)
|
|
|
+ if res ~= true then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+ local upGradeCfg = HeroTianYuanCfg.upGrade
|
|
|
+ local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
|
|
|
+ local tianYuanData = heroGrid.tianYuanData
|
|
|
+ local nowPointIdx = tianYuanData and tianYuanData.pointIdx or 0
|
|
|
+ local nowStage = tianYuanData and tianYuanData.stage or 0
|
|
|
+
|
|
|
+ local msgRet = Msg.gc.GC_HEROTY_QUERY
|
|
|
+ msgRet.pointIdx = nowPointIdx
|
|
|
+ msgRet.stageIdx = nowStage
|
|
|
+ msgRet.stageMax = #upGradeCfg
|
|
|
+
|
|
|
+
|
|
|
+ -- 消耗
|
|
|
+ local itemTb = getTargetItem(nowStage, nowPointIdx, msgRet.stageMax)
|
|
|
+ local itemId, itemCnt = itemTb[1], itemTb[2]
|
|
|
+ if nowStage >= msgRet.stageMax then
|
|
|
+ itemCnt = 0
|
|
|
+ end
|
|
|
+ Grid.makeItem(msgRet.cost, itemId, itemCnt)
|
|
|
+
|
|
|
+
|
|
|
+ -- 总加成属性
|
|
|
+ msgRet.attrs[0] = 0
|
|
|
+ local attrs = calcData(nowStage, nowPointIdx, 1)
|
|
|
+ if attrs then
|
|
|
+ local len = 0
|
|
|
+ for attrId, attrVal in pairs(attrs) do
|
|
|
+ len = len + 1
|
|
|
+ msgRet.attrs[0] = len
|
|
|
+ msgRet.attrs[len].key = attrId
|
|
|
+ msgRet.attrs[len].value = attrVal
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ Msg.send(msgRet, human.fd)
|
|
|
+end
|
|
|
+
|
|
|
+-- 请求点亮天元点
|
|
|
+function HeroTianYuan_PointUpGrade(human, heroID, heroIndex)
|
|
|
+ local res = openCheck(human, heroID, heroIndex)
|
|
|
+ if res ~= true then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
|
|
|
+ local varCfg = HeroTianYuanCfg.var[1]
|
|
|
+
|
|
|
+ local tianYuanData = heroGrid.tianYuanData
|
|
|
+ local nowPointIdx = tianYuanData and tianYuanData.pointIdx or 0
|
|
|
+ local nowStage = tianYuanData and tianYuanData.stage or 0
|
|
|
+
|
|
|
+ if nowPointIdx >= varCfg.pointMaxNum then
|
|
|
+ return Broadcast.sendErr(human, Lang.HERO_TY_POINT_MAX)
|
|
|
+ end
|
|
|
+
|
|
|
+ local targetCfgIdx = nowStage
|
|
|
+ if targetCfgIdx <= 0 then
|
|
|
+ targetCfgIdx = 1
|
|
|
+ end
|
|
|
+
|
|
|
+ local targetStageCfg = HeroTianYuanCfg.upGrade[targetCfgIdx]
|
|
|
+ if not targetStageCfg then
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 消耗检查
|
|
|
+ local itemTb = targetStageCfg.pointCost
|
|
|
+ local itemId, itemCnt = itemTb[1][1], itemTb[1][2]
|
|
|
+ if BagLogic.getItemCnt(human, itemId) < itemCnt then
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_ITEM_NOT_ENOUGH)
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 扣除消耗
|
|
|
+ BagLogic.delItem(human, itemId, itemCnt, LOGTAG)
|
|
|
+
|
|
|
+ -- 更新点亮天元点索引
|
|
|
+ nowPointIdx = nowPointIdx + 1
|
|
|
+ updateData(heroGrid, nowPointIdx)
|
|
|
+
|
|
|
+ -- 推送最新数据给客户端
|
|
|
+ HeroTianYuan_Query(human, heroID, heroIndex)
|
|
|
+
|
|
|
+ -- 更新战力
|
|
|
+ updatePower(human, heroID, heroIndex)
|
|
|
+
|
|
|
+ -- 刷新红点
|
|
|
+ HeroLogic.refreshDot(human, heroGrid.uuid)
|
|
|
+end
|
|
|
+
|
|
|
+-- 请求天元突破
|
|
|
+function HeroTianYuan_StageUpGrade(human, heroID, heroIndex)
|
|
|
+ local res = openCheck(human, heroID, heroIndex)
|
|
|
+ if res ~= true then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
|
|
|
+ local varCfg = HeroTianYuanCfg.var[1]
|
|
|
+
|
|
|
+ local tianYuanData = heroGrid.tianYuanData
|
|
|
+ local nowPointIdx = tianYuanData and tianYuanData.pointIdx or 0
|
|
|
+ local nowStage = tianYuanData and tianYuanData.stage or 0
|
|
|
+
|
|
|
+ if nowPointIdx < varCfg.pointMaxNum then
|
|
|
+ return Broadcast.sendErr(human, Lang.HERO_TY_POINT_NOT_ENOUGH)
|
|
|
+ end
|
|
|
+
|
|
|
+ if nowStage >= #HeroTianYuanCfg.upGrade then
|
|
|
+ return Broadcast.sendErr(human, Lang.HERO_TY_STAGE_MAX)
|
|
|
+ end
|
|
|
+
|
|
|
+ local nextStage = nowStage + 1
|
|
|
+ local nextStageCfg = HeroTianYuanCfg.upGrade[nextStage]
|
|
|
+ if not nextStageCfg then
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 消耗检查
|
|
|
+ local itemTb = nextStageCfg.stageCost
|
|
|
+ local itemId, itemCnt = itemTb[1][1], itemTb[1][2]
|
|
|
+ if BagLogic.getItemCnt(human, itemId) < itemCnt then
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_ITEM_NOT_ENOUGH)
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 扣除消耗
|
|
|
+ BagLogic.delItem(human, itemId, itemCnt, LOGTAG)
|
|
|
+
|
|
|
+ -- 更新天元点索引, 天元重数
|
|
|
+ updateData(heroGrid, 0, nextStage)
|
|
|
+
|
|
|
+ -- 推送最新数据给客户端
|
|
|
+ HeroTianYuan_Query(human, heroID, heroIndex)
|
|
|
+
|
|
|
+ -- 更新战力
|
|
|
+ updatePower(human, heroID, heroIndex)
|
|
|
+
|
|
|
+ -- 刷新红点
|
|
|
+ HeroLogic.refreshDot(human, heroGrid.uuid)
|
|
|
+end
|