|
|
|
|
@ -36,21 +36,37 @@ function setTeams(){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function roomGeneration(playerCount, teamCount = null, playerTeams = null){
|
|
|
|
|
function roomGeneration(roomId){
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
(async () => {
|
|
|
|
|
|
|
|
|
|
// Player's sockets
|
|
|
|
|
console.log('--- Room for generation ---');
|
|
|
|
|
console.log(io.sockets.adapter.rooms.get(roomId));
|
|
|
|
|
|
|
|
|
|
let itemData = startItemCount();
|
|
|
|
|
|
|
|
|
|
// This will be passed by the joinRoom for each player, then built
|
|
|
|
|
// on startGame)
|
|
|
|
|
// Need to make it work if they're the same deck too
|
|
|
|
|
let playerData = [
|
|
|
|
|
{'playerId': 1, 'deck':{'playerId':1,'deckId':1}},
|
|
|
|
|
{'playerId': 2, 'deck':{'playerId':2,'deckId':1}},
|
|
|
|
|
];
|
|
|
|
|
// Player data with Sockets
|
|
|
|
|
let playerData = [];
|
|
|
|
|
let i = 1;
|
|
|
|
|
let clients = global.io.sockets.adapter.rooms.get(roomId);
|
|
|
|
|
for (const clientId of clients) {
|
|
|
|
|
const clientSocket = global.io.sockets.sockets.get(clientId);
|
|
|
|
|
|
|
|
|
|
playerData.push({
|
|
|
|
|
'playerId': clientSocket.playerId
|
|
|
|
|
,'deck':{'playerId':i,'deckId':1}
|
|
|
|
|
,'socketId': clientSocket.id // TODO: ONLY FOR SERVERSIDE!!!
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test alert so that different data/emits can be sent per-player
|
|
|
|
|
global.io.to(playerData[0].socketId).emit('alert', {'message': 'roomMod.js test'});
|
|
|
|
|
|
|
|
|
|
// Add players for the room
|
|
|
|
|
|
|
|
|
|
// Add players for the room (seperate to playerData, currently what's used)
|
|
|
|
|
itemData = setPlayers(playerData, itemData);
|
|
|
|
|
|
|
|
|
|
// TODO: Get their selected decks
|
|
|
|
|
@ -61,8 +77,11 @@ function roomGeneration(playerCount, teamCount = null, playerTeams = null){
|
|
|
|
|
// Generate the decks, and card within the deck cardLists
|
|
|
|
|
[itemData] = await Promise.all([ cardGen.requestDeck(itemData) ]);
|
|
|
|
|
|
|
|
|
|
//console.log('deckData');
|
|
|
|
|
//console.log(deckData);
|
|
|
|
|
// Some room stuff, likely change this
|
|
|
|
|
itemData.roomId = roomId;
|
|
|
|
|
itemData.turn = 0; // The turn count of the match
|
|
|
|
|
itemData.playersTurn = 0; // This means it's playerData[0] turn
|
|
|
|
|
|
|
|
|
|
return resolve(itemData);
|
|
|
|
|
})()
|
|
|
|
|
});
|
|
|
|
|
|