clashofclans.js 3.1.4-dev.68bb5bc → 3.1.5-dev.6c2a144

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.
@@ -0,0 +1,3 @@
1
+ import { APICapitalRaidSeason } from '../types';
2
+ export declare const calculateRaidsCompleted: (attackLog: APICapitalRaidSeason['attackLog']) => number;
3
+ export declare const calculateOffensiveRaidMedals: (attackLog: APICapitalRaidSeason['attackLog'], offensiveReward?: number) => number;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateOffensiveRaidMedals = exports.calculateRaidsCompleted = void 0;
4
+ const calculateRaidsCompleted = (attackLog) => {
5
+ let total = 0;
6
+ for (const clan of attackLog) {
7
+ if (clan.districtsDestroyed === clan.districtCount)
8
+ total += 1;
9
+ }
10
+ return total;
11
+ };
12
+ exports.calculateRaidsCompleted = calculateRaidsCompleted;
13
+ const calculateOffensiveRaidMedals = (attackLog, offensiveReward = 0) => {
14
+ const districtMap = {
15
+ 1: 135,
16
+ 2: 225,
17
+ 3: 350,
18
+ 4: 405,
19
+ 5: 460
20
+ };
21
+ const capitalMap = {
22
+ 2: 180,
23
+ 3: 360,
24
+ 4: 585,
25
+ 5: 810,
26
+ 6: 1115,
27
+ 7: 1240,
28
+ 8: 1260,
29
+ 9: 1375,
30
+ 10: 1450
31
+ };
32
+ let totalMedals = 0;
33
+ let attacksDone = 0;
34
+ for (const clan of attackLog) {
35
+ attacksDone += clan.attackCount;
36
+ for (const district of clan.districts) {
37
+ if (district.destructionPercent === 100) {
38
+ if (district.id === 70000000) {
39
+ totalMedals += capitalMap[district.districtHallLevel];
40
+ }
41
+ else {
42
+ totalMedals += districtMap[district.districtHallLevel];
43
+ }
44
+ }
45
+ }
46
+ }
47
+ if (totalMedals !== 0)
48
+ totalMedals = Math.ceil(totalMedals / attacksDone);
49
+ return Math.max(totalMedals, offensiveReward);
50
+ };
51
+ exports.calculateOffensiveRaidMedals = calculateOffensiveRaidMedals;
package/package.json CHANGED
@@ -1,14 +1,21 @@
1
1
  {
2
2
  "name": "clashofclans.js",
3
- "version": "3.1.4-dev.68bb5bc",
3
+ "version": "3.1.5-dev.6c2a144",
4
4
  "description": "JavaScript library for interacting with the Clash of Clans API",
5
5
  "author": "https://clashofclans.js.org",
6
6
  "license": "MIT",
7
7
  "main": "dist/index.js",
8
8
  "exports": {
9
- "import": "./dist/index.mjs",
10
- "require": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ },
14
+ "./api/": {
15
+ "import": "./dist/types/api.mjs",
16
+ "require": "./dist/types/api.js",
17
+ "types": "./dist/types/api.d.ts"
18
+ }
12
19
  },
13
20
  "scripts": {
14
21
  "build": "tsc && gen-esm-wrapper dist/index.js dist/index.mjs",