You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
269 lines
6.1 KiB
JavaScript
269 lines
6.1 KiB
JavaScript
// Passive effects (just does stuff)
|
|
let flight = {};
|
|
let reach = {};
|
|
let equipped = {}; // Entity x has [a,b,c] equipped to it
|
|
|
|
|
|
// Trigger types
|
|
const triggerTypes = {
|
|
'tap': 1,
|
|
'pay': 2,
|
|
};
|
|
// Basic effects
|
|
// TODO: Pull display name/description from DB?
|
|
const basicEffects = {
|
|
1: 'Equip',
|
|
2: 'Heal',
|
|
3: 'Hurt',
|
|
4: 'Recruit',
|
|
5: 'Give Flight',
|
|
};
|
|
|
|
|
|
// Actives to add passives
|
|
function giveFlight(card){
|
|
flight[card] = true;
|
|
}
|
|
function removeFlight(card){
|
|
// If the card has flight delete entity component
|
|
if(card in flight){
|
|
delete flight[card];
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
function giveReach(card){
|
|
reach[card] = true;
|
|
}
|
|
function removeReach(card){
|
|
if(card in reach){
|
|
delete reach[card];
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Active
|
|
function equip(){
|
|
// Equip card to another unit
|
|
|
|
}
|
|
function unequip(){
|
|
// Remove card from its equipped to unit
|
|
|
|
}
|
|
|
|
function drawCard(drawAmount, player){
|
|
board.drawACard(player, drawAmount);
|
|
}
|
|
|
|
function heal(healAmount, healPlayer){
|
|
// For each heal 1..4
|
|
for(let i = 0; i < healAmount; i++){
|
|
// Loop shield
|
|
let items = this.getItems('shield', healPlayer, null, null);
|
|
for(let item = 0; item < items.length; item++){
|
|
|
|
let itemKey = items[item];
|
|
// If a shield is tapped, untap it to 'heal'
|
|
if(board.isTapped(itemKey)){
|
|
board.untapCard(itemKey);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
function hurt(hurtDamage, hurtTarget = null, hurtPlayer = null){
|
|
// Deal X000 damage to unit this turn, or deal Y to opponent's shield
|
|
|
|
// Set player/element
|
|
if(hurtPlayer == null && hurtTarget != null){
|
|
hurtPlayer = player[hurtTarget];
|
|
hurtElement = boardElement[hurtTarget];
|
|
}else{
|
|
hurtElement = 'shield'
|
|
}
|
|
|
|
switch(hurtElement){
|
|
case 'board':
|
|
// TODO: Make temp damage this turn as well
|
|
if(hurtDamage >= cardAttack[hurtTarget][0]){
|
|
board.sendToGrave(hurtTarget);
|
|
}
|
|
break;
|
|
|
|
case 'shield':
|
|
let destroyCount = cardAttackToShieldDamage(hurtDamage);
|
|
console.log(destroyCount);
|
|
// TODO: loop player's shield, tap if they can be tapped, destroy
|
|
// if all already tapped
|
|
|
|
// While there's still damage to deal
|
|
while(destroyCount > 0){
|
|
|
|
// Keep looping through the shield belonging to target user
|
|
let items = board.getItems('shield', hurtPlayer, null, null);
|
|
let tappedItems = board.getItems('shield', hurtPlayer, 'tapped', null);
|
|
|
|
for(let item = 0; item < items.length; item++){
|
|
|
|
// If nothing more to destroy, exit loop
|
|
if(destroyCount <= 0){ break; }
|
|
|
|
let itemKey = items[item];
|
|
console.log(itemKey);
|
|
console.log(cardStatus[itemKey]);
|
|
|
|
// If there's anything to tap, tap it
|
|
if(cardStatus[itemKey] == null){
|
|
console.log('been tapped');
|
|
board.tapCard(itemKey);
|
|
destroyCount--;
|
|
continue;
|
|
}
|
|
|
|
// If there's nothing to tap, destroy it
|
|
if(items.length == tappedItems.length){
|
|
console.log('been destroyed');
|
|
board.destroyShield(itemKey);
|
|
destroyCount--;
|
|
continue;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
board.drawBoard();
|
|
break; // end case 'shield'
|
|
|
|
}
|
|
}
|
|
|
|
// Effect Trigger(s)
|
|
// Non-event triggers. i.e. these are activated triggers
|
|
// rather than things such as 'On attack', 'When opponent draws'
|
|
|
|
// When card has been actively tapped
|
|
function triggerTap(card){
|
|
if(canTriggerTap(card) == false){ return false; }
|
|
|
|
board.tapCard(card);
|
|
|
|
console.log('triggerTap');
|
|
return true;
|
|
|
|
}
|
|
// Check a card can actively be tapped, otherwise don't start trigger
|
|
function canTriggerTap(card){
|
|
if(board.isTapped(card)){
|
|
return false;
|
|
}
|
|
if(boardElement[card] != 'board'){
|
|
return false;
|
|
}
|
|
|
|
console.log('can triggerTap');
|
|
return true;
|
|
}
|
|
|
|
// Pay the mana cost(s) to trigger event
|
|
function triggerPay(triggerAmount){
|
|
if(canTriggerPay(triggerAmount) == false){
|
|
return false;
|
|
}
|
|
|
|
let effectCosts = [{1:0,2:0,3:0,4:0}, triggerAmount];
|
|
board.tapManaRequired(null, 0, false, effectCosts);
|
|
|
|
console.log('triggerPay');
|
|
return true;
|
|
|
|
}
|
|
// Check the mana cost(s) can be paid, otherwise don't start trigger
|
|
function canTriggerPay(triggerAmount){
|
|
// For player0 only at the mo. and with no specific colour costs
|
|
let effectCosts = [{1:0,2:0,3:0,4:0}, triggerAmount];
|
|
if(board.tapManaRequired(null, 0, true, effectCosts) == false){
|
|
console.log('cannot trigger pay');
|
|
return false;
|
|
}
|
|
|
|
console.log('Can trigger pay');
|
|
return true;
|
|
|
|
}
|
|
|
|
// Pay/Activate (all) the triggers
|
|
function triggerEffect(itemKey, effectIndex, checkOnly = false){
|
|
|
|
// Check card has effectData
|
|
let effectData = cardEffect[itemKey];
|
|
if(effectData === undefined){ return false; } // No effect
|
|
|
|
// Check effectData contains target effect
|
|
let effect = effectData[effectIndex];
|
|
if(effect === undefined){ return false; } // No effect
|
|
|
|
// Loop each trigger, AND activate them
|
|
for (const [key, value] of Object.entries(effect['trigger'])) {
|
|
|
|
let effectTrigger = effect['trigger'][key];
|
|
console.log('--- Trigger '+key+' ---');
|
|
console.log(effectTrigger['triggerTypeId']);
|
|
|
|
// TAP TRIGGER
|
|
if(effectTrigger['triggerTypeId'] == triggerTypes.tap){
|
|
if(canTriggerTap(itemKey) == false){
|
|
console.log('Tap trigger, cannot be triggered');
|
|
return false;
|
|
}
|
|
|
|
// Do the trigger, then continue to next trigger
|
|
if(!checkOnly){board.tapCard(itemKey);}
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
// PAY TRIGGER
|
|
if(effectTrigger['triggerTypeId'] == triggerTypes.pay){
|
|
|
|
// To build the colourReq TODO: Change as could be 1 of either red/blue
|
|
// for instance
|
|
let colourReq = {1:0,2:0,3:0,4:0};
|
|
|
|
// Loop pay required (colours) for said trigger
|
|
// BUILD the colourReq loop needed for tapMana check
|
|
effectTrigger['target'].forEach((effectTriggerTarget) => {
|
|
|
|
// Increment colourReq by one of that colour
|
|
// THIS WILL NEED REDOING, AS MAYBE IT'S 2 OF RED OR BLUE!!
|
|
colourReq[effectTriggerTarget.colourId]++;
|
|
|
|
});
|
|
|
|
// Check if the cost (and colour req.) can be paid
|
|
canPay = board.tapManaRequired(null, null, true, [colourReq, effectTrigger['amount']]);
|
|
if(canPay !== true){
|
|
console.log('Pay trigger, cannot be triggered');
|
|
return false;
|
|
}
|
|
|
|
// Pay trigger costs, then continue to next trigger
|
|
if(!checkOnly){
|
|
board.tapManaRequired(null, null, false, [colourReq, effectTrigger['amount']]);
|
|
}
|
|
continue;
|
|
|
|
}
|
|
|
|
// OTHER TRIGGERS
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|