Jimmied in manaCost stuff, but not 100% working

develop
Nathan Steel 1 year ago
parent 70f4a362b1
commit 9fac1d3dcc

@ -624,65 +624,96 @@ class Board{
// Loop probably not needed, but may be for eg. 'play X cards from top of deck' // Loop probably not needed, but may be for eg. 'play X cards from top of deck'
for(let play = 0; play < cardsToPlay; play++){ for(let play = 0; play < cardsToPlay; play++){
// Check there's space on board TODO: change to locationTo
// TODO: Normalise this for all element/player combos // Check there's space on the board/mana zone/shield/etc
let elementLength = getCurrentPositionAndLength(toElement, toPlayer)[1]; if(!this.hasSpaceInBoardElement(toElement, toPlayer)){
// TODO: Compare against the maxSize for the boardElement alert('No space in element');
// this is fine(ish) for now, as just using hand return false;
if(elementLength >= maxHandSize){
alert('Board full '+elementLength+'/'+maxHandSize);
return 0;
} }
// When done remove false &&
// TODO: Rewrite for ECS let itemKey = this.getItemKey(fromElement, positionFrom);
console.log(itemKey);
console.log(positionFrom);
switch(fromElement){
case 'hand':
// Mana cost required and mana tapping for playing a card from hand, etc // Mana cost required and mana tapping for playing a card from hand, etc
if(false && cardPlayed.cost > playerMana.length){ // The player casting/summoning should pay, ofc
alert('Not enough mana'); let canPayMana = this.canPayMana(itemKey, fromPlayer)
return 0; if(canPayMana !== true){
alert(canPayMana);
return false;
}else{
// Tap mana and play TODO: TEMP SOLUTION
// TODO: May want to make this recursive, it's better and less bulky
// but still lots of dupe code
let items = this.ECSLoop('mana', fromPlayer, null, null);
for(let item = 0; item < items.length; item++){
let mana = items[item];
// For now just tapping the first untapped mana
// TODO: Tap mana of correct colour (also allow player to select in fut)
if(!this.isTapped(mana) && cardData[mana].colour == cardData[itemKey].colour){
this.tapCard(mana);
}else{
return false;
}
}
}
} }
// Move from player0, position 0 (top) of deck, to hand, to pos(null/auto) for toPlayer // Move from player0, position 0 (top) of deck, to hand, to pos(null/auto) for toPlayer
this.addFromBoardElement(fromPlayer, positionFrom, fromElement, toElement, null, toPlayer); this.addFromBoardElement(fromPlayer, positionFrom, fromElement, toElement, null, toPlayer);
} }
this.drawBoard();
// Needs doing for playing cards from hand
if(false){
let manaUsed = [];
if(cardPlayed.cost > playerMana.length){
alert('Not enough mana');
return 0;
}else{
let canPlay = false;
let needsMana = 1;
let usedMana = 0;
playerMana.forEach(function(manaCard, key){
if(cardPlayed.colour == manaCard.colour && manaCard.tapped == false && needsMana > usedMana){
console.log(manaCard);
// Needs changing for multiple colour usage
// 2 red, 1 red + 1 blue, etc.
// Currently only gets one mana of the cards colour
manaUsed.push(key);
usedMana++;
canPlay = true;
} }
});
if(!canPlay){ getItemKey(boardElementId, listPositionId){
alert('Mana conditions not met, right click hand unit to play as mana'); let itemKey = this.ECSLoop(boardElementId, null, null, listPositionId);
return 0; if(itemKey.length < 1){
alert('Could not find key');
return false;
}
if(itemKey.length > 1){
alert('Found more than one key');
return false
} }
// Return first index of array, aka the itemKey
return itemKey[0];
} }
// Tap mana to be used hasSpaceInBoardElement(toElement, toPlayer){
manaUsed.forEach(function(cardKey, key){
playerMana[cardKey].tapped = true; let elementLength = getCurrentPositionAndLength(toElement, toPlayer)[1];
});
if(elementLength >= maxHandSize){
alert('Board full '+elementLength+'/'+maxHandSize);
return false;
}
return true;
}
canPayMana(itemToPlay, playerId){
// Check player has enough mana
if(this.ECSLoop('mana', playerId, null, null).length < cardData[itemToPlay].cost){
return 'Not enough mana';
} }
this.drawBoard(); // 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 manaRequired = cardData[itemToPlay].colour;
console.log(manaRequired);
let items = this.ECSLoop('mana', player[itemToPlay], null, null);
for(let item = 0; item < items.length; item++){
let itemKey = items[item];
if(cardData[itemKey].colour == manaRequired && !this.isTapped(itemKey)){
manaUsed.push(itemKey); // This would be how I'd loop for X colour, or multi
return true;
}
}
return 'Do not have correct mana requirements';
} }
inspectCard(cardToInspect){ inspectCard(cardToInspect){

Loading…
Cancel
Save