0.3.0: UGC removed, battlepass context-carrying API, scenario behavior aligned with web SDK, CI publish
CI / check (push) Successful in 50s
CI / publish (push) Failing after 37s

This commit is contained in:
edmand46
2026-08-19 17:48:58 +03:00
parent 9d8fb29a7c
commit 2a8d5d4f2f
22 changed files with 234 additions and 388 deletions
@@ -47,7 +47,10 @@ public sealed partial class ScenarioService
EmitBattlePassLevel(context);
break;
default:
// Unsupported node type — fail the run (surfaced via OnScenarioFailed)
// instead of leaving it stalled on a node no handler will complete.
_client.Options.Logger?.Log(RudderLogLevel.Warning, $"[Rudder] Unsupported scenario node type '{node.Type}' ({node.Id}).");
FailRun(run, state.NodeId, new Exception($"Unsupported scenario node type '{node.Type}'"));
break;
}
}
@@ -124,7 +127,7 @@ public sealed partial class ScenarioService
private void EmitBattlePass(ScenarioNodeContext context)
{
OnBattlePass?.Invoke(new BattlePassSession(context));
OnBattlePass?.Invoke(new BattlePassSession(context, _client.BattlePass));
}
private void EmitBattlePassLevel(ScenarioNodeContext context)
@@ -3,7 +3,11 @@ using System.Threading.Tasks;
namespace RudderSdk.Core;
/// <summary>Session of a scenario battle-pass-level node.</summary>
/// <summary>
/// Session of a scenario battle-pass-level node — a single claimable tier.
/// <see cref="ClaimAsync"/> crosses onComplete, which the server accepts only
/// once the player has reached the node's configured level.
/// </summary>
public sealed class BattlePassLevelSession
{
internal BattlePassLevelSession(ScenarioNodeContext context) => Context = context;
@@ -14,12 +18,15 @@ public sealed class BattlePassLevelSession
/// <summary>Node id.</summary>
public string Id => Context.NodeId;
/// <summary>The tier level this node claims.</summary>
public int Level => Context.Get("levelNumber", 0);
/// <summary>Reads a typed value from the node data.</summary>
public T Get<T>(string key, T defaultValue = default!) => Context.Get(key, defaultValue);
/// <summary>Advances the run through the onComplete handle.</summary>
public Task CompleteAsync(CancellationToken cancellationToken = default) => Context.CompleteAsync("onComplete", cancellationToken);
/// <summary>Claims this tier; crosses onComplete (the server checks the level was reached).</summary>
public Task ClaimAsync(CancellationToken cancellationToken = default) => Context.CompleteAsync("onComplete", cancellationToken);
/// <summary>Advances the run through the onComplete handle (fire-and-forget).</summary>
public void Complete() => Context.Complete("onComplete");
/// <summary>Claims this tier (fire-and-forget).</summary>
public void Claim() => Context.Complete("onComplete");
}
@@ -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);