mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-16 17:04:44 +01:00
Fix Archive Story Scenario completion (#63)
This commit is contained in:
@@ -10,8 +10,8 @@ namespace EpinelPS.LobbyServer.Archive
|
|||||||
ReqClearArchiveStage req = await ReadData<ReqClearArchiveStage>(); // has fields EventId, StageId, BattleResult
|
ReqClearArchiveStage req = await ReadData<ReqClearArchiveStage>(); // has fields EventId, StageId, BattleResult
|
||||||
int evid = req.EventId;
|
int evid = req.EventId;
|
||||||
int stgid = req.StageId;
|
int stgid = req.StageId;
|
||||||
int result = req.BattleResult; // if 2 add to event info as last stage
|
int result = req.BattleResult;
|
||||||
User user = GetUser() ?? throw new Exception("User not found.");
|
User user = GetUser();
|
||||||
|
|
||||||
// Check if the EventInfo exists for the given EventId
|
// Check if the EventInfo exists for the given EventId
|
||||||
if (!user.EventInfo.TryGetValue(evid, out EventData? eventData))
|
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.");
|
throw new Exception($"Event with ID {evid} not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the EventData if BattleResult is 2
|
// Update the EventData if BattleResult is 1
|
||||||
if (result == 1)
|
if (result == 1 && !eventData.ClearedStages.Contains(stgid))
|
||||||
{
|
{
|
||||||
|
eventData.ClearedStages.Add(stgid);
|
||||||
// Update the LastStage in EventData
|
// Update the LastStage in EventData
|
||||||
eventData.LastStage = stgid;
|
eventData.LastStage = stgid;
|
||||||
|
|
||||||
}
|
}
|
||||||
JsonDb.Save();
|
JsonDb.Save();
|
||||||
ResClearArchiveStage response = new();
|
ResClearArchiveStage response = new();
|
||||||
|
|||||||
@@ -11,16 +11,19 @@ namespace EpinelPS.LobbyServer.Archive
|
|||||||
int evid = req.EventId;
|
int evid = req.EventId;
|
||||||
int stgid = req.StageId;
|
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
|
// Check if the EventInfo exists for the given EventId
|
||||||
if (!user.EventInfo.TryGetValue(evid, out EventData? eventData))
|
if (!user.EventInfo.TryGetValue(evid, out EventData? eventData))
|
||||||
{
|
{
|
||||||
throw new Exception($"Event with ID {evid} not found.");
|
throw new Exception($"Event with ID {evid} not found.");
|
||||||
}
|
}
|
||||||
// Update the LastStage in EventData
|
if (!eventData.ClearedStages.Contains(stgid))
|
||||||
eventData.LastStage = stgid;
|
{
|
||||||
|
eventData.ClearedStages.Add(stgid);
|
||||||
|
// Update the LastStage in EventData
|
||||||
|
eventData.LastStage = stgid;
|
||||||
|
}
|
||||||
JsonDb.Save();
|
JsonDb.Save();
|
||||||
ResFastClearArchiveStage response = new();
|
ResFastClearArchiveStage response = new();
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using EpinelPS.Utils;
|
using EpinelPS.Utils;
|
||||||
using EpinelPS.Data; // Ensure this namespace is included
|
|
||||||
|
|
||||||
|
|
||||||
namespace EpinelPS.LobbyServer.Archive
|
namespace EpinelPS.LobbyServer.Archive
|
||||||
{
|
{
|
||||||
[PacketPath("/archive/scenario/getnonresettable")]
|
[PacketPath("/archive/scenario/getnonresettable")]
|
||||||
@@ -9,41 +6,16 @@ namespace EpinelPS.LobbyServer.Archive
|
|||||||
{
|
{
|
||||||
protected override async Task HandleAsync()
|
protected override async Task HandleAsync()
|
||||||
{
|
{
|
||||||
ReqGetNonResettableArchiveScenario req = await ReadData<ReqGetNonResettableArchiveScenario>(); // req has EventId field
|
ReqGetNonResettableArchiveScenario req = await ReadData<ReqGetNonResettableArchiveScenario>();
|
||||||
int evId = req.EventId;
|
|
||||||
ResGetNonResettableArchiveScenario response = new();
|
ResGetNonResettableArchiveScenario response = new();
|
||||||
|
|
||||||
// Access the GameData instance
|
User user = GetUser();
|
||||||
GameData gameData = GameData.Instance;
|
foreach (var (evtId, evtData) in user.EventInfo)
|
||||||
|
|
||||||
if (evId == 130002)
|
|
||||||
{
|
{
|
||||||
// Directly use the archiveEventQuestRecords dictionary
|
if (evtId == req.EventId)
|
||||||
foreach (ArchiveEventQuestRecord_Raw record in gameData.archiveEventQuestRecords.Values)
|
|
||||||
{
|
{
|
||||||
if (record.EventQuestManagerId == evId)
|
response.ScenarioIdList.AddRange(evtData.CompletedScenarios);
|
||||||
{
|
break;
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,21 @@ namespace EpinelPS.LobbyServer.Archive
|
|||||||
ReqGetResettableArchiveScenario req = await ReadData<ReqGetResettableArchiveScenario>();
|
ReqGetResettableArchiveScenario req = await ReadData<ReqGetResettableArchiveScenario>();
|
||||||
ResGetResettableArchiveScenario response = new(); // has ScenarioIdList field that takes in strings
|
ResGetResettableArchiveScenario response = new(); // has ScenarioIdList field that takes in strings
|
||||||
|
|
||||||
// Retrieve stage IDs from GameData
|
GameData gameData = GameData.Instance;
|
||||||
List<string> stageIds = [.. GameData.Instance.archiveEventDungeonStageRecords.Values.Select(record => record.StageId.ToString())];
|
User user = GetUser();
|
||||||
|
foreach (ArchiveEventStoryRecord record in gameData.archiveEventStoryRecords.Values)
|
||||||
// Add them to the response
|
{
|
||||||
response.ScenarioIdList.Add(stageIds);
|
// 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);
|
await WriteDataAsync(response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using EpinelPS.Utils;
|
using EpinelPS.Utils;
|
||||||
|
|
||||||
namespace EpinelPS.LobbyServer.LobbyUser
|
namespace EpinelPS.LobbyServer.LobbyUser
|
||||||
{
|
{
|
||||||
[PacketPath("/user/scenario/exist")]
|
[PacketPath("/user/scenario/exist")]
|
||||||
@@ -13,21 +12,34 @@ namespace EpinelPS.LobbyServer.LobbyUser
|
|||||||
|
|
||||||
ResExistScenario response = new();
|
ResExistScenario response = new();
|
||||||
|
|
||||||
User user = GetUser();
|
|
||||||
|
|
||||||
foreach (string? item in req.ScenarioGroupIds)
|
foreach (string? item in req.ScenarioGroupIds)
|
||||||
{
|
{
|
||||||
foreach (string completed in user.CompletedScenarios)
|
if (FindScenarioInMainStages(item) || FindScenarioInArchiveStages(item))
|
||||||
{
|
{
|
||||||
// story thingy was completed
|
response.ExistGroupIds.Add(item);
|
||||||
if (completed == item)
|
|
||||||
{
|
|
||||||
response.ExistGroupIds.Add(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await WriteDataAsync(response);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user