diff --git a/website/control-panel/public/cp-v2/art/quests/golden-path-banner.png b/website/control-panel/public/cp-v2/art/quests/golden-path-banner.png new file mode 100644 index 00000000..22784097 Binary files /dev/null and b/website/control-panel/public/cp-v2/art/quests/golden-path-banner.png differ diff --git a/website/control-panel/public/cp-v2/art/quests/golden-path-icon.png b/website/control-panel/public/cp-v2/art/quests/golden-path-icon.png new file mode 100644 index 00000000..ebeb535e Binary files /dev/null and b/website/control-panel/public/cp-v2/art/quests/golden-path-icon.png differ diff --git a/website/control-panel/public/cp-v2/cp-v2-leto-quests.mjs b/website/control-panel/public/cp-v2/cp-v2-leto-quests.mjs index 1841d086..7b55e4f1 100644 --- a/website/control-panel/public/cp-v2/cp-v2-leto-quests.mjs +++ b/website/control-panel/public/cp-v2/cp-v2-leto-quests.mjs @@ -13,10 +13,10 @@ const rows=[ "branch": "leto-search", "season": "S01", "revision": 1, - "optional": true, + "optional": false, "verifiedOnly": true, "xpType": "pol", - "issuer": "stilgar_tabr", + "issuer": "stilgar", "issuerName": "Sietch Tabr", "xp": 150, "amountMinor": 15000, @@ -50,10 +50,10 @@ const rows=[ "branch": "leto-search", "season": "S01", "revision": 1, - "optional": true, + "optional": false, "verifiedOnly": true, "xpType": "pol", - "issuer": "stilgar_tabr", + "issuer": "stilgar", "issuerName": "Sietch Tabr", "xp": 200, "amountMinor": 15000, @@ -87,10 +87,10 @@ const rows=[ "branch": "leto-search", "season": "S01", "revision": 1, - "optional": true, + "optional": false, "verifiedOnly": true, "xpType": "pol", - "issuer": "stilgar_tabr", + "issuer": "stilgar", "issuerName": "Sietch Tabr", "xp": 250, "amountMinor": 20000, @@ -124,10 +124,10 @@ const rows=[ "branch": "leto-search", "season": "S01", "revision": 1, - "optional": true, + "optional": false, "verifiedOnly": true, "xpType": "pol", - "issuer": "stilgar_tabr", + "issuer": "stilgar", "issuerName": "Sietch Tabr", "xp": 300, "amountMinor": 25000, @@ -161,10 +161,10 @@ const rows=[ "branch": "leto-search", "season": "S01", "revision": 1, - "optional": true, + "optional": false, "verifiedOnly": true, "xpType": "pol", - "issuer": "stilgar_tabr", + "issuer": "stilgar", "issuerName": "Sietch Tabr", "xp": 350, "amountMinor": 25000, @@ -198,10 +198,10 @@ const rows=[ "branch": "leto-search", "season": "S01", "revision": 1, - "optional": true, + "optional": false, "verifiedOnly": true, "xpType": "pol", - "issuer": "stilgar_tabr", + "issuer": "stilgar", "issuerName": "Sietch Tabr", "xp": 350, "amountMinor": 25000, @@ -235,10 +235,10 @@ const rows=[ "branch": "leto-search", "season": "S01", "revision": 1, - "optional": true, + "optional": false, "verifiedOnly": true, "xpType": "pol", - "issuer": "stilgar_tabr", + "issuer": "stilgar", "issuerName": "Sietch Tabr", "xp": 450, "amountMinor": 30000, @@ -272,10 +272,10 @@ const rows=[ "branch": "leto-search", "season": "S01", "revision": 1, - "optional": true, + "optional": false, "verifiedOnly": true, "xpType": "pol", - "issuer": "stilgar_tabr", + "issuer": "stilgar", "issuerName": "Sietch Tabr", "xp": 500, "amountMinor": 35000, @@ -309,10 +309,10 @@ const rows=[ "branch": "leto-search", "season": "S01", "revision": 1, - "optional": true, + "optional": false, "verifiedOnly": true, "xpType": "pol", - "issuer": "stilgar_tabr", + "issuer": "stilgar", "issuerName": "Sietch Tabr", "xp": 500, "amountMinor": 30000, @@ -346,10 +346,10 @@ const rows=[ "branch": "leto-search", "season": "S01", "revision": 1, - "optional": true, + "optional": false, "verifiedOnly": true, "xpType": "pol", - "issuer": "stilgar_tabr", + "issuer": "stilgar", "issuerName": "Sietch Tabr", "xp": 550, "amountMinor": 30000, @@ -383,10 +383,10 @@ const rows=[ "branch": "leto-search", "season": "S01", "revision": 1, - "optional": true, + "optional": false, "verifiedOnly": true, "xpType": "pol", - "issuer": "stilgar_tabr", + "issuer": "stilgar", "issuerName": "Sietch Tabr", "xp": 600, "amountMinor": 35000, @@ -420,10 +420,10 @@ const rows=[ "branch": "leto-search", "season": "S01", "revision": 1, - "optional": true, + "optional": false, "verifiedOnly": true, "xpType": "pol", - "issuer": "stilgar_tabr", + "issuer": "stilgar", "issuerName": "Sietch Tabr", "xp": 700, "amountMinor": 40000, @@ -457,10 +457,10 @@ const rows=[ "branch": "leto-search", "season": "S01", "revision": 1, - "optional": true, + "optional": false, "verifiedOnly": true, "xpType": "pol", - "issuer": "stilgar_tabr", + "issuer": "stilgar", "issuerName": "Sietch Tabr", "xp": 1500, "amountMinor": 75000, @@ -483,5 +483,5 @@ const rows=[ } ]; export const LETO_QUESTS=Object.freeze(rows.map(q=>Object.freeze({...q,requires:Object.freeze(q.requires),requiresAny:Object.freeze([]),executionRequirements:Object.freeze({website:false,minecraft:Object.freeze(q.executionRequirements.minecraft)}),dialogue:Object.freeze(q.dialogue)}))); -export const LETO_BRANCH=Object.freeze({id:'leto-search',office:null,title:'The Search for Leto II',issuer:'stilgar_tabr',issuerName:'Sietch Tabr',theme:'Thirteen steps, eight worlds, one boy · Reputation XP',xpType:'pol',quests:LETO_QUESTS,decisions:[]}); +export const LETO_BRANCH=Object.freeze({id:'leto-search',office:null,title:'The Search for Leto II',issuer:'stilgar',issuerName:'Sietch Tabr',theme:'Thirteen steps, eight worlds, one boy · Reputation XP',xpType:'pol',quests:LETO_QUESTS,decisions:[]}); export const LETO_CATEGORY=Object.freeze({"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"]}); diff --git a/website/control-panel/public/cp-v2/cp-v2-pol-quest-catalogue.mjs b/website/control-panel/public/cp-v2/cp-v2-pol-quest-catalogue.mjs index f9607982..af4a2772 100644 --- a/website/control-panel/public/cp-v2/cp-v2-pol-quest-catalogue.mjs +++ b/website/control-panel/public/cp-v2/cp-v2-pol-quest-catalogue.mjs @@ -1,4 +1,5 @@ import {polQuestDialogue,polQuestContact} from './cp-v2-pol-dialogue.mjs'; +import {LETO_BRANCH,LETO_QUESTS} from './cp-v2-leto-quests.mjs'; import {FAITH_QUEST_BRANCHES} from './cp-v2-faith-quests.mjs'; import {ELYTRA_BRANCH} from './cp-v2-elytra-quests.mjs'; import {WAR_QUEST_BRANCH} from './cp-v2-war-quests.mjs'; @@ -1109,9 +1110,10 @@ export const POL_QUEST_BRANCHES=freeze([ BOUNTY_BRANCH, SPICE_UPGRADE_BRANCH, ELYTRA_BRANCH, - WAR_QUEST_BRANCH + WAR_QUEST_BRANCH, + LETO_BRANCH ]); const gameplayMetrics=new Set(['pol-verified-report','pol-counterintelligence','pol-evidence-dossier','pol-covert-intelligence','pol-beneficiary-investigation','pol-diplomatic-dispatch','pol-diplomatic-agreement','pol-imperial-intelligence','pol-trade-intelligence','pol-confidential-diplomacy','pol-political-intelligence','pol-confidential-agreement','pol-smuggler-introduction','pol-sabotage','pol-water-supply','pol-procurement','pol-strategic-procurement','pol-settled-acquisition','pol-spice-transport','pol-sietch-service','pol-verified-route','pol-verified-manifest','pol-route-service','pol-sealed-cargo','pol-restricted-delivery','pol-alternate-route','pol-opposed-delivery','pol-ghost-cargo','pol-escort','pol-interdiction','pol-cargo-recovery','pol-protection','pol-commissioned-recovery','pol-discreet-logistics','pol-protected-delivery']); const withDialogue=d=>Object.freeze({...d,npcRole:polQuestContact(d),dialogue:polQuestDialogue(d)}); -export const POL_QUEST_DEFINITIONS=Object.freeze(POL_QUEST_BRANCHES.flatMap(b=>b.quests.map((q,index)=>withDialogue({...q,issuer:q.issuer||b.issuer||({smugglers:"esmar_tuek",clan:"gurney_halleck",company:"roma_atani"})[b.id],issuerName:q.issuerName||b.issuerName||({smugglers:"Esmar Tuek",clan:"Gurney Halleck",company:"Roma Atani"})[b.id],objective:q.objective,xp:q.xp??150+index*50,executionRequirements:Object.freeze({website:true,minecraft:gameplayMetrics.has(q.metric)||['elytra','war-service','fremen-husbandry','bounty-jobs','spice-upgrading'].includes(q.branch)})})))); +export const POL_QUEST_DEFINITIONS=Object.freeze(POL_QUEST_BRANCHES.flatMap(b=>b===LETO_BRANCH?LETO_QUESTS:b.quests.map((q,index)=>withDialogue({...q,issuer:q.issuer||b.issuer||({smugglers:"esmar_tuek",clan:"gurney_halleck",company:"roma_atani"})[b.id],issuerName:q.issuerName||b.issuerName||({smugglers:"Esmar Tuek",clan:"Gurney Halleck",company:"Roma Atani"})[b.id],objective:q.objective,xp:q.xp??150+index*50,executionRequirements:Object.freeze({website:true,minecraft:gameplayMetrics.has(q.metric)||['elytra','war-service','fremen-husbandry','bounty-jobs','spice-upgrading'].includes(q.branch)})})))); export function polBranch(id){return POL_QUEST_BRANCHES.find(b=>b.id===id||b.office===id)||null;} diff --git a/website/control-panel/public/cp-v2/cp-v2-quest-categories.mjs b/website/control-panel/public/cp-v2/cp-v2-quest-categories.mjs index b33a1759..20c3e7d0 100644 --- a/website/control-panel/public/cp-v2/cp-v2-quest-categories.mjs +++ b/website/control-panel/public/cp-v2/cp-v2-quest-categories.mjs @@ -1,5 +1,6 @@ // Themed story-arc categories over the quest branches. Presentation only: quest ids, rewards, // prerequisites and progress are never changed. Mirrors DuneRealmsGUI/src/main/resources/quest-categories.json. +import {LETO_CATEGORY} from './cp-v2-leto-quests.mjs'; export const QUEST_CATEGORIES=Object.freeze([ { "id": "arrival", @@ -146,7 +147,8 @@ export const QUEST_CATEGORIES=Object.freeze([ "branches": [ "war-service" ] - } + }, + LETO_CATEGORY ].map(c=>Object.freeze({...c,branches:Object.freeze([...c.branches])}))); export const OTHER_CATEGORY=Object.freeze({id:'other',title:'Other Work',tagline:'Quests outside the main story arcs.',accent:'#8f7a5a',icon:'quests/other',branches:Object.freeze([])}); const byBranch=new Map(QUEST_CATEGORIES.flatMap(c=>c.branches.map(b=>[b,c]))); diff --git a/website/node/game-quest-events.mjs b/website/node/game-quest-events.mjs index 89378847..0074632e 100644 --- a/website/node/game-quest-events.mjs +++ b/website/node/game-quest-events.mjs @@ -10,6 +10,7 @@ import {SMUGGLER_DELIVERY_METRIC,smugglerDeliveryReference} from './smuggler-del import {bountyEvent,bountyReference,hasAcceptedBountyReceipt} from './bounty-quest-evidence.mjs'; import {POL_SUPPLY_TASKS} from '../control-panel/public/cp-v2/cp-v2-pol-supply-policy.mjs'; import {verifiedSupplyRequest} from './pol-supply-evidence.mjs'; +import {letoObservation} from './leto-quest-evidence.mjs'; // Only fixed native observations cross this boundary. No supplied account, // metric, progress, quantity or reward can be interpreted as quest authority. @@ -40,9 +41,13 @@ export function createGameQuestEventsAPI(db,keys,settings,{clock=Date.now,events if(!input||Array.isArray(input)||Object.keys(input).sort().join(',')!=='eventId,kind,occurredAt,server,uuid')return json({message:'Invalid starter receipt fields'},400); try{return json(await starter.record(input));}catch{return json({message:'The physical starter receipt could not be verified. It remains queued.'},409);} } - const supply=POL_SUPPLY_TASKS.find(t=>t.kind===input?.kind),isFlight=Object.hasOwn(flight,input?.kind||''),isHusbandry=Object.hasOwn(husbandry,input?.kind||''),isFauna=Object.hasOwn(fauna,input?.kind||'')||isHusbandry,isDelivery=input?.kind==='smuggler_delivery',isBounty=['bounty_accept','bounty_complete'].includes(input?.kind),isPOL=isFlight||isFauna||isDelivery||isBounty||!!supply||input?.kind==='smuggler_introduction'; + const isLeto=typeof input?.kind==='string'&&input.kind.startsWith('leto_'); + const leto=isLeto?letoObservation(input):null; + if(isLeto&&(!leto||!validUuid(input.eventId)||!validUuid(input.uuid)||!Number.isSafeInteger(input.occurredAt)||input.occurredAt<=0||input.occurredAt>clock()+30000))return json({message:'Invalid Golden Path observation.'},400); + if(isLeto&&!db.letoQuestEnabled)return json({message:'The Golden Path is unavailable.'},503); + const supply=POL_SUPPLY_TASKS.find(t=>t.kind===input?.kind),isFlight=Object.hasOwn(flight,input?.kind||''),isHusbandry=Object.hasOwn(husbandry,input?.kind||''),isFauna=Object.hasOwn(fauna,input?.kind||'')||isHusbandry,isDelivery=input?.kind==='smuggler_delivery',isBounty=['bounty_accept','bounty_complete'].includes(input?.kind),isPOL=isLeto||isFlight||isFauna||isDelivery||isBounty||!!supply||input?.kind==='smuggler_introduction'; const fields=['eventId','uuid','kind','server','occurredAt',...(input?.kind==='house_mentor_intro'?['npcRole']:isFlight?['quantity','dimension',...(input.kind==='flight_elytra_acquired'?['source']:[])]:isDelivery?['commodity','amount','distance','opposed','source','destination',...(input.startedAt!==undefined?['startedAt']:[])]:isBounty?['source']:input?.kind==='spice_harvest'||isHusbandry?['quantity']:[])]; - if(!input||Array.isArray(input)||Object.keys(input).length!==fields.length||fields.some(f=>!Object.hasOwn(input,f))||!validUuid(input.eventId)||!validUuid(input.uuid)||!Object.hasOwn(metrics,input.kind)||!servers.has(input.server)||!isFlight&&!supply&&input.kind!=='citizen_introduction'&&input.kind!=='house_mentor_intro'&&!(input.kind==='smuggler_introduction'&&input.server==='lobby')&&(input.server==='lobby'||input.kind!=='equipment_use'&&input.server!=='arrakis')||!Number.isSafeInteger(input.occurredAt)||input.occurredAt<=0||input.occurredAt>clock()+30000)return json({message:'Invalid observation fields'},400); + if(!isLeto&&(!input||Array.isArray(input)||Object.keys(input).length!==fields.length||fields.some(f=>!Object.hasOwn(input,f))||!validUuid(input.eventId)||!validUuid(input.uuid)||!Object.hasOwn(metrics,input.kind)||!servers.has(input.server)||!isFlight&&!supply&&input.kind!=='citizen_introduction'&&input.kind!=='house_mentor_intro'&&!(input.kind==='smuggler_introduction'&&input.server==='lobby')&&(input.server==='lobby'||input.kind!=='equipment_use'&&input.server!=='arrakis')||!Number.isSafeInteger(input.occurredAt)||input.occurredAt<=0||input.occurredAt>clock()+30000))return json({message:'Invalid observation fields'},400); if(input.kind==='house_mentor_intro'&&(input.server!=='lobby'||!Object.values(HOUSE_MENTOR_CONTACTS).includes(input.npcRole)))return json({message:'Meet your matching House Mentat in the Guild lobby.'},400); if(isFlight&&(!Number.isSafeInteger(input.quantity)||input.quantity<1||input.quantity>64||!['NORMAL','NETHER','THE_END'].includes(input.dimension)||flight[input.kind]&&(flight[input.kind][0]!==input.server||flight[input.kind][1]!==input.dimension)||input.kind==='flight_elytra_acquired'&&(!['end','exchange'].includes(input.source)||input.source==='end'&&input.dimension!=='THE_END')))return json({message:'Invalid flight objective location'},400); if(input.kind==='flight_merged'&&(input.quantity!==1||input.dimension!=='NORMAL'||input.server==='lobby'))return json({message:'A single completed physical armour merge on a shared-profile planet is required.'},400); @@ -64,7 +69,11 @@ export function createGameQuestEventsAPI(db,keys,settings,{clock=Date.now,events if(supply&&(!db.polSupplyEnabled||!await verifiedSupplyRequest(db,users[0].id,seasons[0].season_id,supply,input.eventId)))return json({message:'No verified supply mission instruction.'},409); if(turnin&&!await verifiedMeatTurninRequest(db,users[0].id,seasons[0].season_id,turnin,input.eventId))return json({message:'No verified meat turn-in instruction.'},409); if(input.kind==='bounty_complete'&&!await hasAcceptedBountyReceipt(db,users[0].id,input.uuid,seasons[0].season_id,input.source.toLowerCase()))return json({message:'The matching accepted native bounty receipt is pending.'},409); - const evidence={eventId:input.eventId,accountId:users[0].id,minecraftUuid:input.uuid,seasonId:seasons[0].season_id,metric:metrics[input.kind],quantity:isFlight||isHusbandry||input.kind==='spice_harvest'?input.quantity:1,occurredAt:input.occurredAt,reference:input.kind==='house_mentor_intro'?'native:lobby:house_mentor_intro:'+input.npcRole+':'+input.eventId:deliveryReference||(isBounty?bountyReference(input.kind,input.source):'native:'+input.server+':'+input.kind+':'+input.eventId)}; + if(leto?.metric.startsWith('leto-contact-')){ + const prior=await db.query('SELECT key_id FROM jarvis_pol_activity_events WHERE event_id=? AND account_id=? AND minecraft_uuid=? AND season_id=? AND metric=?',[input.eventId,users[0].id,input.uuid,seasons[0].season_id,leto.metric]); + if(prior.length===1)return json({ok:true,eventId:input.eventId,keyId:prior[0].key_id,replayed:true}); + } + const evidence={eventId:input.eventId,accountId:users[0].id,minecraftUuid:input.uuid,seasonId:seasons[0].season_id,metric:leto?.metric??metrics[input.kind],quantity:leto?.quantity??(isFlight||isHusbandry||input.kind==='spice_harvest'?input.quantity:1),occurredAt:input.occurredAt,reference:input.kind==='house_mentor_intro'?'native:lobby:house_mentor_intro:'+input.npcRole+':'+input.eventId:deliveryReference||(isBounty?bountyReference(input.kind,input.source):'native:'+input.server+':'+input.kind+':'+input.eventId)}; if(isPOL&&(!db.polActivityEventsEnabled||!polEvents))return json({message:'Reputation quest evidence is unavailable'},503); const result=await (isPOL?polEvents:events).record(producer,evidence); if(isPOL)await createPOLProgressionRuntime(db,keys,{clock}).collect({id:users[0].id}); diff --git a/website/node/game-quests.mjs b/website/node/game-quests.mjs index caa0d382..01e795ec 100644 --- a/website/node/game-quests.mjs +++ b/website/node/game-quests.mjs @@ -1,3 +1,4 @@ +import {letoContact} 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'; @@ -54,7 +55,7 @@ export function createGameQuestsAPI(db,settings,{personal=null,pol=null,starter= if(input.action==='read_refits'||workshop){if(!refits||input.kind!=='pol')return json({message:'The organisation workshop is unavailable.'},503);return json(workshop?await refits.prepare(actor,input):await refits.list(actor));} await runtime.collect?.(actor); const journal=await runtime.quests.list(actor); - if(input.action==='read'){let npcFaction=null,npcContact=null,housePrologue=null;if(input.npcRole!==undefined){if(typeof input.npcRole!=='string'||! /^[a-z_]{1,32}$/.test(input.npcRole)||input.kind==='personal'&&!Object.values(HOUSE_MENTOR_CONTACTS).includes(input.npcRole))return json({message:'Invalid quest contact.'},400);try{const rows=await db.query('SELECT faction FROM site_character_choices WHERE user_id=? AND minecraft_uuid=?',[user.id,input.uuid.toLowerCase()]);if(rows.length===1)npcFaction=rows[0].faction;}catch{/* Missing faction never authorises a faction NPC. */}try{const contact=await createSystemCharacters(db,null,{authorizeOperator:async()=>false}).inspect(input.npcRole);if(contact?.capabilities.includes('quest.issue'))npcContact={key:input.npcRole,name:contact.name,role:contact.characterRole,avatar:systemPortrait(contact.username)};}catch{/* Invalid or revoked system character is not presented as an issuer. */}if(input.kind==='personal')housePrologue=await housePrologueState(db,keys,actor,input.uuid);if(input.npcRole==='imperial_attendant')npcContact={key:input.npcRole,name:'Imperial attendant',role:'Imperial audience · representation',avatar:systemPortrait('imperial_attendant')};}const quests=input.npcRole&&(dossiers||cargo)&&input.kind==='pol'?await Promise.all(journal.quests.map(async q=>{if(!["active","completed"].includes(q.state)){const initial=q.canStart&&input.npcRole==="edric"?await cargo?.initialContact?.(actor,q.id,input.uuid):null;return initial?{...q,cargo:initial}:q;}const current=await dossiers?.presentation(actor,q,input.npcRole),shipment=await cargo?.presentation(actor,q,input.uuid);return current||shipment?{...q,...(current?{dossier:current}:{}),...(shipment?{cargo:shipment}:{})}:q;})):journal.quests;return json({ok:true,...journal,quests,branches:journal.branches||(input.kind==='personal'?personalBranches:[]),kind:input.kind,npcFaction,npcContact,housePrologue,npcSummary:input.npcRole?((r)=>r?{level:r.level,xp:r.xp,nextXP:r.nextXP,percent:r.percent}:null)(xpReport(journal)):null});} + if(input.action==='read'){let npcFaction=null,npcContact=null,housePrologue=null;if(input.npcRole!==undefined){if(typeof input.npcRole!=='string'||! /^[a-z_]{1,32}$/.test(input.npcRole)||input.kind==='personal'&&!Object.values(HOUSE_MENTOR_CONTACTS).includes(input.npcRole))return json({message:'Invalid quest contact.'},400);try{const rows=await db.query('SELECT faction FROM site_character_choices WHERE user_id=? AND minecraft_uuid=?',[user.id,input.uuid.toLowerCase()]);if(rows.length===1)npcFaction=rows[0].faction;}catch{/* Missing faction never authorises a faction NPC. */}try{const contact=await createSystemCharacters(db,null,{authorizeOperator:async()=>false}).inspect(input.npcRole);if(contact?.capabilities.includes('quest.issue'))npcContact={key:input.npcRole,name:contact.name,role:contact.characterRole,avatar:systemPortrait(contact.username)};}catch{/* Invalid or revoked system character is not presented as an issuer. */}if(input.kind==='personal')housePrologue=await housePrologueState(db,keys,actor,input.uuid);if(db.letoQuestEnabled&&input.kind==='pol')npcContact??=letoContact(input.npcRole);if(input.npcRole==='imperial_attendant')npcContact={key:input.npcRole,name:'Imperial attendant',role:'Imperial audience · representation',avatar:systemPortrait('imperial_attendant')};}const quests=input.npcRole&&(dossiers||cargo)&&input.kind==='pol'?await Promise.all(journal.quests.map(async q=>{if(!["active","completed"].includes(q.state)){const initial=q.canStart&&input.npcRole==="edric"?await cargo?.initialContact?.(actor,q.id,input.uuid):null;return initial?{...q,cargo:initial}:q;}const current=await dossiers?.presentation(actor,q,input.npcRole),shipment=await cargo?.presentation(actor,q,input.uuid);return current||shipment?{...q,...(current?{dossier:current}:{}),...(shipment?{cargo:shipment}:{})}:q;})):journal.quests;return json({ok:true,...journal,quests,branches:journal.branches||(input.kind==='personal'?personalBranches:[]),kind:input.kind,npcFaction,npcContact,housePrologue,npcSummary:input.npcRole?((r)=>r?{level:r.level,xp:r.xp,nextXP:r.nextXP,percent:r.percent}:null)(xpReport(journal)):null});} const quest=journal.quests?.find(q=>q.id===input.definitionId); if(!quest)return json({message:'This quest is not in the current mission journal.'},409); if(cargoPartner){if(!cargo?.partner||input.kind!=='pol')return json({message:'Cooperative cargo assignments are unavailable.'},503);return json(await cargo.partner(actor,input,quest));} diff --git a/website/node/leto-quest-evidence.mjs b/website/node/leto-quest-evidence.mjs index 5d35339f..b742f97c 100644 --- a/website/node/leto-quest-evidence.mjs +++ b/website/node/leto-quest-evidence.mjs @@ -8,7 +8,7 @@ const observations = new Map(LETO_QUESTS.map(quest => { server, dimension: dimension === 'END' ? 'THE_END' : dimension, target: quest.target, - role: quest.npcRole ?? null, + role: quest.metric.startsWith('leto-contact-') ? quest.npcRole : null, })]; })); @@ -22,3 +22,14 @@ export function letoObservation(input) { if (!Number.isSafeInteger(input.quantity) || input.quantity < 1 || input.quantity > policy.target) return null; return {metric: policy.metric, quantity: input.quantity}; } + +const contacts=Object.freeze({ + leto_runner:'Ishaq the Runner',leto_steward:'Sietch Steward',leto_waterkeeper:'Keeper of the Water Basin', + leto_ecologist:'Sietch Ecologist',leto_archivist:'Atreides Archivist',leto_informer:'Pit Informer', + leto_courtier:'Court Archivist',leto_tleilaxu_ghola:'Tleilaxu Go-Between', + leto_navigator:"Guild Navigator's Agent",leto_stilgar:'Sietch Steward of the Hall of Rites' +}); + +export function letoContact(key){ + return Object.hasOwn(contacts,key)?{key,name:contacts[key],role:'The Golden Path'}:null; +} diff --git a/website/node/progression-pol-runtime.mjs b/website/node/progression-pol-runtime.mjs index a3a2e205..bcc897ea 100644 --- a/website/node/progression-pol-runtime.mjs +++ b/website/node/progression-pol-runtime.mjs @@ -68,11 +68,12 @@ export function createPOLProgressionRuntime(central,keys,{clock=Date.now,verifyO if(central.secondaryAffiliationsEnabled&&definition.id==='POL-SMUGGLERS-01')await grantSmugglerAffiliations(polStore,keys,actor,{clock});return true; } }; - const unrestrictedDefinitions=POL_QUEST_DEFINITIONS.filter(d=>!d.faction&&(d.branch!=='bounty-jobs'||central.bountyQuestsEnabled)&&(d.branch!=='spice-upgrading'||central.spiceUpgradeEnabled)),engine=createPOLProgression(central,keys,{...adapters,definitions:unrestrictedDefinitions}); + const arcAvailable=d=>d.branch!=='leto-search'||central.letoQuestEnabled===true; + const unrestrictedDefinitions=POL_QUEST_DEFINITIONS.filter(d=>arcAvailable(d)&&!d.faction&&(d.branch!=='bounty-jobs'||central.bountyQuestsEnabled)&&(d.branch!=='spice-upgrading'||central.spiceUpgradeEnabled)),engine=createPOLProgression(central,keys,{...adapters,definitions:unrestrictedDefinitions}); async function engineFor(actor,requestedDefinitionId=null){ const faction=central.faunaQuestsEnabled&&await currentFremen(central,actor.id)?'fremen':null; if(!central.polRepeatablesEnabled&&!central.organisationResearchEnabled&&!faction)return {engine,definitions:unrestrictedDefinitions}; - const definitions=[...POL_QUEST_DEFINITIONS.filter(d=>(!d.faction||d.faction===faction)&&(d.branch!=='bounty-jobs'||central.bountyQuestsEnabled)&&(d.branch!=='spice-upgrading'||central.spiceUpgradeEnabled)),...(central.polRepeatablesEnabled?await repeatableDefinitions(central,actor,{requestedDefinitionId,faction}):[]),...await currentResearchDefinitions(central,actor,{clock,requestedDefinitionId})]; + const definitions=[...POL_QUEST_DEFINITIONS.filter(d=>arcAvailable(d)&&(!d.faction||d.faction===faction)&&(d.branch!=='bounty-jobs'||central.bountyQuestsEnabled)&&(d.branch!=='spice-upgrading'||central.spiceUpgradeEnabled)),...(central.polRepeatablesEnabled?await repeatableDefinitions(central,actor,{requestedDefinitionId,faction}):[]),...await currentResearchDefinitions(central,actor,{clock,requestedDefinitionId})]; const scoped={...adapters,authorizeIssuer:async(tx,d)=>{if(d.faction==='fremen'&&!await currentFremen(tx,actor.id,{lock:true}))throw Error('Current Fremen character required');return authorizeIssuer(tx,d);},definitions}; return {engine:createPOLProgression(central,keys,scoped),definitions}; } diff --git a/website/node/progression-pol.mjs b/website/node/progression-pol.mjs index 746fc7dd..82b84c2f 100644 --- a/website/node/progression-pol.mjs +++ b/website/node/progression-pol.mjs @@ -46,7 +46,7 @@ export function polPolicyKeys(keys){return { list:async id=>(await keys.list(id)).filter(k=>k.keyType==='progression-policy'&&k.scopeId.startsWith('policy:POL:')), consume:async input=>{const own=(await keys.list(input.accountId)).find(k=>k.code===input.code&&k.keyType==='progression-policy'&&k.scopeId.startsWith('policy:POL:'));if(!own)throw Error('POL policy instrument unavailable');return keys.consume({...input,apply:(tx,c)=>input.apply(polProgressionStore(tx),c)});} };} -export const ensurePOLProgressionPolicy=(db,keys,options={})=>ensureProgressionPolicy(polProgressionStore(db),polPolicyKeys(keys),{...options,policy:POL_XP_POLICY,definitions:POL_QUEST_DEFINITIONS.filter(d=>!d.faction&&!['bounty-jobs','spice-upgrading'].includes(d.branch)),rewardForDefinition:faithQuestInitialReward}); +export const ensurePOLProgressionPolicy=(db,keys,options={})=>ensureProgressionPolicy(polProgressionStore(db),polPolicyKeys(keys),{...options,policy:POL_XP_POLICY,definitions:POL_QUEST_DEFINITIONS.filter(d=>!d.faction&&!['bounty-jobs','spice-upgrading','leto-search'].includes(d.branch)),rewardForDefinition:faithQuestInitialReward}); export const ensurePOLRepeatablePolicy=(db,keys,options={})=>ensureProgressionPolicy(polProgressionStore(db),polPolicyKeys(keys),{...options,policy:{...POL_XP_POLICY,version:2},definitions:repeatablePolicyDefinitions()}); @@ -60,5 +60,9 @@ export const ensureFaunaQuestPolicy=(db,keys,options={})=>ensureProgressionPolic export const ensureBountyQuestPolicy=(db,keys,options={})=>ensureProgressionPolicy(polProgressionStore(db),polPolicyKeys(keys),{...options,policy:{...POL_XP_POLICY,version:8},definitions:POL_QUEST_DEFINITIONS.filter(d=>d.branch==='bounty-jobs')}); 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') +}); + // Add the physical merge without replaying v4 or overwriting existing flight rewards. export const ensureElytraMergePolicy=(db,keys,options={})=>ensureProgressionPolicy(polProgressionStore(db),polPolicyKeys(keys),{...options,policy:{...POL_XP_POLICY,version:10},definitions:POL_QUEST_DEFINITIONS.filter(d=>d.id==='POL-ELYTRA-MERGE')}); diff --git a/website/tests/leto-quests.test.mjs b/website/tests/leto-quests.test.mjs index f8a9687f..154aecb0 100644 --- a/website/tests/leto-quests.test.mjs +++ b/website/tests/leto-quests.test.mjs @@ -1,4 +1,6 @@ import test from 'node:test';import assert from 'node:assert/strict'; +import {categoryFor} from '../control-panel/public/cp-v2/cp-v2-quest-categories.mjs'; +import {questCategoryArt} from '../control-panel/quest-category-art.mjs'; import {LETO_QUESTS,LETO_BRANCH,LETO_CATEGORY} from '../control-panel/public/cp-v2/cp-v2-leto-quests.mjs'; test('arc is structurally valid',()=>{ const ids=new Set(LETO_QUESTS.map(q=>q.id));assert.equal(ids.size,LETO_QUESTS.length); @@ -15,21 +17,84 @@ test('every world is visited',()=>{ const worlds=new Set(LETO_QUESTS.map(q=>q.executionRequirements.minecraft.world)); for(const w of ['Vaerkring','Arrakduin','Kaladam','Giedermark','Giedermark Nether','Kaiterhof','Sigmadraken IV','Sigmadraken IV End'])assert.ok(worlds.has(w),w); }); -test('category lists the branch',()=>{assert.deepEqual(LETO_CATEGORY.branches,[LETO_BRANCH.id]);}); +test('The Golden Path has its own category and serves both supplied PNGs',async()=>{ + assert.deepEqual(LETO_CATEGORY.branches,[LETO_BRANCH.id]); + assert.equal(categoryFor(LETO_BRANCH.id).id,LETO_CATEGORY.id); + for(const type of ['banner','icon']){ + const url='https://cp.dunerealms.com/v2/art/quests/golden-path-'+type+'.png'; + const get=await questCategoryArt(new Request(url)); + assert.equal(get.status,200);assert.equal(get.headers.get('Content-Type'),'image/png'); + assert.equal(Buffer.from(await get.arrayBuffer()).subarray(0,8).toString('hex'),'89504e470d0a1a0a'); + const head=await questCategoryArt(new Request(url,{method:'HEAD'})); + assert.equal(head.status,200);assert.equal(await head.text(),''); + } +}); import {letoObservation} from '../node/leto-quest-evidence.mjs'; test('every Golden Path observation binds a fixed producer kind, source and payload shape',()=>{ const seen=new Set(); for(const q of LETO_QUESTS){ const {server,dimension}=q.executionRequirements.minecraft; - const kind=q.metric.replaceAll('-','_'); + const kind=q.metric.replaceAll('-','_'), isContact=q.metric.startsWith('leto-contact-'); assert(!seen.has(kind));seen.add(kind); - const event={eventId:'receipt',uuid:'player',kind,server,occurredAt:1,dimension:dimension==='END'?'THE_END':dimension,...(q.npcRole?{npcRole:q.npcRole}:{quantity:q.target})}; - assert.deepEqual(letoObservation(event),{metric:q.metric,quantity:q.npcRole?1:q.target}); + const event={eventId:'receipt',uuid:'player',kind,server,occurredAt:1,dimension:dimension==='END'?'THE_END':dimension,...(isContact?{npcRole:q.npcRole}:{quantity:q.target})}; + assert.deepEqual(letoObservation(event),{metric:q.metric,quantity:isContact?1:q.target}); assert.equal(letoObservation({...event,metric:q.metric}),null); assert.equal(letoObservation({...event,server:'invalid'}),null); assert.equal(letoObservation({...event,dimension:'CUSTOM'}),null); - assert.equal(letoObservation({...event,...(q.npcRole?{npcRole:'unrelated'}:{quantity:q.target+1})}),null); + assert.equal(letoObservation({...event,...(isContact?{npcRole:'unrelated'}:{quantity:q.target+1})}),null); } assert.equal(seen.size,13); }); + +test('all 13 chapters advance and claim in sequence from authenticated evidence',async()=>{ + const {randomUUID}=await import('node:crypto'); + const {systemCharacterFixture}=await import('./system-character-fixture.mjs'); + 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 {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'; + await f.characters.provision(f.people.Owner,'stilgar'); + await initializePOLProgression(f.db); + await ensurePOLProgressionPolicy(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,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 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',{ + method:'POST',headers:{...(authenticated?{authorization:'Bearer '+secret}:{}),'content-type':'application/json'},body:JSON.stringify(input) + })); + const event=q=>{const {server,dimension}=q.executionRequirements.minecraft;return{ + eventId:randomUUID(),uuid,kind:q.metric.replaceAll('-','_'),server,dimension:dimension==='END'?'THE_END':dimension,occurredAt:clock(), + ...(q.metric.startsWith('leto-contact-')?{npcRole:q.npcRole}:{quantity:q.target}) + };}; + const first=event(LETO_QUESTS[0]); + assert.equal((await send(first,false)).status,401); + 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; + 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+1q.id===LETO_QUESTS[index+1].id).canStart,false); + const evidence=event(definition); + 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); + if(evidence.npcRole)assert.equal((await (await send({...evidence,occurredAt:clock()+1})).json()).replayed,true); + const current=(await quests.list(actor)).quests.find(q=>q.id===definition.id); + assert.equal(current.progress,definition.target); + assert.equal(current.canClaim,true,definition.id); + await quests.claim(actor,{definitionId:current.id,revision:current.revision,requestId:randomUUID()}); + } + 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)); + assert.equal((await f.db.first('SELECT COUNT(*) n FROM jarvis_pol_activity_events')).n,13); + }finally{f.db.close();} +});