Skip to content
Snippets Groups Projects
Commit 133e373d authored by Chris Kearney's avatar Chris Kearney
Browse files

global ticks

parent 387e81c2
No related branches found
No related tags found
No related merge requests found
...@@ -7,9 +7,9 @@ import com.comandante.creeper.managers.GameManager; ...@@ -7,9 +7,9 @@ import com.comandante.creeper.managers.GameManager;
import com.comandante.creeper.managers.PlayerManager; import com.comandante.creeper.managers.PlayerManager;
import com.comandante.creeper.managers.PlayerManagerMapDB; import com.comandante.creeper.managers.PlayerManagerMapDB;
import com.comandante.creeper.managers.RoomManager; import com.comandante.creeper.managers.RoomManager;
import com.comandante.creeper.model.BasicRoom;
import com.comandante.creeper.model.Player; import com.comandante.creeper.model.Player;
import com.comandante.creeper.model.PlayerMetadata; import com.comandante.creeper.model.PlayerMetadata;
import com.comandante.creeper.model.Room;
import com.comandante.creeper.npc.Derper; import com.comandante.creeper.npc.Derper;
import com.comandante.creeper.server.CreeperServer; import com.comandante.creeper.server.CreeperServer;
import com.google.common.base.Optional; import com.google.common.base.Optional;
...@@ -22,16 +22,18 @@ import java.io.File; ...@@ -22,16 +22,18 @@ import java.io.File;
public class Main { public class Main {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Room lobby = new Room(1, "Lobby", Optional.of(2), Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.<Integer>absent(), BasicRoom lobby = new BasicRoom(1, "Lobby", Optional.of(2), Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.<Integer>absent(),
"This is the lobby. It's pretty empty and the paint still smells fresh.\r\n"); "This is the lobby. It's pretty empty and the paint still smells fresh.\r\n");
Room hallway = new Room(2,"Hallway", Optional.of(3), Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.of(1), BasicRoom hallway = new BasicRoom(2,"Hallway", Optional.of(3), Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.of(1), Optional.<Integer>absent(), Optional.<Integer>absent(),
"This is the hallway. It's long and hallway-ish with exposed wires and floorboards showing.\r\n"); "This is the hallway. It's long and hallway-ish with exposed wires and floorboards showing.\r\n");
Room intake = new Room(3, "Intake", Optional.<Integer>absent(), Optional.of(6), Optional.<Integer>absent(), Optional.of(2), BasicRoom intake = new BasicRoom(3, "Intake", Optional.<Integer>absent(), Optional.of(6), Optional.<Integer>absent(), Optional.of(2),Optional.<Integer>absent(), Optional.<Integer>absent(),
"This is the intake area. People are lined up like cattle waiting to be prodded.\r\n"); "This is the intake area. People are lined up like cattle waiting to be prodded.\r\n");
Room janitorialCloset = new Room(6, "Closet", Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.of(3), Optional.of(7), BasicRoom janitorialCloset = new BasicRoom(6, "Closet", Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.of(3), Optional.of(7), Optional.<Integer>absent(), Optional.<Integer>absent(),
"You find yourself in the janitorial closet. It smells like bleach.\r\n"); "You find yourself in the janitorial closet. It smells like bleach.\r\n");
Room toilet = new Room(7, "Toilet", Optional.of(6), Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.<Integer>absent(), BasicRoom toilet = new BasicRoom(7, "Toilet", Optional.of(6), Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.of(8), Optional.<Integer>absent(),
"You find yourself in the toilet. The smell is horrible.\r\n"); "You find yourself in the toilet. The smell is horrible. There's an opening in the ceiling.\r\n");
BasicRoom attic = new BasicRoom(8, "Toilet Ceiling Crawl Space", Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.<Integer>absent(),Optional.<Integer>absent(), Optional.of(7),
"It's cramped as all hell up here. By the looks of it someone has been spending a great deal of time up here.\r\n");
RoomManager roomManager = new RoomManager(); RoomManager roomManager = new RoomManager();
roomManager.addRoom(lobby); roomManager.addRoom(lobby);
...@@ -39,6 +41,7 @@ public class Main { ...@@ -39,6 +41,7 @@ public class Main {
roomManager.addRoom(intake); roomManager.addRoom(intake);
roomManager.addRoom(janitorialCloset); roomManager.addRoom(janitorialCloset);
roomManager.addRoom(toilet); roomManager.addRoom(toilet);
roomManager.addRoom(attic);
DB db = DBMaker.newFileDB(new File("creeperDb")) DB db = DBMaker.newFileDB(new File("creeperDb"))
.closeOnJvmShutdown() .closeOnJvmShutdown()
......
...@@ -17,8 +17,18 @@ public class MovementCommand extends Command { ...@@ -17,8 +17,18 @@ public class MovementCommand extends Command {
public final static List<String> southTriggers = Arrays.asList("s", "south".toLowerCase()); public final static List<String> southTriggers = Arrays.asList("s", "south".toLowerCase());
public final static List<String> eastTriggers = Arrays.asList("e", "east".toLowerCase()); public final static List<String> eastTriggers = Arrays.asList("e", "east".toLowerCase());
public final static List<String> westTriggers = Arrays.asList("w", "west".toLowerCase()); 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 ImmutableList validTriggers = public final static ImmutableList validTriggers =
new ImmutableList.Builder<String>().addAll(northTriggers).addAll(southTriggers).addAll(eastTriggers).addAll(westTriggers).build(); new ImmutableList.Builder<String>()
.addAll(northTriggers)
.addAll(southTriggers)
.addAll(eastTriggers)
.addAll(westTriggers)
.addAll(upTriggers)
.addAll(downTriggers)
.build();
private final static boolean isCaseSensitiveTriggers = false; private final static boolean isCaseSensitiveTriggers = false;
public MovementCommand(String playerId, GameManager gameManager, String originalMessage) { public MovementCommand(String playerId, GameManager gameManager, String originalMessage) {
...@@ -71,6 +81,22 @@ public class MovementCommand extends Command { ...@@ -71,6 +81,22 @@ public class MovementCommand extends Command {
Room destinationRoom = gameManager.getRoomManager().getRoom(currentRoom.getWestId().get()); Room destinationRoom = gameManager.getRoomManager().getRoom(currentRoom.getWestId().get());
movement = new Movement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), this, "exited to the west."); movement = new Movement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), this, "exited to the west.");
} }
if (upTriggers.contains(command.toLowerCase())) {
if (!currentRoom.getUpId().isPresent()) {
player.getChannel().write("There's no up exit.\r\n");
return;
}
Room destinationRoom = gameManager.getRoomManager().getRoom(currentRoom.getUpId().get());
movement = new Movement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), this, "exited to the west.");
}
if (downTriggers.contains(command.toLowerCase())) {
if (!currentRoom.getDownId().isPresent()) {
player.getChannel().write("There's no down exit.\r\n");
return;
}
Room destinationRoom = gameManager.getRoomManager().getRoom(currentRoom.getDownId().get());
movement = new Movement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), this, "exited to the west.");
}
gameManager.movePlayer(movement); gameManager.movePlayer(movement);
if (movement != null) { if (movement != null) {
gameManager.currentRoomLogic(movement.getPlayer().getPlayerId()); gameManager.currentRoomLogic(movement.getPlayer().getPlayerId());
......
...@@ -13,6 +13,7 @@ public class EntityManager { ...@@ -13,6 +13,7 @@ public class EntityManager {
private final ConcurrentHashMap<String, Npc> npcs = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, Npc> npcs = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, CreeperEntity> entities = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, CreeperEntity> entities = new ConcurrentHashMap<>();
private final ExecutorService tickService = Executors.newFixedThreadPool(1); private final ExecutorService tickService = Executors.newFixedThreadPool(1);
private final ExecutorService ticketRunnerService = Executors.newFixedThreadPool(10);
private final RoomManager roomManager; private final RoomManager roomManager;
public EntityManager(RoomManager roomManager) { public EntityManager(RoomManager roomManager) {
...@@ -45,9 +46,9 @@ public class EntityManager { ...@@ -45,9 +46,9 @@ public class EntityManager {
try { try {
Thread.sleep(10000); Thread.sleep(10000);
System.out.println("tick..."); System.out.println("tick...");
for (Map.Entry<String, Npc> next : npcs.entrySet()) { for (Map.Entry<String, CreeperEntity> next : entities.entrySet()) {
Npc npc = next.getValue(); CreeperEntity creeperEntity = next.getValue();
npc.run(); ticketRunnerService.submit(creeperEntity);
} }
} catch (InterruptedException ie) { } catch (InterruptedException ie) {
throw new RuntimeException("Problem with ticker."); throw new RuntimeException("Problem with ticker.");
......
...@@ -230,6 +230,12 @@ public class GameManager { ...@@ -230,6 +230,12 @@ public class GameManager {
if (room.getWestId().isPresent()) { if (room.getWestId().isPresent()) {
stringBuilder.append("West "); stringBuilder.append("West ");
} }
if (room.getUpId().isPresent()) {
stringBuilder.append("Up ");
}
if (room.getDownId().isPresent()) {
stringBuilder.append("Down ");
}
stringBuilder.append(new Ansi().reset().toString()).append("]\r\n"); stringBuilder.append(new Ansi().reset().toString()).append("]\r\n");
return stringBuilder.toString(); return stringBuilder.toString();
} }
......
...@@ -10,7 +10,7 @@ public class RoomManager { ...@@ -10,7 +10,7 @@ public class RoomManager {
private ConcurrentHashMap<Integer, Room> rooms = new ConcurrentHashMap<Integer, Room>(); private ConcurrentHashMap<Integer, Room> rooms = new ConcurrentHashMap<Integer, Room>();
public void addRoom(Room room) { public void addRoom(Room room) {
rooms.put(room.roomId, room); rooms.put(room.getRoomId(), room);
} }
public Room getRoom(Integer roomId) { public Room getRoom(Integer roomId) {
......
package com.comandante.creeper.model; package com.comandante.creeper.model;
public class BasicRoom { import com.google.common.base.Optional;
public class BasicRoom extends Room {
public BasicRoom(Integer roomId, String roomTitle, Optional<Integer> northId, Optional<Integer> westId, Optional<Integer> eastId, Optional<Integer> southId, Optional<Integer> upId, Optional<Integer> downId, String roomDescription) {
super(roomId, roomTitle, northId, westId, eastId, southId, upId, downId, roomDescription);
}
} }
...@@ -2,30 +2,41 @@ package com.comandante.creeper.model; ...@@ -2,30 +2,41 @@ package com.comandante.creeper.model;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.fusesource.jansi.Ansi;
import java.util.Set; import java.util.Set;
public class Room { public abstract class Room extends CreeperEntity {
public Integer roomId; private final Integer roomId;
public String roomTitle; private final String roomTitle;
public Optional<Integer> northId; private final Optional<Integer> northId;
public Optional<Integer> westId; private final Optional<Integer> westId;
public Optional<Integer> eastId; private final Optional<Integer> eastId;
public Optional<Integer> southId; private final Optional<Integer> southId;
public String roomDescription; private final Optional<Integer> downId;
private Set<String> presentPlayerIds = Sets.<String>newConcurrentHashSet(); private final Optional<Integer> upId;
private Set<String> afkPlayerIds = Sets.<String>newConcurrentHashSet(); private final String roomDescription;
private Set<String> npcIds = Sets.newConcurrentHashSet(); private final Set<String> presentPlayerIds = Sets.<String>newConcurrentHashSet();
private final Set<String> afkPlayerIds = Sets.<String>newConcurrentHashSet();
public Room(Integer roomId, String roomTitle, Optional<Integer> northId, Optional<Integer> westId, Optional<Integer> eastId, Optional<Integer> southId, String roomDescription) { private final Set<String> npcIds = Sets.newConcurrentHashSet();
public Room(Integer roomId,
String roomTitle,
Optional<Integer> northId,
Optional<Integer> westId,
Optional<Integer> eastId,
Optional<Integer> southId,
Optional<Integer> upId,
Optional<Integer> downId,
String roomDescription) {
this.roomId = roomId; this.roomId = roomId;
this.roomTitle = roomTitle; this.roomTitle = roomTitle;
this.northId = northId; this.northId = northId;
this.westId = westId; this.westId = westId;
this.eastId = eastId; this.eastId = eastId;
this.southId = southId; this.southId = southId;
this.upId = upId;
this.downId = downId;
this.roomDescription = roomDescription; this.roomDescription = roomDescription;
} }
...@@ -92,4 +103,17 @@ public class Room { ...@@ -92,4 +103,17 @@ public class Room {
public Optional<Integer> getSouthId() { public Optional<Integer> getSouthId() {
return southId; return southId;
} }
public Optional<Integer> getUpId() {
return upId;
}
public Optional<Integer> getDownId() {
return downId;
}
@Override
public void run() {
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment