using Microsoft.AspNetCore.Mvc; using SVSim.BattleNode.Bridge; using SVSim.EmulatedEntrypoint.Models.Dtos.Requests.ArenaTwoPick; using SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaTwoPick; using SVSim.EmulatedEntrypoint.Services; namespace SVSim.EmulatedEntrypoint.Controllers; [Route("arena_two_pick_battle")] public class ArenaTwoPickBattleController : SVSimController { private readonly IArenaTwoPickService _svc; private readonly IMatchingBridge _matching; private readonly IMatchContextBuilder _matchContextBuilder; public ArenaTwoPickBattleController( IArenaTwoPickService svc, IMatchingBridge matching, IMatchContextBuilder matchContextBuilder) { _svc = svc; _matching = matching; _matchContextBuilder = matchContextBuilder; } [HttpPost("do_matching")] public async Task DoMatching([FromBody] DoMatchingRequest req) { if (!TryGetViewerId(out var vid)) return Unauthorized(); try { var ctx = await _matchContextBuilder.BuildForTwoPickAsync(vid); var match = _matching.RegisterPendingBattle(vid, ctx); return Ok(new DoMatchingResponseDto { MatchingState = 3004, BattleId = match.BattleId, NodeServerUrl = match.NodeServerUrl, }); } catch (ArenaTwoPickException ex) { return BadRequest(new { error_code = ex.ErrorCode }); } } [HttpPost("finish")] public async Task Finish([FromBody] BattleFinishRequest req) { if (!TryGetViewerId(out var vid)) return Unauthorized(); try { var result = await _svc.RecordBattleResultAsync(vid, req.BattleResult == 1); return Ok(new BattleFinishResponseDto { BattleResult = result.BattleResult, GetClassExperience = result.GetClassExperience, ClassExperience = result.ClassExperience, ClassLevel = result.ClassLevel, SpotPointInfo = new SpotPointInfoDto { BeforeSpotPoint = result.BeforeSpotPoint, AddSpotPoint = result.AddSpotPoint, AfterSpotPoint = result.AfterSpotPoint, }, }); } catch (ArenaTwoPickException ex) { return BadRequest(new { error_code = ex.ErrorCode }); } } }