PGRData/Resources/Scripts/XManager/XRpgTowerManager.lua

791 lines
26 KiB
Lua
Raw Normal View History

2022-12-26 14:06:01 +05:30
--兵法蓝图玩法管理器
XRpgTowerManagerCreator = function()
local XRpgTowerManager = {}
local RpgTowerConfig = XRpgTowerConfig
local RpgTowerCharacter = require("XEntity/XRpgTower/XRpgTowerCharacter")
local RpgTowerStage = require("XEntity/XRpgTower/XRpgTowerStage")
local RpgTowerChapter = require("XEntity/XRpgTower/XRpgTowerChapter")
--[[
******************
=========
=========
=========FubenManager代理方法
=========
=========Get方法
=========XRpc方法
]]--
-- **** 玩法基础配置变量
local CurrentConfig -- 基本活动配置读取RpgConfig表
local StartTime = 0 -- 本轮结束时间
local EndTime = 0 -- 本轮开始时间
-- **** 玩法关卡管理模块变量
local CurrentChapter -- 现在的章节对象
local RStageList = {} --关卡对象列表
local HadGetDailyReward = true --是否领取了今日宝箱
-- **** 玩法角色管理模块变量
local MyTeamMember = {} -- 角色小队
local PreTeamLevel = 1 --经验变化前一个节点的队伍等级
local TeamLevel = 1 --队伍等级
local PreTeamExp = 0 --经验变化前一个节点的当前队伍等级经验
local TeamExp = 0 --当前队伍等级的经验
local ChangeExp = 0 --等级变化增加的经验值
local TeamExpNewChange = false --是否有新的经验变动
local IsActivityEnd = false -- 是否玩法已关闭(优先判断此条件)
local IsInit = false -- 是否从服务器获取消息并初始化了数据
local IsReset = false -- 是否重置了数据
local IsStageDataInit = false -- 是否已初始化过关卡信息
local IsRegisterEditBattleProxy = false -- 是否已注册出战界面代理
local UPGRADE_ITEM_ID = 60815
-- **** 玩法枚举类型
--================
--协议名称
--================
local REQUEST_NAMES = { --请求名称
CharaUpgrade = "RpgUpgradeRequest", -- 角色升星
CharaTalentActive = "RpgActivateTalentRequest", -- 角色激活天赋
CharaTalentReset = "RpgResetTalentRequest", --角色天赋重置
GetDailyReward = "RpgGetDailyRewardRequest", -- 角色重置
}
--================
--角色头像面板展示样式
--================
XRpgTowerManager.CharaItemShowType = {
Normal = 1, -- Ui有头像星数名称战力
OnlyIconAndStar = 2 -- Ui仅有头像和星数
}
--================
--怪兽模型位置
--================
XRpgTowerManager.MonsterModelPos = {
Middle = 1,
Left = 2,
Right = 3
}
--================
--主界面关卡图标枚举
--================
XRpgTowerManager.StageDifficultyData = {
[1] = {
IconPath = CS.XGame.ClientConfig:GetString("RpgTowerStageIconNormal")
},
[2] = {
IconPath = CS.XGame.ClientConfig:GetString("RpgTowerStageIconHard")
},
[3] = {
IconPath = CS.XGame.ClientConfig:GetString("RpgTowerStageIconChallenge")
}
}
--================
--玩法养成界面的3D镜头枚举
--================
XRpgTowerManager.UiCharacter_Camera = {
MAIN = 0, -- 主页面镜头
ADAPT = 1,
LEVELUP = 2, -- 升级页签镜头
NATURE = 4, -- 天赋页签镜头
CHANGEMEMBER = 5 -- 切换队员镜头
}
--================
--玩法养成界面的子页面枚举
--================
XRpgTowerManager.PARENT_PAGE = {
MAIN = 1, -- 主页面
ADAPT = 2, -- 改造页面
CHANGEMEMBER = 3, -- 切换队员
}
--================
--编队界面警告面板
--================
XRpgTowerManager.STAGE_WARNING_LEVEL = {
NoWarning = 1, --无警告
Warning = 2, --警告
Danger = 3, --危险
}
-- 相关数据模型
--[[
****
XRpgCharacter =
{
int CharacterId,
int Level,
HashSet<int> Talents
}
**** ()
NotifyRpgData =
{
int ActivityId;
List<XRpgCharacter> Characters;
}
**** ()
XRpgTowerCharacter
]]
-- ========= =========
-- =========初始化方法=========
-- ========= =========
--[[
================
================
]]
function XRpgTowerManager.Init()
CurrentChapter = RpgTowerChapter.New()
end
--[[
================
================
]]
function XRpgTowerManager.RegisterEditBattleProxy()
if IsRegisterEditBattleProxy then return end
IsRegisterEditBattleProxy = true
XUiNewRoomSingleProxy.RegisterProxy(XDataCenter.FubenManager.StageType.RpgTower,
require("XUi/XUiRpgTower/Battle/EditBattleUi/XUiRpgTowerNewRoomSingle"))
end
--[[
================
/
@param:notifyRpgData
================
]]
function XRpgTowerManager.Reset(notifyRpgData)
CurrentConfig = RpgTowerConfig.GetRpgTowerConfigById(notifyRpgData.ActivityId)
if CurrentConfig then
XRpgTowerManager.InitTeamMember()
XRpgTowerManager.SetTeam(notifyRpgData.Characters)
if IsInit then
IsReset = true
CurrentChapter:ResetStage()
end
IsInit = true
else
XLog.Error(string.format("兵法蓝图配置未成功初始化!将导致玩法不能正常运行,请检查!%s",
tostring(notifyRpgData.ActivityId)))
IsActivityEnd = true
IsReset = true
return
end
if not CurrentChapter then
CurrentChapter = RpgTowerChapter.New(notifyRpgData.ActivityId)
else
CurrentChapter:RefreshData(notifyRpgData.ActivityId)
end
CsXGameEventManager.Instance:Notify(XEventId.EVENT_RPGTOWER_RESET)
CsXGameEventManager.Instance:Notify(XEventId.EVENT_ACTIVITY_ON_RESET, XDataCenter.FubenManager.StageType.RpgTower)
end
--[[
================
()
================
]]
function XRpgTowerManager.EndActivity()
if CurrentConfig then
StartTime = XRpgTowerManager.GetStartTime()
EndTime = XRpgTowerManager.GetEndTime()
XRpgTowerManager.InitTeamMember()
end
IsActivityEnd = true
IsReset = true
CsXGameEventManager.Instance:Notify(XEventId.EVENT_RPGTOWER_RESET)
CsXGameEventManager.Instance:Notify(XEventId.EVENT_ACTIVITY_ON_RESET, XDataCenter.FubenManager.StageType.RpgTower)
end
-- ========= =========
-- =========FubenManager代理方法=========
-- ========= =========
--[[
================
================
]]
function XRpgTowerManager.InitStageInfo(checkNewUnlock)
local stageList = RpgTowerConfig.GetRStageList()
RStageList = {}
for rStageId, rStageCfg in pairs(stageList) do
RStageList[rStageId] = RpgTowerStage.New(rStageId)
end
end
--[[
================
================
]]
function XRpgTowerManager.PreFight(stage, teamId, isAssist, challengeCount,challengeId)
local preFight = {}
preFight.CardIds = {}
preFight.StageId = stage.StageId
preFight.IsHasAssist = isAssist and true or false
preFight.ChallengeCount = challengeCount or 1
preFight.RobotIds = {}
local teamData = XDataCenter.TeamManager.GetTeamData(teamId)
for i in pairs(teamData) do
preFight.CardIds[i] = teamData[i]
end
preFight.CaptainPos = XDataCenter.TeamManager.GetTeamCaptainPos(teamId)
preFight.FirstFightPos = XDataCenter.TeamManager.GetTeamFirstFightPos(teamId)
return preFight
end
--===================
--调用结算界面
--===================
function XRpgTowerManager.ShowReward(winData)
XLuaUiManager.Open("UiRpgTowerSettleWin", winData)
end
-- ========= =========
-- =========角色管理方法=========
-- ========= =========
--[[
================
================
]]
function XRpgTowerManager.InitTeamMember()
if not CurrentConfig then
XLog.Error("兵法蓝图配置未成功初始化!将导致玩法不能正常运行,请检查!")
return
end
MyTeamMember = {}
for i = 1, #CurrentConfig.CharacterIds do
local chara = RpgTowerCharacter.New(CurrentConfig.CharacterIds[i], i)
if chara then MyTeamMember[chara:GetCharacterId()] = chara end
end
end
--[[
================
@param teamInfo List<XRpgCharacters>
================
]]
function XRpgTowerManager.SetTeam(teamInfo)
for _, memberInfo in pairs(teamInfo) do
if not MyTeamMember[memberInfo.CharacterId] then
XLog.Error(string.format("兵法蓝图要刷新的成员不存在角色Id:%s",
tostring(memberInfo.CharacterId)))
XLog.Debug("本地兵法蓝图成员数据:", MyTeamMember)
return
else
MyTeamMember[memberInfo.CharacterId]:RefreshCharacterData(memberInfo)
end
end
CsXGameEventManager.Instance:Notify(XEventId.EVENT_RPGTOWER_MEMBERCHANGE)
end
-- ========= =========
-- =========玩法配置Get方法=========
-- ========= =========
--===================
--获取活动配置简表
--===================
function XRpgTowerManager.GetActivityChapters()
if not CurrentConfig then
CurrentConfig = RpgTowerConfig.GetLatestConfig()
end
local timeNow = XTime.GetServerNowTimestamp()
local isEnd = 0
local isStart = 0
isEnd = timeNow >= XRpgTowerManager.GetEndTime()
isStart = timeNow >= XRpgTowerManager.GetStartTime()
local inActivity = (not isEnd) and (isStart)
if not inActivity then return {} end
local chapters = {}
local tempChapter = {}
tempChapter.Type = XDataCenter.FubenManager.ChapterType.RpgTower
tempChapter.Id = CurrentConfig.Id
table.insert(chapters, tempChapter)
return chapters
end
--===================
--获取活动名称
--===================
function XRpgTowerManager.GetActivityName()
return CurrentConfig.ActivityName
end
--===================
--获取活动入口配图地址
--===================
function XRpgTowerManager.GetEntryTexture()
return CurrentConfig.EntryTexture
end
--[[
================
使ID获取玩法关卡对象
@param stageId:ID
================
]]
function XRpgTowerManager.GetRStageByStageId(stageId)
local rStageId = RpgTowerConfig.GetRStageIdByStageId(stageId)
return RStageList[rStageId]
end
--[[
================
================
]]
function XRpgTowerManager.GetTeam()
local team = {}
for _, member in pairs(MyTeamMember) do
team[member:GetOrder()] = member
end
return team
end
--[[
================
ID获取队员信息
================
]]
function XRpgTowerManager.GetTeamMemberByCharacterId(charaId)
if not charaId then return nil end
if not MyTeamMember[charaId] then
XLog.Error(string.format("要查找的成员数据不存在请检查角色ID%s",
tostring(charaId)))
XLog.Debug("本地兵法蓝图成员数据:", MyTeamMember)
return nil
end
return MyTeamMember[charaId]
end
--================
--检查总成员等级是否高于检查数值
--@param checkNum:检查数值
--================
function XRpgTowerManager.GetMemberTotalLevelReachNum(checkNum)
local total = 0
for _, member in pairs(MyTeamMember) do
total = total + member:GetLevel()
end
return total >= checkNum
end
--[[
================
ID
================
]]
function XRpgTowerManager.GetTeamMemberExist(charaId)
if not charaId then return false end
if not MyTeamMember[charaId] then return false end
return true
end
--[[
================
================
]]
function XRpgTowerManager.GetCharacterIsInTeam(charaId)
local teamInfos = XDataCenter.TeamManager.GetPlayerTeam(CS.XGame.Config:GetInt("TypeIdRpgTower"))
if not teamInfos or not charaId then return false end
for _, v in pairs(teamInfos.TeamData) do
if v == charaId then
return true
end
end
return false
end
--[[
================
使
================
]]
function XRpgTowerManager.GetTeamMemberTalentPointsByCharacterId(charaId)
if not MyTeamMember[charaId] then
XLog.Error(string.format("要查找的成员数据不存在请检查角色ID%s",
tostring(charaId)))
XLog.Debug("本地兵法蓝图成员数据:", MyTeamMember)
return 0
end
return MyTeamMember[charaId]:GetTalentPoints()
end
--[[
================
================
]]
function XRpgTowerManager.GetChallengeCountStr()
return CS.XTextManager.GetText("RpgTowerChallengeCountStr",
XRpgTowerManager.GetChallengeCount(),
CurrentConfig.MaxChallengeCount)
end
--[[
================
================
]]
function XRpgTowerManager.GetCanChallenge()
return true
end
--[[
================
================
]]
function XRpgTowerManager.GetChapterProgressStr()
return CurrentChapter:GetPassProgressStr()
end
--[[
================
()
@return param1:
@return param2:
================
]]
function XRpgTowerManager.GetIsEnd()
local timeNow = XTime.GetServerNowTimestamp()
local isEnd = timeNow >= XRpgTowerManager.GetEndTime()
local isStart = timeNow >= XRpgTowerManager.GetStartTime()
local inActivity = (not isEnd) and (isStart)
return IsActivityEnd or not inActivity, timeNow < XRpgTowerManager.GetStartTime()
end
--[[
================
================
]]
function XRpgTowerManager.GetStartTime()
if not CurrentConfig then
CurrentConfig = RpgTowerConfig.GetLatestConfig()
end
return XFunctionManager.GetStartTimeByTimeId(CurrentConfig.TimeId) or 0
end
--[[
================
================
]]
function XRpgTowerManager.GetEndTime()
if not CurrentConfig then
CurrentConfig = RpgTowerConfig.GetLatestConfig()
end
return XFunctionManager.GetEndTimeByTimeId(CurrentConfig.TimeId) or 0
end
--[[
================
================
]]
function XRpgTowerManager.GetCurrentChapter()
return CurrentChapter
end
--[[
================
================
]]
function XRpgTowerManager.GetHaveNewStage()
return (not CurrentChapter:GetIsClear())
end
--================
--获取是否有角色可以升级天赋
--================
function XRpgTowerManager.GetMemberCanActiveTalent()
for _, member in pairs(MyTeamMember) do
if member:CheckCanActiveTalent() then return true end
end
return false
end
--[[
================
()
================
]]
function XRpgTowerManager.GetIsReset()
return IsReset
end
--[[
================
ID(Id)
================
]]
function XRpgTowerManager.GetTalentItemId()
return CurrentConfig.TalentItemId
end
--[[
================
ID
================
]]
function XRpgTowerManager.GetLevelUpItemId()
return UPGRADE_ITEM_ID
end
--==============
--初始化数据是否重置的状态(重置数据后再次重新进入玩法时初始化)
--==============
function XRpgTowerManager.SetNewBegining()
IsReset = false
end
--================
--判断是否第一次进入玩法(本地存储纪录)
--================
function XRpgTowerManager.GetIsFirstIn()
local localData = XSaveTool.GetData("RpgTowerFirstIn" .. XPlayer.Id .. CurrentConfig.ActivityName)
if localData == nil then
XSaveTool.SaveData("RpgTowerFirstIn".. XPlayer.Id .. CurrentConfig.ActivityName, true)
return true
end
return false
end
--================
--判断是否能获取每日补给
--================
function XRpgTowerManager.GetCanReceiveSupply()
return not HadGetDailyReward
end
--================
--获取队伍等级最大值
--================
function XRpgTowerManager.GetMaxLevel()
return RpgTowerConfig.GetTeamMaxLevel()
end
--================
--获取当前等级
--================
function XRpgTowerManager.GetCurrentLevel()
return TeamLevel
end
--================
--获取当前等级配置
--================
function XRpgTowerManager.GetCurrentLevelCfg()
return RpgTowerConfig.GetTeamLevelCfgByLevel(XRpgTowerManager.GetCurrentLevel())
end
--================
--获取当前经验值字符串
--================
function XRpgTowerManager.GetCurrentExp()
return TeamExp
end
--================
--获取等级变化信息
--================
function XRpgTowerManager.GetExpChanges()
local changes = {
TeamExpNewChange = TeamExpNewChange,
PreTeamExp = PreTeamExp,
PreTeamLevel = PreTeamLevel,
TeamExp = TeamExp,
TeamLevel = TeamLevel,
ChangeExp = ChangeExp
}
TeamExpNewChange = false
return changes
end
--================
--检查是否有等级变动
--================
function XRpgTowerManager.CheckExpChange()
local result = TeamExpNewChange
return result
end
-- ========= =========
-- =========跳转方法 =========
-- ========= =========
--[[
================
================
]]
function XRpgTowerManager.JumpTo()
if XFunctionManager.DetectionFunction(XFunctionManager.FunctionName.RpgTower) then
local canGoTo, notStart = XRpgTowerManager.CheckCanGoTo()
if canGoTo then
XLuaUiManager.Open("UiRpgTowerMain")
elseif notStart then
XUiManager.TipMsg(CS.XTextManager.GetText("RpgTowerNotStart"))
else
XUiManager.TipMsg(CS.XTextManager.GetText("RpgTowerEnd"))
end
end
end
--[[
================
@return param1:(true为在活动时间内)
@return param2:(true为未开始活动)
================
]]
function XRpgTowerManager.CheckCanGoTo()
local isActivityEnd, notStart = XRpgTowerManager.GetIsEnd()
return not isActivityEnd, notStart
end
-- ========= =========
-- =========协议方法=========
-- ========= =========
--[[
================
================
]]
function XRpgTowerManager.CharaTalentActive(rTalent)
if rTalent:GetIsUnLock() then
XUiManager.TipMsg(CS.XTextManager.GetText("RpgTowerCharaTalentIsAlreadyUnlock"))
return
end
if not rTalent:CheckNeedTeamLevel() then
XUiManager.TipMsg(CS.XTextManager.GetText("RpgTowerTalentLevelNotEnough", rTalent:GetNeedTeamLevel()))
return
end
if not rTalent:GetCanUnLock() then
if not rTalent:CheckCostEnough() then
XUiManager.TipMsg(CS.XTextManager.GetText("RpgTowerTalentPointsNotEnough"))
else
XUiManager.TipMsg(CS.XTextManager.GetText("RpgTowerTalentCannotUnlock"))
end
return
end
local characterId = rTalent:GetCharacterId()
if not MyTeamMember[characterId] then
XLog.Error(string.format("要激活天赋的成员数据不存在请检查角色ID%s",
tostring(characterId)))
XLog.Debug("本地兵法蓝图成员数据:", MyTeamMember)
return
end
if MyTeamMember[characterId]:GetTalentPoints() < rTalent:GetTalentConsume() then
XUiManager.TipMsg(CS.XTextManager.GetText("RpgTowerTalentPointsNotEnough"))
return
end
XNetwork.Call(REQUEST_NAMES.CharaTalentActive, {CharacterId = characterId, TalentId = rTalent:GetId()}, function(reply)
if reply.Code ~= XCode.Success then
XUiManager.TipCode(reply.Code)
return
end
MyTeamMember[characterId]:TalentActive(rTalent, reply.TalentPoints)
CsXGameEventManager.Instance:Notify(XEventId.EVENT_RPGTOWER_MEMBERCHANGE)
end)
end
--[[
================
================
]]
function XRpgTowerManager.CharacterReset(characterId)
local tipTitle = CS.XTextManager.GetText("RpgTowerResetTalentConfirmTitle")
local content = CS.XTextManager.GetText("RpgTowerResetTalentConfirmContent")
local confirmCb = function()
if not MyTeamMember[characterId] then
XLog.Error(string.format("要激活天赋的成员数据不存在请检查角色ID%s",
tostring(characterId)))
XLog.Debug("本地兵法蓝图成员数据:", MyTeamMember)
return
end
XNetwork.Call(REQUEST_NAMES.CharaTalentReset, {CharacterId = characterId}, function(reply)
if reply.Code ~= XCode.Success then
XUiManager.TipCode(reply.Code)
return
end
MyTeamMember[characterId]:CharacterReset(reply.TalentPoints)
CsXGameEventManager.Instance:Notify(XEventId.EVENT_RPGTOWER_MEMBERCHANGE)
end)
end
CsXUiManager.Instance:Open("UiDialog", tipTitle, content, XUiManager.DialogType.Normal, nil, confirmCb)
end
--================
--请求:获取今日补给
--================
function XRpgTowerManager.ReceiveSupply()
if not XRpgTowerManager.GetCanReceiveSupply() then
XUiManager.TipMsg(CS.XTextManager.GetText("RpgTowerCantGetSupply"))
return
end
XNetwork.Call(REQUEST_NAMES.GetDailyReward, { }, function(reply)
if reply.Code ~= XCode.Success then
XUiManager.TipCode(reply.Code)
return
end
XUiManager.OpenUiObtain(reply.RewardGoodsList)
HadGetDailyReward = true
CsXGameEventManager.Instance:Notify(XEventId.EVENT_RPGTOWER_REFRESH_DAILYREWARD)
end)
end
--[[
================
================
]]
function XRpgTowerManager.RefreshData(data)
if data.ActivityId == 0 then
XRpgTowerManager.EndActivity()
elseif CurrentChapter:GetChapterId() ~= data.ActivityId then
TeamLevel = data.TeamLevel
TeamExp = data.TeamExp
HadGetDailyReward = data.HadGetDailyReward
XRpgTowerManager.Reset(data)
XRpgTowerManager.RegisterEditBattleProxy()
else
IsActivityEnd = false
TeamLevel = data.TeamLevel
TeamExp = data.TeamExp
HadGetDailyReward = data.HadGetDailyReward
XRpgTowerManager.SetTeam(data.Characters) -- List<XRpgCharacter>
XRpgTowerManager.RegisterEditBattleProxy()
end
end
--[[
================
================
]]
function XRpgTowerManager.DailyReset()
HadGetDailyReward = false
CsXGameEventManager.Instance:Notify(XEventId.EVENT_RPGTOWER_REFRESH_DAILYREWARD)
end
--================
--协议处理:刷新队伍等级
--@param data : {
-- int TeamLevel
-- int TeamExp
-- List<XRpgCharacter> Characters
-- int AddExp }
--================
function XRpgTowerManager.RefreshTeamLevelData(data)
if data.AddExp <= 0 then return end
PreTeamExp = TeamExp
PreTeamLevel = TeamLevel
TeamExp = data.TeamExp
TeamLevel = data.TeamLevel
ChangeExp = data.AddExp
TeamExpNewChange = true
XRpgTowerManager.SetTeam(data.Characters)
end
XRpgTowerManager.Init()
return XRpgTowerManager
end
-- ========= =========
-- =========XRpc方法=========
-- ========= =========
--================
--初始化活动数据
--================
XRpc.NotifyRpgData = function(data)
XDataCenter.RpgTowerManager.RefreshData(data.Data)
end
--================
--通知每日重置
--================
XRpc.NotifyRpgDailyReset = function()
XDataCenter.RpgTowerManager.DailyReset()
end
--================
--通知队伍经验变化
--@param data : {
-- int TeamLevel
-- int TeamExp
-- List<XRpgCharacter> Characters
-- int AddExp }
--================
XRpc.NotifyRpgTeamData = function(data)
XDataCenter.RpgTowerManager.RefreshTeamLevelData(data)
end