diff --git a/bruno/neon-sprawl-server/quest-progress/Get quest progress after gather intro complete.bru b/bruno/neon-sprawl-server/quest-progress/Get quest progress after gather intro complete.bru index d7c5cf6..ac37ad7 100644 --- a/bruno/neon-sprawl-server/quest-progress/Get quest progress after gather intro complete.bru +++ b/bruno/neon-sprawl-server/quest-progress/Get quest progress after gather intro complete.bru @@ -5,7 +5,8 @@ meta { } docs { - NEO-129: accept gather intro, complete via three alpha gathers, GET quest-progress asserts completionRewardSummary; second GET unchanged. + NEO-129: accept gather intro, complete via alpha gathers, GET quest-progress asserts completionRewardSummary; second GET unchanged. + Tolerates craft spine (seq 5) partial progress and node_depleted on alpha when quest already completed. } script:pre-request { @@ -13,54 +14,84 @@ script:pre-request { const baseUrl = bru.getEnvVar("baseUrl") || bru.getVar("baseUrl"); const playerId = bru.getEnvVar("playerId") || bru.getVar("playerId"); const headers = { "Content-Type": "application/json" }; + const gatherQuestId = "prototype_quest_gather_intro"; + const alphaNodeId = "prototype_resource_node_alpha"; - await axios.post( - `${baseUrl}/game/players/${playerId}/quests/prototype_quest_gather_intro/accept`, - { schemaVersion: 1 }, - { headers, validateStatus: () => true }, - ); + function gatherRow(body) { + return body.quests.find((x) => x.questId === gatherQuestId); + } - await axios.post( - `${baseUrl}/game/players/${playerId}/move`, - { - schemaVersion: 1, - target: { x: 10, y: 0.9, z: -6 }, - }, - { headers }, - ); + async function getQuestProgress() { + const response = await axios.get( + `${baseUrl}/game/players/${playerId}/quest-progress`, + { validateStatus: () => true }, + ); + if (response.status !== 200) { + throw new Error(`quest-progress GET failed: ${response.status}`); + } + return response.data; + } - for (let i = 0; i < 3; i += 1) { + async function tryGatherAlpha() { const interact = await axios.post( `${baseUrl}/game/players/${playerId}/interact`, { schemaVersion: 1, - interactableId: "prototype_resource_node_alpha", + interactableId: alphaNodeId, }, { headers, validateStatus: () => true }, ); - if (interact.status !== 200 || !interact.data?.success) { - throw new Error(`expected gather interact to succeed, got ${JSON.stringify(interact.data)}`); + if (interact.status !== 200) { + throw new Error(`gather interact HTTP ${interact.status}: ${JSON.stringify(interact.data)}`); } + if (interact.data?.allowed === true) { + return; + } + if (interact.data?.reasonCode === "node_depleted") { + return; + } + throw new Error(`gather interact denied: ${JSON.stringify(interact.data)}`); } - const firstGet = await axios.get( - `${baseUrl}/game/players/${playerId}/quest-progress`, - { validateStatus: () => true }, + await axios.post( + `${baseUrl}/game/players/${playerId}/quests/${gatherQuestId}/accept`, + { schemaVersion: 1 }, + { headers, validateStatus: () => true }, ); - if (firstGet.status !== 200) { - throw new Error(`expected first GET quest-progress to return 200, got ${firstGet.status}`); - } - const firstRow = firstGet.data.quests.find( - (x) => x.questId === "prototype_quest_gather_intro", - ); - if (!firstRow || firstRow.status !== "completed" || !firstRow.completionRewardSummary) { - throw new Error( - `expected first GET gather intro completed with summary, got ${JSON.stringify(firstRow)}`, + + let progress = await getQuestProgress(); + let row = gatherRow(progress); + if (!row || row.status === "not_started") { + await axios.post( + `${baseUrl}/game/players/${playerId}/move`, + { + schemaVersion: 1, + target: { x: 10, y: 0.9, z: -6 }, + }, + { headers }, ); } + + for (let attempt = 0; attempt < 8; attempt += 1) { + progress = await getQuestProgress(); + row = gatherRow(progress); + if (row?.status === "completed" && row.completionRewardSummary) { + break; + } + await tryGatherAlpha(); + } + + progress = await getQuestProgress(); + row = gatherRow(progress); + if (!row || row.status !== "completed" || !row.completionRewardSummary) { + throw new Error( + `expected gather intro completed with summary, got ${JSON.stringify(row)}`, + ); + } + bru.setVar( "firstGatherCompletionRewardSummary", - JSON.stringify(firstRow.completionRewardSummary), + JSON.stringify(row.completionRewardSummary), ); }