import { PityTimer } from './pity-timer' ; export class Set { readonly allCards : readonly SetCard [ ] = [ ] ; readonly pityTimer : PityTimer ; readonly ownedLimitCollectibleCards : number = 0 ; readonly ownedLimitCollectiblePremiumCards : number = 0 ; constructor ( public readonly id , public readonly name , public readonly launchDate , public readonly standard ? , allCards ? , pityTimer ? , ownedLimitCollectibleCards ? , ownedLimitCollectiblePremiumCards ? ) { this . allCards = allCards ? [ ... allCards ] : [ ] ; this . pityTimer = pityTimer ; this . ownedLimitCollectibleCards = ownedLimitCollectibleCards || 0 ; this . ownedLimitCollectiblePremiumCards = ownedLimitCollectiblePremiumCards || 0 ; } public update ( base ) { return Object . assign ( new Set ( this . id , this . name , this . launchDate , this . standard , this . allCards , this . pityTimer , this . ownedLimitCollectibleCards , this . ownedLimitCollectiblePremiumCards ) , base ) ; } public getCard ( cardId ) { return this . allCards . find ( ( card ) => card . id === cardId ) ; } numberOfLimitCollectibleCards ( ) { let totalCards = 0 ; this . allCards . forEach ( ( card ) => { totalCards += card . rarity ?. toLowerCase ( ) === 'legendary' ? 1 : 2 ; } ) ; return totalCards ; } ownedForRarity ( rarity ) { return this . allCards . filter ( ( card ) => card . rarity ?. toLowerCase ( ) === rarity ) . map ( ( card ) => card . getNumberCollected ( ) ) . reduce ( ( c1 , c2 ) => c1 + c2 , 0 ) ; } totalForRarity ( rarity ) { return this . allCards . filter ( ( card ) => card . rarity ?. toLowerCase ( ) === rarity ) . map ( ( card ) => card . getMaxCollectible ( ) ) . reduce ( ( c1 , c2 ) => c1 + c2 , 0 ) ; } } export class SetCard { readonly id : string ; readonly name : string ; readonly cardClass : string ; readonly rarity : string ; readonly cost : number ; readonly ownedNonPremium : number = 0 ; readonly ownedPremium : number = 0 ; readonly ownedDiamond : number = 0 ; readonly displayed : boolean = true ; readonly collectible : boolean = true ; constructor ( id ? , name ? , cardClass ? , rarity ? , cost ? , ownedNonPremium ? , ownedPremium ? , ownedDiamond ? ) { this . id = id ; this . name = name ; this . cardClass = cardClass ? cardClass . toLowerCase ( ) : cardClass ; this . rarity = rarity ?. toLowerCase ( ) ; this . cost = cost ; this . ownedNonPremium = ownedNonPremium || 0 ; this . ownedPremium = ownedPremium || 0 ; this . ownedDiamond = ownedDiamond || 0 ; } getRegularDustCost ( ) { switch ( this . rarity ) { case 'common' : return 40 ; case 'rare' : return 100 ; case 'epic' : return 400 ; case 'legendary' : return 1600 ; default : return 0 ; } } getTotalOwned ( ) { return this . ownedPremium + this . ownedNonPremium + this . ownedDiamond ; } getNumberCollected ( ) { return ~ ~ Math . min ( this . ownedPremium + this . ownedNonPremium + this . ownedDiamond , this . getMaxCollectible ( ) ) ; } getNumberCollectedPremium ( ) { return ~ ~ Math . min ( this . ownedPremium + this . ownedDiamond , this . getMaxCollectible ( ) ) ; } getMaxCollectible ( ) { if ( ! this . rarity ) { console . warn ( 'missing rarity' , this ) ; } return this . rarity ?. toLowerCase ( ) === 'legendary' ? 1 : 2 ; } isOwned ( ) { return this . ownedPremium + this . ownedNonPremium + this . ownedDiamond > 0 ; } }