@ -486,8 +486,15 @@ class Board{
playerTo = playerFrom ;
playerTo = playerFrom ;
}
}
// Check if there's more than 1 thing add that position (something's gone wrong somewhere)
let items = this . ECSLoop ( elementFrom , playerFrom , null , fromPosition ) ;
if ( board . ECSLoop ( elementFrom , playerFrom , null , fromPosition ) . length > 1 ) {
alert ( 'ERROR: There are more than 1 card being added' ) ;
}
// First (and only) item returned is the key thins should be done with
// First (and only) item returned is the key thins should be done with
let itemKey = this . ECSLoop ( elementFrom , playerFrom , null , fromPosition ) [ 0 ] ;
let itemKey = items [ 0 ] ;
if ( listPosition [ itemKey ] == fromPosition ) {
if ( listPosition [ itemKey ] == fromPosition ) {
// Check if a toPostion supplied
// Check if a toPostion supplied
if ( toPosition == null ) {
if ( toPosition == null ) {
@ -571,7 +578,7 @@ class Board{
case 'hand' :
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
// The player casting/summoning should pay, ofc
// The player casting/summoning should pay, ofc
let canPayMana = this . canPayMana ( itemKey , fromPlayer )
let canPayMana = this . canPayMana ( itemKey , fromPlayer ) ;
if ( canPayMana !== true ) {
if ( canPayMana !== true ) {
alert ( canPayMana ) ;
alert ( canPayMana ) ;
return false ;
return false ;
@ -586,8 +593,9 @@ class Board{
// TODO: Tap mana of correct colour (also allow player to select in fut)
// TODO: Tap mana of correct colour (also allow player to select in fut)
if ( ! this . isTapped ( mana ) && cardData [ mana ] . colour == cardData [ itemKey ] . colour ) {
if ( ! this . isTapped ( mana ) && cardData [ mana ] . colour == cardData [ itemKey ] . colour ) {
this . tapCard ( mana ) ;
this . tapCard ( mana ) ;
break ; // Temp TODO: Tap each mana needed until manacost/colours are met, also TODO: allow user to target own mana OR use non-multitypes first (not implemented yet)
} else {
} else {
return fals e;
continu e;
}
}
}
}
}
}
@ -634,13 +642,14 @@ class Board{
// TODO: Multicolours, and X of same colour checks
// TODO: Multicolours, and X of same colour checks
let manaUsed = [ ] ;
let manaUsed = [ ] ;
// For now, until adding colour, and other attributes to ECS modal
// For now, until adding colour, and other attributes to ECS modal
let mana Required = cardData [ itemToPlay ] . colour ;
let mana Colour Required = cardData [ itemToPlay ] . colour ;
console . log ( mana Required) ;
console . log ( mana Colour Required) ;
let items = this . ECSLoop ( 'mana' , player [ itemToPlay ] , null , null ) ;
let items = this . ECSLoop ( 'mana' , player [ itemToPlay ] , null , null ) ;
for ( let item = 0 ; item < items . length ; item ++ ) {
for ( let item = 0 ; item < items . length ; item ++ ) {
let itemKey = items [ item ] ;
let itemKey = items [ item ] ;
if ( cardData [ itemKey ] . colour == mana Required && ! this . isTapped ( itemKey ) ) {
if ( cardData [ itemKey ] . colour == mana Colour Required && ! this . isTapped ( itemKey ) ) {
manaUsed . push ( itemKey ) ; // This would be how I'd loop for X colour, or multi
manaUsed . push ( itemKey ) ; // This would be how I'd loop for X colour, or multi
console . log ( manaUsed ) ;
return true ;
return true ;
}
}
}
}
@ -771,11 +780,12 @@ class Board{
}
}
}
}
playMana ( fromPosition , fromElement , cardsToPlay = 1 ) {
playMana ( fromPosition , fromElement , fromPlayer, cardsToPlay = 1 ) {
// Move from player0, fromPosition of hand (for now), to mana
// Move from player0, fromPosition of hand (for now), to mana
// TODO: FOR ALL addFromBoardElements, if 'fromPosition' not passed get the
// TODO: FOR ALL addFromBoardElements, if 'fromPosition' not passed get the
// fromPosition and boardElementFrom from the itemId (will need to change to pass this)
// fromPosition and boardElementFrom from the itemId (will need to change to pass this)
this . addFromBoardElement ( 0 , fromPosition , fromElement , 'mana' , null , null ) ;
console . log ( 'playMana(' + fromPosition + ',' + fromElement + ',' + cardsToPlay + ')' ) ;
this . addFromBoardElement ( fromPlayer , fromPosition , fromElement , 'mana' , null , null ) ;
}
}
// HELPER METHODS, to simplify code-base for me in the future
// HELPER METHODS, to simplify code-base for me in the future
@ -860,6 +870,8 @@ canvas.addEventListener('contextmenu', function(event) {
var x = event . pageX - canvasLeft ,
var x = event . pageX - canvasLeft ,
y = event . pageY - canvasTop ;
y = event . pageY - canvasTop ;
console . log ( 'RIGHT CLICK X: ' + x + ' Y: ' + y ) ;
for ( let itemKey = 0 ; itemKey < item . length ; itemKey ++ ) {
for ( let itemKey = 0 ; itemKey < item . length ; itemKey ++ ) {
if ( elements [ itemKey ] == 'deck' ) {
if ( elements [ itemKey ] == 'deck' ) {
@ -874,6 +886,9 @@ canvas.addEventListener('contextmenu', function(event) {
// Only want to happen once (for now)
// Only want to happen once (for now)
// Maybe in future add to hand would trigger another event if there's an effect?
// Maybe in future add to hand would trigger another event if there's an effect?
// Player the item belongs to, not who's doing the action
let playerId = player [ itemKey ] ;
// Check the location of element
// Check the location of element
switch ( boardElement [ itemKey ] ) {
switch ( boardElement [ itemKey ] ) {
// Check item location, and trigger events based on it
// Check item location, and trigger events based on it
@ -886,15 +901,17 @@ canvas.addEventListener('contextmenu', function(event) {
if ( inEvent && inEvent [ 0 ] == 'attack' && itemKey == inEvent [ 1 ] ) {
if ( inEvent && inEvent [ 0 ] == 'attack' && itemKey == inEvent [ 1 ] ) {
board . cancelAttackFor ( itemKey ) ;
board . cancelAttackFor ( itemKey ) ;
}
}
board . drawBoard ( ) ;
break ;
break ;
case 'hand' :
case 'hand' :
// Can be played as mana (right click for now)
// Can be played as mana (right click for now)
// Play item from boardElement hand. To boardElement mana (explanitory)
// Play item from boardElement hand. To boardElement mana (explanitory)
board . playMana ( listPosition [ itemKey ] , 'hand' ) ;
board . playMana ( listPosition [ itemKey ] , 'hand' , playerId ) ;
board . drawBoard ( ) ;
break ;
default :
break ;
break ;
}
}
board . drawBoard ( ) ;
return true ;
}
}
}
}
}
}
@ -916,7 +933,7 @@ canvas.addEventListener('click', function(event) {
// Will be the new way
// Will be the new way
// TODO:Maybe write this into a function? If XY WH is hit return true, and the itemKey
// TODO:Maybe write this into a function? If XY WH is hit return true, and the itemKey
// then it can be re-used in contextclick, hover, etc without rewrite
// then it can be re-used in contextclick, hover, etc without rewrite
console . log ( ' X: '+ x + ' Y: ' + y ) ;
console . log ( ' LEFT CLICK X: '+ x + ' Y: ' + y ) ;
// TODO: Normalise this too
// TODO: Normalise this too
for ( let itemKey = 0 ; itemKey < item . length ; itemKey ++ ) {
for ( let itemKey = 0 ; itemKey < item . length ; itemKey ++ ) {
@ -991,8 +1008,11 @@ canvas.addEventListener('click', function(event) {
board . makeAttack ( itemKey ) ;
board . makeAttack ( itemKey ) ;
}
}
break ;
break ;
default :
break ;
}
}
board . drawBoard ( ) ;
board . drawBoard ( ) ;
return true ;
}
}
}
}
}
}