Skip to content

Commit

Permalink
Bug 738395: Characters should never get stuck if diagonally adjacent …
Browse files Browse the repository at this point in the history
…to their target
  • Loading branch information
sork committed Mar 24, 2012
1 parent 3f97029 commit c8d5679
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/js/entity.js
Expand Up @@ -211,6 +211,10 @@ define(function() {
return result;
},

isDiagonallyAdjacent: function(entity) {
return this.isAdjacent(entity) && !this.isAdjacentNonDiagonal(entity);
},

forEachAdjacentNonDiagonalPosition: function(callback) {
callback(this.gridX - 1, this.gridY, Types.Orientations.LEFT);
callback(this.gridX, this.gridY - 1, Types.Orientations.UP);
Expand Down
12 changes: 12 additions & 0 deletions client/js/game.js
Expand Up @@ -2032,7 +2032,12 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT

if(character.canAttack(time)) {
if(!isMoving) { // don't hit target if moving to a different tile.
if(character.hasTarget() && character.getOrientationTo(character.target) !== character.orientation) {
character.lookAtTarget();
}

character.hit();

if(character.id === this.playerId) {
this.client.sendHit(character.target);
}
Expand All @@ -2045,6 +2050,13 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
this.client.sendHurt(character);
}
}
} else {
if(character.hasTarget()
&& character.isDiagonallyAdjacent(character.target)
&& character.target instanceof Player
&& !character.target.isMoving()) {
character.follow(character.target);
}
}
}
},
Expand Down

0 comments on commit c8d5679

Please sign in to comment.