|
|
|
@ -1,9 +1,22 @@
|
|
|
|
|
|
|
|
// Theorising, if this is what's wanted then will need doing for everything
|
|
|
|
|
|
|
|
// not just in effects. eg. 'attack', 'effect1p1', 'flip', yadda yadda
|
|
|
|
|
|
|
|
let triggerQueue = [];
|
|
|
|
|
|
|
|
let triggerId = 1; // So any other effects, etc. queued for a destroyed card can be removed at once
|
|
|
|
|
|
|
|
let triggerDone = []; // The triggers that have completed
|
|
|
|
|
|
|
|
let triggerQueueTargets = []; // Whatever was targetted by the effect, etc. in triggerQueue (for ref by effectStep, etc)
|
|
|
|
|
|
|
|
|
|
|
|
// Passive effects (just does stuff)
|
|
|
|
// Passive effects (just does stuff)
|
|
|
|
let flight = {};
|
|
|
|
let flight = {};
|
|
|
|
let reach = {};
|
|
|
|
let reach = {};
|
|
|
|
let equipped = {}; // Entity x has [a,b,c] equipped to it
|
|
|
|
let equipped = {}; // Entity x has [a,b,c] equipped to it
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Events (when these occur check if this is part of an effect trigger)
|
|
|
|
|
|
|
|
// startOfGame, startOfTurn, endOfTurn
|
|
|
|
|
|
|
|
// cardSummoned, cardRecruited, effectTriggered
|
|
|
|
|
|
|
|
// etc.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Trigger types
|
|
|
|
// Trigger types
|
|
|
|
const triggerTypes = {
|
|
|
|
const triggerTypes = {
|
|
|
|
'tap': 1,
|
|
|
|
'tap': 1,
|
|
|
|
@ -283,7 +296,7 @@ function getEffect(itemKey, effectIndex){
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Get all the targets for effect step, so they can be targgeted
|
|
|
|
// Get all the targets for effect step, so they can be targgeted
|
|
|
|
// by the effect/selected by the player
|
|
|
|
// by the effect/selected by the player
|
|
|
|
function getEffectStepTargets(itemKey, effectIndex, effectStep, fromBoardElement, playerId){
|
|
|
|
function getEffectStepTargets(itemKey, effectIndex, effectStep, fromBoardElement, playerId, effectTriggerId = null){
|
|
|
|
|
|
|
|
|
|
|
|
// Get Effect
|
|
|
|
// Get Effect
|
|
|
|
let effect = getEffect(itemKey, effectIndex);
|
|
|
|
let effect = getEffect(itemKey, effectIndex);
|
|
|
|
@ -303,24 +316,71 @@ function getEffectStepTargets(itemKey, effectIndex, effectStep, fromBoardElement
|
|
|
|
// TODO: Not 100% sure how to keep track. May need a var for each item in previous steps
|
|
|
|
// TODO: Not 100% sure how to keep track. May need a var for each item in previous steps
|
|
|
|
// or previous chains so they can be accessed, and used
|
|
|
|
// or previous chains so they can be accessed, and used
|
|
|
|
// If itemFromStep, return the itemKeys of the items selected from a previous step
|
|
|
|
// If itemFromStep, return the itemKeys of the items selected from a previous step
|
|
|
|
/*
|
|
|
|
|
|
|
|
if(target['itemFromStep'] == null){
|
|
|
|
console.log('HELLOO');
|
|
|
|
// So something from step 1 needs to be selected by this.
|
|
|
|
console.log(step['target']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: If target is 'itemFromStep', then get whatever item(s) were selected in
|
|
|
|
|
|
|
|
// said step, and add them to the thing
|
|
|
|
|
|
|
|
// TODO TODO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the target requirement is something from a previous step
|
|
|
|
|
|
|
|
// Check if target criteria is something from another step
|
|
|
|
|
|
|
|
let isFromStep = false;
|
|
|
|
|
|
|
|
step['target'].forEach((target) => {
|
|
|
|
|
|
|
|
if(target['itemFromStep'] != null){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(target['itemFromStep']);
|
|
|
|
|
|
|
|
console.log(effectTriggerId);
|
|
|
|
|
|
|
|
//console.log(triggerQueue);
|
|
|
|
|
|
|
|
//console.log(triggerDone);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Loop all triggers that have been done (completed)
|
|
|
|
|
|
|
|
triggerDone.forEach((oldTrigger) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If not same triggerId, or the effectStep is not that of itemFromStep
|
|
|
|
|
|
|
|
if(oldTrigger['triggerId'] != effectTriggerId || target['itemFromStep'] != oldTrigger['effectStep']){
|
|
|
|
|
|
|
|
return isFromStep = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(oldTrigger);
|
|
|
|
|
|
|
|
return isFromStep = oldTrigger['targets'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// If above returns a step, need to get the target(s) from that prior step to use a targets now
|
|
|
|
|
|
|
|
if(isFromStep){
|
|
|
|
|
|
|
|
console.log(isFromStep);
|
|
|
|
|
|
|
|
console.log('AAAAAAAAAAAAAAAAAAAAAA');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let items = [];
|
|
|
|
|
|
|
|
// If from a previous step, loop those
|
|
|
|
|
|
|
|
if(isFromStep !== null && isFromStep !== undefined && isFromStep !== false){ items = isFromStep; }
|
|
|
|
|
|
|
|
// If not, get all the related doodads
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
items = board.getItems(fromBoardElement, playerId, null, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Loop the boardlements and compare the colours, classes, etc. to match effect target criteria
|
|
|
|
// boardElement, playerId, cardStatus, listPosition
|
|
|
|
// boardElement, playerId, cardStatus, listPosition
|
|
|
|
let items = board.getItems(fromBoardElement, playerId, null, null); // TODO: maybe 'from top of deck, or if tapped'
|
|
|
|
|
|
|
|
for(let item = 0; item < items.length; item++){
|
|
|
|
for(let item = 0; item < items.length; item++){
|
|
|
|
// TODO: MAYBE ADD THE COLOUR/PASSIVE CHECKS to the getItems itself
|
|
|
|
// TODO: MAYBE ADD THE COLOUR/PASSIVE CHECKS to the getItems itself
|
|
|
|
|
|
|
|
|
|
|
|
let itemKey = items[item];
|
|
|
|
let itemKey = items[item];
|
|
|
|
console.log(cardColours[itemKey]);
|
|
|
|
//console.log(cardColours[itemKey]);
|
|
|
|
|
|
|
|
|
|
|
|
// If the item from getItems meets the criterias of target DB
|
|
|
|
// If the item from getItems meets the criterias of target DB
|
|
|
|
step['target'].forEach((target) => {
|
|
|
|
step['target'].forEach((target) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//console.log(target);
|
|
|
|
|
|
|
|
//console.log(triggerDone);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check the class the same for target, and item
|
|
|
|
// Check the class the same for target, and item
|
|
|
|
// If targetDB has null this means 'any' so is always correct
|
|
|
|
// If targetDB has null this means 'any' so is always correct
|
|
|
|
// Check Class (TODO: mixed classes, colours, etc ie select 1 red+blue card)
|
|
|
|
// Check Class (TODO: mixed classes, colours, etc ie select 1 red+blue card)
|
|
|
|
@ -370,11 +430,102 @@ function getEffectStepTargets(itemKey, effectIndex, effectStep, fromBoardElement
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function addTargettedCardsToQueueEvent(queueTriggerId, triggerStep, targets){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('ADD TARGETTED TO QUEUED TRIGGER');
|
|
|
|
|
|
|
|
console.log(queueTriggerId);
|
|
|
|
|
|
|
|
console.log(triggerStep);
|
|
|
|
|
|
|
|
console.log(targets);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//console.log(triggerQueue[queueTriggerId]);
|
|
|
|
|
|
|
|
//console.log(targets);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(triggerQueue);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
triggerQueue.forEach((queued) => {
|
|
|
|
|
|
|
|
console.log(queued);
|
|
|
|
|
|
|
|
if(
|
|
|
|
|
|
|
|
queued.triggerId == queueTriggerId
|
|
|
|
|
|
|
|
&&
|
|
|
|
|
|
|
|
queued.effectStep == triggerStep
|
|
|
|
|
|
|
|
){
|
|
|
|
|
|
|
|
console.log('THIS SHOULD HAVE TARGETS ADDED');
|
|
|
|
|
|
|
|
queued['targets'] = targets;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(triggerQueue);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function queueEffect(itemKey, effectIndex){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let effect = getEffect(itemKey, effectIndex);
|
|
|
|
|
|
|
|
if(effect == false){ return false; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Sort steps by stepOrder incase wrong in DB, etc.
|
|
|
|
|
|
|
|
for (const [stepKey, step] of Object.entries(effect['step'])) {
|
|
|
|
|
|
|
|
triggerQueue.push(
|
|
|
|
|
|
|
|
// event, item, effectId, target, triggerId (commented atop)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
'event': 'effect' // Which event. attack, destroy, effect, etc.
|
|
|
|
|
|
|
|
,'item': itemKey // Which card is doing event
|
|
|
|
|
|
|
|
,'effectIndex': effectIndex // Which effect (if effect)
|
|
|
|
|
|
|
|
,'effectStep': stepKey // Which effect (if effect)
|
|
|
|
|
|
|
|
,'target': null // ?
|
|
|
|
|
|
|
|
,'triggerId': triggerId
|
|
|
|
|
|
|
|
,'targets': null // ?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Increment triggerId
|
|
|
|
|
|
|
|
triggerId++;
|
|
|
|
|
|
|
|
console.log(triggerQueue);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function doNextInQueue(){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(triggerQueue.length <= 0){
|
|
|
|
|
|
|
|
console.log('Nothing in queue, doing next phase/event/whatever');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If effect, trigger it (should already have paid the trigger costs)
|
|
|
|
|
|
|
|
switch(triggerQueue[0].event){
|
|
|
|
|
|
|
|
case 'effect':
|
|
|
|
|
|
|
|
// Do the effect
|
|
|
|
|
|
|
|
doEffect(triggerQueue[0].item, triggerQueue[0].effectIndex, triggerQueue[0].effectStep, triggerQueue[0].triggerId);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
alert('Error in doNextInQueue');
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add to completed triggers
|
|
|
|
|
|
|
|
triggerDone.push(triggerQueue[0]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// And remove from the triggerQueue (first index)
|
|
|
|
|
|
|
|
triggerQueue.shift();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function loopTriggerQueue(){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(triggerQueue.length > 0){
|
|
|
|
|
|
|
|
doNextInQueue();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Recusively call doEffect until each is done?
|
|
|
|
// Recusively call doEffect until each is done?
|
|
|
|
// Once recruit (play from hand) is triggered, need to allow user to select
|
|
|
|
// Once recruit (play from hand) is triggered, need to allow user to select
|
|
|
|
// then when done move to next step
|
|
|
|
// then when done move to next step
|
|
|
|
function doEffect(itemKey, effectIndex, effectStep = 1){
|
|
|
|
function doEffect(itemKey, effectIndex, effectStep, effectTriggerId){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('doEffect');
|
|
|
|
|
|
|
|
|
|
|
|
let effect = getEffect(itemKey, effectIndex);
|
|
|
|
let effect = getEffect(itemKey, effectIndex);
|
|
|
|
if(effect == false){ return false; }
|
|
|
|
if(effect == false){ return false; }
|
|
|
|
@ -387,34 +538,97 @@ function doEffect(itemKey, effectIndex, effectStep = 1){
|
|
|
|
// For each step, activate the correct effect type on
|
|
|
|
// For each step, activate the correct effect type on
|
|
|
|
// the correct targets.
|
|
|
|
// the correct targets.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get targets TODO: Use this instead of each case having it
|
|
|
|
|
|
|
|
//let targets = getEffectStepTargets(itemKey, effectIndex, effectStep, fromBoardElement, playerId, effectTriggerId);
|
|
|
|
|
|
|
|
|
|
|
|
switch (step['basicEffectId']){
|
|
|
|
switch (step['basicEffectId']){
|
|
|
|
|
|
|
|
|
|
|
|
// Recruit
|
|
|
|
// Recruit
|
|
|
|
case 4:
|
|
|
|
case 4:
|
|
|
|
recruitCard(itemKey, effectIndex, effectStep, step['amount']);
|
|
|
|
recruitCard(itemKey, effectIndex, effectStep, step['amount'], effectTriggerId);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// Give Flight
|
|
|
|
// Give Flight
|
|
|
|
case 5:
|
|
|
|
case 5:
|
|
|
|
console.log('GIVE FLIGHT');
|
|
|
|
givePassive(itemKey, effectIndex, effectStep, step['amount'], effectTriggerId, 'flight');
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add the selected targets to the queuedItem so it can be referred to in future
|
|
|
|
|
|
|
|
|
|
|
|
// Now do the next step, if there's another in the effect
|
|
|
|
// Now do the next step, if there's another in the effect
|
|
|
|
|
|
|
|
// Commented out while testing triggerQueue
|
|
|
|
|
|
|
|
/*
|
|
|
|
if(effect['step'][effectStep++] !== undefined){
|
|
|
|
if(effect['step'][effectStep++] !== undefined){
|
|
|
|
doEffect(itemKey, effectIndex, effectStep++);
|
|
|
|
doEffect(itemKey, effectIndex, effectStep++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function givePassive(itemKey, effectIndex, effectStep, targetAmount, effectTriggerId, passive){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('GIVE PASSIVE: '+passive);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let effect = getEffect(itemKey, effectIndex);
|
|
|
|
|
|
|
|
if(effect == false){ return false; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get the step
|
|
|
|
|
|
|
|
let step = effect['step'][effectStep];
|
|
|
|
|
|
|
|
if(step == undefined){ return false; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(step);
|
|
|
|
|
|
|
|
//return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: null, 0 are boardElement/playerId (for now) need to redo, rethink
|
|
|
|
|
|
|
|
console.log('HELP ME');
|
|
|
|
|
|
|
|
let targets = getEffectStepTargets(itemKey, effectIndex, effectStep, null, 0, effectTriggerId);
|
|
|
|
|
|
|
|
console.log(targets);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(targetAmount > 0 && targets.length > 0){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: better, and if just one thing omit, and do automatically
|
|
|
|
|
|
|
|
let selectedTarget = prompt("Select a card to gain flight: \n"+targets, targets[0]);
|
|
|
|
|
|
|
|
// User didn't select anything
|
|
|
|
|
|
|
|
if (selectedTarget == null || selectedTarget == "") {
|
|
|
|
|
|
|
|
alert('No card recruited, c ya');
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// User inputted card not in ID (obv temp, as will be done in game UI)
|
|
|
|
|
|
|
|
// Huh I forgot why this is written like this, maybe it doens't work?
|
|
|
|
|
|
|
|
if (!selectedTarget.includes(selectedTarget)){
|
|
|
|
|
|
|
|
alert('Not in selection');
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove the card from the selection (in case there's another in this loop)
|
|
|
|
|
|
|
|
targets.splice(targets.indexOf(selectedTarget), 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Give the passive
|
|
|
|
|
|
|
|
if(passive == 'flight'){
|
|
|
|
|
|
|
|
giveFlight(selectedTarget);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function recruitCard(itemKey, effectIndex, effectStep, targetAmount){
|
|
|
|
function removePassive(){}
|
|
|
|
|
|
|
|
function hasPassive(){}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function recruitCard(itemKey, effectIndex, effectStep, targetAmount, effectTriggerId = null){
|
|
|
|
console.log('RECRUIT');
|
|
|
|
console.log('RECRUIT');
|
|
|
|
|
|
|
|
|
|
|
|
let fromBoardElement = 'hand'; // FOR NOW, JUST TO TEST, THIS WILL BE PER BASIC EFFECT
|
|
|
|
let fromBoardElement = 'hand'; // FOR NOW, JUST TO TEST, THIS WILL BE PER BASIC EFFECT
|
|
|
|
let playerId = 0;
|
|
|
|
let playerId = 0;
|
|
|
|
|
|
|
|
|
|
|
|
let targets = getEffectStepTargets(itemKey, effectIndex, effectStep, fromBoardElement, playerId);
|
|
|
|
let targets = getEffectStepTargets(itemKey, effectIndex, effectStep, fromBoardElement, playerId, effectTriggerId);
|
|
|
|
console.log(targets);
|
|
|
|
let targettedCards = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//console.log(targets);
|
|
|
|
|
|
|
|
|
|
|
|
if(targetAmount > 0 && targets.length > 0){
|
|
|
|
if(targetAmount > 0 && targets.length > 0){
|
|
|
|
|
|
|
|
|
|
|
|
@ -430,15 +644,19 @@ function recruitCard(itemKey, effectIndex, effectStep, targetAmount){
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Remove the card from the selection
|
|
|
|
// Remove the card from the selection (in case there's another)
|
|
|
|
targets.splice(targets.indexOf(selectedTarget), 1);
|
|
|
|
targets.splice(targets.indexOf(selectedTarget), 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add to targetted (for future ref)
|
|
|
|
|
|
|
|
targettedCards.push(selectedTarget);
|
|
|
|
|
|
|
|
|
|
|
|
// Play recruited card
|
|
|
|
// Play recruited card
|
|
|
|
// TODO: Maybe needs a new function 'playRecruitedCard' for different event triggers
|
|
|
|
// TODO: Need to pass player/listPosition better?
|
|
|
|
board.playCardToBoard(listPosition[itemKey], boardElement[itemKey], 'board', 0, 0, 1);
|
|
|
|
board.playRecruitedCard(player[selectedTarget], listPosition[selectedTarget]);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addTargettedCardsToQueueEvent(effectTriggerId, effectStep, targettedCards);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|