Skip to content

Commit

Permalink
Merge pull request #270 from the-hideout/achievements
Browse files Browse the repository at this point in the history
Add achievements
  • Loading branch information
Razzmatazzz authored Feb 2, 2024
2 parents 80e16b9 + a488396 commit e5fb9ff
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
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;
Expand All @@ -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'));
}

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

let prices = this.cache.historicalPricePoint[itemId];
let prices = data.historicalPricePoint[itemId];
if (!prices) {
return [];
}
Expand Down
16 changes: 16 additions & 0 deletions datasources/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
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!
Expand All @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -385,6 +395,7 @@ type ItemPropertiesArmorAttachment {
ergoPenalty: Int
headZones: [String]
material: ArmorMaterial
armorType: String
blindnessProtection: Float
bluntThroughput: Float
slots: [ItemSlot]
Expand Down Expand Up @@ -1050,6 +1061,7 @@ type TaskObjectiveItem implements TaskObjective {
maps: [Map]!
optional: Boolean!
item: Item!
items: [Item]!
count: Int!
foundInRaid: Boolean!
dogTagLevel: Int
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit e5fb9ff

Please sign in to comment.