import { toPrevious } from 'app/actions/Card' ; import { CombatPhase } from 'app/Constants' ; import { AppStateWithHistory , CardName , SettingsType } from 'app/reducers/StateTypes' ; import { connect } from 'react-redux' ; import Redux from 'redux' ; import { midCombatChoice , } from '../roleplay/Actions' ; import { ParserNode } from '../TemplateTypes' ; import MidCombatRoleplay , { DispatchProps , StateProps } from './MidCombatRoleplay' ; import { mapStateToProps as mapStateToPropsBase } from './Types' ; const mapStateToProps = ( state , ownProps ) : StateProps => { let maxTier = 0 ; let histIdx = state . _history . length - 1 ; while ( Boolean ( state . _history [ histIdx ] ) && state . _history [ histIdx ] . quest && state . _history [ histIdx ] . quest . node && state . _history [ histIdx ] . quest . node . ctx . templates . combat && histIdx > 0 ) { const combatContext = state . _history [ histIdx ] . quest . node . ctx . templates . combat ; if ( ! combatContext ) { break ; } const tier = combatContext . tier ; histIdx -- ; const phase = state . _history [ histIdx ] . quest . node . ctx . templates . combat . phase ; if ( tier && phase !== null && phase === CombatPhase . prepare ) { maxTier = Math . max ( maxTier , tier ) ; } } return { ... mapStateToPropsBase ( state , ownProps ) , questID : state . quest . details . id , maxTier , } ; } ; const mapDispatchToProps = ( dispatch ) : DispatchProps => { return { onChoice : ( node , settings , index , maxTier , seed ) => { dispatch ( midCombatChoice ( { node , settings , index , maxTier , seed } ) ) ; } , onRetry : ( ) => { dispatch ( toPrevious ( { matchFn : ( c , n ) => n . getTag ( ) === 'combat' && n . ctx . templates . combat . phase === CombatPhase . drawEnemies , before : true } ) ) ; } , onReturn : ( ) => { dispatch ( toPrevious ( { before : false , matchFn : ( c , n ) => n . ctx . templates . combat . phase !== CombatPhase . timer } ) ) ; } , } ; } ; export default connect ( mapStateToProps , mapDispatchToProps ) ( MidCombatRoleplay ) ;