Skip to content

Commit

Permalink
Merge pull request #1951 from nandastone/fix-disable-materialization-…
Browse files Browse the repository at this point in the history
…sickness-power

Fix "Disable Materialization Sickness" Meta Power
  • Loading branch information
DreadKnight committed Dec 13, 2021
2 parents dee5549 + 7a5c027 commit 9268b3a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/abilities/Dark-Priest.js
Expand Up @@ -285,7 +285,7 @@ export default (G) => {
G.queue.tempCreature = fullCrea;

// Show temporary Creature in queue
G.queue.addByInitiative(fullCrea, creatureHasMaterializationSickness);
G.queue.addByInitiative(fullCrea, !creatureHasMaterializationSickness);
G.updateQueueDisplay();

// Reduce temporary Creature vignette transparency
Expand Down
4 changes: 2 additions & 2 deletions src/creature.js
Expand Up @@ -262,9 +262,9 @@ export class Creature {

/* Without Sickness the creature should act in the current turn, except the dark
priest who must always be in the next queue to properly start the game. */
const addToCurrentQueue = disableMaterializationSickness && !this.isDarkPriest();
const alsoAddToCurrentQueue = disableMaterializationSickness && !this.isDarkPriest();

game.queue.addByInitiative(this, !addToCurrentQueue);
game.queue.addByInitiative(this, alsoAddToCurrentQueue);

if (disableMaterializationSickness) {
this.materializationSickness = false;
Expand Down
31 changes: 19 additions & 12 deletions src/creature_queue.js
Expand Up @@ -9,25 +9,32 @@ export class CreatureQueue {
}

/**
* Add a creature to the next turn's queue by initiative
* Add a creature to the next turn's queue by initiative, and optionally the current
* turn's queue.
*
* @param {Creature} creature The creature to add.
* @param {boolean} addToNextQueue Add creature to the next queue, or the current one.
* @returns
* @param {boolean} alsoAddToCurrentQueue Also add the creature to the current
* turn's queue. Doing so lets a creature act in the same turn it was summoned.
*/
addByInitiative(creature, addToNextQueue = true) {
const targetQueue = addToNextQueue ? this.nextQueue : this.queue;
addByInitiative(creature, alsoAddToCurrentQueue = true) {
const queues = [this.nextQueue];

for (let i = 0; i < targetQueue.length; i++) {
let queue = targetQueue[i];
if (alsoAddToCurrentQueue) {
queues.push(this.queue);
}

if (queue.delayed || queue.getInitiative() < creature.getInitiative()) {
targetQueue.splice(i, 0, creature);
return;
queues.forEach((queue) => {
for (let i = 0; i < queue.length; i++) {
let queueItem = queue[i];

if (queueItem.delayed || queueItem.getInitiative() < creature.getInitiative()) {
queue.splice(i, 0, creature);
return;
}
}
}

targetQueue.push(creature);
queue.push(creature);
});
}

dequeue() {
Expand Down

0 comments on commit 9268b3a

Please sign in to comment.