warframe-worldstate-parser 2.32.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/WorldState.js +60 -94
- package/lib/models/Alert.js +18 -44
- package/lib/models/CambionCycle.js +8 -12
- package/lib/models/CetusCycle.js +34 -54
- package/lib/models/ChallengeInstance.js +11 -14
- package/lib/models/ConclaveChallenge.js +24 -44
- package/lib/models/ConstructionProgress.js +10 -22
- package/lib/models/DailyDeal.js +15 -34
- package/lib/models/DarkSector.js +14 -25
- package/lib/models/DarkSectorBattle.js +6 -8
- package/lib/models/DuviriCycle.js +9 -10
- package/lib/models/EarthCycle.js +36 -35
- package/lib/models/Fissure.js +36 -44
- package/lib/models/FlashSale.js +17 -37
- package/lib/models/GlobalUpgrade.js +23 -41
- package/lib/models/Invasion.js +37 -79
- package/lib/models/Kuva.js +20 -26
- package/lib/models/Mission.js +28 -38
- package/lib/models/News.js +34 -54
- package/lib/models/Nightwave.js +22 -48
- package/lib/models/NightwaveChallenge.js +15 -19
- package/lib/models/PersistentEnemy.js +21 -30
- package/lib/models/Reward.js +18 -20
- package/lib/models/SentientOutpost.js +11 -12
- package/lib/models/Simaris.js +9 -21
- package/lib/models/Sortie.js +36 -54
- package/lib/models/SortieVariant.js +23 -25
- package/lib/models/SteelPathOffering.js +26 -9
- package/lib/models/SyndicateJob.js +20 -30
- package/lib/models/SyndicateMission.js +22 -52
- package/lib/models/VallisCycle.js +37 -45
- package/lib/models/VoidTrader.js +35 -54
- package/lib/models/VoidTraderItem.js +5 -8
- package/lib/models/VoidTraderSchedule.js +7 -6
- package/lib/models/WeeklyChallenge.js +9 -17
- package/lib/models/WorldEvent.js +49 -74
- package/lib/models/WorldstateObject.js +23 -34
- package/lib/models/ZarimanCycle.js +34 -54
- package/lib/supporting/Dependency.js +2 -11
- package/lib/supporting/DuviriChoice.js +1 -5
- package/lib/supporting/ExternalMission.js +2 -6
- package/lib/supporting/MarkdownSettings.js +15 -19
- package/lib/supporting/RewardData.js +4 -6
- package/lib/supporting/RewardTypes.js +2 -4
- package/lib/utilities/integrity.js +11 -0
- package/lib/utilities/timeDate.js +16 -18
- package/lib/utilities/translation.js +188 -56
- package/main.js +2 -2
- package/package.json +4 -6
- package/types/lib/WorldState.d.ts +39 -28
- package/types/lib/models/Alert.d.ts +13 -24
- package/types/lib/models/CambionCycle.d.ts +5 -10
- package/types/lib/models/CetusCycle.d.ts +8 -26
- package/types/lib/models/ChallengeInstance.d.ts +7 -9
- package/types/lib/models/ConclaveChallenge.d.ts +11 -24
- package/types/lib/models/ConstructionProgress.d.ts +5 -16
- package/types/lib/models/DailyDeal.d.ts +7 -26
- package/types/lib/models/DarkSector.d.ts +11 -22
- package/types/lib/models/DarkSectorBattle.d.ts +3 -6
- package/types/lib/models/DuviriCycle.d.ts +5 -11
- package/types/lib/models/EarthCycle.d.ts +40 -17
- package/types/lib/models/Fissure.d.ts +10 -17
- package/types/lib/models/FlashSale.d.ts +8 -29
- package/types/lib/models/GlobalUpgrade.d.ts +8 -27
- package/types/lib/models/Invasion.d.ts +18 -53
- package/types/lib/models/Kuva.d.ts +10 -21
- package/types/lib/models/Mission.d.ts +11 -23
- package/types/lib/models/News.d.ts +18 -31
- package/types/lib/models/Nightwave.d.ts +12 -29
- package/types/lib/models/NightwaveChallenge.d.ts +10 -15
- package/types/lib/models/PersistentEnemy.d.ts +9 -20
- package/types/lib/models/Reward.d.ts +34 -18
- package/types/lib/models/SentientOutpost.d.ts +9 -13
- package/types/lib/models/Simaris.d.ts +6 -17
- package/types/lib/models/Sortie.d.ts +16 -25
- package/types/lib/models/SortieVariant.d.ts +13 -15
- package/types/lib/models/SteelPathOffering.d.ts +5 -8
- package/types/lib/models/SyndicateJob.d.ts +13 -14
- package/types/lib/models/SyndicateMission.d.ts +9 -22
- package/types/lib/models/VallisCycle.d.ts +28 -18
- package/types/lib/models/VoidTrader.d.ts +8 -21
- package/types/lib/models/VoidTraderItem.d.ts +4 -6
- package/types/lib/models/VoidTraderSchedule.d.ts +5 -8
- package/types/lib/models/WeeklyChallenge.d.ts +5 -14
- package/types/lib/models/WorldEvent.d.ts +38 -52
- package/types/lib/models/WorldstateObject.d.ts +46 -24
- package/types/lib/models/ZarimanCycle.d.ts +9 -27
- package/types/lib/supporting/Dependency.d.ts +2 -8
- package/types/lib/supporting/DuviriChoice.d.ts +1 -2
- package/types/lib/supporting/ExternalMission.d.ts +3 -7
- package/types/lib/supporting/MarkdownSettings.d.ts +29 -15
- package/types/lib/supporting/RewardData.d.ts +8 -2
- package/types/lib/supporting/RewardTypes.d.ts +2 -2
- package/types/lib/utilities/integrity.d.ts +1 -0
- package/types/lib/utilities/timeDate.d.ts +19 -12
- package/types/lib/utilities/translation.d.ts +188 -23
- package/types/main.d.ts +2 -4
package/lib/models/Fissure.js
CHANGED
|
@@ -1,93 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
node,
|
|
3
|
+
nodeMissionType,
|
|
4
|
+
missionType,
|
|
5
|
+
nodeEnemy,
|
|
6
|
+
fissureModifier,
|
|
7
|
+
fissureTier,
|
|
8
|
+
} from '../utilities/translation.js';
|
|
9
|
+
import { parseDate, fromNow, timeDeltaToString } from '../utilities/timeDate.js';
|
|
10
|
+
|
|
11
|
+
import WorldstateObject from './WorldstateObject.js';
|
|
4
12
|
|
|
5
13
|
/**
|
|
6
14
|
* Represents a fissure mission
|
|
7
|
-
* @
|
|
15
|
+
* @augments {WorldstateObject}
|
|
8
16
|
*/
|
|
9
|
-
class Fissure extends WorldstateObject {
|
|
17
|
+
export default class Fissure extends WorldstateObject {
|
|
10
18
|
/**
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {Translator} deps.translator The string translator
|
|
14
|
-
* @param {TimeDateFunctions} deps.timeDate The time and date functions
|
|
19
|
+
* @param {object} data The fissure data
|
|
20
|
+
* @param {Dependency} deps The dependencies object
|
|
15
21
|
* @param {string} deps.locale Locale to use for translations
|
|
16
22
|
*/
|
|
17
|
-
constructor(data, {
|
|
18
|
-
super(data
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The time and date functions
|
|
22
|
-
* @type {TimeDateFunctions}
|
|
23
|
-
* @private
|
|
24
|
-
*/
|
|
25
|
-
this.timeDate = timeDate;
|
|
26
|
-
Object.defineProperty(this, 'timeDate', { enumerable: false, configurable: false });
|
|
23
|
+
constructor(data, { locale = 'en' } = { locale: 'en' }) {
|
|
24
|
+
super(data);
|
|
27
25
|
|
|
28
26
|
/**
|
|
29
27
|
* The node where the fissure has appeared
|
|
30
28
|
* @type {string}
|
|
31
29
|
*/
|
|
32
|
-
this.node =
|
|
30
|
+
this.node = node(data.Node, locale);
|
|
33
31
|
|
|
34
32
|
/**
|
|
35
33
|
* The fissure mission type
|
|
36
34
|
* @type {string}
|
|
37
35
|
*/
|
|
38
|
-
this.missionType = data.MissionType
|
|
39
|
-
? translator.missionType(data.MissionType, locale)
|
|
40
|
-
: translator.nodeMissionType(data.Node, locale);
|
|
36
|
+
this.missionType = data.MissionType ? missionType(data.MissionType, locale) : nodeMissionType(data.Node, locale);
|
|
41
37
|
|
|
42
38
|
/**
|
|
43
39
|
* The fissure mission type key
|
|
44
40
|
* @type {string}
|
|
45
41
|
*/
|
|
46
|
-
this.missionKey = data.MissionType
|
|
47
|
-
? translator.missionType(data.MissionType)
|
|
48
|
-
: translator.nodeMissionType(data.Node);
|
|
42
|
+
this.missionKey = data.MissionType ? missionType(data.MissionType) : nodeMissionType(data.Node);
|
|
49
43
|
|
|
50
44
|
/**
|
|
51
45
|
* The faction controlling the node where the fissure has appeared
|
|
52
46
|
* @type {string}
|
|
53
47
|
*/
|
|
54
|
-
this.enemy =
|
|
48
|
+
this.enemy = nodeEnemy(data.Node, locale);
|
|
55
49
|
|
|
56
50
|
/**
|
|
57
51
|
* Faction enum for the faction controlling the node where the fissure has appeared
|
|
58
52
|
* @type {string}
|
|
59
53
|
*/
|
|
60
|
-
this.enemyKey =
|
|
54
|
+
this.enemyKey = nodeEnemy(data.Node);
|
|
61
55
|
|
|
62
56
|
/**
|
|
63
57
|
* The node key where the fissure has appeared
|
|
64
58
|
* @type {string}
|
|
65
59
|
*/
|
|
66
|
-
this.nodeKey =
|
|
60
|
+
this.nodeKey = node(data.Node);
|
|
67
61
|
|
|
68
62
|
/**
|
|
69
63
|
* The fissure's tier
|
|
70
64
|
* @type {string}
|
|
71
65
|
*/
|
|
72
|
-
this.tier =
|
|
66
|
+
this.tier = fissureModifier(data.Modifier || data.ActiveMissionTier, locale);
|
|
73
67
|
|
|
74
68
|
/**
|
|
75
69
|
* The fissure's tier as a number
|
|
76
70
|
* @type {number}
|
|
77
71
|
*/
|
|
78
|
-
this.tierNum =
|
|
72
|
+
this.tierNum = fissureTier(data.Modifier || data.ActiveMissionTier, locale);
|
|
79
73
|
|
|
80
74
|
/**
|
|
81
75
|
* The date and time at which the fissure appeared
|
|
82
76
|
* @type {Date}
|
|
83
77
|
*/
|
|
84
|
-
this.activation =
|
|
78
|
+
this.activation = parseDate(data.Activation);
|
|
85
79
|
|
|
86
80
|
/**
|
|
87
81
|
* The date and time at which the fissure will disappear
|
|
88
82
|
* @type {Date}
|
|
89
83
|
*/
|
|
90
|
-
this.expiry =
|
|
84
|
+
this.expiry = parseDate(data.Expiry);
|
|
91
85
|
|
|
92
86
|
/**
|
|
93
87
|
* Whether this is expired (at time of object creation)
|
|
@@ -97,46 +91,44 @@ class Fissure extends WorldstateObject {
|
|
|
97
91
|
|
|
98
92
|
/**
|
|
99
93
|
* ETA string (at time of object creation)
|
|
100
|
-
* @type {
|
|
94
|
+
* @type {string}
|
|
101
95
|
*/
|
|
102
96
|
this.eta = this.getETAString();
|
|
103
97
|
|
|
104
98
|
/**
|
|
105
99
|
* Whether this fissure corresponds to a RailJack Void Storm
|
|
106
|
-
* @type {
|
|
100
|
+
* @type {boolean}
|
|
107
101
|
*/
|
|
108
|
-
this.isStorm =
|
|
102
|
+
this.isStorm = Boolean(data.ActiveMissionTier);
|
|
109
103
|
|
|
110
104
|
/**
|
|
111
105
|
* Whether this fissure is a Steel Path fissure
|
|
112
106
|
* @type {boolean}
|
|
113
107
|
*/
|
|
114
|
-
this.isHard =
|
|
108
|
+
this.isHard = Boolean(data.Hard);
|
|
115
109
|
}
|
|
116
110
|
|
|
117
111
|
/**
|
|
118
112
|
* Get whether this deal has expired
|
|
119
|
-
* @returns {boolean}
|
|
113
|
+
* @returns {boolean} Whether or not the deal has expired
|
|
120
114
|
*/
|
|
121
115
|
getExpired() {
|
|
122
|
-
return
|
|
116
|
+
return fromNow(this.expiry) < 0;
|
|
123
117
|
}
|
|
124
118
|
|
|
125
119
|
/**
|
|
126
120
|
* Get a string representation of how long the void fissure will remain active
|
|
127
|
-
* @returns {string}
|
|
121
|
+
* @returns {string} The string representation of the fissure's remaining time
|
|
128
122
|
*/
|
|
129
123
|
getETAString() {
|
|
130
|
-
return
|
|
124
|
+
return timeDeltaToString(fromNow(this.expiry));
|
|
131
125
|
}
|
|
132
126
|
|
|
133
127
|
/**
|
|
134
128
|
* Returns a string representation of the fissure
|
|
135
|
-
* @returns {string}
|
|
129
|
+
* @returns {string} The string representation of the fissure
|
|
136
130
|
*/
|
|
137
131
|
toString() {
|
|
138
132
|
return `[${this.getETAString()}] ${this.tier} fissure at ${this.node} - ${this.enemy} ${this.missionType}`;
|
|
139
133
|
}
|
|
140
134
|
}
|
|
141
|
-
|
|
142
|
-
module.exports = Fissure;
|
package/lib/models/FlashSale.js
CHANGED
|
@@ -1,51 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
import mdConfig from '../supporting/MarkdownSettings.js';
|
|
2
|
+
import { languageString } from '../utilities/translation.js';
|
|
3
|
+
import { parseDate, fromNow, timeDeltaToString } from '../utilities/timeDate.js';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Represents a flash sale
|
|
5
7
|
*/
|
|
6
|
-
class FlashSale {
|
|
8
|
+
export default class FlashSale {
|
|
7
9
|
/**
|
|
8
|
-
* @param {
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {MarkdownSettings} deps.mdConfig The markdown settings
|
|
11
|
-
* @param {Translator} deps.translator The string translator
|
|
12
|
-
* @param {TimeDateFunctions} deps.timeDate The time and date functions
|
|
10
|
+
* @param {object} data The flash sale data
|
|
11
|
+
* @param {Dependency} deps The dependencies object
|
|
13
12
|
* @param {string} deps.locale Locale to use for translations
|
|
14
13
|
*/
|
|
15
|
-
constructor(data, {
|
|
16
|
-
/**
|
|
17
|
-
* The markdown settings
|
|
18
|
-
* @type {MarkdownSettings}
|
|
19
|
-
* @private
|
|
20
|
-
*/
|
|
21
|
-
this.mdConfig = mdConfig;
|
|
22
|
-
Object.defineProperty(this, 'mdConfig', { enumerable: false, configurable: false });
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The time and date functions
|
|
26
|
-
* @type {TimeDateFunctions}
|
|
27
|
-
* @private
|
|
28
|
-
*/
|
|
29
|
-
this.timeDate = timeDate;
|
|
30
|
-
Object.defineProperty(this, 'timeDate', { enumerable: false, configurable: false });
|
|
31
|
-
|
|
14
|
+
constructor(data, { locale = 'en' } = { locale: 'en' }) {
|
|
32
15
|
/**
|
|
33
16
|
* The item being offered in the flash sale
|
|
34
17
|
* @type {string}
|
|
35
18
|
*/
|
|
36
|
-
this.item =
|
|
19
|
+
this.item = languageString(data.TypeName, locale);
|
|
37
20
|
|
|
38
21
|
/**
|
|
39
22
|
* The date and time at which the sale will end
|
|
40
23
|
* @type {Date}
|
|
41
24
|
*/
|
|
42
|
-
this.expiry =
|
|
25
|
+
this.expiry = parseDate(data.EndDate);
|
|
43
26
|
|
|
44
27
|
/**
|
|
45
28
|
* The date and time at which the sale will or did start
|
|
46
29
|
* @type {Date}
|
|
47
30
|
*/
|
|
48
|
-
this.activation =
|
|
31
|
+
this.activation = parseDate(data.StartDate);
|
|
49
32
|
|
|
50
33
|
/**
|
|
51
34
|
* The item's discount percentage
|
|
@@ -97,31 +80,30 @@ class FlashSale {
|
|
|
97
80
|
|
|
98
81
|
/**
|
|
99
82
|
* ETA string (at time of object creation)
|
|
100
|
-
* @type {
|
|
83
|
+
* @type {string}
|
|
101
84
|
*/
|
|
102
85
|
this.eta = this.getETAString();
|
|
103
86
|
}
|
|
104
87
|
|
|
105
88
|
/**
|
|
106
89
|
* Get how much time is left before the deal expires
|
|
107
|
-
* @returns {string}
|
|
90
|
+
* @returns {string} The time left before the deal expires
|
|
108
91
|
*/
|
|
109
92
|
getETAString() {
|
|
110
|
-
|
|
111
|
-
return this.timeDate.timeDeltaToString(timeDelta);
|
|
93
|
+
return timeDeltaToString(fromNow(this.expiry));
|
|
112
94
|
}
|
|
113
95
|
|
|
114
96
|
/**
|
|
115
97
|
* Get whether or not this deal has expired
|
|
116
|
-
* @returns {boolean}
|
|
98
|
+
* @returns {boolean} Whether or not the deal has expired
|
|
117
99
|
*/
|
|
118
100
|
getExpired() {
|
|
119
|
-
return
|
|
101
|
+
return fromNow(this.expiry) < 0;
|
|
120
102
|
}
|
|
121
103
|
|
|
122
104
|
/**
|
|
123
105
|
* Returns a string representation of the flash sale
|
|
124
|
-
* @returns {string}
|
|
106
|
+
* @returns {string} The string representation of the flash sale
|
|
125
107
|
*/
|
|
126
108
|
toString() {
|
|
127
109
|
const lines = [`${this.item}, ${this.premiumOverride}p`, `Expires in ${this.getETAString()}`];
|
|
@@ -136,8 +118,6 @@ class FlashSale {
|
|
|
136
118
|
lines.unshift('**Featured**');
|
|
137
119
|
}
|
|
138
120
|
|
|
139
|
-
return `${
|
|
121
|
+
return `${mdConfig.codeBlock}${lines.join(mdConfig.lineEnd)}${mdConfig.blockEnd}`;
|
|
140
122
|
}
|
|
141
123
|
}
|
|
142
|
-
|
|
143
|
-
module.exports = FlashSale;
|
|
@@ -1,63 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import mdConfig from '../supporting/MarkdownSettings.js';
|
|
2
|
+
import { parseDate, fromNow, timeDeltaToString } from '../utilities/timeDate.js';
|
|
3
|
+
import { upgrade, operation, operationSymbol } from '../utilities/translation.js';
|
|
3
4
|
/**
|
|
4
5
|
* Represents an upgrade that applies to all players
|
|
5
6
|
*/
|
|
6
|
-
class GlobalUpgrade {
|
|
7
|
+
export default class GlobalUpgrade {
|
|
7
8
|
/**
|
|
8
|
-
* @param {
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {Translator} deps.translator The string translator
|
|
11
|
-
* @param {TimeDateFunctions} deps.timeDate The time and date functions
|
|
12
|
-
* @param {MarkdownSettings} deps.mdConfig The markdown settings
|
|
9
|
+
* @param {object} data The global upgrade data
|
|
10
|
+
* @param {object} deps The dependencies object
|
|
13
11
|
* @param {string} deps.locale Locale to use for translations
|
|
14
12
|
*/
|
|
15
|
-
constructor(data, {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* @private
|
|
20
|
-
*/
|
|
21
|
-
this.timeDate = timeDate;
|
|
22
|
-
Object.defineProperty(this, 'timeDate', { enumerable: false, configurable: false });
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The markdown settings
|
|
26
|
-
* @type {MarkdownSettings}
|
|
27
|
-
* @private
|
|
28
|
-
*/
|
|
29
|
-
this.mdConfig = mdConfig;
|
|
30
|
-
Object.defineProperty(this, 'mdConfig', { enumerable: false, configurable: false });
|
|
31
|
-
|
|
13
|
+
constructor(data, { locale = 'en' } = { locale: 'en' }) {
|
|
14
|
+
if (!data.Activation || !data.ExpiryDate) {
|
|
15
|
+
throw new TypeError('The provided data does not have the required properties.');
|
|
16
|
+
}
|
|
32
17
|
/**
|
|
33
18
|
* The time and date at which the global upgrade starts being active
|
|
34
19
|
* @type {Date}
|
|
35
20
|
*/
|
|
36
|
-
this.start =
|
|
21
|
+
this.start = parseDate(data.Activation);
|
|
37
22
|
|
|
38
23
|
/**
|
|
39
24
|
* The time and date at which the global upgrade stops being active
|
|
40
25
|
* @type {Date}
|
|
41
26
|
*/
|
|
42
|
-
this.end =
|
|
27
|
+
this.end = parseDate(data.ExpiryDate);
|
|
43
28
|
|
|
44
29
|
/**
|
|
45
30
|
* The effect of the upgrade
|
|
46
31
|
* @type {string}
|
|
47
32
|
*/
|
|
48
|
-
this.upgrade =
|
|
33
|
+
this.upgrade = upgrade(data.UpgradeType, locale);
|
|
49
34
|
|
|
50
35
|
/**
|
|
51
36
|
* The operation type
|
|
52
37
|
* @type {string}
|
|
53
38
|
*/
|
|
54
|
-
this.operation =
|
|
39
|
+
this.operation = operation(data.OperationType, locale);
|
|
55
40
|
|
|
56
41
|
/**
|
|
57
42
|
* Symbol for operation
|
|
58
43
|
* @type {string}
|
|
59
44
|
*/
|
|
60
|
-
this.operationSymbol =
|
|
45
|
+
this.operationSymbol = operationSymbol(data.OperationType, locale);
|
|
61
46
|
|
|
62
47
|
/**
|
|
63
48
|
* The operation value
|
|
@@ -73,7 +58,7 @@ class GlobalUpgrade {
|
|
|
73
58
|
|
|
74
59
|
/**
|
|
75
60
|
* ETA string (at time of object creation)
|
|
76
|
-
* @type {
|
|
61
|
+
* @type {string}
|
|
77
62
|
*/
|
|
78
63
|
this.eta = this.getETAString();
|
|
79
64
|
|
|
@@ -86,19 +71,18 @@ class GlobalUpgrade {
|
|
|
86
71
|
|
|
87
72
|
/**
|
|
88
73
|
* Get whether or not the event has expired
|
|
89
|
-
* @returns {boolean}
|
|
74
|
+
* @returns {boolean} whether the event has expired
|
|
90
75
|
*/
|
|
91
76
|
getExpired() {
|
|
92
|
-
return
|
|
77
|
+
return fromNow(this.end) < 0;
|
|
93
78
|
}
|
|
94
79
|
|
|
95
80
|
/**
|
|
96
81
|
* Get a string indicating how long it will take for the upgrade to expire
|
|
97
|
-
* @returns {string}
|
|
82
|
+
* @returns {string} estimated timer of the upgrade
|
|
98
83
|
*/
|
|
99
84
|
getETAString() {
|
|
100
|
-
|
|
101
|
-
return this.timeDate.timeDeltaToString(timeDelta);
|
|
85
|
+
return timeDeltaToString(fromNow(this.end));
|
|
102
86
|
}
|
|
103
87
|
|
|
104
88
|
/**
|
|
@@ -111,14 +95,12 @@ class GlobalUpgrade {
|
|
|
111
95
|
|
|
112
96
|
/**
|
|
113
97
|
* Returns a string representation of the upgrade
|
|
114
|
-
* @returns {string}
|
|
98
|
+
* @returns {string} string representation
|
|
115
99
|
*/
|
|
116
100
|
toString() {
|
|
117
101
|
return (
|
|
118
|
-
`${
|
|
119
|
-
`${this.operation} ${this.upgradeOperationValue}${
|
|
102
|
+
`${mdConfig.codeBlock}[${this.getETAString()}] ${this.upgrade}` +
|
|
103
|
+
`${this.operation} ${this.upgradeOperationValue}${mdConfig.blockEnd}`
|
|
120
104
|
);
|
|
121
105
|
}
|
|
122
106
|
}
|
|
123
|
-
|
|
124
|
-
module.exports = GlobalUpgrade;
|
package/lib/models/Invasion.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { node, languageString, faction } from '../utilities/translation.js';
|
|
2
|
+
import { parseDate, timeDeltaToString, toNow } from '../utilities/timeDate.js';
|
|
3
|
+
import mdConfig from '../supporting/MarkdownSettings.js';
|
|
4
4
|
|
|
5
|
+
import Reward from './Reward.js';
|
|
6
|
+
import WorldstateObject from './WorldstateObject.js';
|
|
5
7
|
/**
|
|
6
8
|
* An invasion participant
|
|
7
|
-
* @typedef {
|
|
9
|
+
* @typedef {object} InvasionParticipant
|
|
8
10
|
* @property {string} reward Reward for supporting this participant in the invasion
|
|
9
11
|
* @property {string} faction Faction of this participant (localized)
|
|
10
12
|
* @property {string} factionKey Faction of this participant (always English)
|
|
@@ -13,103 +15,61 @@ const WorldstateObject = require('./WorldstateObject');
|
|
|
13
15
|
/**
|
|
14
16
|
* Represents an invasion
|
|
15
17
|
*/
|
|
16
|
-
class Invasion extends WorldstateObject {
|
|
18
|
+
export default class Invasion extends WorldstateObject {
|
|
17
19
|
/**
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {
|
|
20
|
-
* @param {MarkdownSettings} deps.mdConfig The markdown settings
|
|
21
|
-
* @param {Translator} deps.translator The string translator
|
|
22
|
-
* @param {TimeDateFunctions} deps.timeDate The time and date functions
|
|
23
|
-
* @param {Reward} deps.Reward The Reward parser
|
|
20
|
+
* @param {object} data The invasion data
|
|
21
|
+
* @param {Dependency} deps The dependencies object
|
|
24
22
|
* @param {string} deps.locale Locale to use for translations
|
|
25
23
|
*/
|
|
26
|
-
constructor(data, {
|
|
27
|
-
super(data
|
|
24
|
+
constructor(data, { locale = 'en' } = { locale: 'en' }) {
|
|
25
|
+
super(data);
|
|
28
26
|
|
|
29
27
|
const opts = {
|
|
30
|
-
mdConfig,
|
|
31
|
-
translator,
|
|
32
|
-
timeDate,
|
|
33
|
-
Reward,
|
|
34
28
|
locale,
|
|
35
29
|
};
|
|
36
30
|
|
|
37
|
-
/**
|
|
38
|
-
* The markdown settings
|
|
39
|
-
* @type {MarkdownSettings}
|
|
40
|
-
* @private
|
|
41
|
-
*/
|
|
42
|
-
this.mdConfig = mdConfig;
|
|
43
|
-
Object.defineProperty(this, 'mdConfig', { enumerable: false, configurable: false });
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The time and date functions
|
|
47
|
-
* @type {TimeDateFunctions}
|
|
48
|
-
* @private
|
|
49
|
-
*/
|
|
50
|
-
this.timeDate = timeDate;
|
|
51
|
-
Object.defineProperty(this, 'timeDate', { enumerable: false, configurable: false });
|
|
52
|
-
|
|
53
31
|
/**
|
|
54
32
|
* The node where the invasion is taking place
|
|
55
33
|
* @type {string}
|
|
56
34
|
*/
|
|
57
|
-
this.node =
|
|
35
|
+
this.node = node(data.Node, locale);
|
|
58
36
|
|
|
59
37
|
/**
|
|
60
38
|
* The node key where the invasion is taking place
|
|
61
39
|
* @type {string}
|
|
62
40
|
*/
|
|
63
|
-
this.nodeKey =
|
|
41
|
+
this.nodeKey = node(data.Node);
|
|
64
42
|
|
|
65
43
|
/**
|
|
66
44
|
* The invasion's description
|
|
67
45
|
* @type {string}
|
|
68
46
|
*/
|
|
69
|
-
this.desc =
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* The attacker's reward
|
|
73
|
-
* @type {Reward}
|
|
74
|
-
*/
|
|
75
|
-
this.attackerReward = new Reward(data.AttackerReward, opts);
|
|
47
|
+
this.desc = languageString(data.LocTag, locale);
|
|
76
48
|
|
|
77
49
|
/**
|
|
78
50
|
* The attacking faction
|
|
79
51
|
* @type {string}
|
|
80
52
|
*/
|
|
81
|
-
this.attackingFaction =
|
|
53
|
+
this.attackingFaction = faction(data.DefenderMissionInfo.faction, locale);
|
|
82
54
|
|
|
83
55
|
/**
|
|
84
56
|
* Invasion attacker
|
|
85
|
-
* @type {
|
|
57
|
+
* @type {InvasionParticipant}
|
|
86
58
|
*/
|
|
87
59
|
this.attacker = {
|
|
88
|
-
reward:
|
|
89
|
-
faction:
|
|
90
|
-
factionKey:
|
|
60
|
+
reward: Object.keys(data?.AttackerReward || {})?.length ? new Reward(data.AttackerReward, opts) : undefined,
|
|
61
|
+
faction: faction(data.DefenderMissionInfo.faction, locale),
|
|
62
|
+
factionKey: faction(data.DefenderMissionInfo.faction, 'en'),
|
|
91
63
|
};
|
|
92
64
|
|
|
93
|
-
/**
|
|
94
|
-
* The defender's reward
|
|
95
|
-
* @type {Reward}
|
|
96
|
-
*/
|
|
97
|
-
this.defenderReward = new Reward(data.DefenderReward, opts);
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* The defending faction
|
|
101
|
-
* @type {string}
|
|
102
|
-
*/
|
|
103
|
-
this.defendingFaction = translator.faction(data.AttackerMissionInfo.faction, locale);
|
|
104
|
-
|
|
105
65
|
/**
|
|
106
66
|
* Invasion defender
|
|
107
|
-
* @type {
|
|
67
|
+
* @type {InvasionParticipant}
|
|
108
68
|
*/
|
|
109
69
|
this.defender = {
|
|
110
|
-
reward:
|
|
111
|
-
faction:
|
|
112
|
-
factionKey:
|
|
70
|
+
reward: Object.keys(data?.DefenderReward || {})?.length ? new Reward(data.DefenderReward, opts) : undefined,
|
|
71
|
+
faction: faction(data.AttackerMissionInfo.faction, locale),
|
|
72
|
+
factionKey: faction(data.AttackerMissionInfo.faction, 'en'),
|
|
113
73
|
};
|
|
114
74
|
|
|
115
75
|
/**
|
|
@@ -122,7 +82,7 @@ class Invasion extends WorldstateObject {
|
|
|
122
82
|
* The time at which the invasion starts
|
|
123
83
|
* @type {Date}
|
|
124
84
|
*/
|
|
125
|
-
this.activation =
|
|
85
|
+
this.activation = parseDate(data.Activation);
|
|
126
86
|
|
|
127
87
|
/**
|
|
128
88
|
* The signed count of completed runs. Supporting the attackers makes the count go up,
|
|
@@ -152,7 +112,7 @@ class Invasion extends WorldstateObject {
|
|
|
152
112
|
|
|
153
113
|
/**
|
|
154
114
|
* ETA string (at time of object creation)
|
|
155
|
-
* @type {
|
|
115
|
+
* @type {string}
|
|
156
116
|
*/
|
|
157
117
|
this.eta = this.getETAString();
|
|
158
118
|
|
|
@@ -166,7 +126,7 @@ class Invasion extends WorldstateObject {
|
|
|
166
126
|
/**
|
|
167
127
|
* Whether or not the attackers are winning.
|
|
168
128
|
* This is always false when the infestation is attacking
|
|
169
|
-
* @returns {boolean}
|
|
129
|
+
* @returns {boolean} whether the attacker is winning
|
|
170
130
|
*/
|
|
171
131
|
isAttackerWinning() {
|
|
172
132
|
return this.count > 0;
|
|
@@ -174,52 +134,50 @@ class Invasion extends WorldstateObject {
|
|
|
174
134
|
|
|
175
135
|
/**
|
|
176
136
|
* Get an estimation of how much time is left before the invasion ends in milliseconds
|
|
177
|
-
* @returns {number}
|
|
137
|
+
* @returns {number} remaining time in ms
|
|
178
138
|
*/
|
|
179
139
|
getRemainingTime() {
|
|
180
140
|
const completedRuns = Math.abs(this.count);
|
|
181
|
-
const elapsedMillis =
|
|
141
|
+
const elapsedMillis = toNow(this.activation);
|
|
182
142
|
const remainingRuns = this.requiredRuns - completedRuns;
|
|
183
143
|
return remainingRuns * (elapsedMillis / completedRuns);
|
|
184
144
|
}
|
|
185
145
|
|
|
186
146
|
/**
|
|
187
147
|
* Get a string estimating how much time is left before the invasion ends
|
|
188
|
-
* @returns {string}
|
|
148
|
+
* @returns {string} time delta string from now to the end
|
|
189
149
|
*/
|
|
190
150
|
getETAString() {
|
|
191
|
-
return
|
|
151
|
+
return timeDeltaToString(this.getRemainingTime());
|
|
192
152
|
}
|
|
193
153
|
|
|
194
154
|
/**
|
|
195
155
|
* Get the types of the items being rewarded in the invasion
|
|
196
|
-
* @returns {Array
|
|
156
|
+
* @returns {Array<string>} types of items being rewarded
|
|
197
157
|
*/
|
|
198
158
|
getRewardTypes() {
|
|
199
|
-
return this.attacker.reward
|
|
159
|
+
return [...(this.attacker.reward?.getTypes() ?? []), ...(this.defender.reward?.getTypes() ?? [])];
|
|
200
160
|
}
|
|
201
161
|
|
|
202
162
|
/**
|
|
203
163
|
* The invasion's string representation
|
|
204
|
-
* @returns {string}
|
|
164
|
+
* @returns {string} string representation of the invasion
|
|
205
165
|
*/
|
|
206
166
|
toString() {
|
|
207
167
|
let lines = [];
|
|
208
168
|
if (this.vsInfestation) {
|
|
209
169
|
lines = [
|
|
210
|
-
this.
|
|
170
|
+
this.defender.reward?.toString(),
|
|
211
171
|
`${this.desc} on ${this.node}`,
|
|
212
172
|
`${Math.round(this.completion * 100) / 100}% - ETA: ${this.getETAString()}`,
|
|
213
|
-
];
|
|
173
|
+
].filter(Boolean);
|
|
214
174
|
} else {
|
|
215
175
|
lines = [
|
|
216
|
-
`${this.attackingFaction} (${this.
|
|
176
|
+
`${this.attackingFaction} (${this.attacker.reward}) vs. ${this.defender.faction} (${this.defender.reward})`,
|
|
217
177
|
`${this.node} - ${this.desc}`,
|
|
218
178
|
`${Math.round(this.completion * 100) / 100}% - ETA: ${this.getETAString()}`,
|
|
219
179
|
];
|
|
220
180
|
}
|
|
221
|
-
return `${
|
|
181
|
+
return `${mdConfig.codeBlock}${lines.join(mdConfig.lineEnd)}${mdConfig.blockEnd}`;
|
|
222
182
|
}
|
|
223
183
|
}
|
|
224
|
-
|
|
225
|
-
module.exports = Invasion;
|