Commit 88609700 authored by 18신대성's avatar 18신대성

이동 도중 퇴실시 정상대응

parent 85326296
......@@ -136,7 +136,7 @@ class GameRoom
{
if (this.currentPhase === GameServer.Phase.READY)
{
this.endTime = Date.now() + 1000; // 테스트용 10초
this.endTime = Date.now() + 5000; // 테스트용 10초
this.announceToRoom('setRoomCount',
{
isEnable: true, endTime: this.endTime, playerCount: this.currentPlayer.length,
......@@ -172,17 +172,50 @@ class GameRoom
{
for (let j = i+1; j < this.currentPlayer.length; j++)
{
this.currentPlayer[i].index--;
this.currentPlayer[j].index--;
}
this.aliveCount--;
if (this.aliveCount < this.startCount)
{
this.announceToRoom('setRoomCount',
{
isEnable: false, endTime: 0, playerCount: this.currentPlayer.length,
isEnter: false, player: this.currentPlayer[i]
});
this.currentPhase = GameServer.Phase.READY;
this.refreshRoom();
}
else this.announceToRoom('setRoomCount',
{
isEnable: true, endTime: this.endTime, playerCount: this.currentPlayer.length,
isEnter: false, player: this.currentPlayer[i]
});
this.currentPlayer.splice(i, 1);
this.currentSocket.splice(i, 1);
//this.aliveCount--;
return;
}
}
console.log('[ERR] No player who have ' + playerId);
return;
}
refreshRoom()
{
this.currentPhase = GameServer.Phase.READY;
this.aliveCount = this.currentPlayer.length;
if (this.startTimer != undefined)
{
clearTimeout(this.startTimer);
this.startTimer = undefined;
}
this.announceToRoom('enterRoom');
this.announceToRoom('syncRoomScene', this.currentPlayer);
this.announceToRoom('setRoomCount', {
isEnable: false, endTime: 0, playerCount: this.currentPlayer.length,
isEnter: false, player: {id: -1}
});
console.error('[ROOM#' + this.roomId + '] room Refreshed');
}
startRoom()
{
......@@ -204,6 +237,7 @@ class GameRoom
this.announceToRoom('syncRoomData', toSync);
console.log('[ROOM#'+this.roomId+'] Game Start with ' + this.currentPlayer.length + ' players');
console.table(this.currentPlayer);
this.announceToRoom('startGame');
this.startTime = Date.now();
}
......@@ -280,7 +314,7 @@ class GameRoom
return element.playerData.id === targetId;
});
//console.log('send to ' + targetSocketIndex + ', receivable? ' + this.currentSocket[targetSocketIndex].playerData.isReceivable);
if (this.currentSocket[targetSocketIndex].playerData.isReceivable) this.currentSocket[targetSocketIndex].emit(_message, _data);
if (targetSocketIndex != -1 && this.currentSocket[targetSocketIndex].playerData.isReceivable) this.currentSocket[targetSocketIndex].emit(_message, _data);
}
}
......@@ -295,7 +329,7 @@ class Player
this.playerImage = null;
this.position = null;
this.isAlive = true;
this.isAlive = false;
this.rank = -1;
this.playerTyping = 0;
......@@ -314,37 +348,40 @@ class Player
socket.playerData.isReceivable = false;
room.aliveCount--;
room.checkPhase(Date.now());
if (this.lastAttacks.length > 0)
if (room.aliveCount > 0)
{
this.lastAttack = this.lastAttacks[this.lastAttacks.length - 1];
if (Date.now() - this.lastAttack.time > 20000) this.lastAttack = null;
else
room.checkPhase(Date.now());
if (this.lastAttacks.length > 0)
{
this.lastAttacks.forEach(function(element)
this.lastAttack = this.lastAttacks[this.lastAttacks.length - 1];
if (Date.now() - this.lastAttack.time > 20000) this.lastAttack = null;
else
{
if (Date.now() - element.time < 20000)
this.lastAttacks.forEach(function(element)
{
if (element.wrongCount > player.lastAttack.wrongCount) player.lastAttack = element;
else if (element.wrongCount === player.lastAttack.wrongCount && element.wordGrade > player.lastAttack.wordGrade) player.lastAttack = element;
}
});
if (Date.now() - element.time < 20000)
{
if (element.wrongCount > player.lastAttack.wrongCount) player.lastAttack = element;
else if (element.wrongCount === player.lastAttack.wrongCount && element.wordGrade > player.lastAttack.wordGrade) player.lastAttack = element;
}
});
}
}
}
room.announceToRoom('defeat', this);
console.log('[' + this.id + '] defeated, rank: ' + this.rank + ', ' + room.aliveCount + ' player left');
room.announceToRoom('defeat', this);
console.log('[' + this.id + '] defeated, rank: ' + this.rank + ', ' + room.aliveCount + ' player left');
if (socket.playerData.currentRoom.aliveCount === 1)
{
let winner = room.currentPlayer.find(function(element)
if (socket.playerData.currentRoom.aliveCount === 1)
{
return element.isAlive;
});
room.announceToRoom('gameEnd', winner);
room.announceToTarget(winner.id, 'alert', 'gameWin');
console.log('['+winner.id+']' + ' winner! ' + winner.nickname);
let winner = room.currentPlayer.find(function(element)
{
return element.isAlive;
});
room.announceToRoom('gameEnd', winner);
room.announceToTarget(winner.id, 'alert', 'gameWin');
console.log('['+winner.id+']' + ' winner! ' + winner.nickname);
}
}
}
}
......
......@@ -41,6 +41,11 @@ socket.on('enterRoom', function()
fbClient.updateUserData('recentHopae', PlayerData.currentHopae);
Audio.killSound(ScenesData.menuScene, 'login');
ScenesData.changeScene('roomScene');
if (ScenesData.endCountTimer != undefined)
{
clearTimeout(ScenesData.endCountTimer);
ScenesData.endCountTimer = undefined;
}
});
socket.on('syncRoomScene', function(msg)
{
......@@ -240,7 +245,7 @@ socket.on('defeat', function(msg) // object player
if(msg.id == RoomData.myself.id)
{
setTimeout(() => {
socket.emit('exitRoom', {roomId: RoomData.myself.gameRoomId, playerId: RoomData.myself.id});
socket.emit('defeat');
ScenesData.changeScene('menuScene');
}, 2000);
}
......
......@@ -344,16 +344,15 @@ var roomScene = new Phaser.Class(
{
this.peopleText.setText(this.peopleCount + ' / 10');
if (this.isCounting)
if (this.isCounting && !this.isCountEnd)
{
this.countText.setText(((this.endTime - Date.now()) / 1000).toFixed(1));
if (this.endTime < Date.now())
if (this.endTime != 0 && this.endTime < Date.now())
{
//console.log('end Count');
setTimeout(() => {
ScenesData.endCountTimer = setTimeout(() => {
socket.emit('endCount');
}, (Phaser.Math.Distance.Between(0, 0, game.config.width / 2, game.config.height * 10 / 9) * 10));
this.isCounting = false;
}, (Phaser.Math.Distance.Between(0, 0, game.config.width / 2, game.config.height * 10 / 9) * 3));
this.isCountEnd = true;
this.players.forEach(function(element){
element.follower = { t: 0, vec: new Phaser.Math.Vector2() };
......@@ -373,12 +372,21 @@ var roomScene = new Phaser.Class(
}
else if (this.isCountEnd)
{
this.players.forEach(function(element){
element.path.getPoint(element.follower.t, element.follower.vec);
element.sprite.setPosition(element.follower.vec.x, element.follower.vec.y);
element.nickname.setPosition(element.sprite.x - game.config.width / 128, element.sprite.y - game.config.height / 12);
});
this.countText.setText('잠시만 기다려주세요...');
if (this.isCounting)
{
this.players.forEach(function(element){
element.path.getPoint(element.follower.t, element.follower.vec);
element.sprite.setPosition(element.follower.vec.x, element.follower.vec.y);
element.nickname.setPosition(element.sprite.x - game.config.width / 128, element.sprite.y - game.config.height / 12);
});
this.countText.setText('잠시만 기다려주세요...');
}
else
{
this.countText.setText('이동 도중 사람이 퇴실했습니다...\n잠시만 기다려주세요...');
clearTimeout(ScenesData.endCountTimer);
ScenesData.endCountTimer = undefined;
}
}
else
{
......
......@@ -63,11 +63,6 @@ io.on('connection', function(socket)
}
});
socket.on('exitRoom', function(msg) // string new_nickname
{
GameServer.findRoom(msg.roomId).exitRoom(msg.playerId);
});
socket.on('setPlayerTyping', function(msg) // number playerTyping
{
try
......@@ -94,15 +89,51 @@ io.on('connection', function(socket)
socket.playerData.currentRoom.announceToRoom('attackMode', socket.playerData.id);
}
}
catch (e) {console.error('[ERR] error catched on setPlayerTyping')}
catch (e) {
console.error('[ERR] error catched on setPlayerTyping');
socket.disconnect();
}
});
socket.on('endCount', function()
{
socket.playerData.currentRoom.aliveCount--;
if (socket.playerData.currentRoom.aliveCount === 0)
//console.log('counted, ' + socket.playerData.currentRoom.aliveCount);
socket.playerData.playingData.isAlive = true;
if (socket.playerData.currentRoom.aliveCount === 0 && socket.playerData.currentRoom.currentPlayer.length >= socket.playerData.currentRoom.startCount)
{
socket.playerData.currentRoom.startRoom();
clearTimeout(socket.playerData.currentRoom.startTimer);
}
if (socket.playerData.currentRoom.startTimer === undefined)
{
const room = socket.playerData.currentRoom;
room.startTimer = setTimeout(function()
{
let deads = room.currentPlayer.filter(element => !element.isAlive);
if (room.aliveCount != 0)
{
console.error('[ROOM#'+room.roomId+'] FORCE START!!!');
if (room.currentPlayer.length - deads.length >= room.startCount)
{
room.startRoom();
deads.forEach(function(element)
{
element.defeat();
});
}
clearTimeout(room.startTimer);
}
else
{
deads.forEach(function(element)
{
room.currentSocket[element.index].disconnect();
room.exitRoom(element.id);
});
room.refreshRoom();
}
}, 2000);
}
});
......@@ -170,6 +201,7 @@ io.on('connection', function(socket)
console.log({ connectDiff, playerCount });
console.table(GameServer.currentPlayer);
}
socket.disconnect();
});
});
......@@ -188,20 +220,6 @@ var disconnectUser = function(data, reason)
if (data.currentRoom.currentPhase === GameServer.Phase.READY || data.currentRoom.currentPhase === GameServer.Phase.COUNT)
{
data.currentRoom.exitRoom(data.id);
if (data.currentRoom.aliveCount < data.currentRoom.startCount)
{
data.currentRoom.announceToRoom('setRoomCount',
{
isEnable: false, endTime: 0, playerCount: data.currentRoom.currentPlayer.length,
isEnter: false, player: data.playingData
});
data.currentRoom.currentPhase = GameServer.Phase.READY;
}
else data.currentRoom.announceToRoom('setRoomCount',
{
isEnable: true, endTime: data.currentRoom.endTime, playerCount: data.currentRoom.currentPlayer.length,
isEnter: false, player: data.playingData
});
}
else if (data.playingData.isAlive)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment