Skip to content

Commit

Permalink
fix: improve narmer drop matching & timebinding
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Dec 17, 2021
1 parent ec2c04f commit b9047f4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 24 deletions.
36 changes: 30 additions & 6 deletions lib/SyndicateJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fetch = require('node-fetch');
const WorldstateObject = require('./WorldstateObject');

const apiBase = process.env.API_BASE_URL || 'https://api.warframestat.us';
const bountyRewardRegex = /Tier([ABCDE])Table([ABC])Rewards/i;
const bountyRewardRegex = /(?:Tier([ABCDE])|Narmer)Table([ABC])Rewards/i;
const ghoulRewardRegex = /GhoulBountyTable([AB])Rewards/i;

/**
Expand Down Expand Up @@ -75,17 +75,20 @@ const getBountyRewards = async (i18n, isVault, raw) => {
return [];
};

const FIFTY_MINUTES = 3000000;

/**
* Represents a syndicate daily mission
* @extends {WorldstateObject}
*/
class SyndicateJob extends WorldstateObject {
/**
* @param {Object} data The syndicate mission data
* @param {Date} expiry The syndicate job expiration
* @param {Object} deps The dependencies object
* @param {Translator} deps.translator The string translator
* @param {string} deps.locale Locale to use for translations
* @param {Object} data The syndicate mission data
* @param {Date} expiry The syndicate job expiration
* @param {Object} deps The dependencies object
* @param {Object} timeDate Time/Date functions
* @param {Translator} translator The string translator
* @param {string} locale Locale to use for translations
*/
constructor(data, expiry, { translator, timeDate, locale }) {
super({ _id: { $oid: data.JobCurrentVersion ? data.JobCurrentVersion.$oid : `${(data.jobType || '').split('/').slice(-1)[0]}${expiry.getTime()}` } }, { timeDate });
Expand Down Expand Up @@ -141,6 +144,27 @@ class SyndicateJob extends WorldstateObject {
* @type {string|null}
*/
this.locationTag = data.locationTag;

/**
* End time for the syndicate mission.
* Should be inherited from the Syndicate, but some are timebound.
* @type {Date}
*/
this.expiry = expiry;

/**
* What time phase this bounty is bound to
* @type {string}
*/
this.timeBound = undefined;
if (data.jobType && data.jobType.toLowerCase().includes('narmer')) {
if (data.jobType.toLowerCase().includes('eidolon')) {
this.timeBound = 'day';
this.expiry = new Date(this.expiry.getTime() - FIFTY_MINUTES);
} else {
this.timeBoound = 'night';
}
}
}
}

Expand Down
40 changes: 22 additions & 18 deletions test/integration/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,30 @@ const WorldState = rewire('../../lib/WorldState.js');
describe('WorldState (integration)', () => {
describe('#constructor()', async () => {
['pc', 'ps4', 'xb1', 'swi'].forEach((platform) => {
it('should parse live worldstate data', async function () {
it('should parse live worldstate data', function (done) {
this.timeout = 10000; // allow 10 seconds to parse the worldstate
const url = `https://content.${platform === 'pc' ? '' : `${platform}.`}warframe.com/dynamic/worldState.php`;
const ws = await fetch(url).then((d) => d.text());

let wsl;
(() => {
wsl = new WorldState(ws, { logger, locale: 'zh' });
}).should.not.throw();

wsl.news.forEach((article) => {
if (article.message.toLowerCase().includes('stream')) {
article.should.include({ stream: true });
}
});

/* Easy debugging! */
setTimeout(() => {
fs.writeFileSync(`./data.${platform}.json`, JSON.stringify(wsl));
}, 1000);
fetch(url)
.then((d) => d.text())
.then((ws) => {
let wsl;
(() => {
wsl = new WorldState(ws, { logger, locale: 'en' });
}).should.not.throw();

wsl.news.forEach((article) => {
if (article.message.toLowerCase().includes('stream')) {
article.should.include({ stream: true });
}
});

/* Easy debugging! */
setTimeout(() => {
fs.writeFileSync(`./data.${platform}.json`, JSON.stringify(wsl.syndicateMissions
.find((m) => m.syndicateKey === 'Ostrons')));
done();
}, 1000);
});
});
});
});
Expand Down

0 comments on commit b9047f4

Please sign in to comment.