2020-08-19 02:50:24 +00:00
var player ;
2020-08-21 19:02:34 +00:00
var tmp = { } ;
2020-08-19 02:50:24 +00:00
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-01 00:25:14 +00:00
let VERSION = {
2020-10-01 01:30:50 +00:00
num : "1.1.1" ,
2020-10-01 00:25:14 +00:00
name : "Enhanced Edition"
}
2020-09-27 03:53:03 +00:00
function startPlayerBase ( ) {
return {
2020-08-19 02:50:24 +00:00
tab : "tree" ,
time : Date . now ( ) ,
autosave : true ,
2020-09-08 23:22:22 +00:00
notify : { } ,
2020-08-27 19:12:20 +00:00
msDisplay : "always" ,
2020-09-03 21:59:23 +00:00
offlineProd : true ,
2020-09-27 03:42:41 +00:00
versionType : "Modding" ,
2020-09-14 19:26:10 +00:00
version : VERSION . num ,
beta : VERSION . beta ,
2020-08-23 19:36:03 +00:00
timePlayed : 0 ,
2020-09-10 01:39:08 +00:00
keepGoing : false ,
2020-08-24 02:01:14 +00:00
hasNaN : false ,
2020-08-19 02:50:24 +00:00
points : new Decimal ( 10 ) ,
}
2020-09-27 03:53:03 +00:00
}
function getStartPlayer ( ) {
playerdata = startPlayerBase ( )
2020-09-24 15:54:41 +00:00
for ( layer in layers ) {
playerdata [ layer ] = layers [ layer ] . startData ( )
2020-10-01 00:25:14 +00:00
playerdata [ layer ] . buyables = getStartBuyables ( layer )
playerdata [ layer ] . spentOnBuyables = new Decimal ( 0 )
2020-10-01 02:55:38 +00:00
playerdata [ layer ] . upgrades = [ ]
playerdata [ layer ] . milestones = [ ]
playerdata [ layer ] . challs = [ ]
2020-09-24 15:54:41 +00:00
}
return playerdata
2020-08-19 02:50:24 +00:00
}
2020-09-24 15:54:41 +00:00
function getPointGen ( ) {
let gain = new Decimal ( 1 )
if ( player . c . upgrades . includes ( 12 ) ) gain = gain . times ( layers . c . upgrades [ "12" ] . effect ( ) )
return gain
2020-08-19 02:50:24 +00:00
}
2020-09-27 22:01:36 +00:00
// 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 )
}
2020-09-24 15:54:41 +00:00
function save ( ) {
localStorage . setItem ( "prestige-tree" , btoa ( JSON . stringify ( player ) ) )
2020-08-19 02:50:24 +00:00
}
2020-09-24 15:54:41 +00:00
function fixSave ( ) {
2020-09-27 03:53:03 +00:00
defaultData = startPlayerBase ( )
for ( datum in defaultData ) {
if ( player [ datum ] == undefined ) {
player [ datum ] = defaultData [ datum ]
}
}
2020-09-24 15:54:41 +00:00
for ( layer in layers ) {
defaultData = layers [ layer ] . startData ( )
2020-10-01 02:55:38 +00:00
if ( player [ layer ] . upgrades == undefined )
player [ layer ] . upgrades = [ ]
if ( player [ layer ] . milestones == undefined )
player [ layer ] . milestones = [ ]
if ( player [ layer ] . challs == undefined )
player [ layer ] . challs = [ ]
2020-08-19 02:50:24 +00:00
2020-09-24 15:54:41 +00:00
for ( datum in defaultData ) {
if ( player [ layer ] [ datum ] == undefined ) {
player [ layer ] [ datum ] = defaultData [ datum ]
}
2020-09-11 02:15:05 +00:00
}
2020-10-01 00:25:14 +00:00
if ( player [ layer ] . spentOnBuyables == undefined )
player [ layer ] . spentOnBuyables = new Decimal ( 0 )
if ( layers [ layer ] . buyables ) {
if ( player [ layer ] . buyables == undefined ) player [ layer ] . buyables = { }
for ( id in layers [ layer ] . buyables ) {
if ( player [ layer ] . buyables [ id ] == undefined && ! isNaN ( id ) )
player [ layer ] . buyables [ id ] = new Decimal ( 0 )
}
}
2020-08-19 02:50:24 +00:00
}
}
function load ( ) {
let get = localStorage . getItem ( "prestige-tree" ) ;
2020-09-24 15:54:41 +00:00
if ( get === null || get === undefined ) player = getStartPlayer ( )
else player = Object . assign ( getStartPlayer ( ) , JSON . parse ( atob ( get ) ) )
fixSave ( )
2020-08-19 02:50:24 +00:00
player . tab = "tree"
2020-09-16 17:21:16 +00:00
if ( player . offlineProd ) {
2020-09-15 19:27:33 +00:00
if ( player . offTime === undefined ) player . offTime = { remain : 0 }
player . offTime . remain += ( Date . now ( ) - player . time ) / 1000
}
2020-09-24 15:54:41 +00:00
player . time = Date . now ( ) ;
2020-08-19 02:50:24 +00:00
convertToDecimal ( ) ;
2020-08-23 19:36:03 +00:00
versionCheck ( ) ;
2020-09-14 19:26:10 +00:00
changeTheme ( ) ;
2020-09-07 14:16:04 +00:00
changeTreeQuality ( ) ;
2020-08-21 19:02:34 +00:00
updateTemp ( ) ;
2020-09-01 00:39:33 +00:00
updateTemp ( ) ;
2020-08-19 02:50:24 +00:00
loadVue ( ) ;
}
function exportSave ( ) {
let str = btoa ( JSON . stringify ( player ) )
const el = document . createElement ( "textarea" ) ;
el . value = str ;
document . body . appendChild ( el ) ;
el . select ( ) ;
el . setSelectionRange ( 0 , 99999 ) ;
document . execCommand ( "copy" ) ;
document . body . removeChild ( el ) ;
}
2020-09-29 23:47:47 +00:00
function importSave ( imported = undefined , forced = false ) {
2020-08-23 19:36:03 +00:00
if ( imported === undefined ) imported = prompt ( "Paste your save here" )
2020-08-19 02:50:24 +00:00
try {
2020-09-24 15:54:41 +00:00
tempPlr = Object . assign ( getStartPlayer ( ) , JSON . parse ( atob ( imported ) ) )
2020-09-29 23:47:47 +00:00
if ( tempPlr . versionType != modInfo . id && ! forced ) // Wrong save (use "Forced" to force it to accept.)
2020-09-24 15:54:41 +00:00
return
player = tempPlr ;
2020-09-29 23:47:47 +00:00
player . versionType = modInfo . id
2020-09-24 15:54:41 +00:00
fixSave ( )
2020-08-19 02:50:24 +00:00
save ( )
window . location . reload ( )
} catch ( e ) {
return ;
}
}
2020-08-23 19:36:03 +00:00
function versionCheck ( ) {
let setVersion = true
if ( player . versionType === undefined || player . version === undefined ) {
2020-09-27 03:42:41 +00:00
player . versionType = "Modding"
2020-08-23 19:36:03 +00:00
player . version = 0
}
if ( setVersion ) {
2020-09-27 03:42:41 +00:00
if ( player . versionType == "Modding" && VERSION . num > player . version ) player . keepGoing = false
2020-08-23 19:36:03 +00:00
player . versionType = getStartPlayer ( ) . versionType
2020-09-14 19:26:10 +00:00
player . version = VERSION . num
player . beta = VERSION . beta
2020-08-23 19:36:03 +00:00
}
}
2020-08-19 02:50:24 +00:00
function convertToDecimal ( ) {
player . points = new Decimal ( player . points )
2020-09-24 15:54:41 +00:00
for ( layer in layers ) {
player [ layer ] . points = new Decimal ( player [ layer ] . points )
2020-09-24 23:32:34 +00:00
if ( player [ layer ] . best != undefined ) player [ layer ] . best = new Decimal ( player [ layer ] . best )
2020-09-24 15:54:41 +00:00
if ( player [ layer ] . total !== undefined ) player [ layer ] . total = new Decimal ( player [ layer ] . total )
2020-10-01 00:25:14 +00:00
player [ layer ] . spentOnBuyables = new Decimal ( player [ layer ] . spentOnBuyables )
if ( player [ layer ] . buyables != undefined ) {
for ( id in player [ layer ] . buyables )
player [ layer ] . buyables [ id ] = new Decimal ( player [ layer ] . buyables [ id ] )
}
player [ layer ] . best = new Decimal ( player [ layer ] . best )
2020-09-24 15:54:41 +00:00
if ( layers [ layer ] . convertToDecimal ) layers [ layer ] . convertToDecimal ( ) ;
2020-09-10 13:18:18 +00:00
}
2020-08-19 02:50:24 +00:00
}
function toggleOpt ( name ) {
player [ name ] = ! player [ name ]
2020-09-07 14:16:04 +00:00
if ( name == "hqTree" ) changeTreeQuality ( )
}
function changeTreeQuality ( ) {
var on = player . hqTree
2020-09-07 16:54:23 +00:00
document . body . style . setProperty ( '--hqProperty1' , on ? "2px solid" : "4px solid" )
document . body . style . setProperty ( '--hqProperty2a' , on ? "-4px -4px 4px rgba(0, 0, 0, 0.25) inset" : "-4px -4px 4px rgba(0, 0, 0, 0) inset" )
2020-09-14 19:26:10 +00:00
document . body . style . setProperty ( '--hqProperty2b' , on ? "0px 0px 20px var(--background)" : "" )
2020-09-07 16:54:23 +00:00
document . body . style . setProperty ( '--hqProperty3' , on ? "2px 2px 4px rgba(0, 0, 0, 0.25)" : "none" )
2020-08-19 02:50:24 +00:00
}
function exponentialFormat ( num , precision ) {
let e = num . log10 ( ) . floor ( )
let m = num . div ( Decimal . pow ( 10 , e ) )
return m . toStringWithDecimalPlaces ( 3 ) + "e" + e . toStringWithDecimalPlaces ( 0 )
}
function commaFormat ( num , precision ) {
if ( num === null || num === undefined ) return "NaN"
2020-09-14 02:41:42 +00:00
if ( num . mag < 0.001 ) return ( 0 ) . toFixed ( precision )
2020-08-19 02:50:24 +00:00
return num . toStringWithDecimalPlaces ( precision ) . replace ( /\B(?=(\d{3})+(?!\d))/g , "," )
}
2020-09-10 02:44:25 +00:00
function fixValue ( x , y = 0 ) {
2020-09-14 02:41:42 +00:00
return x || new Decimal ( y )
2020-09-10 02:44:25 +00:00
}
function sumValues ( x ) {
x = Object . values ( x )
2020-09-14 02:41:42 +00:00
if ( ! x [ 0 ] ) return new Decimal ( 0 )
2020-09-10 13:18:18 +00:00
return x . reduce ( ( a , b ) => Decimal . add ( a , b ) )
2020-09-10 02:44:25 +00:00
}
2020-10-01 00:25:14 +00:00
function format ( decimal , precision = 2 ) {
2020-08-19 02:50:24 +00:00
decimal = new Decimal ( decimal )
2020-08-24 02:01:14 +00:00
if ( isNaN ( decimal . sign ) || isNaN ( decimal . layer ) || isNaN ( decimal . mag ) ) {
player . hasNaN = true ;
return "NaN"
}
2020-09-14 02:41:42 +00:00
if ( decimal . sign < 0 ) return "-" + format ( decimal . neg ( ) , precision )
if ( decimal . mag == Number . POSITIVE _INFINITY ) return "Infinity"
if ( decimal . gte ( "eeee1000" ) ) {
2020-09-13 02:38:32 +00:00
var slog = decimal . slog ( )
if ( slog . gte ( 1e6 ) ) return "F" + format ( slog . floor ( ) )
else return Decimal . pow ( 10 , slog . sub ( slog . floor ( ) ) ) . toStringWithDecimalPlaces ( 3 ) + "F" + commaFormat ( slog . floor ( ) , 0 )
2020-09-27 03:42:41 +00:00
} else if ( decimal . gte ( "1e1000" ) ) return ( Math . floor ( decimal . mantissa + 0.01 ) + ( "e" + formatWhole ( decimal . log10 ( ) ) ) )
2020-08-21 03:33:13 +00:00
else if ( decimal . gte ( 1e9 ) ) return exponentialFormat ( decimal , precision )
2020-08-19 19:53:14 +00:00
else if ( decimal . gte ( 1e3 ) ) return commaFormat ( decimal , 0 )
2020-08-19 02:50:24 +00:00
else return commaFormat ( decimal , precision )
}
function formatWhole ( decimal ) {
return format ( decimal , 0 )
}
2020-08-24 02:01:14 +00:00
function formatTime ( s ) {
if ( s < 60 ) return format ( s ) + "s"
else if ( s < 3600 ) return formatWhole ( Math . floor ( s / 60 ) ) + "m " + format ( s % 60 ) + "s"
else return formatWhole ( Math . floor ( s / 3600 ) ) + "h " + formatWhole ( Math . floor ( s / 60 ) % 60 ) + "m " + format ( s % 60 ) + "s"
}
2020-09-08 23:22:22 +00:00
var onTreeTab = true
2020-08-19 02:50:24 +00:00
function showTab ( name ) {
2020-09-11 02:15:05 +00:00
if ( LAYERS . includes ( name ) && ! layerUnl ( name ) ) return
2020-09-08 23:22:22 +00:00
var toTreeTab = name == "tree"
2020-08-19 02:50:24 +00:00
player . tab = name
2020-09-08 23:22:22 +00:00
if ( toTreeTab != onTreeTab ) {
2020-09-10 01:46:36 +00:00
document . getElementById ( "treeTab" ) . className = toTreeTab ? "fullWidth" : "col left"
2020-09-08 23:22:22 +00:00
onTreeTab = toTreeTab
resizeCanvas ( )
}
delete player . notify [ name ]
}
function notifyLayer ( name ) {
2020-09-11 02:15:05 +00:00
if ( player . tab == name || ! layerUnl ( name ) ) return
2020-09-08 23:22:22 +00:00
player . notify [ name ] = 1
2020-08-19 02:50:24 +00:00
}
function getResetGain ( layer ) {
2020-09-16 14:25:07 +00:00
if ( tmp . gainExp [ layer ] . eq ( 0 ) ) return new Decimal ( 0 )
2020-09-24 15:54:41 +00:00
if ( layers [ layer ] . type == "static" ) {
2020-09-30 02:32:08 +00:00
if ( ( ! layers [ layer ] . canBuyMax ( ) ) || tmp . layerAmt [ layer ] . lt ( tmp . layerReqs [ layer ] ) ) return new Decimal ( 1 )
2020-09-24 15:54:41 +00:00
let gain = tmp . layerAmt [ layer ] . div ( tmp . layerReqs [ layer ] ) . div ( tmp . gainMults [ layer ] ) . max ( 1 ) . log ( layers [ layer ] . base ) . times ( tmp . gainExp [ layer ] ) . 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-09-13 02:38:32 +00:00
} else {
if ( tmp . layerAmt [ layer ] . lt ( tmp . layerReqs [ layer ] ) ) return new Decimal ( 0 )
2020-09-24 15:54:41 +00:00
let gain = tmp . layerAmt [ layer ] . div ( tmp . layerReqs [ layer ] ) . pow ( layers [ layer ] . exponent ) . times ( tmp . gainMults [ layer ] ) . pow ( tmp . gainExp [ layer ] )
2020-09-13 02:38:32 +00:00
if ( gain . gte ( "e1e7" ) ) gain = gain . sqrt ( ) . times ( "e5e6" )
return gain . floor ( ) . max ( 0 ) ;
2020-08-19 02:50:24 +00:00
}
}
function getNextAt ( layer ) {
2020-09-16 14:25:07 +00:00
if ( tmp . gainExp [ layer ] . eq ( 0 ) ) return new Decimal ( 1 / 0 )
2020-09-24 15:54:41 +00:00
if ( layers [ layer ] . type == "static" ) {
2020-08-19 02:50:24 +00:00
let amt = player [ layer ] . points
2020-09-24 15:54:41 +00:00
let extraCost = Decimal . pow ( layers [ layer ] . base , amt . pow ( layers [ layer ] . exponent ) . div ( tmp . gainExp [ layer ] ) ) . times ( tmp . gainMults [ layer ] )
2020-08-25 22:42:43 +00:00
let cost = extraCost . times ( tmp . layerReqs [ layer ] ) . max ( tmp . layerReqs [ layer ] )
2020-09-24 15:54:41 +00:00
if ( layers [ layer ] . resCeil ) cost = cost . ceil ( )
2020-08-25 22:42:43 +00:00
return cost ;
} else {
2020-09-14 19:26:10 +00:00
let next = tmp . resetGain [ layer ] . add ( 1 )
2020-09-07 16:33:50 +00:00
if ( next . gte ( "e1e7" ) ) next = next . div ( "e5e6" ) . pow ( 2 )
2020-09-24 15:54:41 +00:00
next = next . root ( tmp . gainExp [ layer ] ) . div ( tmp . gainMults [ layer ] ) . root ( layers [ layer ] . exponent ) . times ( tmp . layerReqs [ layer ] ) . max ( tmp . layerReqs [ layer ] )
if ( layers [ layer ] . resCeil ) next = next . ceil ( )
2020-08-25 22:42:43 +00:00
return next ;
}
2020-08-19 02:50:24 +00:00
}
2020-09-11 02:15:05 +00:00
function nodeShown ( layer ) {
2020-09-24 15:54:41 +00:00
if ( layers [ layer ] . layerShown ( ) ) return true
2020-09-11 02:15:05 +00:00
switch ( layer ) {
2020-09-24 15:54:41 +00:00
case "idk" :
2020-09-11 02:15:05 +00:00
return player . l . unl
break ;
}
return false
}
function layerUnl ( layer ) {
2020-09-24 15:54:41 +00:00
return LAYERS . includes ( layer ) && ( player [ layer ] . unl || ( tmp . layerAmt [ layer ] . gte ( tmp . layerReqs [ layer ] ) && layers [ layer ] . layerShown ( ) ) )
2020-09-11 02:15:05 +00:00
}
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 ] ) {
if ( layers [ lr ] . doReset )
layers [ lr ] . doReset ( layer )
else
if ( layers [ layer ] . row > layers [ lr ] . row ) fullLayerReset ( lr )
2020-08-19 02:50:24 +00:00
}
}
2020-09-24 21:46:57 +00:00
function fullLayerReset ( layer ) {
player [ layer ] = layers [ layer ] . startData ( ) ;
2020-10-01 02:55:38 +00:00
player [ layer ] . upgrades = [ ]
player [ layer ] . milestones = [ ]
player [ layer ] . challs = [ ]
2020-10-01 00:25:14 +00:00
resetBuyables ( layer )
}
function resetBuyables ( layer ) {
if ( layers [ layer ] . buyables )
player [ layer ] . buyables = getStartBuyables ( layer )
player [ layer ] . spentOnBuyables = new Decimal ( 0 )
}
function getStartBuyables ( layer ) {
let data = { }
if ( layers [ layer ] . buyables ) {
for ( id in layers [ layer ] . buyables )
if ( ! isNaN ( id ) )
data [ id ] = new Decimal ( 0 )
}
return data
2020-09-24 21:46:57 +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 ) {
addPoints ( layer , tmp . resetGain [ layer ] . times ( diff ) )
}
2020-09-11 02:15:05 +00:00
var prevOnReset
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-08-22 01:16:23 +00:00
if ( tmp . layerAmt [ layer ] . lt ( tmp . layerReqs [ layer ] ) ) return ;
2020-08-21 19:02:34 +00:00
let gain = tmp . resetGain [ layer ]
2020-09-24 15:54:41 +00:00
if ( layers [ layer ] . type == "static" ) {
2020-08-22 01:16:23 +00:00
if ( tmp . layerAmt [ layer ] . lt ( tmp . nextAt [ layer ] ) ) return ;
2020-09-30 02:32:08 +00:00
gain = ( layers [ layer ] . canBuyMax ( ) ? gain : 1 )
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-08-19 02:50:24 +00:00
if ( ! player [ layer ] . unl ) {
player [ layer ] . unl = true ;
needCanvasUpdate = true ;
2020-09-11 14:21:08 +00:00
2020-09-24 15:54:41 +00:00
if ( layers [ layer ] . incr _order ) {
for ( lr in layers [ layer ] . incr _order )
2020-09-24 23:32:34 +00:00
if ( ! player [ lr ] . unl ) player [ lr ] . order ++
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-08-22 03:59:24 +00:00
tmp . layerAmt [ layer ] = new Decimal ( 0 ) // quick fix
2020-08-19 02:50:24 +00:00
}
2020-09-09 22:14:05 +00:00
2020-09-24 23:32:34 +00:00
if ( layers [ layer ] . resetsNothing && layers [ 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 ) {
if ( row >= layers [ layerResetting ] . row && ( ! force || layerResetting != layer ) ) completeChall ( 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-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
}
2020-10-01 00:25:14 +00:00
function respecBuyables ( layer ) {
if ( ! layers [ layer ] . buyables ) return
if ( ! layers [ layer ] . buyables . respec ) return
if ( ! confirm ( "Are you sure you want to respec? This will force you to do a \"" + layer + "\" reset as well!" ) ) return
layers [ layer ] . buyables . respec ( )
}
2020-09-24 15:54:41 +00:00
function canAffordUpg ( layer , id ) {
upg = layers [ layer ] . upgrades [ id ]
2020-10-01 00:25:14 +00:00
cost = upg . cost
return canAffordPurchase ( layer , upg , cost )
}
2020-08-19 02:50:24 +00:00
2020-10-01 02:55:38 +00:00
function hasUpg ( layer , id ) {
return ( player [ layer ] . upgrades . includes ( id ) )
}
function hasMilestone ( layer , id ) {
return ( player [ layer ] . milestones . includes ( id ) )
}
function hasChall ( layer , id ) {
return ( player [ layer ] . challs . includes ( id ) )
}
2020-10-01 00:25:14 +00:00
function canAffordPurchase ( layer , thing , cost ) {
if ( thing . currencyInternalName ) {
let name = thing . currencyInternalName
if ( thing . currencyLayer ) {
let lr = thing . currencyLayer
return ! ( player [ lr ] [ name ] . lt ( cost ) )
2020-09-24 15:54:41 +00:00
}
else {
2020-10-01 00:25:14 +00:00
return ! ( player [ name ] . lt ( cost ) )
2020-09-24 15:54:41 +00:00
}
}
else {
2020-10-01 00:25:14 +00:00
return ! ( player [ layer ] . points . lt ( cost ) )
2020-09-24 15:54:41 +00:00
}
2020-09-01 00:39:33 +00:00
}
2020-09-24 15:54:41 +00:00
function buyUpg ( layer , id ) {
if ( ! player [ layer ] . unl ) return
if ( ! layers [ layer ] . upgrades [ id ] . unl ( ) ) return
if ( player [ layer ] . upgrades . includes ( id ) ) return
upg = layers [ layer ] . upgrades [ id ]
2020-08-19 02:50:24 +00:00
2020-09-24 15:54:41 +00:00
if ( upg . currencyInternalName ) {
let name = upg . currencyInternalName
if ( upg . currencyLayer ) {
let lr = upg . currencyLayer
if ( player [ lr ] [ name ] . lt ( upg . cost ) ) return
player [ lr ] [ name ] = player [ lr ] [ name ] . sub ( upg . cost )
}
else {
if ( player [ name ] . lt ( upg . cost ) ) return
player [ name ] = player [ name ] . sub ( upg . cost )
}
}
else {
if ( player [ layer ] . points . lt ( upg . cost ) ) return
player [ layer ] . points = player [ layer ] . points . sub ( upg . cost )
}
player [ layer ] . upgrades . push ( id ) ;
if ( upg . onPurchase != undefined )
upg . onPurchase ( )
2020-08-21 03:33:13 +00:00
}
2020-10-01 00:25:14 +00:00
function buyBuyable ( layer , id ) {
if ( ! player [ layer ] . unl ) return
if ( ! layers [ layer ] . buyables [ id ] . unl ( ) ) return
if ( ! layers [ layer ] . buyables [ id ] . canAfford ( ) ) return
layers [ layer ] . buyables [ id ] . buy ( )
}
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 ) {
player [ layers [ layer ] ] . unl = false
2020-08-21 03:33:13 +00:00
if ( player [ layers [ layer ] ] . order ) player [ layers [ layer ] ] . order = 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-09-24 21:46:57 +00:00
function toggleAuto ( toggle ) {
player [ toggle [ 0 ] ] [ toggle [ 1 ] ] = ! player [ toggle [ 0 ] ] [ toggle [ 1 ] ]
2020-08-20 04:55:26 +00:00
}
2020-08-26 16:26:46 +00:00
2020-09-14 02:41:42 +00:00
function startChall ( layer , x ) {
if ( ! player [ layer ] . unl ) return
if ( player [ layer ] . active == x ) {
completeChall ( layer , x )
delete player [ layer ] . active
2020-08-26 16:26:46 +00:00
} else {
2020-09-14 02:41:42 +00:00
player [ layer ] . active = x
2020-08-26 16:26:46 +00:00
}
2020-09-14 02:41:42 +00:00
doReset ( layer , true )
updateChallTemp ( layer )
2020-08-26 16:26:46 +00:00
}
2020-09-27 22:01:36 +00:00
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 ) )
}
}
2020-09-14 02:41:42 +00:00
function completeChall ( layer , x ) {
var x = player [ layer ] . active
if ( ! x ) return
2020-09-27 22:01:36 +00:00
if ( ! canCompleteChall ( layer , x ) ) return
2020-09-14 02:41:42 +00:00
if ( ! player [ layer ] . challs . includes ( x ) ) {
2020-09-27 22:01:36 +00:00
needCanvasUpdate = true
2020-09-14 02:41:42 +00:00
player [ layer ] . challs . push ( x ) ;
2020-09-27 22:01:36 +00:00
if ( layers [ layer ] . challs [ x ] . onComplete ) layers [ layer ] . challs [ x ] . onComplete ( )
2020-09-09 22:14:05 +00:00
}
2020-09-14 02:41:42 +00:00
delete player [ layer ] . active
updateChallTemp ( layer )
2020-09-09 22:14:05 +00:00
}
2020-08-27 19:12:20 +00:00
function adjustMSDisp ( ) {
let displays = [ "always" , "automation" , "incomplete" , "never" ] ;
player . msDisplay = displays [ ( displays . indexOf ( player . msDisplay ) + 1 ) % 4 ]
}
2020-09-24 21:46:57 +00:00
function milestoneShown ( layer , id ) {
complete = player [ layer ] . milestones . includes ( id )
auto = layers [ layer ] . milestones [ id ] . toggles
2020-08-27 19:12:20 +00:00
switch ( player . msDisplay ) {
case "always" :
return true ;
break ;
case "automation" :
2020-09-24 21:46:57 +00:00
return ( auto ) || ! complete
2020-08-27 19:12:20 +00:00
break ;
case "incomplete" :
return ! complete
break ;
case "never" :
return false ;
break ;
}
return false ;
}
2020-09-13 02:38:32 +00:00
2020-09-14 19:26:10 +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-09-11 02:15:05 +00:00
function keepGoing ( ) {
player . keepGoing = true ;
showTab ( "tree" )
}
2020-09-15 14:38:47 +00:00
function toNumber ( x ) {
if ( x . mag !== undefined ) return x . toNumber ( )
if ( x + 0 !== x ) return parseFloat ( x )
return x
}
2020-09-24 21:46:57 +00:00
function updateMilestones ( layer ) {
for ( id in layers [ layer ] . milestones ) {
if ( ! ( player [ layer ] . milestones . includes ( id ) ) && layers [ layer ] . milestones [ id ] . done ( ) )
player [ layer ] . milestones . push ( id )
}
}
2020-09-14 22:12:36 +00:00
function addTime ( diff , layer ) {
let data = player
let time = data . timePlayed
if ( layer ) {
data = data [ layer ]
time = data . time
}
//I am not that good to perfectly fix that leak. ~ DB Aarex
if ( time + 0 !== time ) {
console . log ( "Memory leak detected. Trying to fix..." )
2020-09-15 14:38:47 +00:00
time = toNumber ( time )
2020-09-14 22:12:36 +00:00
if ( isNaN ( time ) || time == 0 ) {
console . log ( "Couldn't fix! Resetting..." )
time = layer ? player . timePlayed : 0
if ( ! layer ) player . timePlayedReset = true
}
}
2020-09-15 14:38:47 +00:00
time += toNumber ( diff )
2020-09-14 22:12:36 +00:00
if ( layer ) data . time = time
else data . timePlayed = time
}
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-09-14 22:12:36 +00:00
addTime ( diff )
2020-09-14 21:18:02 +00:00
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-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 ( ) ;
}
var saveInterval = setInterval ( function ( ) {
2020-08-19 22:20:42 +00:00
if ( player === undefined ) return ;
2020-09-10 01:39:08 +00:00
if ( gameEnded && ! player . keepGoing ) return ;
2020-08-19 02:50:24 +00:00
if ( player . autosave ) save ( ) ;
} , 5000 )
2020-09-15 00:45:31 +00:00
var ticking = false
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-02 01:59:41 +00:00
if ( player . offTime . remain > modInfo . offlineLimit * 3600000 ) player . offlineTime . 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 )
2020-09-14 19:26:10 +00:00
const themes = {
1 : "aqua"
}
const theme _names = {
aqua : "Aqua"
}
function changeTheme ( ) {
let aqua = player . theme == "aqua"
colors _theme = colors [ player . theme || "default" ]
2020-09-14 21:18:02 +00:00
document . body . style . setProperty ( '--background' , aqua ? "#001f3f" : "#0f0f0f" )
document . body . style . setProperty ( '--background_tooltip' , aqua ? "rgba(0, 15, 31, 0.75)" : "rgba(0, 0, 0, 0.75)" )
document . body . style . setProperty ( '--color' , aqua ? "#bfdfff" : "#dfdfdf" )
document . body . style . setProperty ( '--points' , aqua ? "#dfefff" : "#ffffff" )
2020-09-14 19:26:10 +00:00
}
function getThemeName ( ) {
return player . theme ? theme _names [ player . theme ] : "Default"
}
function switchTheme ( ) {
if ( player . theme === undefined ) player . theme = themes [ 1 ]
else {
player . theme = themes [ Object . keys ( themes ) [ player . theme ] + 1 ]
if ( ! player . theme ) delete player . theme
}
changeTheme ( )
resizeCanvas ( )
}
2020-10-01 01:30:50 +00:00
function updateHotkeys ( )
{
hotkeys = { } ;
for ( layer in layers ) {
hk = layers [ layer ] . hotkeys
if ( hk ) {
for ( id in hk ) {
hotkeys [ hk [ id ] . key ] = hk [ id ]
hotkeys [ hk [ id ] . key ] . layer = layer
}
}
}
}
updateHotkeys ( )
2020-08-19 22:12:31 +00:00
document . onkeydown = function ( e ) {
2020-08-19 22:20:42 +00:00
if ( player === undefined ) return ;
2020-09-10 01:39:08 +00:00
if ( gameEnded && ! player . keepGoing ) return ;
2020-08-19 22:12:31 +00:00
let shiftDown = e . shiftKey
2020-08-29 23:43:53 +00:00
let ctrlDown = e . ctrlKey
2020-08-19 22:12:31 +00:00
let key = e . key
2020-10-01 01:30:50 +00:00
if ( ctrlDown ) key = "ctrl+" + key
2020-09-11 02:15:05 +00:00
if ( onFocused ) return
2020-09-15 00:45:31 +00:00
if ( ctrlDown && key != "-" && key != "_" && key != "+" && key != "=" && key != "r" && key != "R" && key != "F5" ) e . preventDefault ( )
2020-10-01 01:30:50 +00:00
if ( hotkeys [ key ] ) {
if ( player [ hotkeys [ key ] . layer ] . unl )
hotkeys [ key ] . onPress ( )
}
2020-09-11 02:15:05 +00:00
}
var onFocused = false
function focused ( x ) {
onFocused = x
2020-08-19 22:12:31 +00:00
}