feat(svc): IArenaTwoPickService + response DTOs + GetTopAsync
6 response DTOs, IArenaTwoPickService interface + ArenaTwoPickException, ArenaTwoPickService skeleton with GetTopAsync implemented and stubs for Tasks 13-15. 3 NUnit tests for GetTopAsync all pass. DI: AddScoped.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaTwoPick;
|
||||
|
||||
/// <summary>
|
||||
/// What the battle controller needs from the service to build the standard battle-finish
|
||||
/// envelope (class XP delta + post-state, spot points before/add/after, battle_result echo).
|
||||
/// Achieved-info is built by the controller from IMissionAssembler.
|
||||
/// </summary>
|
||||
public class BattleFinishResultDto
|
||||
{
|
||||
public int BattleResult { get; set; }
|
||||
public int GetClassExperience { get; set; }
|
||||
public int ClassExperience { get; set; }
|
||||
public int ClassLevel { get; set; }
|
||||
public int BeforeSpotPoint { get; set; }
|
||||
public int AddSpotPoint { get; set; }
|
||||
public int AfterSpotPoint { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using MessagePack;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Common.ArenaTwoPick;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaTwoPick;
|
||||
|
||||
[MessagePackObject]
|
||||
public class CardChooseResponseDto
|
||||
{
|
||||
[JsonPropertyName("deck_info")] [Key("deck_info")]
|
||||
public DeckInfoDto DeckInfo { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("candidate_card_list")] [Key("candidate_card_list")]
|
||||
public List<CandidatePairDto>? CandidateCardList { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using MessagePack;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Common.ArenaTwoPick;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaTwoPick;
|
||||
|
||||
[MessagePackObject]
|
||||
public class ClassChooseResponseDto
|
||||
{
|
||||
[JsonPropertyName("class_info")] [Key("class_info")]
|
||||
public ClassInfoDto ClassInfo { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("deck_info")] [Key("deck_info")]
|
||||
public DeckInfoDto DeckInfo { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("candidate_card_list")] [Key("candidate_card_list")]
|
||||
public List<CandidatePairDto> CandidateCardList { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using MessagePack;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Common.ArenaTwoPick;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaTwoPick;
|
||||
|
||||
[MessagePackObject]
|
||||
public class EntryResponseDto
|
||||
{
|
||||
[JsonPropertyName("entry_info")] [Key("entry_info")]
|
||||
public EntryInfoDto EntryInfo { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("reward_list")] [Key("reward_list")]
|
||||
public List<RewardEntryDto> RewardList { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("candidate_class_ids")] [Key("candidate_class_ids")]
|
||||
public List<int> CandidateClassIds { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("battle_results")] [Key("battle_results")]
|
||||
public BattleResultsDto BattleResults { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using MessagePack;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Common.ArenaTwoPick;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaTwoPick;
|
||||
|
||||
[MessagePackObject]
|
||||
public class FinishResponseDto
|
||||
{
|
||||
/// <summary>Per-grant deltas — drives "+N received" popup.</summary>
|
||||
[JsonPropertyName("rewards")] [Key("rewards")]
|
||||
public List<RewardEntryDto> Rewards { get; set; } = new();
|
||||
|
||||
/// <summary>Post-state totals — drives PlayerStaticData.UpdateHaveUserGoodsNumByJsonData.</summary>
|
||||
[JsonPropertyName("reward_list")] [Key("reward_list")]
|
||||
public List<RewardEntryDto> RewardList { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using MessagePack;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Common;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Common.ArenaTwoPick;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaTwoPick;
|
||||
|
||||
[MessagePackObject]
|
||||
public class TopResponseDto
|
||||
{
|
||||
[JsonPropertyName("entry_info")] [JsonIgnore(Condition = JsonIgnoreCondition.Never)] [Key("entry_info")]
|
||||
public EntryInfoDto? EntryInfo { get; set; }
|
||||
|
||||
[JsonPropertyName("battle_results")] [Key("battle_results")]
|
||||
public BattleResultsDto? BattleResults { get; set; }
|
||||
|
||||
[JsonPropertyName("class_info")] [Key("class_info")]
|
||||
public ClassInfoDto? ClassInfo { get; set; }
|
||||
|
||||
[JsonPropertyName("deck_info")] [Key("deck_info")]
|
||||
public DeckInfoDto? DeckInfo { get; set; }
|
||||
|
||||
[JsonPropertyName("leader_skin_id")] [JsonConverter(typeof(StringifiedLongConverter))] [Key("leader_skin_id")]
|
||||
public long? LeaderSkinId { get; set; }
|
||||
}
|
||||
@@ -105,6 +105,7 @@ public class Program
|
||||
builder.Services.AddScoped<IViewerStoryProgressRepository, ViewerStoryProgressRepository>();
|
||||
builder.Services.AddScoped<IArenaTwoPickRunRepository, ArenaTwoPickRunRepository>();
|
||||
builder.Services.AddScoped<IArenaTwoPickCardPoolService, ArenaTwoPickCardPoolService>();
|
||||
builder.Services.AddScoped<IArenaTwoPickService, ArenaTwoPickService>();
|
||||
builder.Services.AddScoped<IStoryService, StoryService>();
|
||||
builder.Services.AddScoped<IDeckListBuilder, DeckListBuilder>();
|
||||
builder.Services.AddSingleton<IRandom, SystemRandom>();
|
||||
|
||||
113
SVSim.EmulatedEntrypoint/Services/ArenaTwoPickService.cs
Normal file
113
SVSim.EmulatedEntrypoint/Services/ArenaTwoPickService.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System.Text.Json;
|
||||
using SVSim.Database;
|
||||
using SVSim.Database.Models;
|
||||
using SVSim.Database.Repositories.Globals;
|
||||
using SVSim.Database.Repositories.Viewer;
|
||||
using SVSim.Database.Services;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Common.ArenaTwoPick;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaTwoPick;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Services;
|
||||
|
||||
public class ArenaTwoPickService : IArenaTwoPickService
|
||||
{
|
||||
private readonly IArenaTwoPickRunRepository _runs;
|
||||
private readonly IArenaTwoPickRewardRepository _rewards;
|
||||
private readonly IArenaTwoPickCardPoolService _pool;
|
||||
private readonly IGameConfigService _config;
|
||||
private readonly IViewerRepository _viewers;
|
||||
private readonly RewardGrantService _grants;
|
||||
private readonly IViewerEntitlements _entitlements;
|
||||
private readonly IRandom _rng;
|
||||
private readonly SVSimDbContext _db;
|
||||
|
||||
public ArenaTwoPickService(
|
||||
IArenaTwoPickRunRepository runs,
|
||||
IArenaTwoPickRewardRepository rewards,
|
||||
IArenaTwoPickCardPoolService pool,
|
||||
IGameConfigService config,
|
||||
IViewerRepository viewers,
|
||||
RewardGrantService grants,
|
||||
IViewerEntitlements entitlements,
|
||||
IRandom rng,
|
||||
SVSimDbContext db)
|
||||
{
|
||||
_runs = runs; _rewards = rewards; _pool = pool; _config = config;
|
||||
_viewers = viewers; _grants = grants; _entitlements = entitlements; _rng = rng; _db = db;
|
||||
}
|
||||
|
||||
public async Task<TopResponseDto> GetTopAsync(long viewerId)
|
||||
{
|
||||
var run = await _runs.GetByViewerIdAsync(viewerId);
|
||||
if (run is null) return new TopResponseDto { EntryInfo = null };
|
||||
|
||||
var dto = new TopResponseDto
|
||||
{
|
||||
EntryInfo = ProjectEntryInfo(run, viewerId),
|
||||
BattleResults = ProjectBattleResults(run),
|
||||
};
|
||||
if (run.ClassId != 0)
|
||||
{
|
||||
dto.ClassInfo = ProjectClassInfo(run);
|
||||
dto.DeckInfo = ProjectDeckInfo(run);
|
||||
if (run.WinCount > 0 || run.LossCount > 0)
|
||||
dto.LeaderSkinId = run.LeaderSkinId;
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
public Task<EntryResponseDto> EntryAsync(long viewerId, int consumeItemType) => throw new NotImplementedException();
|
||||
public Task<ClassChooseResponseDto> ChooseClassAsync(long viewerId, int classId) => throw new NotImplementedException();
|
||||
public Task<CardChooseResponseDto> ChooseCardAsync(long viewerId, long selectedId) => throw new NotImplementedException();
|
||||
public Task<FinishResponseDto> RetireAsync(long viewerId) => throw new NotImplementedException();
|
||||
public Task<FinishResponseDto> FinishAsync(long viewerId) => throw new NotImplementedException();
|
||||
public Task<BattleFinishResultDto> RecordBattleResultAsync(long viewerId, bool isWin) => throw new NotImplementedException();
|
||||
|
||||
// --- projection helpers (kept internal so test subclasses could exercise if needed) ---
|
||||
|
||||
internal static EntryInfoDto ProjectEntryInfo(ViewerArenaTwoPickRun run, long viewerId) => new()
|
||||
{
|
||||
Id = run.EntryId,
|
||||
ViewerId = viewerId,
|
||||
RewardScheduleId = run.RewardScheduleId,
|
||||
ChallengeId = run.ChallengeId,
|
||||
MaxBattleCount = run.MaxBattleCount,
|
||||
LeaderSkinId = run.LeaderSkinId,
|
||||
IsRetire = run.IsRetire ? 1 : 0,
|
||||
};
|
||||
|
||||
internal static BattleResultsDto ProjectBattleResults(ViewerArenaTwoPickRun run)
|
||||
{
|
||||
var bools = JsonSerializer.Deserialize<List<bool>>(run.ResultListJson) ?? new();
|
||||
return new()
|
||||
{
|
||||
ResultList = bools.Select(b => b ? 1 : 0).ToList(),
|
||||
WinCount = run.WinCount,
|
||||
};
|
||||
}
|
||||
|
||||
internal static ClassInfoDto ProjectClassInfo(ViewerArenaTwoPickRun run)
|
||||
{
|
||||
var ids = JsonSerializer.Deserialize<List<int>>(run.CandidateClassIdsJson) ?? new();
|
||||
return new()
|
||||
{
|
||||
ClassId1 = ids.ElementAtOrDefault(0),
|
||||
ClassId2 = ids.ElementAtOrDefault(1),
|
||||
ClassId3 = ids.ElementAtOrDefault(2),
|
||||
SelectedClassId = run.ClassId,
|
||||
};
|
||||
}
|
||||
|
||||
internal static DeckInfoDto ProjectDeckInfo(ViewerArenaTwoPickRun run)
|
||||
{
|
||||
var cards = JsonSerializer.Deserialize<List<long>>(run.SelectedCardIdsJson) ?? new();
|
||||
return new()
|
||||
{
|
||||
TwoPickEntryId = run.EntryId,
|
||||
ClassId = run.ClassId,
|
||||
IsSelectCompleted = run.IsSelectCompleted,
|
||||
SelectedCardIds = cards,
|
||||
SelectTurn = run.SelectTurn == 0 ? 1 : run.SelectTurn,
|
||||
};
|
||||
}
|
||||
}
|
||||
20
SVSim.EmulatedEntrypoint/Services/IArenaTwoPickService.cs
Normal file
20
SVSim.EmulatedEntrypoint/Services/IArenaTwoPickService.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaTwoPick;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Services;
|
||||
|
||||
public interface IArenaTwoPickService
|
||||
{
|
||||
Task<TopResponseDto> GetTopAsync(long viewerId);
|
||||
Task<EntryResponseDto> EntryAsync(long viewerId, int consumeItemType);
|
||||
Task<ClassChooseResponseDto> ChooseClassAsync(long viewerId, int classId);
|
||||
Task<CardChooseResponseDto> ChooseCardAsync(long viewerId, long selectedId);
|
||||
Task<FinishResponseDto> RetireAsync(long viewerId);
|
||||
Task<FinishResponseDto> FinishAsync(long viewerId);
|
||||
Task<BattleFinishResultDto> RecordBattleResultAsync(long viewerId, bool isWin);
|
||||
}
|
||||
|
||||
public class ArenaTwoPickException : Exception
|
||||
{
|
||||
public string ErrorCode { get; }
|
||||
public ArenaTwoPickException(string errorCode) : base(errorCode) { ErrorCode = errorCode; }
|
||||
}
|
||||
Reference in New Issue
Block a user