forked from unimatrix/web
45 lines
2.8 KiB
JavaScript
45 lines
2.8 KiB
JavaScript
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'];
|
|
const observations = new Map(LETO_QUESTS.map(quest => {
|
|
const {server, dimension} = quest.executionRequirements.minecraft;
|
|
return [quest.metric.replaceAll('-', '_'), Object.freeze({
|
|
metric: quest.metric,
|
|
server,
|
|
dimension: dimension === 'END' ? 'THE_END' : dimension,
|
|
target: quest.target,
|
|
role: quest.metric.startsWith('leto-contact-') ? quest.npcRole : null,
|
|
})];
|
|
}));
|
|
|
|
export function letoObservation(input) {
|
|
if (!input || Array.isArray(input)) return null;
|
|
const policy = observations.get(input.kind);
|
|
if (!policy || input.server !== policy.server || input.dimension !== policy.dimension) return null;
|
|
const fields = [...common, policy.role ? 'npcRole' : 'quantity'];
|
|
if (Object.keys(input).length !== fields.length || fields.some(field => !Object.hasOwn(input, field))) return null;
|
|
if (policy.role) return input.npcRole === policy.role ? {metric: policy.metric, quantity: 1} : null;
|
|
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;
|
|
}
|
|
|
|
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)}));
|
|
}
|

Staff