|
|
|
@ -1045,6 +1045,12 @@ class Board{
|
|
|
|
let atkAttacker = this.attackOf(itemAttacking);
|
|
|
|
let atkAttacker = this.attackOf(itemAttacking);
|
|
|
|
let atkDefender = this.attackOf(itemDefending);
|
|
|
|
let atkDefender = this.attackOf(itemDefending);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if the attack can target the defender
|
|
|
|
|
|
|
|
if(!this.canAttackDefender(itemAttacking, itemDefending)){
|
|
|
|
|
|
|
|
alert('Cannot target card.');
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Does Attacker kill Defender
|
|
|
|
// Does Attacker kill Defender
|
|
|
|
if(atkDefender <= atkAttacker){
|
|
|
|
if(atkDefender <= atkAttacker){
|
|
|
|
this.sendToGrave(itemDefending);
|
|
|
|
this.sendToGrave(itemDefending);
|
|
|
|
@ -1062,6 +1068,13 @@ class Board{
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 'shield':
|
|
|
|
case 'shield':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check shield can be targetted (not defended by taunt/block unit)
|
|
|
|
|
|
|
|
if(!this.canAttackDirect(itemAttacking, player[itemDefending])){
|
|
|
|
|
|
|
|
alert('Cannot attack shield for some reason');
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the shield is tapped 'destroy' it
|
|
|
|
// If the shield is tapped 'destroy' it
|
|
|
|
if(this.isTapped(itemDefending)){
|
|
|
|
if(this.isTapped(itemDefending)){
|
|
|
|
if(!this.destroyShield(itemDefending)){
|
|
|
|
if(!this.destroyShield(itemDefending)){
|
|
|
|
@ -1081,6 +1094,58 @@ class Board{
|
|
|
|
|
|
|
|
|
|
|
|
this.drawBoard();
|
|
|
|
this.drawBoard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
canAttackDefender(itemAttacking, itemDefending){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Currently all there is is that flight cannot
|
|
|
|
|
|
|
|
// be attacked by anything but flight and reach
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If defender has flight
|
|
|
|
|
|
|
|
if(flight[itemDefending]){
|
|
|
|
|
|
|
|
// And attack doesn't have either flight or reach
|
|
|
|
|
|
|
|
if(flight[itemAttacking] === undefined && reach[itemAttacking] === undefined){
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
canAttackDirect(itemAttacking, playerDefending){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Defender must not be tapped, as you can ignore tapped units
|
|
|
|
|
|
|
|
let itemsToBlock = this.getItems('board', playerDefending, null, null);
|
|
|
|
|
|
|
|
for(let item = 0; item < itemsToBlock.length; item++){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let defender = itemsToBlock[item];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Defender cannot block if tapped
|
|
|
|
|
|
|
|
if(this.isTapped(defender)){
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the defender doesn't have taunt, direct attacks can occur
|
|
|
|
|
|
|
|
if(taunt[defender] == undefined){
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the attacked doesn't have flight (or another means of bypassing taunt)
|
|
|
|
|
|
|
|
// it can't attack direct
|
|
|
|
|
|
|
|
if(!flight[itemAttacking]){
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the unitAttacking has flight, it can be blocked by a taunt+flight
|
|
|
|
|
|
|
|
// or giant+flight
|
|
|
|
|
|
|
|
if(flight[itemAttacking] && flight[defender]){
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
attackOf(itemKey){
|
|
|
|
attackOf(itemKey){
|
|
|
|
// TODO: Change this to ECSey element when added
|
|
|
|
// TODO: Change this to ECSey element when added
|
|
|
|
return cardData[itemKey];
|
|
|
|
return cardData[itemKey];
|
|
|
|
|