Files
MinFt/Client/Assets/Scripts/DataCenter/DataCenter.LeadboardData.cs
Liubing\LB 3d8d4d18f3 first commit
先修复一下,错误的场景

删除不必要的钓场资产

修复into场景

update:更新meta文件,修复报错

update:修复资源

修复第一章节建造

修复建造第三章

update:删除多余内容

update:更新README.md

update:还原图标

update:更新README

update:更新配置
2026-04-28 02:17:22 +08:00

331 lines
11 KiB
C#

using asap.core;
using asap.playfab.async;
using cfg;
using game;
using PlayFab.ClientModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
namespace GameCore
{
public enum ELeaderboardState : byte
{
Success = 0,
Failed = 1,
Delay = 2
}
public class GetLeaderboardsRequest
{
public string playerId { get; set; }
public bool includeOther { get; set; }
public int? Score { get; set; }
}
/// <summary>
/// Leaderboard Model
/// </summary>
public class GetLeaderboardsResp
{
public ELeaderboardState state { get; set; }
/// <summary>
/// Event Id from table
/// </summary>
public int eventId { get; set; }
/// <summary>
/// Level of Leaderboard eg. T0 T1 T2
/// </summary>
public int rankLevel { get; set; }
///
/// <summary>
/// Max players of this leaderboard
/// </summary>
public int capacity { get; set; }
/// <summary>
/// Num of current member in this leaderboard (Players + Bots)
/// </summary>
//public int Count => data?.Length ?? 0;
/// <summary>
/// Avaliable Rank Datas
/// </summary>
public RankData[] data { get; set; }
}
public class UpdateScoreRequest
{
public string playerId { get; set; }
public float Score { get; set; }
}
public class UpdateScoreResp
{
public ELeaderboardState state { get; set; }
public int rank { get; set; }
public int preRank { get; set; }
public double score { get; set; }
public double preScore { get; set; }
}
public class GetRewardsRequest
{
public string playerId { get; set; }
}
public class GetRewardsResp
{
public bool success { get; set; }
public List<RewardData> rewardDatas { get; set; }
}
//public class ManualUpdateRequest
//{
// public int eventId { get; set; }
//}
public class RewardData
{
public int rankLevel { get; set; }
public int dropId { get; set; }
public int eventId { get; set; }
public RankData[] ranks { get; set; }
}
public class RankData
{
/// <summary>
/// Player PlayFab ID
/// </summary>
public string id { get; set; }
/// <summary>
/// Leaderboard ranking
/// </summary>
public int rank { get; set; }
/// <summary>
/// leaderboard score
/// </summary>
public float score { get; set; }
/// <summary>
/// Is this player myself
/// </summary>
public bool isMe { get; set; }
public bool isBot { get; set; }
public string displayName { get; set; }
public string avatarUrl { get; set; }
}
public class EventRankData
{
}
public class PFRankDataEvent
{
public bool isLocal;
}
public class LeadboardData
{
[Inject]
public IUserService userService { get; set; }
// [REMOVED] CustomServerMgr deleted
public static int LV_MODELING = 100000;
//public const string leadboardLevelName = "Level";
public const string leadboardLevelName = "LevelB";
const int RefreshSeconds = 300;
bool isRefreshing = false;
// [REMOVED] LeadboardItemData type no longer exists
// public List<LeadboardItemData> LeadboardDataList = new List<LeadboardItemData>();
// public List<LeadboardItemData> LeadboardContinentDataList = new List<LeadboardItemData>();
public List<object> LeadboardDataList = new List<object>();
public List<object> LeadboardContinentDataList = new List<object>();
public GetLeaderboardsResp curEventRank;
public RewardData eventRankReward;
public cfg.RankInit lastEventRank;
public cfg.FishingEvent fishingEvent;
public cfg.RankTargets rankTarget;
public int lastScore;
public int lastAllScore;
int MeRank = 0;
public bool IsOpenleaderboard;
public async Task SetLeadboardData(List<string> names, List<int> value)
{
List<StatisticUpdate> Statistics = new List<StatisticUpdate>();
for (int i = 0; i < names.Count; i++)
{
Statistics.Add(new StatisticUpdate() { StatisticName = names[i], Value = value[i] });
}
UpdatePlayerStatisticsRequest request = new UpdatePlayerStatisticsRequest()
{
Statistics = Statistics,
};
await PlayFabClientAsyncAPI.UpdatePlayerStatisticsAsync(request);
}
public async Task<GetLeaderboardResult> GetLeadboardData(string leaderboardNaem, int maxCount = 50)
{
GetLeaderboardRequest reques = new GetLeaderboardRequest()
{
StartPosition = 0,
MaxResultsCount = maxCount,
StatisticName = leaderboardNaem,
ProfileConstraints = new PlayerProfileViewConstraints()
{
ShowAvatarUrl = true,
ShowLocations = true,
ShowDisplayName = true,
}
};
return await PlayFabClientAsyncAPI.GetLeaderboardAsync(reques);
}
public async void SetLvData()
{
isRefreshing = true;
string localName = GContext.container.Resolve<IUserService>().ContinentCode + leadboardLevelName;
string InfiniteBuildingLevel = GContext.container.Resolve<PlayerData>().InfiniteBuildingLevel;
int.TryParse(InfiniteBuildingLevel, out int InfiniteBuildingLevelInt);
if (InfiniteBuildingLevelInt >= LV_MODELING)
{
InfiniteBuildingLevelInt = LV_MODELING - 1;
}
int maxLevel = GContext.container.Resolve<Tables>().TbMapData.DataList[^1].LevelRequired;
if (GContext.container.Resolve<PlayerData>().lv > maxLevel)
{
GContext.container.Resolve<PlayerData>().lv = maxLevel;
}
int level = GContext.container.Resolve<PlayerData>().lv * LV_MODELING + InfiniteBuildingLevelInt;
await SetLeadboardData(new List<string> { leadboardLevelName, localName }, new List<int> { level, level });
isRefreshing = false;
}
public async void AwaitSetLvData()
{
if (isRefreshing)
{
return;
}
isRefreshing = true;
await Awaiters.Seconds(RefreshSeconds);
SetLvData();
}
public async void GetLevelLeadboardData(bool islocal = false,/* bool save = false,*/ string name = leadboardLevelName)
{
if (islocal)
{
name = GContext.container.Resolve<IUserService>().ContinentCode + leadboardLevelName;
}
var result = await GetLeadboardData(name);
if (result != null)
{
// [REMOVED] LeadboardItemData type no longer exists
List<object> curList = new List<object>();
var Leaderboard = result.Leaderboard;
if (Leaderboard.Count > 0)
{
for (int i = 0; i < Leaderboard.Count; i++)
{
// LeadboardItemData item = new LeadboardItemData();
if (string.IsNullOrEmpty(Leaderboard[i].Profile.DisplayName))
{
Leaderboard[i].Profile.DisplayName = userService.GetDefaultName(Leaderboard[i].PlayFabId);
}
// item.SetData(Leaderboard[i]);
userService.SetPlayInfo(Leaderboard[i].PlayFabId, Leaderboard[i].Profile.DisplayName, Leaderboard[i].Profile.AvatarUrl);
curList.Add(Leaderboard[i]);
}
if (islocal)
{
LeadboardContinentDataList = curList;
}
else
{
LeadboardDataList = curList;
}
GContext.Publish(new PFRankDataEvent() { isLocal = islocal });
}
}
}
#region EventLeaderboard
public async Task<bool> GetLeaderboard(int Score = 0)
{
GetLeaderboardsResp getLeaderboardsResp = null;
GetLeaderboardsRequest getLeaderboardRequest = new GetLeaderboardsRequest()
{
playerId = userService.UserId,
includeOther = true,
Score = Score
};
// [REMOVED] CustomServerMgr deleted
return false;
}
public int GetMeRank()
{
return MeRank;
}
public List<ItemData> rankItemDatas { set; get; }
public static string NextQueueKey = "EventRankNextQueueKey";
public async Task GetRewards()
{
if (lastEventRank != null && rankItemDatas == null && rankTarget == null)
{
int eventId = PlayerPrefs.GetInt(NextQueueKey + userService.CustomId, 0);
if (GContext.container.Resolve<FishingEventData>().RankTargetCount.GetValueOrDefault(0) == eventId)
{
Debug.Log("Event Rank Rewards already got.");
return;
}
int dropId = 0;
GetRewardsRequest request = new GetRewardsRequest { playerId = userService.UserId };
// [REMOVED] CustomServerMgr deleted
return;
}
}
public async void UpdateScore(int score)
{
// [REMOVED] CustomServerMgr deleted
return;
}
void GetRankPlayInfo(RankData[] RankDatas)
{
Dictionary<int, cfg.Robot> robots = GContext.container.Resolve<cfg.Tables>().TbRobot.DataMap;
foreach (var item in RankDatas)
{
if (!item.isMe && !item.isBot)
{
if (!string.IsNullOrEmpty(item.avatarUrl) || !string.IsNullOrEmpty(item.displayName))
{
userService.SetPlayInfo(item.id, item.displayName, item.avatarUrl);
}
else
{
userService.GetPlayInfo(item.id);
}
}
else if (item.isBot)
{
int b = Convert.ToInt32(item.id, 16);
if (robots.TryGetValue(b, out cfg.Robot robot))
{
userService.SetPlayInfo(item.id, LocalizationMgr.GetText(robot.Name_l10n_key), robot.Avatar);
}
}
}
}
#endregion
}
}