Skip to content

Commit

Permalink
feat(*): equipment list (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
csuvajit authored Dec 25, 2023
1 parent 8b4dbb1 commit 81e56e1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clashofclans.js",
"version": "3.3.0",
"version": "3.3.1",
"description": "JavaScript library for interacting with the Clash of Clans API",
"author": "https://clashofclans.js.org",
"license": "MIT",
Expand Down Expand Up @@ -67,4 +67,4 @@
"engines": {
"node": ">=16.x"
}
}
}
13 changes: 7 additions & 6 deletions src/struct/Unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class Unit {
this.unlockBuilding = original.unlock.building;
this.unlockBuildingLevel = original.unlock.buildingLevel;

this.dps = rawUnit!.dps[this.level - 1];
this.dps = rawUnit!.dps[this.level - 1] ?? 0;
this.trainingTime = Number(rawUnit!.trainingTime);

const origin = data.troops.find((troop) => troop.village === 'home' && troop.name === original.name)!;
Expand All @@ -113,8 +113,7 @@ export class Unit {
this.upgradeCost = original.upgrade.cost[origin.level - 1] || 0;
this.upgradeResource = original.upgrade.resource;
this.upgradeTime = original.upgrade.time[origin.level - 1] || 0;
this.hallMaxLevel = original.levels[data.townHallLevel - 1];
this.equipment = (unit.equipment ?? []).map((unit) => new HeroEquipment(data, unit));
this.hallMaxLevel = original.levels[data.townHallLevel - 1] ?? this.maxLevel;
} else if (rawUnit) {
// special case for the builder base
this.level = this.level === 0 ? 0 : Math.max(this.level, rawUnit.minLevel ?? this.level);
Expand All @@ -131,10 +130,12 @@ export class Unit {
this.upgradeResource = rawUnit.upgrade.resource;
this.upgradeCost = rawUnit.upgrade.cost[this.level - 1] || 0;
this.upgradeTime = rawUnit.upgrade.time[this.level - 1] || 0;
this.dps = rawUnit.dps[this.level - 1];
this.dps = rawUnit.dps[this.level - 1] ?? 0;
this.trainingTime = Number(rawUnit.trainingTime);
if (rawUnit.category === 'hero') this.regenerationTime = rawUnit.regenerationTimes[this.level - 1];
this.hallMaxLevel = rawUnit.levels[(this.village === 'home' ? data.townHallLevel : data.builderHallLevel!) - 1];
if (rawUnit.category === 'hero') this.regenerationTime = rawUnit.regenerationTimes[this.level - 1] ?? 0;
this.hallMaxLevel =
rawUnit.levels[(this.village === 'home' ? data.townHallLevel : data.builderHallLevel!) - 1] ?? this.maxLevel;
this.equipment = (unit.equipment ?? []).map((unit) => new HeroEquipment(data, unit));
}

this.seasonal = Boolean(rawUnit?.seasonal);
Expand Down
2 changes: 1 addition & 1 deletion src/util/raw.json

Large diffs are not rendered by default.

1 comment on commit 81e56e1

@csuvajit
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for clashofclans-js ready!

✅ Preview
https://clashofclans-bbm1kea35-csuvajit.vercel.app

Built with commit 81e56e1.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.