使用奖励表

本教程介绍如何创建奖励表,此奖励表将触发对可重置排行榜中某排名范围内的一组玩家执行的一组操作。

特别是,这是一种在重置排行榜时触发电子邮件、发送推送通知、授予物品栏物品虚拟货币或执行 CloudScript 函数的方法。

在本示例中,将介绍如何创建奖励表“End Tournament Prizes”,以在执行重置后根据玩家在排行榜中的排名向 5 位玩家授予虚拟货币。

要求

重要

这是高级教程。 请确保满足下面列出的所有要求,否则无法完成本教程。

  • 您必须掌握创建玩家的基本知识,因为排行榜中必须有玩家,您才能对他们执行操作。
  • 如果不熟悉 Game Manager,请先阅读 Game Manager 快速入门(因为我们需要在 Game Manager 中创建奖励表)。
  • 要使用奖励表,您必须具备可重置排行榜工作原理的一般知识。 请阅读教程使用可重置统计数据和排行榜中的排行榜。
  • 此外,还必须设置虚拟货币。 请阅读关于货币的教程,并使用以下参数设置两种货币:
    • Currency code:GO
    • Display name:Gold
    • Initial deposit:200
    • Currency code:SI
    • Display name:Silver
    • Initial deposit:1000

第 1 步 - 创建排行榜

在 Game Manager 中:

  • 转到左侧菜单中的 Leaderboards
  • 选择 New Leaderboard
  • Statistic name 字段中,添加名为 tournamentScore_manualLeaderboard
  • 使用提供的下拉菜单,将 Reset frequency 字段设置为 Manually
  • 移至 Aggregation method 字段,然后从提供的下拉菜单中选择 Maximum (always use the highest value)

Game Manager - Leaderboards - New Leaderboard

第 2 步 - 为排行榜创建奖励表

现在已经创建了排行榜,可以为其关联奖励表了。 转到:

  • 左侧菜单中的 Leaderboards
  • 选择 Prize Tables 选项卡。
  • 选择 NEW PRIZE TABLE 按钮进入 New Prize Table 视图。

Game Manager - Leaderboards - Prize Tables

New Prize Table 视图中:

  • 移至“信息”区域,然后输入新奖品表名称End Tournament Prizes
  • Leaderboard 下拉菜单中选择 tournamentScore_manual

要使此奖励表执行某些操作,需要设置排名。 要实现此目的,请执行以下操作:

  • TABLE CONTENTS 部分下选择 + ADD RANK
  • 此时将显示 Rank 表。

Game Manager - Leaderboards - New Prize Table

Rank 表中:

  • 验证 Rank from 字段的值为 1
  • 验证 To (inclusive) 字段的值为 2
  • Type 下拉菜单中,选择 Grant virtual currency
  • virtual currency code 下拉菜单中,选择 GO (Gold),金额输入 10

Game Manager - Leaderboards - Prize Table - Add Rank

接下来,添加第二个排名范围:

  • TABLE CONTENTS 部分下选择 +ADD RANK(底部 有一个“+ADD RANK”,选择它也可以)。
  • 在显示的 Rank 表中,确保 Rank from 字段的值为 3To (inclusive) 字段的值为 5
  • Virtual currency code 下拉菜单中,选择 SI (Silver),金额输入 10

Game Manager - Leaderboards - Prize Table - 添加第二个排名

第 3 步 - 使用玩家填充排行榜

现在已经创建了与排行榜和与其关联的奖励表。 下一步是使用玩家填充排行榜。

为了创建玩家,我们使用 LoginWithCustomID。 然后,使用 UpdatePlayerStatistics 将玩家填充到排行榜中。

使用 UpdatePlayerStatistics 前,必须在“API Features”中启用它。

  • 在左侧菜单中选择 Settings
  • 选择 API Features 选项卡。
  • 选中 Allow client to post player statistics
  • 然后选择屏幕底部的 SAVE API FEATURES 按钮。

Game Manager - Settings - API Features - Allow client to post player statistics

C# 代码示例

以下 C# 代码示例创建 5 个玩家,并使用 LoginWithCustomID 让他们登录。

然后,它使用 UpdatePlayerStatistics 将这 5 个玩家填充到之前创建的排行榜 (tournamentScore_manual) 中,值为:105104103102101

// Note: This is a recursive function. Invoke it initially with no parameter
public void CreatePlayerAndPopulateLeaderboard(int playerIndex = 5) {
    if (playerIndex <= 0) return;
    const string leaderboardName = "tournamentScore_manual";
    PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest {
        CustomId = playerIndex.ToString(),
        CreateAccount = true
    }, result => OnLoggedIn(result,playerIndex,leaderboardName), FailureCallback);
}

