ive only gone and actually processed a turn *in full*
This commit is contained in:
@@ -21,6 +21,7 @@ GAME OBJECT
|
||||
}],
|
||||
// Index of players whos turn it is
|
||||
turn: int,
|
||||
turntotal: int,
|
||||
// Array of GAMESTATEs, latest at head of array
|
||||
gamestates: [],
|
||||
tilebag: [],
|
||||
@@ -204,6 +205,7 @@ function BeginGame(lobby)
|
||||
locale: gameowner.locale,
|
||||
players: players,
|
||||
turn: 0,
|
||||
turntotal: 0,
|
||||
gamestates: [gamestate],
|
||||
tilebag: tilebag,
|
||||
tileset: Dist.GetTileSet(gameowner.locale)
|
||||
@@ -259,9 +261,7 @@ function PlayTurn(gameuid, playeruid, turn)
|
||||
{
|
||||
const game = ActiveGames[gameuid];
|
||||
|
||||
ActiveGames[gameuid].gamestate.push(turn);
|
||||
|
||||
console.log(turn);
|
||||
ActiveGames[gameuid].gamestates.push(turn);
|
||||
|
||||
const turninfo = gameNextTurn(gameuid);
|
||||
|
||||
@@ -271,11 +271,19 @@ function PlayTurn(gameuid, playeruid, turn)
|
||||
function SkipTurn(gameuid, playeruid)
|
||||
{
|
||||
console.log('skip');
|
||||
gameNextTurn(gameuid);
|
||||
}
|
||||
|
||||
function gameNextTurn(gameuid)
|
||||
{
|
||||
|
||||
const PlayerCount = ActiveGames[gameuid].players.length;
|
||||
ActiveGames[gameuid].turn++;
|
||||
ActiveGames[gameuid].turn %= PlayerCount;
|
||||
ActiveGames[gameuid].turntotal++;
|
||||
return {
|
||||
// i forgot why this is an object, there's more attributes i forgot about
|
||||
turnplayer: ActiveGames[gameuid].players[ActiveGames[gameuid].turn],
|
||||
};
|
||||
}
|
||||
|
||||
// returns tuple ([newtileset], [newusertiles])
|
||||
|
||||
@@ -398,18 +398,33 @@ function GamePlayTurn(socket, args)
|
||||
if (!user || !game)
|
||||
{
|
||||
// do something bad
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.game(`USER ${user.uid} (${user.name}) IS ATTEMPTING TO PLAY A TURN IN GAME ${game.uid}`);
|
||||
|
||||
if (args.skip === true)
|
||||
{
|
||||
const [outcome, turninfo] = Game.Logic.SkipTurn(game.uid, user.uid);
|
||||
|
||||
io.to(game.uid).emit()
|
||||
|
||||
const {outcome, turninfo} = Game.Logic.SkipTurn(game.uid, user.uid);
|
||||
} else
|
||||
{
|
||||
// TODO: validate args
|
||||
outcome = Game.Logic.PlayTurn(game.uid, user.uid, args)
|
||||
const [outcome, turninfo] = Game.Logic.PlayTurn(game.uid, user.uid, args)
|
||||
|
||||
// give user new tiles
|
||||
// process errorsq
|
||||
|
||||
io.to(game.uid).emit('game-turn-processed', {
|
||||
outcome: outcome
|
||||
});
|
||||
|
||||
const nextuser = Game.Registrar.GetConnectionByUser(turninfo.turnplayer.uid);
|
||||
|
||||
io.to(game.uid).emit('game-turn-start', {
|
||||
turninfo: turninfo
|
||||
});
|
||||
|
||||
io.to(nextuser).emit('game-your-turn');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user