Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add achievements #270

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions datasources/historical-prices.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const WorkerKV = require('../utils/worker-kv');
const WorkerKVSplit = require('../utils/worker-kv-split');

class historicalPricesAPI extends WorkerKV {
class historicalPricesAPI extends WorkerKVSplit {
constructor(dataSource) {
super('historical_price_data', dataSource);
this.defaultDays = 7;
@@ -9,8 +9,9 @@ class historicalPricesAPI extends WorkerKV {
}

async getByItemId(context, itemId, days = this.defaultDays, halfResults = false) {
await this.init(context);
if (!this.cache) {
await this.init(context, itemId);
const data = await this.getKVData(context, itemId);
if (!data) {
return Promise.reject(new Error('Historical prices cache is empty'));
}

@@ -22,7 +23,7 @@ class historicalPricesAPI extends WorkerKV {
}
}

let prices = this.cache.historicalPricePoint[itemId];
let prices = data.historicalPricePoint[itemId];
if (!prices) {
return [];
}
16 changes: 16 additions & 0 deletions datasources/tasks.js
Original file line number Diff line number Diff line change
@@ -130,6 +130,22 @@ class TasksAPI extends WorkerKV {
await this.init(context);
return this.cache.QuestItem[id];
}

async getAchievements(context) {
await this.init(context);
return this.cache.Achievement;
}

async getAchievement(context, id) {
await this.init(context);
const achievements = await this.getAchievements(context);
for (const achievement of achievements) {
if (achievement.id === id) {
return achievement;
}
}
return Promise.reject(new Error(`No achievement with id ${id} found`));
}
}

module.exports = TasksAPI;
14 changes: 14 additions & 0 deletions resolvers/taskResolver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = {
Query: {
achievements(obj, args, context) {
return context.util.paginate(context.data.task.getAchievements(context), args);
},
async tasks(obj, args, context, info) {
let tasks = await context.data.task.getList(context);
if (args.faction) {
@@ -22,6 +25,14 @@ module.exports = {
return context.data.task.getQuestItems(context);
}
},
Achievement: {
name(data, args, context, info) {
return context.data.task.getLocale(data.name, context, info);
},
description(data, args, context, info) {
return context.data.task.getLocale(data.description, context, info);
},
},
HealthEffect: {
bodyParts(data, args, context, info) {
if (data.bodyParts.length === 0) {
@@ -193,6 +204,9 @@ module.exports = {
item(data, args, context) {
return context.data.item.getItem(context, data.item);
},
items(data, args, context) {
return data.items.map(id => context.data.item.getItem(context, id));
},
maps(data, args, context) {
return data.map_ids.map(id => {
return context.data.map.get(context, id);
13 changes: 13 additions & 0 deletions schema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
module.exports = `
type Achievement {
id: ID!
name: String!
description: String
hidden: Boolean!
playersCompletedPercent: Float!
}

type Ammo {
item: Item!
weight: Float!
@@ -14,6 +22,7 @@ type Ammo {
ricochetChance: Float!
penetrationChance: Float!
penetrationPower: Int!
penetrationPowerDeviation: Float
accuracy: Int @deprecated(reason: "Use accuracyModifier instead.")
accuracyModifier: Float
recoil: Int @deprecated(reason: "Use recoilModifier instead.")
@@ -347,6 +356,7 @@ type ItemPropertiesAmmo {
ricochetChance: Float
penetrationChance: Float
penetrationPower: Int
penetrationPowerDeviation: Float
accuracy: Int @deprecated(reason: "Use accuracyModifier instead.")
accuracyModifier: Float
recoil: Float @deprecated(reason: "Use recoilModifier instead.")
@@ -385,6 +395,7 @@ type ItemPropertiesArmorAttachment {
ergoPenalty: Int
headZones: [String]
material: ArmorMaterial
armorType: String
blindnessProtection: Float
bluntThroughput: Float
slots: [ItemSlot]
@@ -1050,6 +1061,7 @@ type TaskObjectiveItem implements TaskObjective {
maps: [Map]!
optional: Boolean!
item: Item!
items: [Item]!
count: Int!
foundInRaid: Boolean!
dogTagLevel: Int
@@ -1306,6 +1318,7 @@ interface Vendor {
#union Vendor = TraderOffer | FleaMarket

type Query {
achievements(lang: LanguageCode, limit: Int, offset: Int): [Achievement]!
ammo(lang: LanguageCode, limit: Int, offset: Int): [Ammo]
#archivedItemPrices(id: ID!, limit: Int, offset: Int): [historicalPricePoint]!
barters(lang: LanguageCode, limit: Int, offset: Int): [Barter]