private void OnLoggedIn(LoginResult loginResult, int playerIndex, string leaderboardName) {
    Debug.Log("Player has successfully logged in with " + loginResult.PlayFabId);
    PlayFabClientAPI.UpdatePlayerStatistics(new UpdatePlayerStatisticsRequest {
        Statistics = new List<StatisticUpdate> {
            new StatisticUpdate {
                StatisticName = leaderboardName,
                Value = playerIndex + 100
            }
        }
    }, result=> OnStatisticsUpdated(result,playerIndex), FailureCallback);
}

private void OnStatisticsUpdated(UpdatePlayerStatisticsResult updateResult, int playerIndex) {
    Debug.Log("Successfully updated player statistic");
    // Recursively invoke for next player
    CreatePlayerAndPopulateLeaderboard(playerIndex - 1);
}

private void FailureCallback(PlayFabError error){
    Debug.LogWarning("Something went wrong with your API call. Here's some debug information:");
    Debug.LogError(error.GenerateErrorReport());
}

检查 C# 代码示例的结果

检查排行榜中是否填充了 5 个具有正确的值的玩家:

  • 从左侧菜单中选择 Leaderboards
  • Leaderboards 选项卡上,返回 Leaderboard 列表视图。
  • 选择 tournamentScore_manual,应有 5 个值为 105104103102101Players

Game Manager - Leaderboards - 查看排行榜 - 检查值

第 4 步 - 检查玩家的初始货币

进行检查之前:

  • 返回第 2 步中左侧菜单中的 Players
  • 转到“玩家”选项卡,找到在第 3 步中放入 tournamentScore_manualLeaderboard 的玩家。
  • 选择 Player ID,然后选择此玩家的 Virtual Currency 选项卡。
  • 记录此玩家的 GO (Gold) 和 SI (Silver) 货币的值。

进行检查之前,返回第 2 步中的测试 Players

  • 转到 Players,找到在第 3 步中放入 tournamentScore_manual Leaderboard 的一个玩家。
  • 选择 Player ID,然后选择此玩家的 Virtual Currency 选项卡。
  • 记录此玩家的 GO (Gold) 和 SI (Silver) 货币的值。
  • 接下来,对在第 3 步中放入 tournamentScore_manual Leaderboard 的 5 个玩家中的其余 4 个进行此操作。
  • 请务必记录他们的 GO (Gold) 和 SI (Silver) 货币的值(这些值对于在重置后确认奖励表有效非常重要)。

Game Manager - Players - Virtual Currency - 检查值

第 5 步 - 重置排行榜以授予奖励

现在,转到 Leaderboards

  • 返回 Leaderboards 列表视图。

  • 选择 tournamentScore_manual

  • 记下 PlayersLeaderboard 上的位置(位置从 0 开始索引,因此第 0 位为第一名)。

  • 选择 RESET NOW 按钮。

  • 选择 RESET 按钮确认重置 Leaderboard

  • 这将清除 Players 列表。

Game Manager - Leaderboards - 检查玩家位置

  • 在屏幕顶部,选择 RESET NOW 按钮。
  • 当提示 Reset this Leaderboard now? 时,选择 RESET 按钮确认重置。
  • 这将清除 Players 列表。

Game Manager - 重置排行榜

第 6 步 - 测试奖励表是否有效

要查看奖励表是否有效,可以检查排行榜中的玩家是否获得了正确的货币金额。 这可以在玩家的 PlayStream Debugger 中快速查看。

在 PlayStream Debugger 中查看货币金额:

  • 从左侧菜单中选择 Players
  • PlayStream 选项卡将显示 PlayerLeaderboard 事件的排名,后跟 Virtual Currency 更新。

Game Manager - Players - PlayStream Debugger - 检查排行榜事件

接下来,手动检查玩家是否收到了正确的货币:

  • 从左侧菜单中选择 Players
  • Players 选项卡上,移至屏幕的 Virtual Currency 区域。
  • 验证是否已正确授予货币。
  • 这应该比之前记录的金额多一个
  • 请注意,排行榜位置 01玩家获得了 10 枚金币,但未获得银币奖励
  • 同时,位置 234玩家获得了 10 枚银币,但未获得金币
  • 这与为奖励表设置的操作相匹配。

Game Manager - Player1 - 检查虚拟货币金额

Game Manager - Player2 - 检查虚拟货币金额

另一种检查是否已正确授予虚拟货币的方法是:

  • 转到 Players
  • 查看 Event History
  • 这将显示一个 player_virtual_currency_balance_changed 事件,其中包含有关金额因授予虚拟货币而发生更改的特定详细信息。

Game Manager - Players - Event History Chart - 检查虚拟货币更改