Add faux deckDB/array to add cards/decklists

develop
Nathan Steel 1 year ago
parent b2da688cf8
commit 79bd2da845

@ -158,6 +158,7 @@ class Board{
let colourId = cardData[itemKey].colour; let colourId = cardData[itemKey].colour;
if(colourId == 0){ fill = '#EEE'; } if(colourId == 0){ fill = '#EEE'; }
else if(colourId == 1){ fill = '#0033EE'; } else if(colourId == 1){ fill = '#0033EE'; }
else if(colourId == 2){ fill = '#ED344A'; }
}else{ }else{
fill = '#B0B0B0'; fill = '#B0B0B0';
} }
@ -541,7 +542,7 @@ class Board{
alert('Hand full '+elementLength+'/'+maxHandSize); alert('Hand full '+elementLength+'/'+maxHandSize);
return 0; return 0;
} }
this.addFromBoardElement(playerId, 0, 'deck', 'hand', null, null); this.addFromBoardElement(playerId, 1, 'deck', 'hand', null, null);
} }
} }
@ -841,12 +842,12 @@ let board = new Board;
// TODO: TEMP!! Replace soon // TODO: TEMP!! Replace soon
createDeck(); createDeck();
createDeckList(playerDeck, deckCount, 0); //createDeckList(playerDeck, deckCount, 0);
createDeckList(opponentDeck, deckCountOpponent, 1); //createDeckList(opponentDeck, deckCountOpponent, 1);
// Play 4 shield from top (0) of each players deck // Play 4 shield from top (0) of each players deck
for(let currentPlayer = 0; currentPlayer <= players-1; currentPlayer++){ for(let currentPlayer = 0; currentPlayer <= players-1; currentPlayer++){
board.playShield(0, 'deck', currentPlayer, 4); board.playShield(1, 'deck', currentPlayer, 4);
} }
board.drawBoard(true); board.drawBoard(true);
@ -1047,43 +1048,40 @@ function createDeck(){
itemCount++; itemCount++;
} }
console.log(item.length); // createDeckList will need to continue from here, not 0 // Loop again and create the deckLists
for(let i = 0; i < players; i++){
createDeckList(i);
}
} }
// TEMP: Create a deck of X different cards that can be drawn/played // TODO: USE DATABASE FOR THIS!!!
// for UI development, will be done on server and not shown to clients function createDeckList(playerId){
// TODO: Randomly create a deck from objects stored in file (for now) then DB // TODO:Create the deckList by loading the deckDB
// 3 of each card max, and likely one colour too for time being // For now pulling from a deckList array that uses a cardArray
function createDeckList(deck, deckCount, playerId){ let deckList = null;
let i = item.length; // Continue from the last item, don't overwrite if(playerId == 0){ deckList = deckListPlayer; }
deckCount = deckCount + i; if(playerId == 1){ deckList = deckListOpponent; }
for(i; i < deckCount; i++){
// Randomise colour
let colour = Math.floor(Math.random() * 2);
let effect = Math.floor(Math.random() * 5);
if(effect == 0){ effect = 'effect here'; } else{ effect = null }
for(let deckItem = 0; deckItem < deckList.length; deckItem++){
// Create new item for ECS
item.push(itemCount); item.push(itemCount);
// Set card data for new item
// Use the ID from the deckList of player, and return the card of that ID from cardList/DB
cardData[itemCount] = cardArray[deckList[deckItem]];
// Set to base position of 'deck'
boardElement[itemCount] = 'deck'; boardElement[itemCount] = 'deck';
cardData[itemCount] = { // Set Attack, ManaCost, ManaColours TODO: When these are implemented seperately
'name':'CardName '+(i+1)
, 'cost':1 // Set the player
, 'atk':1
, 'def':1
, 'rarity': 'common'
, 'effect':effect
, 'type':'human'
, 'colour':colour
, 'tapped':false
};
player[itemCount] = playerId; player[itemCount] = playerId;
listPosition[itemCount] = i; // Set the position in the deck (as was added), will be shuffled on game start
// Previous iteration, kept to prevent errors for now listPosition[itemCount] = deckItem+1;
deck.push(cardData[itemCount]);
// Increment the itemCount to prevent overwriting stuff
itemCount++; itemCount++;
} }
let cardsInDeck = board.ECSLoop(null, playerId);
// Shuffle the deck straight away after generating/loading it in
shuffleDeck(playerId); shuffleDeck(playerId);
} }
@ -1102,7 +1100,6 @@ function shuffleDeck(playerId){
[ tempDeck[i], tempDeck[shuffle] ] = [ tempDeck[shuffle], tempDeck[i] ]; [ tempDeck[i], tempDeck[shuffle] ] = [ tempDeck[shuffle], tempDeck[i] ];
} }
console.log(getCurrentPositionAndLength('deck', playerId)[1]);
// For each item in the actual deck, set the listPosition to the random number from tempDeck // For each item in the actual deck, set the listPosition to the random number from tempDeck
let items = board.ECSLoop('deck', playerId, null, null); let items = board.ECSLoop('deck', playerId, null, null);
for(let item = 0; item < items.length; item++){ for(let item = 0; item < items.length; item++){
@ -1114,7 +1111,6 @@ function shuffleDeck(playerId){
//console.log('NEW LIST POSITION: '+listPosition[itemKey]); //console.log('NEW LIST POSITION: '+listPosition[itemKey]);
} }
console.log(getCurrentPositionAndLength('deck', playerId)[1]);
} }
@ -1312,4 +1308,19 @@ function printECSData(items){
); );
} }
} }
function echoCards(){
console.log(cardArray);
}
function echoCardsInDeck(playerId){
// Get all the cards that belong to player
let cardsInDeck = board.ECSLoop(null, playerId);
let deckList = [];
for(let i = 0; i < cardsInDeck.length; i++){
// If it's a card TODO: Change this to check 'card' from some ECS element
if(cardData[i] !== null && cardData[i] !== undefined){
deckList.push(cardData[i]);
}
}
console.log(deckList);
}

