You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
3.8 KiB
JavaScript
134 lines
3.8 KiB
JavaScript
// Any socket request/responses for the actual game (when in a match)
|
|
|
|
// PASS TURN
|
|
function requestPassTurn(){
|
|
console.log('>> passTurn');
|
|
socket.emit('passTurn', gameData.roomId, gameData.playerId);
|
|
}
|
|
socket.on('responsePassTurn', function (data) {
|
|
console.log('<< passTurn');
|
|
// Set turn data for clients (bolds their name)
|
|
updateTurn(data.turn, data.playerTurn);
|
|
drawGameBoard();
|
|
});
|
|
|
|
|
|
// DRAW A CARD
|
|
function requestDrawACard(){
|
|
console.log('>> drawACard');
|
|
socket.emit('drawACard', gameData.roomId, gameData.playerId);
|
|
}
|
|
// Both players get new hand + deck counts updated
|
|
socket.on('responseDrawCard', function (data) {
|
|
console.log('<< drawCard');
|
|
updateCardCount(data);
|
|
drawGameBoard();
|
|
});
|
|
socket.on('responseCardCounts', function (data) {
|
|
console.log('<< responseCardCounts');
|
|
updateCardCount(data);
|
|
drawGameBoard();
|
|
});
|
|
|
|
|
|
// Player drew card
|
|
// Player that drew the card (atm) gets the cardData, listPosition
|
|
// TODO: related attack, cost, effects, etc.
|
|
socket.on('responsePlayerDrewCard', function (data) {
|
|
console.log('<< playerDrewCard');
|
|
updatePlayerHand(data);
|
|
drawGameBoard();
|
|
});
|
|
|
|
|
|
socket.on('responseUpdateBoard', function (data) {
|
|
console.log('<< updateBoard');
|
|
updateBoard(data);
|
|
drawGameBoard();
|
|
});
|
|
|
|
// SHUFFLE DECK
|
|
function requestShuffleDeck(){
|
|
console.log('>> shuffleDeck');
|
|
socket.emit('shuffleDeck', gameData.roomId, gameData.playerId);
|
|
}
|
|
// Both players get an emit that the deck has been shuffled
|
|
// but do not recieve any other data (not needed)
|
|
// Only need to know a deck has been shuffled to perform animation in future
|
|
socket.on('responseShuffleDeck', function (data) {
|
|
console.log('<< shuffleDeck');
|
|
alert(data[0] + ' shuffled');
|
|
// TODO
|
|
// animateDeckShuffle(playerX from data);
|
|
// drawGameBoard(); // From this point drawGameBoard should be a 60FPS loop
|
|
// not a one off draw after emits
|
|
});
|
|
|
|
function requestPlayFromHand(listPosition){
|
|
console.log('>> playFromHand');
|
|
socket.emit('playFromHand', gameData.roomId, gameData.playerId, listPosition);
|
|
}
|
|
socket.on('responsePlayFromHand', function (data) {
|
|
// Return boardData, update hand
|
|
console.log('<< playFromHand');
|
|
console.log(data);
|
|
});
|
|
function requestPlayManaFromHand(listPosition){
|
|
console.log('>> playManaFromHand');
|
|
socket.emit('playManaFromHand', gameData.roomId, gameData.playerId, listPosition);
|
|
}
|
|
socket.on('responseUpdateMana', function (data) {
|
|
// Return boardData, update hand
|
|
console.log('<< updateMana');
|
|
console.log(data);
|
|
updateMana(data);
|
|
drawGameBoard();
|
|
});
|
|
|
|
socket.on('responsePlayedShield', function (data) {
|
|
// The playerId that played it for animations
|
|
console.log('<< playedShield');
|
|
drawGameBoard();
|
|
});
|
|
socket.on('responseUpdateShield', function (data) {
|
|
console.log('<< updateShield');
|
|
console.log(data);
|
|
updateShield(data);
|
|
});
|
|
|
|
// Stack
|
|
socket.on('responseAddToStack', function (data) {
|
|
console.log('<< addToStack');
|
|
console.log(data);
|
|
});
|
|
socket.on('responseResolveStack', function (data) {
|
|
console.log('<< resolveStack _x_');
|
|
console.log(data);
|
|
drawGameBoard();
|
|
});
|
|
socket.on('responseRemoveFromStack', function (data) {
|
|
console.log('<< removeFromStack ?');
|
|
console.log(data);
|
|
});
|
|
// All players need to accept the stack 'resolve' before it'll occur
|
|
socket.on('responseGetStackResponse', function (data) {
|
|
// TODO: Return all valid effect triggers/responses to the effect trigger
|
|
// on the top of the stack, and a 'resolve' option to not trigger anything
|
|
console.log('<< getStackResponse');
|
|
updateStack(data);
|
|
});
|
|
function requestResolveStack(){
|
|
// This is just for 'resolve' press. Not playing atop the stack.
|
|
console.log('>> requestResolveStack');
|
|
socket.emit('requestResolveStack', gameData.roomId, gameData.playerId);
|
|
}
|
|
|
|
|
|
// Functions like this would be elsewhere, do client-side
|
|
// validation THEN request stuff from the server?
|
|
// This is here for now, as it's used by the button
|
|
function passTurn(){
|
|
requestPassTurn();
|
|
}
|
|
|