mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-02-23 15:38:29 +01:00
MapObject & MonsterSpawnArea can be activated/deactivated using theisActive boolean.
No handle exist yet to deactivate these areas. Deactivated areas are never returned by PredefinedMap API. Inactive container areas' Loot are not created on createAllContainerLoot() calls. Think of creating it on area activation when implemented (TODO label placed in the code to never forget :p) Updated comment; fixed old, one-object processing to better match the List type.
This commit is contained in:
@@ -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<MapObject> 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<MapObject> 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;
|
||||
|
||||
@@ -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<MapObject> 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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -21,6 +21,7 @@ public final class MonsterSpawnArea {
|
||||
public final ArrayList<Monster> monsters = new ArrayList<Monster>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<MapObject> getActiveEventObjectsAt(final Coord p) {
|
||||
List<MapObject> result = null;
|
||||
for (MapObject o : eventObjects) {
|
||||
if (!o.isActive) continue;
|
||||
if (o.position.contains(p)) {
|
||||
return o;
|
||||
if (result == null) result = new ArrayList<MapObject>();
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user