import { chars } from '@emporium/data-lists' ; import { get } from 'lodash-es' ; import { createSelector } from 'reselect' ; import * as initialState from '../initialState' ; import { equipmentStats } from './equipmentStats' ; import { talentCount } from './talentCount' ; const archetype = state => state . archetype ; const archetypes = state => state . archetypes ; const creationCharacteristics = state => state . creationCharacteristics ; const talentModifiers = state => state . talentModifiers ; const talents = state => state . talents ; export const characteristics = state => calcCharacteristics ( state ) ; const calcCharacteristics = createSelector ( archetype , archetypes , creationCharacteristics , talentModifiers , equipmentStats , talents , talentCount , ( archetype , archetypes , creationCharacteristics , talentModifiers , equipmentStats , talents , talentCount ) => { const characteristics = { ... creationCharacteristics } ; const arch = get ( archetypes , `${ archetype }` , initialState . creationCharacteristics ) ; Object . keys ( characteristics ) . forEach ( key => ( characteristics [ key ] += arch [ key ] ) ) ; const dedication = get ( talentModifiers , 'Dedication' , { } ) ; Object . keys ( dedication ) . forEach ( key => characteristics [ dedication [ key ] ] ++ ) ; Object . entries ( talentCount ) . forEach ( ( [ talent , count ] ) => { const modifier = get ( talents , `${ talent }.modifier` , { } ) ; chars . forEach ( key => { if ( key in modifier ) { characteristics [ key ] += count ; } } ) ; } ) ; Object . keys ( equipmentStats ) . forEach ( key => { const modifier = get ( equipmentStats , `${ key }.modifier` , { } ) , carried = get ( equipmentStats , `${ key }.carried` , false ) , equipped = get ( equipmentStats , `${ key }.equipped` , false ) , type = get ( equipmentStats , `${ key }.type` , '' ) ; if ( carried && modifier && ( equipped || type !== 'armor' ) ) { Object . keys ( modifier ) . forEach ( key => { if ( chars . includes ( key ) ) { characteristics [ key ] += 1 ; } } ) ; } } ) ; Object . keys ( characteristics ) . forEach ( key => { if ( characteristics [ key ] > 6 ) { characteristics [ key ] = 6 ; } } ) ; return characteristics ; } ) ;