diff --git a/public/board.js b/public/board.js index 89ad5ab..2db6ae7 100644 --- a/public/board.js +++ b/public/board.js @@ -704,7 +704,7 @@ class Board{ // TODO: Look at combining or normalising this and canPayMana() let manaRequired = []; - if(effectCosts !== null){ manaRequired = effectCosts; } + if(effectCosts != null){ manaRequired = effectCosts; } else{ manaRequired = this.getManaTotalOf(itemToPayCost); } let noManaReq = {1:0, 2:0, 3:0, 4:0}; diff --git a/public/debug.js b/public/debug.js index bbc76b7..1a47973 100644 --- a/public/debug.js +++ b/public/debug.js @@ -151,3 +151,22 @@ function debugGetCardEffects(itemKey){ }); } + +function debugEffectCanTrigger(){ + + let ecTriggerTargetId = document.getElementById("ecTriggerTargetId").value; + if(ecTriggerTargetId == ""){ ecTriggerTargetId = null; } + + let ecTriggerIndex = document.getElementById("ecTriggerIndex").value; + if(ecTriggerIndex == ""){ ecTriggerIndex = 0; } + + if(triggerEffect(ecTriggerTargetId, ecTriggerIndex, true) != true){ + console.log('Effect cannot be triggered'); + return false; + } + + console.log('Effect CAN be triggered'); + triggerEffect(ecTriggerTargetId, ecTriggerIndex); + +} + diff --git a/public/effect.js b/public/effect.js index 5140ddc..cbba37d 100644 --- a/public/effect.js +++ b/public/effect.js @@ -6,8 +6,8 @@ let equipped = {}; // Entity x has [a,b,c] equipped to it // Trigger types const triggerTypes = { - 1: 'Tap', - 2: 'Pay', + 'tap': 1, + 'pay': 2, }; // Basic effects // TODO: Pull display name/description from DB? @@ -194,3 +194,75 @@ function canTriggerPay(triggerAmount){ } +// 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; + +} + diff --git a/public/index.html b/public/index.html index fd1bbd7..0d650ff 100644 --- a/public/index.html +++ b/public/index.html @@ -101,6 +101,15 @@ +