import { GetDEBUG } from "../app" ; import { Text } from "./text" ; export class Stat { public base : number ; public bonus : number ; public level : number ; public temp : number ; public cheat : number ; public growth : number ; public growthStep : number ; public growthBase : number ; public debug : ( ) => string ; constructor ( base ? , growth ? , growthStep ? ) { this . base = base || 0 ; this . bonus = 0 ; this . level = 0 ; this . temp = 0 ; this . cheat = 0 ; this . growth = growth || 1 ; this . growthStep = growthStep || 0.1 ; this . growthBase = this . growth ; } static get growthPerPoint ( ) { return 0.1 ; } static get growthPointsPerLevel ( ) { return 3 ; } public Get ( ) { return this . base + this . bonus + this . level + this . temp + this . cheat ; } public Clear ( ) { this . bonus = 0 ; this . temp = 0 ; } public GrowthRank ( ) { return Math . round ( ( ( this . growth - this . growthBase ) / this . growthStep ) + 1 ) ; } public IdealStat ( ideal , maxChange ? , fraction ? ) { ideal = ideal || 0 ; maxChange = maxChange || 1 ; let diff = ideal - this . base ; if ( diff < 0 ) { maxChange *= - 1 ; } diff = ( Math . abs ( diff ) <= Math . abs ( maxChange ) ) ? diff : maxChange ; const old = this . base ; this . base += diff ; if ( GetDEBUG ( ) && this . debug ) { if ( diff > 0 ) { Text . Add ( `<br>DEBUG: ${ this . debug ( ) } ${ old } -> ${ this . base } (ideal: ${ ideal })<br>` , undefined , "blue bold" ) ; } else if ( diff === 0 ) { Text . Add ( `<br>DEBUG: ${ this . debug ( ) } ${ old } capped (ideal: ${ ideal })<br>` , undefined , "bold" ) ; } else { Text . Add ( `<br>DEBUG: ${ this . debug ( ) } ${ old } -> ${ this . base } (ideal: ${ ideal })<br>` , undefined , "red bold" ) ; } Text . Flush ( ) ; } if ( fraction ) { return this . base - old ; } else { return Math . floor ( this . base ) - Math . floor ( old ) ; } } public IncreaseStat ( ideal , maxChange ? , fraction ? ) { ideal = ideal || 0 ; maxChange = maxChange || 1 ; let diff = ideal - this . base ; if ( diff < 0 ) { return undefined ; } diff = ( diff <= maxChange ) ? diff : maxChange ; const old = this . base ; this . base += diff ; if ( GetDEBUG ( ) && this . debug ) { if ( diff === 0 ) { Text . Add ( `<br>DEBUG: ${ this . debug ( ) } ${ old } capped (ideal: ${ ideal })<br>` , undefined , "black bold" ) ; } else { Text . Add ( `<br>DEBUG: ${ this . debug ( ) } ${ old } -> ${ this . base } (max: ${ ideal })<br>` , undefined , "blue bold" ) ; } Text . Flush ( ) ; } if ( fraction ) { return this . base - old ; } else { return Math . floor ( this . base ) - Math . floor ( old ) ; } } public DecreaseStat ( ideal , maxChange ? , fraction ? ) { ideal = ideal || 0 ; maxChange = maxChange || 1 ; let diff = this . base - ideal ; if ( diff < 0 ) { return undefined ; } diff = ( diff <= maxChange ) ? diff : maxChange ; const old = this . base ; this . base -= diff ; if ( GetDEBUG ( ) && this . debug ) { if ( diff === 0 ) { Text . Add ( `<br>DEBUG: ${ this . debug ( ) } ${ old } capped (ideal: ${ ideal })<br>` , undefined , "black bold" ) ; } else { Text . Add ( `<br>DEBUG: ${ this . debug ( ) } ${ old } -> ${ this . base } (min: ${ ideal })<br>` , undefined , "red bold" ) ; } Text . Flush ( ) ; } if ( fraction ) { return this . base - old ; } else { return Math . floor ( this . base ) - Math . floor ( old ) ; } } }