1
0
Fork 0
mirror of https://github.com/Acamaeda/The-Modding-Tree.git synced 2024-11-27 18:41:57 +00:00

Auto-supply amounts to buyable cost/effect

This commit is contained in:
Harley White 2021-04-30 22:08:25 -04:00
parent 349a94c19f
commit 4af32d5c71
7 changed files with 31 additions and 5 deletions

View file

@ -1,5 +1,7 @@
# The Modding Tree changelog: # The Modding Tree changelog:
- Amount is automatically supplied to buyable cost and effect functions.
# v2.4.1 - 4/29/21 # v2.4.1 - 4/29/21
- A number of minor fixes, many thanks to thepaperpilot. - A number of minor fixes, many thanks to thepaperpilot.
- The respec confirmation checkbox is now part of the respec-button component. - The respec confirmation checkbox is now part of the respec-button component.

View file

@ -14,6 +14,8 @@
<script src="js/demo/demoLayers.js"></script> <script src="js/demo/demoLayers.js"></script>
<script src="js/demo/demoMod.js"></script> <script src="js/demo/demoMod.js"></script>
<script src="js/technical/temp.js"></script> <script src="js/technical/temp.js"></script>
<script src="js/technical/displays.js"></script>
<script src="js/game.js"></script> <script src="js/game.js"></script>
<script src="js/utils.js"></script> <script src="js/utils.js"></script>
<script src="js/technical/systemComponents.js"></script> <script src="js/technical/systemComponents.js"></script>

View file

@ -32,9 +32,11 @@ Features:
- title: **optional**. displayed at the top in a larger font. It can also be a function that returns updating text. - title: **optional**. displayed at the top in a larger font. It can also be a function that returns updating text.
- cost(): cost for buying the next buyable. Can have an optional argument "x" to calculate the cost of the x+1th object, but needs to use "current amount" as a default value for x. (x is a `Decimal`). Can return an object if there are multiple currencies. - cost(): cost for buying the next buyable. Can have an optional argument "x" to calculate the cost of the x+1th purchase. (x is a `Decimal`).
Can return an object if there are multiple currencies.
- effect(): **optional**. A function that calculates and returns the current values of bonuses of this buyable. Can return a value or an object containing multiple values. - effect(): **optional**. A function that calculates and returns the current values of bonuses of this buyable. Can have an optional argument "x", similar to cost.
Can return a value or an object containing multiple values.
- display(): A function returning everything that should be displayed on the buyable after the title, likely including the description, amount bought, cost, and current effect. Can use basic HTML. - display(): A function returning everything that should be displayed on the buyable after the title, likely including the description, amount bought, cost, and current effect. Can use basic HTML.

View file

@ -14,6 +14,7 @@
<script src="js/layers.js"></script> <script src="js/layers.js"></script>
<script src="js/mod.js"></script> <script src="js/mod.js"></script>
<script src="js/technical/temp.js"></script> <script src="js/technical/temp.js"></script>
<script src="js/technical/displays.js"></script>
<script src="js/game.js"></script> <script src="js/game.js"></script>
<script src="js/utils.js"></script> <script src="js/utils.js"></script>
<script src="js/technical/systemComponents.js"></script> <script src="js/technical/systemComponents.js"></script>

View file

@ -158,12 +158,12 @@ addLayer("c", {
respecMessage: "Are you sure? Respeccing these doesn't accomplish much.", respecMessage: "Are you sure? Respeccing these doesn't accomplish much.",
11: { 11: {
title: "Exhancers", // Optional, displayed at the top in a larger font title: "Exhancers", // Optional, displayed at the top in a larger font
cost(x=player[this.layer].buyables[this.id]) { // cost for buying xth buyable, can be an object if there are multiple currencies cost(x) { // cost for buying xth buyable, can be an object if there are multiple currencies
if (x.gte(25)) x = x.pow(2).div(25) if (x.gte(25)) x = x.pow(2).div(25)
let cost = Decimal.pow(2, x.pow(1.5)) let cost = Decimal.pow(2, x.pow(1.5))
return cost.floor() return cost.floor()
}, },
effect(x=player[this.layer].buyables[this.id]) { // Effects of owning x of the items, x is a decimal effect(x) { // Effects of owning x of the items, x is a decimal
let eff = {} let eff = {}
if (x.gte(0)) eff.first = Decimal.pow(25, x.pow(1.1)) if (x.gte(0)) eff.first = Decimal.pow(25, x.pow(1.1))
else eff.first = Decimal.pow(1/25, x.times(-1).pow(1.1)) else eff.first = Decimal.pow(1/25, x.times(-1).pow(1.1))

0
js/technical/displays.js Normal file
View file

View file

@ -7,7 +7,7 @@ var NaNalert = false;
var activeFunctions = [ var activeFunctions = [
"startData", "onPrestige", "doReset", "update", "automate", "startData", "onPrestige", "doReset", "update", "automate",
"buy", "buyMax", "respec", "onComplete", "onPurchase", "onPress", "onClick", "masterButtonPress", "buy", "buyMax", "respec", "onComplete", "onPurchase", "onPress", "onClick", "masterButtonPress",
"sellOne", "sellAll", "pay", "sellOne", "sellAll", "pay", "actualCostFunction", "actualEffectFunction",
] ]
var noCall = doNotCallTheseFunctionsEveryTick var noCall = doNotCallTheseFunctionsEveryTick
@ -36,6 +36,7 @@ function setupTemp() {
tmp[layer].prestigeButtonText = {} tmp[layer].prestigeButtonText = {}
tmp[layer].computedNodeStyle = [] tmp[layer].computedNodeStyle = []
setupBarStyles(layer) setupBarStyles(layer)
setupBuyables(layer)
} }
temp = tmp temp = tmp
} }
@ -230,3 +231,21 @@ function setupBarStyles(layer){
bar.fillDims = {} bar.fillDims = {}
} }
} }
function setupBuyables(layer) {
for (id in layers[layer].buyables) {
if (!isNaN(id)) {
let b = layers[layer].buyables[id]
b.actualCostFunction = b.cost
b.cost = function(x) {
x = x ?? player[this.layer].buyables[this.id]
return layers[this.layer].buyables[this.id].actualCostFunction(x)
}
b.actualEffectFunction = b.effect
b.effect = function(x) {
x = x ?? player[this.layer].buyables[this.id]
return layers[this.layer].buyables[this.id].actualEffectFunction(x)
}
}
}
}