diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MapController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MapController.java index bfee4373c..4ad1d9abb 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MapController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MapController.java @@ -1,5 +1,7 @@ package com.gpl.rpg.AndorsTrail.controller; +import java.util.List; + import android.content.res.Resources; import com.gpl.rpg.AndorsTrail.context.ControllerContext; import com.gpl.rpg.AndorsTrail.context.WorldContext; @@ -30,26 +32,31 @@ public final class MapController { } public void handleMapEventsAfterMovement(PredefinedMap currentMap, Coord newPosition, Coord lastPosition) { - // We don't allow event objects to overlap, so there can only be one object returned here. - MapObject mapObject = currentMap.getEventObjectAt(newPosition); - if (mapObject == null) return; + // Several map objects can now overlap. Inactive ones won't be returned by getActiveEventObjectsAt() + List objects = currentMap.getActiveEventObjectsAt(newPosition); + if (objects == null) return; + for (MapObject mapObject : objects) { - switch (mapObject.evaluateWhen) { + switch (mapObject.evaluateWhen) { case afterEveryRound: return; case whenEntering: // Do not trigger event if the player already was on the same MapObject before. if (mapObject.position.contains(lastPosition)) return; break; + } + handleMapEvent(mapObject, newPosition); } - handleMapEvent(mapObject, newPosition); } public void handleMapEvents(PredefinedMap currentMap, Coord position, MapObject.MapObjectEvaluationType evaluationType) { - MapObject mapObject = currentMap.getEventObjectAt(position); - if (mapObject == null) return; - if (mapObject.evaluateWhen != evaluationType) return; - handleMapEvent(mapObject, position); + List objects = currentMap.getActiveEventObjectsAt(position); + if (objects == null) return; + for (MapObject mapObject : objects) { + if (mapObject == null) return; + if (mapObject.evaluateWhen != evaluationType) return; + handleMapEvent(mapObject, position); + } } private void handleMapEvent(MapObject o, Coord position) { @@ -75,6 +82,7 @@ public final class MapController { } private boolean shouldHandleMapEvent(MapObject mapObject) { + if (!mapObject.isActive) return false; if (world.model.uiSelections.isInCombat) { // Only "script" events may run while in combat. if (mapObject.type != MapObject.MapObjectType.script) return false; diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MonsterMovementController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MonsterMovementController.java index f001a6ef4..dff957764 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MonsterMovementController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MonsterMovementController.java @@ -1,5 +1,7 @@ package com.gpl.rpg.AndorsTrail.controller; +import java.util.List; + import com.gpl.rpg.AndorsTrail.context.ControllerContext; import com.gpl.rpg.AndorsTrail.context.WorldContext; import com.gpl.rpg.AndorsTrail.controller.PathFinder.EvaluateWalkable; @@ -57,10 +59,15 @@ public final class MonsterMovementController implements EvaluateWalkable { if (!tilemap.isWalkable(p)) return false; } if (map.getMonsterAt(p) != null) return false; - MapObject m = map.getEventObjectAt(p.topLeft); - if (m != null) { - if (m.type == MapObject.MapObjectType.newmap) return false; - if (m.type == MapObject.MapObjectType.keyarea) return false; + //There can be several objects at the same place ! + List objects = map.getActiveEventObjectsAt(p.topLeft); + if (objects != null) { + for (MapObject m : objects) { + if (m != null) { + if (m.type == MapObject.MapObjectType.newmap) return false; + if (m.type == MapObject.MapObjectType.keyarea) return false; + } + } } return true; } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java index c8946ed77..b9f778e01 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java @@ -65,6 +65,10 @@ public final class MovementController implements TimedMessageTask.Callback { L.log("Cannot find place " + placeName + " of type " + objectType + " in map " + mapName); return; } + if (!place.isActive) { + L.log("Place " + placeName + " of type " + objectType + " in map " + mapName + " cannot be used as it is inactive"); + return; + } final ModelContainer model = world.model; if (model.currentMap != null) model.currentMap.updateLastVisitTime(); @@ -90,12 +94,13 @@ public final class MovementController implements TimedMessageTask.Callback { final ModelContainer model = world.model; model.currentMap = newMap; cacheCurrentMapData(res, newMap); + //Apply replacements before spawning, so that MonsterSpawnArea's isActive variable is up to date. + controllers.mapController.applyCurrentMapReplacements(res, false); if (spawnMonsters) { if (!newMap.isRecentlyVisited()) { controllers.monsterSpawnController.spawnAll(newMap, model.currentTileMap); } } - controllers.mapController.applyCurrentMapReplacements(res, false); controllers.mapController.prepareScriptsOnCurrentMap(); newMap.visited = true; newMap.updateLastVisitTime(); @@ -213,6 +218,7 @@ public final class MovementController implements TimedMessageTask.Callback { final Coord newPosition = player.nextPosition; for (MapObject o : currentMap.eventObjects) { + if (!o.isActive) continue; if (o.type == MapObject.MapObjectType.keyarea) { if (o.position.contains(newPosition)) { if (!controllers.mapController.canEnterKeyArea(o)) return; @@ -278,6 +284,7 @@ public final class MovementController implements TimedMessageTask.Callback { private static Coord getFirstMapChangeAreaPosition(PredefinedMap map) { for (MapObject o : map.eventObjects) { + if (!o.isActive) continue; if (o.type == MapObject.MapObjectType.newmap) return o.position.topLeft; } return null; diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapObject.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapObject.java index 2d94613ef..8b91758fe 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapObject.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapObject.java @@ -30,6 +30,7 @@ public final class MapObject { public final Requirement enteringRequirement; public final DropList dropList; public final MapObjectEvaluationType evaluateWhen; + public boolean isActive = true; private MapObject( final CoordRect position diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MonsterSpawnArea.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MonsterSpawnArea.java index c22f7a411..2444f43a9 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MonsterSpawnArea.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MonsterSpawnArea.java @@ -21,6 +21,7 @@ public final class MonsterSpawnArea { public final ArrayList monsters = new ArrayList(); public final boolean isUnique; // unique == non-respawnable public final String group; + public boolean isActive = true; public MonsterSpawnArea(CoordRect area, Range quantity, Range spawnChance, String[] monsterTypeIDs, boolean isUnique, String group) { this.area = area; @@ -77,6 +78,7 @@ public final class MonsterSpawnArea { public boolean isSpawnable(boolean includeUniqueMonsters) { if (isUnique && !includeUniqueMonsters) return false; + if (!isActive) return false; return quantity.current < quantity.max; } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java index 94491b493..e18b9cf3e 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java @@ -17,6 +17,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.List; public final class PredefinedMap { private static final long VISIT_RESET = 0; @@ -62,20 +63,25 @@ public final class PredefinedMap { public MapObject findEventObject(MapObject.MapObjectType objectType, String name) { for (MapObject o : eventObjects) { + if (!o.isActive) continue; if (o.type == objectType && name.equals(o.id)) return o; } return null; } - public MapObject getEventObjectAt(final Coord p) { + public List getActiveEventObjectsAt(final Coord p) { + List result = null; for (MapObject o : eventObjects) { + if (!o.isActive) continue; if (o.position.contains(p)) { - return o; + if (result == null) result = new ArrayList(); + result.add(o); } } - return null; + return result; } public boolean hasContainerAt(final Coord p) { for (MapObject o : eventObjects) { + if (!o.isActive) continue; if (o.type == MapObject.MapObjectType.container) { if (o.position.contains(p)) { return true; @@ -177,6 +183,8 @@ public final class PredefinedMap { public void createAllContainerLoot() { for (MapObject o : eventObjects) { + //TODO : Don't forget to create loot on container activation once implemented + if (!o.isActive) continue; if (o.type == MapObject.MapObjectType.container) { Loot bag = getBagOrCreateAt(o.position.topLeft); o.dropList.createRandomLoot(bag, null);