121 lines
3.9 KiB
C#
121 lines
3.9 KiB
C#
namespace NeonSprawl.Server.Game.Quests;
|
|
|
|
/// <summary>Maps <c>GET /game/world/quest-definitions</c> (NEO-115).</summary>
|
|
public static class QuestDefinitionsWorldApi
|
|
{
|
|
public static WebApplication MapQuestDefinitionsWorldApi(this WebApplication app)
|
|
{
|
|
app.MapGet(
|
|
"/game/world/quest-definitions",
|
|
(IQuestDefinitionRegistry questRegistry) =>
|
|
{
|
|
var defs = questRegistry.GetDefinitionsInIdOrder();
|
|
var quests = new List<QuestDefinitionJson>(defs.Count);
|
|
foreach (var d in defs)
|
|
{
|
|
quests.Add(
|
|
new QuestDefinitionJson
|
|
{
|
|
Id = d.Id,
|
|
DisplayName = d.DisplayName,
|
|
PrerequisiteQuestIds = d.PrerequisiteQuestIds,
|
|
Steps = MapSteps(d.Steps),
|
|
FactionGateRules = MapFactionGateRules(d.FactionGateRules),
|
|
});
|
|
}
|
|
|
|
return Results.Json(
|
|
new QuestDefinitionsListResponse
|
|
{
|
|
SchemaVersion = QuestDefinitionsListResponse.CurrentSchemaVersion,
|
|
Quests = quests,
|
|
});
|
|
});
|
|
|
|
return app;
|
|
}
|
|
|
|
private static List<QuestFactionGateRuleJson>? MapFactionGateRules(IReadOnlyList<FactionGateRuleRow> rules)
|
|
{
|
|
if (rules.Count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var list = new List<QuestFactionGateRuleJson>(rules.Count);
|
|
foreach (var rule in rules)
|
|
{
|
|
list.Add(
|
|
new QuestFactionGateRuleJson
|
|
{
|
|
FactionId = rule.FactionId,
|
|
MinStanding = rule.MinStanding,
|
|
});
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
private static List<QuestStepDefinitionJson> MapSteps(IReadOnlyList<QuestStepDefRow> steps)
|
|
{
|
|
var list = new List<QuestStepDefinitionJson>(steps.Count);
|
|
foreach (var step in steps)
|
|
{
|
|
list.Add(
|
|
new QuestStepDefinitionJson
|
|
{
|
|
Id = step.Id,
|
|
DisplayName = step.DisplayName,
|
|
Objectives = MapObjectives(step.Objectives),
|
|
});
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
private static List<QuestObjectiveDefinitionJson> MapObjectives(IReadOnlyList<QuestObjectiveDefRow> objectives)
|
|
{
|
|
var list = new List<QuestObjectiveDefinitionJson>(objectives.Count);
|
|
foreach (var objective in objectives)
|
|
{
|
|
list.Add(MapObjective(objective));
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
private static QuestObjectiveDefinitionJson MapObjective(QuestObjectiveDefRow objective) =>
|
|
objective.Kind switch
|
|
{
|
|
"gather_item" or "inventory_has_item" => new QuestObjectiveDefinitionJson
|
|
{
|
|
Id = objective.Id,
|
|
Kind = objective.Kind,
|
|
ItemId = objective.ItemId,
|
|
Quantity = objective.Quantity,
|
|
},
|
|
"craft_recipe" => new QuestObjectiveDefinitionJson
|
|
{
|
|
Id = objective.Id,
|
|
Kind = objective.Kind,
|
|
RecipeId = objective.RecipeId,
|
|
Quantity = objective.Quantity,
|
|
},
|
|
"encounter_complete" => new QuestObjectiveDefinitionJson
|
|
{
|
|
Id = objective.Id,
|
|
Kind = objective.Kind,
|
|
EncounterId = objective.EncounterId,
|
|
},
|
|
_ => new QuestObjectiveDefinitionJson
|
|
{
|
|
Id = objective.Id,
|
|
Kind = objective.Kind,
|
|
ItemId = objective.ItemId,
|
|
Quantity = objective.Quantity,
|
|
RecipeId = objective.RecipeId,
|
|
EncounterId = objective.EncounterId,
|
|
},
|
|
};
|
|
}
|