From 2a4327c5cf9947e033ea630a02e0606c13443354 Mon Sep 17 00:00:00 2001 From: Jeena Date: Mon, 20 Jan 2014 18:44:58 +0100 Subject: [PATCH] added inheritance to last moved Item --- app/Game/Core/GameObjects/Item.js | 10 +++++----- app/Game/Server/GameObjects/Item.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/Game/Core/GameObjects/Item.js b/app/Game/Core/GameObjects/Item.js index b8eb2ec..667c3f1 100644 --- a/app/Game/Core/GameObjects/Item.js +++ b/app/Game/Core/GameObjects/Item.js @@ -60,13 +60,9 @@ function (Parent, Box2D, Settings) { fixtureDef.isSensor = false; - /* fixtureDef.userData = { - onCollisionChange: function(isColliding, fixture) { - self.onFixtureWithinReach(isColliding, "right", fixture); - } + onCollisionChange: this.onCollisionChange.bind(this) } - */ this.body.CreateFixture(fixtureDef); } @@ -84,6 +80,10 @@ function (Parent, Box2D, Settings) { Item.prototype.beingReleased = function(player) { // overwrite if necessary }; + + Item.prototype.onCollisionChange = function(isColliding, fixture, info) { + // overwrite if necessary + }; return Item; diff --git a/app/Game/Server/GameObjects/Item.js b/app/Game/Server/GameObjects/Item.js index 6fbcc97..dcf28ef 100755 --- a/app/Game/Server/GameObjects/Item.js +++ b/app/Game/Server/GameObjects/Item.js @@ -54,6 +54,34 @@ function (Parent) { } }; + Item.prototype.onCollisionChange = function(isColliding, fixture) { + + if(isColliding) { + var otherBody = fixture.GetBody(); + if(otherBody) { + var otherItem = otherBody.GetUserData(); + if(otherItem instanceof Item) { + if(!this.lastMoved && !otherItem.lastMoved) return; + + if(this.lastMoved && otherItem.lastMoved) { + if(this.lastMoved.timestamp > otherItem.lastMoved.timestamp) { + this.setLastMovedBy(otherItem.lastMoved.player); + } else { + otherItem.setLastMovedBy(this.lastMoved.player); + } + } else { + if(!this.lastMoved) { + this.setLastMovedBy(otherItem.lastMoved.player); + } else { + otherItem.setLastMovedBy(this.lastMoved.player); + } + } + } + } + } + } + + return Item; });