Commit 95b3b93e authored by 18신대성's avatar 18신대성

서버의 많은 부분을 뜯어고침

게임룸 클래스화
parent 61daf001
This diff is collapsed.
......@@ -14,7 +14,7 @@ socket.on('alert', function(msg) // string errorcode
socket.on('setId', function(msg) // {str, num playerNum}
{
console.log(msg.str);
PlayerData.idNum = msg.num;
PlayerData.id = msg.num;
});
socket.on('enterRoom', function()
{
......@@ -26,15 +26,24 @@ socket.on('setCount', function(msg)
{
ScenesData.roomScene.isCounting = msg.isEnable;
ScenesData.roomScene.endTime = msg.endTime;
ScenesData.roomScene.peopleCount = msg.playerCount;
});
// init game
socket.on('syncRoomData', function(msg) // {num roomNum, [] players}
{
console.log(msg);
RoomData.roomNum = msg.roomNum;
//console.log(msg);
RoomData.roomId = msg.roomId;
RoomData.players = msg.players;
RoomData.aliveCount = msg.players.length;
RoomData.players.forEach(function(element)
{
if(element.id === PlayerData.id)
{
RoomData.myself = element;
return;
}
});
});
socket.on('startGame', function()
{
......@@ -55,6 +64,7 @@ socket.on('setPlayerTypingRate', function(msg) // number playerTypingRate
});
socket.on('attacked', function(msg) // object attackData
{
//console.log('attacked by ' + msg.attacker.nickname);
setTimeout(function()
{
WordSpace.generateWord.Attack(ScenesData.gameScene, msg.text, msg.grade, msg.attacker, msg.isStrong);
......
......@@ -61,6 +61,7 @@ var roomScene = new Phaser.Class(
this.countText.setText(((this.endTime - Date.now()) / 1000).toFixed(1));
if (this.endTime - Date.now() < 0)
{
//console.log('end Count');
socket.emit('endCount');
this.isCounting = false;
}
......@@ -119,14 +120,8 @@ var gameScene = new Phaser.Class(
WordSpace.nameWordTextForTest = ScenesData.gameScene.add.text(50,400,'현재 가진 호패들 : 없음').setDepth(10).setColor('#000000');
WordSpace.nameQueue.initiate();
RoomData.players.forEach(function(element)
{
if(element.nickname == PlayerData.nickname)
{
RoomData.myself = element;
return;
}
});
// for test
WordSpace.attackGauge.add(11);
},
......
......@@ -394,7 +394,7 @@ WordSpace.findWord = function(wordText)
console.log('Attack word : ' + element.wordText + ' of ' + element.attacker.nickname + ' 오타임');
let victimData =
{
roomNum: RoomData.roomNum,
roomNum: RoomData.roomId,
victim: RoomData.myself,
target: element.attacker.id
}
......@@ -431,9 +431,10 @@ WordSpace.attack = function(wordText, grade)
console.log('attack ' + wordText + ', grade: ' + grade);
WordSpace.nameGroup.forEach(function(element)
{
//console.log(RoomData.myself);
let attackData =
{
roomNum: RoomData.roomNum,
roomNum: RoomData.roomId,
attacker: RoomData.myself,
target: element.ownerId,
text: wordText,
......@@ -474,7 +475,7 @@ WordSpace.nameQueue =
}
tempQueue.forEach(function(element)
{
if(element.id != PlayerData.idNum && element.isAlive)
if(element.id != PlayerData.id && element.isAlive)
WordSpace.nameQueue.queue.push(element);
});
},
......
......@@ -23,13 +23,13 @@ var game = new Phaser.Game(config)
//테스트용이므로 차후 수정 요망
var PlayerData = PlayerData || {};
PlayerData.idNum = -1; //플레이어 아이디, 고유 번호
PlayerData.id = -1; //플레이어 아이디, 고유 번호
PlayerData.nickname = '홍길동'; //플레이어 닉네임
// 현재 들어가있는 Game Room의 정보
var RoomData = RoomData || {};
RoomData.roomNum = -1;
RoomData.roomId = -1;
RoomData.myself = null;
RoomData.players = null;
RoomData.aliveCount = -1;
\ No newline at end of file
......@@ -25,12 +25,11 @@ io.on('connection', function(socket)
{
id: GameServer.getPlayerNumber(),
nickname: '게스트',
socketId: socket,
currentRoom: null,
playingData: null,
isReceivable: false
};
GameServer.currentPlayer.push(socket.playerData);
GameServer.currentPlayer.push(socket);
console.log('['+socket.playerData.id+'] client request');
socket.emit('setId',
{
......@@ -44,14 +43,14 @@ io.on('connection', function(socket)
let isAlreadyHave = false;
GameServer.currentPlayer.forEach(function(element)
{
if (element.nickname === msg) isAlreadyHave = true;
if (element.playerData.nickname === msg) isAlreadyHave = true;
});
if (isAlreadyHave) socket.emit('alert' ,'errNicknameOverlaped');
else
{
socket.playerData.nickname = msg;
console.log('['+socket.playerData.id+'] nickname set to ' + msg);
GameServer.enterEmptyRoom(socket.playerData);
GameServer.enterEmptyRoom(socket);
}
});
......@@ -76,15 +75,15 @@ io.on('connection', function(socket)
socket.playerData.currentRoom.aliveCount--;
if (socket.playerData.currentRoom.aliveCount === 0)
{
GameServer.startRoom(GameServer.findRoomIndex(socket.playerData.currentRoom.roomNum));
socket.playerData.currentRoom.startRoom();
}
});
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);
socket.playerData.currentRoom.announceToTarget(msg.target, 'attacked', msg);
//console.log('attack ' + msg.target + ' by ' + msg.attacker.id + ' with ' + msg.text);
let target = GameServer.findPlayerSocket(msg.target);
if (target != null)
{
let dataToPush =
......@@ -96,23 +95,23 @@ io.on('connection', function(socket)
time: Date.now()
}
if (target.playingData.lastAttacks.length < 5) target.playingData.lastAttacks.push(dataToPush);
if (target.playerData.playingData.lastAttacks.length < 5) target.playerData.playingData.lastAttacks.push(dataToPush);
else
{
target.playingData.lastAttacks.splice(0, 1);
target.playingData.lastAttacks.push(dataToPush);
target.playerData.playingData.lastAttacks.splice(0, 1);
target.playerData.playingData.lastAttacks.push(dataToPush);
}
}
});
socket.on('defeated', function()
{
GameServer.playerDefeat(socket.playerData);
socket.playerData.playingData.defeat();
});
socket.on('defenseFailed', function(msg)
{
GameServer.announceToTarget(GameServer.findRoomIndex(msg.roomNum), msg.target, 'attackSucceed', msg);
socket.playerData.currentRoom.announceToTarget(msg.target, 'attackSucceed', msg);
});
socket.on('disconnect', function(reason)
......@@ -128,31 +127,30 @@ io.on('connection', function(socket)
console.log('['+ data.id +'] client disconnected, reason: ' + reason);
let idxToDel = GameServer.currentPlayer.findIndex(function(element)
{
return element.id === data.id;
return element.playerData.id === data.id;
});
if (idxToDel != -1)
{
GameServer.currentPlayer.splice(idxToDel, 1);
// 룸에서도 제거
if (data.currentRoom != null)
{
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--;
data.currentRoom.exitRoom(data.id);
if (data.currentRoom.aliveCount < GameServer.startCount)
{
GameServer.announceToRoom(GameServer.findRoomIndex(data.currentRoom.roomNum), 'setCount', {isEnable: false, endTime: 0});
data.currentRoom.announceToRoom('setCount', {isEnable: false, endTime: 0, playerCount: data.currentRoom.currentPlayer.length});
data.currentRoom.currentPhase = GameServer.Phase.READY;
}
else data.currentRoom.announceToRoom('setCount', {isEnable: true, endTime: data.currentRoom.endTime, playerCount: data.currentRoom.currentPlayer.length});
}
else if (data.playingData.isAlive)
{
GameServer.playerDefeat(socket.playerData);
GameServer.announceToRoom(GameServer.findRoomIndex(data.currentRoom.roomNum), 'userDisconnect', data.playingData);
data.playingData.defeat();
data.currentRoom.announceToRoom('userDisconnect', data.playingData);
}
}
GameServer.currentPlayer.splice(idxToDel, 1);
}
console.log('['+ data.id +'] disconnect complete');
}
......
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