class BrigGenerator { /**
     * Return a randomly generated brig
     */ static getRandomBrig ( randomMode , isBloodclash ) { let randomList = FamProvider . getRandomFamList ( + randomMode ) ; let brigIds = [ ] ; let maxIndex = isBloodclash ? 9 : 4 ; if ( isBloodclash ) { let randIndex = getRandomInt ( 0 , maxIndex ) ; brigIds [ randIndex ] = getRandomElement ( FamProvider . getWarlordList ( ) ) ; } for ( let i = 0 ; i <= maxIndex ; i ++ ) { if ( ! brigIds [ i ] ) { brigIds [ i ] = getRandomElement ( randomList ) ; } } return brigIds ; } /**
     * Initialize the two players' brigade
     */ static initializeBrigs ( data , option = { } ) { let battle = BattleModel . getInstance ( ) ; let isBloodClash = battle . isBloodClash ; let p1_cardIds = [ ] ; let p2_cardIds = [ ] ; let p1_warlordSkillIds = [ ] ; let p2_warlordSkillIds = [ ] ; if ( option . p1RandomMode ) { p1_cardIds = BrigGenerator . getRandomBrig ( option . p1RandomMode , isBloodClash ) ; p1_warlordSkillIds = BrigGenerator . getSmartWarlordSkills ( ) ; } else { p1_cardIds = data . p1_cardIds ; p1_warlordSkillIds = data . p1_warlordSkillIds ; } if ( option . p2RandomMode ) { p2_cardIds = BrigGenerator . getRandomBrig ( option . p2RandomMode , isBloodClash ) ; p2_warlordSkillIds = BrigGenerator . getSmartWarlordSkills ( ) ; } else { p2_cardIds = data . p2_cardIds ; p2_warlordSkillIds = data . p2_warlordSkillIds ; } for ( let i = 0 ; i < 10 ; i ++ ) { if ( i >= 5 && ! isBloodClash ) break ; let p1_cardInfo = famDatabase [ p1_cardIds [ i ] ] ; let p2_cardInfo = famDatabase [ p2_cardIds [ i ] ] ; let p1fSkillIdArray = p1_cardInfo . skills ; if ( p1_cardInfo . isWarlord ) { p1fSkillIdArray = p1_warlordSkillIds ; } if ( data . p1_customSkills [ i ] ) { p1fSkillIdArray = data . p1_customSkills [ i ] ; } let p2fSkillIdArray = p2_cardInfo . skills ; if ( p2_cardInfo . isWarlord ) { p2fSkillIdArray = p2_warlordSkillIds ; } if ( data . p2_customSkills [ i ] ) { p2fSkillIdArray = data . p2_customSkills [ i ] ; } let player1Skills = this . makeSkillArray ( p1fSkillIdArray ) ; let player2Skills = this . makeSkillArray ( p2fSkillIdArray ) ; let bonusType ; if ( battle . isColiseum ) { bonusType = ENUM . BonusType . COLISEUM ; } let card1 = new Card ( p1_cardIds [ i ] , battle . player1 , i , player1Skills , data . p1_customStats [ i ] , bonusType ) ; let card2 = new Card ( p2_cardIds [ i ] , battle . player2 , i , player2Skills , data . p2_customStats [ i ] , bonusType ) ; if ( i < 5 ) { battle . p1_mainCards [ i ] = card1 ; battle . p2_mainCards [ i ] = card2 ; battle . p1_originalMainCards [ i ] = card1 ; battle . p2_originalMainCards [ i ] = card2 ; battle . allCurrentMainCards . push ( card1 ) ; battle . allCurrentMainCards . push ( card2 ) ; } else if ( i >= 5 && isBloodClash ) { battle . p1_reserveCards [ i % 5 ] = card1 ; battle . p2_reserveCards [ i % 5 ] = card2 ; battle . p1_originalReserveCards [ i % 5 ] = card1 ; battle . p2_originalReserveCards [ i % 5 ] = card2 ; } battle . allCardsById [ card1 . id ] = card1 ; battle . allCardsById [ card2 . id ] = card2 ; } } /**
     * Given an array of skill ids, return an array of Skills
     */ static makeSkillArray ( skillIds ) { let skillArray = [ ] ; for ( let i = 0 ; i < 3 ; i ++ ) { if ( skillIds [ i ] && + skillIds [ i ] !== 0 ) { skillArray . push ( new Skill ( skillIds [ i ] ) ) ; } } return skillArray ; } /**
     * Returns 3 skill ids such that each skill belongs to a different "category"
     */ static getSmartWarlordSkills ( ) { let choosenCategory = getRandomUniqueElements ( SkillProvider . skillCategories , 3 ) ; let skills = [ ] ; for ( let i = 0 ; i < choosenCategory . length ; i ++ ) { switch ( choosenCategory [ i ] ) { case ENUM . SkillCategory . OPENING : skills . push ( getRandomElement ( SkillProvider . getAvailableOpeningSkillList ( ) ) ) ; break ; case ENUM . SkillCategory . ACTIVE : skills . push ( getRandomElement ( SkillProvider . getAvailableActiveSkillList ( ) ) ) ; break ; case ENUM . SkillCategory . REACTIVE : skills . push ( getRandomElement ( SkillProvider . getAvailableReactiveSkillList ( ) ) ) ; break ; case ENUM . SkillCategory . ACTION_ON_DEATH : skills . push ( getRandomElement ( SkillProvider . getAvailableOnDeathSkillList ( ) ) ) ; break ; default : throw new Error ( "Invalid skill category" ) ; } } return skills ; } }