cleared items of player fingerprints (lastMovedBy). fixes #92

This commit is contained in:
Logsol 2015-05-03 12:45:35 +02:00
parent bd7edc779e
commit 6233588e63
4 changed files with 23 additions and 102 deletions

View file

@ -5,10 +5,11 @@ define([
"Lib/Utilities/NotificationCenter",
"Game/" + GLOBALS.context + "/GameObjects/Doll",
"Game/" + GLOBALS.context + "/GameObjects/GameObject",
"Lib/Utilities/Assert"
"Game/" + GLOBALS.context + "/GameObjects/Item",
"Lib/Utilities/Assert",
],
function (PhysicsEngine, TiledLevel, Player, Nc, Doll, GameObject, Assert) {
function (PhysicsEngine, TiledLevel, Player, Nc, Doll, GameObject, Item, Assert) {
"use strict";
@ -126,6 +127,8 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll, GameObject, Assert) {
console.warn("User (", userId ,") left who has not joined");
return;
}
this.clearItemsOfPlayerFingerPrints(player);
player.destroy();
delete this.players[userId];
@ -137,6 +140,20 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll, GameObject, Assert) {
return player;
};
GameController.prototype.clearItemsOfPlayerFingerPrints = function(player) {
for (var key in this.gameObjects) {
for (var i = 0; i < this.gameObjects[key].length; i++) { // to go through animated and fixed.
var gameObject = this.gameObjects[key][i];
if (gameObject instanceof Item) {
if (gameObject.getLastMovedBy() && gameObject.getLastMovedBy().player === player) {
gameObject.setLastMovedBy(null);
}
}
}
}
};
GameController.prototype.destroy = function () {
var i = 0;
@ -149,7 +166,6 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll, GameObject, Assert) {
// try using a real gameobject for the health bar
}*/
for (i = 0; i < this.ncTokens.length; i++) {
Nc.off(this.ncTokens[i]);
}