diff --git a/src/main/java/com/comandante/creeper/Main.java b/src/main/java/com/comandante/creeper/Main.java index 71a9d5df48445ac7f19fe87a95262a6d15213169..4a9596794d2e5170f4b3713adf99020a8cec1a47 100644 --- a/src/main/java/com/comandante/creeper/Main.java +++ b/src/main/java/com/comandante/creeper/Main.java @@ -102,7 +102,7 @@ public class Main { creeperCommandRegistry.addCommand(new MapCommand(gameManager)); - CreeperServer creeperServer = new CreeperServer(8080, db); + CreeperServer creeperServer = new CreeperServer(8081, db); startUpMessage("Creeper engine started"); creeperServer.run(gameManager); startUpMessage("Creeper online"); diff --git a/src/main/java/com/comandante/creeper/managers/GameManager.java b/src/main/java/com/comandante/creeper/managers/GameManager.java index 3e88ae60a80186dab67c118718229d744e47045b..8a3aa7b7ea5afc2b4550027f1c36dc3aaa45a124 100644 --- a/src/main/java/com/comandante/creeper/managers/GameManager.java +++ b/src/main/java/com/comandante/creeper/managers/GameManager.java @@ -13,10 +13,7 @@ import com.comandante.creeper.server.ChannelUtils; import com.comandante.creeper.server.Color; import com.comandante.creeper.server.CreeperSession; import com.comandante.creeper.server.MultiLineInputManager; -import com.comandante.creeper.world.FloorManager; -import com.comandante.creeper.world.MapsManager; -import com.comandante.creeper.world.Room; -import com.comandante.creeper.world.RoomManager; +import com.comandante.creeper.world.*; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Interners; @@ -24,6 +21,7 @@ import org.apache.commons.lang3.text.WordUtils; import org.jboss.netty.channel.MessageEvent; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; @@ -226,6 +224,22 @@ public class GameManager { } numExits++; } + if (room.getDownId().isPresent()) { + if (player.getReturnDirection().get().equalsIgnoreCase("down")) { + sb.append(BOLD_OFF); + sb.append("Down "); + sb.append(BOLD_ON); + } else { + sb.append("Down "); + } + numExits++; + } + if (room.getEnterExits() != null && room.getEnterExits().size() > 0) { + List<RemoteExit> enters = room.getEnterExits(); + for (RemoteExit enter: enters) { + sb.append("e-" + enter.getExitDetail() + " "); + } + } String fin = null; if (numExits == 1) { fin = sb.toString().replace(BOLD_OFF, BOLD_ON); diff --git a/src/main/java/com/comandante/creeper/server/command/MovementCommand.java b/src/main/java/com/comandante/creeper/server/command/MovementCommand.java index c5926ebb38c973c775769ed3c590936271cecabb..b66720a5f0312d5b3e6a8561213c8723982d8fa6 100644 --- a/src/main/java/com/comandante/creeper/server/command/MovementCommand.java +++ b/src/main/java/com/comandante/creeper/server/command/MovementCommand.java @@ -3,6 +3,7 @@ package com.comandante.creeper.server.command; import com.comandante.creeper.fight.FightManager; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.PlayerMovement; +import com.comandante.creeper.world.RemoteExit; import com.comandante.creeper.world.Room; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; @@ -22,8 +23,9 @@ public class MovementCommand extends Command { public final static List<String> westTriggers = Arrays.asList("w", "west".toLowerCase()); public final static List<String> upTriggers = Arrays.asList("u", "up".toLowerCase()); public final static List<String> downTriggers = Arrays.asList("d", "down".toLowerCase()); + public final static List<String> enterTriggers = Arrays.asList("enter", "enter".toLowerCase()); - public final static ImmutableList validTriggers = new ImmutableList.Builder<String>().addAll(northTriggers).addAll(southTriggers).addAll(eastTriggers).addAll(westTriggers).addAll(upTriggers).addAll(downTriggers).build(); + public final static ImmutableList validTriggers = new ImmutableList.Builder<String>().addAll(northTriggers).addAll(southTriggers).addAll(eastTriggers).addAll(westTriggers).addAll(upTriggers).addAll(downTriggers).addAll(enterTriggers).build(); public MovementCommand(GameManager gameManager) { super(gameManager, validTriggers, description); @@ -59,6 +61,15 @@ public class MovementCommand extends Command { } else if (downTriggers.contains(command.toLowerCase()) && currentRoom.getDownId().isPresent()) { Room destinationRoom = roomManager.getRoom(currentRoom.getDownId().get()); playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), this, "exited to the west.", "up"); + } else if (enterTriggers.contains(command.toLowerCase())) { + Optional<RemoteExit> remoteExitOptional = doesEnterExitExist(); + if (remoteExitOptional.isPresent()) { + Room destinationRoom = roomManager.getRoom(remoteExitOptional.get().getRoomId()); + playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), this, "entered " + remoteExitOptional.get().getDirection() + ".", "N/A"); + } else { + write("There's no where to go with that name. (" + command + ")"); + return; + } } else { write("There's no exit in that direction. (" + command + ")"); return; @@ -72,4 +83,14 @@ public class MovementCommand extends Command { super.messageReceived(ctx, e); } } + + private Optional<RemoteExit> doesEnterExitExist() { + String enterExitName = originalMessageParts.get(1); + for (RemoteExit remoteExit : currentRoom.getEnterExits()) { + if (remoteExit.getExitDetail().equals(enterExitName)) { + return Optional.of(remoteExit); + } + } + return Optional.absent(); + } } diff --git a/src/main/java/com/comandante/creeper/server/command/admin/BuildCommand.java b/src/main/java/com/comandante/creeper/server/command/admin/BuildCommand.java index 62db4fea4fb6b51782244754647229beb214fcfb..28e77388e664afe6f34cf28a9d7c195cf54c64bf 100644 --- a/src/main/java/com/comandante/creeper/server/command/admin/BuildCommand.java +++ b/src/main/java/com/comandante/creeper/server/command/admin/BuildCommand.java @@ -14,6 +14,7 @@ import com.comandante.creeper.world.Room; import com.comandante.creeper.world.WorldExporter; import com.google.common.base.Optional; import com.google.common.collect.Iterators; +import com.google.common.collect.Lists; import com.google.common.collect.Sets; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; @@ -63,8 +64,9 @@ public class BuildCommand extends Command { if (!currentRoom.getUpId().isPresent()) { Integer newRoomId = findUnusedRoomId(); Integer newFloorId = findUnusedFloorId(); - mapMatrix.addRemote(currentRoom.getRoomId(), new RemoteExit(RemoteExit.Direction.UP, newRoomId)); - FloorModel newFloorModel = newFloorModel(newFloorId, newRoomId, currentRoom.getRoomId(), RemoteExit.Direction.DOWN); + RemoteExit remoteExit = new RemoteExit(RemoteExit.Direction.UP, newRoomId, ""); + mapMatrix.addRemote(currentRoom.getRoomId(), remoteExit); + FloorModel newFloorModel = newFloorModel(newFloorId, newRoomId, currentRoom.getRoomId(), remoteExit); BasicRoom basicRoom = newBasic() .setRoomId(newRoomId) .setFloorId(newFloorId) @@ -84,8 +86,9 @@ public class BuildCommand extends Command { if (!currentRoom.getDownId().isPresent()) { Integer newRoomId = findUnusedRoomId(); Integer newFloorId = findUnusedFloorId(); - mapMatrix.addRemote(currentRoom.getRoomId(), new RemoteExit(RemoteExit.Direction.DOWN, newRoomId)); - FloorModel newFloorModel = newFloorModel(newFloorId, newRoomId, currentRoom.getRoomId(), RemoteExit.Direction.UP); + RemoteExit remoteExit = new RemoteExit(RemoteExit.Direction.DOWN, newRoomId, ""); + mapMatrix.addRemote(currentRoom.getRoomId(), remoteExit); + FloorModel newFloorModel = newFloorModel(newFloorId, newRoomId, currentRoom.getRoomId(), remoteExit); BasicRoom basicRoom = newBasic() .setRoomId(newRoomId) .setFloorId(newFloorId) @@ -101,6 +104,27 @@ public class BuildCommand extends Command { gameManager.currentRoomLogic(player.getPlayerId()); return; } + } else if (desiredBuildDirection.equalsIgnoreCase("enter")) { + String enterName = originalMessageParts.get(2); + Integer newRoomId = findUnusedRoomId(); + Integer newFloorId = findUnusedFloorId(); + RemoteExit remoteExit = new RemoteExit(RemoteExit.Direction.ENTER, newRoomId, enterName); + mapMatrix.addRemote(currentRoom.getRoomId(),remoteExit ); + FloorModel newFloorModel = newFloorModel(newFloorId, newRoomId, currentRoom.getRoomId(), remoteExit); + BasicRoom basicRoom = newBasic() + .setRoomId(newRoomId) + .setFloorId(newFloorId) + .addEnterExit(new RemoteExit(RemoteExit.Direction.ENTER, currentRoom.getRoomId(), "Leave")) + .createBasicRoom(); + currentRoom.addEnterExit(remoteExit); + entityManager.addEntity(basicRoom); + newFloorModel.setRoomModels(Sets.newHashSet(Iterators.transform(Sets.newHashSet(basicRoom).iterator(), WorldExporter.buildRoomModelsFromRooms()))); + floorManager.addFloor(newFloorModel.getId(), newFloorModel.getName()); + mapsManager.addFloorMatrix(newFloorModel.getId(), MapMatrix.createMatrixFromCsv(newFloorModel.getRawMatrixCsv())); + mapsManager.generateAllMaps(9, 9); + gameManager.movePlayer(new PlayerMovement(player, currentRoom.getRoomId(), basicRoom.getRoomId(), null, "", "")); + gameManager.currentRoomLogic(player.getPlayerId()); + return; } channelUtils.write(playerId, "Room already exists at that location."); } @@ -109,13 +133,16 @@ public class BuildCommand extends Command { } } - private FloorModel newFloorModel(Integer floorId, Integer newRoomId, Integer currentRoomId, RemoteExit.Direction returnDirection) { + private FloorModel newFloorModel(Integer floorId, Integer newRoomId, Integer currentRoomId, RemoteExit remoteExit) { FloorModel newFloorModel = new FloorModel(); + RemoteExit.Direction returnDirection = remoteExit.getDirection(); newFloorModel.setId(floorId); if (returnDirection.equals(RemoteExit.Direction.DOWN)) { newFloorModel.setRawMatrixCsv(Integer.toString(newRoomId) + "d" + currentRoomId); } else if (returnDirection.equals(RemoteExit.Direction.UP)) { newFloorModel.setRawMatrixCsv(Integer.toString(newRoomId) + "u" + currentRoomId); + } else if (returnDirection.equals(RemoteExit.Direction.ENTER)) { + newFloorModel.setRawMatrixCsv(Integer.toString(newRoomId) + "e" + currentRoomId + "ee" + remoteExit.getExitDetail()); } newFloorModel.setName(UUID.randomUUID().toString()); return newFloorModel; @@ -175,6 +202,7 @@ public class BuildCommand extends Command { if (mapMatrix.getWesternExit(room.getRoomId()) > 0) { room.setWestId(Optional.of(mapMatrix.getWesternExit(room.getRoomId()))); } + room.setEnterExits(Lists.<RemoteExit>newArrayList()); if (mapMatrix.getRemotes().containsKey(room.getRoomId())) { Set<RemoteExit> remoteExits = mapMatrix.getRemotes().get(room.getRoomId()); for (RemoteExit next : remoteExits) { @@ -182,6 +210,8 @@ public class BuildCommand extends Command { room.setUpId(Optional.of(next.getRoomId())); } else if (next.getDirection().equals(RemoteExit.Direction.DOWN)) { room.setDownId(Optional.of(next.getRoomId())); + } else if (next.getDirection().equals(RemoteExit.Direction.ENTER)) { + room.addEnterExit(next); } } } diff --git a/src/main/java/com/comandante/creeper/world/BasicRoom.java b/src/main/java/com/comandante/creeper/world/BasicRoom.java index fcc0e00c4b5678681a8e581c5d4380938cbf3cc7..faca5d81aefacb4c6b54f79d070fbae4b94894e8 100644 --- a/src/main/java/com/comandante/creeper/world/BasicRoom.java +++ b/src/main/java/com/comandante/creeper/world/BasicRoom.java @@ -2,6 +2,7 @@ package com.comandante.creeper.world; import com.google.common.base.Optional; +import java.util.List; import java.util.Set; public class BasicRoom extends Room { @@ -20,9 +21,10 @@ public class BasicRoom extends Room { Optional<Integer> westId, Optional<Integer> upId, Optional<Integer> downId, + List<RemoteExit> enterExits, String roomDescription, Set<String> roomTags, Set<Area> areas) { - super(roomId, roomTitle, floorId, northId, southId, eastId, westId, upId, downId, roomDescription, roomTags, areas); + super(roomId, roomTitle, floorId, northId, southId, eastId, westId, upId, downId, enterExits, roomDescription, roomTags, areas); } } diff --git a/src/main/java/com/comandante/creeper/world/BasicRoomBuilder.java b/src/main/java/com/comandante/creeper/world/BasicRoomBuilder.java index a038e11f3ddba9030c7cced03f872d6d2d5b5b03..b8097c73b55da360a737a41a8d52da65643f6bd3 100644 --- a/src/main/java/com/comandante/creeper/world/BasicRoomBuilder.java +++ b/src/main/java/com/comandante/creeper/world/BasicRoomBuilder.java @@ -1,8 +1,10 @@ package com.comandante.creeper.world; import com.google.common.base.Optional; +import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import java.util.List; import java.util.Set; public class BasicRoomBuilder { @@ -15,6 +17,7 @@ public class BasicRoomBuilder { private Optional<Integer> westId = Optional.absent(); private Optional<Integer> upId = Optional.absent(); private Optional<Integer> downId = Optional.absent(); + private List<RemoteExit> enterExits = Lists.newArrayList(); private String roomDescription; private Set<String> roomTags = Sets.newConcurrentHashSet(); private Set<Area> areas = Sets.newConcurrentHashSet(); @@ -80,7 +83,12 @@ public class BasicRoomBuilder { return this; } + public BasicRoomBuilder addEnterExit(RemoteExit remoteExit) { + this.enterExits.add(remoteExit); + return this; + } + public BasicRoom createBasicRoom() { - return new BasicRoom(roomId, roomTitle, floorId, northId, southId, eastId, westId, upId, downId, roomDescription, roomTags, areas); + return new BasicRoom(roomId, roomTitle, floorId, northId, southId, eastId, westId, upId, downId, enterExits, roomDescription, roomTags, areas); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/world/MapMatrix.java b/src/main/java/com/comandante/creeper/world/MapMatrix.java index 22d65247b0fd0d21be5f3f64867e7e493fce6a98..24b1c66be24326a67f5b5fea2e5c9cf3711be916 100644 --- a/src/main/java/com/comandante/creeper/world/MapMatrix.java +++ b/src/main/java/com/comandante/creeper/world/MapMatrix.java @@ -190,9 +190,12 @@ public class MapMatrix { if (remotes.containsKey(roomId)) { for (RemoteExit exit : remotes.get(roomId)) { if (exit.getDirection().equals(RemoteExit.Direction.UP)) { - sb.append("u").append(exit.getRoomId()); + sb.append("u|").append(exit.getRoomId()); } else if (exit.getDirection().equals(RemoteExit.Direction.DOWN)) { - sb.append("d").append(exit.getRoomId()); + sb.append("d|").append(exit.getRoomId()); + }else if (exit.getDirection().equals(RemoteExit.Direction.ENTER)) { + sb.append("e|").append(exit.getRoomId()); + sb.append("ee").append(exit.getExitDetail()); } } } @@ -205,7 +208,7 @@ public class MapMatrix { } private static Integer getUp(String csvInputCell) { - String[] us = csvInputCell.split("u"); + String[] us = csvInputCell.split("u|"); if (us[1].matches(".*[a-zA-Z]+.*")) { return Integer.valueOf(us[1].split("[a-zA-Z]")[0]); } @@ -213,13 +216,26 @@ public class MapMatrix { } private static Integer getDown(String csvInputCell) { - String[] us = csvInputCell.split("d"); + String[] us = csvInputCell.split("d|"); if (us[1].matches(".*[a-zA-Z]+.*")) { return Integer.valueOf(us[1].split("[a-zA-Z]")[0]); } return Integer.valueOf(us[1]); } + private static Integer getEnter(String csvInputCell) { + String[] us = csvInputCell.split("e|"); + if (us[1].matches(".*[a-zA-Z]+.*")) { + return Integer.valueOf(us[1].split("[a-zA-Z]")[0]); + } + return Integer.valueOf(us[1]); + } + + private static String getEnterDescription(String csvInputCell) { + String[] us = csvInputCell.split("ee"); + return us[1]; + } + public static MapMatrix createMatrixFromCsv(String mapCSV) { List<String> rows = Arrays.asList(mapCSV.split("\\r?\\n")); ArrayList<List<Integer>> rowsList = Lists.newArrayList(); @@ -230,13 +246,17 @@ public class MapMatrix { for (String string : strings) { if (!string.isEmpty()) { Integer roomId = Integer.parseInt(string.split("[a-zA-Z]")[0]); - if (string.contains("u")) { + if (string.contains("u|")) { Integer up = getUp(string); - addRemote(roomId, new RemoteExit(RemoteExit.Direction.UP, up), remotes); + addRemote(roomId, new RemoteExit(RemoteExit.Direction.UP, up, ""), remotes); } - if (string.contains("d")) { + if (string.contains("d|")) { Integer down = getDown(string); - addRemote(roomId, new RemoteExit(RemoteExit.Direction.DOWN, down), remotes); + addRemote(roomId, new RemoteExit(RemoteExit.Direction.DOWN, down, ""), remotes); + } + if (string.contains("e|")) { + Integer enter = getEnter(string); + addRemote(roomId, new RemoteExit(RemoteExit.Direction.ENTER, enter, getEnterDescription(string)), remotes); } data.add(roomId); } else { diff --git a/src/main/java/com/comandante/creeper/world/RemoteExit.java b/src/main/java/com/comandante/creeper/world/RemoteExit.java index 8cc7b6edd70cd73357575eec6c7d4de4708f15c8..2516f84f4d226675d9ce0ff7a5bac0370cb163cf 100644 --- a/src/main/java/com/comandante/creeper/world/RemoteExit.java +++ b/src/main/java/com/comandante/creeper/world/RemoteExit.java @@ -3,15 +3,17 @@ package com.comandante.creeper.world; public class RemoteExit { public enum Direction { - UP, DOWN + UP, DOWN, ENTER } private final Direction direction; private final Integer roomId; + private final String exitDetail; - public RemoteExit(Direction direction, Integer roomId) { + public RemoteExit(Direction direction, Integer roomId, String exitDetail) { this.direction = direction; this.roomId = roomId; + this.exitDetail = exitDetail; } public Direction getDirection() { @@ -21,4 +23,8 @@ public class RemoteExit { public Integer getRoomId() { return roomId; } + + public String getExitDetail() { + return exitDetail; + } } diff --git a/src/main/java/com/comandante/creeper/world/Room.java b/src/main/java/com/comandante/creeper/world/Room.java index 78a8553ad5f8db695febc7b465effc1860dd8a30..a1a84ddc7ec13ee55135529b5bdcef0e175ffaf3 100644 --- a/src/main/java/com/comandante/creeper/world/Room.java +++ b/src/main/java/com/comandante/creeper/world/Room.java @@ -30,6 +30,7 @@ public abstract class Room extends CreeperEntity { private Optional<Integer> southId; private Optional<Integer> downId; private Optional<Integer> upId; + private List<RemoteExit> enterExits = Lists.newArrayList(); private String roomDescription; private final Set<String> presentPlayerIds = Sets.<String>newConcurrentHashSet(); private final Set<String> afkPlayerIds = Sets.<String>newConcurrentHashSet(); @@ -49,6 +50,7 @@ public abstract class Room extends CreeperEntity { Optional<Integer> westId, Optional<Integer> upId, Optional<Integer> downId, + List<RemoteExit> enterExits, String roomDescription, Set<String> roomTags, Set<Area> areas) { this.roomId = roomId; @@ -63,6 +65,7 @@ public abstract class Room extends CreeperEntity { this.roomDescription = roomDescription; this.roomTags = roomTags; this.areas = areas; + this.enterExits = enterExits; } public Set<String> getRoomTags() { @@ -201,6 +204,18 @@ public abstract class Room extends CreeperEntity { return downId; } + public List<RemoteExit> getEnterExits() { + return enterExits; + } + + public void addEnterExit(RemoteExit remoteExit) { + enterExits.add(remoteExit); + } + + public void setEnterExits(List<RemoteExit> enterExits) { + this.enterExits = enterExits; + } + public void addItemSpawner(ItemSpawner itemSpawner) { itemSpawners.add(itemSpawner); } diff --git a/src/main/java/com/comandante/creeper/world/WorldExporter.java b/src/main/java/com/comandante/creeper/world/WorldExporter.java index 8ac89b1d159c6d19a3b941208e7e0beb77d176a1..16e18e8eda3a8de70fde24a2d86a28dc5c19ecdb 100644 --- a/src/main/java/com/comandante/creeper/world/WorldExporter.java +++ b/src/main/java/com/comandante/creeper/world/WorldExporter.java @@ -129,6 +129,8 @@ public class WorldExporter { basicRoomBuilder.setUpId(Optional.of(exit.getRoomId())); } else if (exit.getDirection().equals(RemoteExit.Direction.DOWN)) { basicRoomBuilder.setDownId(Optional.of(exit.getRoomId())); + } else if (exit.getDirection().equals(RemoteExit.Direction.ENTER)) { + basicRoomBuilder.addEnterExit(exit); } } }