warframe-worldstate-parser
Version:
An Open parser for Warframe's Worldstate in Javascript
372 lines (371 loc) • 11 kB
JavaScript
import { n as __decorateMetadata, t as __decorate } from "../../decorate-BCC26nnB.mjs";
import { Reward } from "./Reward.mjs";
import { WorldStateObject } from "./WorldStateObject.mjs";
import { SyndicateJob } from "./SyndicateJob.mjs";
import { Type } from "class-transformer";
import { IsArray, IsBoolean, IsDate, IsInt, IsNumber, IsObject, IsOptional, IsString, Min, ValidateNested } from "class-validator";
import { faction, fromNow, languageString, node, parseDate, syndicate } from "warframe-worldstate-data/utilities";
//#region lib/models/WorldEvent.ts
/**
* Represents an in-game special event
* @augments {WorldStateObject}
*/
var WorldEvent = class WorldEvent extends WorldStateObject {
/**
* Jobs associated with this event
*/
jobs;
/**
* Previous jobs associated with this event
*/
previousJobs;
/**
* The event's main score goal
*/
maximumScore;
/**
* The current score on the event
*/
currentScore;
/**
* The first intermediate score goal
*/
smallInterval;
/**
* The second intermediate score goal
*/
largeInterval;
/**
* The faction that the players must fight in the event
*/
faction;
/**
* The description of the event
*/
description;
/**
* Tooltip for the event
*/
tooltip;
/**
* The node where the event takes place
*/
node;
/**
* The other nodes where the event takes place
*/
concurrentNodes;
/**
* The victim node
*/
victimNode;
/**
* The score description
*/
scoreLocTag;
/**
* The event's rewards
*/
rewards;
/**
* Health remaining for the target
*/
health;
/**
* Previous job id
*/
previousId;
/**
* Array of steps
*/
interimSteps;
/**
* Progress Steps, if any are present
*/
progressSteps;
/**
* Total of all MultiProgress
*/
progressTotal;
/**
* Whether to show the total score at the end of the mission
*/
showTotalAtEndOfMission;
/**
* Whether the event is personal
*/
isPersonal;
/**
* Whether the event is community
*/
isCommunity;
regionDrops;
/**
* Archwing Drops in effect while this event is active
*/
archwingDrops;
/**
* Metadata provided by DE
*/
metadata;
/**
* Bonuses given for completion
*/
completionBonuses;
/**
* Score variable name
*/
scoreVar;
/**
* Alternative expiry date
*/
altExpiry;
/**
* Alternative activation date
*/
altActivation;
/**
* Next alternative cycle dates
*/
nextAlt;
/**
* Affiliated syndicate, if any
*/
affiliatedWith;
/**
* The event's tag
*/
tag;
/**
* Victim identifier, if any
*/
victim;
/**
* Asynchronously build a new WorldEvent
* @param data The event data
* @param deps The dependencies object
* @returns The created WorldEvent object
*/
static async build(data, deps) {
const event = new WorldEvent(data, deps);
if (data.Jobs) {
const jobs = [];
for await (const job of data.Jobs ?? []) jobs.push(await SyndicateJob.build(job, event.expiry, deps));
event.jobs = jobs;
}
if (data.PreviousJobs) {
const previousJobs = [];
for await (const job of data.PreviousJobs ?? []) previousJobs.push(await SyndicateJob.build(job, event.expiry, deps));
event.previousJobs = previousJobs;
}
return event;
}
/**
* @param data The event data
* @param deps The dependencies object
*/
constructor(data, { locale = "en" } = { locale: "en" }) {
super(data);
const opts = { locale };
this.maximumScore = Number.parseInt(String(data.Goal), 10);
this.currentScore = Number.parseInt(String(data.Count), 10);
this.smallInterval = Number.parseInt(String(data.GoalInterim), 10);
this.largeInterval = Number.parseInt(String(data.GoalInterim2), 10);
this.faction = data.Faction ? faction(data.Faction, locale) : void 0;
this.description = languageString(data.Desc, locale);
this.tooltip = data.ToolTip ? languageString(data.ToolTip, locale) : void 0;
this.node = data.Node ? node(data.Node, locale) : void 0;
this.concurrentNodes = data.ConcurrentNodes ? data.ConcurrentNodes.map((n) => node(n, locale)) : [];
this.victimNode = data.VictimNode ? node(data.VictimNode, locale) : void 0;
this.scoreLocTag = data.ScoreLocTag ? languageString(data.ScoreLocTag, locale) : void 0;
if (data.Fomorian) this.scoreLocTag = "Fomorian Assault Score";
this.rewards = Object.keys(data).filter((k) => k.includes("Reward") || k.includes("reward")).map((k) => new Reward(data[k], opts)).filter((r) => r.items.length > 0);
this.health = typeof data.HealthPct !== "undefined" ? Number.parseFloat(((data.HealthPct || 0) * 100).toFixed(2)) : void 0;
this.jobs = [];
this.previousJobs = [];
this.previousId = data.JobPreviousVersion?.$oid;
this.interimSteps = [];
(data.InterimRewards || []).forEach((reward, index) => {
const msg = (data.InterimRewardMessages || [])[index] || {};
this.interimSteps[index] = {
goal: Number.parseInt(String(data.InterimGoals[index]), 10),
reward: reward ? new Reward(reward, opts) : void 0,
message: {
sender: languageString(msg.sender, locale),
subject: languageString(msg.subject, locale),
message: languageString(msg.message, locale),
senderIcon: msg.senderIcon,
attachments: msg.attachments
},
winnerCount: (data._interimWinnerCounts || [])[index]
};
});
this.progressSteps = [];
if (data.IsMultiProgress) {
data.Types?.forEach((type, index) => {
this.progressSteps[index] = {
type: languageString(type, locale),
progressAmt: Number.parseInt(String(data.MultiProgress[index]), 10)
};
});
this.progressTotal = Number.parseFloat(String(data.MultiProgress.reduce((acc, val) => acc + Number.parseFloat(val), 0)));
}
this.showTotalAtEndOfMission = data.ShowTotalAtEOM ?? false;
this.isPersonal = data.Personal;
this.isCommunity = data.Community ?? false;
this.regionDrops = (data.RegionDrops || []).map((drop) => languageString(drop, locale));
this.archwingDrops = (data.ArchwingDrops || []).map((drop) => languageString(drop, locale));
this.metadata = JSON.parse((data.Metadata || "{}").replace("\" ", "\""));
this.completionBonuses = data.CompletionBonus || [];
this.scoreVar = data.ScoreVar;
this.altExpiry = parseDate(data.AltExpiry);
this.altActivation = parseDate(data.AltActivation);
this.nextAlt = {
expiry: parseDate(data.NextAltExpiry),
activation: parseDate(data.NextAltActivation)
};
if (data.JobAffiliationTag) this.affiliatedWith = syndicate(data.JobAffiliationTag, locale);
this.tag = data.Tag;
}
/**
* Whether the event has expired
*/
get expired() {
return fromNow(this.expiry) < 0;
}
};
__decorate([
IsArray(),
ValidateNested({ each: true }),
Type(() => SyndicateJob),
__decorateMetadata("design:type", Array)
], WorldEvent.prototype, "jobs", void 0);
__decorate([
IsArray(),
ValidateNested({ each: true }),
Type(() => SyndicateJob),
__decorateMetadata("design:type", Array)
], WorldEvent.prototype, "previousJobs", void 0);
__decorate([
IsInt(),
Min(0),
__decorateMetadata("design:type", Number)
], WorldEvent.prototype, "maximumScore", void 0);
__decorate([
IsInt(),
Min(0),
__decorateMetadata("design:type", Number)
], WorldEvent.prototype, "currentScore", void 0);
__decorate([
IsInt(),
Min(0),
__decorateMetadata("design:type", Number)
], WorldEvent.prototype, "smallInterval", void 0);
__decorate([
IsInt(),
Min(0),
__decorateMetadata("design:type", Number)
], WorldEvent.prototype, "largeInterval", void 0);
__decorate([
IsOptional(),
IsString(),
__decorateMetadata("design:type", Object)
], WorldEvent.prototype, "faction", void 0);
__decorate([IsString(), __decorateMetadata("design:type", String)], WorldEvent.prototype, "description", void 0);
__decorate([
IsOptional(),
IsString(),
__decorateMetadata("design:type", Object)
], WorldEvent.prototype, "tooltip", void 0);
__decorate([
IsOptional(),
IsString(),
__decorateMetadata("design:type", Object)
], WorldEvent.prototype, "node", void 0);
__decorate([
IsArray(),
IsString({ each: true }),
__decorateMetadata("design:type", Array)
], WorldEvent.prototype, "concurrentNodes", void 0);
__decorate([
IsOptional(),
IsString(),
__decorateMetadata("design:type", Object)
], WorldEvent.prototype, "victimNode", void 0);
__decorate([
IsOptional(),
IsString(),
__decorateMetadata("design:type", Object)
], WorldEvent.prototype, "scoreLocTag", void 0);
__decorate([
IsArray(),
ValidateNested({ each: true }),
Type(() => Reward),
__decorateMetadata("design:type", Array)
], WorldEvent.prototype, "rewards", void 0);
__decorate([
IsOptional(),
IsNumber(),
Min(0),
__decorateMetadata("design:type", Object)
], WorldEvent.prototype, "health", void 0);
__decorate([
IsOptional(),
IsString(),
__decorateMetadata("design:type", Object)
], WorldEvent.prototype, "previousId", void 0);
__decorate([IsArray(), __decorateMetadata("design:type", Array)], WorldEvent.prototype, "interimSteps", void 0);
__decorate([IsArray(), __decorateMetadata("design:type", Array)], WorldEvent.prototype, "progressSteps", void 0);
__decorate([
IsOptional(),
IsNumber(),
__decorateMetadata("design:type", Number)
], WorldEvent.prototype, "progressTotal", void 0);
__decorate([IsBoolean(), __decorateMetadata("design:type", Boolean)], WorldEvent.prototype, "showTotalAtEndOfMission", void 0);
__decorate([IsBoolean(), __decorateMetadata("design:type", Boolean)], WorldEvent.prototype, "isPersonal", void 0);
__decorate([IsBoolean(), __decorateMetadata("design:type", Boolean)], WorldEvent.prototype, "isCommunity", void 0);
__decorate([
IsArray(),
IsString({ each: true }),
__decorateMetadata("design:type", Array)
], WorldEvent.prototype, "regionDrops", void 0);
__decorate([
IsArray(),
IsString({ each: true }),
__decorateMetadata("design:type", Array)
], WorldEvent.prototype, "archwingDrops", void 0);
__decorate([IsObject(), __decorateMetadata("design:type", Object)], WorldEvent.prototype, "metadata", void 0);
__decorate([
IsArray(),
IsNumber({}, { each: true }),
__decorateMetadata("design:type", Array)
], WorldEvent.prototype, "completionBonuses", void 0);
__decorate([IsString(), __decorateMetadata("design:type", String)], WorldEvent.prototype, "scoreVar", void 0);
__decorate([
IsDate(),
Type(() => Date),
__decorateMetadata("design:type", typeof Date === "undefined" ? Object : Date)
], WorldEvent.prototype, "altExpiry", void 0);
__decorate([
IsDate(),
Type(() => Date),
__decorateMetadata("design:type", typeof Date === "undefined" ? Object : Date)
], WorldEvent.prototype, "altActivation", void 0);
__decorate([
IsObject(),
ValidateNested(),
__decorateMetadata("design:type", Object)
], WorldEvent.prototype, "nextAlt", void 0);
__decorate([
IsOptional(),
IsString(),
__decorateMetadata("design:type", String)
], WorldEvent.prototype, "affiliatedWith", void 0);
__decorate([IsString(), __decorateMetadata("design:type", String)], WorldEvent.prototype, "tag", void 0);
__decorate([
IsOptional(),
IsString(),
__decorateMetadata("design:type", String)
], WorldEvent.prototype, "victim", void 0);
//#endregion
export { WorldEvent };