warframe-worldstate-parser
Version:
An Open parser for Warframe's Worldstate in Javascript
83 lines (82 loc) • 2.7 kB
JavaScript
import { n as __decorateMetadata, t as __decorate } from "../../decorate-BCC26nnB.mjs";
import { WorldStateObject } from "./WorldStateObject.mjs";
import { IsBoolean, IsString } from "class-validator";
import { fromNow, timeDeltaToString } from "warframe-worldstate-data/utilities";
//#region lib/models/ZarimanCycle.ts
const corpusTimeMillis = 16551828e5;
const fullCycle = 18e6;
const stateMaximum = 9e6;
/**
* Represents the current Zariman Corpus/Grineer Cycle
* @augments {WorldStateObject}
*/
var ZarimanCycle = class extends WorldStateObject {
/**
* Whether or not this it's corpus or grineer
*/
isCorpus;
/**
* Current cycle state. One of `corpus`, `grineer`
*/
state;
/**
* Time remaining string
*/
timeLeft;
/**
* The current zariman cycle, for calculating the other fields
*/
#ec;
/**
* The end of the Zariman bounties timer, the faction changes exactly half way through
*/
#bountiesEndDate;
/**
* @param {Date} bountiesEndDate The current Zariman cycle expiry
*/
constructor(bountiesEndDate) {
super({ _id: { $oid: "zarimanCycle0" } });
this.#bountiesEndDate = bountiesEndDate;
this.#ec = this.getCurrentZarimanCycle();
this.expiry = this.#ec.expiry;
this.activation = new Date(this.#ec.start);
this.isCorpus = this.#ec.isCorpus;
this.state = this.#ec.state;
this.timeLeft = this.#ec.timeLeft;
this.id = `zarimanCycle${this.expiry.getTime()}`;
}
/**
* Whether this is expired
*/
get expired() {
return this.expiry ? fromNow(this.expiry) < 0 : true;
}
getCurrentZarimanCycle() {
const now = Date.now();
const bountiesClone = this.#bountiesEndDate.getTime() - 5e3;
const millisLeft = fromNow(new Date(bountiesClone));
const isCorpus = fullCycle - ((bountiesClone - corpusTimeMillis) % fullCycle + fullCycle) % fullCycle > stateMaximum;
const minutesCoef = 1e3 * 60;
const expiry = /* @__PURE__ */ new Date(Math.round((now + millisLeft) / minutesCoef) * minutesCoef);
const state = isCorpus ? "corpus" : "grineer";
return {
isCorpus,
timeLeft: timeDeltaToString(millisLeft),
expiry,
expiresIn: millisLeft,
state,
start: expiry.getTime() - stateMaximum
};
}
/**
* The event's string representation
*/
get shortString() {
return `${this.timeLeft.replace(/\s\d*s/gi, "")} to ${this.isCorpus ? "grineer" : "corpus"}`;
}
};
__decorate([IsBoolean(), __decorateMetadata("design:type", Boolean)], ZarimanCycle.prototype, "isCorpus", void 0);
__decorate([IsString(), __decorateMetadata("design:type", String)], ZarimanCycle.prototype, "state", void 0);
__decorate([IsString(), __decorateMetadata("design:type", String)], ZarimanCycle.prototype, "timeLeft", void 0);
//#endregion
export { ZarimanCycle };