Fix Archive Story Scenario completion (#63)

This commit is contained in:
Vi-brance
2025-11-08 11:39:25 +08:00
committed by GitHub
parent 795f18445c
commit f09d959220
5 changed files with 54 additions and 58 deletions

View File

@@ -10,8 +10,8 @@ namespace EpinelPS.LobbyServer.Archive
ReqClearArchiveStage req = await ReadData<ReqClearArchiveStage>(); // has fields EventId, StageId, BattleResult
int evid = req.EventId;
int stgid = req.StageId;
int result = req.BattleResult; // if 2 add to event info as last stage
User user = GetUser() ?? throw new Exception("User not found.");
int result = req.BattleResult;
User user = GetUser();
// Check if the EventInfo exists for the given EventId
if (!user.EventInfo.TryGetValue(evid, out EventData? eventData))
@@ -19,13 +19,12 @@ namespace EpinelPS.LobbyServer.Archive
throw new Exception($"Event with ID {evid} not found.");
}
// Update the EventData if BattleResult is 2
if (result == 1)
// Update the EventData if BattleResult is 1
if (result == 1 && !eventData.ClearedStages.Contains(stgid))
{
eventData.ClearedStages.Add(stgid);
// Update the LastStage in EventData
eventData.LastStage = stgid;
}
JsonDb.Save();
ResClearArchiveStage response = new();

View File

@@ -11,16 +11,19 @@ namespace EpinelPS.LobbyServer.Archive
int evid = req.EventId;
int stgid = req.StageId;
User user = GetUser() ?? throw new Exception("User not found.");
User user = GetUser();
// Check if the EventInfo exists for the given EventId
if (!user.EventInfo.TryGetValue(evid, out EventData? eventData))
{
throw new Exception($"Event with ID {evid} not found.");
}
// Update the LastStage in EventData
eventData.LastStage = stgid;
if (!eventData.ClearedStages.Contains(stgid))
{
eventData.ClearedStages.Add(stgid);
// Update the LastStage in EventData
eventData.LastStage = stgid;
}
JsonDb.Save();
ResFastClearArchiveStage response = new();

View File

@@ -1,7 +1,4 @@
using EpinelPS.Utils;
using EpinelPS.Data; // Ensure this namespace is included
namespace EpinelPS.LobbyServer.Archive
{
[PacketPath("/archive/scenario/getnonresettable")]
@@ -9,41 +6,16 @@ namespace EpinelPS.LobbyServer.Archive
{
protected override async Task HandleAsync()
{
ReqGetNonResettableArchiveScenario req = await ReadData<ReqGetNonResettableArchiveScenario>(); // req has EventId field
int evId = req.EventId;
ReqGetNonResettableArchiveScenario req = await ReadData<ReqGetNonResettableArchiveScenario>();
ResGetNonResettableArchiveScenario response = new();
// Access the GameData instance
GameData gameData = GameData.Instance;
if (evId == 130002)
User user = GetUser();
foreach (var (evtId, evtData) in user.EventInfo)
{
// Directly use the archiveEventQuestRecords dictionary
foreach (ArchiveEventQuestRecord_Raw record in gameData.archiveEventQuestRecords.Values)
if (evtId == req.EventId)
{
if (record.EventQuestManagerId == evId)
{
// Add the end_scenario_Id to the ScenarioIdList
if (!string.IsNullOrEmpty(record.EndScenarioId))
{
response.ScenarioIdList.Add(record.EndScenarioId);
}
}
}
}
else
{
// Directly use the archiveEventStoryRecords dictionary
foreach (ArchiveEventStoryRecord record in gameData.archiveEventStoryRecords.Values)
{
if (record.EventId == evId)
{
// Add the PrologueScenario to the ScenarioIdList
if (!string.IsNullOrEmpty(record.PrologueScenario))
{
response.ScenarioIdList.Add(record.PrologueScenario);
}
}
response.ScenarioIdList.AddRange(evtData.CompletedScenarios);
break;
}
}

View File

@@ -10,11 +10,21 @@ namespace EpinelPS.LobbyServer.Archive
ReqGetResettableArchiveScenario req = await ReadData<ReqGetResettableArchiveScenario>();
ResGetResettableArchiveScenario response = new(); // has ScenarioIdList field that takes in strings
// Retrieve stage IDs from GameData
List<string> stageIds = [.. GameData.Instance.archiveEventDungeonStageRecords.Values.Select(record => record.StageId.ToString())];
// Add them to the response
response.ScenarioIdList.Add(stageIds);
GameData gameData = GameData.Instance;
User user = GetUser();
foreach (ArchiveEventStoryRecord record in gameData.archiveEventStoryRecords.Values)
{
// Add the PrologueScenario to the ScenarioIdList
if (record.EventId == req.EventId && !string.IsNullOrEmpty(record.PrologueScenario))
{
if (user.EventInfo.TryGetValue(req.EventId, out EventData? evtData) &&
evtData.CompletedScenarios.Contains(record.PrologueScenario))
{
response.ScenarioIdList.Add(record.PrologueScenario);
}
break;
}
}
await WriteDataAsync(response);
}

View File

@@ -1,5 +1,4 @@
using EpinelPS.Utils;
namespace EpinelPS.LobbyServer.LobbyUser
{
[PacketPath("/user/scenario/exist")]
@@ -13,21 +12,34 @@ namespace EpinelPS.LobbyServer.LobbyUser
ResExistScenario response = new();
User user = GetUser();
foreach (string? item in req.ScenarioGroupIds)
{
foreach (string completed in user.CompletedScenarios)
if (FindScenarioInMainStages(item) || FindScenarioInArchiveStages(item))
{
// story thingy was completed
if (completed == item)
{
response.ExistGroupIds.Add(item);
}
response.ExistGroupIds.Add(item);
}
}
await WriteDataAsync(response);
}
private bool FindScenarioInMainStages(string scenarioGroupId)
{
User user = GetUser();
return user.CompletedScenarios.Contains(scenarioGroupId);
}
private bool FindScenarioInArchiveStages(string scenarioGroupId)
{
User user = GetUser();
foreach (EventData evtData in user.EventInfo.Values)
{
if (evtData.CompletedScenarios.Contains(scenarioGroupId))
{
return true;
}
}
return false;
}
}
}