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

이동 도중 퇴실시 정상대응

parent 85326296
...@@ -136,7 +136,7 @@ class GameRoom ...@@ -136,7 +136,7 @@ class GameRoom
{ {
if (this.currentPhase === GameServer.Phase.READY) if (this.currentPhase === GameServer.Phase.READY)
{ {
this.endTime = Date.now() + 1000; // 테스트용 10초 this.endTime = Date.now() + 5000; // 테스트용 10초
this.announceToRoom('setRoomCount', this.announceToRoom('setRoomCount',
{ {
isEnable: true, endTime: this.endTime, playerCount: this.currentPlayer.length, isEnable: true, endTime: this.endTime, playerCount: this.currentPlayer.length,
...@@ -172,11 +172,26 @@ class GameRoom ...@@ -172,11 +172,26 @@ class GameRoom
{ {
for (let j = i+1; j < this.currentPlayer.length; j++) 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.currentPlayer.splice(i, 1);
this.currentSocket.splice(i, 1); this.currentSocket.splice(i, 1);
//this.aliveCount--;
return; return;
} }
} }
...@@ -184,6 +199,24 @@ class GameRoom ...@@ -184,6 +199,24 @@ class GameRoom
return; 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() startRoom()
{ {
this.currentPhase = GameServer.Phase.START; this.currentPhase = GameServer.Phase.START;
...@@ -204,6 +237,7 @@ class GameRoom ...@@ -204,6 +237,7 @@ class GameRoom
this.announceToRoom('syncRoomData', toSync); this.announceToRoom('syncRoomData', toSync);
console.log('[ROOM#'+this.roomId+'] Game Start with ' + this.currentPlayer.length + ' players'); console.log('[ROOM#'+this.roomId+'] Game Start with ' + this.currentPlayer.length + ' players');
console.table(this.currentPlayer);
this.announceToRoom('startGame'); this.announceToRoom('startGame');
this.startTime = Date.now(); this.startTime = Date.now();
} }
...@@ -280,7 +314,7 @@ class GameRoom ...@@ -280,7 +314,7 @@ class GameRoom
return element.playerData.id === targetId; return element.playerData.id === targetId;
}); });
//console.log('send to ' + targetSocketIndex + ', receivable? ' + this.currentSocket[targetSocketIndex].playerData.isReceivable); //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 ...@@ -295,7 +329,7 @@ class Player
this.playerImage = null; this.playerImage = null;
this.position = null; this.position = null;
this.isAlive = true; this.isAlive = false;
this.rank = -1; this.rank = -1;
this.playerTyping = 0; this.playerTyping = 0;
...@@ -314,6 +348,8 @@ class Player ...@@ -314,6 +348,8 @@ class Player
socket.playerData.isReceivable = false; socket.playerData.isReceivable = false;
room.aliveCount--; room.aliveCount--;
if (room.aliveCount > 0)
{
room.checkPhase(Date.now()); room.checkPhase(Date.now());
if (this.lastAttacks.length > 0) if (this.lastAttacks.length > 0)
...@@ -347,6 +383,7 @@ class Player ...@@ -347,6 +383,7 @@ class Player
console.log('['+winner.id+']' + ' winner! ' + winner.nickname); console.log('['+winner.id+']' + ' winner! ' + winner.nickname);
} }
} }
}
} }
module.exports = GameServer; module.exports = GameServer;
\ No newline at end of file
...@@ -41,6 +41,11 @@ socket.on('enterRoom', function() ...@@ -41,6 +41,11 @@ socket.on('enterRoom', function()
fbClient.updateUserData('recentHopae', PlayerData.currentHopae); fbClient.updateUserData('recentHopae', PlayerData.currentHopae);
Audio.killSound(ScenesData.menuScene, 'login'); Audio.killSound(ScenesData.menuScene, 'login');
ScenesData.changeScene('roomScene'); ScenesData.changeScene('roomScene');
if (ScenesData.endCountTimer != undefined)
{
clearTimeout(ScenesData.endCountTimer);
ScenesData.endCountTimer = undefined;
}
}); });
socket.on('syncRoomScene', function(msg) socket.on('syncRoomScene', function(msg)
{ {
...@@ -240,7 +245,7 @@ socket.on('defeat', function(msg) // object player ...@@ -240,7 +245,7 @@ socket.on('defeat', function(msg) // object player
if(msg.id == RoomData.myself.id) if(msg.id == RoomData.myself.id)
{ {
setTimeout(() => { setTimeout(() => {
socket.emit('exitRoom', {roomId: RoomData.myself.gameRoomId, playerId: RoomData.myself.id}); socket.emit('defeat');
ScenesData.changeScene('menuScene'); ScenesData.changeScene('menuScene');
}, 2000); }, 2000);
} }
......
...@@ -344,16 +344,15 @@ var roomScene = new Phaser.Class( ...@@ -344,16 +344,15 @@ var roomScene = new Phaser.Class(
{ {
this.peopleText.setText(this.peopleCount + ' / 10'); this.peopleText.setText(this.peopleCount + ' / 10');
if (this.isCounting) if (this.isCounting && !this.isCountEnd)
{ {
this.countText.setText(((this.endTime - Date.now()) / 1000).toFixed(1)); 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'); //console.log('end Count');
setTimeout(() => { ScenesData.endCountTimer = setTimeout(() => {
socket.emit('endCount'); socket.emit('endCount');
}, (Phaser.Math.Distance.Between(0, 0, game.config.width / 2, game.config.height * 10 / 9) * 10)); }, (Phaser.Math.Distance.Between(0, 0, game.config.width / 2, game.config.height * 10 / 9) * 3));
this.isCounting = false;
this.isCountEnd = true; this.isCountEnd = true;
this.players.forEach(function(element){ this.players.forEach(function(element){
element.follower = { t: 0, vec: new Phaser.Math.Vector2() }; element.follower = { t: 0, vec: new Phaser.Math.Vector2() };
...@@ -372,6 +371,8 @@ var roomScene = new Phaser.Class( ...@@ -372,6 +371,8 @@ var roomScene = new Phaser.Class(
} }
} }
else if (this.isCountEnd) else if (this.isCountEnd)
{
if (this.isCounting)
{ {
this.players.forEach(function(element){ this.players.forEach(function(element){
element.path.getPoint(element.follower.t, element.follower.vec); element.path.getPoint(element.follower.t, element.follower.vec);
...@@ -381,6 +382,13 @@ var roomScene = new Phaser.Class( ...@@ -381,6 +382,13 @@ var roomScene = new Phaser.Class(
this.countText.setText('잠시만 기다려주세요...'); this.countText.setText('잠시만 기다려주세요...');
} }
else else
{
this.countText.setText('이동 도중 사람이 퇴실했습니다...\n잠시만 기다려주세요...');
clearTimeout(ScenesData.endCountTimer);
ScenesData.endCountTimer = undefined;
}
}
else
{ {
this.countText.setText('사람들을 위해 대기중입니다...'); this.countText.setText('사람들을 위해 대기중입니다...');
} }
......
...@@ -63,11 +63,6 @@ io.on('connection', function(socket) ...@@ -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 socket.on('setPlayerTyping', function(msg) // number playerTyping
{ {
try try
...@@ -94,15 +89,51 @@ io.on('connection', function(socket) ...@@ -94,15 +89,51 @@ io.on('connection', function(socket)
socket.playerData.currentRoom.announceToRoom('attackMode', socket.playerData.id); 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.on('endCount', function()
{ {
socket.playerData.currentRoom.aliveCount--; 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(); 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) ...@@ -170,6 +201,7 @@ io.on('connection', function(socket)
console.log({ connectDiff, playerCount }); console.log({ connectDiff, playerCount });
console.table(GameServer.currentPlayer); console.table(GameServer.currentPlayer);
} }
socket.disconnect();
}); });
}); });
...@@ -188,20 +220,6 @@ var disconnectUser = function(data, reason) ...@@ -188,20 +220,6 @@ var disconnectUser = function(data, reason)
if (data.currentRoom.currentPhase === GameServer.Phase.READY || data.currentRoom.currentPhase === GameServer.Phase.COUNT) if (data.currentRoom.currentPhase === GameServer.Phase.READY || data.currentRoom.currentPhase === GameServer.Phase.COUNT)
{ {
data.currentRoom.exitRoom(data.id); 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) 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