ZoriaRPG

FFC Chest Minigame

Nov 19th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.99 KB | None | 0 0
  1. //Chest Minigame FFC
  2. //By: ZoriaRPG
  3. //v0.3.4
  4.  
  5. //!The initial combo for this ffc should be a rupee icon with a numeric cost. The next combo in the list, should be blank.
  6.  
  7. const int CMB_CHEST_GAME_CLOSED = 0;
  8. const int CMB_CHEST_GAME_OPEN = 0;
  9.  
  10. const int CHEST_GAME_NO_CHEST = 0;
  11. const int CHEST_GAME_CHEST_CLOSED = 1;
  12. const int CHEST_GAME_CHEST_OPEN = 2;
  13.  
  14. const int TIME_INPUT_UP_OPEN_CHEST = 100; //100 frames of inputting up will open a closed chest.
  15.  
  16. const int MSG_CHEST_GAME_OVER = 0;
  17. const int SFX_OPEN_CHEST = 63;
  18.  
  19. const int MSG_CHEST_GAME_OVER = 0;
  20. const int MSG_CHEST_GAME_RULES = 0;
  21.  
  22. const int CHEST_GAME_LAYER = 2;
  23. const int CHEST_GAME_SCREEN_D_REGISTER = 5;
  24. const int CHEST_GAME_HOLDUP_TYPE = LA_HOLD1LAND;
  25.  
  26. const int CHEST_GAME_ALLOW_REPLAY = 0;
  27.  
  28. const int SFX_CHEST_GAME_SPECIAL_PRIZE_FANFARE = 64;
  29.  
  30.  
  31.  
  32.  
  33. //D0: Number of chests to allow the player to open, per play.
  34. //D1: ID of special prize to award.
  35. //D2: Percentage chance of awarding special prize.
  36. //D3: Backup prize, if special prize already awarded (e.g. 100 rupees, instead of a heart piece). Set to '0' to not offer a backup prize.
  37. //D4: Cost per play.
  38. //D5: String for game rules.
  39. //D6: String to play at end of game.
  40.  
  41.  
  42. ffc script ChestMiniGame{   //layer for combos, number of plays, big prize, hold up animation, Screen->D register, percentage chance of main prize, backup prize if big prize already awarded, and rolled again. cost per play, message to play when game is over.
  43.     void run(int max_chests_Link_can_open, int specialPrize, int percentMainprize, int backupPrize, int costPerPlay, int msgRules, int msgEnd,){
  44.         //!We need to decide which args to keep.
  45.        
  46.         //! chestLayer, and reg can easily be constants.
  47.             //the sfx should only be a constant
  48.        
  49.        
  50.         //Populate with the IDs of prizes to award. Each index is a 1% chance.
  51.         int chestPrizes[]= {    0000000000,
  52.                     0000000000,
  53.                     0000000000,
  54.                     0000000000,
  55.                     0000000000,
  56.                     0000000000,
  57.                     0000000000,
  58.                     0000000000,
  59.                     0000000000,
  60.                     0000000000;  }
  61.  
  62.         int initialData = this->Data; //Store the initial combo, to revert, if replay is enabled.
  63.         int chestComboSpots[176];
  64.         int check;
  65.        
  66.         int mainprize;
  67.         int input_up_timer = TIME_INPUT_UP_OPEN_CHEST;
  68.         bool openchest;
  69.         int has_opened_number_of_chests;
  70.         bool award_main_prize;
  71.         bool gameRunning;
  72.         bool gameOver;
  73.        
  74.         //Populate chestComboSpots with the coordinates of each closed chest.
  75.         for ( int q = 0; q < 176; q++ ) {
  76.             int cmb = GetLayerComboD(CHEST_GAME_LAYER,q);
  77.             if ( cmb == CMB_CHEST_GAME_CLOSED ) chestComboSpots[q] = CHEST_GAME_CHEST_CLOSED;
  78.         }
  79.        
  80.         int spotsUnderChests[192]; //Populate with the combo positions under closed chests.
  81.        
  82.         for ( int q = 0; q < 176; q++ ) { //Each combo under a chest is 16 combos higher in number than the actual chest.
  83.              spotsUnderChests[q+16] = chestComboSpots[q];
  84.         }
  85.        
  86.         if ( msgRules ) Screen->Message(msgRules);
  87.         else Screen->Message(MSG_CHEST_GAME_RULES); //Show the string for the chest game rules.
  88.        
  89.         while(true) {
  90.            
  91.             if ( gameOver && !CHEST_GAME_ALLOW_REPLAY ) break;
  92.            
  93.             if ( gameOver && CHEST_GAME_ALLOW_REPLAY ) {
  94.                 gameRunning = false;
  95.                 this->Data = initialData;
  96.             }
  97.            
  98.             if ( LinkCollision(this) && Game->Counter[CR_RUPEES] > costPerPlay && Xor(Link->PressA,Link->PressB) && !gameRunning ) {   
  99.                     //If Link collides with the ffc, which should show the cost, and presses a button, start the game.
  100.                 gameRunning = true;
  101.                 Game->DCounter[CR_RUPEES] -= costPerPlay;
  102.                 this->Data++; //increase to the next combo, removing the cost icon.
  103.             }
  104.                
  105.            
  106.            
  107.             if ( gameRunning ) {
  108.            
  109.                 if ( input_up_timer <= 0 ) {
  110.                     openchest = true;
  111.                     input_up_timer = TIME_INPUT_UP_OPEN_CHEST;
  112.                 }
  113.                
  114.                 //Check to see if the combo above Link is a chest.
  115.            
  116.                 if ( spotsUnderChests[ ComboAt( CenterLinkX(), CenterLinkY() ) ] == CHEST_GAME_CHEST_CLOSED && Link->Dir == DIR_UP && has_opened_number_of_chests <= max_chests_Link_can_open) {
  117.                
  118.                     //if Link is under a closed chest, and is facing up.
  119.                     //if Link is pressing up
  120.                     if ( Link->InputUP && !openchest ) input_up_timer--;
  121.  
  122.                     //if Link stops pressing up, reset the timer instantly.
  123.                     if ( !Link->InputUp ) input_up_timer = TIME_INPUT_UP_OPEN_CHEST;
  124.                    
  125.                     //If the timer expires, and Link is still pressing up...
  126.                     if ( ( Link->InputUp && openchest ) || ( Xor(Link->PressA,Link->PressB) ) ) { //The timer is over, and Link is still pressing up, so open the chest.
  127.                         has_opened_number_of_chests++; //Update out counter, so that Link can only open as many chests as specified by arg 'max_chests_Link_can_open'.
  128.                         int combo_under_link = ComboAt( CenterLinkX(), CenterLinkY() ); //Store the position of Link's undercombo.
  129.                         int cmb_chest_to_open = ComboAt( CenterLinkX(), CenterLinkY() ) - 16; //and the position of the chest combo.
  130.                        
  131.                        
  132.                        
  133.                         item i; //make an item pointer.
  134.                         SetLayerComboD(CHEST_GAME_LAYER,cmb_chest_to_open,CMB_CHEST_GAME_OPEN); //Change the chest to an open chest combo.
  135.                        
  136.                         spotsUnderChests[combo_under_link] = CHEST_GAME_CHEST_OPEN; //Mark the array indices as being open.
  137.                         chestComboSpots[cmb_chest_to_open] = CHEST_GAME_CHEST_OPEN; //in both arrays.
  138.                        
  139.                         check = Rand(1,100);  //Make a check, to use for determining if the main prize should e awarded.
  140.                         if ( check <= percentMainPrize ) award_main_prize = true; //If that check passes, then we will award the main prize.
  141.                        
  142.                         if ( check > percentMainPrize ) check = Rand(0,SizeOfArray(chestPrizes); //Otherwise, reuse that var, and make a new check to determine
  143.                                                             //the prize to award from the table.
  144.                        
  145.        
  146.                         int itm;
  147.            
  148.                         if ( award_main_prize && !Screen->D[CHEST_GAME_SCREEN_D_REGISTER] ) { //The main prize has not been awarded, and has been randomly chosen.
  149.                             Screen->D[CHEST_GAME_SCREEN_D_REGISTER] = 1;    //Set the register so that Link cannot collect the special prize again.
  150.                             Game->PlaySound(SFX_CHEST_GAME_SPECIAL_PRIZE_FANFARE); //Play the fanfare...
  151.                             i = Screen->CreateItem(specialPrize);   //Assign the pointer, and make the item.
  152.                             itm = specialPrize; //Set the value of the item ID to a var so that we can use it for holding it up.
  153.                         }
  154.                         if ( award_main_prize && Screen->D[CHEST_GAME_SCREEN_D_REGISTER] ) {    //The main prize has already been awarded, so recheck.
  155.                             check = Rand(0,SizeOfArray(chestPrizes)); //Make the new check, to determine what prize to award.
  156.                             if ( backupPrize ) {    //if a backup prize is set in the script args...
  157.                                 Game->PlaySound(SFX_CHEST_GAME_SPECIAL_PRIZE_FANFARE);  //Play the special award fanfare...
  158.                                 i = Screen->CreateItem(backupPrize);    //Assign the pointer, and make the item.
  159.                                 itm = backupPrize;  //Set the value of the item ID to a var so that we can use it for holding it up.
  160.                             }
  161.                            
  162.                             if ( !backupPrize && check ) {  //If the array index is not zero...
  163.                                 //if ( sfx ) Game->PlaySound(sfx); //if the sfx arg is set, play that SFX file.
  164.                                 Game->PlaySound(SFX_OPEN_CHEST); //otherwise, play the default.
  165.                                 i = Screen->CreateItem(chestPrizes[check]); //Assign the pointer, and make the item.
  166.                                 itm = chestPrizes[check];   //Set the value of the item ID to a var so that we can use it for holding it up.
  167.                             }
  168.                         }
  169.                         else {  //Otherwise, if the check to award a special prize did not pass..
  170.                             if ( check ) { //if the array index is not zero...
  171.                                 //if ( sfx ) Game->PlaySound(sfx); //if the sfx arg is set, play that SFX file.
  172.                                 Game->PlaySound(SFX_OPEN_CHEST); //otherwise, play the default.
  173.                                 i = Screen->CreateItem(chestPrizes[check]); //Award a normal prize, from the list.
  174.                                 itm = chestPrizes[check]; //Set the value of the item ID to a var so that we can use it for holding it up.
  175.                             }
  176.                         }
  177.                         if ( check ) {  //if we're awarding a prize...
  178.                             i -> X = Link->X;
  179.                             i -> Y = Link->Y;
  180.                             if ( CHEST_GAME_HOLDUP_TYPE ) {  //If the setting to hold the item overhead is enabled...
  181.                                 Link->Action = CHEST_GAME_HOLDUP_TYPE; //Hold the item overhead, using the value of that setting.
  182.                                 Link->HeldItem =  itm;
  183.                             }
  184.                         }
  185.                         else Remove(i); //if check is zero, remove the item pointer.
  186.                                 //This allows chances of getting nothing at all.
  187.                     }
  188.                
  189.                     if ( has_opened_number_of_chests > max_chests_Link_can_open ) {
  190.                         gameOver = true;
  191.                         gameRunning = false;
  192.                         if ( msgEnd ) Screen->Message(msgEnd);
  193.                         else Screen->Message(MSG_CHEST_GAME_OVER);
  194.                        
  195.                     }
  196.                
  197.                     Waitframe();
  198.  
  199.                     //if ComboAt( ( GridX( CenterLinkX()  ) ), GridX( CenterLinkY() -8 ) )
  200.                 }
  201.                 Waitframe();
  202.             }
  203.        
  204.             Waitframe();
  205.         }
  206.         //If we reach here, then the chest game is over.
  207.         this->Data = 0;
  208.         this->Script = 0;
  209.         Quit();
  210.     }
  211. }
Add Comment
Please, Sign In to add comment