Skip to content

Commit

Permalink
fix undefined bug, change ai to headless
Browse files Browse the repository at this point in the history
  • Loading branch information
conwayok committed Jun 29, 2020
1 parent 4b3616d commit 43bdaf0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/client/mp_ai.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<script>
const config = {
type: Phaser.AUTO,
type: Phaser.HEADLESS,
width: 2560,
height: 1440,
physics: {
Expand Down
12 changes: 8 additions & 4 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ io.on('connection', function (socket) {

socket.on(PLAYER_DIE_EVENT, function () {
let player = PLAYERS[uid];
player.isDead = true;
spawnXp(player.x, player.y, player.totalXp);
socket.broadcast.emit(PLAYER_DIE_EVENT, uid);
if (player !== undefined) {
player.isDead = true;
spawnXp(player.x, player.y, player.totalXp);
socket.broadcast.emit(PLAYER_DIE_EVENT, uid);
}
});

socket.on(PLAYER_SPAWN_EVENT, function (pos) {
Expand Down Expand Up @@ -152,7 +154,9 @@ io.on('connection', function (socket) {
setInterval(serverCleaner, 3000);

function serverCleaner () {
if (io.engine.clientsCount === 0)
if (io.engine.clientsCount === 0 &&
Object.keys(PLAYERS).length > 0 &&
PLAYERS.constructor === Object)
resetServer();
}

Expand Down

0 comments on commit 43bdaf0

Please sign in to comment.