-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgrade.ts
More file actions
135 lines (120 loc) · 4.77 KB
/
Copy pathupgrade.ts
File metadata and controls
135 lines (120 loc) · 4.77 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// class NewUpgrade {
// readonly modifier: NewModifier
// constructor(public sim: BaseSimulator, public name: string, components: NewModifier.Component[]) {
// this.modifier = new NewModifier(sim, components, name, true);
// }
// }
enum UpgradeFlags {
Unlocked = 0x001,
Unsupported = 0x002,
Egg = 0x004,
SantaReward = 0x008,
GoldenSwitch = 0x010,
SeasonChanger = 0x020,
RareEgg = 0x040,
Cookie = 0x080,
Synergy = 0x100,
Toggle = 0x200,
HeartCookie = 0x400,
Prestige = 0x800,
}
class Upgrade extends Purchase {
readonly basePrice: number
constructor(sim: Simulator, public name: string, private flags: UpgradeFlags = 0) {
super(sim);
let gameUpgrade = Game.Upgrades[name];
if (gameUpgrade) {
this.basePrice = gameUpgrade.basePrice;
} else {
console.log("Upgrade not found: " + name);
}
if (this.flags & (UpgradeFlags.Egg | UpgradeFlags.RareEgg))
this.boostsEggCount();
if (this.flags & UpgradeFlags.HeartCookie)
this.boostsHeartCookieCount();
}
get isAvailable(): boolean { return this.isUnlocked && !this.isUnsupported && !this.isApplied; }
get isCookie(): boolean { return (this.flags & UpgradeFlags.Cookie) > 0; }
get isEgg(): boolean { return (this.flags & UpgradeFlags.Egg) > 0; }
get isGoldenSwitch(): boolean { return (this.flags & UpgradeFlags.GoldenSwitch) > 0; }
get isHeartCookie(): boolean { return (this.flags & UpgradeFlags.HeartCookie) > 0; }
get isPrestige(): boolean { return (this.flags & UpgradeFlags.Prestige) > 0; }
get isRareEgg(): boolean { return (this.flags & UpgradeFlags.RareEgg) > 0; }
get isSantaReward(): boolean { return (this.flags & UpgradeFlags.SantaReward) > 0; }
get isSeasonChanger(): boolean { return (this.flags & UpgradeFlags.SeasonChanger) > 0; }
get isSynergy(): boolean { return (this.flags & UpgradeFlags.Synergy) > 0; }
get isToggle(): boolean { return (this.flags & UpgradeFlags.Toggle) > 0; }
get isUnlocked(): boolean { return (this.flags & UpgradeFlags.Unlocked) > 0; }
get isUnsupported(): boolean { return (this.flags & UpgradeFlags.Unsupported) > 0; }
set isUnlocked(flag: boolean) {
if (flag) {
this.flags |= UpgradeFlags.Unlocked;
} else {
this.flags &= ~UpgradeFlags.Unlocked;
}
}
reset(): void {
this.isUnlocked = false;
super.reset();
}
requiresSeason(name: string): this {
let season: Season = this.sim.seasons[name];
if (!season) {
console.log("Missing season for " + this.name + ": " + name);
} else {
season.addLock(this);
}
return this;
}
get price(): number {
let p: number = this.basePrice;
if (this.name == "Elder Pledge")
p = Math.pow(8, Math.min(Game.pledges + 2, 14));
else if (this.isSantaReward)
p = this.sim.santa.randomRewardCost(this.sim.santa.level);
else if (this.isRareEgg)
p = Math.pow(3, this.sim.eggCount) * 999;
else if (this.isEgg)
p = Math.pow(2, this.sim.eggCount) * 999;
else if (this.isSeasonChanger)
p = this.basePrice * Math.pow(2, this.sim.seasonChanges);
else if (this.isGoldenSwitch)
p = this.sim.cps * 60 * 60;
if (this.isCookie)
p *= this.sim.cookieUpgradePriceMultiplier;
if (this.isSynergy)
p *= this.sim.synergyUpgradePriceMultiplier;
return Math.ceil(p * this.sim.upgradePriceScale * this.sim.upgradePriceCursorScale);
}
get matchErrors(): string[] {
if (!(this.flags & UpgradeFlags.Unsupported)) {
let gameObj = Game.Upgrades[this.name];
if (!gameObj)
return ["Upgrade Name " + this.name + " has no corresponding match in store."];
if (!floatEqual(this.price, gameObj.getPrice()))
return ["Upgrade Cost " + this.name + " - Predicted: " + this.price + ", Actual: " + gameObj.getPrice()];
if (this.isApplied && gameObj.bought == 0)
return ["Upgrade " + this.name + " bought in sim but not bought in game."];
if (!this.isApplied && gameObj.bought == 1)
return ["Upgrade " + this.name + " not bought in sim but bought in game."];
if (this.isUnlocked && gameObj.unlocked == 0)
return ["Upgrade " + this.name + " unlocked but not unlocked in game."];
if (!this.isUnlocked && gameObj.unlocked == 1)
return ["Upgrade " + this.name + " locked but not locked in game."];
}
return [];
}
get value(): number {
if (this.name == "Chocolate egg" || (this.flags & UpgradeFlags.Unsupported))
return 0;
let ben: number = this.benefit;
if (ben > 0)
return ben;
let m = new Modifier(this.sim).scalesProduction(1.01);
return m.benefit;
}
purchase(): void {
Game.Upgrades[this.name].buy(1);
this.apply();
}
}