clashofclans.js 3.1.4-dev.68bb5bc → 3.1.5-dev.46123c0
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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +5 -0
- package/dist/struct/ClanWar.js +8 -9
- package/dist/util/Helper.d.ts +10 -0
- package/dist/util/Helper.js +74 -0
- package/package.json +11 -4
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -65,4 +65,9 @@ export const Util = mod.Util;
|
|
|
65
65
|
export const WarClan = mod.WarClan;
|
|
66
66
|
export const WarLeagues = mod.WarLeagues;
|
|
67
67
|
export const WarLogClan = mod.WarLogClan;
|
|
68
|
+
export const calculateOffensiveRaidMedals = mod.calculateOffensiveRaidMedals;
|
|
69
|
+
export const calculateRaidsCompleted = mod.calculateRaidsCompleted;
|
|
70
|
+
export const getWarResult = mod.getWarResult;
|
|
71
|
+
export const isFriendlyWar = mod.isFriendlyWar;
|
|
72
|
+
export const isWarWinner = mod.isWarWinner;
|
|
68
73
|
export const timeoutSignal = mod.timeoutSignal;
|
package/dist/struct/ClanWar.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClanWar = exports.WarClan = exports.ClanWarMember = exports.ClanWarAttack = void 0;
|
|
4
4
|
const Constants_1 = require("../util/Constants");
|
|
5
|
+
const Helper_1 = require("../util/Helper");
|
|
5
6
|
const Badge_1 = require("./Badge");
|
|
6
7
|
/** Represents a Clash of Clans War Attack. */
|
|
7
8
|
class ClanWarAttack {
|
|
@@ -225,15 +226,13 @@ class ClanWar {
|
|
|
225
226
|
get status() {
|
|
226
227
|
if (this.state === 'preparation')
|
|
227
228
|
return 'pending';
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
return 'lose';
|
|
229
|
+
return (0, Helper_1.getWarResult)({
|
|
230
|
+
stars: this.clan.stars,
|
|
231
|
+
destructionPercentage: this.clan.destruction
|
|
232
|
+
}, {
|
|
233
|
+
stars: this.opponent.stars,
|
|
234
|
+
destructionPercentage: this.opponent.destruction
|
|
235
|
+
});
|
|
237
236
|
}
|
|
238
237
|
/** Returns the Clan War League Group. */
|
|
239
238
|
getClanWarLeagueGroup() {
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
4
|
+
export declare const isFriendlyWar: (preparationStartTime: Date, startTime: Date) => boolean;
|
|
5
|
+
export declare const getWarResult: (clan: PartialWarClan, opponent: PartialWarClan) => "win" | "lose" | "tie";
|
|
6
|
+
export declare const isWarWinner: (clan: PartialWarClan, opponent: PartialWarClan) => boolean;
|
|
7
|
+
export interface PartialWarClan {
|
|
8
|
+
stars: number;
|
|
9
|
+
destructionPercentage: number;
|
|
10
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isWarWinner = exports.getWarResult = exports.isFriendlyWar = exports.calculateOffensiveRaidMedals = exports.calculateRaidsCompleted = void 0;
|
|
4
|
+
const Constants_1 = require("./Constants");
|
|
5
|
+
const calculateRaidsCompleted = (attackLog) => {
|
|
6
|
+
let total = 0;
|
|
7
|
+
for (const clan of attackLog) {
|
|
8
|
+
if (clan.districtsDestroyed === clan.districtCount)
|
|
9
|
+
total += 1;
|
|
10
|
+
}
|
|
11
|
+
return total;
|
|
12
|
+
};
|
|
13
|
+
exports.calculateRaidsCompleted = calculateRaidsCompleted;
|
|
14
|
+
const calculateOffensiveRaidMedals = (attackLog, offensiveReward = 0) => {
|
|
15
|
+
const districtMap = {
|
|
16
|
+
1: 135,
|
|
17
|
+
2: 225,
|
|
18
|
+
3: 350,
|
|
19
|
+
4: 405,
|
|
20
|
+
5: 460
|
|
21
|
+
};
|
|
22
|
+
const capitalMap = {
|
|
23
|
+
2: 180,
|
|
24
|
+
3: 360,
|
|
25
|
+
4: 585,
|
|
26
|
+
5: 810,
|
|
27
|
+
6: 1115,
|
|
28
|
+
7: 1240,
|
|
29
|
+
8: 1260,
|
|
30
|
+
9: 1375,
|
|
31
|
+
10: 1450
|
|
32
|
+
};
|
|
33
|
+
let totalMedals = 0;
|
|
34
|
+
let attacksDone = 0;
|
|
35
|
+
for (const clan of attackLog) {
|
|
36
|
+
attacksDone += clan.attackCount;
|
|
37
|
+
for (const district of clan.districts) {
|
|
38
|
+
if (district.destructionPercent === 100) {
|
|
39
|
+
if (district.id === 70000000) {
|
|
40
|
+
totalMedals += capitalMap[district.districtHallLevel];
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
totalMedals += districtMap[district.districtHallLevel];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (totalMedals !== 0)
|
|
49
|
+
totalMedals = Math.ceil(totalMedals / attacksDone);
|
|
50
|
+
return Math.max(totalMedals, offensiveReward);
|
|
51
|
+
};
|
|
52
|
+
exports.calculateOffensiveRaidMedals = calculateOffensiveRaidMedals;
|
|
53
|
+
const isFriendlyWar = (preparationStartTime, startTime) => {
|
|
54
|
+
const preparationTime = startTime.getTime() - preparationStartTime.getTime();
|
|
55
|
+
return Constants_1.FriendlyWarPreparationTimes.includes(preparationTime);
|
|
56
|
+
};
|
|
57
|
+
exports.isFriendlyWar = isFriendlyWar;
|
|
58
|
+
const getWarResult = (clan, opponent) => {
|
|
59
|
+
if (clan.stars > opponent.stars)
|
|
60
|
+
return 'win';
|
|
61
|
+
if (clan.stars === opponent.stars) {
|
|
62
|
+
if (clan.destructionPercentage > opponent.destructionPercentage)
|
|
63
|
+
return 'win';
|
|
64
|
+
if (clan.destructionPercentage === opponent.destructionPercentage)
|
|
65
|
+
return 'tie';
|
|
66
|
+
}
|
|
67
|
+
return 'lose';
|
|
68
|
+
};
|
|
69
|
+
exports.getWarResult = getWarResult;
|
|
70
|
+
const isWarWinner = (clan, opponent) => {
|
|
71
|
+
const result = (0, exports.getWarResult)(clan, opponent);
|
|
72
|
+
return result === 'win';
|
|
73
|
+
};
|
|
74
|
+
exports.isWarWinner = isWarWinner;
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clashofclans.js",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.5-dev.46123c0",
|
|
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
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
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",
|