src/scripts/Status.js
//this is called to update value of the stat and will trigger calculation of dependend stats 
this is called to update value of the stat and will trigger calculation of dependend stats
this is called to update value of the stat and will trigger calculation of dependend stats
Calc( ) {
        let attr = this.data;
        let min = -999999;
        let max = 999999;
        let msg = '';
        for(let k=0;k<attr.limits.length;k++) {
            let lmin = attr.limits[k].min, lmax = attr.limits[k].max;  
            if (lmin || lmin===0) {
                min= (typeof lmin ==='string')? Math.max(this.parent.get(lmin).value,min): Math.max(lmin,min);
            }
            if (lmax || lmax===0) {
                max=(typeof lmax ==='string') ? Math.min(this.parent.get(lmax).value,max): Math.min(lmax,max);
            }
        }
        let _old =  attr.value;
        attr.base = attr.value = Math.max(min,Math.min(max,attr.base));  
        for(let i=0;i<attr.modifier.length;i++) {
            attr.value += attr.modifier[i].bonus;
        }
        let _new = Math.max(min,Math.min(max,attr.value));
        attr.value = _new;
        msg+=this.formatMsgStatChange(attr,_new,_old);
        this.updateModifier();
        for(let m=0;m<attr.modifys.length;m++) {
            msg+=this.parent.get(attr.modifys[m].id).Calc().msg;
        }
        return({OK:true,msg:msg});
    }
Calc ( ) { let attr = this . data ; let min = - 999999 ; let max = 999999 ; let msg = '' ; for ( let k = 0 ; k < attr . limits . length ; k ++ ) { let lmin = attr . limits [ k ] . min , lmax = attr . limits [ k ] . max ; if ( lmin || lmin === 0 ) { min = ( typeof lmin === 'string' ) ? Math . max ( this . parent . get ( lmin ) . value , min ) : Math . max ( lmin , min ) ; } if ( lmax || lmax === 0 ) { max = ( typeof lmax === 'string' ) ? Math . min ( this . parent . get ( lmax ) . value , max ) : Math . min ( lmax , max ) ; } } let _old = attr . value ; attr . base = attr . value = Math . max ( min , Math . min ( max , attr . base ) ) ; for ( let i = 0 ; i < attr . modifier . length ; i ++ ) { attr . value += attr . modifier [ i ] . bonus ; } let _new = Math . max ( min , Math . min ( max , attr . value ) ) ; attr . value = _new ; msg += this . formatMsgStatChange ( attr , _new , _old ) ; this . updateModifier ( ) ; for ( let m = 0 ; m < attr . modifys . length ; m ++ ) { msg += this . parent . get ( attr . modifys [ m ] . id ) . Calc ( ) . msg ; } return ( { OK : true , msg : msg } ) ; }
this is called to update value of the stat and will trigger calculation of dependend stats
this is called to update value of the stat and will trigger calculation of dependend stats
//get limits //this might behave odly if any min>max //lm__ is id or number //recalculate modifiers //todo no log hidden //trigger recalculation of dependend Stats