69 lines
2.0 KiB
C#
69 lines
2.0 KiB
C#
namespace NeonSprawl.Server.Game.Quests;
|
|
|
|
/// <summary>Applies dev-only quest progress fixture writes (NEO-137 Bruno/manual QA).</summary>
|
|
public static class QuestFixtureOperations
|
|
{
|
|
/// <summary>
|
|
/// Marks each quest completed via store activate + mark-complete (no reward delivery).
|
|
/// Idempotent when a quest is already completed.
|
|
/// </summary>
|
|
public static bool TryApply(
|
|
string playerId,
|
|
QuestFixtureRequest body,
|
|
IQuestDefinitionRegistry questRegistry,
|
|
IPlayerQuestStateStore progressStore,
|
|
TimeProvider timeProvider)
|
|
{
|
|
if (body.CompletedQuestIds.Count == 0)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (!progressStore.CanWritePlayer(playerId))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
foreach (var questId in body.CompletedQuestIds)
|
|
{
|
|
if (!questRegistry.TryNormalizeKnown(questId, out var normalizedQuestId))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (progressStore.TryGetProgress(playerId, normalizedQuestId, out var existing) &&
|
|
existing.Status == QuestProgressStatus.Completed)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!progressStore.TryGetProgress(playerId, normalizedQuestId, out _))
|
|
{
|
|
if (!progressStore.TryActivate(playerId, normalizedQuestId, out _))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (progressStore.TryMarkComplete(
|
|
playerId,
|
|
normalizedQuestId,
|
|
timeProvider.GetUtcNow(),
|
|
out _))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (progressStore.TryGetProgress(playerId, normalizedQuestId, out var afterAttempt) &&
|
|
afterAttempt.Status == QuestProgressStatus.Completed)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|