-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodifier.ts
More file actions
224 lines (185 loc) · 10.2 KB
/
Copy pathmodifier.ts
File metadata and controls
224 lines (185 loc) · 10.2 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
//
// Modifier
//
// Modifiers are used to change some of the values in a BaseSimulation. They encapsulate the functionality
// of the games various upgrades, buildings, buffs etc.
//
class Modifier {
applicationCount: number = 0
components: Modifier.Component[] = []
constructor(public sim: Simulator, public isUnique?: boolean) {}
get isApplied(): boolean {
return this.applicationCount > 0;
}
// The benefit is the exact amount of effective CpS that will be gained from applying this
// modifier
get benefit(): number {
let cps: number = this.sim.effectiveCps();
this.apply();
cps = this.sim.effectiveCps() - cps;
this.revoke();
return cps;
}
reset(): void {
this.applicationCount = 0;
}
apply(): void {
if (!this.isUnique && this.isApplied)
throw new Error("Attempt to reapply unique modifier.");
for (let i = 0; i < this.components.length; ++i)
this.components[i].apply(this.sim);
this.applicationCount++;
}
revoke(): void {
if (this.applicationCount <= 0) {
throw new Error("Attempt to revoke unapplied modifier.");
} else {
for (let i = this.components.length - 1; i >= 0; --i)
this.components[i].revoke(this.sim);
this.applicationCount--;
}
}
protected addComponent(component: Modifier.Component): this {
this.components.push(component);
return this;
}
protected addScaler(field: string, scale: number): this {
return this.addComponent(new Modifier.Scaler(field, scale));
}
protected addBooster(field: string, amount: number): this {
return this.addComponent(new Modifier.Booster(field, amount));
}
protected addNestedBooster(field: string, subfield: string, amount: number): this {
return this.addComponent(new Modifier.NestedBooster(field, subfield, amount));
}
angersGrandmas(): this { return this.addBooster("grandmatriarchLevel", 1); }
boostsBaseCps(amount: number): this { return this.addBooster("baseCps", amount); }
boostsClickCps(amount: number): this { return this.addBooster("cpcCpsMultiplier", amount); }
boostsEggCount(amount: number = 1): this { return this.addBooster("eggCount", amount); }
boostsHeartCookieCount(amount: number = 1): this { return this.addBooster("heartCookieCount", amount); }
boostsLumpScale(amount: number): this { return this.addBooster("lumpScale", amount); }
boostsLumpScaleLimit(amount: number): this { return this.addBooster("lumpScaleLimit", amount); }
boostsMaxWrinklers(amount: number): this { return this.addBooster("maxWrinklers", amount); }
boostsSantaPower(amount: number): this { return this.addNestedBooster("santa", "power", amount); }
calmsGrandmas(): this { return this; }
cursesFinger(): this { return this.addBooster("cursedFingerCount", 1); }
enablesUpgradePriceCursorScale(): this { return this.addBooster("upgradePriceCursorScaleEnables", 1); }
scalesBaseClicking(scale: number): this { return this.addScaler("cpcBaseMultiplier", scale); }
scalesBuildingPrice(scale: number): this { return this.addScaler("buildingPriceScale", scale); }
scalesBuildingRefundRate(scale: number): this { return this.addScaler("buildingRefundRate", scale); }
scalesCenturyMultiplier(scale: number): this { return this.addScaler("centuryMultiplier", scale); }
scalesClickFrenzyMultiplier(scale: number): this { return this.addScaler("clickFrenzyMultiplier", scale); }
scalesClicking(scale: number): this { return this.addScaler("cpcMultiplier", scale); }
scalesCookieUpgradePrice(scale: number): this { return this.addScaler("cookieUpgradePriceMultiplier", scale); }
scalesElderPledgeDuration(scale: number): this { return this.addScaler("elderPledgeDurationScale", scale); }
scalesFrenzyMultiplier(scale: number): this { return this.addScaler("frenzyMultiplier", scale); }
scalesGoldenCookieDuration(scale: number): this { return this.addScaler("goldenCookieDuration", scale); }
scalesHeartCookies(scale: number): this { return this.addScaler("heartCookieScale", scale); }
scalesGoldenCookieEffectDuration(scale: number): this { return this.addScaler("goldenCookieEffectDurationMultiplier", scale); }
scalesGoldenCookieFrequency(scale: number): this { return this.addScaler("goldenCookieTime", 1 / scale); }
scalesMilk(scale: number): this { return this.addScaler("milkMultiplier", scale); }
scalesPrestige(scale: number): this { return this.addScaler("prestigeScale", scale); }
scalesProduction(scale: number): this { return this.addScaler("productionScale", scale); }
scalesRandomDropFrequency(scale: number): this { return this; }
scalesReindeer(scale: number): this { return this.addScaler("reindeerMultiplier", scale); }
scalesReindeerBuffMultiplier(scale: number): this { return this.addScaler("reindeerBuffMultiplier", scale); }
scalesReindeerDuration(scale: number): this { return this.addScaler("reindeerDuration", scale); }
scalesReindeerFrequency(scale: number): this { return this.addScaler("reindeerTime", scale); }
scalesSynergyUpgradePrice(scale: number): this { return this.addScaler("synergyUpgradePriceMultiplier", scale); }
scalesUpgradePrice(scale: number): this { return this.addScaler("upgradePriceScale", scale); }
setsSeason(name: string): this { return this.addComponent(new Modifier.SeasonChanger(name)); }
unlocksMilk(amount: number, tier: number = 0): this { return this.addComponent(new Modifier.MilkScaler(amount, tier)); }
unlocksPrestige(amount: number): this { return this.addBooster("prestigeUnlocked", amount); }
givesBuildingPerBuildingFlatCpsBoost(receiver: BuildingIndex, source: BuildingIndex, amount: number): this {
return this.addComponent(new Modifier.BuildingCountBooster(receiver, "perBuildingFlatCpsBoostCounter", BuildingCounter.ForMost(source, amount)));
}
givesBuildingPerBuildingBoost(receiver: BuildingIndex, source: BuildingIndex, amount: number): this {
return this.addComponent(new Modifier.BuildingCountBooster(receiver, "scaleCounter", BuildingCounter.ForMost(source, amount)));
}
givesPerBuildingFlatCpcBoost(source: BuildingIndex, amount: number): this {
return this.addComponent(new Modifier.BuildingCountBooster(null, "perBuildingFlatCpcBoostCounter", BuildingCounter.ForOne(source, amount)));
}
scalesBuildingCps(index: BuildingIndex, scale: number): this {
return this.addComponent(new Modifier.BuildingCpsScaler(index, scale));
}
scalesSeasonalGoldenCookieFrequency(season: string, scale: number): this {
return this.addComponent(new Modifier.SeasonScaler(season, "goldenCookieFrequencyScale", scale));
}
givesSynergy(receiver: BuildingIndex, giver: BuildingIndex, amount: number, reverse: number = 0): this {
this.addComponent(new Modifier.Synergy(receiver, giver, amount));
if (reverse != 0)
this.addComponent(new Modifier.Synergy(giver, receiver, reverse));
return this;
}
}
module Modifier {
// Each modifier consists of zero or more Components
export interface Component {
apply(sim: Simulator): void;
revoke(sim: Simulator): void;
}
// Booster components add a value to a given BaseSimulator field.
export class Booster implements Component {
constructor(public field: string, public amount: number = 1) {}
apply(sim: Simulator): void { sim[this.field] += this.amount; }
revoke(sim: Simulator): void { sim[this.field] -= this.amount; }
}
// Add to a building counter
export class BuildingCountBooster implements Component {
constructor(public building: BuildingIndex | null, public field: string, public counter: BuildingCounter) {}
apply(sim: Simulator): void {
if (this.building != null)
sim.buildings[this.building][this.field].add(this.counter);
else
sim[this.field].add(this.counter);
}
revoke(sim: Simulator): void {
if (this.building != null)
sim.buildings[this.building][this.field].add(this.counter);
else
sim[this.field].subtract(this.counter);
}
}
// Increase a buildings cps
export class BuildingCpsScaler implements Component {
constructor(public index: BuildingIndex, public scale: number) {}
apply(sim: Simulator): void { sim.buildings[this.index].multiplier *= this.scale; }
revoke(sim: Simulator): void { sim.buildings[this.index].multiplier /= this.scale; }
}
// Increase milk
export class MilkScaler implements Component {
constructor(public amount: number, public tier: number) {}
apply(sim: Simulator): void { sim.milkUnlocks[this.tier].push(this.amount); sim.milkUnlocks[this.tier].sort(); }
revoke(sim: Simulator): void { sim.milkUnlocks[this.tier].splice(sim.milkUnlocks[this.tier].indexOf(this.amount), 1); }
}
// Increase a field of a sub field
export class NestedBooster implements Component {
constructor(public field: string, public subfield: string, public amount: number) {}
apply(sim: Simulator): void { sim[this.field][this.subfield] += this.amount; }
revoke(sim: Simulator): void { sim[this.field][this.subfield] -= this.amount; }
}
// Scaler components multiply a BaseSimulator field by a given value.
export class Scaler implements Component {
constructor(public field: string, public scale: number) {}
apply(sim: Simulator): void { sim[this.field] *= this.scale; }
revoke(sim: Simulator): void { sim[this.field] /= this.scale; }
}
// Scaler a field of a season by an amount
export class SeasonScaler implements Component {
constructor(public season: string, public field: string, public scale: number) {}
apply(sim: Simulator): void { sim.seasons[this.season][this.field] *= this.scale; }
revoke(sim: Simulator): void { sim.seasons[this.season][this.field] /= this.scale; }
}
// SeasonChanger component sets the season
export class SeasonChanger implements Component {
constructor(public name: string) {}
apply(sim: Simulator): void { sim.seasonStack.push(name); sim.seasonChanges++; }
revoke(sim: Simulator): void { sim.seasonStack.pop(); sim.seasonChanges--; }
}
// Synergies give buildings boosts based on the count of another building
export class Synergy implements Component {
constructor(public receiver: BuildingIndex, public giver: BuildingIndex, public amount: number) {}
apply(sim: Simulator): void { sim.buildings[this.receiver].addSynergy(this.giver, this.amount); }
revoke(sim: Simulator): void { sim.buildings[this.receiver].removeSynergy(this.giver, this.amount); }
}
}