WIP: Actual effect check/doing

Needs lots of work, perhaps splitting into a function per step to
prevent loops, etc in case of chains, and counterspells, etc.
develop
Nathan Steel 1 year ago
parent 4fb1a2694d
commit 6a6c9ffb83

@ -160,13 +160,24 @@ function debugEffectCanTrigger(){
let ecTriggerIndex = document.getElementById("ecTriggerIndex").value;
if(ecTriggerIndex == ""){ ecTriggerIndex = 0; }
if(triggerEffect(ecTriggerTargetId, ecTriggerIndex, true) != true){
let ecDoTrigger = document.getElementById("ecDoTrigger").value;
if(ecDoTrigger == ""){ ecDoTrigger = 0; }
if(doEffectTriggers(ecTriggerTargetId, ecTriggerIndex, true) != true){
console.log('Effect cannot be triggered');
doEffect(ecTriggerTargetId, ecTriggerIndex, 1);
return false;
}
console.log('Effect CAN be triggered');
triggerEffect(ecTriggerTargetId, ecTriggerIndex);
if(ecDoTrigger){
// Do everything needed in triggers
doEffectTriggers(ecTriggerTargetId, ecTriggerIndex);
// Then do the actual effects
doEffect(ecTriggerTargetId, ecTriggerIndex); // also step = 1,2,3
}
}

@ -195,7 +195,7 @@ function canTriggerPay(triggerAmount){
}
// Pay/Activate (all) the triggers
function triggerEffect(itemKey, effectIndex, checkOnly = false){
function doEffectTriggers(itemKey, effectIndex, checkOnly = false){
// Check card has effectData
let effectData = cardEffect[itemKey];
@ -266,3 +266,179 @@ function triggerEffect(itemKey, effectIndex, checkOnly = false){
}
function activateEffect(){
// Do effect triggers, then doEffect once payed
}
function getEffect(itemKey, effectIndex){
// 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
return effect;
}
// Get all the targets for effect step, so they can be targgeted
// by the effect/selected by the player
function getEffectStepTargets(itemKey, effectIndex, effectStep, fromBoardElement, playerId){
// Get Effect
let effect = getEffect(itemKey, effectIndex);
if(effect == false){ return false; }
// Get the step
let step = effect['step'][effectStep];
if(step == undefined){ return false; }
// The items that can be targetted with the effectStep
let itemsToSelectFrom = [];
// Loop the target location (or all locations)
// Check which cards meet the criteria in the DB
// 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
// If itemFromStep, return the itemKeys of the items selected from a previous step
/*
if(target['itemFromStep'] == null){
// So something from step 1 needs to be selected by this.
}
*/
// 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++){
// TODO: MAYBE ADD THE COLOUR/PASSIVE CHECKS to the getItems itself
let itemKey = items[item];
console.log(cardColours[itemKey]);
// If the item from getItems meets the criterias of target DB
step['target'].forEach((target) => {
// Check the class the same for target, and item
// If targetDB has null this means 'any' so is always correct
// Check Class (TODO: mixed classes, colours, etc ie select 1 red+blue card)
/*
if(class[itemKey] == target['classId'] || target['classId'] == null){
}
*/
// Check colour
// If not null check the colours, otherwise null means any colour is ok
if(target['colourId'] !== null){
// Check the colours to see if one is of requirement
cardColours[itemKey].forEach((colour) => {
// If the colour doesn't match, continue to next target (forEach)
if(colour[0] != target['colourId']){
// The return below is just a 'continue' in forEach terms
return; // forEach jank. forEach executes the 'function' 'target' each loop
}
// If the colour is correct, keep checking requirements
});
}
// Check passive (If hasPassive(id))
/*
if(cardColours[itemKey] == target['passiveId'] || target['passiveId'] == null){
}
*/
/*
if(cardType[itemKey] == target['typeId'] || target['typeId'] == null){
}
*/
// Once all the target Req. have been checked against the item
// and they match, add to selectable list
itemsToSelectFrom.push(itemKey);
});
}
return itemsToSelectFrom;
}
// Recusively call doEffect until each is done?
// Once recruit (play from hand) is triggered, need to allow user to select
// then when done move to next step
function doEffect(itemKey, effectIndex, effectStep = 1){
let effect = getEffect(itemKey, effectIndex);
if(effect == false){ return false; }
// Get the step
let step = effect['step'][effectStep];
if(step == undefined){ return false; }
// For each step, activate the correct effect type on
// the correct targets.
switch (step['basicEffectId']){
// Recruit
case 4:
recruitCard(itemKey, effectIndex, effectStep, step['amount']);
break;
// Give Flight
case 5:
console.log('GIVE FLIGHT');
break;
}
// Now do the next step, if there's another in the effect
if(effect['step'][effectStep++] !== undefined){
doEffect(itemKey, effectIndex, effectStep++);
}
}
function recruitCard(itemKey, effectIndex, effectStep, targetAmount){
console.log('RECRUIT');
let fromBoardElement = 'hand'; // FOR NOW, JUST TO TEST, THIS WILL BE PER BASIC EFFECT
let playerId = 0;
let targets = getEffectStepTargets(itemKey, effectIndex, effectStep, fromBoardElement, playerId);
console.log(targets);
if(targetAmount > 0 && targets.length > 0){
let selectedTarget = prompt("Select a card to recruit: \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)
if (!selectedTarget.includes(selectedTarget)){
alert('Not in selection');
return false;
}
// Remove the card from the selection
targets.splice(targets.indexOf(selectedTarget), 1);
// Play recruited card
// TODO: Maybe needs a new function 'playRecruitedCard' for different event triggers
board.playCardToBoard(listPosition[itemKey], boardElement[itemKey], 'board', 0, 0, 1);
}
}

@ -107,6 +107,10 @@
<input type="text" placeholder="targetId" id="ecTriggerTargetId">
<input type="text" placeholder="effectIndex" id="ecTriggerIndex">
<select id="ecDoTrigger">
<option value="0">Just Check</option>
<option value="1">Trigger Effect</option>
</select>
</div>

Loading…
Cancel
Save