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

count중 나가도 오류 없게 만듬

parent dfca8a59
......@@ -87,11 +87,11 @@ GameServer.enterRoom = function(roomIdx, playerData)
console.log('[' + playerData.id + '] entered to room #' + room.roomNum);
playerData.socketId.emit('enterRoom');
room.endTime = Date.now() + 6000; // 테스트로 6초로 남겨둠
if (room.currentPlayer.length >= this.startCount)
{
if (room.currentPhase === this.Phase.READY) // start count
{
room.endTime = Date.now() + 15000; // 테스트로 15초로 남겨둠
this.announceToRoom(room.roomNum, 'setCount', {isEnable: true, endTime: room.endTime});
}
else if (room.currentPhase === this.Phase.COUNT) // countinue count
......@@ -185,14 +185,14 @@ GameServer.announceToRoom = function(roomIdx, _message, _data = null)
{
this.playingRoom[roomIdx].currentSocket.forEach(function(element)
{
element.socketId.emit(_message, _data);
if (element != null) element.socketId.emit(_message, _data);
});
}
GameServer.announceToTarget = function(roomIdx, targetNum, _message, _data = null)
{
let targetSocket = this.playingRoom[roomIdx].currentSocket.find(function(element)
{
return element.id === targetNum;
return (element != null && element.id === targetNum);
});
if (targetSocket != undefined && targetSocket.isReceivable) targetSocket.socketId.emit(_message, _data);
}
......
......@@ -53,7 +53,6 @@ io.on('connection', function(socket)
console.log('['+socket.playerData.id+'] nickname set to ' + msg);
GameServer.enterEmptyRoom(socket.playerData);
}
});
socket.on('setPlayerTyping', function(msg) // number playerTyping
......@@ -84,6 +83,7 @@ io.on('connection', function(socket)
socket.on('attack', function(msg)
{
GameServer.announceToTarget(GameServer.findRoomIndex(msg.roomNum), msg.target, 'attacked', msg);
//console.log('find ' + msg.target + ' by ' + msg.attacker.idNum + ' with ' + msg.text);
let target = GameServer.findPlayer(msg.target);
if (target != null)
{
......@@ -136,10 +136,15 @@ io.on('connection', function(socket)
// 룸에서도 제거
if (data.currentRoom != null)
{
if (data.currentRoom.currentPhase === GameServer.Phase.READY)
if (data.currentRoom.currentPhase === GameServer.Phase.READY || data.currentRoom.currentPhase === GameServer.Phase.COUNT)
{
data.currentRoom.currentPlayer[data.playingData.index] = null;
data.currentRoom.currentSocket[data.playingData.index] = null;
data.currentRoom.aliveCount--;
if (data.currentRoom.aliveCount < GameServer.startCount)
{
GameServer.announceToRoom(GameServer.findRoomIndex(data.currentRoom.roomNum), 'setCount', {isEnable: false, endTime: 0});
}
}
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