Bind Golden Path deliveries to exact Reputation quest claims

This commit is contained in:
unimatrixgit 2026-12-05 15:01:24 +01:00
commit 1a011deb2b
10 changed files with 59 additions and 13 deletions

View file

@ -447,7 +447,7 @@ const rows=[
{
"id": "POL-LETO-RETURN",
"title": "The Sea That Walks",
"objective": "Return to Sietch Tabr and bring the water ring and the sandtrout token to the Steward.",
"objective": "Return to Sietch Tabr and tell the Steward what you learned along the Golden Path.",
"metric": "leto-contact-finale",
"target": 1,
"requires": [
@ -476,7 +476,7 @@ const rows=[
"dialogue": {
"version": 1,
"introduction": "Everything has led back to the sand. The trail of Leto II leads to the old sietch, and the boy already knows you are coming.",
"context": "Return to Sietch Tabr and bring the water ring and the sandtrout token to the Steward.",
"context": "Return to Sietch Tabr and tell the Steward what you learned along the Golden Path.",
"turnIn": "You have found the trace of a boy who will become more than a man. The Search is over, but the Golden Path is long."
},
"itemReward": "leto/golden-path-seal"

View file

@ -4,6 +4,8 @@ export const POL_SUPPLY_TASKS=Object.freeze([
{id:'POL-FREMEN-01',kind:'supply_water',metric:'pol-water-supply',item:'jerboa_water_vial',quantity:6,label:'Water Vials',server:'arrakis',role:'stilgar',contact:'Stilgar',faction:'fremen'},
{id:'POL-FREMEN-03',kind:'supply_sietch',metric:'pol-sietch-service',item:'farmers_bucket',quantity:1,label:"Farmer’s Bucket",server:'arrakis',role:'stilgar',contact:'Stilgar',faction:'fremen'},
{id:'POL-COMPANY-01',kind:'supply_company',metric:'pol-procurement',item:'spice',quantity:8,label:'raw Spice',server:'sigma-draconis-iv',role:'roma_atani',contact:'Roma Atani'},
{id:'POL-ORDOS-02',faction:'ordos',kind:'supply_ordos',metric:'pol-strategic-procurement',item:'refined_spice',quantity:4,label:'Refined Spice',server:'sigma-draconis-iv',role:'roma_atani',contact:'Roma Atani'}
{id:'POL-ORDOS-02',faction:'ordos',kind:'supply_ordos',metric:'pol-strategic-procurement',item:'refined_spice',quantity:4,label:'Refined Spice',server:'sigma-draconis-iv',role:'roma_atani',contact:'Roma Atani'},
{id:'POL-LETO-WATER',kind:'leto_gather_water',metric:'leto-gather-water',item:'bottled_water',quantity:12,label:'Water Bottles',server:'arrakis',role:'leto_waterkeeper',contact:'Keeper of the Water Basin'},
{id:'POL-LETO-JACURUTU',kind:'leto_gather_spice',metric:'leto-gather-spice',item:'spice',quantity:16,label:'raw Spice',server:'arrakis',role:'leto_ecologist',contact:'Sietch Ecologist'}
].map(Object.freeze));
export const polSupplyTask=id=>POL_SUPPLY_TASKS.find(t=>t.id===id)||null;

File diff suppressed because one or more lines are too long

View file

@ -56,7 +56,7 @@ export function createGameQuestEventsAPI(db,keys,settings,{clock=Date.now,events
if(isHusbandry&&(!Number.isSafeInteger(input.quantity)||input.quantity<1||(turnin?input.quantity!==turnin.units:input.quantity>(['husbandry_leather','husbandry_collect_egg','husbandry_collect_hide','husbandry_hide_paste','husbandry_spice_paste','husbandry_spice_bread','husbandry_spice_cake'].includes(input.kind)?64:1))))return json({message:'Invalid husbandry observation quantity'},400);
if(!events)return json({message:'Quest evidence is unavailable'},503);
let deliveryReference=null;if(isDelivery){if(!db.smugglerContractsEnabled)return json({message:'Smuggling contract evidence is unavailable'},503);try{deliveryReference=smugglerDeliveryReference(input);}catch{return json({message:'Invalid native smuggling contract receipt'},400);}}
if(supply&&input.server!==supply.server)return json({message:'Wrong supply mission world'},400);
if(supply&&(input.server!==supply.server||isLeto&&input.quantity!==supply.quantity))return json({message:'Wrong supply mission world'},400);
if(isBounty&&!db.bountyQuestsEnabled)return json({message:'Bounty job evidence is unavailable'},503);
if(isBounty&&(!validUuid(input.source)||bountyEvent(input.kind,input.source.toLowerCase())!==input.eventId.toLowerCase()))return json({message:'Invalid native bounty receipt'},400);
try{

View file

@ -1,4 +1,4 @@
import {letoContact} from './leto-quest-evidence.mjs';
import {letoContact,letoRewards} from './leto-quest-evidence.mjs';
import {housePrologueState,HOUSE_MENTOR_CONTACTS} from './house-prologue.mjs';
import {gameAuthorized,validUuid,json} from './game-link.mjs';
import {questChannel} from '../control-panel/public/cp-v2/cp-v2-quest-channels.mjs';
@ -28,6 +28,14 @@ export function createGameQuestsAPI(db,settings,{personal=null,pol=null,starter=
let input;
try{const chunks=[];let size=0;while(true){const {done,value}=await reader.read();if(done)break;size+=value.byteLength;if(size>4096){await reader.cancel();return json({message:'Quest request too large.'},413);}chunks.push(value);}input=JSON.parse(Buffer.concat(chunks).toString('utf8'));}
catch{return json({message:'Invalid quest action.'},400);}finally{reader.releaseLock();}
if(input?.action==='read_leto_rewards'){
if(!db.letoQuestEnabled)return json({message:'The Golden Path is unavailable.'},503);
if(Array.isArray(input)||Object.keys(input).length!==2||!validUuid(input.uuid))return json({message:'A player UUID is required.'},400);
try{
const player=await resolve(input.uuid);if(!player)return json({message:'Link an active personal Minecraft account first.'},403);
return json({ok:true,uuid:input.uuid.toLowerCase(),items:await letoRewards(db,player.id)});
}catch{return json({message:'The Golden Path rewards remain available for retry.'},503);}
}
if(input?.action==='login_settle'){
if(!input||typeof input!=='object'||Array.isArray(input)||Object.keys(input).some(k=>!['action','uuid'].includes(k))||!validUuid(input.uuid))return json({message:'A player UUID is required.'},400);
try{

View file

@ -1,3 +1,4 @@
import {starterIdentity} from './starter-kit-native-design.mjs';
import { LETO_QUESTS } from '../control-panel/public/cp-v2/cp-v2-leto-quests.mjs';
const common = ['eventId', 'uuid', 'kind', 'server', 'occurredAt', 'dimension'];
@ -33,3 +34,12 @@ const contacts=Object.freeze({
export function letoContact(key){
return Object.hasOwn(contacts,key)?{key,name:contacts[key],role:'The Golden Path'}:null;
}
const rewardByQuest=new Map(LETO_QUESTS.filter(quest=>quest.itemReward).map(quest=>[quest.id,quest.itemReward]));
/** Only a consumed, linked Reputation quest claim entitles the player to a reward item. */
export async function letoRewards(db,accountId){
const quests=[...rewardByQuest.keys()];
const rows=await db.query("SELECT s.definition_id,s.key_id,k.scope_id FROM jarvis_pol_quest_states s JOIN jarvis_pol_quest_claims c ON c.key_id=s.key_id AND c.account_id=s.account_id JOIN organisation_keys k ON k.id=s.key_id AND k.account_id=s.account_id WHERE s.account_id=? AND s.season_id='S01' AND s.state='claimed' AND k.key_type='quest' AND k.used_at IS NOT NULL AND k.revoked_at IS NULL AND s.definition_id IN ("+quests.map(()=>'?').join(',')+") ORDER BY c.claimed_at,s.definition_id",[accountId,...quests]);
return rows.filter(row=>row.scope_id==='S01:POL_'+row.definition_id).map(row=>({receiptId:starterIdentity('golden-path-item:'+row.key_id),itemId:rewardByQuest.get(row.definition_id)}));
}

View file

@ -61,7 +61,8 @@ export const ensureBountyQuestPolicy=(db,keys,options={})=>ensureProgressionPoli
export const ensureSpiceUpgradeQuestPolicy=(db,keys,options={})=>ensureProgressionPolicy(polProgressionStore(db),polPolicyKeys(keys),{...options,policy:{...POL_XP_POLICY,version:9},definitions:POL_QUEST_DEFINITIONS.filter(d=>d.branch==='spice-upgrading')});
export const ensureLetoQuestPolicy=(db,keys,options={})=>ensureProgressionPolicy(polProgressionStore(db),polPolicyKeys(keys),{
...options,policy:{...POL_XP_POLICY,version:11},definitions:POL_QUEST_DEFINITIONS.filter(d=>d.branch==='leto-search')
...options,policy:{...POL_XP_POLICY,version:11},definitions:POL_QUEST_DEFINITIONS.filter(d=>d.branch==='leto-search'),
rewardForDefinition:d=>({schema:'pol-dm-reward-v1',amountMinor:d.amountMinor})
});
// Add the physical merge without replaying v4 or overwriting existing flight rewards.

View file

@ -14,6 +14,7 @@
{"id":"lanes","title":"Lanes and Shadows","tagline":"Guild lanes, smugglers' routes and hunted bounties.","accent":"#b07a4a","icon":"quests/lanes","branches":["guild","smugglers","bounty-jobs"]},
{"id":"contracts","title":"Contracts of the Realm","tagline":"Work for clan and company.","accent":"#c3a060","icon":"quests/contracts","branches":["clan","company"]},
{"id":"wings","title":"Wings across the Realms","tagline":"Five worlds. One elytra.","accent":"#e0c27c","icon":"quests/wings","branches":["elytra"]},
{"id":"campaign","title":"Campaign Banners","tagline":"Banners raised, ground held.","accent":"#b5653f","icon":"quests/campaign","branches":["war-service"]}
{"id":"campaign","title":"Campaign Banners","tagline":"Banners raised, ground held.","accent":"#b5653f","icon":"quests/campaign","branches":["war-service"]},
{"id":"golden-path","title":"The Golden Path","tagline":"Seek the son of Muad'Dib across every world.","accent":"#e0b04a","icon":"quests/golden-path","branches":["leto-search"]}
]
}

View file

@ -53,6 +53,8 @@ test('all 13 chapters advance and claim in sequence from authenticated evidence'
const {initializePOLProgression,ensurePOLProgressionPolicy,ensureLetoQuestPolicy}=await import('../node/progression-pol.mjs');
const {initializePOLActivityEvents}=await import('../node/pol-activity-events.mjs');
const {createGameQuestEventsAPI}=await import('../node/game-quest-events.mjs');
const {createGameQuestsAPI}=await import('../node/game-quests.mjs');
const {supplyEvent,supplyRequest}=await import('../node/pol-supply-evidence.mjs');
const {createPOLProgressionRuntime}=await import('../node/progression-pol-runtime.mjs');
const f=await systemCharacterFixture();try{
const actor=f.people.Member,uuid=randomUUID(),clock=()=>2000,secret='golden-path-fixture-secret-at-least-32-characters';
@ -62,7 +64,7 @@ test('all 13 chapters advance and claim in sequence from authenticated evidence'
assert.equal((await f.db.first("SELECT COUNT(*) n FROM jarvis_pol_quest_config WHERE definition_id LIKE 'POL-LETO-%'")).n,0);
await ensureLetoQuestPolicy(f.db,f.keys,{clock});await ensureLetoQuestPolicy(f.db,f.keys,{clock});
assert.equal((await f.db.first("SELECT COUNT(*) n FROM jarvis_pol_quest_config WHERE definition_id LIKE 'POL-LETO-%'")).n,13);
await initializePOLActivityEvents(f.db);f.db.polActivityEventsEnabled=true;
await initializePOLActivityEvents(f.db);f.db.polActivityEventsEnabled=true;f.db.polSupplyEnabled=true;
await f.db.query('UPDATE site_game_links SET minecraft_uuid=? WHERE user_id=?',[uuid,actor.id]);
const api=createGameQuestEventsAPI(f.db,f.keys,{GAME_LINK_SECRET:secret},{clock});
const send=(input,authenticated=true)=>api(new Request('https://cp.dunerealms.com/internal/game/quest-events',{
@ -77,12 +79,28 @@ test('all 13 chapters advance and claim in sequence from authenticated evidence'
assert.equal((await send(first)).status,503);
assert(!(await createPOLProgressionRuntime(f.db,f.keys,{clock}).quests.list(actor)).quests.some(q=>q.branch===LETO_BRANCH.id));
f.db.letoQuestEnabled=true;
const quests=createPOLProgressionRuntime(f.db,f.keys,{clock}).quests;
const runtime=createPOLProgressionRuntime(f.db,f.keys,{clock});
const quests=runtime.quests;
const questApi=createGameQuestsAPI(f.db,{GAME_LINK_SECRET:secret},{pol:runtime});
const callQuest=(body,authenticated=true)=>questApi(new Request('https://cp.dunerealms.com/internal/game/quests',{
method:'POST',headers:{...(authenticated?{authorization:'Bearer '+secret}:{}),'content-type':'application/json'},body:JSON.stringify(body)
}));
const items={action:'read_leto_rewards',uuid};
assert.equal((await callQuest(items,false)).status,401);
assert.deepEqual((await (await callQuest(items)).json()).items,[]);
const runner=await (await callQuest({action:'read',uuid,kind:'pol',npcRole:'leto_runner'})).json();
assert.equal(runner.npcContact.name,'Ishaq the Runner');
for(const [index,definition] of LETO_QUESTS.entries()){
const page=await quests.list(actor);
assert.equal(page.quests.find(q=>q.id===definition.id).canStart,true,definition.id);
if(index+1<LETO_QUESTS.length)assert.equal(page.quests.find(q=>q.id===LETO_QUESTS[index+1].id).canStart,false);
const evidence=event(definition);
if(['POL-LETO-WATER','POL-LETO-JACURUTU'].includes(definition.id)){
assert.equal((await send(evidence)).status,409);
await quests.start(actor,{definitionId:definition.id});
evidence.eventId=supplyEvent(evidence.kind,supplyRequest(actor.id,'S01',definition.id));
assert.equal((await send({...evidence,quantity:evidence.quantity-1})).status,400);
}
assert.equal((await send({...evidence,dimension:'CUSTOM'})).status,400);
const accepted=await send(evidence);assert.equal(accepted.status,200,await accepted.text());
assert.equal((await (await send(evidence)).json()).replayed,true);
@ -92,6 +110,12 @@ test('all 13 chapters advance and claim in sequence from authenticated evidence'
assert.equal(current.canClaim,true,definition.id);
await quests.claim(actor,{definitionId:current.id,revision:current.revision,requestId:randomUUID()});
}
const entitled=(await (await callQuest(items)).json()).items;
assert.equal(entitled.length,8);
assert.equal(new Set(entitled.map(item=>item.receiptId)).size,8);
assert.deepEqual(new Set(entitled.map(item=>item.itemId)),new Set(LETO_QUESTS.flatMap(q=>q.itemReward?[q.itemReward]:[])));
assert.deepEqual((await (await callQuest(items)).json()).items,entitled);
assert.equal((await callQuest({...items,uuid:randomUUID()})).status,403);
const done=await quests.list(actor);
assert.equal(done.quests.filter(q=>q.branch===LETO_BRANCH.id&&q.state==='claimed').length,13);
assert.equal(done.profile.totalXP,LETO_QUESTS.reduce((total,q)=>total+q.xp,0));

View file

@ -12,8 +12,8 @@ test('every known quest branch belongs to exactly one themed category',()=>{
const seen=new Map();
for(const c of QUEST_CATEGORIES)for(const b of c.branches){assert.ok(!seen.has(b),'branch twice: '+b);seen.set(b,c.id);}
for(const b of known)assert.notEqual(categoryFor(b),OTHER_CATEGORY,'unmapped branch '+b);
assert.equal(QUEST_CATEGORIES.length,13);
assert.equal(new Set(QUEST_CATEGORIES.map(c=>c.id)).size,13);
assert.equal(QUEST_CATEGORIES.length,14);
assert.equal(new Set(QUEST_CATEGORIES.map(c=>c.id)).size,14);
});
test('the website catalogue matches the in-game catalogue file',()=>{
const game=JSON.parse(fs.readFileSync(new URL('./fixtures/quest-categories.plugin.json',import.meta.url),'utf8')).categories;