Skip to content

Commit e5fb9ff

Browse files
authored
Merge pull request #270 from the-hideout/achievements
Add achievements
2 parents 80e16b9 + a488396 commit e5fb9ff

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

datasources/historical-prices.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const WorkerKV = require('../utils/worker-kv');
1+
const WorkerKVSplit = require('../utils/worker-kv-split');
22

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

1111
async getByItemId(context, itemId, days = this.defaultDays, halfResults = false) {
12-
await this.init(context);
13-
if (!this.cache) {
12+
await this.init(context, itemId);
13+
const data = await this.getKVData(context, itemId);
14+
if (!data) {
1415
return Promise.reject(new Error('Historical prices cache is empty'));
1516
}
1617

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

25-
let prices = this.cache.historicalPricePoint[itemId];
26+
let prices = data.historicalPricePoint[itemId];
2627
if (!prices) {
2728
return [];
2829
}

datasources/tasks.js

+16
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ class TasksAPI extends WorkerKV {
130130
await this.init(context);
131131
return this.cache.QuestItem[id];
132132
}
133+
134+
async getAchievements(context) {
135+
await this.init(context);
136+
return this.cache.Achievement;
137+
}
138+
139+
async getAchievement(context, id) {
140+
await this.init(context);
141+
const achievements = await this.getAchievements(context);
142+
for (const achievement of achievements) {
143+
if (achievement.id === id) {
144+
return achievement;
145+
}
146+
}
147+
return Promise.reject(new Error(`No achievement with id ${id} found`));
148+
}
133149
}
134150

135151
module.exports = TasksAPI;

resolvers/taskResolver.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module.exports = {
22
Query: {
3+
achievements(obj, args, context) {
4+
return context.util.paginate(context.data.task.getAchievements(context), args);
5+
},
36
async tasks(obj, args, context, info) {
47
let tasks = await context.data.task.getList(context);
58
if (args.faction) {
@@ -22,6 +25,14 @@ module.exports = {
2225
return context.data.task.getQuestItems(context);
2326
}
2427
},
28+
Achievement: {
29+
name(data, args, context, info) {
30+
return context.data.task.getLocale(data.name, context, info);
31+
},
32+
description(data, args, context, info) {
33+
return context.data.task.getLocale(data.description, context, info);
34+
},
35+
},
2536
HealthEffect: {
2637
bodyParts(data, args, context, info) {
2738
if (data.bodyParts.length === 0) {
@@ -193,6 +204,9 @@ module.exports = {
193204
item(data, args, context) {
194205
return context.data.item.getItem(context, data.item);
195206
},
207+
items(data, args, context) {
208+
return data.items.map(id => context.data.item.getItem(context, id));
209+
},
196210
maps(data, args, context) {
197211
return data.map_ids.map(id => {
198212
return context.data.map.get(context, id);

schema.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
module.exports = `
2+
type Achievement {
3+
id: ID!
4+
name: String!
5+
description: String
6+
hidden: Boolean!
7+
playersCompletedPercent: Float!
8+
}
9+
210
type Ammo {
311
item: Item!
412
weight: Float!
@@ -14,6 +22,7 @@ type Ammo {
1422
ricochetChance: Float!
1523
penetrationChance: Float!
1624
penetrationPower: Int!
25+
penetrationPowerDeviation: Float
1726
accuracy: Int @deprecated(reason: "Use accuracyModifier instead.")
1827
accuracyModifier: Float
1928
recoil: Int @deprecated(reason: "Use recoilModifier instead.")
@@ -347,6 +356,7 @@ type ItemPropertiesAmmo {
347356
ricochetChance: Float
348357
penetrationChance: Float
349358
penetrationPower: Int
359+
penetrationPowerDeviation: Float
350360
accuracy: Int @deprecated(reason: "Use accuracyModifier instead.")
351361
accuracyModifier: Float
352362
recoil: Float @deprecated(reason: "Use recoilModifier instead.")
@@ -385,6 +395,7 @@ type ItemPropertiesArmorAttachment {
385395
ergoPenalty: Int
386396
headZones: [String]
387397
material: ArmorMaterial
398+
armorType: String
388399
blindnessProtection: Float
389400
bluntThroughput: Float
390401
slots: [ItemSlot]
@@ -1050,6 +1061,7 @@ type TaskObjectiveItem implements TaskObjective {
10501061
maps: [Map]!
10511062
optional: Boolean!
10521063
item: Item!
1064+
items: [Item]!
10531065
count: Int!
10541066
foundInRaid: Boolean!
10551067
dogTagLevel: Int
@@ -1306,6 +1318,7 @@ interface Vendor {
13061318
#union Vendor = TraderOffer | FleaMarket
13071319
13081320
type Query {
1321+
achievements(lang: LanguageCode, limit: Int, offset: Int): [Achievement]!
13091322
ammo(lang: LanguageCode, limit: Int, offset: Int): [Ammo]
13101323
#archivedItemPrices(id: ID!, limit: Int, offset: Int): [historicalPricePoint]!
13111324
barters(lang: LanguageCode, limit: Int, offset: Int): [Barter]

0 commit comments

Comments
 (0)