-
Notifications
You must be signed in to change notification settings - Fork 0
Buildings
Buildings are created by creating an instance of the Building
class, requiring the following parameters:
Parameter | Usage | Type | Required? |
---|---|---|---|
name | The name of the building. If the version of the game is less than 0.7, then this must be the object instance name! | string |
Yes |
quote | What quote to be put below the name of the building | string |
Yes |
upgradeCost | How much it costs to upgrade the building. Is multiplied by 1.15 whenever the building is purchased. | number |
Yes |
CPSGain | How many Cookies Per Second is gained whenever the building is purchased. | number |
Yes |
iconImg | What image file should be used for the building icon. Currently only supports anything in the /img directory. | string |
No, default: "unknown.png" |
esPlural | Because of the english language being strange with how plural words work, defining whether your building has an "s" plural or an "es" plural form in a necessity. false: "s" plural, true: "es" plural. | boolean |
No, default: false |
Here is an example of how the Keyboard building is created:
const keyboard = new Building("keyboard","type in cookies",15,0.1,"keyboard.png");
keyboard.unlocked = true;
keyboard.unlocked needs to be set to true
since the Keyboard building is unlocked by default.
One of the most confusing parts of creating a building is the difference between the two variables CPSGiven
and CPSGain
, below is an explaination for the two of them.
CPSGiven
: How much CPS the building is actively giving you. If you have bought two grandpas, the CPSGiven
variable for the grandpa will be equal to 2. If you bought 5 keyboards, the CPSGiven variable will be equal to 0.5.
CPSGain
: How much CPS a building gives you when you buy one. The CPSGain
of a keyboard is 0.1
, since that is the amount that it gives you.
How these variables work together can further complicate their understanding. When an upgrade for a building is bought, the CPSGain
is going to be modified by how much that upgrade says it should modify it by, but the CPSGiven
will also be affected by that number. If the upgrade doubles the CPSGain
, then the CPSGiven
will also be doubled.
Without context, this doesn't make much sense, but upon digging deeper, it becomes a bigger issue. Prices reload fine when a building is purchased, but more specifically when a save is loaded (or something similar), a function called helper.reloadBuildingPrices()
is run, which will reload the prices for every vanilla building defined within the function, but this doesn't account for modded buildings. The solution recommended for mod developers is to create some sort of loop somewhere within their code that will run a custom reloadBuildingPrices()
function. Do not overwrite the vanilla helper.reloadBuildingPrices()
function. This will lead to conflicts with other mods that add their own buildings.