Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.text.TextField;
- // Based off calculations performed by Hamlet
- public class Simulation
- {
- // GLOBAL VARIABLES //
- // THESE VARIABLES CHANGE THE WHOLE SIMULATION //
- // Static Strings prevent typos and make my job easier.
- private static var COMMON:String = "COMMON";
- private static var RARE:String = "RARE";
- private static var EPIC:String = "EPIC";
- private static var LEGENDARY:String = "LEGENDARY";
- private static var GOLDEN:String = "GOLDEN";
- private static var STANDARD:String = "STANDARD";
- // The number of cards of each rarity that are available to collect.
- private static var availableCards:Object = {
- "COMMON" : 94,
- "RARE" : 81,
- "EPIC" : 37,
- "LEGENDARY" : 33
- };
- // The number of items of each card required to complete that item. Based on rarity.
- private static var collectionLimitbyRarity:Object = {
- "COMMON" : 2,
- "RARE" : 2,
- "EPIC" : 2,
- "LEGENDARY" : 1
- }
- // The amount of dust earned by disenchanting an card.
- private static var disenchantValue:Object = {
- "COMMON": {
- "STANDARD" : 5,
- "GOLDEN" : 50
- },
- "RARE": {
- "STANDARD" : 20,
- "GOLDEN" : 100
- },
- "EPIC": {
- "STANDARD" : 100,
- "GOLDEN" : 400
- },
- "LEGENDARY": {
- "STANDARD" : 400,
- "GOLDEN" : 1600
- }
- };
- // The amount of dust required to craft a card.
- private static var craftValue:Object = {
- "COMMON": {
- "STANDARD" : 40,
- "GOLDEN" : 400
- },
- "RARE": {
- "STANDARD" : 100,
- "GOLDEN" : 800
- },
- "EPIC": {
- "STANDARD" : 400,
- "GOLDEN" : 1600
- },
- "LEGENDARY": {
- "STANDARD" : 1600,
- "GOLDEN" : 3200
- }
- };
- // Rarity Distribution Multiplied by 1000 for easier calculations. Example: 730 = 0.73 or 73%
- private static var rarityDistribution:Object = {
- "COMMON" : 730,
- "RARE" : 210,
- "EPIC" : 50,
- "LEGENDARY" : 10,
- "GOLDEN" : 25
- };
- // List of rarities
- private static var rarities:Array = new Array(COMMON, RARE, EPIC, LEGENDARY);
- // SIMULATOR VARIABLES //
- // THESE VARIABLES ARE USED BY THE SIMULATOR TO TRACK PROGRESS. DO NOT CHANGE THEM. //
- // Create the collection "Array"
- private var collection:Object = {
- "COMMON": {
- "STANDARD" : {},
- "GOLDEN" : {}
- },
- "RARE": {
- "STANDARD" : {},
- "GOLDEN" : {}
- },
- "EPIC": {
- "STANDARD" : {},
- "GOLDEN" : {}
- },
- "LEGENDARY": {
- "STANDARD" : {},
- "GOLDEN" : {}
- }
- };
- // The amount of dust currently collected
- public var dust:int = 0;
- // Number of Cards available in the collection
- public var completeCollectionCardCount:int = 0;
- // The number of packs opened.
- public var packsOpened:int = 0;
- // This is a calculated amount of dust required to complete the collection after each pack is opened.
- public var dustRequiredToCompleteCollection:int = 0;
- // The nubmer of cards that required disenchantment.
- public var cardsDisenchanted:int = 0;
- // The number of cards collected so far.
- public var cardsCollected:int = 0;
- public function Simulation():void
- {
- /*
- * This is the plan.
- *
- * 1. Open packs, and track collected cards. As soon as a card exceeds the collection limit (2 for most cards, 1 for LEGENDARY) that card will be disenchanted.
- * 2. After each pack is opened a check will be made to determine if enough dust is available to complete the collection.
- * 3. Output the results
- *
- * Note: a "RARE or better" card is "guaranteed" in each pack. This complicates things. However, the percentages given for rarities are based on opening a huge number of packs. Since this is what this simulation is attempting, theoretically we do not need to account for the rarity guarantee.
- */
- // Build the Collection and set all card quantity to 0;
- buildCollectionArray();
- // How many cards do we need to collected?
- calculateCardCount();
- // Let's Calculate the total dust remaining.
- calculateDustRequired();
- // Now let's run the simulation
- simulation();
- }
- private function simulation():void
- {
- while ( dust < dustRequiredToCompleteCollection )
- openAPack();
- // Done!
- }
- private function openAPack():void
- {
- // Record that a pack was opened!
- packsOpened++;
- for ( var cardNumber:int = 0; cardNumber < 5; cardNumber ++ )
- {
- // Geat a new random card.
- var card:Object = generateRandomCard();
- //trace("Opened a Card!", card.rarity, card.version, card.cardNumber);
- // Check the existing quantity of this card.
- var existingQuantity:int = collection[card.rarity][card.version][card.cardNumber];
- // Do we already have the maximum of this card?
- if ( existingQuantity == collectionLimitbyRarity[card.rarity] )
- {
- // Disenchant it!
- dust += disenchantValue[card.rarity][card.version];
- cardsDisenchanted++;
- }
- else
- {
- // Add the card to the collection
- collection[card.rarity][card.version][card.cardNumber]++;
- cardsCollected++;
- // Subtract it's craft value from the dust required to complete the collection
- dustRequiredToCompleteCollection -= craftValue[card.rarity][card.version];
- }
- }
- }
- private function generateRandomCard():Object
- {
- // First let's determine the rarity.
- var rarity:String = determineRarity();
- // Is the card Golden or standard
- var version:String = randomNumber(0, 999) < rarityDistribution[GOLDEN] ? GOLDEN : STANDARD;
- // Now generate a card number
- var cardNumber:int = randomNumber(1, availableCards[rarity]);
- // Return the card info
- return {
- "rarity" : rarity,
- "version" : version,
- "cardNumber" : cardNumber
- };
- }
- private function determineRarity():String
- {
- var rarityTarget:int = randomNumber(0, 999);
- if ( rarityTarget < rarityDistribution[COMMON] )
- return COMMON;
- else if ( rarityTarget < rarityDistribution[COMMON] + rarityDistribution[RARE] )
- return RARE;
- else if ( rarityTarget < rarityDistribution[COMMON] + rarityDistribution[RARE] + rarityDistribution[EPIC] )
- return EPIC;
- else
- return LEGENDARY;
- }
- private function randomNumber(min:int, max:int):int
- {
- return Math.floor(Math.random() * (1 + max - min)) + min;
- }
- private function buildCollectionArray():void
- {
- for ( var rarity:String in availableCards )
- {
- buildCollectionSubArray(collection[rarity], availableCards[rarity]);
- }
- }
- private function buildCollectionSubArray(subCollection:Object, quantity:int):void
- {
- for ( var i:int = 1; i <= quantity; i++ )
- {
- subCollection.STANDARD[i] = 0;
- subCollection.GOLDEN[i] = 0;
- }
- }
- private function calculateDustRequired():void
- {
- for ( var rarity:String in availableCards )
- {
- // Cost to craft Standard Cards
- dustRequiredToCompleteCollection += availableCards[rarity] * craftValue[rarity][STANDARD] * collectionLimitbyRarity[rarity];
- // Cost to craft Golden Cards
- dustRequiredToCompleteCollection += availableCards[rarity] * craftValue[rarity][GOLDEN] * collectionLimitbyRarity[rarity];
- }
- }
- private function calculateCardCount():void
- {
- for ( var rarity:String in availableCards )
- {
- // Multiplied by 2 to include gold and standard cards.
- completeCollectionCardCount += availableCards[rarity] * collectionLimitbyRarity[rarity] * 2;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement