From 029f5546c0108a1de8edd5e444d7fb472050416a Mon Sep 17 00:00:00 2001 From: Acamaeda Date: Sun, 27 Sep 2020 18:01:36 -0400 Subject: [PATCH] More features and customization for Challenges --- index.html | 8 ++++---- js/game.js | 36 +++++++++++++++++++++++++++++++++--- js/layers.js | 23 +++++++++++++++++++++++ 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 7825049..77a99c0 100644 --- a/index.html +++ b/index.html @@ -150,13 +150,13 @@
-
+

{{layers[layer].challs[row*10+col].name}}



-

+

{{layers[layer].challs[row*10+col].desc}}
- Goal: {{format(layers[layer].challs[row*10+col].goal)}} Points
+ Goal: {{format(layers[layer].challs[row*10+col].goal)}} {{layers[layer].challs[row*10+col].currencyDisplayName ? layers[layer].challs[row*10+col].currencyDisplayName : "points"}}
Reward: {{layers[layer].challs[row*10+col].reward}}
- Currently: {{layers[layer].challs[row*10+col].effDisp(layers[layer].challs[row*10+col].effect())}} + Currently: {{(layers[layer].challs[row*10+col].effDisp) ? (layers[layer].challs[row*10+col].effDisp(layers[layer].challs[row*10+col].effect())) : format(layers[layer].challs[row*10+col].effect())}}
diff --git a/js/game.js b/js/game.js index 43d5fdd..e446e02 100644 --- a/js/game.js +++ b/js/game.js @@ -36,6 +36,14 @@ function getPointGen() { return gain } +// Function to determine if the player is in a challenge +function inChallenge(layer, id){ + if (player.c.active==x) return true + + if (layers[layer].challs[id].countsAs) + return layers[layer].challs[id].countsAs.includes(id) +} + function save() { localStorage.setItem("prestige-tree", btoa(JSON.stringify(player))) } @@ -263,7 +271,6 @@ function layerUnl(layer) { function rowReset(row, layer) { for (lr in ROW_LAYERS[row]){ - console.log(lr) if(layers[lr].doReset) layers[lr].doReset(layer) else @@ -412,13 +419,36 @@ function startChall(layer, x) { updateChallTemp(layer) } +function canCompleteChall(layer, x) +{ + if (x != player[layer].active) return + + let chall = layers[layer].challs[x] + + if (chall.currencyInternalName){ + let name = chall.currencyInternalName + if (chall.currencyLayer){ + let lr = chall.currencyLayer + return !(player[lr][name].lt(chall.goal)) + } + else { + return !(player[name].lt(chall.cost)) + } + } + else { + return !(player[layer].points.lt(chall.cost)) + } + +} + function completeChall(layer, x) { var x = player[layer].active if (!x) return - if (!player.points.gte(layers[layer].challs[x].goal)) return + if (! canCompleteChall(layer, x)) return if (!player[layer].challs.includes(x)) { - //if (layer == "h" && x == 62) needCanvasUpdate = true + needCanvasUpdate = true player[layer].challs.push(x); + if (layers[layer].challs[x].onComplete) layers[layer].challs[x].onComplete() } delete player[layer].active updateChallTemp(layer) diff --git a/js/layers.js b/js/layers.js index 81a2c72..d7c660e 100644 --- a/js/layers.js +++ b/js/layers.js @@ -7,6 +7,7 @@ var layers = { total: new Decimal(0), upgrades: [], milestones: [], + challs: [], beep: false, }}, color: "#4BEC13", @@ -81,6 +82,28 @@ var layers = { } }, }, + + challs: { + rows: 1, + cols: 1, + 11: { + name: "Fun", + desc: "Makes the game 0% harder", + unl() { return player.c.best.gt(0) }, + goal: new Decimal("20"), + currencyDisplayName: "lollipops", // Use if using a nonstandard currency + currencyInternalName: "points", // Use if using a nonstandard currency + currencyLayer: "c", // Leave empty if not in a layer + effect() { + let ret = player.c.points.add(1).tetrate(0.02) + return ret; + }, + effDisp(x) { return format(x)+"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. + reward: "Says hi", + onComplete() {console.log("hiii")} // Called when you complete the challenge + }, + }, doReset(layer){ if(layers[layer].row > layers["c"].row) fullLayerReset('c') // This is actually the default behavior },