From 9bb0dc9034e1f00da330b56bb203c1a0dfbc03a0 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Jan 2018 20:42:24 -0500 Subject: [PATCH] Boilerplate code for Vault Door --- Plugin Cubot/Plugin Cubot.iml | 3 + Plugin Misc HW/Plugin Misc HW.iml | 3 + Plugin NPC/Plugin NPC.iml | 3 + Plugin Plant/Plugin Plant.iml | 3 + Plugin Vault/pom.xml | 31 ++++++ .../net/simon987/vaultplugin/VaultDoor.java | 102 ++++++++++++++++++ .../net/simon987/vaultplugin/VaultPlugin.java | 16 +++ .../src/main/resources/plugin.properties | 3 + Server/Server.iml | 3 +- .../net/simon987/server/game/Enterable.java | 13 +++ 10 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 Plugin Vault/pom.xml create mode 100644 Plugin Vault/src/main/java/net/simon987/vaultplugin/VaultDoor.java create mode 100644 Plugin Vault/src/main/java/net/simon987/vaultplugin/VaultPlugin.java create mode 100644 Plugin Vault/src/main/resources/plugin.properties create mode 100644 Server/src/main/java/net/simon987/server/game/Enterable.java diff --git a/Plugin Cubot/Plugin Cubot.iml b/Plugin Cubot/Plugin Cubot.iml index 1f0dd37..16c112e 100644 --- a/Plugin Cubot/Plugin Cubot.iml +++ b/Plugin Cubot/Plugin Cubot.iml @@ -15,6 +15,9 @@ + + + diff --git a/Plugin Misc HW/Plugin Misc HW.iml b/Plugin Misc HW/Plugin Misc HW.iml index f044428..f79e042 100644 --- a/Plugin Misc HW/Plugin Misc HW.iml +++ b/Plugin Misc HW/Plugin Misc HW.iml @@ -14,6 +14,9 @@ + + + diff --git a/Plugin NPC/Plugin NPC.iml b/Plugin NPC/Plugin NPC.iml index 0fda0f5..436be4c 100644 --- a/Plugin NPC/Plugin NPC.iml +++ b/Plugin NPC/Plugin NPC.iml @@ -17,5 +17,8 @@ + + + \ No newline at end of file diff --git a/Plugin Plant/Plugin Plant.iml b/Plugin Plant/Plugin Plant.iml index 0fda0f5..436be4c 100644 --- a/Plugin Plant/Plugin Plant.iml +++ b/Plugin Plant/Plugin Plant.iml @@ -17,5 +17,8 @@ + + + \ No newline at end of file diff --git a/Plugin Vault/pom.xml b/Plugin Vault/pom.xml new file mode 100644 index 0000000..8c85358 --- /dev/null +++ b/Plugin Vault/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + + net.simon987.server + server_root + 1.2a + + + net.simon987.pluginplant + plugin-vault + 1.4a + + + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + + net.simon987.server + server + 1.2a + + + \ No newline at end of file diff --git a/Plugin Vault/src/main/java/net/simon987/vaultplugin/VaultDoor.java b/Plugin Vault/src/main/java/net/simon987/vaultplugin/VaultDoor.java new file mode 100644 index 0000000..5103a8a --- /dev/null +++ b/Plugin Vault/src/main/java/net/simon987/vaultplugin/VaultDoor.java @@ -0,0 +1,102 @@ +package net.simon987.vaultplugin; + +import com.mongodb.BasicDBObject; +import net.simon987.server.game.Enterable; +import net.simon987.server.game.GameObject; +import net.simon987.server.game.Programmable; +import net.simon987.server.game.Updatable; +import net.simon987.server.logging.LogManager; + +import java.util.Arrays; + + +public class VaultDoor extends GameObject implements Programmable, Enterable, Updatable { + + private static final int MAP_INFO = 0x0800; + + /** + * Password to open the vault door + */ + private char[] password; + + /** + * Whether or not the vault door is opened + */ + private boolean opened; + + private int openedTimer; + + /** + * Number of ticks to remain the door open + */ + private static final int OPEN_TIME = 4; //todo load from config + + + @Override + public void update() { + + if (openedTimer <= 0) { + + //Door was opened for OPEN_TIME, close it and regen password + password = getRandomPassword(); + opened = false; + + LogManager.LOGGER.fine("Closed Vault door ID: " + getObjectId()); + } else { + openedTimer--; + } + + } + + @Override + public boolean sendMessage(char[] message) { + + System.out.println("VAULT: sendMessage" + new String(message));//todo rmv + + if (!opened) { + + if (Arrays.equals(message, password)) { + opened = true; + openedTimer = OPEN_TIME; + + LogManager.LOGGER.fine("Opened Vault door ID: " + getObjectId()); + } + + return true; + } else { + //Can't receive messages when opened + return false; + } + } + + @Override + public boolean enter(GameObject object) { + + LogManager.LOGGER.fine("VAULT enter " + opened); + + if (opened) { + + //TODO: Enter in the vault + + + return true; + } else { + return false; + } + + } + + private static char[] getRandomPassword() { + return "12345678".toCharArray();//todo actual random password + } + + @Override + public char getMapInfo() { + return MAP_INFO; + } + + @Override + public BasicDBObject mongoSerialise() { + return null; + } +} diff --git a/Plugin Vault/src/main/java/net/simon987/vaultplugin/VaultPlugin.java b/Plugin Vault/src/main/java/net/simon987/vaultplugin/VaultPlugin.java new file mode 100644 index 0000000..d44405a --- /dev/null +++ b/Plugin Vault/src/main/java/net/simon987/vaultplugin/VaultPlugin.java @@ -0,0 +1,16 @@ +package net.simon987.vaultplugin; + +import net.simon987.server.ServerConfiguration; +import net.simon987.server.logging.LogManager; +import net.simon987.server.plugin.ServerPlugin; + +public class VaultPlugin extends ServerPlugin { + + + @Override + public void init(ServerConfiguration config) { + + + LogManager.LOGGER.info("Initialised Vault plugin"); + } +} diff --git a/Plugin Vault/src/main/resources/plugin.properties b/Plugin Vault/src/main/resources/plugin.properties new file mode 100644 index 0000000..72e6b22 --- /dev/null +++ b/Plugin Vault/src/main/resources/plugin.properties @@ -0,0 +1,3 @@ +classpath=net.simon987.vaultplugin.VaultPlugin +name=Vault Plugin +version=1.0 \ No newline at end of file diff --git a/Server/Server.iml b/Server/Server.iml index 52af955..bdbaa5b 100644 --- a/Server/Server.iml +++ b/Server/Server.iml @@ -18,5 +18,6 @@ + - + \ No newline at end of file diff --git a/Server/src/main/java/net/simon987/server/game/Enterable.java b/Server/src/main/java/net/simon987/server/game/Enterable.java new file mode 100644 index 0000000..cda8b98 --- /dev/null +++ b/Server/src/main/java/net/simon987/server/game/Enterable.java @@ -0,0 +1,13 @@ +package net.simon987.server.game; + +public interface Enterable { + + /** + * Called when an object attempts to walk directly into a Enterable object + * + * @param object The game object that attempted to enter + * @return true if successful, + */ + boolean enter(GameObject object); + +}