ea20ea6d51
LeaderboardSession.ClaimAsync sends onClaim. Generated DTOs live under Models/ with nullable wire fields. Remove incomplete duplicate type files.
49 lines
1.9 KiB
C#
49 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using RudderSdk.Core.Models.Quests;
|
|
|
|
namespace RudderSdk.Core;
|
|
|
|
/// <summary>
|
|
/// Global quests (list + claim), distinct from scenario quest nodes which
|
|
/// advance through <see cref="QuestSession"/>.
|
|
/// </summary>
|
|
public sealed class QuestsService
|
|
{
|
|
private readonly RudderClient _client;
|
|
|
|
internal QuestsService(RudderClient client) => _client = client;
|
|
|
|
/// <summary>Lists the player's quests with per-objective progress and rewards.</summary>
|
|
public async Task<IReadOnlyList<Quest>> ListAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
var response = await _client.SendAsync<ListQuestsResponse>(
|
|
"POST",
|
|
"/sdk/v1/quests/list",
|
|
cancellationToken).ConfigureAwait(false);
|
|
|
|
return response?.Quests ?? new List<Quest>();
|
|
}
|
|
|
|
/// <summary>Claims a completed quest's rewards (idempotent server-side).</summary>
|
|
public Task<ClaimQuestResponse> ClaimAsync(string questId, CancellationToken cancellationToken = default)
|
|
=> _client.SendAsync<ClaimQuestRequest, ClaimQuestResponse>(
|
|
"POST",
|
|
"/sdk/v1/quests/claim",
|
|
new ClaimQuestRequest { QuestId = questId },
|
|
cancellationToken);
|
|
|
|
/// <summary>Reports progress for a metric and returns the ids of quests completed by this report.</summary>
|
|
public async Task<IReadOnlyList<string>> ReportProgressAsync(string metric, long amount, CancellationToken cancellationToken = default)
|
|
{
|
|
var response = await _client.SendAsync<ReportQuestProgressRequest, ReportQuestProgressResponse>(
|
|
"POST",
|
|
"/sdk/v1/quests/progress",
|
|
new ReportQuestProgressRequest { Metric = metric, Amount = amount },
|
|
cancellationToken).ConfigureAwait(false);
|
|
|
|
return response?.CompletedQuestIds ?? new List<string>();
|
|
}
|
|
}
|