/
buySkillAction.ts
48 lines (44 loc) · 1.48 KB
/
buySkillAction.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { BuyAction } from "./buyAction";
import { SkillEffect } from "../prestige/skillEffects";
import { MultiPrice } from "../prices/multiPrice";
import { Price } from "../prices/price";
import { PrestigeManager } from "../prestige/prestigeManager";
import { AllSkillEffects } from "../prestige/allSkillEffects";
export class BuySkillAction extends BuyAction {
constructor(public skillEffect: SkillEffect) {
super(
skillEffect,
new MultiPrice([new Price(SkillEffect.availableSkill, 1, 1)])
);
this.name = this.skillEffect.getDescription(1);
}
afterBuy(number: Decimal) {
const multi = Math.max(2 * PrestigeManager.getInstance().ascension, 1);
this.skillEffect.numOwned =
number.toNumber() * multi * this.quantity.toNumber();
this.skillEffect.afterBuy();
AllSkillEffects.effectList
.map(s => s.buyAction)
.forEach(a => {
a.reload();
});
}
reload() {
const groupNum = this.skillEffect.skillGroup.skills
.map(s => s.quantity.toNumber())
.reduce((p, c) => p + c, 0);
this.skillEffect.limit = Decimal.min(
this.skillEffect.maxLimit,
PrestigeManager.getInstance().totalPrestige *
this.skillEffect.skillGroup.maxPercent -
groupNum +
this.quantity.toNumber()
).floor();
if (this.skillEffect.limit.gt(0)) super.reload();
else {
this.canBuy = false;
}
if (this.maxBuy.lt(1)) this.canBuy = false;
if (!this.canBuy) this.maxBuy = new Decimal(0);
}
}