2020-08-19 02:50:24 +00:00
var player ;
var needCanvasUpdate = true ;
2020-08-24 02:01:14 +00:00
var NaNalert = false ;
2020-09-10 01:28:47 +00:00
var gameEnded = false ;
2020-08-19 02:50:24 +00:00
2020-10-11 02:30:17 +00:00
let modInfo = {
name : "The Modding Tree" ,
id : "modbase" ,
pointsName : "points" ,
discordName : "" ,
discordLink : "" ,
2020-10-11 22:11:42 +00:00
changelogLink : "https://github.com/Acamaeda/The-Modding-Tree/blob/master/changelog.md" ,
2020-10-11 02:30:17 +00:00
offlineLimit : 1 // In hours
}
2020-10-13 22:56:17 +00:00
// Set your version in num and name, but leave the tmt values so people know what version it is
2020-10-01 00:25:14 +00:00
let VERSION = {
2020-10-16 16:20:33 +00:00
num : "2.0.4" ,
2020-10-15 01:43:16 +00:00
name : "Pinnacle of Achievement Mountain" ,
2020-10-16 16:20:33 +00:00
tmtNum : "2.0.4" ,
2020-10-15 01:43:16 +00:00
tmtName : "Pinnacle of Achievement Mountain"
2020-08-19 02:50:24 +00:00
}
2020-10-07 05:18:56 +00:00
// Determines if it should show points/sec
2020-10-11 22:38:54 +00:00
function canGenPoints ( ) {
2020-10-13 03:08:19 +00:00
return hasUpgrade ( "c" , 11 )
2020-10-11 22:38:54 +00:00
}
2020-10-07 05:18:56 +00:00
2020-10-05 21:11:15 +00:00
// Calculate points/sec!
2020-09-24 15:54:41 +00:00
function getPointGen ( ) {
2020-10-11 22:38:54 +00:00
if ( ! canGenPoints ( ) )
2020-10-07 04:57:41 +00:00
return new Decimal ( 0 )
2020-09-24 15:54:41 +00:00
let gain = new Decimal ( 1 )
2020-10-13 03:08:19 +00:00
if ( hasUpgrade ( "c" , 12 ) ) gain = gain . times ( upgradeEffect ( "c" , 12 ) )
2020-09-24 15:54:41 +00:00
return gain
2020-08-19 02:50:24 +00:00
}
2020-10-16 15:39:39 +00:00
// You can change this if you have things that can be messed up by long tick lengths
function maxTickLength ( ) {
return ( 3600000 ) // Default is 1 hour which is just arbitrarily large
}
2020-10-05 21:11:15 +00:00
2020-10-07 03:11:36 +00:00
function getResetGain ( layer , useType = null ) {
let type = useType
if ( ! useType ) type = layers [ layer ] . type
2020-10-15 03:09:30 +00:00
if ( tmp [ layer ] . type == "none" )
return new Decimal ( 0 )
2020-10-10 03:16:29 +00:00
if ( tmp [ layer ] . gainExp . eq ( 0 ) ) return new Decimal ( 0 )
2020-10-07 03:11:36 +00:00
if ( type == "static" ) {
2020-10-10 03:16:29 +00:00
if ( ( ! layers [ layer ] . canBuyMax ( ) ) || tmp [ layer ] . baseAmount . lt ( tmp [ layer ] . requires ) ) return new Decimal ( 1 )
let gain = tmp [ layer ] . baseAmount . div ( tmp [ layer ] . requires ) . div ( tmp [ layer ] . gainMult ) . max ( 1 ) . log ( layers [ layer ] . base ) . times ( tmp [ layer ] . gainExp ) . pow ( Decimal . pow ( layers [ layer ] . exponent , - 1 ) )
2020-09-14 19:26:10 +00:00
return gain . floor ( ) . sub ( player [ layer ] . points ) . add ( 1 ) . max ( 1 ) ;
2020-10-07 03:11:36 +00:00
} else if ( type == "normal" ) {
2020-10-10 03:16:29 +00:00
if ( tmp [ layer ] . baseAmount . lt ( tmp [ layer ] . requires ) ) return new Decimal ( 0 )
let gain = tmp [ layer ] . baseAmount . div ( tmp [ layer ] . requires ) . pow ( layers [ layer ] . exponent ) . times ( tmp [ layer ] . gainMult ) . pow ( tmp [ layer ] . gainExp )
2020-09-13 02:38:32 +00:00
if ( gain . gte ( "e1e7" ) ) gain = gain . sqrt ( ) . times ( "e5e6" )
return gain . floor ( ) . max ( 0 ) ;
2020-10-07 03:11:36 +00:00
} else if ( type == "custom" ) {
return layers [ layer ] . getResetGain ( )
} else {
return new Decimal ( 0 )
2020-08-19 02:50:24 +00:00
}
}
2020-10-07 03:11:36 +00:00
function getNextAt ( layer , canMax = false , useType = null ) {
let type = useType
if ( ! useType ) type = layers [ layer ] . type
2020-10-15 03:09:30 +00:00
if ( tmp [ layer ] . type == "none" )
return new Decimal ( Infinity )
2020-10-07 03:11:36 +00:00
2020-10-12 22:28:12 +00:00
if ( tmp [ layer ] . gainMult . lte ( 0 ) ) return new Decimal ( Infinity )
if ( tmp [ layer ] . gainExp . lte ( 0 ) ) return new Decimal ( Infinity )
2020-10-07 03:11:36 +00:00
if ( type == "static" )
2020-10-07 00:09:54 +00:00
{
2020-10-07 03:11:36 +00:00
if ( ! layers [ layer ] . canBuyMax ( ) ) canMax = false
2020-10-10 03:16:29 +00:00
let amt = player [ layer ] . points . plus ( ( canMax && tmp [ layer ] . baseAmount . gte ( tmp [ layer ] . nextAt ) ) ? tmp [ layer ] . resetGain : 0 )
2020-10-12 22:28:12 +00:00
let extraCost = Decimal . pow ( layers [ layer ] . base , amt . pow ( tmp [ layer ] . exponent ) . div ( tmp [ layer ] . gainExp ) ) . times ( tmp [ layer ] . gainMult )
2020-10-10 03:16:29 +00:00
let cost = extraCost . times ( tmp [ layer ] . requires ) . max ( tmp [ layer ] . requires )
2020-10-13 03:08:19 +00:00
if ( layers [ layer ] . roundUpCost ) cost = cost . ceil ( )
2020-08-25 22:42:43 +00:00
return cost ;
2020-10-07 03:11:36 +00:00
} else if ( type == "normal" ) {
2020-10-10 03:16:29 +00:00
let next = tmp [ layer ] . resetGain . add ( 1 )
2020-09-07 16:33:50 +00:00
if ( next . gte ( "e1e7" ) ) next = next . div ( "e5e6" ) . pow ( 2 )
2020-10-12 23:18:20 +00:00
next = next . root ( tmp [ layer ] . gainExp ) . div ( tmp [ layer ] . gainMult ) . root ( tmp [ layer ] . exponent ) . times ( tmp [ layer ] . requires ) . max ( tmp [ layer ] . requires )
2020-10-13 03:08:19 +00:00
if ( layers [ layer ] . roundUpCost ) next = next . ceil ( )
2020-08-25 22:42:43 +00:00
return next ;
2020-10-07 03:11:36 +00:00
} else if ( type == "custom" ) {
return layers [ layer ] . getNextAt ( canMax )
} else {
return new Decimal ( 0 )
} }
2020-08-19 02:50:24 +00:00
2020-10-04 15:23:38 +00:00
// Return true if the layer should be highlighted. By default checks for upgrades only.
function shouldNotify ( layer ) {
for ( id in layers [ layer ] . upgrades ) {
if ( ! isNaN ( id ) ) {
2020-10-13 03:08:19 +00:00
if ( canAffordUpgrade ( layer , id ) && ! hasUpgrade ( layer , id ) && tmp [ layer ] . upgrades [ id ] . unlocked ) {
2020-10-04 15:23:38 +00:00
return true
}
}
}
if ( layers [ layer ] . shouldNotify ) {
return layers [ layer ] . shouldNotify ( )
}
else
return false
}
2020-10-10 03:16:29 +00:00
function canReset ( layer )
{
if ( tmp [ layer ] . type == "normal" )
return tmp [ layer ] . baseAmount . gte ( tmp [ layer ] . requires )
else if ( tmp [ layer ] . type == "static" )
return tmp [ layer ] . baseAmount . gte ( tmp [ layer ] . nextAt )
2020-10-15 03:09:30 +00:00
if ( tmp [ layer ] . type == "none" )
return false
2020-10-10 03:16:29 +00:00
else
return layers [ layer ] . canReset ( )
}
2020-08-19 02:50:24 +00:00
function rowReset ( row , layer ) {
2020-09-24 21:46:57 +00:00
for ( lr in ROW _LAYERS [ row ] ) {
2020-10-07 00:09:54 +00:00
if ( layers [ lr ] . doReset ) {
2020-10-14 23:46:35 +00:00
player [ lr ] . activeChallenge = null // Exit challenges on any row reset on an equal or higher row
2020-09-24 21:46:57 +00:00
layers [ lr ] . doReset ( layer )
2020-10-07 00:09:54 +00:00
}
2020-09-24 21:46:57 +00:00
else
2020-10-14 23:46:35 +00:00
if ( layers [ layer ] . row > layers [ lr ] . row && row !== "side" ) layerDataReset ( lr )
2020-08-19 02:50:24 +00:00
}
}
2020-10-13 22:56:17 +00:00
function layerDataReset ( layer , keep = [ ] ) {
let storedData = { }
for ( thing in keep ) {
if ( player [ layer ] [ keep [ thing ] ] !== undefined )
storedData [ keep [ thing ] ] = player [ layer ] [ keep [ thing ] ]
}
console . log ( storedData )
2020-09-24 21:46:57 +00:00
player [ layer ] = layers [ layer ] . startData ( ) ;
2020-10-01 02:55:38 +00:00
player [ layer ] . upgrades = [ ]
player [ layer ] . milestones = [ ]
2020-10-13 03:08:19 +00:00
player [ layer ] . challenges = [ ]
2020-10-13 22:56:17 +00:00
resetBuyables ( layer )
2020-10-07 03:11:36 +00:00
2020-10-13 22:56:17 +00:00
for ( thing in storedData ) {
player [ layer ] [ thing ] = storedData [ thing ]
2020-10-07 03:11:36 +00:00
}
2020-10-01 00:25:14 +00:00
}
function resetBuyables ( layer ) {
if ( layers [ layer ] . buyables )
player [ layer ] . buyables = getStartBuyables ( layer )
player [ layer ] . spentOnBuyables = new Decimal ( 0 )
}
2020-10-11 20:16:36 +00:00
2020-09-09 22:14:05 +00:00
function addPoints ( layer , gain ) {
2020-09-14 19:26:10 +00:00
player [ layer ] . points = player [ layer ] . points . add ( gain ) . max ( 0 )
2020-09-27 20:21:14 +00:00
if ( player [ layer ] . best ) player [ layer ] . best = player [ layer ] . best . max ( player [ layer ] . points )
2020-09-14 19:26:10 +00:00
if ( player [ layer ] . total ) player [ layer ] . total = player [ layer ] . total . add ( gain )
2020-09-09 22:14:05 +00:00
}
function generatePoints ( layer , diff ) {
2020-10-10 03:16:29 +00:00
addPoints ( layer , tmp [ layer ] . resetGain . times ( diff ) )
2020-09-09 22:14:05 +00:00
}
2020-09-11 02:15:05 +00:00
var prevOnReset
2020-10-03 21:52:51 +00:00
2020-08-19 02:50:24 +00:00
function doReset ( layer , force = false ) {
2020-09-24 15:54:41 +00:00
let row = layers [ layer ] . row
2020-08-19 02:50:24 +00:00
if ( ! force ) {
2020-10-10 03:16:29 +00:00
if ( tmp [ layer ] . baseAmount . lt ( tmp [ layer ] . requires ) ) return ;
let gain = tmp [ layer ] . resetGain
2020-09-24 15:54:41 +00:00
if ( layers [ layer ] . type == "static" ) {
2020-10-10 03:16:29 +00:00
if ( tmp [ layer ] . baseAmount . lt ( tmp [ layer ] . nextAt ) ) return ;
2020-09-30 02:32:08 +00:00
gain = ( layers [ layer ] . canBuyMax ( ) ? gain : 1 )
2020-09-24 22:42:52 +00:00
}
2020-10-07 03:11:36 +00:00
if ( layers [ layer ] . type == "custom" ) {
2020-10-10 03:16:29 +00:00
if ( ! tmp [ layer ] . canReset ) return ;
2020-10-07 03:11:36 +00:00
}
2020-09-24 22:42:52 +00:00
if ( layers [ layer ] . onPrestige )
layers [ layer ] . onPrestige ( gain )
addPoints ( layer , gain )
2020-09-27 04:04:08 +00:00
updateMilestones ( layer )
2020-10-15 01:43:16 +00:00
updateAchievements ( layer )
2020-09-27 04:04:08 +00:00
2020-10-13 03:08:19 +00:00
if ( ! player [ layer ] . unlocked ) {
player [ layer ] . unlocked = true ;
2020-08-19 02:50:24 +00:00
needCanvasUpdate = true ;
2020-09-11 14:21:08 +00:00
2020-10-15 03:31:05 +00:00
if ( layers [ layer ] . increaseUnlockOrder ) {
lrs = layers [ layer ] . increaseUnlockOrder
2020-10-06 01:38:50 +00:00
for ( lr in lrs )
2020-10-15 03:31:05 +00:00
if ( ! player [ lrs [ lr ] ] . unlocked ) player [ lrs [ lr ] ] . unlockOrder ++
2020-09-24 15:54:41 +00:00
}
2020-08-19 02:50:24 +00:00
}
2020-09-11 14:21:08 +00:00
2020-10-10 03:16:29 +00:00
tmp [ layer ] . baseAmount = new Decimal ( 0 ) // quick fix
2020-08-19 02:50:24 +00:00
}
2020-09-09 22:14:05 +00:00
2020-10-10 03:16:29 +00:00
if ( tmp [ layer ] . resetsNothing ) return
2020-09-24 15:54:41 +00:00
2020-09-14 02:41:42 +00:00
2020-09-24 15:54:41 +00:00
for ( layerResetting in layers ) {
2020-10-13 03:08:19 +00:00
if ( row >= layers [ layerResetting ] . row && ( ! force || layerResetting != layer ) ) completeChallenge ( layerResetting )
2020-09-14 02:41:42 +00:00
}
2020-09-11 02:15:05 +00:00
prevOnReset = { ... player } //Deep Copy
2020-09-24 21:46:57 +00:00
player . points = ( row == 0 ? new Decimal ( 0 ) : new Decimal ( 10 ) )
for ( let x = row ; x >= 0 ; x -- ) rowReset ( x , layer )
2020-10-14 23:46:35 +00:00
rowReset ( "side" , layer )
2020-09-11 02:15:05 +00:00
prevOnReset = undefined
2020-08-26 19:08:00 +00:00
updateTemp ( )
2020-09-09 02:10:25 +00:00
updateTemp ( )
2020-08-19 02:50:24 +00:00
}
function resetRow ( row ) {
if ( prompt ( 'Are you sure you want to reset this row? It is highly recommended that you wait until the end of your current run before doing this! Type "I WANT TO RESET THIS" to confirm' ) != "I WANT TO RESET THIS" ) return
let pre _layers = ROW _LAYERS [ row - 1 ]
let layers = ROW _LAYERS [ row ]
let post _layers = ROW _LAYERS [ row + 1 ]
rowReset ( row + 1 , post _layers [ 0 ] )
doReset ( pre _layers [ 0 ] , true )
for ( let layer in layers ) {
2020-10-13 03:08:19 +00:00
player [ layers [ layer ] ] . unlocked = false
2020-10-15 03:31:05 +00:00
if ( player [ layers [ layer ] ] . unlockOrder ) player [ layers [ layer ] ] . unlockOrder = 0
2020-08-19 02:50:24 +00:00
}
2020-09-24 21:46:57 +00:00
player . points = new Decimal ( 10 )
2020-08-21 19:02:34 +00:00
updateTemp ( ) ;
2020-08-19 02:50:24 +00:00
resizeCanvas ( ) ;
}
2020-10-13 03:08:19 +00:00
function startChallenge ( layer , x ) {
2020-10-07 20:41:45 +00:00
let enter = false
2020-10-13 03:08:19 +00:00
if ( ! player [ layer ] . unlocked ) return
2020-10-14 23:46:35 +00:00
if ( player [ layer ] . activeChallenge == x ) {
2020-10-13 03:08:19 +00:00
completeChallenge ( layer , x )
2020-10-14 23:46:35 +00:00
delete player [ layer ] . activeChallenge
2020-08-26 16:26:46 +00:00
} else {
2020-10-07 20:41:45 +00:00
enter = true
}
2020-09-14 02:41:42 +00:00
doReset ( layer , true )
2020-10-14 23:46:35 +00:00
if ( enter ) player [ layer ] . activeChallenge = x
2020-10-07 20:41:45 +00:00
2020-10-13 03:08:19 +00:00
updateChallengeTemp ( layer )
2020-08-26 16:26:46 +00:00
}
2020-10-13 03:08:19 +00:00
function canCompleteChallenge ( layer , x )
2020-09-27 22:01:36 +00:00
{
2020-10-14 23:46:35 +00:00
if ( x != player [ layer ] . activeChallenge ) return
2020-09-27 22:01:36 +00:00
2020-10-16 15:39:39 +00:00
let challenge = tmp [ layer ] . challenges [ x ]
2020-09-27 22:01:36 +00:00
2020-10-13 03:08:19 +00:00
if ( challenge . currencyInternalName ) {
let name = challenge . currencyInternalName
2020-10-16 15:39:39 +00:00
if ( challenge . currencyLocation ) {
return ! ( challenge . currencyLocation [ name ] . lt ( challenge . goal ) )
}
else if ( challenge . currencyLayer ) {
2020-10-13 03:08:19 +00:00
let lr = challenge . currencyLayer
return ! ( player [ lr ] [ name ] . lt ( readData ( challenge . goal ) ) )
2020-09-27 22:01:36 +00:00
}
else {
2020-10-13 03:08:19 +00:00
return ! ( player [ name ] . lt ( challenge . cost ) )
2020-09-27 22:01:36 +00:00
}
}
else {
2020-10-13 03:08:19 +00:00
return ! ( player [ layer ] . points . lt ( challenge . cost ) )
2020-09-27 22:01:36 +00:00
}
}
2020-10-13 03:08:19 +00:00
function completeChallenge ( layer , x ) {
2020-10-14 23:46:35 +00:00
var x = player [ layer ] . activeChallenge
2020-09-14 02:41:42 +00:00
if ( ! x ) return
2020-10-13 03:08:19 +00:00
if ( ! canCompleteChallenge ( layer , x ) ) {
2020-10-14 23:46:35 +00:00
delete player [ layer ] . activeChallenge
2020-10-11 20:42:32 +00:00
return
}
2020-10-13 03:08:19 +00:00
if ( player [ layer ] . challenges [ x ] < tmp [ layer ] . challenges [ x ] . completionLimit ) {
2020-09-27 22:01:36 +00:00
needCanvasUpdate = true
2020-10-13 03:08:19 +00:00
player [ layer ] . challenges [ x ] += 1
if ( layers [ layer ] . challenges [ x ] . onComplete ) layers [ layer ] . challenges [ x ] . onComplete ( )
2020-09-09 22:14:05 +00:00
}
2020-10-14 23:46:35 +00:00
delete player [ layer ] . activeChallenge
2020-10-13 03:08:19 +00:00
updateChallengeTemp ( layer )
2020-09-09 22:14:05 +00:00
}
2020-09-15 19:27:33 +00:00
VERSION . withoutName = "v" + VERSION . num + ( VERSION . pre ? " Pre-Release " + VERSION . pre : VERSION . pre ? " Beta " + VERSION . beta : "" )
2020-09-14 19:26:10 +00:00
VERSION . withName = VERSION . withoutName + ( VERSION . name ? ": " + VERSION . name : "" )
2020-09-14 02:41:42 +00:00
2020-09-16 02:50:53 +00:00
const ENDGAME = new Decimal ( "e280000000" ) ;
2020-09-10 01:28:47 +00:00
2020-08-19 02:50:24 +00:00
function gameLoop ( diff ) {
2020-09-14 19:26:10 +00:00
if ( player . points . gte ( ENDGAME ) || gameEnded ) gameEnded = 1
2020-09-09 22:14:05 +00:00
if ( isNaN ( diff ) ) diff = 0
2020-09-10 01:46:36 +00:00
if ( gameEnded && ! player . keepGoing ) {
diff = 0
player . tab = "gameEnded"
2020-09-10 01:28:47 +00:00
}
2020-09-14 19:26:10 +00:00
if ( player . devSpeed ) diff *= player . devSpeed
2020-09-14 21:18:02 +00:00
2020-10-16 15:39:39 +00:00
let limit = maxTickLength ( )
if ( diff > limit )
diff = limit
2020-09-14 22:12:36 +00:00
addTime ( diff )
2020-10-11 22:38:54 +00:00
player . points = player . points . add ( tmp . pointGen . times ( diff ) ) . max ( 0 )
2020-09-24 15:54:41 +00:00
for ( layer in layers ) {
if ( layers [ layer ] . update ) layers [ layer ] . update ( diff ) ;
2020-08-29 19:45:18 +00:00
}
2020-09-14 02:41:42 +00:00
2020-09-24 15:54:41 +00:00
for ( layer in layers ) {
if ( layers [ layer ] . automate ) layers [ layer ] . automate ( ) ;
2020-09-24 21:46:57 +00:00
}
2020-08-26 03:32:27 +00:00
2020-09-24 21:46:57 +00:00
for ( layer in layers ) {
if ( layers [ layer ] . milestones ) updateMilestones ( layer ) ;
2020-10-15 01:43:16 +00:00
if ( layers [ layer ] . achievements ) updateAchievements ( layer )
2020-09-09 02:10:25 +00:00
}
2020-08-26 03:32:27 +00:00
2020-08-24 02:01:14 +00:00
if ( player . hasNaN && ! NaNalert ) {
2020-08-25 22:42:43 +00:00
clearInterval ( interval ) ;
2020-08-26 01:45:22 +00:00
player . autosave = false ;
2020-08-24 02:01:14 +00:00
NaNalert = true ;
2020-09-14 21:18:02 +00:00
alert ( "We have detected a corruption in your save. Please visit https://discord.gg/wwQfgPa for help." )
2020-08-24 02:01:14 +00:00
}
2020-08-19 02:50:24 +00:00
}
function hardReset ( ) {
if ( ! confirm ( "Are you sure you want to do this? You will lose all your progress!" ) ) return
player = getStartPlayer ( )
save ( ) ;
window . location . reload ( ) ;
}
2020-09-15 00:45:31 +00:00
var ticking = false
2020-10-03 21:52:51 +00:00
2020-08-19 02:50:24 +00:00
var interval = setInterval ( function ( ) {
2020-08-31 18:33:29 +00:00
if ( player === undefined || tmp === undefined ) return ;
2020-09-15 00:45:31 +00:00
if ( ticking ) return ;
2020-09-10 01:39:08 +00:00
if ( gameEnded && ! player . keepGoing ) return ;
2020-09-15 00:45:31 +00:00
ticking = true
let now = Date . now ( )
2020-09-15 19:27:33 +00:00
let diff = ( now - player . time ) / 1e3
if ( player . offTime !== undefined ) {
2020-10-15 23:56:08 +00:00
if ( player . offTime . remain > modInfo . offlineLimit * 3600000 ) player . offTime . remain = modInfo . offlineLimit * 3600000
2020-09-15 19:27:33 +00:00
if ( player . offTime . remain > 0 ) {
let offlineDiff = Math . max ( player . offTime . remain / 10 , diff )
player . offTime . remain -= offlineDiff
diff += offlineDiff
}
if ( ! player . offlineProd || player . offTime . remain <= 0 ) delete player . offTime
2020-09-01 00:39:33 +00:00
}
2020-09-15 19:27:33 +00:00
if ( player . devSpeed ) diff *= player . devSpeed
2020-09-15 00:45:31 +00:00
player . time = now
2020-08-22 03:59:24 +00:00
if ( needCanvasUpdate ) resizeCanvas ( ) ;
2020-08-21 19:02:34 +00:00
updateTemp ( ) ;
2020-09-09 22:14:05 +00:00
gameLoop ( diff )
2020-09-15 00:45:31 +00:00
ticking = false
2020-08-19 22:12:31 +00:00
} , 50 )