UNPKG

warframe-worldstate-parser

Version:

An Open parser for Warframe's Worldstate in Javascript

124 lines (123 loc) 4.58 kB
import { n as __decorateMetadata, t as __decorate } from "../../decorate-BCC26nnB.mjs"; import { Reward } from "./Reward.mjs"; import { WorldStateObject } from "./WorldStateObject.mjs"; import { IsArray, IsBoolean, IsInt, IsNumber, IsString, ValidateNested } from "class-validator"; import { faction, languageString, node, timeDeltaToString, toNow } from "warframe-worldstate-data/utilities"; //#region lib/models/Invasion.ts /** * Represents an invasion */ var Invasion = class extends WorldStateObject { /** * The node where the invasion is taking place */ node; /** * The node key where the invasion is taking place */ nodeKey; /** * The invasion's description */ desc; /** * Invasion attacker */ attacker; /** * Invasion defender */ defender; /** * Whether this invasion is against the infestation */ vsInfestation; /** * The signed count of completed runs. Supporting the attackers makes the count go up, * supporting the defenders makes it go down */ count; /** * The number of runs that one side needs to win */ requiredRuns; /** * The invasion's completion percentage. Defenders win if it gets to 0 * Grineer vs. Corpus invasions start at 50, Infested invasions start at 100 */ completion; /** * Whether the invasion has finished */ completed; /** * An array containing the types of all of the invasions's rewards */ rewardTypes; /** * @param {object} data The invasion data * @param {Dependency} deps The dependencies object * @param {string} deps.locale Locale to use for translations */ constructor(data, { locale = "en" } = { locale: "en" }) { super(data); const opts = { locale }; this.node = node(data.Node, locale); this.nodeKey = node(data.Node); this.desc = languageString(data.LocTag, locale); this.attacker = { reward: Object.keys(data?.AttackerReward || {})?.length ? new Reward(data.AttackerReward, opts) : void 0, faction: faction(data.DefenderMissionInfo.faction, locale), factionKey: faction(data.DefenderMissionInfo.faction, "en") }; this.defender = { reward: Object.keys(data?.DefenderReward || {})?.length ? new Reward(data.DefenderReward, opts) : void 0, faction: faction(data.AttackerMissionInfo.faction, locale), factionKey: faction(data.AttackerMissionInfo.faction, "en") }; this.vsInfestation = /infest/i.test(data.DefenderMissionInfo.faction); this.count = data.Count; this.requiredRuns = data.Goal; this.completion = (1 + data.Count / data.Goal) * (this.vsInfestation ? 100 : 50); this.completed = data.Completed; this.rewardTypes = [...this.attacker.reward?.getTypes() ?? [], ...this.defender.reward?.getTypes() ?? []]; } /** * Whether or not the attackers are winning. * This is always false when the infestation is attacking */ get isAttackerWinning() { return this.count > 0; } /** * ETA string (at time of object creation) */ get eta() { return timeDeltaToString(this.getRemainingTime()); } /** * Get an estimation of how much time is left before the invasion ends in milliseconds */ getRemainingTime() { const completedRuns = Math.abs(this.count); const elapsedMillis = toNow(this.activation); return (this.requiredRuns - completedRuns) * (elapsedMillis / completedRuns); } }; __decorate([IsString(), __decorateMetadata("design:type", String)], Invasion.prototype, "node", void 0); __decorate([IsString(), __decorateMetadata("design:type", String)], Invasion.prototype, "nodeKey", void 0); __decorate([IsString(), __decorateMetadata("design:type", String)], Invasion.prototype, "desc", void 0); __decorate([ValidateNested(), __decorateMetadata("design:type", Object)], Invasion.prototype, "attacker", void 0); __decorate([ValidateNested(), __decorateMetadata("design:type", Object)], Invasion.prototype, "defender", void 0); __decorate([IsBoolean(), __decorateMetadata("design:type", Boolean)], Invasion.prototype, "vsInfestation", void 0); __decorate([IsInt(), __decorateMetadata("design:type", Number)], Invasion.prototype, "count", void 0); __decorate([IsInt(), __decorateMetadata("design:type", Number)], Invasion.prototype, "requiredRuns", void 0); __decorate([IsNumber(), __decorateMetadata("design:type", Number)], Invasion.prototype, "completion", void 0); __decorate([IsBoolean(), __decorateMetadata("design:type", Boolean)], Invasion.prototype, "completed", void 0); __decorate([ IsArray(), IsString({ each: true }), __decorateMetadata("design:type", Array) ], Invasion.prototype, "rewardTypes", void 0); //#endregion export { Invasion };