|
|
|
|
@ -4,22 +4,12 @@ const database = require('./database');
|
|
|
|
|
const util = require('util')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// cardClass, cardColourRequirement
|
|
|
|
|
// may want to be seperate too (as well as in cardItem), so that
|
|
|
|
|
// during match they can be altered by effects while keeping the OG card
|
|
|
|
|
// for inspecting (and compare against new stats,reqs,etc.)
|
|
|
|
|
// same with attack, cost, etc. things that will can be visually shown as
|
|
|
|
|
// changed in game
|
|
|
|
|
|
|
|
|
|
// Just grabbing everything from DB for now, as it's quite small at current
|
|
|
|
|
// then will rejig when needed.
|
|
|
|
|
// Should all cards, effects, classes etc. be loaded in on server start
|
|
|
|
|
// then just load decks and decklists when needed?
|
|
|
|
|
// Get the decks requested
|
|
|
|
|
function getDecks(deckIds = false){
|
|
|
|
|
// Await promise, once it's done get the data, if errors send err
|
|
|
|
|
const dPromise = new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
|
|
database.dbGetDecks().then(data => {
|
|
|
|
|
database.dbGetDecks(deckIds).then(data => {
|
|
|
|
|
|
|
|
|
|
let decks = [];
|
|
|
|
|
|
|
|
|
|
@ -48,10 +38,10 @@ function getDecks(deckIds = false){
|
|
|
|
|
return dPromise;
|
|
|
|
|
}
|
|
|
|
|
//getDecks();
|
|
|
|
|
function getDeckList(){
|
|
|
|
|
function getDeckList(deckIds = false){
|
|
|
|
|
const dPromise = new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
|
|
database.dbGetDeckList().then(data => {
|
|
|
|
|
database.dbGetDeckList(deckIds).then(data => {
|
|
|
|
|
|
|
|
|
|
let deckList = [];
|
|
|
|
|
|
|
|
|
|
@ -70,11 +60,10 @@ function getDeckList(){
|
|
|
|
|
});
|
|
|
|
|
return dPromise;
|
|
|
|
|
}
|
|
|
|
|
//getDeckList();
|
|
|
|
|
function getCards(){
|
|
|
|
|
function getCards(cardIds = false){
|
|
|
|
|
const dPromise = new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
|
|
database.dbGetCards().then(data => {
|
|
|
|
|
database.dbGetCards(cardIds).then(data => {
|
|
|
|
|
|
|
|
|
|
let cards = [];
|
|
|
|
|
|
|
|
|
|
@ -97,10 +86,9 @@ function getCards(){
|
|
|
|
|
});
|
|
|
|
|
return dPromise;
|
|
|
|
|
}
|
|
|
|
|
//getCards();
|
|
|
|
|
function getCardClasses(){
|
|
|
|
|
function getCardClasses(cardIds = false){
|
|
|
|
|
const dPromise = new Promise((resolve, reject) => {
|
|
|
|
|
database.dbGetCardClasses().then(data => {
|
|
|
|
|
database.dbGetCardClasses(cardIds).then(data => {
|
|
|
|
|
|
|
|
|
|
let cardClasses = [];
|
|
|
|
|
|
|
|
|
|
@ -118,10 +106,9 @@ function getCardClasses(){
|
|
|
|
|
});
|
|
|
|
|
return dPromise;
|
|
|
|
|
}
|
|
|
|
|
//getCardClasses();
|
|
|
|
|
function getCardColourRequirement(){
|
|
|
|
|
function getCardColourRequirement(cardIds = false){
|
|
|
|
|
const dPromise = new Promise((resolve, reject) => {
|
|
|
|
|
database.dbGetCardColourRequirement().then(data => {
|
|
|
|
|
database.dbGetCardColourRequirement(cardIds).then(data => {
|
|
|
|
|
|
|
|
|
|
let colourRequirements = [];
|
|
|
|
|
|
|
|
|
|
@ -141,9 +128,9 @@ function getCardColourRequirement(){
|
|
|
|
|
});
|
|
|
|
|
return dPromise;
|
|
|
|
|
}
|
|
|
|
|
function getCardManaColour(){
|
|
|
|
|
function getCardManaColour(cardIds = false){
|
|
|
|
|
const cPromise = new Promise((resolve, reject) => {
|
|
|
|
|
database.dbGetCardManaColour().then(data => {
|
|
|
|
|
database.dbGetCardManaColour(cardIds).then(data => {
|
|
|
|
|
|
|
|
|
|
let manaColours = [];
|
|
|
|
|
|
|
|
|
|
@ -274,25 +261,9 @@ function getCardPassive(){
|
|
|
|
|
return cPromise;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//getCardColourRequirement();
|
|
|
|
|
// Then effects which will have effects with parent triggers, and unit type checks
|
|
|
|
|
// colour checks, all sorts. So will be more difficult. Basic (flight, etc)
|
|
|
|
|
// shouldn't be too bad
|
|
|
|
|
// something like effect_basic, card_effect, effect_trigger, effect_requirement, effect_option
|
|
|
|
|
// effect_stage, effect_advanced, with advanced being an id with x triggers, triggers have
|
|
|
|
|
// x req, advanced as with x options, x stages to be able to fine-tune fancy stuff
|
|
|
|
|
// combining all other effects, units, cards, colours, etc. Will be a lot of though,
|
|
|
|
|
// but better than hard coding anything more than basic effects and effect check logic
|
|
|
|
|
// TODO: effect (as above)
|
|
|
|
|
|
|
|
|
|
// request a deck in the format CURRENTLY used in the game
|
|
|
|
|
// decks will likely be changed around
|
|
|
|
|
|
|
|
|
|
// https://www.geeksforgeeks.org/how-to-wait-for-multiple-promises-in-javascript/
|
|
|
|
|
// https://medium.com/@nikolozz/using-socket-io-with-async-await-13fa8c2dc9d9
|
|
|
|
|
// using last example
|
|
|
|
|
// TODO: When this is functionally working, need to split up into other func/modules
|
|
|
|
|
// such as: playerMod, cardMod, deckMod, miscMod ?
|
|
|
|
|
function requestDeck(itemData = null){
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
(async () => {
|
|
|
|
|
@ -300,53 +271,73 @@ function requestDeck(itemData = null){
|
|
|
|
|
// Get the deck(s) requested.
|
|
|
|
|
// Not 100% on how to do two differening atm
|
|
|
|
|
// Besides all of playerId, and all of deckId. But 1,2/2,3 for instance
|
|
|
|
|
|
|
|
|
|
// Build array of decks to get
|
|
|
|
|
let deckIds = [];
|
|
|
|
|
for(let i = 0; i < itemData.players.length; i++){
|
|
|
|
|
let deckStuff = itemData.players[i][1].deck;
|
|
|
|
|
deckIds.push([deckStuff.playerId, deckStuff.deckId]);
|
|
|
|
|
// So should be array of [playerId, deckId] which is primary key in DB
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get said decks, and their deckLists
|
|
|
|
|
const [decks, deckList] =
|
|
|
|
|
await Promise.all([
|
|
|
|
|
getDecks(),
|
|
|
|
|
getDeckList()
|
|
|
|
|
getDecks(deckIds),
|
|
|
|
|
getDeckList(deckIds)
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
//console.log(decks);
|
|
|
|
|
//console.log(deckList);
|
|
|
|
|
/*
|
|
|
|
|
console.log('--- decks ---');
|
|
|
|
|
console.log(decks);
|
|
|
|
|
console.log('= deckLists =')
|
|
|
|
|
console.log(deckList);
|
|
|
|
|
console.log('------');
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Now loop the deckList for the cardIds
|
|
|
|
|
let deckCardIds = [];
|
|
|
|
|
deckList.forEach((deckItem) => {
|
|
|
|
|
deckCardIds.push(deckItem.cardId);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
//console.log(deckCardIds);
|
|
|
|
|
|
|
|
|
|
// Next, get the cards in the deck by their ID
|
|
|
|
|
// TODO: https://stackoverflow.com/a/65510676
|
|
|
|
|
// Change SQL to accept for just the cards passed
|
|
|
|
|
|
|
|
|
|
// Get each cards data, colourReqs, and classes
|
|
|
|
|
const [cards, cardClasses, cardColourRequirements, cardManaColours, cardPassives] =
|
|
|
|
|
await Promise.all([
|
|
|
|
|
getCards(),
|
|
|
|
|
getCardClasses(),
|
|
|
|
|
getCardColourRequirement(),
|
|
|
|
|
getCardManaColour(),
|
|
|
|
|
getCardPassive(),
|
|
|
|
|
getCards(deckCardIds),
|
|
|
|
|
getCardClasses(deckCardIds),
|
|
|
|
|
getCardColourRequirement(deckCardIds),
|
|
|
|
|
getCardManaColour(deckCardIds),
|
|
|
|
|
getCardPassive(deckCardIds),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// ^^^^ Classes async? Can pass the cardsIds, then loop classes, if the class cardId
|
|
|
|
|
// matches the cardId in cards[] then push the class to cards[x].classes
|
|
|
|
|
// Return all effect data from DB
|
|
|
|
|
const [effects] =
|
|
|
|
|
await Promise.all([
|
|
|
|
|
database.dbGetEffect(deckCardIds), // Get effects
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// TODO: Build the card so far async for it's done alongside getting effects?
|
|
|
|
|
// Then when both done add the effects to the existing cardObjects? Yep good idea me
|
|
|
|
|
//console.log(cards);
|
|
|
|
|
//console.info(cardClasses);
|
|
|
|
|
//console.log(cardColourRequirements);
|
|
|
|
|
// Loop the effects for their effectIds to then get the steps/triggers from DB
|
|
|
|
|
let effectIds = [];
|
|
|
|
|
await effects.forEach((effect) => {
|
|
|
|
|
effectIds.push(effect.effectId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Return all effect data from DB
|
|
|
|
|
const [effects, effectSteps, effectTriggers] =
|
|
|
|
|
// Then pass the effectIds to get their steps/triggers
|
|
|
|
|
const [effectSteps, effectTriggers] =
|
|
|
|
|
await Promise.all([
|
|
|
|
|
database.dbGetEffect(),
|
|
|
|
|
database.dbGetEffectStep(),
|
|
|
|
|
database.dbGetEffectTrigger(),
|
|
|
|
|
database.dbGetEffectStep(effectIds),
|
|
|
|
|
database.dbGetEffectTrigger(effectIds),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
console.log('--- Effects ---');
|
|
|
|
|
console.log(effects);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Build Effects
|
|
|
|
|
const [cardEffects] =
|
|
|
|
|
await Promise.all([
|
|
|
|
|
@ -460,6 +451,8 @@ function requestDeck(itemData = null){
|
|
|
|
|
|
|
|
|
|
// For each new card, loop to the cardCount (how many cards in deck)
|
|
|
|
|
// and add to the deck
|
|
|
|
|
// TODO: Associate player to deck differently (both could be using same deck
|
|
|
|
|
// via some kind of 'try a deck' or 'use friends deck' option)
|
|
|
|
|
for(let i = 0; i < deckListItem.cardCount; i++){
|
|
|
|
|
item.push(itemCount); // Add new item to add stuff for
|
|
|
|
|
// ^ not using item.length incase anything in future gets deleted
|
|
|
|
|
|