Reporting works but guards don't anymore
This commit is contained in:
@@ -911,7 +911,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.path_set = function(target, force, maxsteps) {
|
this.path_set = function(target, force, maxsteps) {
|
||||||
maxsteps = (typeof maxsteps == undefined ? this.path_maximum_steps : maxsteps);
|
maxsteps = (typeof maxsteps == undefined ? maxsteps : this.path_maximum_steps);
|
||||||
force = ( typeof force == undefined ? false : force );
|
force = ( typeof force == undefined ? false : force );
|
||||||
if ( force == false &&
|
if ( force == false &&
|
||||||
this.path.length > 0 &&
|
this.path.length > 0 &&
|
||||||
@@ -919,14 +919,16 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.path_purge();
|
this.path_purge();
|
||||||
|
var pos = nearestWalkableTile(target);
|
||||||
tpath = pathfinder.findPath(
|
tpath = pathfinder.findPath(
|
||||||
parseInt(this.x/32),
|
parseInt(this.x/32),
|
||||||
parseInt(this.y/32),
|
parseInt(this.y/32),
|
||||||
parseInt(target.x/32),
|
pos[0],
|
||||||
parseInt(target.y/32),
|
pos[1],
|
||||||
pathfinder_grid.clone()
|
pathfinder_grid.clone()
|
||||||
);
|
);
|
||||||
prevpoint = [this.x, this.y];
|
prevpoint = [this.x, this.y];
|
||||||
|
console.log("New path has at most " + maxsteps + " steps in it");
|
||||||
for ( var i = 0 ; i < Math.min(maxsteps, tpath.length) ; i++ ) {
|
for ( var i = 0 ; i < Math.min(maxsteps, tpath.length) ; i++ ) {
|
||||||
if ( (prevpoint[0]+prevpoint[1]) == ((tpath[i][0]*32)+(tpath[i][1]*32)) )
|
if ( (prevpoint[0]+prevpoint[1]) == ((tpath[i][0]*32)+(tpath[i][1]*32)) )
|
||||||
continue;
|
continue;
|
||||||
@@ -1062,24 +1064,17 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
this.target = nearestInGroup(this, aiSprites, "townsfolk-guard");
|
this.target = nearestInGroup(this, aiSprites, "townsfolk-guard");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( this.target !== null ) {
|
if ( this.target !== null &&
|
||||||
var targetseesyou = false;
|
hasState(this, STATE_RUNNINGTOLIGHT) == false ) {
|
||||||
if (this.target.canSeeSprite) {
|
if ( (game.physics.arcade.collide(this, this.target) == true) ) {
|
||||||
if (this.target.canSeeSprite(this) == true)
|
this.path_tween_stop();
|
||||||
targetseesyou = true;
|
this.path_purge();
|
||||||
}
|
var staticLights = game.state.states.game.staticLights;
|
||||||
if ( (game.physics.arcade.collide(this, this.target) == true) ||
|
this.target = nearestInGroup(this, staticLights);
|
||||||
targetseesyou == true ) {
|
console.log("Running to the nearest light");
|
||||||
if ( hasState(this, STATE_RUNNINGTOLIGHT) == false ) {
|
console.log(this.target);
|
||||||
this.path_tween_stop();
|
addState(this, STATE_RUNNINGTOLIGHT);
|
||||||
this.path_purge();
|
}
|
||||||
var staticLights = game.state.states.game.staticLights;
|
|
||||||
this.target = nearestInGroup(this, staticLights);
|
|
||||||
console.log("Running to the nearest light");
|
|
||||||
console.log(this.target);
|
|
||||||
addState(this, STATE_RUNNINGTOLIGHT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.chasetarget(this.target,
|
this.chasetarget(this.target,
|
||||||
STATE_ALERTED,
|
STATE_ALERTED,
|
||||||
STATE_MOVING | STATE_RUNNING,
|
STATE_MOVING | STATE_RUNNING,
|
||||||
@@ -1263,6 +1258,46 @@ function nearestInGroup(sprite, group, sprite_group) {
|
|||||||
return nearest;
|
return nearest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nearestWalkableTile(spr)
|
||||||
|
{
|
||||||
|
function _walkable_inner(multiplier) {
|
||||||
|
var startx = parseInt(Math.max((spr.x / 32) - (1 * multiplier), 0));
|
||||||
|
var starty = parseInt(Math.max((spr.y / 32) - (1 * multiplier), 0));
|
||||||
|
var endx = parseInt(Math.min((spr.x / 32) + 1 + (1 * multiplier), game.state.states.game.map.width));
|
||||||
|
var endy = parseInt(Math.min((spr.y / 32) + 1 + (1 * multiplier), game.state.states.game.map.width));
|
||||||
|
|
||||||
|
for ( var x = startx ; x <= endx ; x++ ) {
|
||||||
|
for ( var y = starty ; y <= endy ; y++ ) {
|
||||||
|
if ( (x == startx && y == starty) ||
|
||||||
|
(x == startx && y == endy) ||
|
||||||
|
(y == starty) ||
|
||||||
|
(y == endy) ) {
|
||||||
|
console.log(pathfinder_grid);
|
||||||
|
if ( pathfinder_grid.nodes[x][y].walkable == true ) {
|
||||||
|
console.log([x, y]);
|
||||||
|
return [x, y];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( var i = 1 ; i < 100 ; i++ ) {
|
||||||
|
var rv = _walkable_inner(i);
|
||||||
|
if ( rv !== null ) {
|
||||||
|
console.log("Found near walkable tile");
|
||||||
|
console.log([rv] + [spr.x / 32, spr.y / 32]);
|
||||||
|
return rv
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//if ( multiplier >= 10 )
|
||||||
|
console.log("Couldn't find a near walkable tile");
|
||||||
|
console.log([spr.x / 32, spr.y / 32]);
|
||||||
|
return [parseInt(spr.x / 32), parseInt(spr.y / 32)];
|
||||||
|
//return nearestWalkableTile(spr, multiplier + 1);
|
||||||
|
}
|
||||||
|
|
||||||
function addAnimation(obj, anim)
|
function addAnimation(obj, anim)
|
||||||
{
|
{
|
||||||
a = moonlightSettings['animations'][anim]
|
a = moonlightSettings['animations'][anim]
|
||||||
|
|||||||
Reference in New Issue
Block a user