|
@@ -108,38 +108,44 @@ class Thing implements Printable {
|
|
|
|
|
|
// TODO: Make sure you never bring back a fodder Room - these disappear between games and we don't want to lose Things in them.
|
|
|
this.addGetAlterations((thing : Thing) => {
|
|
|
- function getClosestRoom (currentRoom : RoomRandom, rooms : Array<RoomRandom>) {
|
|
|
- if (currentRoom instanceof RoomRandom && rooms.length > 0) {
|
|
|
- rooms.sort((a : RoomRandom, b : RoomRandom) => {
|
|
|
- if (!(a instanceof RoomRandom)) return -1;
|
|
|
- if (!(b instanceof RoomRandom)) return 1;
|
|
|
- let da = a.getDistanceTo(<RoomRandom> currentRoom);
|
|
|
- let db = b.getDistanceTo(<RoomRandom> currentRoom);
|
|
|
- return da - db;
|
|
|
- });
|
|
|
- return {
|
|
|
- Location : rooms[0].getName()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
if (Thing.EnclosedRelation.getLeft(thing) == thing.getRoom() && thing.getRoom() != undefined) {
|
|
|
if (thing.getRoom().fodder) {
|
|
|
if (thing.isPlayer()) {
|
|
|
// put at closest remembered room
|
|
|
- let rooms = WorldState.getRememberedRoomsAsRooms();
|
|
|
- let currentRoom = thing.getRoom();
|
|
|
- return getClosestRoom(<RoomRandom> currentRoom, <Array<RoomRandom>> rooms);
|
|
|
+ let rooms = WorldState.getRememberedRoomsAsRooms().filter((room : Room) => { return !(room instanceof RoomRandomFodder);});
|
|
|
+ let room : Room;
|
|
|
+ if (rooms.length <= 0) {
|
|
|
+ // Find Closest visited room
|
|
|
+ rooms = Region.InRelation.getLeft(thing.getRoom()).getRooms().filter(room => {return room.visited && !room.fodder && room.placed;}).sort((rooma, roomb) => {
|
|
|
+ if (rooma instanceof RoomRandom && roomb instanceof RoomRandom) {
|
|
|
+ let da = rooma.getDistanceTo(<RoomRandom> thing.getRoom());
|
|
|
+ let db = roomb.getDistanceTo(<RoomRandom> thing.getRoom());
|
|
|
+ return da - db;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ if (rooms.length > 0) {
|
|
|
+ room = rooms[0]; // freshest room
|
|
|
+ } else {
|
|
|
+ room = PlayBegins.startingRoom; // back to square one
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ Location : room.getName()
|
|
|
+ }
|
|
|
} else {
|
|
|
// put at closest room
|
|
|
- let rooms = thing.getRoom().getConnectedRooms();
|
|
|
- let currentRoom = thing.getRoom();
|
|
|
- let foundRoom = getClosestRoom(<RoomRandom> currentRoom, <Array<RoomRandom>> rooms);
|
|
|
- if (foundRoom != undefined) {
|
|
|
- return foundRoom;
|
|
|
- } else {
|
|
|
- rooms = (<Region> Region.InRelation.getLeft(thing.getRoom())).getRooms();
|
|
|
- return getClosestRoom(<RoomRandom> currentRoom, <Array<RoomRandom>> rooms);
|
|
|
+ let rooms = Region.InRelation.getLeft(thing.getRoom()).getRooms().filter(room => {return !room.fodder && room.placed;}).sort((rooma, roomb) => {
|
|
|
+ if (rooma instanceof RoomRandom && roomb instanceof RoomRandom) {
|
|
|
+ let da = rooma.getDistanceTo(<RoomRandom> thing.getRoom());
|
|
|
+ let db = roomb.getDistanceTo(<RoomRandom> thing.getRoom());
|
|
|
+ return da - db;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ });
|
|
|
+ return {
|
|
|
+ Location : rooms[0].getName()
|
|
|
}
|
|
|
}
|
|
|
} else {
|