PGRData/Script/matrix/xentity/xsupersmashbros/XSmashBRankingManager.lua

113 lines
3.3 KiB
Lua
Raw Normal View History

--===========================
--超限乱斗排行榜管理器
--模块负责:吕天元
--===========================
local XSmashBRankingManager = {}
--=============
--排位列表
--XSuperSmashBrosRankPlayer
--int PlayerId
--string Name
--int Head
--int Frame
--int Level
--string Sign
--int Score
--int WinCount
--int SpendTime
--List<int> CharacterIdList
--=============
local RankingList
local MyRankInfo
local MyRank
local TotalRankMemberCount
local GetRankFlag
2024-09-01 20:49:41 +00:00
--local GetMyRankFlag
--=============
--初始化管理器
--=============
function XSmashBRankingManager.Init()
2024-09-01 20:49:41 +00:00
RankingList = {}
MyRankInfo = {}
2024-09-01 20:49:41 +00:00
MyRank = {}
TotalRankMemberCount = 0
2024-09-01 20:49:41 +00:00
GetRankFlag = {}
--GetMyRankFlag = false
end
--=============
--刷新后台推送排行榜数据
--=============
2024-09-01 20:49:41 +00:00
function XSmashBRankingManager.RefreshRankingData(career, rankData)
local data = rankData.Rank
2024-09-01 20:49:41 +00:00
RankingList[career] = data.RankPlayer
MyRankInfo[career] = {}
MyRank[career] = rankData.Ranking
TotalRankMemberCount = rankData.MemberCount
2024-09-01 20:49:41 +00:00
for ranking, info in pairs(RankingList[career] or {}) do
if info.PlayerId == XPlayer.Id then
2024-09-01 20:49:41 +00:00
MyRankInfo[career] = info
end
end
end
--=============
--获取排行榜数据
--=============
2024-09-01 20:49:41 +00:00
function XSmashBRankingManager.GetRankingList(career, cb)
if not GetRankFlag[career] then
XDataCenter.SuperSmashBrosManager.GetRankingInfo(career, function()
GetRankFlag[career] = true
XSmashBRankingManager.GetRankingList(career, cb)
end)
return
end
2024-09-01 20:49:41 +00:00
GetRankFlag[career] = false
if cb then
2024-09-01 20:49:41 +00:00
cb(RankingList[career])
end
end
--=============
--获取排行榜排位特殊图标
--=============
function XSmashBRankingManager.GetRankingSpecialIcon(ranking)
local rankIcons = XDataCenter.SuperSmashBrosManager.GetRankingIcons()
local maxNum = rankIcons and #rankIcons or 0
return maxNum > 0 and rankIcons[ranking] or nil
end
--=============
--获取自己的排位队伍第一个成员的图标
--=============
2024-09-01 20:49:41 +00:00
function XSmashBRankingManager.GetRankingCaptainIcon(career)
local charaId = MyRankInfo and MyRankInfo[career] and MyRankInfo[career].CharacterIdList and MyRankInfo[career].CharacterIdList[1].Id
local chara = XDataCenter.SuperSmashBrosManager.GetRoleById(charaId)
return chara and chara:GetBigHeadIcon()
end
--=============
--获取玩家自己的排位(缓存在本地的,之前需要先跟后端获取)
--=============
2024-09-01 20:49:41 +00:00
function XSmashBRankingManager.GetMyRank(career)
local myRank = MyRank[career] or 0
if not myRank or myRank == 0 then return 0 end
if myRank <= 100 then return myRank end
local percent = myRank / TotalRankMemberCount
local result = math.ceil(percent * 100)
return string.format("%d%s", (result > 99 and 99 or result), "%")
end
--=============
--跟后端获取玩家自己的排位
2024-09-01 20:49:41 +00:00
-- -------------------- abandon ----------------
--=============
--function XSmashBRankingManager.GetMyRankByNet(cb)
-- if not GetMyRankFlag then
-- XDataCenter.SuperSmashBrosManager.GetRankingInfo(function()
-- GetMyRankFlag = true
-- XSmashBRankingManager.GetMyRankByNet(cb)
-- end)
-- return
-- end
-- GetMyRankFlag = false
-- if cb then
-- cb(XSmashBRankingManager.GetMyRank())
-- end
--end
return XSmashBRankingManager