enefel 1.0.132 → 1.0.134

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/badge.js CHANGED
@@ -1,9 +1,10 @@
1
+ const { getCareers } = require("./career");
1
2
  const { ranges } = require("./improvement");
2
- const { getCareers } = require("./race");
3
3
 
4
4
  const BADGE_NAMES = {
5
5
  KILL: "kill",
6
6
  DEAD: "dead",
7
+ BLOODTHIRSTY: "bloodthirsty",
7
8
  };
8
9
  const badges = {};
9
10
 
@@ -12,38 +13,39 @@ const badges = {};
12
13
  // ...
13
14
  Object.values(getCareers()).forEach((r) => {
14
15
  if (!badges[r.badge]) {
15
- badges[r.badge] = ranges;
16
+ badges[r.badge] = [0, ...ranges];
16
17
  }
17
18
  });
18
- badges[BADGE_NAMES.KILL] = [];
19
- badges[BADGE_NAMES.DEAD] = [];
19
+ badges[BADGE_NAMES.KILL] = [0, 1, 2, 3, 5, 7, 9]; // 10 max
20
+ badges[BADGE_NAMES.DEAD] = [0, 1, 2, 3, 5, 7, 9]; // 10 max
21
+ badges[BADGE_NAMES.BLOODTHIRSTY] = [0]; // 1 max
20
22
 
21
- function getBadgeQuantity(myBadges, badgeId) {
22
- if (!myBadges || myBadges.length === 0) {
23
- return null;
24
- }
25
- const index = myBadges.findIndex((mb) => mb.badge_id === badgeId);
26
- if (index === -1) {
27
- return null;
28
- }
29
- return myBadges[index].quantity;
23
+ function getBadgeMaxLevel(badge) {
24
+ return badges[badge.badge_id].length;
30
25
  }
31
26
 
32
- function hasBadge(myBadges, race) {
33
- const range = getRanges()[race.range];
34
- // TODO range == 0 for locked careers
35
- if (range === 0) {
36
- return true;
37
- }
38
- const quantity = getBadgeQuantity(myBadges, race.badge);
39
- if (quantity === null) {
40
- return false;
27
+ function getBadgeLevel(badge) {
28
+ const meta = badges[badge.badge_id];
29
+
30
+ let level = meta.findIndex((lvl) => badge.quantity <= lvl);
31
+ if (level === -1) {
32
+ return getBadgeMaxLevel(badge);
41
33
  }
42
- return quantity >= range;
34
+ return level;
43
35
  }
44
36
 
45
- function getRanges() {
46
- return [0, ...ranges];
37
+ function hasBadge(badgeId, user, quantity = 1) {
38
+ const hasBadgeQte = user.badges.find((b) => {
39
+ return b.badge_id === badgeId && b.quantity >= quantity;
40
+ });
41
+
42
+ return hasBadgeQte == null ? false : true;
47
43
  }
48
44
 
49
- module.exports = { BADGE_NAMES, badges, hasBadge, getBadgeQuantity, getRanges };
45
+ module.exports = {
46
+ BADGE_NAMES,
47
+ badges,
48
+ getBadgeLevel,
49
+ getBadgeMaxLevel,
50
+ hasBadge,
51
+ };