From 876b705407f8225a68dece60ee14c045cad7f6cb Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 25 Oct 2024 02:30:30 +0100 Subject: [PATCH] Start 'pay' trigger + amend tapManaRequired --- public/board.js | 43 +++++++++++++++++++++++++++++-------------- public/debug.js | 2 +- public/effect.js | 24 +++++++++++++++++++++--- 3 files changed, 51 insertions(+), 18 deletions(-) diff --git a/public/board.js b/public/board.js index 3dcb565..d3da392 100644 --- a/public/board.js +++ b/public/board.js @@ -698,10 +698,15 @@ class Board{ this.drawBoard(); } - tapManaRequired(itemToPayCost, playerId){ + // TODO: Make to check mana, and actually do it. + // also make work for effects + tapManaRequired(itemToPayCost, playerId, checkOnly = false, effectCosts = null){ // TODO: Look at combining or normalising this and canPayMana() - let manaRequired = this.getManaTotalOf(itemToPayCost); + let manaRequired = []; + if(effectCosts !== null){ manaRequired = effectCosts; } + else{ manaRequired = this.getManaTotalOf(itemToPayCost); } + let noManaReq = {1:0, 2:0, 3:0, 4:0}; let manaToTap = []; @@ -723,7 +728,6 @@ class Board{ console.log(JSON.stringify(manaRequired[0])); // Loop the requirements of the cost to pay for (const manaColour in manaRequired[0]) { - //console.log(manaColour+' '+manaRequired[manaColour]+', '+colourId); // If the colour of the mana is in the requirements // of the cost to pay, reduce the cost for that colour by // 1 and tap the mana @@ -745,17 +749,25 @@ class Board{ // For 3 cost cards that only require 1 red, two more mana (any colour) // need to be tapped // TODO: Better more efficiently and let user select... - let itemCostRemaining = cardData[itemToPayCost].cost - manaRequired[1]; - if(itemCostRemaining > 0){ - /* - let tapRequirement = (cardData[itemToPayCost].cost - manaRequired[1]); - alert('Tap: '+(tapRequirement)+' more mana to play'); + let itemCostRemaining = 0; + let itemCost = 0; + if(itemToPayCost !== null){ + itemCostRemaining = cardData[itemToPayCost].cost - manaRequired[1]; + itemCost = cardData[itemToPayCost].cost; + } + else if(effectCosts !== null){ + itemCostRemaining = manaRequired[1]; + itemCost = manaRequired[1]; + } - // start mana tap event - */ + if(itemCostRemaining > 0){ // TODO: decide 100% how cards are to be played/payed for // don't want to slam time into a mana system if it'll be nuked. + if(items.length < itemCostRemaining){ + return false; + } + // For now, reloop and tap first available mana so that card // payment is satiated // Using same items from above @@ -772,18 +784,21 @@ class Board{ } manaToTap.push(mana); + itemCostRemaining--; // TODO: ?????? } } - if(cardData[itemToPayCost].cost - manaToTap.length > 0){ + if(itemCost - manaToTap.length > 0){ return 'itemCostRemaining: '+itemCostRemaining; // Didn't find another mana to tap so cost not satiated } // If the mana to tap has been satitated then tap the mana selected - manaToTap.forEach(manaId => { - this.tapCard(manaId); - }); + if(checkOnly == false){ // Tap the mana if this isn't a check + manaToTap.forEach(manaId => { + this.tapCard(manaId); + }); + } // And continue with whatever we were doing return true; diff --git a/public/debug.js b/public/debug.js index 327f37d..98a97ca 100644 --- a/public/debug.js +++ b/public/debug.js @@ -87,7 +87,7 @@ function debugTriggerFunction(targetId = null, trigger = null, triggerAmount = n triggerTap(targetId); } if(trigger == 'pay'){ - triggerPay(targetId, triggerAmount); + triggerPay(triggerAmount); } } diff --git a/public/effect.js b/public/effect.js index 509d270..f10c2c6 100644 --- a/public/effect.js +++ b/public/effect.js @@ -130,7 +130,7 @@ function hurt(hurtDamage, hurtTarget = null, hurtPlayer = null){ // When card has been actively tapped function triggerTap(card){ - if(!canTriggerTap(card)){ return false; } + if(canTriggerTap(card) == false){ return false; } board.tapCard(card); @@ -152,11 +152,29 @@ function canTriggerTap(card){ } // Pay the mana cost(s) to trigger event -function triggerPay(){ +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(){ +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; }