import { extrapolateFloat } from "../../extrapolateFloat" ; import artifactSubstatData from "./artifactSubstat" ; const rollsForRarity = { 3 : 2 , 4 : 4 , 5 : 6 , } ; /** accurate value = artifactSubstatRollCorrection[rarity][key][fastValue] */ export const artifactSubstatRollCorrection = { } ; function getRolls ( key , possibleRolls , maxRolls , rarity ) { const accurateStrings = new Set ( ) ; const accuratePossibleRolls = possibleRolls . map ( Math . fround ) ; const fastPossibleRolls = possibleRolls . map ( roll => key . endsWith ( "_" ) ? roll * 100 : roll ) ; const root = { accurateValue : 0 , accurateString : "" , fastValue : 0 , fastString : "" , rolls : [ ] , badChildCount : 0 } ; const allRolls = [ root ] ; for ( let i = 0 ; i < allRolls . length ; i ++ ) { const current = allRolls [ i ] , rolls = current . rolls ; if ( rolls . length >= maxRolls ) continue ; possibleRolls . forEach ( ( _ , i ) => { const accurateValue = Math . fround ( current . accurateValue + accuratePossibleRolls [ i ] ) ; const fastValue = current . fastValue + fastPossibleRolls [ i ] ; const accurateString = key . endsWith ( "_" ) ? ( Math . round ( extrapolateFloat ( Math . fround ( Math . fround ( accurateValue * 100 ) * 10 ) ) ) / 10 ) . toFixed ( 1 ) : Math . round ( accurateValue ) . toFixed ( 0 ) ; const fastString = key . endsWith ( "_" ) ? ( Math . round ( fastValue * 10 ) / 10 ) . toFixed ( 1 ) : Math . round ( fastValue ) . toFixed ( 0 ) ; const newEntry = { accurateValue , accurateString , fastValue , fastString , rolls : [ ... rolls , i ] , badChildCount : 0 } ; current [ i ] = newEntry ; allRolls . push ( newEntry ) ; accurateStrings . add ( accurateString ) ; } ) ; } for ( const current of allRolls ) { if ( current . rolls . length >= maxRolls ) continue ; possibleRolls . forEach ( ( _ , i ) => { const child = current [ i ] ; if ( ! accurateStrings . has ( child . fastString ) ) { current . badChildCount += 1 ; } } ) ; } const outputRolls = { } ; for ( const current of allRolls ) { if ( ! current . rolls . length ) continue ; const { accurateString } = current ; const array = outputRolls [ accurateString ] ?? [ ] ; outputRolls [ accurateString ] = array ; const index = array . findIndex ( other => other . rolls . length === current . rolls . length ) ; if ( index === - 1 ) array . push ( current ) ; else if ( array [ index ] . badChildCount > current . badChildCount ) array [ index ] = current ; else if ( array [ index ] . badChildCount === current . badChildCount && current . rolls . every ( ( value , i , rolls ) => ! i || rolls [ i - 1 ] >= value ) ) array [ index ] = current ; } for ( const rolls of Object . values ( outputRolls ) ) { for ( const current of rolls ) { possibleRolls . forEach ( ( _ , i ) => { const child = current [ i ] ; if ( ! child ) return ; if ( ! accurateStrings . has ( child . fastString ) ) { if ( ! ( rarity in artifactSubstatRollCorrection ) ) artifactSubstatRollCorrection [ rarity ] = { } ; if ( ! ( key in artifactSubstatRollCorrection [ rarity ] ) ) artifactSubstatRollCorrection [ rarity ] [ key ] = { } ; artifactSubstatRollCorrection [ rarity ] [ key ] [ child . fastString ] = child . accurateString ; } } ) ; } } return Object . fromEntries ( Object . entries ( outputRolls ) . map ( ( [ key , value ] ) => [ key , value . map ( roll => roll . rolls ) ] ) ) ; } export const artifactSubstatRollData = Object . fromEntries ( Object . entries ( rollsForRarity ) . map ( ( [ rarity , maxRolls ] ) => [ rarity , Object . fromEntries ( Object . entries ( artifactSubstatData [ rarity ] ) . map ( ( [ statKey , rolls ] ) => [ statKey , getRolls ( statKey , rolls , maxRolls , rarity ) ] ) ) ] ) ) ; type RollValue = { [ index ] : RollValue ; accurateValue : number ; accurateString : string ; fastValue : number ; fastString : string ; rolls : number [ ] ; badChildCount : number ; } ;