|
|
|
|
@ -128,7 +128,10 @@ function playFromHand(roomId, playerId, position){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
playACardFromHand(roomId, playerId, cardId);
|
|
|
|
|
// Attempt to play the card from hand
|
|
|
|
|
if(!playACardFromHand(roomId, playerId, cardId)){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -140,18 +143,11 @@ function playACardFromHand(roomId, playerId, cardId){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the card can be played/had been
|
|
|
|
|
// Reduce handSize by 1 for the player that played the card
|
|
|
|
|
global.roomData[roomId].itemData.component.cardCount.hand[playerId]--;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Send a socket response for 'played a card from hand' with cardData
|
|
|
|
|
// of said card. This is sent so that it can be 'chained' and added to the stack
|
|
|
|
|
// On play, it is put onto field/activated but the effect(s) don't occur until both/all
|
|
|
|
|
// players have a chance to 'chain', once the 'chain' is completed, the effect(s) trigger
|
|
|
|
|
global.socketResponsePlayFromHand(roomId, playerId, cardId);
|
|
|
|
|
// TODO: Above can probably be the same/similar to what is added to the roomData on
|
|
|
|
|
// client-end (when it's fully done)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -180,12 +176,50 @@ function playACard(roomId, playerId, cardId, playedFrom){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hasSpaceOnBoard(roomId, playerId){
|
|
|
|
|
// TODO:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
function removeFromHand(roomId, playerId, cardId){
|
|
|
|
|
console.log('remove from hand');
|
|
|
|
|
if(cardId in global.roomData[roomId].itemData.component.hand){
|
|
|
|
|
delete(global.roomData[roomId].itemData.component.hand[cardId]);
|
|
|
|
|
}
|
|
|
|
|
global.roomData[roomId].itemData.component.cardCount.hand[playerId]--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function playAUnit(roomId, playerId, cardId, playedFrom){
|
|
|
|
|
|
|
|
|
|
console.log('playAUnit');
|
|
|
|
|
|
|
|
|
|
// TODO: Make work, AND allow to play to opponent board (in future)
|
|
|
|
|
if(hasSpaceOnBoard(roomId, playerId) !== true){
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Costs
|
|
|
|
|
|
|
|
|
|
if(playedFrom == 'hand'){
|
|
|
|
|
|
|
|
|
|
// Remove from hand
|
|
|
|
|
removeFromHand(roomId, playerId, cardId);
|
|
|
|
|
|
|
|
|
|
// Add unit to board
|
|
|
|
|
global.roomData[roomId].itemData.component.board[cardId] = cardId;
|
|
|
|
|
global.roomData[roomId].itemData.component.cardCount.board[playerId]++;
|
|
|
|
|
|
|
|
|
|
// Change list positions of hand and board
|
|
|
|
|
// Next position on board (using cardCount to determine here)
|
|
|
|
|
// From current position in hand (the listPosition of the entity at this current point)
|
|
|
|
|
gameHelper.setCardPosition(roomId, playerId, cardId, global.roomData[roomId].itemData.component.cardCount.board[playerId], global.roomData[roomId].itemData.component.board, global.roomData[roomId].itemData.component.listPosition[cardId], global.roomData[roomId].itemData.component.hand);
|
|
|
|
|
|
|
|
|
|
// TODO: unit onPlay effects to the stack
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add to board
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
function playASpell(roomId, playerId, cardId, playedFrom){
|
|
|
|
|
|
|
|
|
|
@ -196,14 +230,31 @@ function playASpell(roomId, playerId, cardId, playedFrom){
|
|
|
|
|
// TODO: If spell has different effects, select which one/ensure
|
|
|
|
|
// correct one is used based on criteria
|
|
|
|
|
|
|
|
|
|
if(playedFrom == 'hand'){
|
|
|
|
|
// Remove from hand
|
|
|
|
|
console.log(cardId);
|
|
|
|
|
console.log(global.roomData[roomId].itemData.component.hand);
|
|
|
|
|
|
|
|
|
|
// Remove from ahnd
|
|
|
|
|
removeFromHand(roomId, playerId, cardId);
|
|
|
|
|
// if Spell when it's final effect finished (or removed) from stack, it should get
|
|
|
|
|
// added to grave then
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If card was played, add its effect(s) to the stack
|
|
|
|
|
// If it should be added to stack (spell, or onPlay effect) do so
|
|
|
|
|
// Add to stack (each part of the spells effect)
|
|
|
|
|
// TODO: Use actual effects, for now just adding a 'drawCard' for testing
|
|
|
|
|
|
|
|
|
|
addToStack(roomId, playerId, cardId, null);
|
|
|
|
|
|
|
|
|
|
// Spell can/'has' been played
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
function playAToken(roomId, playerId, cardId, playedFrom){
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Not 100% sure how to implement the stack
|
|
|
|
|
@ -233,14 +284,52 @@ function addToStack(roomId, playerId, cardId, effectId){
|
|
|
|
|
|
|
|
|
|
console.log(global.roomData[roomId].itemData.component.stack);
|
|
|
|
|
|
|
|
|
|
// Send addToStack response to trigger any animations, etc.
|
|
|
|
|
global.socketResponseAddToStack(roomId);
|
|
|
|
|
|
|
|
|
|
// TODO: TEMP, this will need to wait for a 'resolve' accept from both players before the stack
|
|
|
|
|
// would trigger.
|
|
|
|
|
//resolveStack(roomId);
|
|
|
|
|
|
|
|
|
|
// TODO: Improve this, potentially drop out of function, and have a while stack > 0
|
|
|
|
|
// do the stack stuff. If it's <= 0 then other functionality is as normal
|
|
|
|
|
// Need to write a game loop for this rather than a
|
|
|
|
|
// nested function calling the getStackResponse.
|
|
|
|
|
getStackResponse(roomId);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getStackResponse(roomId){
|
|
|
|
|
|
|
|
|
|
// If there's something in the stack both/all players must accept to resolve
|
|
|
|
|
// and/or have a chance to play a counter/chain card/effect atop of the current
|
|
|
|
|
// top of the stack
|
|
|
|
|
|
|
|
|
|
// TODO: Opponent gets chance to chain first, then player
|
|
|
|
|
// if opponent chained, player gets to chain that chain first before stopping
|
|
|
|
|
// opponent double chaining
|
|
|
|
|
|
|
|
|
|
global.socketGetStackResponse(roomId);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function acceptResolveStack(roomId, playerId){
|
|
|
|
|
|
|
|
|
|
// TODO: Make so each player needs to accept
|
|
|
|
|
// with whoever is to counter getting to ability to chain first
|
|
|
|
|
|
|
|
|
|
// Once the player has resolved, the next player gets the option to chain/resolve
|
|
|
|
|
|
|
|
|
|
// If all players have resolved, then resolve the top of the stack
|
|
|
|
|
resolveStack(roomId);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resolveStack(roomId){
|
|
|
|
|
|
|
|
|
|
// Resolve the stack if all players have requested
|
|
|
|
|
// to resolve the stack, and not chain anything atop of it
|
|
|
|
|
|
|
|
|
|
// Does the next effect in the stack, if something
|
|
|
|
|
// is to chain onto the stack that would instead trigger
|
|
|
|
|
// 'addToStack' after paying any costs
|
|
|
|
|
@ -249,14 +338,25 @@ function resolveStack(roomId){
|
|
|
|
|
let stackLength = Object.keys(global.roomData[roomId].itemData.component.stack).length;
|
|
|
|
|
if(stackLength > 0){
|
|
|
|
|
|
|
|
|
|
// Send the 'resolve' response to room to trigger any animations, etc.
|
|
|
|
|
global.socketResponseResolveStack(roomId);
|
|
|
|
|
|
|
|
|
|
// Trigger the last (most recently added to) the stack effect
|
|
|
|
|
// THIS WILL NOW ACTUALLY CAST THE EFFECT STEP WITHOUT INTERRUPT
|
|
|
|
|
// While the stack is being resolved their are no counters/chains until
|
|
|
|
|
// the next stack action which players will get option to chain or not again
|
|
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
|
global.roomData[roomId].itemData.component.stack[stackLength]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let stackTrigger = global.roomData[roomId].itemData.component.stack[stackLength];
|
|
|
|
|
|
|
|
|
|
// TODO: actually trigger the correct effect, etc.
|
|
|
|
|
// check if targets, check validity, etc. then trigger
|
|
|
|
|
|
|
|
|
|
// TODO: Remove drawACard and use actual triggers/effects
|
|
|
|
|
drawACard(roomId, stackTrigger.targetPlayer);
|
|
|
|
|
|
|
|
|
|
// Once the effect atop the stack has triggered, remove it from the stack
|
|
|
|
|
delete(global.roomData[roomId].itemData.component.stack[stackLength]);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -336,6 +436,15 @@ function getPlayerHandData(roomId, playerId){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: This is here to prevent overwriting with less content when a draw happens.
|
|
|
|
|
// Will want reverting at some point (or other functions for returning only certain bits
|
|
|
|
|
// everywhere else should be written)
|
|
|
|
|
|
|
|
|
|
//handEntities = global.roomData[roomId].itemData.component.hand;
|
|
|
|
|
handPositions = global.roomData[roomId].itemData.component.listPosition;
|
|
|
|
|
handCardData = global.roomData[roomId].itemData.component.cardData;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
'handEntities': handEntities,
|
|
|
|
|
'handPositions': handPositions,
|
|
|
|
|
@ -351,5 +460,6 @@ module.exports = {
|
|
|
|
|
,drawACard
|
|
|
|
|
,shuffleDeck
|
|
|
|
|
,playFromHand
|
|
|
|
|
,acceptResolveStack
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|