Skip to content

Commit

Permalink
[211] Added shuffling when drawing curses and blessings
Browse files Browse the repository at this point in the history
  • Loading branch information
orichalque committed Mar 2, 2022
1 parent d300f8b commit ac2dd42
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions js/modifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,18 @@ var modifiersManagement = {
shuffleModifiersDeck: function() {
this.modifiersDrawPile = this.modifiersChosen.slice()

this.shuffle()

this.lastDrawnModifier = null
this.modifiersDiscardPile = []
},
shuffle: function() {
// JavaScript implementation of the Durstenfeld shuffle, an optimized version of Fisher-Yates
// More here: https://stackoverflow.com/a/12646864
for (let i = this.modifiersDrawPile.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[this.modifiersDrawPile[i], this.modifiersDrawPile[j]] = [this.modifiersDrawPile[j], this.modifiersDrawPile[i]];
}

this.lastDrawnModifier = null
this.modifiersDiscardPile = []
},
displaySpecialModifiers: function() {
if(this.specialModifiers){
Expand All @@ -183,6 +186,7 @@ var modifiersManagement = {
.filter(element => !this.modifiersDrawPile.includes(element))

if(availableBlessings.length > 0) this.addModifier(availableBlessings[0])
this.shuffle();
},
addCurse: function() {
const availableCurses = this.modifiersSpecial
Expand All @@ -191,6 +195,7 @@ var modifiersManagement = {
.filter(element => !this.modifiersDrawPile.includes(element))

if(availableCurses.length > 0) this.addModifier(availableCurses[0])
this.shuffle();
},
resetModifiers: function() {
this.shuffleModifiersDeck()
Expand Down

0 comments on commit ac2dd42

Please sign in to comment.