Skip to content

Commit 2e84cb3

Browse files
feat(core): Remove hardcoded build requirements
Previously, builds would optionally define a single required resource. This resource would be the only one taken into consideration for the trigger value. Now, this hardcoded requirement has been removed and the trigger applies to all source materials that have a capacity.
1 parent c0b6e88 commit 2e84cb3

File tree

6 files changed

+56
-150
lines changed

6 files changed

+56
-150
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"biolab",
2323
"Blackcoin",
2424
"blackcoins",
25+
"broadcasttower",
2526
"browserstack",
2627
"bulkmanager",
2728
"calciner",

packages/userscript/source/WorkshopManager.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,23 @@ export class WorkshopManager extends UpgradeManager implements Automation {
107107

108108
const materials = Object.keys(this.getMaterials(craft.resource)) as Array<Resource>;
109109
// The resource information for the requirement of this craft which have a capacity.
110-
const require = materials
110+
const requiredMaterials = materials
111111
.map(material => this.getResource(material))
112112
.filter(material => 0 < material.maxValue);
113113

114114
const allMaterialsAboveTrigger =
115-
require.filter(material => material.value / material.maxValue < trigger).length === 0;
115+
requiredMaterials.filter(material => material.value / material.maxValue < trigger)
116+
.length === 0;
116117

117118
if (!allMaterialsAboveTrigger) {
118119
continue;
119120
}
120121

121-
const amount = this.getLowestCraftAmount(craft.resource, craft.limited, 0 < require.length);
122+
const amount = this.getLowestCraftAmount(
123+
craft.resource,
124+
craft.limited,
125+
0 < requiredMaterials.length
126+
);
122127

123128
// If we can craft any of this item, do it.
124129
if (0 < amount) {

packages/userscript/source/helper/BulkPurchaseHelper.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BonfireItem } from "../settings/BonfireSettings";
2-
import { AllItems, Requirement } from "../settings/Settings";
2+
import { AllItems } from "../settings/Settings";
33
import { objectEntries } from "../tools/Entries";
44
import { isNil, mustExist } from "../tools/Maybe";
55
import {
@@ -62,7 +62,6 @@ export class BulkPurchaseHelper {
6262
max?: number;
6363
baseBuilding?: Building;
6464
building?: AllBuildings | BonfireItem;
65-
require?: Requirement;
6665
stage?: number;
6766
variant?: TimeItemVariant | UnicornItemVariant;
6867
}
@@ -153,10 +152,15 @@ export class BulkPurchaseHelper {
153152
}
154153

155154
// Check the requirements for this build.
156-
const require = !build.require ? false : this._workshopManager.getResource(build.require);
157-
// Either if we don't require a resource, of the stock is filled to a percentage
158-
// greater than the trigger value.
159-
if (!require || trigger <= require.value / require.maxValue) {
155+
// We want a list of all resources that are required for this build, which have a capacity.
156+
const requiredMaterials = prices
157+
.map(price => this._workshopManager.getResource(price.name))
158+
.filter(material => 0 < material.maxValue);
159+
const allMaterialsAboveTrigger =
160+
requiredMaterials.filter(material => material.value / material.maxValue < trigger)
161+
.length === 0;
162+
163+
if (allMaterialsAboveTrigger) {
160164
// If the build is for a stage that the building isn't currently at, skip it.
161165
if (
162166
this._isStagedBuild(buildMetaData) &&

packages/userscript/source/settings/BonfireSettings.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { consumeEntriesPedantic } from "../tools/Entries";
22
import { isNil, Maybe } from "../tools/Maybe";
33
import { Building } from "../types";
44
import { BuildingUpgradeSettings } from "./BuildingUpgradeSettings";
5-
import { Requirement, Setting, SettingMax, SettingTrigger } from "./Settings";
5+
import { Setting, SettingMax, SettingTrigger } from "./Settings";
66

77
/**
88
* One of the building options in the KS menu.
@@ -20,11 +20,6 @@ export class BonfireBuildingSetting extends SettingMax {
2020

2121
readonly building: BonfireItem;
2222

23-
/**
24-
* A resource that you must have unlocked to build this.
25-
*/
26-
readonly require: Requirement = false;
27-
2823
/**
2924
* In case this is an upgradable building, this indicates the level of
3025
* the stage.

packages/userscript/source/settings/ReligionSettings.ts

Lines changed: 32 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { consumeEntriesPedantic } from "../tools/Entries";
22
import { isNil, Maybe } from "../tools/Maybe";
33
import { UnicornItemVariant } from "../types";
4-
import { Requirement, Setting, SettingMax, SettingTrigger } from "./Settings";
4+
import { Setting, SettingMax, SettingTrigger } from "./Settings";
55

66
export type FaithItem =
77
| "apocripha"
@@ -42,19 +42,16 @@ export type ReligionAdditionItem = "adore" | "autoPraise" | "bestUnicornBuilding
4242

4343
export class ReligionSettingsItem extends SettingMax {
4444
readonly building: FaithItem | UnicornItem;
45-
readonly require: Requirement;
4645
readonly variant: UnicornItemVariant;
4746

4847
constructor(
4948
building: FaithItem | UnicornItem,
5049
variant: UnicornItemVariant,
5150
enabled = false,
52-
max = -1,
53-
require: Requirement = false
51+
max = -1
5452
) {
5553
super(enabled, max);
5654
this.building = building;
57-
this.require = require;
5855
this.variant = variant;
5956
}
6057
}
@@ -105,215 +102,130 @@ export class ReligionSettings extends SettingTrigger {
105102
enabled = false,
106103
trigger = 1,
107104
buildings: ReligionSettingsItems = {
108-
apocripha: new ReligionSettingsItem(
109-
"apocripha",
110-
UnicornItemVariant.OrderOfTheSun,
111-
false,
112-
-1,
113-
"faith"
114-
),
115-
basilica: new ReligionSettingsItem(
116-
"basilica",
117-
UnicornItemVariant.OrderOfTheSun,
118-
true,
119-
-1,
120-
"faith"
121-
),
105+
apocripha: new ReligionSettingsItem("apocripha", UnicornItemVariant.OrderOfTheSun, false, -1),
106+
basilica: new ReligionSettingsItem("basilica", UnicornItemVariant.OrderOfTheSun, true, -1),
122107
blackCore: new ReligionSettingsItem(
123108
"blackCore",
124109
UnicornItemVariant.Cryptotheology,
125110
false,
126-
-1,
127-
false
111+
-1
128112
),
129113
blackLibrary: new ReligionSettingsItem(
130114
"blackLibrary",
131115
UnicornItemVariant.Cryptotheology,
132116
false,
133-
-1,
134-
false
117+
-1
135118
),
136119
blackNexus: new ReligionSettingsItem(
137120
"blackNexus",
138121
UnicornItemVariant.Cryptotheology,
139122
false,
140-
-1,
141-
false
123+
-1
142124
),
143125
blackObelisk: new ReligionSettingsItem(
144126
"blackObelisk",
145127
UnicornItemVariant.Cryptotheology,
146128
false,
147-
-1,
148-
false
129+
-1
149130
),
150131
blackPyramid: new ReligionSettingsItem(
151132
"blackPyramid",
152133
UnicornItemVariant.Ziggurat,
153134
false,
154-
-1,
155-
"unobtainium"
135+
-1
156136
),
157137
blackRadiance: new ReligionSettingsItem(
158138
"blackRadiance",
159139
UnicornItemVariant.Cryptotheology,
160140
false,
161-
-1,
162-
false
163-
),
164-
blazar: new ReligionSettingsItem(
165-
"blazar",
166-
UnicornItemVariant.Cryptotheology,
167-
false,
168-
-1,
169-
false
170-
),
171-
darkNova: new ReligionSettingsItem(
172-
"darkNova",
173-
UnicornItemVariant.Cryptotheology,
174-
false,
175-
-1,
176-
false
141+
-1
177142
),
143+
blazar: new ReligionSettingsItem("blazar", UnicornItemVariant.Cryptotheology, false, -1),
144+
darkNova: new ReligionSettingsItem("darkNova", UnicornItemVariant.Cryptotheology, false, -1),
178145
goldenSpire: new ReligionSettingsItem(
179146
"goldenSpire",
180147
UnicornItemVariant.OrderOfTheSun,
181148
true,
182-
-1,
183-
"faith"
149+
-1
184150
),
185151
holyGenocide: new ReligionSettingsItem(
186152
"holyGenocide",
187153
UnicornItemVariant.Cryptotheology,
188154
false,
189-
-1,
190-
false
155+
-1
191156
),
192157
ivoryCitadel: new ReligionSettingsItem(
193158
"ivoryCitadel",
194159
UnicornItemVariant.Ziggurat,
195160
false,
196-
-1,
197-
false
198-
),
199-
ivoryTower: new ReligionSettingsItem(
200-
"ivoryTower",
201-
UnicornItemVariant.Ziggurat,
202-
false,
203-
-1,
204-
false
205-
),
206-
marker: new ReligionSettingsItem(
207-
"marker",
208-
UnicornItemVariant.Ziggurat,
209-
false,
210-
-1,
211-
"unobtainium"
161+
-1
212162
),
163+
ivoryTower: new ReligionSettingsItem("ivoryTower", UnicornItemVariant.Ziggurat, false, -1),
164+
marker: new ReligionSettingsItem("marker", UnicornItemVariant.Ziggurat, false, -1),
213165
scholasticism: new ReligionSettingsItem(
214166
"scholasticism",
215167
UnicornItemVariant.OrderOfTheSun,
216168
true,
217-
-1,
218-
"faith"
169+
-1
219170
),
220171
singularity: new ReligionSettingsItem(
221172
"singularity",
222173
UnicornItemVariant.Cryptotheology,
223174
false,
224-
-1,
225-
false
226-
),
227-
skyPalace: new ReligionSettingsItem(
228-
"skyPalace",
229-
UnicornItemVariant.Ziggurat,
230-
false,
231-
-1,
232-
false
175+
-1
233176
),
177+
skyPalace: new ReligionSettingsItem("skyPalace", UnicornItemVariant.Ziggurat, false, -1),
234178
solarchant: new ReligionSettingsItem(
235179
"solarchant",
236180
UnicornItemVariant.OrderOfTheSun,
237181
true,
238-
-1,
239-
"faith"
182+
-1
240183
),
241184
solarRevolution: new ReligionSettingsItem(
242185
"solarRevolution",
243186
UnicornItemVariant.OrderOfTheSun,
244187
true,
245-
-1,
246-
"faith"
188+
-1
247189
),
248190
stainedGlass: new ReligionSettingsItem(
249191
"stainedGlass",
250192
UnicornItemVariant.OrderOfTheSun,
251193
true,
252-
-1,
253-
"faith"
254-
),
255-
sunAltar: new ReligionSettingsItem(
256-
"sunAltar",
257-
UnicornItemVariant.OrderOfTheSun,
258-
true,
259-
-1,
260-
"faith"
261-
),
262-
sunspire: new ReligionSettingsItem(
263-
"sunspire",
264-
UnicornItemVariant.Ziggurat,
265-
false,
266-
-1,
267-
"gold"
268-
),
269-
templars: new ReligionSettingsItem(
270-
"templars",
271-
UnicornItemVariant.OrderOfTheSun,
272-
true,
273-
-1,
274-
"faith"
194+
-1
275195
),
196+
sunAltar: new ReligionSettingsItem("sunAltar", UnicornItemVariant.OrderOfTheSun, true, -1),
197+
sunspire: new ReligionSettingsItem("sunspire", UnicornItemVariant.Ziggurat, false, -1),
198+
templars: new ReligionSettingsItem("templars", UnicornItemVariant.OrderOfTheSun, true, -1),
276199
transcendence: new ReligionSettingsItem(
277200
"transcendence",
278201
UnicornItemVariant.OrderOfTheSun,
279202
true,
280-
-1,
281-
"faith"
203+
-1
282204
),
283205
unicornGraveyard: new ReligionSettingsItem(
284206
"unicornGraveyard",
285207
UnicornItemVariant.Ziggurat,
286208
false,
287-
-1,
288-
false
209+
-1
289210
),
290211
unicornNecropolis: new ReligionSettingsItem(
291212
"unicornNecropolis",
292213
UnicornItemVariant.Ziggurat,
293214
false,
294-
-1,
295-
false
215+
-1
296216
),
297217
unicornPasture: new ReligionSettingsItem(
298218
"unicornPasture",
299219
UnicornItemVariant.UnicornPasture,
300220
true,
301-
-1,
302-
false
303-
),
304-
unicornTomb: new ReligionSettingsItem(
305-
"unicornTomb",
306-
UnicornItemVariant.Ziggurat,
307-
false,
308-
-1,
309-
false
221+
-1
310222
),
223+
unicornTomb: new ReligionSettingsItem("unicornTomb", UnicornItemVariant.Ziggurat, false, -1),
311224
unicornUtopia: new ReligionSettingsItem(
312225
"unicornUtopia",
313226
UnicornItemVariant.Ziggurat,
314227
false,
315-
-1,
316-
"gold"
228+
-1
317229
),
318230
},
319231
bestUnicornBuilding = new Setting(false),

0 commit comments

Comments
 (0)