Skip to content

Commit

Permalink
Add wyrmsigil support / sparking (#754)
Browse files Browse the repository at this point in the history
Closes #693 

Enables trading for units with wyrmsigils earned from summoning.
Wyrmsigil points have always been recorded but not shown to the user, in
`PlayerBannerData`, so no savefile update is required.

TODO:

- [x] Tests
- [x] Replace GetTradeDictionary
- [x] Banner changes in masterasset - create ModTools util to update
SummonData / SummonPointData from bannerConfig.json
  • Loading branch information
SapiensAnatis authored Apr 9, 2024
1 parent f726843 commit b875f8a
Show file tree
Hide file tree
Showing 22 changed files with 742 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,4 @@ await this.fixture.AddRangeToDatabase(
.Should()
.BeEquivalentTo(new List<DbPlayerSummonHistory>() { history });
}

[Fact]
public async Task GetPlayerBannerData_ReturnsOnlyPlayerBannerDataWithRightId()
{
DbPlayerBannerData bannerData = DbPlayerBannerDataFactory.Create(1, 1);
await this.fixture.AddRangeToDatabase(
new List<DbPlayerBannerData>()
{
bannerData,
DbPlayerBannerDataFactory.Create(2, 2),
DbPlayerBannerDataFactory.Create(3, 1)
}
);

(await this.summonRepository.GetPlayerBannerData(1)).Should().BeEquivalentTo(bannerData);
}

[Fact]
public async Task GetPlayerBannerData_AddsIfNotFound()
{
(await this.summonRepository.GetPlayerBannerData(10))
.Should()
.BeEquivalentTo(
DbPlayerBannerDataFactory.Create(ViewerId, 10),
options =>
options
.Excluding(x => x.ConsecutionSummonPointsMinDate)
.Excluding(x => x.ConsecutionSummonPointsMaxDate)
);
}
}
2 changes: 1 addition & 1 deletion DragaliaAPI/DragaliaAPI.Database/ApiContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.HasQueryFilter(x => x.ViewerId == this.playerIdentityService.ViewerId);

modelBuilder
.Entity<DbPlayerStoryState>()
.Entity<DbPlayerBannerData>()
.HasQueryFilter(x => x.ViewerId == this.playerIdentityService.ViewerId);
}
}
2 changes: 1 addition & 1 deletion DragaliaAPI/DragaliaAPI.Database/Entities/DbPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class DbPlayer

public List<DbParty> PartyList { get; set; } = [];

public List<DbPlayerBannerData> UserSummonList { get; set; } = [];
public List<DbPlayerBannerData> BannerData { get; set; } = [];

public List<DbPlayerCharaData> CharaList { get; set; } = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ public interface ISummonRepository : IBaseRepository
IQueryable<DbPlayerSummonHistory> SummonHistory { get; }

Task AddSummonHistory(DbPlayerSummonHistory summonHistory);
Task<DbPlayerBannerData> AddPlayerBannerData(int bannerId);
Task<DbPlayerBannerData> GetPlayerBannerData(int bannerId);
}
21 changes: 0 additions & 21 deletions DragaliaAPI/DragaliaAPI.Database/Repositories/SummonRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,6 @@ public SummonRepository(ApiContext apiContext, IPlayerIdentityService playerIden
x.ViewerId == this.playerIdentityService.ViewerId
);

public async Task<DbPlayerBannerData> GetPlayerBannerData(int bannerId)
{
DbPlayerBannerData bannerData =
await apiContext.PlayerBannerData.FirstOrDefaultAsync(x =>
x.ViewerId.Equals(this.playerIdentityService.ViewerId)
&& x.SummonBannerId == bannerId
) ?? await this.AddPlayerBannerData(bannerId);
return bannerData;
}

public async Task<DbPlayerBannerData> AddPlayerBannerData(int bannerId)
{
DbPlayerBannerData bannerData = DbPlayerBannerDataFactory.Create(
this.playerIdentityService.ViewerId,
bannerId
);
bannerData = (await apiContext.PlayerBannerData.AddAsync(bannerData)).Entity;

return bannerData;
}

