level upgrade step

This commit is contained in:
azykov@mail.ru
2026-02-14 14:21:10 +03:00
parent 52f75c74c0
commit ef5caab748
5 changed files with 64 additions and 25 deletions
+16 -9
View File
@@ -89,20 +89,27 @@ export class ResourceGenerator {
return this.rule.upgradePrice(level ?? this.level, this.game);
}
public upgradableToLevel(limit: number = 100000): number {
public upgradeLevelsAvailable(step: number | 'max' = 1): number {
for (let idx = 0; idx < limit; idx++) {
const level = this.level + idx;
if (!this.rule.isUpgradable(level, this.game, this.getUpgradePrice(level)))
return level;
if (step === 'max') {
for (let idx = 0; idx < 1000; idx++) {
const level = this.level + idx;
if (!this.rule.isUpgradable(level, this.game, this.getUpgradePrice(level)))
return idx;
}
}
else {
const level = this.level + step - 1;
if (this.rule.isUpgradable(level, this.game, this.getUpgradePrice(level)))
return step;
}
return -1;
return 0;
}
public get isUpgradable(): boolean {
return this.rule.isUpgradable(this.level, this.game, this.getUpgradePrice());
}
// public get isUpgradable(): boolean {
// return this.rule.isUpgradable(this.level, this.game, this.getUpgradePrice());
// }
public getGain(level?: number): ResourceSet {
return this.rule.generationGain(level ?? this.level, this.game);