From d5a0b88796a46854758dbd1ff49a7783056565ab Mon Sep 17 00:00:00 2001 From: Harley White Date: Mon, 10 May 2021 18:18:02 -0400 Subject: [PATCH] Added onEnter and onExit for challenges --- changelog.md | 4 ++++ docs/challenges.md | 4 ++++ docs/layer-features.md | 5 ++++- js/Demo/demoLayers.js | 5 ++++- js/game.js | 8 ++++++-- js/technical/temp.js | 3 ++- 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 2014337..52b7934 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # The Modding Tree changelog: +- Added directMult, which multiplies gain after exponents and softcaps. It actually multiplies gain for static layers. +- Added onEnter and onExit for challenges. +- Added documentation on how gainMult/Exp work for static layers. + # v2.5.3 - 5/8/21 - Improved performance of tab formats and bars. - Respec confirmation settings are now kept on resets. diff --git a/docs/challenges.md b/docs/challenges.md index 567d527..0c36d3f 100644 --- a/docs/challenges.md +++ b/docs/challenges.md @@ -48,6 +48,10 @@ Individual Challenges can have these features: - onComplete() - **optional**. this function will be called when the challenge is completed when previously incomplete. +- onEnter() - **optional**. this function will be called when entering the challenge + +- onExit() - **optional**. this function will be called when exiting the challenge in any way + - countsAs: **optional**. If a challenge combines the effects of other challenges in this layer, you can use this. An array of challenge ids. The player is effectively in all of those challenges when in the current one. - completionLimit: **optional**. the amount of times you can complete this challenge. Default is 1 completion. diff --git a/docs/layer-features.md b/docs/layer-features.md index a33f792..96dba6e 100644 --- a/docs/layer-features.md +++ b/docs/layer-features.md @@ -101,7 +101,10 @@ You can make almost any value dynamic by using a function in its place, includin - roundUpCost: **optional**. a bool, which is true if the resource cost needs to be rounded up. (use if the base resource is a "static" currency.) -- gainMult(), gainExp(): **optional**. Functions that calculate the multiplier and exponent on resource gain from upgrades and boosts and such. Plug in any bonuses here. +- gainMult(), gainExp(): **optional**. For normal layers, these functions calculate the multiplier and exponent on resource gain from upgrades and boosts and such. Plug in most bonuses here. + For static layers, they instead divide and root the cost of the resource. + +- directMult(): **optional**. Directly multiplies the resource gain, after exponents and softcaps. For static layers, actually multiplies resource gain instead of reducing the cost. - softcap, softcapPower: **optional**. For normal layers, gain beyond [softcap] points is put to the [softcapPower]th power Default for softcap is e1e7, and for power is 0.5. diff --git a/js/Demo/demoLayers.js b/js/Demo/demoLayers.js index 18b1219..3acdd18 100644 --- a/js/Demo/demoLayers.js +++ b/js/Demo/demoLayers.js @@ -95,7 +95,10 @@ addLayer("c", { rewardDisplay() { return format(this.rewardEffect())+"x" }, countsAs: [12, 21], // Use this for if a challenge includes the effects of other challenges. Being in this challenge "counts as" being in these. rewardDescription: "Says hi", - onComplete() {console.log("hiii")} // Called when you complete the challenge + onComplete() {console.log("hiii")}, // Called when you successfully complete the challenge + onEnter() {console.log("So challenging")}, + onExit() {console.log("Sweet freedom!")}, + }, }, upgrades: { diff --git a/js/game.js b/js/game.js index 756b659..f743d3f 100644 --- a/js/game.js +++ b/js/game.js @@ -264,8 +264,10 @@ function startChallenge(layer, x) { enter = true } doReset(layer, true) - if(enter) player[layer].activeChallenge = x - + if(enter) { + player[layer].activeChallenge = x + run(layers[layer].challenges[x].onEnter, layers[layer].challenges[x]) + } updateChallengeTemp(layer) } @@ -301,6 +303,7 @@ function completeChallenge(layer, x) { let completions = canCompleteChallenge(layer, x) if (!completions){ player[layer].activeChallenge = null + run(layers[layer].challenges[x].onExit, layers[layer].challenges[x]) return } if (player[layer].challenges[x] < tmp[layer].challenges[x].completionLimit) { @@ -310,6 +313,7 @@ function completeChallenge(layer, x) { if (layers[layer].challenges[x].onComplete) run(layers[layer].challenges[x].onComplete, layers[layer].challenges[x]) } player[layer].activeChallenge = null + run(layers[layer].challenges[x].onExit, layers[layer].challenges[x]) updateChallengeTemp(layer) } diff --git a/js/technical/temp.js b/js/technical/temp.js index d57c820..0e8ecd8 100644 --- a/js/technical/temp.js +++ b/js/technical/temp.js @@ -6,10 +6,11 @@ var NaNalert = false; // Tmp will not call these var activeFunctions = [ "startData", "onPrestige", "doReset", "update", "automate", - "buy", "buyMax", "respec", "onComplete", "onPurchase", "onPress", "onClick", "onHold", "masterButtonPress", + "buy", "buyMax", "respec", "onPress", "onClick", "onHold", "masterButtonPress", "sellOne", "sellAll", "pay", "actualCostFunction", "actualEffectFunction", "effectDescription", "display", "fullDisplay", "effectDisplay", "rewardDisplay", "tabFormat", "content", + "onComplete", "onPurchase", "onEnter", "onExit", ] var noCall = doNotCallTheseFunctionsEveryTick