0.3.0: UGC removed, battlepass context-carrying API, scenario behavior aligned with web SDK, CI publish
This commit is contained in:
@@ -1,12 +1,24 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using RudderSdk.Core.Models.BattlePass;
|
||||
|
||||
namespace RudderSdk.Core;
|
||||
|
||||
/// <summary>Session of a scenario battle-pass node.</summary>
|
||||
/// <summary>
|
||||
/// Session of a scenario battle-pass node. Exposes the battle pass operations
|
||||
/// bound to this node's scenario/node/run ids, plus explicit boundary crossings
|
||||
/// the game drives from its UI; the server validates each crossing.
|
||||
/// </summary>
|
||||
public sealed class BattlePassSession
|
||||
{
|
||||
internal BattlePassSession(ScenarioNodeContext context) => Context = context;
|
||||
private readonly BattlePassService _battlePass;
|
||||
|
||||
internal BattlePassSession(ScenarioNodeContext context, BattlePassService battlePass)
|
||||
{
|
||||
Context = context;
|
||||
_battlePass = battlePass;
|
||||
}
|
||||
|
||||
/// <summary>Underlying node context.</summary>
|
||||
public ScenarioNodeContext Context { get; }
|
||||
@@ -17,6 +29,52 @@ public sealed class BattlePassSession
|
||||
/// <summary>Reads a typed value from the node data.</summary>
|
||||
public T Get<T>(string key, T defaultValue = default!) => Context.Get(key, defaultValue);
|
||||
|
||||
/// <summary>Reads current progress (xp, level, premium ownership, claimed tiers) for this node.</summary>
|
||||
public Task<GetBattlePassProgressResponse> GetProgressAsync(CancellationToken cancellationToken = default)
|
||||
=> _battlePass.GetProgressAsync(Context.ScenarioId, Context.NodeId, cancellationToken);
|
||||
|
||||
/// <summary>Credits xp from a configured source.</summary>
|
||||
public Task<AddBattlePassXpResponse> AddXpAsync(string source, long amount, CancellationToken cancellationToken = default)
|
||||
=> _battlePass.AddXpAsync(new AddBattlePassXpRequest
|
||||
{
|
||||
ScenarioId = Context.ScenarioId,
|
||||
NodeId = Context.NodeId,
|
||||
RunId = Context.RunId,
|
||||
Source = source,
|
||||
Amount = amount
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Claims a tier reward at a reached level.
|
||||
/// <paramref name="track"/> is <see cref="BattlePassService.TrackFree"/> or <see cref="BattlePassService.TrackPremium"/>.
|
||||
/// </summary>
|
||||
public Task<ClaimBattlePassRewardResponse> ClaimRewardAsync(int level, string track, CancellationToken cancellationToken = default)
|
||||
=> _battlePass.ClaimRewardAsync(new ClaimBattlePassRewardRequest
|
||||
{
|
||||
ScenarioId = Context.ScenarioId,
|
||||
NodeId = Context.NodeId,
|
||||
RunId = Context.RunId,
|
||||
Level = level,
|
||||
Track = track
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>Purchases the premium track, then crosses onPremiumPurchase on success.</summary>
|
||||
public async Task<PurchaseBattlePassPremiumResponse> PurchasePremiumAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var response = await _battlePass.PurchasePremiumAsync(new PurchaseBattlePassPremiumRequest
|
||||
{
|
||||
ScenarioId = Context.ScenarioId,
|
||||
NodeId = Context.NodeId,
|
||||
RunId = Context.RunId,
|
||||
IdempotencyKey = Guid.NewGuid().ToString()
|
||||
}, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (response != null && response.Success)
|
||||
await Context.CompleteAsync("onPremiumPurchase", cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return response!;
|
||||
}
|
||||
|
||||
/// <summary>Advances the run through the onLevelUp handle.</summary>
|
||||
public Task LevelUpAsync(CancellationToken cancellationToken = default) => Context.CompleteAsync("onLevelUp", cancellationToken);
|
||||
|
||||
@@ -29,12 +87,6 @@ public sealed class BattlePassSession
|
||||
/// <summary>Advances the run through the onMaxLevel handle (fire-and-forget).</summary>
|
||||
public void MaxLevel() => Context.Complete("onMaxLevel");
|
||||
|
||||
/// <summary>Advances the run through the onPremiumPurchase handle.</summary>
|
||||
public Task PremiumPurchaseAsync(CancellationToken cancellationToken = default) => Context.CompleteAsync("onPremiumPurchase", cancellationToken);
|
||||
|
||||
/// <summary>Advances the run through the onPremiumPurchase handle (fire-and-forget).</summary>
|
||||
public void PremiumPurchase() => Context.Complete("onPremiumPurchase");
|
||||
|
||||
/// <summary>Advances the run through the onComplete handle.</summary>
|
||||
public Task CompleteAsync(CancellationToken cancellationToken = default) => Context.CompleteAsync("onComplete", cancellationToken);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user