Commit b54eea87 authored by 18손재민's avatar 18손재민

Merge branch 'server' into gameScene

# Conflicts:
#	js/FirebaseClient.js
parents 93abd960 15a3a82b
...@@ -80,7 +80,7 @@ class GameRoom ...@@ -80,7 +80,7 @@ class GameRoom
{ {
this.roomId = GameServer.getRoomNumber(); this.roomId = GameServer.getRoomNumber();
this.roomIndex = -1; this.roomIndex = -1;
this.startCount = 5; this.startCount = 2;
this.maxPlayer = 100; this.maxPlayer = 100;
this.nextRank = 100; this.nextRank = 100;
...@@ -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,17 +172,50 @@ class GameRoom ...@@ -172,17 +172,50 @@ 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;
} }
} }
console.log('[ERR] No player who have ' + playerId); console.log('[ERR] No player who have ' + playerId);
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()
{ {
...@@ -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();
} }
...@@ -269,7 +303,7 @@ class GameRoom ...@@ -269,7 +303,7 @@ class GameRoom
{ {
this.currentSocket.forEach(function(element) this.currentSocket.forEach(function(element)
{ {
element.emit(_message, _data); if(element.playerData.playingData.isInThisRoom) element.emit(_message, _data);
}); });
} }
...@@ -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);
} }
} }
...@@ -294,8 +328,9 @@ class Player ...@@ -294,8 +328,9 @@ class Player
this.nickname = playerData.nickname; this.nickname = playerData.nickname;
this.playerImage = null; this.playerImage = null;
this.position = null; this.position = null;
this.isInThisRoom = true;
this.isAlive = true; this.isAlive = false;
this.rank = -1; this.rank = -1;
this.playerTyping = 0; this.playerTyping = 0;
...@@ -314,38 +349,42 @@ class Player ...@@ -314,38 +349,42 @@ class Player
socket.playerData.isReceivable = false; socket.playerData.isReceivable = false;
room.aliveCount--; room.aliveCount--;
room.checkPhase(Date.now()); if (room.aliveCount > 0)
if (this.lastAttacks.length > 0)
{ {
this.lastAttack = this.lastAttacks[this.lastAttacks.length - 1]; room.checkPhase(Date.now());
if (Date.now() - this.lastAttack.time > 20000) this.lastAttack = null;
else 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; if (Date.now() - element.time < 20000)
else if (element.wrongCount === player.lastAttack.wrongCount && element.wordGrade > player.lastAttack.wordGrade) player.lastAttack = 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;
}
});
}
} }
}
room.announceToRoom('defeat', this); room.announceToRoom('defeat', this);
console.log('[' + this.id + '] defeated, rank: ' + this.rank + ', ' + room.aliveCount + ' player left'); console.log('[' + this.id + '] defeated, rank: ' + this.rank + ', ' + room.aliveCount + ' player left');
if (socket.playerData.currentRoom.aliveCount === 1) if (socket.playerData.currentRoom.aliveCount === 1)
{
let winner = room.currentPlayer.find(function(element)
{ {
return element.isAlive; let winner = room.currentPlayer.find(function(element)
}); {
room.announceToRoom('gameEnd', winner); return element.isAlive;
room.announceToTarget(winner.id, 'alert', 'gameWin'); });
console.log('['+winner.id+']' + ' winner! ' + winner.nickname); room.announceToRoom('gameEnd', winner);
room.announceToTarget(winner.id, 'alert', 'gameWin');
console.log('['+winner.id+']' + ' winner! ' + winner.nickname);
}
} }
this.isInThisRoom = false;
} }
} }
......
...@@ -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)
{ {
...@@ -190,8 +195,6 @@ socket.on('defeat', function(msg) // object player ...@@ -190,8 +195,6 @@ socket.on('defeat', function(msg) // object player
RoomData.players[msg.index].nicknameText = nicknameText; RoomData.players[msg.index].nicknameText = nicknameText;
RoomData.aliveCount--; RoomData.aliveCount--;
console.log(msg.id);
console.log(RoomData.findPlayer(msg.id));
RoomData.findPlayer(msg.id).playerImage.play(WordSpace.pyeongminAnims[Enums.characterAnim.gameOver]); RoomData.findPlayer(msg.id).playerImage.play(WordSpace.pyeongminAnims[Enums.characterAnim.gameOver]);
if (msg.lastAttack != null) if (msg.lastAttack != null)
{ {
...@@ -239,11 +242,25 @@ socket.on('defeat', function(msg) // object player ...@@ -239,11 +242,25 @@ socket.on('defeat', function(msg) // object player
console.log(RoomData.findPlayer(msg.id).nickname + ' defeated'); console.log(RoomData.findPlayer(msg.id).nickname + ' defeated');
WordSpace.killLogForTest += ('\n--Suicide->' + RoomData.findPlayer(msg.id).nickname); WordSpace.killLogForTest += ('\n--Suicide->' + RoomData.findPlayer(msg.id).nickname);
} }
if(msg.id == RoomData.myself.id)
{
setTimeout(() => {
socket.emit('defeat');
ScenesData.changeScene('menuScene');
}, 2000);
}
}); });
socket.on('gameEnd', function(msg) // object player socket.on('gameEnd', function(msg) // object player
{ {
console.log(msg.nickname + ' Win!!!!!!'); console.log(msg.nickname + ' Win!!!!!!');
if(msg.id == RoomData.myself.id)
{
setTimeout(() => {
ScenesData.changeScene('menuScene');
}, 2000);
}
}); });
socket.on('attackSucceed', function(msg) socket.on('attackSucceed', function(msg)
{ {
//console.log('client'); //console.log('client');
......
...@@ -70,7 +70,7 @@ FirebaseClient.prototype.setLogin = function() ...@@ -70,7 +70,7 @@ FirebaseClient.prototype.setLogin = function()
.then(function() .then(function()
{ {
game = new Phaser.Game(config); game = new Phaser.Game(config);
this.isGameStarted = true; fbClient.isGameStarted = true;
}); });
document.getElementById('mainTitle').style.display = 'none'; document.getElementById('mainTitle').style.display = 'none';
...@@ -79,7 +79,10 @@ FirebaseClient.prototype.setLogin = function() ...@@ -79,7 +79,10 @@ FirebaseClient.prototype.setLogin = function()
FirebaseClient.prototype.setLogOut = function() FirebaseClient.prototype.setLogOut = function()
{ {
if (game != null) game.destroy(true);
this.isGameStarted = false;
document.getElementById('mainTitle').style.display = 'block';
document.getElementById('titleImg').style.display = 'block';
} }
FirebaseClient.prototype.onEmailBtnClick = function() FirebaseClient.prototype.onEmailBtnClick = function()
...@@ -248,6 +251,11 @@ document.addEventListener('DOMContentLoaded', function() ...@@ -248,6 +251,11 @@ document.addEventListener('DOMContentLoaded', function()
console.log('done load'); console.log('done load');
}); });
document.onkeydown = function(e)
{
if (fbClient.isGameStarted && e.keyCode === 27) fbClient.logOut();
}
class UserData class UserData
{ {
constructor() constructor()
......
...@@ -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() };
...@@ -373,12 +372,21 @@ var roomScene = new Phaser.Class( ...@@ -373,12 +372,21 @@ var roomScene = new Phaser.Class(
} }
else if (this.isCountEnd) else if (this.isCountEnd)
{ {
this.players.forEach(function(element){ if (this.isCounting)
element.path.getPoint(element.follower.t, element.follower.vec); {
element.sprite.setPosition(element.follower.vec.x, element.follower.vec.y); this.players.forEach(function(element){
element.nickname.setPosition(element.sprite.x - game.config.width / 128, element.sprite.y - game.config.height / 12); element.path.getPoint(element.follower.t, element.follower.vec);
}); element.sprite.setPosition(element.follower.vec.x, element.follower.vec.y);
this.countText.setText('잠시만 기다려주세요...'); 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 else
{ {
...@@ -437,8 +445,7 @@ var gameScene = new Phaser.Class( ...@@ -437,8 +445,7 @@ var gameScene = new Phaser.Class(
WordSpace.startCycle(this); WordSpace.startCycle(this);
WordSpace.setPlayerTyping.initiate(this); WordSpace.setPlayerTyping.initiate(this);
WordSpace.nameWordTextForTest = this.add.text(50,400,'현재 가진 호패들 : 없음').setDepth(10).setColor('#000000');
WordSpace.nameQueue.initiate(); WordSpace.nameQueue.initiate();
//WordSpace.attackGauge.add(11); //WordSpace.attackGauge.add(11);
...@@ -446,29 +453,25 @@ var gameScene = new Phaser.Class( ...@@ -446,29 +453,25 @@ var gameScene = new Phaser.Class(
update: function() update: function()
{ {
WordSpace.deltaTime = this.sys.game.loop.delta; if(ScenesData.currentScene == ScenesData.gameScene)
WordSpace.wordForcedGroup.forEach(function(element)
{
element.attract();
});
WordSpace.nameGroup.forEach(function(element)
{ {
element.attract(); WordSpace.deltaTime = this.sys.game.loop.delta;
}) WordSpace.wordForcedGroup.forEach(function(element)
WordSpace.attackPaperGroup.forEach(function(element){ {
element.moveObject(element); element.attract();
}); });
let tempNames = ''; WordSpace.nameGroup.forEach(function(element)
WordSpace.nameGroup.forEach(function(element) {
{ element.attract();
//테스트용 })
tempNames += element.wordText + (element.isStrong?' [강]':'') + '\n'; WordSpace.attackPaperGroup.forEach(function(element){
}); element.moveObject(element);
});
WordSpace.nameWordTextForTest.setText('현재 가진 호패들 : \n' + tempNames);
WordSpace.weightTextObjForTest.setText('뇌의 무게: (현재) '+WordSpace.totalWeight+' / '+ WordSpace.brainCapacity+' (전체)'); WordSpace.weightTextObjForTest.setText('뇌의 무게: (현재) '+WordSpace.totalWeight+' / '+ WordSpace.brainCapacity+' (전체)');
WordSpace.killLogTextForTest.setText(WordSpace.killLogForTest); WordSpace.killLogTextForTest.setText(WordSpace.killLogForTest);
WordSpace.setPlayerTyping.add(''); WordSpace.setPlayerTyping.add('');
}
} }
}); });
......
var config = { var config = {
type: Phaser.AUTO, type: Phaser.CANVAS,
width: 1920, width: 1920,
height: 1080, height: 1080,
scale: { scale: {
......
...@@ -16,7 +16,7 @@ app.get('/', function(req, res) { ...@@ -16,7 +16,7 @@ app.get('/', function(req, res) {
server.listen(80, function() { server.listen(80, function() {
console.log('[SERVER] Listening on port ' + server.address().port); console.log('[SERVER] Listening on port ' + server.address().port);
GameServer.serverNumber = Math.floor(Math.random() * 1000 + 1); GameServer.serverNumber = Math.floor(Math.random() * 1000 + 1);
console.log('[SERVER] server number is ${GameServer.serverNumber}'); console.log('[SERVER] server number is ' + GameServer.serverNumber);
}); });
...@@ -89,15 +89,51 @@ io.on('connection', function(socket) ...@@ -89,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);
} }
}); });
...@@ -148,18 +184,24 @@ io.on('connection', function(socket) ...@@ -148,18 +184,24 @@ io.on('connection', function(socket)
{ {
GameServer.disconnectCount++; GameServer.disconnectCount++;
let data = socket.playerData; let data = socket.playerData;
if (typeof data === undefined) if (data === undefined)
{ {
console.error('[ERROR] data is undefined'); console.error('[ERROR] data is undefined');
console.table(GameServer.currentPlayer); console.table(GameServer.currentPlayer);
GameServer.disconnectCount--;
} }
else // data.id is not undefined else // data.id is not undefined
{ {
disconnectUser(data, reason); disconnectUser(data, reason);
} }
const connectDiff = GameServer.connectCount - GameServer.disconnectCount; const connectDiff = GameServer.connectCount - GameServer.disconnectCount;
const playerCount = GameServer.currentPlayer.length const playerCount = GameServer.currentPlayer.length;
console.log({ connectDiff, playerCount }); if (connectDiff != playerCount)
{
console.log({ connectDiff, playerCount });
console.table(GameServer.currentPlayer);
}
socket.disconnect();
}); });
}); });
...@@ -178,20 +220,6 @@ var disconnectUser = function(data, reason) ...@@ -178,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