-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f17166f
commit bc09f4b
Showing
16 changed files
with
489 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
82 changes: 41 additions & 41 deletions
82
DragaliaAPI/Features/Dungeon/Record/DungeonRecordController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,81 @@ | ||
using System.Diagnostics; | ||
using DragaliaAPI.Controllers; | ||
using DragaliaAPI.Database.Entities; | ||
using DragaliaAPI.Database.Repositories; | ||
using DragaliaAPI.Features.Missions; | ||
using DragaliaAPI.Controllers; | ||
using DragaliaAPI.Middleware; | ||
using DragaliaAPI.Models; | ||
using DragaliaAPI.Models.Generated; | ||
using DragaliaAPI.Services; | ||
using DragaliaAPI.Services.Game; | ||
using DragaliaAPI.Shared.Definitions.Enums; | ||
using DragaliaAPI.Shared.MasterAsset; | ||
using DragaliaAPI.Shared.MasterAsset.Models; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace DragaliaAPI.Features.Dungeon.Record; | ||
|
||
[Route("dungeon_record")] | ||
public class DungeonRecordController : DragaliaControllerBase | ||
public class DungeonRecordController( | ||
IDungeonRecordService dungeonRecordService, | ||
IDungeonRecordDamageService dungeonRecordDamageService, | ||
IDungeonService dungeonService, | ||
ITutorialService tutorialService, | ||
IUpdateDataService updateDataService | ||
) : DragaliaControllerBase | ||
{ | ||
private readonly IUpdateDataService updateDataService; | ||
private readonly IDungeonRecordService dungeonRecordService; | ||
private readonly ITutorialService tutorialService; | ||
private readonly ILogger<DungeonRecordController> logger; | ||
|
||
public DungeonRecordController( | ||
IUpdateDataService updateDataService, | ||
IDungeonRecordService dungeonRecordService, | ||
ITutorialService tutorialService, | ||
ILogger<DungeonRecordController> logger | ||
) | ||
{ | ||
this.updateDataService = updateDataService; | ||
this.dungeonRecordService = dungeonRecordService; | ||
this.tutorialService = tutorialService; | ||
this.logger = logger; | ||
} | ||
|
||
[HttpPost("record")] | ||
public async Task<DragaliaResult> Record(DungeonRecordRecordRequest request) | ||
{ | ||
DungeonSession session = await dungeonService.FinishDungeon(request.dungeon_key); | ||
|
||
await tutorialService.AddTutorialFlag(1022); | ||
|
||
IngameResultData ingameResultData = | ||
await this.dungeonRecordService.GenerateIngameResultData( | ||
request.dungeon_key, | ||
request.play_record | ||
); | ||
IngameResultData ingameResultData = await dungeonRecordService.GenerateIngameResultData( | ||
request.dungeon_key, | ||
request.play_record, | ||
session | ||
); | ||
|
||
UpdateDataList updateDataList = await this.updateDataService.SaveChangesAsync(); | ||
UpdateDataList updateDataList = await updateDataService.SaveChangesAsync(); | ||
|
||
DungeonRecordRecordData response = | ||
new() { ingame_result_data = ingameResultData, update_data_list = updateDataList, }; | ||
|
||
if (session.QuestData.IsSumUpTotalDamage) | ||
{ | ||
response.event_damage_ranking = await dungeonRecordDamageService.GetEventDamageRanking( | ||
request.play_record, | ||
session.QuestData.Gid | ||
); | ||
} | ||
|
||
return Ok(response); | ||
} | ||
|
||
[HttpPost("record_multi")] | ||
[Authorize(AuthenticationSchemes = nameof(PhotonAuthenticationHandler))] | ||
public async Task<DragaliaResult> RecordMulti(DungeonRecordRecordMultiRequest request) | ||
{ | ||
DungeonSession session = await dungeonService.FinishDungeon(request.dungeon_key); | ||
|
||
await tutorialService.AddTutorialFlag(1022); | ||
|
||
IngameResultData ingameResultData = | ||
await this.dungeonRecordService.GenerateIngameResultData( | ||
request.dungeon_key, | ||
request.play_record | ||
); | ||
IngameResultData ingameResultData = await dungeonRecordService.GenerateIngameResultData( | ||
request.dungeon_key, | ||
request.play_record, | ||
session | ||
); | ||
|
||
ingameResultData.play_type = QuestPlayType.Multi; | ||
|
||
UpdateDataList updateDataList = await this.updateDataService.SaveChangesAsync(); | ||
UpdateDataList updateDataList = await updateDataService.SaveChangesAsync(); | ||
|
||
DungeonRecordRecordMultiData response = | ||
DungeonRecordRecordData response = | ||
new() { ingame_result_data = ingameResultData, update_data_list = updateDataList, }; | ||
|
||
if (session.QuestData.IsSumUpTotalDamage) | ||
{ | ||
response.event_damage_ranking = await dungeonRecordDamageService.GetEventDamageRanking( | ||
request.play_record, | ||
session.QuestData.Gid | ||
); | ||
} | ||
|
||
return Ok(response); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
DragaliaAPI/Features/Dungeon/Record/DungeonRecordDamageService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using DragaliaAPI.Models; | ||
using DragaliaAPI.Models.Generated; | ||
|
||
namespace DragaliaAPI.Features.Dungeon.Record; | ||
|
||
public class DungeonRecordDamageService : IDungeonRecordDamageService | ||
{ | ||
public Task<EventDamageRanking> GetEventDamageRanking(PlayRecord playRecord, int eventId) | ||
{ | ||
EventDamageRanking damageRanking = | ||
new() | ||
{ | ||
event_id = eventId, | ||
own_damage_ranking_list = new List<AtgenOwnDamageRankingList>() | ||
{ | ||
// TODO: track in database to determine if it's a new personal best | ||
new AtgenOwnDamageRankingList() | ||
{ | ||
chara_id = 0, | ||
rank = 0, | ||
damage_value = playRecord?.total_play_damage ?? 0, | ||
is_new = false, | ||
} | ||
} | ||
}; | ||
|
||
return Task.FromResult(damageRanking); | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
DragaliaAPI/Features/Dungeon/Record/DungeonRecordHelperService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
using DragaliaAPI.Database.Entities; | ||
using DragaliaAPI.Database.Repositories; | ||
using DragaliaAPI.Models.Generated; | ||
using DragaliaAPI.Services; | ||
using DragaliaAPI.Services.Photon; | ||
using DragaliaAPI.Shared.PlayerDetails; | ||
using Microsoft.EntityFrameworkCore; | ||
using PhotonPlayer = DragaliaAPI.Photon.Shared.Models.Player; | ||
|
||
namespace DragaliaAPI.Features.Dungeon.Record; | ||
|
||
public class DungeonRecordHelperService( | ||
IPlayerIdentityService playerIdentityService, | ||
IUserDataRepository userDataRepository, | ||
IHelperService helperService, | ||
IMatchingService matchingService, | ||
ILogger<DungeonRecordHelperService> logger | ||
) : IDungeonRecordHelperService | ||
{ | ||
public async Task<IngameResultData> ProcessHelperDataSolo( | ||
IngameResultData resultData, | ||
ulong? supportViewerId | ||
) | ||
{ | ||
if (supportViewerId is null) | ||
return resultData; | ||
|
||
UserSupportList? supportList = await helperService.GetHelper(supportViewerId.Value); | ||
|
||
if (supportList is null) | ||
return resultData; | ||
|
||
resultData.helper_list = new List<UserSupportList>() { supportList }; | ||
|
||
// TODO: Replace with friend system once implemented | ||
resultData.helper_detail_list = new List<AtgenHelperDetailList>() | ||
{ | ||
new() | ||
{ | ||
viewer_id = supportList.viewer_id, | ||
is_friend = true, | ||
apply_send_status = 1, | ||
get_mana_point = 50 | ||
} | ||
}; | ||
|
||
return resultData; | ||
} | ||
|
||
// TODO: test with empty weapon / dragon / print slots / etc | ||
public async Task<IngameResultData> ProcessHelperDataMulti(IngameResultData resultData) | ||
{ | ||
IEnumerable<PhotonPlayer> teammates = await matchingService.GetTeammates(); | ||
|
||
IEnumerable<UserSupportList> teammateSupportLists = await this.GetTeammateSupportList( | ||
teammates | ||
); | ||
|
||
// TODO: Replace with friend system once implemented | ||
IEnumerable<AtgenHelperDetailList> teammateDetailLists = teammates.Select( | ||
x => | ||
new AtgenHelperDetailList() | ||
{ | ||
is_friend = true, | ||
viewer_id = (ulong)x.ViewerId, | ||
get_mana_point = 50, | ||
apply_send_status = 0, | ||
} | ||
); | ||
|
||
resultData.helper_list = teammateSupportLists; | ||
resultData.helper_detail_list = teammateDetailLists; | ||
|
||
return resultData; | ||
} | ||
|
||
private async Task<IEnumerable<UserSupportList>> GetTeammateSupportList( | ||
IEnumerable<PhotonPlayer> teammates | ||
) | ||
{ | ||
List<UserSupportList> helperList = new(); | ||
|
||
Dictionary<long, DbPlayerUserData> userDetails = await userDataRepository | ||
.GetMultipleViewerData(teammates.Select(x => x.ViewerId)) | ||
.ToDictionaryAsync(x => x.ViewerId, x => x); | ||
|
||
foreach (PhotonPlayer player in teammates) | ||
{ | ||
if (!userDetails.TryGetValue(player.ViewerId, out DbPlayerUserData? userData)) | ||
{ | ||
logger.LogDebug("No user details returned for player {@player}", player); | ||
continue; | ||
} | ||
|
||
using IDisposable impersonationCtx = playerIdentityService.StartUserImpersonation( | ||
userData.DeviceAccountId, | ||
userData.ViewerId | ||
); | ||
|
||
try | ||
{ | ||
UserSupportList leadUnit = await helperService.GetLeadUnit( | ||
player.PartyNoList.First() | ||
); | ||
|
||
helperList.Add(leadUnit); | ||
} | ||
catch (Exception e) | ||
{ | ||
logger.LogDebug( | ||
e, | ||
"Failed to populate multiplayer support info for player {@player}", | ||
player | ||
); | ||
continue; | ||
} | ||
} | ||
|
||
return helperList; | ||
} | ||
} |
62 changes: 0 additions & 62 deletions
62
DragaliaAPI/Features/Dungeon/Record/DungeonRecordMultiService.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.