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.
cardGame/roomMod.js

70 lines
2.1 KiB
JavaScript

// Build a room, fill will players, etc.
const cardGen = require('./cardGen');
// Room should, setPlayers, add them to correct team (TODO), build their decks, and first shuffle
function startItemCount(){
let item = [];
let itemCount = 0;
returns = {'item': item, 'itemCount': itemCount};
return(returns);
}
function setPlayers(playerCount = 2, itemData){
// Add new item attribute for 'players'
// TODO: Maybe check if exists, and add to in that case (for replacing people?)
// Doubt that would ever make it into the game, but could still be worth
itemData.player = {}; //let player = {}; // Player item belongs to
itemData.players = []; // List of the players (an associated playerItem?)
//itemData.
// Can be done with just referring to itemData[x], but less readable
// Will likely redefine vars each new function. For now will keep this as-is
let playerNo = 0 + itemData['itemCount']; // Start loop from current itemCount
playerCount = playerCount + itemData['itemCount']; // End at playerCount diff from itemCount
for(playerNo; playerNo < playerCount; playerNo++){
itemData['item'].push(playerNo);
itemData['player'][itemData['itemCount']] = playerNo; // The player belongs to itself
itemData['itemCount']++;
itemData['players'].push(playerNo); // Add player no to array so can be looped
}
// Return related item and item attributes
//returns = {'item': item, 'itemCount': itemCount, 'player': player};
return itemData;
//return([item, itemCount, player]);
}
// For future, when 2v2s, and 5v1 Raids, etc.
function setTeams(){
}
function roomGeneration(playerCount, teamCount = null, playerTeams = null){
return new Promise((resolve, reject) => {
(async () => {
let itemData = startItemCount();
// Create 2 players for the room
itemData = setPlayers(2, itemData);
// TODO: Get their selected decks (will need to pass somewhere)
// Generate the decks, and card within the deck cardLists
[itemData] = await Promise.all([ cardGen.requestDeck(itemData) ]);
//console.log('deckData');
//console.log(deckData);
return resolve(itemData);
})()
});
}
module.exports = {
startItemCount
,setPlayers
,roomGeneration
};