Change check for mana available vs card mana cost

develop
Nathan Steel 1 year ago
parent 90de381d69
commit 2e86707243

@ -579,23 +579,85 @@ class Board{
return 'Not enough mana';
}
// TODO: Check mana colours are available to play, then tap them
// TODO: Multicolours, and X of same colour checks
let manaUsed = [];
// For now, until adding colour, and other attributes to ECS modal
let manaColourRequired = cardData[itemToPlay].colour;
console.log(manaColourRequired);
// Check if the player has X amount of each mana colour required
// may not be needed to tap them all (if cost reduced), but they need
// to have those colours available.
// Setting them to 0 to start so they can be added to. Could be nicer
let manaAvailable = {0:0, 1:0, 2:0, 3:0, 4:0};
// TODO: Thought, maybe instead of tapping colour used, it's just if you
// have the colour? May be a silly thought, but
// Loop the card to be played, and total its mana requirements
let manaRequired = this.getManaTotalOf(itemToPlay);
// player check for this may need changing for "play from opp hand" etc?
let items = this.getItems('mana', player[itemToPlay], null, null);
for(let item = 0; item < items.length; item++){
// Looping the mana to check player has equal mana/colours to req.
let itemKey = items[item];
if(cardData[itemKey].colour == manaColourRequired && !this.isTapped(itemKey)){
manaUsed.push(itemKey); // This would be how I'd loop for X colour, or multi
console.log(manaUsed);
// Check if the mana is tapped. Ignore if it is (for now)
if(this.isTapped(itemKey)){
continue;
}
// Loop the mana card's colours
// can be multi-coloured, and can be used as diff costs
// TODO: This currently takes a White/Red mana as 2 available manas
// when it should be 1 available of either type...
// TODO: FOR NOW, the colour of the mana is the primary colour
// will set 'manaColour' in DB at some point. So multi-colour
// cards aren't all those when in mana (ie. 6 colour decks can't play
// everything all the time)
let manaType = null; // TODO: Will use the highest mana req as it's colour for now
let manaColours = cardColours[itemKey];
for(let i = 0; i < manaColours.length; i++){
// Set mana colour for card if there isn't one
if(manaType == null){ manaType = manaColours[i]; }
// Check each other colour, use the highest cost colour
// as the colour type for this specific mana
// TODO: Do better, and nicer, manaType in DB with the colour?
if(manaColours[i][1] > manaType[1]){
manaType = manaColours[i];
}
}
let colourId = manaType[0];
manaAvailable[colourId] += 1;
}
// If the manaReq is satiated by the manaAvailable then return true
for (const manaColour in manaRequired) {
console.log('req');
console.log(manaRequired[manaColour]);
console.log('av');
console.log(manaAvailable[manaColour]);
if(manaRequired[manaColour] > manaAvailable[manaColour]){
return 'Do not have enough: '+manaColour+' mana';
}
}
console.log('manaAvailable: ');
console.log(manaAvailable);
return true;
}
getManaTotalOf(itemKey){
let manaTotal = {0:0, 1:0, 2:0, 3:0, 4:0};
let manaColours = cardColours[itemKey];
for(let i = 0; i < cardColours[itemKey].length; i++){
// Add one to the available mana
let colourId = manaColours[i][0];
manaTotal[colourId] += manaColours[i][1]; // Add the cost
}
return 'Do not have correct mana requirements';
console.log('manaTotal: ');
console.log(manaTotal);
return manaTotal;
}
inspectCard(cardToInspect){

Loading…
Cancel
Save