import { ENCOUNTERS } from 'app/Encounters' ; import { isSurgeRound } from './Actions' ; const seedrandom = require ( 'seedrandom' ) ; function supportedEnemies ( scope ) { const contentSets = scope . _ . contentSets ( ) || [ ] ; return Object . keys ( ENCOUNTERS ) . filter ( ( key ) => ENCOUNTERS [ key ] . set === 'base' || contentSets [ ENCOUNTERS [ key ] . set ] ) ; } function pickRandom < T > ( list , rng = Math . random ) { return list [ Math . floor ( rng ( ) * list . length ) ] ; } export function combatScope ( ) { return { randomEnemy ( ) { const options = supportedEnemies ( this . scope ) ; return ENCOUNTERS [ pickRandom ( options , this . scope . _ . crng ) ] . name ; } , randomEnemyOfTier ( tier ) { const options = supportedEnemies ( this . scope ) . filter ( ( key ) => ENCOUNTERS [ key ] . tier === tier ) ; return ( ENCOUNTERS [ pickRandom ( options , this . scope . _ . crng ) ] || { } ) . name ; } , randomEnemyOfClass ( className ) { className = className . toLowerCase ( ) ; const options = supportedEnemies ( this . scope ) . filter ( ( key ) => ENCOUNTERS [ key ] . class . toLowerCase ( ) === className ) ; return ( ENCOUNTERS [ pickRandom ( options , this . scope . _ . crng ) ] || { } ) . name ; } , randomEnemyOfClassTier ( className , tier ) { className = className . toLowerCase ( ) ; const options = supportedEnemies ( this . scope ) . filter ( ( key ) => ENCOUNTERS [ key ] . tier === tier ) . filter ( ( key ) => ENCOUNTERS [ key ] . class . toLowerCase ( ) === className ) ; return ( ENCOUNTERS [ pickRandom ( options , this . scope . _ . crng ) ] || { } ) . name ; } , aliveAdventurers ( ) { return ( this . templates && this . templates . combat && this . templates . combat . numAliveAdventurers ) || 0 ; } , currentCombatRound ( ) { return ( this . templates && this . templates . combat && this . templates . combat . roundCount ) || 0 ; } , currentCombatTier ( ) { return ( this . templates && this . templates . combat && this . templates . combat . tier ) || 0 ; } , isCombatSurgeRound ( ) { if ( ! this . templates || ! this . templates . combat ) { return false ; } return isSurgeRound ( this . templates . combat . roundCount , this . templates . combat . surgePeriod ) ; } , crng ( ) { this . scope . _ . crng = seedrandom . alea ( this . seed ) ; return this . scope . _ . crng ( ) ; } , } ; }