Files
rudder-csharp-sdk/Services/QuestsService.cs
T
2026-09-06 22:25:32 +03:00

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="QuestEffect"/>.
/// </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 questSlug, CancellationToken cancellationToken = default)
=> _client.SendAsync<ClaimQuestRequest, ClaimQuestResponse>(
"POST",
"/sdk/v1/quests/claim",
new ClaimQuestRequest { QuestSlug = questSlug },
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?.CompletedQuestSlugs ?? new List<string>();
}
}