|
|
|
@ -6,8 +6,8 @@ let equipped = {}; // Entity x has [a,b,c] equipped to it
|
|
|
|
|
|
|
|
|
|
|
|
// Trigger types
|
|
|
|
// Trigger types
|
|
|
|
const triggerTypes = {
|
|
|
|
const triggerTypes = {
|
|
|
|
1: 'Tap',
|
|
|
|
'tap': 1,
|
|
|
|
2: 'Pay',
|
|
|
|
'pay': 2,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
// Basic effects
|
|
|
|
// Basic effects
|
|
|
|
// TODO: Pull display name/description from DB?
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|