public async Task AddSummonHistory(DbPlayerSummonHistory summonHistory)
{
await apiContext.PlayerSummonHistory.AddRangeAsync(summonHistory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ namespace DragaliaAPI.Integration.Test.Features.Summoning;
/// </summary>
public class SummonTest : TestFixture
{
private const int TestBannerId = 1020010;
private const int TestBannerId = 1020121;

public SummonTest(CustomWebApplicationFactory factory, ITestOutputHelper outputHelper)
: base(factory, outputHelper) { }
: base(factory, outputHelper)
{
CommonAssertionOptions.ApplyTimeOptions();
}

[Fact]
public async Task SummonExcludeGetList_ReturnsAnyData()
Expand All @@ -33,7 +36,7 @@ public async Task SummonGetOddsData_ReturnsExpectedData()
SummonGetOddsDataResponse response = (
await this.Client.PostMsgpack<SummonGetOddsDataResponse>(
"summon/get_odds_data",
new SummonGetOddsDataRequest(1020010)
new SummonGetOddsDataRequest(TestBannerId)
)
).Data;

Expand Down Expand Up @@ -186,14 +189,13 @@ await this.Client.PostMsgpack<SummonGetSummonHistoryResponse>(
[Fact]
public async Task SummonGetSummonList_ReturnsDataWithBannerInformation()
{
int bannerId = 1020010;
int dailyCount = 1;
int summonCount = 10;

await this.AddToDatabase(
new DbPlayerBannerData()
{
SummonBannerId = bannerId,
SummonBannerId = TestBannerId,
DailyLimitedSummonCount = dailyCount,
SummonCount = summonCount
}
Expand All @@ -220,15 +222,15 @@ await this.Client.PostMsgpack<SummonGetSummonListResponse>("summon/get_summon_li
.BeEquivalentTo(
new SummonList()
{
SummonId = bannerId,
SummonId = TestBannerId,
SummonType = 2,
SingleCrystal = 120,
SingleDiamond = 120,
MultiCrystal = 1200,
MultiDiamond = 1200,
LimitedCrystal = 0,
LimitedDiamond = 30,
SummonPointId = bannerId,
SummonPointId = TestBannerId,
AddSummonPoint = 1,
AddSummonPointStone = 2,
ExchangeSummonPoint = 300,
Expand Down Expand Up @@ -263,19 +265,92 @@ await this.Client.PostMsgpack<SummonGetSummonListResponse>("summon/get_summon_li
}

[Fact]
public async Task SummonRequest_GetSummonPointData_ReturnsAnyData()
public async Task SummonGetSummonPointTrade_NoBannerData_CreatesDefaultData()
{
this.ApiContext.PlayerBannerData.Should()
.NotContain(x => x.ViewerId == this.ViewerId && x.SummonBannerId == TestBannerId);

SummonGetSummonPointTradeResponse response = (
await this.Client.PostMsgpack<SummonGetSummonPointTradeResponse>(
"summon/get_summon_point_trade",
new SummonGetSummonPointTradeRequest(TestBannerId)
)
).Data;

response.Should().NotBeNull();
response
.Should()
.BeEquivalentTo(
new SummonGetSummonPointTradeResponse()
{
SummonPointTradeList =
[
new()
{
TradeId = int.Parse($"{TestBannerId}100"),
EntityId = (int)Charas.Mona,
EntityType = EntityTypes.Chara
},
new()
{
TradeId = int.Parse($"{TestBannerId}700"),
EntityId = (int)Dragons.Arsene,
EntityType = EntityTypes.Dragon
}
],
SummonPointList = [new() { SummonPointId = TestBannerId, SummonPoint = 0, }],
UpdateDataList = new()
{
SummonPointList = [new() { SummonPointId = TestBannerId, SummonPoint = 0, }]
},
EntityResult = new(),
},
opts => opts.Excluding(x => x.Name.Contains("CsPoint"))
);

response.SummonPointList.Should().NotBeEmpty();
response.SummonPointTradeList.Should().NotBeEmpty();
this.ApiContext.PlayerBannerData.Should()
.Contain(x => x.ViewerId == this.ViewerId && x.SummonBannerId == TestBannerId);
}

[Fact]
public async Task SummonGetSummonPointTrade_ExistingBannerData_ReturnsData()
{
await this.AddToDatabase(
new DbPlayerBannerData() { SummonBannerId = TestBannerId, SummonPoints = 400, }
);

SummonGetSummonPointTradeResponse response = (
await this.Client.PostMsgpack<SummonGetSummonPointTradeResponse>(
"summon/get_summon_point_trade",
new SummonGetSummonPointTradeRequest(TestBannerId)
)
).Data;

response
.Should()
.BeEquivalentTo(
new SummonGetSummonPointTradeResponse()
{
SummonPointTradeList =
[
new()
{
TradeId = int.Parse($"{TestBannerId}100"),
EntityId = (int)Charas.Mona,
EntityType = EntityTypes.Chara
},
new()
{
TradeId = int.Parse($"{TestBannerId}700"),
EntityId = (int)Dragons.Arsene,
EntityType = EntityTypes.Dragon
}
],
SummonPointList = [new() { SummonPointId = TestBannerId, SummonPoint = 400, }],
UpdateDataList = new(),
EntityResult = new(),
},
opts => opts.Excluding(x => x.Name.Contains("CsPoint"))
);
}

[Fact]
Expand Down Expand Up @@ -423,6 +498,50 @@ await this.Client.PostMsgpack<SummonRequestResponse>(
response.DataHeaders.ResultCode.Should().Be(ResultCode.Success);
}

[Fact]
public async Task SummonRequest_IncrementsWyrmsigilPoints()
{
DbPlayerUserData userData = await this.ApiContext.PlayerUserData.SingleAsync(x =>
x.ViewerId == this.ViewerId
);

SummonRequestResponse response = (
await this.Client.PostMsgpack<SummonRequestResponse>(
"summon/request",
new SummonRequestRequest(
TestBannerId,
SummonExecTypes.Tenfold,
1,
PaymentTypes.Wyrmite,
new PaymentTarget(userData.Crystal, 1200)
)
)
).Data;

response.ResultSummonPoint.Should().Be(10);
response
.UpdateDataList.SummonPointList.Should()
.Contain(x => x.SummonPointId == TestBannerId && x.SummonPoint == 10);

SummonRequestResponse singleResponse = (
await this.Client.PostMsgpack<SummonRequestResponse>(
"summon/request",
new SummonRequestRequest(
TestBannerId,
SummonExecTypes.Single,
3,
PaymentTypes.Wyrmite,
new PaymentTarget(userData.Crystal - 1200, 360)
)
)
).Data;

singleResponse.ResultSummonPoint.Should().Be(3);
singleResponse
.UpdateDataList.SummonPointList.Should()
.Contain(x => x.SummonPointId == TestBannerId && x.SummonPoint == 13);
}

[Theory]
[InlineData(SummonExecTypes.Tenfold)]
[InlineData(SummonExecTypes.Single)]
Expand Down Expand Up @@ -450,6 +569,72 @@ await this.Client.PostMsgpack<SummonRequestResponse>(
response.DataHeaders.ResultCode.Should().Be(ResultCode.CommonMaterialShort);
}

[Fact]
public async Task SummonPointTrade_Chara_Success_ReturnsData()
{
int monaTradeId = int.Parse($"{TestBannerId}100");

await this.AddToDatabase(
new DbPlayerBannerData() { SummonBannerId = TestBannerId, SummonPoints = 400, }
);

SummonSummonPointTradeResponse response = (
await this.Client.PostMsgpack<SummonSummonPointTradeResponse>(
"summon/summon_point_trade",
new SummonSummonPointTradeRequest(TestBannerId, monaTradeId)
)
).Data;

response
.ExchangeEntityList.Should()
.ContainEquivalentOf(
new AtgenBuildEventRewardEntityList()
{
EntityId = (int)Charas.Mona,
EntityType = EntityTypes.Chara,
EntityQuantity = 1,
}
);

response.UpdateDataList.CharaList.Should().Contain(x => x.CharaId == Charas.Mona);

this.ApiContext.PlayerCharaData.Should()
.Contain(x => x.ViewerId == this.ViewerId && x.CharaId == Charas.Mona);
}

[Fact]
public async Task SummonPointTrade_Dragon_Success_ReturnsData()
{
int arseneTradeId = int.Parse($"{TestBannerId}700");

await this.AddToDatabase(
new DbPlayerBannerData() { SummonBannerId = TestBannerId, SummonPoints = 400, }
);

SummonSummonPointTradeResponse response = (
await this.Client.PostMsgpack<SummonSummonPointTradeResponse>(
"summon/summon_point_trade",
new SummonSummonPointTradeRequest(TestBannerId, arseneTradeId)
)
).Data;

response
.ExchangeEntityList.Should()
.ContainEquivalentOf(
new AtgenBuildEventRewardEntityList()
{
EntityId = (int)Dragons.Arsene,
EntityType = EntityTypes.Dragon,
EntityQuantity = 1,
}
);

response.UpdateDataList.DragonList.Should().Contain(x => x.DragonId == Dragons.Arsene);

this.ApiContext.PlayerDragonData.Should()
.Contain(x => x.ViewerId == this.ViewerId && x.DragonId == Dragons.Arsene);
}

private async Task CheckRewardInDb(AtgenResultUnitList reward)
{
if (reward.EntityType == EntityTypes.Dragon)
Expand Down
Loading

0 comments on commit b875f8a

Please sign in to comment.