@ -0,0 +1,21 @@
// 0,1,2 = white,blue,red (for now)
// TODO: Use a DB in future, this is just for testing
let cardArray =
[
{ id: 1, name: 'Red1', colour: 2, cost: 1, type: 'Goblin', atk: 500, rarity: 'common', effect:'[[Sneak]] 500'},
{ id: 2, name: 'Red2', colour: 2, cost: 1, type: 'Goblin', atk: 1500, rarity: 'common', effect:'Cannot attack direct'},
{ id: 3, name: 'Red3', colour: 2, cost: 2, type: 'Goblin', atk: 1000, rarity: 'common', effect:'[[DEATH]] deal 1500 extra to killer'},
{ id: 4, name: 'Red4', colour: 2, cost: 2, type: 'Goblin', atk: 2000, rarity: 'common', effect:null},
{ id: 5, name: 'White1', colour: 0, cost: 1, type: 'Weapon', atk: 500, rarity: 'common', effect:'[[Equip]]'},
{ id: 6, name: 'White2', colour: 0, cost: 2, type: 'Human', atk: 1500, rarity: 'common', effect:null},
{ id: 7, name: 'White3', colour: 0, cost: 2, type: 'Human', atk: 2000, rarity: 'common', effect:'[[TAUNT]]'},
{ id: 8, name: 'White5', colour: 0, cost: 2, type: 'Human', atk: 1500, rarity: 'common', effect:'[[REACH]]'},
{ id: 9, name: 'Blue1', colour: 1, cost: 2, type: 'Spirit', atk: 1000, rarity: 'common', effect:null},
{ id: 10, name: 'Blue3', colour: 1, cost: 2, type: 'Spirit', atk: 1000, rarity: 'common', effect:'[[DRAW]] 1'},
{ id: 11, name: 'Blue4', colour: 1, cost: 2, type: 'Spirit', atk: 1500, rarity: 'common', effect:null},
{ id: 12, name: 'Blue5', colour: 1, cost: 3, type: 'Spirit', atk: 2500, rarity: 'common', effect:'[[FLIGHT]]'}
]
let deckListPlayer = [5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10];
let deckListOpponent = [1,1,1,1,2,2,3,3,4,4,7,7,7,7,5,5,5,3,3,8,8];

@ -18,8 +18,12 @@
<canvas id="canvas" width="1000" height="600"></canvas> <canvas id="canvas" width="1000" height="600"></canvas>
<button onclick="untapAllZones()">Untap all</button> <button onclick="untapAllZones()">Untap all</button>
<button onclick="ECSLoopTest()">Test ECS Loop</button> <button onclick="ECSLoopTest()">Test ECS Loop</button>
<button onclick="echoCards()">Print cardlist to console</button>
<button onclick="echoCardsInDeck(0)">Print cardsInDeck for player0</button>
<button onclick="echoCardsInDeck(1)">Print cardsInDeck for player1</button>
<script src="/socket.io/socket.io.js"></script> <script src="/socket.io/socket.io.js"></script>
<script src="/cards.js"></script><!-- Temp until DB -->
<script src="/shapes.js"></script> <script src="/shapes.js"></script>
<script src="/board.js"></script> <script src="/board.js"></script>
<script src="/main.js"></script> <script src="/main.js"></script>

Loading…
Cancel
Save