> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 手動層級排行榜

> 了解如何在 PlayFab 排行榜之上建置手動分層系統，將玩家排入 Bronze、Silver、Gold、Platinum、Diamond 和 Savior 層級。

# 使用排行榜的手動層級

在本教學課程中，我們將學習如何在排行榜服務中套用一些屬性，
為玩家建立層級系統。為了理解如何根據服務屬性建立手動層級系統，
我們將從一個範例開始。假設我們有一款殺殭屍遊戲，
玩家在有限的時間內要盡可能獲得最多分數。可以採用不同的策略來獲得更多分數，
而且未受到任何傷害也能得分。

在此範例中，玩家會根據每場對戰的表現獲得經驗值。我們想要建立一個層級系統，將頂尖玩家
識別為「Saviors」等級，而其餘玩家則分布在 Bronze、Silver、Gold、Platinum 和 Diamond 等不同等級。

## 建立排行榜

第一步是建立排行榜定義，其中包含為玩家排名的主要元素。對於我們的殭屍遊戲，
我們將使用多個分數。下列範例說明如何使用 C# SDK 建立排行榜定義。

```C# theme={null}
public static async Task CreateLeaderboardDefinitionAsync(PlayFabAuthenticationContext context, string leaderboardName)
{
    PlayFabProgressionInstanceAPI leaderboardsAPI = new PlayFabProgressionInstanceAPI(context);
    CreateLeaderboardDefinitionRequest leaderboardDefinitionRequest = new CreateLeaderboardDefinitionRequest()
    {
        AuthenticationContext = context,
        Name = leaderboardName,
        SizeLimit = 10000,
        EntityType = "title_player_account",
        VersionConfiguration = new VersionConfiguration()
        {
            MaxQueryableVersions = 1,
            ResetInterval = ResetInterval.Manual,
        },
        Columns = new List<LeaderboardColumn>()
        {
            new LeaderboardColumn()
            {
                Name = "Eliminations",
                SortDirection = LeaderboardSortDirection.Descending,
            },
            new LeaderboardColumn()
            {
                Name = "SkillPoints",
                SortDirection = LeaderboardSortDirection.Descending,
            }
            new LeaderboardColumn()
            {
                Name = "Deaths",
                SortDirection = LeaderboardSortDirection.Ascending,
            }         
        }
    };

    PlayFabResult<PlayFab.LeaderboardsModels.EmptyResponse> createLbDefinitionResult = await leaderboardsAPI.CreateLeaderboardDefinitionAsync(leaderboardDefinitionRequest);
}
```

這裡我們定義了具有三個不同分數的排行榜。如需建立排行榜或平手判定運作方式的詳細資訊，
請參閱下列指南：[使用排行榜執行更多操作](/zh-TW/services/playfab/community/leaderboards/doing-more-with-leaderboards)。

## 手動分層

正確建立排行榜後，我們現在可以繼續定義要如何建立層級。首先，
我們需要定義要如何劃分玩家群體。一般而言，等級越高，
玩家就越少。基於這個概念，以下是我們定義層級的方式。

* Bronze：0 - 35% 的玩家。
* Silver：35% - 60% 的玩家。
* Gold：60% - 80% 的玩家。
* Platinum：80% - 90% 的玩家。
* Diamond：90% - 99.5% 的玩家。
* Saviors：前 0.05% 的玩家。

由於此流程是層級系統的手動方法，玩家的分布
需要以開發人員認為合適的任何方式儲存。

為了擷取資料，我們將使用下列範例：

```C# theme={null}
public static async Task<List<EntityLeaderboardEntry>> GetLeaderboard(PlayFabAuthenticationContext context, string leaderboardName)
{
    PlayFabProgressionInstanceAPI leaderboardsAPI = new PlayFabProgressionInstanceAPI(context);
    GetEntityLeaderboardRequest getLbRequest = new GetEntityLeaderboardRequest()
    {
        LeaderboardName = leaderboardName,
        StartingPosition = 1,
        PageSize = 20,
        AuthenticationContext = context,
    };

    PlayFabResult<GetEntityLeaderboardResponse> lbResponse = await leaderboardsAPI.GetLeaderboardAsync(getLbRequest);
    
    return lbResponse.Result;
}
```

此範例是我們從排行榜擷取資料的多種方式之一。在回應的 Result 屬性中，
我們會找到一個名為 `EntryCount` 的屬性，它會告訴我們排行榜目前有多少列。
此數字與 `SizeLimit` 不同，後者代表排行榜的最大列數。

若要判斷玩家的層級，我們會取得玩家在排行榜中的位置，並將其除以 `EntryCount`
屬性，以了解他們落在所定義層級中的哪個位置。

快速範例：

* 底層玩家：在 10,000 名中位於第 8500 名的玩家位於群體的 85% 內，屬於 Bronze 層級。
* 中間玩家：在 10,000 名中位於第 3500 名的玩家位於前 35% 的玩家內，屬於 Gold 層級。
* 頂尖玩家：在 10,000 名中位於第 50 名的玩家位於前 0.5% 的玩家內，成為「Savior」。

## 結論

在本教學課程中，我們學到了如何執行下列作業：

* 建立排行榜。
* 了解如何從排行榜查詢資料。
* 了解如何根據百分位數建立手動層級分布。
* 了解如何將玩家位置的結果對應至實際層級。

## 另請參閱

* [使用排行榜執行更多操作](/zh-TW/services/playfab/community/leaderboards/doing-more-with-leaderboards)。
* [建立基本排行榜](/zh-TW/services/playfab/community/leaderboards/create-basic-leaderboard)
* [群組排行榜](/zh-TW/services/playfab/community/leaderboards/group-leaderboards)。
* [限制](/zh-TW/services/playfab/community/leaderboards/limits-leaderboards)。
* [配額 ](/zh-TW/services/playfab/community/leaderboards/quota-leaderboards)。
* [依統計資料為玩家排名](/zh-TW/services/playfab/community/leaderboards/leaderboards-linked-to-stats)
* [將內容相關資料新增至排行榜](/zh-TW/services/playfab/community/leaderboards/metadata-leaderboards)
* [API 參考](/zh-TW/services/playfab/community/leaderboards/api-reference)
* [排行榜與 Cloudscript](/zh-TW/services/playfab/community/leaderboards/leaderboards-cloudscript)。
* [排行榜與 Playstream](/zh-TW/services/playfab/community/leaderboards/leaderboards-with-playstream-and-telemetry)


## Related topics

- [群組排行榜](/zh-TW/services/playfab/community/leaderboards/group-leaderboards.md)
- [排行榜配額](/zh-TW/services/playfab/community/leaderboards/quota-leaderboards.md)
- [季節性排行榜](/zh-TW/services/playfab/community/leaderboards/seasonal-leaderboards.md)
- [排行榜的限制](/zh-TW/services/playfab/community/leaderboards/limits-leaderboards.md)
- [使用 Azure Functions 的排行榜](/zh-TW/services/playfab/community/leaderboards/leaderboards-cloudscript.md)
