From 716b96b6245d065ee55d956272ea9bbf2422073e Mon Sep 17 00:00:00 2001 From: Zukero Date: Mon, 2 Oct 2017 19:04:27 +0200 Subject: [PATCH] Even a NPC with a 1x1 spawn area can track a player down. --- AndorsTrail/res/raw/monsterlist_debug.json | 2 ++ .../controller/MonsterMovementController.java | 22 ++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/AndorsTrail/res/raw/monsterlist_debug.json b/AndorsTrail/res/raw/monsterlist_debug.json index 81dcb97d8..bfad50ac0 100644 --- a/AndorsTrail/res/raw/monsterlist_debug.json +++ b/AndorsTrail/res/raw/monsterlist_debug.json @@ -13,6 +13,7 @@ "attackChance": 50, "droplistID": "debugshop1", "phraseID": "debugshop", + "movementAggressionType":"wholeMap", "attackDamage": { "min": 1, "max": 2 @@ -85,6 +86,7 @@ "attackCost": 10, "attackChance": 50, "droplistID": "debuglist1", + "movementAggressionType":"wholeMap", "attackDamage": { "min": 1, "max": 2 diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MonsterMovementController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MonsterMovementController.java index 145a4aca4..2759de0bb 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MonsterMovementController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MonsterMovementController.java @@ -76,15 +76,7 @@ public final class MonsterMovementController implements EvaluateWalkable { PredefinedMap map = world.model.currentMap; LayeredTileMap tileMap = world.model.currentTileMap; m.nextActionTime = System.currentTimeMillis() + getMillisecondsPerMove(m); - if (m.movementDestination == null) { - // Monster has waited and should start to move again. - m.movementDestination = new Coord(m.position); - if (Constants.rnd.nextBoolean()) { - m.movementDestination.x = area.area.topLeft.x + Constants.rnd.nextInt(area.area.size.width); - } else { - m.movementDestination.y = area.area.topLeft.y + Constants.rnd.nextInt(area.area.size.height); - } - } else if (m.position.equals(m.movementDestination)) { + if (m.movementDestination != null && m.position.equals(m.movementDestination)) { // Monster has been moving and arrived at the destination. cancelCurrentMonsterMovement(m); } else { @@ -119,7 +111,17 @@ public final class MonsterMovementController implements EvaluateWalkable { if (findPathFor(m, playerPosition)) return; } // } - + + // Monster has waited and should start to move again. + if (m.movementDestination == null) { + m.movementDestination = new Coord(m.position); + if (Constants.rnd.nextBoolean()) { + m.movementDestination.x = area.area.topLeft.x + Constants.rnd.nextInt(area.area.size.width); + } else { + m.movementDestination.y = area.area.topLeft.y + Constants.rnd.nextInt(area.area.size.height); + } + } + // Monster is moving in a straight line. m.nextPosition.topLeft.set( m.position.x + sgn(m.movementDestination.x - m.position.x)