Merlin_R

Dunno Dice Incremental Distribution

Jan 30th, 2018
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Die( stars )
  2. {
  3.   this.stars = stars;
  4.   this.red = 0;
  5.   this.yellow = 0;
  6.   this.blue = 0;
  7.   this.pink = 0;
  8.   this.calculateStars();
  9. }
  10.  
  11. Die.prototype.up = function( stars )
  12. {
  13.   if ( !stars ) stars = 1;
  14.   this.stars += stars;
  15.   this.calculateStars();
  16. }
  17.  
  18. Die.prototype.calculateStars = function()
  19. {
  20.   var stars = this.stars;
  21.   var blue = 0, red = 0, yellow = 0, pink = 0;
  22.  
  23.   // Pink
  24.   stars -= pink   = 0 | ( stars > 20 ? stars * .175 - 2.5 : 0 );
  25.   if ( pink > this.pink )
  26.     console.log( "PINK: " + (pink - this.pink) );
  27.   this.pink = pink;
  28.  
  29.   // Blue
  30.   stars -= blue   = 0 | ( stars * .15 );
  31.   if ( blue > this.blue )
  32.     console.log( "BLUE: " + (blue - this.blue) );
  33.   this.blue = blue;
  34.  
  35.   // Yellow
  36.   stars -= yellow = 0 | ( stars * .33 );
  37.   if ( yellow > this.yellow )
  38.     console.log( "YELLOW: " + (yellow - this.yellow) );
  39.   this.yellow = yellow;
  40.  
  41.   // Red
  42.   stars -= red    = 0 | stars;
  43.   if ( red > this.red )
  44.     console.log( "RED: " + (red - this.red) );
  45.   this.red = red;
  46.  
  47.   return this;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment