mirror of
https://github.com/MaciejkaG/statki.git
synced 2024-11-30 05:42:56 +01:00
Major bug fixes
- Fixed ready up bug - Fixed a bug that made shooting impossible
This commit is contained in:
parent
8969d6242e
commit
1bd84bee09
7
index.js
7
index.js
@ -549,6 +549,7 @@ io.on('connection', async (socket) => {
|
|||||||
if (!(callback && typeof callback === 'function')) {
|
if (!(callback && typeof callback === 'function')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const playerGame = await GInfo.getPlayerGameData(socket);
|
const playerGame = await GInfo.getPlayerGameData(socket);
|
||||||
let timeLeft = await GInfo.timerLeft(playerGame.id);
|
let timeLeft = await GInfo.timerLeft(playerGame.id);
|
||||||
|
|
||||||
@ -593,9 +594,7 @@ io.on('connection', async (socket) => {
|
|||||||
await GInfo.timer(playerGame.id, Math.max(timeLeft / 2.5, 15), async () => {
|
await GInfo.timer(playerGame.id, Math.max(timeLeft / 2.5, 15), async () => {
|
||||||
await finishPrepPhase(socket, playerGame);
|
await finishPrepPhase(socket, playerGame);
|
||||||
});
|
});
|
||||||
} // else if (playerGame.data.ready[1]) {
|
}
|
||||||
// // Guest set ready
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -637,7 +636,7 @@ io.on('connection', async (socket) => {
|
|||||||
let playerGame = await GInfo.getPlayerGameData(socket);
|
let playerGame = await GInfo.getPlayerGameData(socket);
|
||||||
|
|
||||||
if (playerGame && playerGame.data.state === 'action') {
|
if (playerGame && playerGame.data.state === 'action') {
|
||||||
if (bships.checkTurn(playerGame.data, socket.session.id)) {
|
if (bships.checkTurn(playerGame.data, session.userId)) {
|
||||||
const enemyIdx = session.userId === playerGame.data.hostId ? 1 : 0;
|
const enemyIdx = session.userId === playerGame.data.hostId ? 1 : 0;
|
||||||
|
|
||||||
let hit = await GInfo.shootShip(socket, posX, posY);
|
let hit = await GInfo.shootShip(socket, posX, posY);
|
||||||
|
@ -61,14 +61,14 @@ export class GameInfo {
|
|||||||
|
|
||||||
async incrStat(socket, statKey, by = 1) {
|
async incrStat(socket, statKey, by = 1) {
|
||||||
const game = await this.redis.json.get(`game:${socket.session.activeGame}`);
|
const game = await this.redis.json.get(`game:${socket.session.activeGame}`);
|
||||||
const idx = socket.request.session.id === game.hostId ? 0 : 1;
|
const idx = socket.request.session.userId === game.hostId ? 0 : 1;
|
||||||
|
|
||||||
this.redis.json.numIncrBy(`game:${socket.session.activeGame}`, `.boards[${idx}].stats.${statKey}`, by);
|
this.redis.json.numIncrBy(`game:${socket.session.activeGame}`, `.boards[${idx}].stats.${statKey}`, by);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPlayerShips(socket) {
|
async getPlayerShips(socket) {
|
||||||
const game = await this.redis.json.get(`game:${socket.session.activeGame}`);
|
const game = await this.redis.json.get(`game:${socket.session.activeGame}`);
|
||||||
const idx = socket.request.session.id === game.hostId ? 0 : 1;
|
const idx = socket.request.session.userId === game.hostId ? 0 : 1;
|
||||||
return game.boards[idx].ships;
|
return game.boards[idx].ships;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ export class GameInfo {
|
|||||||
const key = `game:${gameId}`;
|
const key = `game:${gameId}`;
|
||||||
const hostId = (await this.redis.json.get(key, { path: '.hostId' }));
|
const hostId = (await this.redis.json.get(key, { path: '.hostId' }));
|
||||||
|
|
||||||
const playerIdx = socket.request.session.id === hostId ? 0 : 1;
|
const playerIdx = socket.request.session.userId === hostId ? 0 : 1;
|
||||||
await this.redis.json.arrAppend(key, `.boards[${playerIdx}].ships`, shipData);
|
await this.redis.json.arrAppend(key, `.boards[${playerIdx}].ships`, shipData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ export class GameInfo {
|
|||||||
const key = `game:${gameId}`;
|
const key = `game:${gameId}`;
|
||||||
const hostId = (await this.redis.json.get(key, { path: '.hostId' }));
|
const hostId = (await this.redis.json.get(key, { path: '.hostId' }));
|
||||||
|
|
||||||
const playerIdx = socket.request.session.id === hostId ? 0 : 1;
|
const playerIdx = socket.request.session.userId === hostId ? 0 : 1;
|
||||||
|
|
||||||
var playerShips = (await this.redis.json.get(key, { path: `.boards[${playerIdx}].ships` }));
|
var playerShips = (await this.redis.json.get(key, { path: `.boards[${playerIdx}].ships` }));
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ export class GameInfo {
|
|||||||
const key = `game:${gameId}`;
|
const key = `game:${gameId}`;
|
||||||
const hostId = (await this.redis.json.get(key, { path: '.hostId' }));
|
const hostId = (await this.redis.json.get(key, { path: '.hostId' }));
|
||||||
|
|
||||||
const playerIdx = socket.request.session.id === hostId ? 0 : 1;
|
const playerIdx = socket.request.session.userId === hostId ? 0 : 1;
|
||||||
let playerShips = await this.redis.json.get(key, {path: `.boards[${playerIdx}].ships`});
|
let playerShips = await this.redis.json.get(key, {path: `.boards[${playerIdx}].ships`});
|
||||||
|
|
||||||
var deletedShip;
|
var deletedShip;
|
||||||
@ -242,7 +242,7 @@ export class GameInfo {
|
|||||||
const key = `game:${gameId}`;
|
const key = `game:${gameId}`;
|
||||||
const hostId = (await this.redis.json.get(key, { path: '.hostId' }));
|
const hostId = (await this.redis.json.get(key, { path: '.hostId' }));
|
||||||
|
|
||||||
const enemyIdx = socket.request.session.id === hostId ? 1 : 0;
|
const enemyIdx = socket.request.session.userId === hostId ? 1 : 0;
|
||||||
// const playerIdx = enemyIdx ? 0 : 1;
|
// const playerIdx = enemyIdx ? 0 : 1;
|
||||||
|
|
||||||
let playerBoard = await this.redis.json.get(key, { path: `.boards[${enemyIdx}]` });
|
let playerBoard = await this.redis.json.get(key, { path: `.boards[${enemyIdx}]` });
|
||||||
@ -291,7 +291,7 @@ export class GameInfo {
|
|||||||
const key = `game:${gameId}`;
|
const key = `game:${gameId}`;
|
||||||
const hostId = (await this.redis.json.get(key, { path: '.hostId' }));
|
const hostId = (await this.redis.json.get(key, { path: '.hostId' }));
|
||||||
|
|
||||||
const playerIdx = socket.request.session.id === hostId ? 0 : 1;
|
const playerIdx = socket.request.session.userId === hostId ? 0 : 1;
|
||||||
|
|
||||||
await this.redis.json.set(key, `.ready[${playerIdx}]`, true);
|
await this.redis.json.set(key, `.ready[${playerIdx}]`, true);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user