feat(rank-battle): AiStart returns ai_id + camelCase self/oppo_info

AiStartInternal builds the self MatchContext, picks a bot from
IBotRoster, projects to the AiBattleStartResponseDto with camelCase
wire keys (sleeveId, emblemId, ... — see ai-start.md). turnState=0
(player first) is the safe default per the ai-start.md TODO; live
capture would clarify the enum.

No deck → ai_id=-1 fallback (the documented "no AI assigned" sentinel
per AIBattleStartTask.cs:21). 3 new wire-shape tests assert the
camelCase keys land verbatim in the JSON, plus self/oppo info come from
the right sources.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-02 01:24:04 -04:00
parent bb63b0df2f
commit 07eb6f1c05
2 changed files with 130 additions and 5 deletions

View File

@@ -157,11 +157,66 @@ public sealed class RankBattleController : ControllerBase
});
}
// Filled in by Task 10.
private Task<IActionResult> AiStartInternal(Format format, CancellationToken ct)
private async Task<IActionResult> AiStartInternal(Format format, CancellationToken ct)
{
if (!TryGetViewerId(out var _)) return Task.FromResult<IActionResult>(Unauthorized());
// Placeholder; real impl arrives in Task 10.
return Task.FromResult<IActionResult>(Ok(new AiBattleStartResponseDto { AiId = -1 }));
if (!TryGetViewerId(out var vid)) return Unauthorized();
MatchContext selfCtx;
try
{
selfCtx = await _ctxBuilder.BuildForRankBattleAsync(vid, format);
}
catch (InvalidOperationException ex)
{
// No deck → can't build a self profile. Surface as the "no AI assigned"
// sentinel; the client treats ai_id=-1 as a fallback/error condition.
_log.LogWarning(ex, "AiStart failed for viewer {Vid} format {Fmt}; returning ai_id=-1.", vid, format);
return Ok(new AiBattleStartResponseDto { AiId = -1 });
}
var bot = _botRoster.Pick(selfCtx);
// Per spec, ai-start.md TODO: turnState semantics unclear. Default 0 (player first).
return Ok(new AiBattleStartResponseDto
{
AiId = bot.AiId,
TurnState = 0,
SelfInfo = new AiBattlePlayerInfo
{
CountryCode = selfCtx.CountryCode,
UserName = selfCtx.UserName,
SleeveId = int.TryParse(selfCtx.SleeveId, out var sId) ? sId : -1,
EmblemId = int.TryParse(selfCtx.EmblemId, out var eId) ? eId : -1,
DegreeId = int.TryParse(selfCtx.DegreeId, out var dId) ? dId : -1,
FieldId = selfCtx.FieldId,
IsOfficial = selfCtx.IsOfficial,
OppoId = bot.AiId,
Seed = 0,
Rank = 0,
BattlePoint = 0,
ClassId = int.TryParse(selfCtx.ClassId, out var cId) ? cId : -1,
CharaId = int.TryParse(selfCtx.CharaId, out var chId) ? chId : -1,
IsMasterRank = 0,
MasterPoint = 0,
},
OppoInfo = new AiBattlePlayerInfo
{
CountryCode = bot.CountryCode,
UserName = bot.UserName,
SleeveId = bot.SleeveId,
EmblemId = bot.EmblemId,
DegreeId = bot.DegreeId,
FieldId = bot.FieldId,
IsOfficial = bot.IsOfficial,
OppoId = (int)vid,
Seed = 0,
Rank = bot.Rank,
BattlePoint = bot.BattlePoint,
ClassId = bot.ClassId,
CharaId = bot.CharaId,
IsMasterRank = bot.IsMasterRank,
MasterPoint = bot.MasterPoint,
},
});
}
}