mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-12 02:57:34 +00:00
added ASSERT, fixed #103
This commit is contained in:
parent
55eff36f34
commit
dfa71bc8e5
17 changed files with 249 additions and 153 deletions
|
|
@ -6,6 +6,8 @@ define([
|
|||
],
|
||||
|
||||
function(Parent, Nc, Parser, Settings) {
|
||||
|
||||
"use strict";
|
||||
|
||||
function PlayerController(player) {
|
||||
|
||||
|
|
@ -33,6 +35,9 @@ function(Parent, Nc, Parser, Settings) {
|
|||
};
|
||||
|
||||
PlayerController.prototype.handActionRequest = function(options) {
|
||||
options.x = parseFloat(options.x) || 0;
|
||||
options.y = parseFloat(options.y) || 0;
|
||||
options.av = parseFloat(options.av) || 0;
|
||||
if (options) this.player.handActionRequest(options);
|
||||
};
|
||||
|
||||
|
|
@ -43,21 +48,21 @@ function(Parent, Nc, Parser, Settings) {
|
|||
PlayerController.prototype.mePositionStateUpdate = function(update) {
|
||||
|
||||
if(!this.player.doll) {
|
||||
console.warn('me state update, even though doll does not exist');
|
||||
console.warn("me state update, even though doll does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
var difference = {
|
||||
x: Math.abs(update.p.x - this.player.doll.body.GetPosition().x),
|
||||
y: Math.abs(update.p.y - this.player.doll.body.GetPosition().y)
|
||||
}
|
||||
};
|
||||
|
||||
if(true || difference.x < Settings.PUNKBUSTER_DIFFERENCE_METERS
|
||||
&& difference.y < Settings.PUNKBUSTER_DIFFERENCE_METERS) {
|
||||
if(true || difference.x < Settings.PUNKBUSTER_DIFFERENCE_METERS &&
|
||||
difference.y < Settings.PUNKBUSTER_DIFFERENCE_METERS) {
|
||||
this.player.doll.updatePositionState(update);
|
||||
} else {
|
||||
// HARD UPDATE FOR SELF
|
||||
console.log(this.player.user.options.nickname + ' is cheating.')
|
||||
console.log(this.player.user.options.nickname + " is cheating.");
|
||||
|
||||
var body = this.player.doll.body;
|
||||
|
||||
|
|
@ -66,7 +71,7 @@ function(Parent, Nc, Parser, Settings) {
|
|||
lv: body.GetLinearVelocity()
|
||||
};
|
||||
|
||||
Nc.trigger(Nc.ns.channel.to.client.user.gameCommand.send + this.player.id, 'positionStateReset', options);
|
||||
Nc.trigger(Nc.ns.channel.to.client.user.gameCommand.send + this.player.id, "positionStateReset", options);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@ define([
|
|||
"Game/Core/GameObjects/Doll",
|
||||
"Game/Channel/GameObjects/Item",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Lib/Utilities/NotificationCenter"
|
||||
"Lib/Utilities/NotificationCenter",
|
||||
"Lib/Utilities/Assert"
|
||||
],
|
||||
|
||||
function (Parent, Item, Box2D, Nc) {
|
||||
function (Parent, Item, Box2D, Nc, Assert) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
|
@ -15,7 +16,7 @@ function (Parent, Item, Box2D, Nc) {
|
|||
|
||||
Doll.prototype = Object.create(Parent.prototype);
|
||||
|
||||
Doll.prototype.findCloseItem = function(x, y) {
|
||||
Doll.prototype.findCloseItem = function(x) {
|
||||
|
||||
var self = this;
|
||||
|
||||
|
|
@ -33,7 +34,7 @@ function (Parent, Item, Box2D, Nc) {
|
|||
} else {
|
||||
return findItem(this.reachableItems.right);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.onImpact = function(isColliding, fixture) {
|
||||
var self = this;
|
||||
|
|
@ -52,7 +53,7 @@ function (Parent, Item, Box2D, Nc) {
|
|||
|
||||
var b2Math = Box2D.Common.Math.b2Math;
|
||||
|
||||
var absItemVelocity = b2Math.AbsV(itemVelocity)
|
||||
var absItemVelocity = b2Math.AbsV(itemVelocity);
|
||||
var max = 1;
|
||||
|
||||
if(absItemVelocity.x > max || absItemVelocity.y > max) {
|
||||
|
|
@ -71,9 +72,9 @@ function (Parent, Item, Box2D, Nc) {
|
|||
|
||||
var callback = function() {
|
||||
self.player.addDamage(damage, player, item);
|
||||
}
|
||||
};
|
||||
|
||||
Nc.trigger(Nc.ns.channel.engine.worldQueue.add, callback)
|
||||
Nc.trigger(Nc.ns.channel.engine.worldQueue.add, callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -81,10 +82,12 @@ function (Parent, Item, Box2D, Nc) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.updatePositionState = function(update) {
|
||||
if(!this.isAnotherPlayerNearby()) {
|
||||
Assert.number(update.p.x, update.p.y);
|
||||
Assert.number(update.lv.x, update.lv.y);
|
||||
this.body.SetAwake(true);
|
||||
this.body.SetPosition(update.p);
|
||||
this.body.SetLinearVelocity(update.lv);
|
||||
|
|
|
|||
|
|
@ -21,14 +21,14 @@ function (Parent) {
|
|||
this.lastMoved = {
|
||||
player: player,
|
||||
timestamp: new Date()
|
||||
}
|
||||
};
|
||||
} else {
|
||||
this.lastMoved = null;
|
||||
}
|
||||
};
|
||||
|
||||
Item.prototype.isGrabbingAllowed = function(player) {
|
||||
return this.heldByPlayers.length == 0;
|
||||
Item.prototype.isGrabbingAllowed = function(player) { // jshint unused:false
|
||||
return this.heldByPlayers.length === 0;
|
||||
};
|
||||
|
||||
Item.prototype.beingGrabbed = function(player) {
|
||||
|
|
@ -40,7 +40,7 @@ function (Parent) {
|
|||
}
|
||||
};
|
||||
|
||||
Item.prototype.isReleasingAllowed = function(player) {
|
||||
Item.prototype.isReleasingAllowed = function(player) { // jshint unused:false
|
||||
return true;
|
||||
};
|
||||
|
||||
|
|
@ -81,8 +81,7 @@ function (Parent) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
return Item;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ function (Parent, Nc) {
|
|||
if (isHolding) {
|
||||
item = this.holdingItem;
|
||||
} else {
|
||||
item = this.doll.findCloseItem(options.x, options.y);
|
||||
item = this.doll.findCloseItem(options.x);
|
||||
}
|
||||
|
||||
if(item) {
|
||||
this.handAction(options, isHolding, item);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.handAction = function(options, isHolding, item) {
|
||||
|
||||
|
|
@ -110,8 +110,7 @@ function (Parent, Nc) {
|
|||
stats: this.stats
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
return Player;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue