feat(arena-colosseum): playable bracket + rank-match promotion (phase 2)
Closes 4 more arena-colosseum spec shapes (6/16 → 10/16): the dual-prefix
battle URLs (colosseum_battle/* and colosseum_rank_battle/*) for both
do_matching and per-match finish, plus the bracket-end /finish + /retire
pair on /arena_colosseum.
* ColosseumProgressionService: pure-logic decisions for win-threshold
advancement, 3008 promotion trigger, and per-round reward bundles.
Extends ColosseumRoundsConfig with FinishRewards/RetireRewards per
round + a top-level ChampionRewards list.
* MatchContextBuilder.BuildForColosseumAsync: lifts the registered deck
via IDeckRepository (NOT viewer-graph) per project_ef_nav_include_pitfall.
* ArenaColosseumBattleController: dual route prefixes off one controller
via explicit absolute [HttpPost("/...")] routes — does NOT extend
SVSimController's [Route("[controller]")]. Same pattern as FreeBattle.
URL-vs-IsRankMatching mismatch returns 400 with a phase-mismatch error;
no-deck triggers the standard 3001 matchmaking-illegal state. 3008
flips run.IsRankMatching exactly once via the progression service.
* /arena_colosseum/finish + /retire share FinishResponse (rewards +
reward_list + colosseum_status). Champion finish appends ChampionRewards
and surfaces colosseum_status.is_champion = true. Both delete the run
row after granting via IInventoryTransaction.GrantAsync.
* DI: ModePolicy entries for "colosseum_battle" and "colosseum_rank_battle".
* Tests: 8 progression-service unit tests (pure logic), 5 battle-controller
HTTP tests, 5 bracket-terminate HTTP tests, 2 full-bracket E2E walks
(champion path + retire mid-round). Full suite: 1331/1331.
This commit is contained in:
@@ -12,6 +12,7 @@ using SVSim.EmulatedEntrypoint.Models.Dtos.Common.ArenaTwoPick;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests.ArenaColosseum;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaColosseum;
|
||||
using SVSim.EmulatedEntrypoint.Services.ArenaColosseum;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Controllers;
|
||||
|
||||
@@ -28,17 +29,20 @@ public class ArenaColosseumController : SVSimController
|
||||
private readonly IArenaColosseumRunRepository _runs;
|
||||
private readonly IInventoryService _inventory;
|
||||
private readonly IDeckRepository _decks;
|
||||
private readonly IColosseumProgressionService _progression;
|
||||
|
||||
public ArenaColosseumController(
|
||||
IGameConfigService config,
|
||||
IArenaColosseumRunRepository runs,
|
||||
IInventoryService inventory,
|
||||
IDeckRepository decks)
|
||||
IDeckRepository decks,
|
||||
IColosseumProgressionService progression)
|
||||
{
|
||||
_config = config;
|
||||
_runs = runs;
|
||||
_inventory = inventory;
|
||||
_decks = decks;
|
||||
_progression = progression;
|
||||
}
|
||||
|
||||
[HttpPost("top")]
|
||||
@@ -247,6 +251,104 @@ public class ArenaColosseumController : SVSimController
|
||||
return Ok(new { });
|
||||
}
|
||||
|
||||
[HttpPost("finish")]
|
||||
public async Task<IActionResult> Finish([FromBody] BaseRequest _)
|
||||
{
|
||||
if (!TryGetViewerId(out var vid)) return Unauthorized();
|
||||
var run = await _runs.GetByViewerIdAsync(vid);
|
||||
if (run is null) return BadRequest(new { error = "no_active_run" });
|
||||
|
||||
var rounds = _config.Get<ColosseumRoundsConfig>();
|
||||
var decision = _progression.DecideAdvancement(run, rounds);
|
||||
if (!decision.IsBracketEnd)
|
||||
{
|
||||
return BadRequest(new { error = "bracket_not_finished" });
|
||||
}
|
||||
|
||||
run.IsChampion = decision.IsChampion;
|
||||
var rewardEntries = _progression.BuildFinishRewards(run, rounds);
|
||||
var (wireRewards, wireRewardList) = await GrantRewardsAsync(vid, rewardEntries);
|
||||
|
||||
await _runs.DeleteAsync(vid);
|
||||
|
||||
return Ok(new FinishResponse
|
||||
{
|
||||
Rewards = wireRewards,
|
||||
RewardList = wireRewardList,
|
||||
ColosseumStatus = new ColosseumOwnStatus
|
||||
{
|
||||
NowRoundId = run.RoundId,
|
||||
IsChampion = decision.IsChampion ? true : null,
|
||||
ColosseumName = decision.IsChampion ? rounds.Rounds.Count > 0
|
||||
? _config.Get<ColosseumSeasonConfig>().ColosseumName
|
||||
: null : null,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("retire")]
|
||||
public async Task<IActionResult> Retire([FromBody] BaseRequest _)
|
||||
{
|
||||
if (!TryGetViewerId(out var vid)) return Unauthorized();
|
||||
var run = await _runs.GetByViewerIdAsync(vid);
|
||||
if (run is null) return BadRequest(new { error = "no_active_run" });
|
||||
|
||||
var rounds = _config.Get<ColosseumRoundsConfig>();
|
||||
var rewardEntries = _progression.BuildRetireRewards(run, rounds);
|
||||
var (wireRewards, wireRewardList) = await GrantRewardsAsync(vid, rewardEntries);
|
||||
|
||||
await _runs.DeleteAsync(vid);
|
||||
|
||||
return Ok(new FinishResponse
|
||||
{
|
||||
Rewards = wireRewards,
|
||||
RewardList = wireRewardList,
|
||||
ColosseumStatus = new ColosseumOwnStatus
|
||||
{
|
||||
NowRoundId = run.RoundId,
|
||||
RestEntryNum = 0,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grant the bundle through <c>IInventoryTransaction.GrantAsync</c> per
|
||||
/// <c>feedback_reward_grant_service</c> — single dispatch table for every UserGoodsType.
|
||||
/// Returns the two wire forms (rich <c>rewards</c> receipt + wallet-delta <c>reward_list</c>).
|
||||
/// </summary>
|
||||
private async Task<(List<ColosseumReceivedReward>, List<RewardEntryDto>)> GrantRewardsAsync(
|
||||
long viewerId, IReadOnlyList<ColosseumRoundsConfig.RewardEntry> bundle)
|
||||
{
|
||||
var receipts = new List<ColosseumReceivedReward>();
|
||||
var deltas = new List<RewardEntryDto>();
|
||||
if (bundle.Count == 0) return (receipts, deltas);
|
||||
|
||||
await using var tx = await _inventory.BeginAsync(viewerId);
|
||||
foreach (var entry in bundle)
|
||||
{
|
||||
var granted = await tx.GrantAsync(entry.Type, entry.DetailId, entry.Count);
|
||||
receipts.Add(new ColosseumReceivedReward
|
||||
{
|
||||
RewardNumber = entry.Count,
|
||||
RewardType = (int)entry.Type,
|
||||
RewardDetailId = entry.DetailId,
|
||||
Name = entry.Name,
|
||||
});
|
||||
// GrantAsync returns one or more (RewardType, RewardId, RewardNum) tuples — the
|
||||
// post-state-total semantics are owned by the inventory commit, which the wallet-delta
|
||||
// reflection inherits via tx.CommitAsync below.
|
||||
var first = granted.FirstOrDefault();
|
||||
deltas.Add(new RewardEntryDto
|
||||
{
|
||||
RewardType = first is null ? (int)entry.Type : (int)first.RewardType,
|
||||
RewardId = first?.RewardId ?? entry.DetailId,
|
||||
RewardNum = first?.RewardNum ?? entry.Count,
|
||||
});
|
||||
}
|
||||
await tx.CommitAsync();
|
||||
return (receipts, deltas);
|
||||
}
|
||||
|
||||
private static int ResolveServerRoundId(ColosseumSeasonConfig season) => 1;
|
||||
|
||||
private async Task<RewardEntryDto> DebitCrystalAsync(IInventoryTransaction tx, int cost)
|
||||
|
||||
Reference in New Issue
Block a user