mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-12-14 07:09:04 +00:00
Compare commits
9 Commits
refactor-1
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| ac374f5b52 | |||
|
|
d01eac646f | ||
| 35b48ddd95 | |||
|
|
5a0c5b6911 | ||
| a85e672eb9 | |||
| 053d3e35ec | |||
|
|
35140cc834 | ||
| 6a9c656e66 | |||
|
|
d07a59607f |
10
.gitattributes
vendored
10
.gitattributes
vendored
@@ -1,5 +1,5 @@
|
||||
src/main/resources/static/css/bootstrap4-neon-glow.min linguist-vendored
|
||||
src/main/resources/static/css/bootstrap-grid.min linguist-vendored
|
||||
src/main/resources/static/css/bootstrap-reboot.min linguist-vendored
|
||||
src/main/resources/static/js/* linguist-vendored
|
||||
src/main/resources/static/js/ace/* linguist-vendored
|
||||
Server/src/main/resources/static/css/bootstrap4-neon-glow.min linguist-vendored
|
||||
Server/src/main/resources/static/css/bootstrap-grid.min linguist-vendored
|
||||
Server/src/main/resources/static/css/bootstrap-reboot.min linguist-vendored
|
||||
Server/src/main/resources/static/js/* linguist-vendored
|
||||
Server/src/main/resources/static/js/ace/* linguist-vendored
|
||||
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1,4 +1,8 @@
|
||||
|
||||
plugins/Plugin NPC.jar
|
||||
plugins/Plugin Misc HW.jar
|
||||
plugins/Plant.jar
|
||||
plugins/Cubot.jar
|
||||
.idea/*
|
||||
mar.log
|
||||
mar.log.lck
|
||||
@@ -9,8 +13,8 @@ plugins/*.jar
|
||||
save.json
|
||||
Server/Server.iml
|
||||
target/*
|
||||
src/main/java/META-INF/MANIFEST.MF
|
||||
src/main/resources/static/js/mar.js
|
||||
Server/Server.iml
|
||||
Server/src/main/java/META-INF/MANIFEST.MF
|
||||
.settings
|
||||
.project
|
||||
.classpath
|
||||
|
||||
@@ -8,7 +8,12 @@ Here small unordered list of guidelines to read before creating a pull request
|
||||
- Use java <= 1.8 features
|
||||
- Please follow [Google's Java style guide](https://google.github.io/styleguide/javaguide.html)
|
||||
- Constants (e.g. the energy cost of an in-game action) should be loaded from config.properties
|
||||
- Use `Logmanager.LOGGER` to log messages to the console. Use `.fine()` for debugging messages and `.info()` for
|
||||
- The project is separated into multiple modules, the `Server` module and its plugins. Plugins should
|
||||
not depend on another plugin to compile or to run.
|
||||
(e.g. NPC plugin shouldn't import `net.simon987.biomassplugin` )
|
||||
- Use `Logmanager.LOGGER` to log messages to the console. Use `.fine()` for debugging messages and `.info()` for
|
||||
info for more important messages
|
||||
that are not too frequently used.
|
||||
- Do not submit a pull request for a new feature that has not been approved
|
||||
by [simon987](https://github.com/simon987) in an Issue beforehand
|
||||
- Please state what tests have been performed in the pull request
|
||||
|
||||
@@ -3,4 +3,4 @@ COPY /. /app/
|
||||
WORKDIR /app
|
||||
RUN mvn package
|
||||
WORKDIR /app/target
|
||||
CMD ["java", "-jar", "/app/target/server-1.6a.jar"]
|
||||
CMD ["java", "-jar", "/app/target/server-1.4a.jar"]
|
||||
59
Plugin Cubot/Plugin Cubot.iml
Normal file
59
Plugin Cubot/Plugin Cubot.iml
Normal file
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="Spring" name="Spring">
|
||||
<configuration />
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="Server" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.8.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-sync:3.9.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:bson:3.9.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-core:3.9.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.1.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-http:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-util:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-io:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-webapp:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-xml:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-servlet:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-security:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-server:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-common:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-client:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-client:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-servlet:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-api:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sparkjava:spark-template-velocity:2.7.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.velocity:velocity:1.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.25" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
34
Plugin Cubot/pom.xml
Normal file
34
Plugin Cubot/pom.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.simon987.server</groupId>
|
||||
<artifactId>server_root</artifactId>
|
||||
<version>1.4a</version>
|
||||
</parent>
|
||||
|
||||
<groupId>net.simon987.plugincubot</groupId>
|
||||
<artifactId>plugin-cubot</artifactId>
|
||||
<version>1.4a</version>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.simon987.server</groupId>
|
||||
<artifactId>server</artifactId>
|
||||
<version>1.4a</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -1,19 +1,19 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.mar.cubot.event.CubotWalkEvent;
|
||||
import net.simon987.mar.cubot.event.DeathEvent;
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.IServerConfiguration;
|
||||
import net.simon987.mar.server.assembly.CPU;
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Memory;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.assembly.exception.CancelledException;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.game.item.Item;
|
||||
import net.simon987.mar.server.game.item.ItemVoid;
|
||||
import net.simon987.mar.server.game.objects.*;
|
||||
import net.simon987.mar.server.user.User;
|
||||
import net.simon987.cubotplugin.event.CubotWalkEvent;
|
||||
import net.simon987.cubotplugin.event.DeathEvent;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.IServerConfiguration;
|
||||
import net.simon987.server.assembly.CPU;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Memory;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.exception.CancelledException;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.game.item.Item;
|
||||
import net.simon987.server.game.item.ItemVoid;
|
||||
import net.simon987.server.game.objects.*;
|
||||
import net.simon987.server.user.User;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -74,7 +74,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
/**
|
||||
* Buffer of console messages (also called 'internal buffer') that was set during the current tick
|
||||
*/
|
||||
private final ArrayList<char[]> consoleMessagesBuffer = new ArrayList<>(CONSOLE_BUFFER_MAX_SIZE);
|
||||
private ArrayList<char[]> consoleMessagesBuffer = new ArrayList<>(CONSOLE_BUFFER_MAX_SIZE);
|
||||
/**
|
||||
* Buffer of console messages (also called 'internal buffer') at the end of the last tick
|
||||
*/
|
||||
@@ -101,8 +101,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
/**
|
||||
* List of attached hardware, 'modules'
|
||||
*/
|
||||
private final Map<Integer, HardwareModule> hardwareAddresses = new HashMap<>();
|
||||
private final Map<Class<? extends HardwareModule>, Integer> hardwareModules = new HashMap<>();
|
||||
private Map<Integer, HardwareModule> hardwareAddresses = new HashMap<>();
|
||||
private Map<Class<? extends HardwareModule>, Integer> hardwareModules = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Cubot's brain box
|
||||
@@ -157,11 +157,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
if (getCpu().isPaused() || getCpu().isExecuting()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentAction == Action.WALKING) {
|
||||
if (spendEnergy(100)) {
|
||||
if (!incrementLocation()) {
|
||||
@@ -293,7 +288,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
int spawnX = config.getInt("new_user_worldX") + random.nextInt(5);
|
||||
int spawnY = config.getInt("new_user_worldY") + random.nextInt(5);
|
||||
String dimension = config.getString("new_user_dimension");
|
||||
this.setWorld(GameServer.INSTANCE.getUniverse().getWorld(spawnX, spawnY, true, dimension));
|
||||
this.setWorld(GameServer.INSTANCE.getGameUniverse().getWorld(spawnX, spawnY, true, dimension));
|
||||
|
||||
Point point = this.getWorld().getRandomPassableTile();
|
||||
this.setX(point.x);
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.mar.server.game.objects.MessageReceiver;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.MessageReceiver;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotCore extends HardwareModule {
|
||||
@@ -1,11 +1,11 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.item.Item;
|
||||
import net.simon987.mar.server.game.objects.Action;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.mar.server.game.world.Tile;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.item.Item;
|
||||
import net.simon987.server.game.objects.Action;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.world.Tile;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotDrill extends HardwareModule {
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotFloppyDrive extends CubotHardwareModule {
|
||||
@@ -17,7 +17,7 @@ public class CubotFloppyDrive extends CubotHardwareModule {
|
||||
private static final int FLOPPY_READ_SECTOR = 2;
|
||||
private static final int FLOPPY_WRITE_SECTOR = 3;
|
||||
|
||||
private final FloppyDisk floppyDisk;
|
||||
private FloppyDisk floppyDisk;
|
||||
|
||||
public CubotFloppyDrive(Cubot cubot) {
|
||||
super(cubot);
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
public abstract class CubotHardwareModule extends HardwareModule {
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.item.Item;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.item.Item;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -25,7 +25,7 @@ public class CubotInventory extends HardwareModule {
|
||||
private static final int INV_SCAN = 3;
|
||||
|
||||
private int inventorySize = 4; //TODO: load from config
|
||||
private final Map<Integer, Item> inventory;
|
||||
private Map<Integer, Item> inventory;
|
||||
private int position = 0;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotKeyboard extends CubotHardwareModule {
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.objects.*;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.*;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.objects.Action;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.mar.server.game.objects.Direction;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.Action;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.Direction;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotLeg extends HardwareModule {
|
||||
@@ -1,11 +1,11 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Memory;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.mar.server.game.pathfinding.Node;
|
||||
import net.simon987.mar.server.game.pathfinding.Pathfinder;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Memory;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.pathfinding.Node;
|
||||
import net.simon987.server.game.pathfinding.Pathfinder;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -0,0 +1,44 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.cubotplugin.event.*;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.objects.GameRegistry;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.plugin.ServerPlugin;
|
||||
|
||||
public class CubotPlugin extends ServerPlugin {
|
||||
|
||||
|
||||
@Override
|
||||
public void init(GameServer gameServer) {
|
||||
listeners.add(new CpuInitialisationListener());
|
||||
listeners.add(new UserCreationListener());
|
||||
//Debug commands
|
||||
listeners.add(new ChargeShieldCommandListener());
|
||||
listeners.add(new SetInventoryPosition());
|
||||
listeners.add(new PutItemCommandListener());
|
||||
listeners.add(new PopItemCommandListener());
|
||||
//Leaderboard
|
||||
listeners.add(new DeathListener());
|
||||
listeners.add(new WalkListener());
|
||||
|
||||
GameRegistry registry = gameServer.getRegistry();
|
||||
|
||||
registry.registerGameObject(Cubot.class);
|
||||
|
||||
registry.registerHardware(CubotLeg.class);
|
||||
registry.registerHardware(CubotLaser.class);
|
||||
registry.registerHardware(CubotLidar.class);
|
||||
registry.registerHardware(CubotDrill.class);
|
||||
registry.registerHardware(CubotInventory.class);
|
||||
registry.registerHardware(CubotKeyboard.class);
|
||||
registry.registerHardware(CubotHologram.class);
|
||||
registry.registerHardware(CubotBattery.class);
|
||||
registry.registerHardware(CubotFloppyDrive.class);
|
||||
registry.registerHardware(CubotComPort.class);
|
||||
registry.registerHardware(CubotShield.class);
|
||||
registry.registerHardware(CubotCore.class);
|
||||
|
||||
LogManager.LOGGER.info("(Cubot Plugin) Initialised Cubot plugin");
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotShield extends CubotHardwareModule {
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
/**
|
||||
* Status of a Cubot (Special buff or debuff)
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
|
||||
import net.simon987.mar.server.assembly.Memory;
|
||||
import net.simon987.mar.server.io.MongoSerializable;
|
||||
import net.simon987.server.assembly.Memory;
|
||||
import net.simon987.server.io.MongoSerializable;
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
@@ -15,7 +15,7 @@ public class FloppyDisk implements MongoSerializable {
|
||||
/**
|
||||
* Contents of the disk
|
||||
*/
|
||||
private final Memory memory;
|
||||
private Memory memory;
|
||||
|
||||
/**
|
||||
* Current location of the read/write head.
|
||||
@@ -1,11 +1,11 @@
|
||||
package net.simon987.mar.cubot.event;
|
||||
package net.simon987.cubotplugin.event;
|
||||
|
||||
import net.simon987.mar.cubot.Cubot;
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.event.DebugCommandEvent;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.cubotplugin.Cubot;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.event.DebugCommandEvent;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
|
||||
/**
|
||||
* Debug command to add shield points to a Cubot
|
||||
@@ -23,7 +23,7 @@ public class ChargeShieldCommandListener implements GameEventListener {
|
||||
|
||||
if (e.getName().equals("chargeShield")) {
|
||||
|
||||
GameObject cubot = GameServer.INSTANCE.getUniverse().getObject(e.getObjectId("objectId"));
|
||||
GameObject cubot = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId"));
|
||||
|
||||
if (cubot != null) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.simon987.mar.cubot.event;
|
||||
package net.simon987.cubotplugin.event;
|
||||
|
||||
import net.simon987.mar.cubot.*;
|
||||
import net.simon987.mar.server.assembly.CPU;
|
||||
import net.simon987.mar.server.event.CpuInitialisationEvent;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.cubotplugin.*;
|
||||
import net.simon987.server.assembly.CPU;
|
||||
import net.simon987.server.event.CpuInitialisationEvent;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
|
||||
public class CpuInitialisationListener implements GameEventListener {
|
||||
@Override
|
||||
@@ -44,11 +44,6 @@ public class CpuInitialisationListener implements GameEventListener {
|
||||
CubotShield shieldHw = new CubotShield(cubot);
|
||||
shieldHw.setCpu(cpu);
|
||||
|
||||
Clock clockHw = new Clock();
|
||||
clockHw.setCpu(cpu);
|
||||
RandomNumberGenerator rngHw = new RandomNumberGenerator();
|
||||
rngHw.setCpu(cpu);
|
||||
|
||||
cubot.attachHardware(legHw, CubotLeg.DEFAULT_ADDRESS);
|
||||
cubot.attachHardware(laserHw, CubotLaser.DEFAULT_ADDRESS);
|
||||
cubot.attachHardware(radarHw, CubotLidar.DEFAULT_ADDRESS);
|
||||
@@ -62,8 +57,5 @@ public class CpuInitialisationListener implements GameEventListener {
|
||||
cubot.attachHardware(comPortHw, CubotComPort.DEFAULT_ADDRESS);
|
||||
cubot.attachHardware(coreHw, CubotCore.DEFAULT_ADDRESS);
|
||||
cubot.attachHardware(shieldHw, CubotShield.DEFAULT_ADDRESS);
|
||||
|
||||
cubot.attachHardware(clockHw, Clock.DEFAULT_ADDRESS);
|
||||
cubot.attachHardware(rngHw, RandomNumberGenerator.DEFAULT_ADDRESS);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.simon987.mar.cubot.event;
|
||||
package net.simon987.cubotplugin.event;
|
||||
|
||||
import net.simon987.mar.cubot.Cubot;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.cubotplugin.Cubot;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
|
||||
public class CubotWalkEvent extends GameEvent {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.simon987.mar.cubot.event;
|
||||
package net.simon987.cubotplugin.event;
|
||||
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
|
||||
public class DeathEvent extends GameEvent {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.simon987.mar.cubot.event;
|
||||
package net.simon987.cubotplugin.event;
|
||||
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
|
||||
public class DeathListener implements GameEventListener {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package net.simon987.mar.cubot.event;
|
||||
package net.simon987.cubotplugin.event;
|
||||
|
||||
import net.simon987.mar.cubot.Cubot;
|
||||
import net.simon987.mar.cubot.CubotInventory;
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.event.DebugCommandEvent;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.cubotplugin.Cubot;
|
||||
import net.simon987.cubotplugin.CubotInventory;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.event.DebugCommandEvent;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
|
||||
public class PopItemCommandListener implements GameEventListener {
|
||||
|
||||
@@ -22,7 +22,7 @@ public class PopItemCommandListener implements GameEventListener {
|
||||
|
||||
if (e.getName().equals("clearItem")) {
|
||||
|
||||
GameObject object = GameServer.INSTANCE.getUniverse().getObject(e.getObjectId("objectId"));
|
||||
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId"));
|
||||
|
||||
if (object != null) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.simon987.mar.cubot.event;
|
||||
package net.simon987.cubotplugin.event;
|
||||
|
||||
import net.simon987.mar.cubot.Cubot;
|
||||
import net.simon987.mar.cubot.CubotInventory;
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.event.DebugCommandEvent;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.mar.server.game.item.Item;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.cubotplugin.Cubot;
|
||||
import net.simon987.cubotplugin.CubotInventory;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.event.DebugCommandEvent;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.game.item.Item;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import org.bson.Document;
|
||||
|
||||
public class PutItemCommandListener implements GameEventListener {
|
||||
@@ -24,7 +24,7 @@ public class PutItemCommandListener implements GameEventListener {
|
||||
|
||||
if (e.getName().equals("putItem")) {
|
||||
|
||||
GameObject object = GameServer.INSTANCE.getUniverse().getObject(e.getObjectId("objectId"));
|
||||
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId"));
|
||||
|
||||
if (object != null) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package net.simon987.mar.cubot.event;
|
||||
package net.simon987.cubotplugin.event;
|
||||
|
||||
import net.simon987.mar.cubot.Cubot;
|
||||
import net.simon987.mar.cubot.CubotInventory;
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.event.DebugCommandEvent;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.cubotplugin.Cubot;
|
||||
import net.simon987.cubotplugin.CubotInventory;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.event.DebugCommandEvent;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
|
||||
public class SetInventoryPosition implements GameEventListener {
|
||||
|
||||
@@ -22,7 +22,7 @@ public class SetInventoryPosition implements GameEventListener {
|
||||
|
||||
if (e.getName().equals("setInventoryPosition")) {
|
||||
|
||||
GameObject object = GameServer.INSTANCE.getUniverse().getObject(e.getObjectId("objectId"));
|
||||
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId"));
|
||||
|
||||
if (object != null) {
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
package net.simon987.mar.cubot.event;
|
||||
package net.simon987.cubotplugin.event;
|
||||
|
||||
import net.simon987.mar.cubot.Cubot;
|
||||
import net.simon987.mar.cubot.CubotStatus;
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.IServerConfiguration;
|
||||
import net.simon987.mar.server.assembly.Assembler;
|
||||
import net.simon987.mar.server.assembly.AssemblyResult;
|
||||
import net.simon987.mar.server.assembly.CPU;
|
||||
import net.simon987.mar.server.assembly.exception.CancelledException;
|
||||
import net.simon987.mar.server.event.CpuInitialisationEvent;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.mar.server.event.UserCreationEvent;
|
||||
import net.simon987.mar.server.logging.LogManager;
|
||||
import net.simon987.mar.server.user.User;
|
||||
import net.simon987.cubotplugin.Cubot;
|
||||
import net.simon987.cubotplugin.CubotStatus;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.IServerConfiguration;
|
||||
import net.simon987.server.assembly.Assembler;
|
||||
import net.simon987.server.assembly.AssemblyResult;
|
||||
import net.simon987.server.assembly.CPU;
|
||||
import net.simon987.server.assembly.exception.CancelledException;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.event.UserCreationEvent;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.user.User;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -41,7 +40,7 @@ public class UserCreationListener implements GameEventListener {
|
||||
int spawnX = config.getInt("new_user_worldX") + random.nextInt(5);
|
||||
int spawnY = config.getInt("new_user_worldY") + random.nextInt(5);
|
||||
String dimension = config.getString("new_user_dimension");
|
||||
cubot.setWorld(GameServer.INSTANCE.getUniverse().getWorld(spawnX, spawnY, true, dimension));
|
||||
cubot.setWorld(GameServer.INSTANCE.getGameUniverse().getWorld(spawnX, spawnY, true, dimension));
|
||||
|
||||
point = cubot.getWorld().getRandomPassableTile();
|
||||
}
|
||||
@@ -56,20 +55,13 @@ public class UserCreationListener implements GameEventListener {
|
||||
|
||||
//Create CPU
|
||||
try {
|
||||
CPU cpu = new CPU(config);
|
||||
cubot.setCpu(cpu);
|
||||
cubot.setCpu(new CPU(GameServer.INSTANCE.getConfig(), cubot));
|
||||
cubot.getCpu().setHardwareHost(cubot);
|
||||
user.setUserCode(config.getString("new_user_code"));
|
||||
|
||||
GameEvent initEvent = new CpuInitialisationEvent(cpu, cubot);
|
||||
GameServer.INSTANCE.getEventDispatcher().dispatch(initEvent);
|
||||
if (initEvent.isCancelled()) {
|
||||
throw new CancelledException();
|
||||
}
|
||||
|
||||
//Compile user code
|
||||
AssemblyResult ar = new Assembler(cpu.getInstructionSet(), cpu.getRegisterSet(),
|
||||
config).parse(user.getUserCode());
|
||||
AssemblyResult ar = new Assembler(cubot.getCpu().getInstructionSet(), cubot.getCpu().getRegisterSet(),
|
||||
GameServer.INSTANCE.getConfig()).parse(user.getUserCode());
|
||||
|
||||
cubot.getCpu().getMemory().clear();
|
||||
|
||||
@@ -86,6 +78,6 @@ public class UserCreationListener implements GameEventListener {
|
||||
cubot.setMaxHp(config.getInt("cubot_max_hp"));
|
||||
cubot.setMaxShield(config.getInt("cubot_max_shield"));
|
||||
|
||||
LogManager.LOGGER.fine("Handled User creation event");
|
||||
LogManager.LOGGER.fine("(Plugin) Handled User creation event (Cubot Plugin)");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.simon987.mar.cubot.event;
|
||||
package net.simon987.cubotplugin.event;
|
||||
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
|
||||
public class WalkListener implements GameEventListener {
|
||||
|
||||
3
Plugin Cubot/src/main/resources/plugin.properties
Normal file
3
Plugin Cubot/src/main/resources/plugin.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
classpath=net.simon987.cubotplugin.CubotPlugin
|
||||
name=Cubot Plugin
|
||||
version=1.0
|
||||
12
Plugin Cubot/test/net/simon987/cubotplugin/CubotTest.java
Normal file
12
Plugin Cubot/test/net/simon987/cubotplugin/CubotTest.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CubotTest {
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
|
||||
}
|
||||
}
|
||||
58
Plugin Misc HW/Plugin Misc HW.iml
Normal file
58
Plugin Misc HW/Plugin Misc HW.iml
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="Spring" name="Spring">
|
||||
<configuration />
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="Server" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.8.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-sync:3.9.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:bson:3.9.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-core:3.9.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.1.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-http:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-util:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-io:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-webapp:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-xml:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-servlet:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-security:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-server:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-common:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-client:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-client:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-servlet:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-api:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sparkjava:spark-template-velocity:2.7.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.velocity:velocity:1.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.25" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
32
Plugin Misc HW/pom.xml
Normal file
32
Plugin Misc HW/pom.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.simon987.server</groupId>
|
||||
<artifactId>server_root</artifactId>
|
||||
<version>1.4a</version>
|
||||
</parent>
|
||||
|
||||
<groupId>net.simon987.pluginmischw</groupId>
|
||||
<artifactId>plugin-misc-hw</artifactId>
|
||||
<version>1.4a</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.simon987.server</groupId>
|
||||
<artifactId>server</artifactId>
|
||||
<version>1.4a</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.mischwplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.assembly.Util;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Util;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
@@ -27,7 +27,7 @@ public class Clock extends HardwareModule {
|
||||
@Override
|
||||
public void handleInterrupt(Status status) {
|
||||
|
||||
int time = (int) GameServer.INSTANCE.getUniverse().getTime();
|
||||
int time = (int) GameServer.INSTANCE.getGameUniverse().getTime();
|
||||
|
||||
//Will need to be changed to quadword in about 136 years
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(Util.getHigherWord(time));
|
||||
@@ -0,0 +1,26 @@
|
||||
package net.simon987.mischwplugin;
|
||||
|
||||
import net.simon987.mischwplugin.event.CpuInitialisationListener;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.objects.GameRegistry;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.plugin.ServerPlugin;
|
||||
|
||||
/**
|
||||
* Plugin that adds miscellaneous hardware to the game
|
||||
*/
|
||||
public class MiscHWPlugin extends ServerPlugin {
|
||||
|
||||
|
||||
@Override
|
||||
public void init(GameServer gameServer) {
|
||||
listeners.add(new CpuInitialisationListener());
|
||||
|
||||
GameRegistry registry = gameServer.getRegistry();
|
||||
|
||||
registry.registerHardware(RandomNumberGenerator.class);
|
||||
registry.registerHardware(Clock.class);
|
||||
|
||||
LogManager.LOGGER.info("(Mist HW Plugin) Initialised Misc Hardware Plugin");
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.simon987.mar.cubot;
|
||||
package net.simon987.mischwplugin;
|
||||
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.Random;
|
||||
@@ -16,7 +16,7 @@ public class RandomNumberGenerator extends HardwareModule {
|
||||
|
||||
public static final char DEFAULT_ADDRESS = 0x0007;
|
||||
|
||||
private final Random random;
|
||||
private Random random;
|
||||
|
||||
public RandomNumberGenerator() {
|
||||
random = new Random();
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.simon987.mischwplugin.event;
|
||||
|
||||
import net.simon987.mischwplugin.Clock;
|
||||
import net.simon987.mischwplugin.RandomNumberGenerator;
|
||||
import net.simon987.server.assembly.CPU;
|
||||
import net.simon987.server.event.CpuInitialisationEvent;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.game.objects.HardwareHost;
|
||||
|
||||
public class CpuInitialisationListener implements GameEventListener {
|
||||
|
||||
@Override
|
||||
public Class getListenedEventType() {
|
||||
return CpuInitialisationEvent.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(GameEvent event) {
|
||||
|
||||
CPU cpu = (CPU) event.getSource();
|
||||
HardwareHost cubot = (HardwareHost) ((CpuInitialisationEvent) event).getUnit();
|
||||
cpu.setHardwareHost(cubot);
|
||||
|
||||
RandomNumberGenerator rngHW = new RandomNumberGenerator();
|
||||
rngHW.setCpu(cpu);
|
||||
Clock clock = new Clock();
|
||||
clock.setCpu(cpu);
|
||||
|
||||
cpu.getHardwareHost().attachHardware(rngHW, RandomNumberGenerator.DEFAULT_ADDRESS);
|
||||
cpu.getHardwareHost().attachHardware(clock, Clock.DEFAULT_ADDRESS);
|
||||
}
|
||||
}
|
||||
3
Plugin Misc HW/src/main/resources/plugin.properties
Normal file
3
Plugin Misc HW/src/main/resources/plugin.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
classpath=net.simon987.mischwplugin.MiscHWPlugin
|
||||
name=Misc HW Plugin
|
||||
version=1.0
|
||||
58
Plugin NPC/Plugin NPC.iml
Normal file
58
Plugin NPC/Plugin NPC.iml
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="Spring" name="Spring">
|
||||
<configuration />
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
<orderEntry type="module" module-name="Server" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.8.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-sync:3.9.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:bson:3.9.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-core:3.9.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.1.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-http:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-util:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-io:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-webapp:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-xml:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-servlet:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-security:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-server:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-common:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-client:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-client:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-servlet:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-api:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sparkjava:spark-template-velocity:2.7.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.velocity:velocity:1.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.25" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
31
Plugin NPC/pom.xml
Normal file
31
Plugin NPC/pom.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.simon987.server</groupId>
|
||||
<artifactId>server_root</artifactId>
|
||||
<version>1.4a</version>
|
||||
</parent>
|
||||
|
||||
<groupId>net.simon987.pluginnpc</groupId>
|
||||
<artifactId>plugin-npc</artifactId>
|
||||
<version>1.4a</version>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.simon987.server</groupId>
|
||||
<artifactId>server</artifactId>
|
||||
<version>1.4a</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,11 +1,11 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.assembly.Util;
|
||||
import net.simon987.mar.server.game.objects.Attackable;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.mar.server.game.objects.Rechargeable;
|
||||
import net.simon987.mar.server.game.objects.Updatable;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.Util;
|
||||
import net.simon987.server.game.objects.Attackable;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.Rechargeable;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -37,7 +37,7 @@ public class ElectricBox extends GameObject implements Updatable, Attackable {
|
||||
/**
|
||||
* List of nearby objects. Is updated every tick
|
||||
*/
|
||||
private final ArrayList<Attackable> nearObjects = new ArrayList<>();
|
||||
private ArrayList<Attackable> nearObjects = new ArrayList<>();
|
||||
|
||||
public ElectricBox() {
|
||||
hp = maxHp;
|
||||
@@ -1,11 +1,11 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.game.objects.Action;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.objects.Action;
|
||||
|
||||
public class ExecuteCpuTask extends NPCTask {
|
||||
|
||||
private static final int MAX_EXEC_INSTRUCTIONS = GameServer.INSTANCE.getConfig().getInt("npc_exec_instructions");
|
||||
private static final int MAX_EXEC_TIME = GameServer.INSTANCE.getConfig().getInt("npc_exec_time");
|
||||
|
||||
@Override
|
||||
public boolean checkCompleted() {
|
||||
@@ -18,10 +18,9 @@ public class ExecuteCpuTask extends NPCTask {
|
||||
HackedNPC hNpc = (HackedNPC) npc;
|
||||
|
||||
//Execute code
|
||||
int allocation = Math.min(hNpc.getEnergy() * 10000, MAX_EXEC_INSTRUCTIONS);
|
||||
int timeout = Math.min(hNpc.getEnergy(), MAX_EXEC_TIME);
|
||||
hNpc.getCpu().reset();
|
||||
hNpc.getCpu().setInstructionAlloction(allocation);
|
||||
int cost = hNpc.getCpu().execute();
|
||||
int cost = hNpc.getCpu().execute(timeout);
|
||||
hNpc.spendEnergy(cost);
|
||||
|
||||
if (hNpc.getCurrentAction() == Action.WALKING) {
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.game.objects.MessageReceiver;
|
||||
import net.simon987.mar.server.game.objects.Structure;
|
||||
import net.simon987.mar.server.game.objects.Updatable;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.objects.MessageReceiver;
|
||||
import net.simon987.server.game.objects.Structure;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class Factory extends Structure implements Updatable, MessageReceiver {
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
Settlement settlement = Settlement.MAP.get(getWorld().getId());
|
||||
Settlement settlement = NpcPlugin.settlementMap.get(getWorld().getId());
|
||||
|
||||
if (settlement == null) {
|
||||
//Only happens when server is killed during save function
|
||||
@@ -133,7 +133,7 @@ public class Factory extends Structure implements Updatable, MessageReceiver {
|
||||
public boolean sendMessage(char[] message) {
|
||||
|
||||
if (locked) {
|
||||
Settlement settlement = Settlement.MAP.get(getWorld().getId());
|
||||
Settlement settlement = NpcPlugin.settlementMap.get(getWorld().getId());
|
||||
|
||||
if (Arrays.equals(settlement.getPassword(), message)) {
|
||||
this.locked = false;
|
||||
@@ -1,15 +1,15 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.assembly.*;
|
||||
import net.simon987.mar.server.event.ObjectDeathEvent;
|
||||
import net.simon987.mar.server.game.item.Item;
|
||||
import net.simon987.mar.server.game.item.ItemVoid;
|
||||
import net.simon987.mar.server.game.objects.Action;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.mar.server.game.objects.Direction;
|
||||
import net.simon987.mar.server.logging.LogManager;
|
||||
import net.simon987.mar.server.user.User;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.*;
|
||||
import net.simon987.server.event.ObjectDeathEvent;
|
||||
import net.simon987.server.game.item.Item;
|
||||
import net.simon987.server.game.item.ItemVoid;
|
||||
import net.simon987.server.game.objects.Action;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.Direction;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.user.User;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -20,21 +20,19 @@ import java.util.Map;
|
||||
|
||||
public class HackedNPC extends NonPlayerCharacter implements ControllableUnit {
|
||||
|
||||
public static Document DEFAULT_HACKED_NPC;
|
||||
|
||||
private static final int MEM_SIZE = GameServer.INSTANCE.getConfig().getInt("hacked_npc_mem_size");
|
||||
private static final boolean DIE_ON_NO_ENERGY = GameServer.INSTANCE.getConfig().getInt("hacked_npc_die_on_no_energy") != 0;
|
||||
|
||||
private final CPU cpu;
|
||||
private CPU cpu;
|
||||
/**
|
||||
* List of attached hardware, 'modules'
|
||||
*/
|
||||
private final Map<Integer, HardwareModule> hardwareAddresses = new HashMap<>();
|
||||
private final Map<Class<? extends HardwareModule>, Integer> hardwareModules = new HashMap<>();
|
||||
private Map<Integer, HardwareModule> hardwareAddresses = new HashMap<>();
|
||||
private Map<Class<? extends HardwareModule>, Integer> hardwareModules = new HashMap<>();
|
||||
|
||||
private Action currentAction = Action.IDLE;
|
||||
private Action lastAction = Action.IDLE;
|
||||
private final List<char[]> consoleMessagesBuffer = new ArrayList<>(30); //todo load from conf
|
||||
private ArrayList<char[]> consoleMessagesBuffer = new ArrayList<>(30); //todo load from conf
|
||||
private ArrayList<char[]> lastConsoleMessagesBuffer = new ArrayList<>(30);
|
||||
|
||||
HackedNPC(char[] program) {
|
||||
@@ -45,7 +43,7 @@ public class HackedNPC extends NonPlayerCharacter implements ControllableUnit {
|
||||
cpu.setHardwareHost(this);
|
||||
cpu.getMemory().write(cpu.getCodeSectionOffset(), program, 0, program.length);
|
||||
|
||||
for (Object serialisedHw : (List) DEFAULT_HACKED_NPC.get("hardware")) {
|
||||
for (Object serialisedHw : (List) NpcPlugin.DEFAULT_HACKED_NPC.get("hardware")) {
|
||||
HardwareModule hardware = GameServer.INSTANCE.getRegistry().deserializeHardware((Document) serialisedHw, this);
|
||||
hardware.setCpu(cpu);
|
||||
attachHardware(hardware, ((Document) serialisedHw).getInteger("address"));
|
||||
@@ -1,11 +1,11 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
|
||||
import net.simon987.mar.server.assembly.Util;
|
||||
import net.simon987.mar.server.game.objects.Direction;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.mar.server.game.objects.InventoryHolder;
|
||||
import net.simon987.mar.server.logging.LogManager;
|
||||
import net.simon987.server.assembly.Util;
|
||||
import net.simon987.server.game.objects.Direction;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.InventoryHolder;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
@@ -15,7 +15,7 @@ import java.util.Random;
|
||||
*/
|
||||
public class HarvestTask extends NPCTask {
|
||||
|
||||
private final Random random;
|
||||
private Random random;
|
||||
|
||||
/**
|
||||
* Number of ticks to wait before continuing
|
||||
@@ -45,7 +45,7 @@ public class HarvestTask extends NPCTask {
|
||||
|
||||
if (pause == 0) {
|
||||
//Get biomass
|
||||
ArrayList<GameObject> biomass = npc.getWorld().findGameObjects("net.simon987.mar.biomassplugin.BiomassBlob");
|
||||
ArrayList<GameObject> biomass = npc.getWorld().findGameObjects("net.simon987.biomassplugin.BiomassBlob");
|
||||
|
||||
//Get closest one
|
||||
int minDist = Integer.MAX_VALUE;
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.event.ObjectDeathEvent;
|
||||
import net.simon987.mar.server.game.objects.Direction;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.event.ObjectDeathEvent;
|
||||
import net.simon987.server.game.objects.Direction;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
|
||||
public abstract class NPCTask {
|
||||
@@ -1,11 +1,11 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.assembly.Util;
|
||||
import net.simon987.mar.server.game.objects.*;
|
||||
import net.simon987.mar.server.game.pathfinding.Node;
|
||||
import net.simon987.mar.server.game.pathfinding.Pathfinder;
|
||||
import net.simon987.mar.server.logging.LogManager;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.Util;
|
||||
import net.simon987.server.game.objects.*;
|
||||
import net.simon987.server.game.pathfinding.Node;
|
||||
import net.simon987.server.game.pathfinding.Pathfinder;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.game.item.Item;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.item.Item;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.npcplugin.event.CpuInitialisationListener;
|
||||
import net.simon987.npcplugin.event.VaultCompleteListener;
|
||||
import net.simon987.npcplugin.event.VaultWorldUpdateListener;
|
||||
import net.simon987.npcplugin.event.WorldCreationListener;
|
||||
import net.simon987.npcplugin.world.TileVaultFloor;
|
||||
import net.simon987.npcplugin.world.TileVaultWall;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.IServerConfiguration;
|
||||
import net.simon987.server.game.objects.GameRegistry;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.plugin.ServerPlugin;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class NpcPlugin extends ServerPlugin {
|
||||
|
||||
public static Map<String, Settlement> settlementMap;
|
||||
|
||||
public static Document DEFAULT_HACKED_NPC;
|
||||
|
||||
@Override
|
||||
public void init(GameServer gameServer) {
|
||||
|
||||
IServerConfiguration configuration = gameServer.getConfig();
|
||||
GameRegistry registry = gameServer.getRegistry();
|
||||
|
||||
listeners.add(new WorldCreationListener(configuration.getInt("settlement_spawn_rate")));
|
||||
listeners.add(new CpuInitialisationListener());
|
||||
listeners.add(new VaultWorldUpdateListener(configuration));
|
||||
listeners.add(new VaultCompleteListener());
|
||||
|
||||
registry.registerGameObject(HarvesterNPC.class);
|
||||
registry.registerGameObject(Factory.class);
|
||||
registry.registerGameObject(RadioTower.class);
|
||||
registry.registerGameObject(VaultDoor.class);
|
||||
registry.registerGameObject(Obstacle.class);
|
||||
registry.registerGameObject(ElectricBox.class);
|
||||
registry.registerGameObject(Portal.class);
|
||||
registry.registerGameObject(VaultExitPortal.class);
|
||||
registry.registerGameObject(HackedNPC.class);
|
||||
|
||||
registry.registerHardware(RadioReceiverHardware.class);
|
||||
registry.registerHardware(NpcBattery.class);
|
||||
registry.registerHardware(NpcInventory.class);
|
||||
|
||||
registry.registerTile(TileVaultFloor.ID, TileVaultFloor.class);
|
||||
registry.registerTile(TileVaultWall.ID, TileVaultWall.class);
|
||||
|
||||
settlementMap = new ConcurrentHashMap<>();
|
||||
|
||||
LogManager.LOGGER.fine("(NPC Plugin) Loading default HackedNPC settings from" +
|
||||
" defaultHackedCubotHardware.json");
|
||||
InputStream is = getClass().getClassLoader().getResourceAsStream("defaultHackedCubotHardware.json");
|
||||
Scanner scanner = new Scanner(is).useDelimiter("\\A");
|
||||
String json = scanner.next();
|
||||
DEFAULT_HACKED_NPC = Document.parse(json);
|
||||
|
||||
LogManager.LOGGER.info("(NPC Plugin) Initialised NPC plugin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
Document document = super.mongoSerialise();
|
||||
|
||||
Document settlements = new Document();
|
||||
for (String world : settlementMap.keySet()) {
|
||||
settlements.put(world, settlementMap.get(world).mongoSerialise());
|
||||
}
|
||||
|
||||
document.put("settlement_map", settlements);
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(Document document) {
|
||||
super.load(document);
|
||||
|
||||
Document settlements = (Document) document.get("settlement_map");
|
||||
|
||||
for (String world : settlements.keySet()) {
|
||||
settlementMap.put(world, new Settlement((Document) settlements.get(world)));
|
||||
}
|
||||
|
||||
LogManager.LOGGER.fine(String.format("(%s) Loaded %d settlements", name, settlementMap.size()));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.game.objects.Attackable;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.Attackable;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.game.objects.Enterable;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.mar.server.game.objects.Structure;
|
||||
import net.simon987.mar.server.game.objects.Updatable;
|
||||
import net.simon987.mar.server.game.world.Location;
|
||||
import net.simon987.mar.server.game.world.World;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.objects.Enterable;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.Structure;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
import net.simon987.server.game.world.Location;
|
||||
import net.simon987.server.game.world.World;
|
||||
import org.bson.Document;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class Portal extends Structure implements Enterable {
|
||||
@Override
|
||||
public boolean enter(GameObject object) {
|
||||
|
||||
World world = GameServer.INSTANCE.getUniverse().getWorld(destination.worldX, destination.worldY, false, destination.dimension);
|
||||
World world = GameServer.INSTANCE.getGameUniverse().getWorld(destination.worldX, destination.worldY, false, destination.dimension);
|
||||
|
||||
if (object instanceof Updatable) {
|
||||
object.getWorld().decUpdatable();
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.assembly.HardwareModule;
|
||||
import net.simon987.mar.server.assembly.Status;
|
||||
import net.simon987.mar.server.assembly.Util;
|
||||
import net.simon987.mar.server.game.objects.Action;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Util;
|
||||
import net.simon987.server.game.objects.Action;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -18,7 +18,7 @@ public class RadioReceiverHardware extends HardwareModule {
|
||||
|
||||
public static final int DEFAULT_ADDRESS = 0xC;
|
||||
|
||||
private final ControllableUnit cubot;
|
||||
private ControllableUnit cubot;
|
||||
|
||||
public RadioReceiverHardware(ControllableUnit cubot) {
|
||||
this.cubot = cubot;
|
||||
@@ -42,8 +42,8 @@ public class RadioReceiverHardware extends HardwareModule {
|
||||
|
||||
List<char[]> messages = new ArrayList<>(6);
|
||||
|
||||
for (String world : Settlement.MAP.keySet()) {
|
||||
RadioTower tower = Settlement.MAP.get(world).getRadioTower();
|
||||
for (String world : NpcPlugin.settlementMap.keySet()) {
|
||||
RadioTower tower = NpcPlugin.settlementMap.get(world).getRadioTower();
|
||||
|
||||
if (tower != null && Util.manhattanDist(
|
||||
tower.getWorld().getX(), tower.getWorld().getY(),
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.game.objects.MessageReceiver;
|
||||
import net.simon987.mar.server.game.objects.Structure;
|
||||
import net.simon987.mar.server.game.objects.Updatable;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.objects.MessageReceiver;
|
||||
import net.simon987.server.game.objects.Structure;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
@@ -34,7 +34,7 @@ public class RadioTower extends Structure implements MessageReceiver, Updatable
|
||||
/**
|
||||
* Messages from the current tick
|
||||
*/
|
||||
private final ArrayList<char[]> messages = new ArrayList<>(4);
|
||||
private ArrayList<char[]> messages = new ArrayList<>(4);
|
||||
|
||||
/**
|
||||
* Messages from the last tick
|
||||
@@ -1,53 +1,49 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.game.world.TilePlain;
|
||||
import net.simon987.mar.server.game.world.World;
|
||||
import net.simon987.mar.server.game.world.WorldGenerationException;
|
||||
import net.simon987.mar.server.io.MongoSerializable;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.world.TilePlain;
|
||||
import net.simon987.server.game.world.World;
|
||||
import net.simon987.server.game.world.WorldGenerationException;
|
||||
import net.simon987.server.io.MongoSerializable;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class Settlement implements MongoSerializable {
|
||||
|
||||
private Factory factory = null;
|
||||
private RadioTower radioTower = null;
|
||||
private VaultDoor vaultDoor = null;
|
||||
private final World world;
|
||||
private final DifficultyLevel difficultyLevel;
|
||||
private World world;
|
||||
private DifficultyLevel difficultyLevel;
|
||||
|
||||
public static Map<String, Settlement> MAP = new ConcurrentHashMap<>();
|
||||
private List<NonPlayerCharacter> npcs = new ArrayList<>();
|
||||
|
||||
private final List<NonPlayerCharacter> npcs = new ArrayList<>();
|
||||
|
||||
private final char[] password;
|
||||
private char[] password;
|
||||
|
||||
public Settlement(Document document) {
|
||||
|
||||
world = GameServer.INSTANCE.getUniverse().getWorld(document.getString("world"), false);
|
||||
world = GameServer.INSTANCE.getGameUniverse().getWorld(document.getString("world"), false);
|
||||
ObjectId radioTowerId = document.getObjectId("radio_tower");
|
||||
if (radioTowerId != null) {
|
||||
radioTower = (RadioTower) GameServer.INSTANCE.getUniverse().getObject(radioTowerId);
|
||||
radioTower = (RadioTower) GameServer.INSTANCE.getGameUniverse().getObject(radioTowerId);
|
||||
}
|
||||
ObjectId vaultDoorId = document.getObjectId("vault_door");
|
||||
if (vaultDoorId != null) {
|
||||
vaultDoor = (VaultDoor) GameServer.INSTANCE.getUniverse().getObject(vaultDoorId);
|
||||
vaultDoor = (VaultDoor) GameServer.INSTANCE.getGameUniverse().getObject(vaultDoorId);
|
||||
}
|
||||
ObjectId factoryId = document.getObjectId("factory");
|
||||
factory = (Factory) GameServer.INSTANCE.getUniverse().getObject(factoryId);
|
||||
factory = (Factory) GameServer.INSTANCE.getGameUniverse().getObject(factoryId);
|
||||
|
||||
difficultyLevel = DifficultyLevel.values()[document.getInteger("difficulty_level")];
|
||||
|
||||
Object[] npcArray = ((ArrayList) document.get("npcs")).toArray();
|
||||
for (Object id : npcArray) {
|
||||
|
||||
NonPlayerCharacter npc = (NonPlayerCharacter) GameServer.INSTANCE.getUniverse().getObject((ObjectId) id);
|
||||
NonPlayerCharacter npc = (NonPlayerCharacter) GameServer.INSTANCE.getGameUniverse().getObject((ObjectId) id);
|
||||
|
||||
if (npc != null) {
|
||||
addNpc(npc);
|
||||
@@ -1,12 +1,12 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.npc.world.TileVaultFloor;
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.IServerConfiguration;
|
||||
import net.simon987.mar.server.game.objects.Direction;
|
||||
import net.simon987.mar.server.game.world.Location;
|
||||
import net.simon987.mar.server.game.world.World;
|
||||
import net.simon987.mar.server.logging.LogManager;
|
||||
import net.simon987.npcplugin.world.TileVaultFloor;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.IServerConfiguration;
|
||||
import net.simon987.server.game.objects.Direction;
|
||||
import net.simon987.server.game.world.Location;
|
||||
import net.simon987.server.game.world.World;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -20,7 +20,7 @@ public class VaultDimension {
|
||||
/**
|
||||
* Name of the dimension
|
||||
*/
|
||||
private final String name;
|
||||
private String name;
|
||||
|
||||
private World homeWorld;
|
||||
|
||||
@@ -113,7 +113,7 @@ public class VaultDimension {
|
||||
|
||||
for (WorldBluePrint bp : layer) {
|
||||
World vWorld = generator.generateVaultWorld(bp.coords.x, bp.coords.y, bp.openings, name);
|
||||
GameServer.INSTANCE.getUniverse().addWorld(vWorld);
|
||||
GameServer.INSTANCE.getGameUniverse().addWorld(vWorld);
|
||||
|
||||
ArrayList<ElectricBox> newBoxes = VaultWorldUtils.generateElectricBoxes(vWorld, minElectricBoxCount,
|
||||
maxElectricBoxCount);
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.game.objects.*;
|
||||
import net.simon987.mar.server.game.world.World;
|
||||
import net.simon987.mar.server.logging.LogManager;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.objects.*;
|
||||
import net.simon987.server.game.world.World;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -26,7 +26,7 @@ public class VaultDoor extends Structure implements MessageReceiver, Enterable,
|
||||
/**
|
||||
* Number of ticks to remain the door open
|
||||
*/
|
||||
private final int OPEN_TIME = GameServer.INSTANCE.getConfig().getInt("vault_door_open_time");
|
||||
private int OPEN_TIME = GameServer.INSTANCE.getConfig().getInt("vault_door_open_time");
|
||||
|
||||
private int openedTimer = 0;
|
||||
|
||||
@@ -66,7 +66,7 @@ public class VaultDoor extends Structure implements MessageReceiver, Enterable,
|
||||
@Override
|
||||
public boolean sendMessage(char[] message) {
|
||||
|
||||
Settlement settlement = Settlement.MAP.get(getWorld().getId());
|
||||
Settlement settlement = NpcPlugin.settlementMap.get(getWorld().getId());
|
||||
|
||||
System.out.println("message: " + new String(message));
|
||||
System.out.println("password: " + new String(settlement.getPassword()));
|
||||
@@ -135,7 +135,7 @@ public class VaultDoor extends Structure implements MessageReceiver, Enterable,
|
||||
@Override
|
||||
public void initialize() {
|
||||
//Get or generate vault world
|
||||
homeWorld = GameServer.INSTANCE.getUniverse().getWorld(0x7FFF, 0x7FFF,
|
||||
homeWorld = GameServer.INSTANCE.getGameUniverse().getWorld(0x7FFF, 0x7FFF,
|
||||
false, "v" + getObjectId() + "-");
|
||||
|
||||
if (homeWorld == null) {
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.mar.server.game.world.Location;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.world.Location;
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.server.game.objects.Direction;
|
||||
import net.simon987.mar.server.game.world.TileMap;
|
||||
import net.simon987.mar.server.game.world.TileVoid;
|
||||
import net.simon987.mar.server.game.world.World;
|
||||
import net.simon987.server.game.objects.Direction;
|
||||
import net.simon987.server.game.world.TileMap;
|
||||
import net.simon987.server.game.world.TileVoid;
|
||||
import net.simon987.server.game.world.World;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
@@ -158,7 +158,7 @@ public class VaultWorldGenerator {
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.simon987.mar.npc;
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.mar.npc.world.TileVaultFloor;
|
||||
import net.simon987.mar.server.game.world.TileMap;
|
||||
import net.simon987.mar.server.game.world.World;
|
||||
import net.simon987.npcplugin.world.TileVaultFloor;
|
||||
import net.simon987.server.game.world.TileMap;
|
||||
import net.simon987.server.game.world.World;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -1,11 +1,12 @@
|
||||
package net.simon987.mar.npc.event;
|
||||
package net.simon987.npcplugin.event;
|
||||
|
||||
import net.simon987.mar.npc.RadioReceiverHardware;
|
||||
import net.simon987.mar.server.assembly.CPU;
|
||||
import net.simon987.mar.server.event.CpuInitialisationEvent;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.npcplugin.RadioReceiverHardware;
|
||||
import net.simon987.server.assembly.CPU;
|
||||
import net.simon987.server.event.CpuInitialisationEvent;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.HardwareHost;
|
||||
|
||||
public class CpuInitialisationListener implements GameEventListener {
|
||||
@Override
|
||||
@@ -18,7 +19,7 @@ public class CpuInitialisationListener implements GameEventListener {
|
||||
public void handle(GameEvent event) {
|
||||
CPU cpu = (CPU) event.getSource();
|
||||
ControllableUnit controllableUnit = ((CpuInitialisationEvent) event).getUnit();
|
||||
cpu.setHardwareHost(controllableUnit);
|
||||
cpu.setHardwareHost((HardwareHost) controllableUnit);
|
||||
|
||||
RadioReceiverHardware radioHw = new RadioReceiverHardware(controllableUnit);
|
||||
radioHw.setCpu(cpu);
|
||||
@@ -1,12 +1,12 @@
|
||||
package net.simon987.mar.npc.event;
|
||||
package net.simon987.npcplugin.event;
|
||||
|
||||
import net.simon987.mar.npc.VaultExitPortal;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.npcplugin.VaultExitPortal;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
|
||||
public class VaultCompleteEvent extends GameEvent {
|
||||
|
||||
private final VaultExitPortal portal;
|
||||
private VaultExitPortal portal;
|
||||
|
||||
public VaultCompleteEvent(GameObject object, VaultExitPortal portal) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.simon987.mar.npc.event;
|
||||
package net.simon987.npcplugin.event;
|
||||
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.mar.server.logging.LogManager;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
|
||||
public class VaultCompleteListener implements GameEventListener {
|
||||
@Override
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.simon987.mar.npc.event;
|
||||
package net.simon987.npcplugin.event;
|
||||
|
||||
import net.simon987.mar.npc.ElectricBox;
|
||||
import net.simon987.mar.npc.VaultWorldUtils;
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.IServerConfiguration;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.mar.server.event.WorldUpdateEvent;
|
||||
import net.simon987.mar.server.game.world.World;
|
||||
import net.simon987.npcplugin.ElectricBox;
|
||||
import net.simon987.npcplugin.VaultWorldUtils;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.IServerConfiguration;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.event.WorldUpdateEvent;
|
||||
import net.simon987.server.game.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -17,7 +17,7 @@ public class VaultWorldUpdateListener implements GameEventListener {
|
||||
/**
|
||||
* Map of worlds and their time to wait until next respawn event
|
||||
*/
|
||||
private final HashMap<World, Long> worldWaitMap = new HashMap<>(200);
|
||||
private HashMap<World, Long> worldWaitMap = new HashMap<>(200);
|
||||
|
||||
/**
|
||||
* Lower bound of ElectricBox to be created on a respawn event
|
||||
@@ -61,12 +61,12 @@ public class VaultWorldUpdateListener implements GameEventListener {
|
||||
|
||||
//Set a timer for respawn_time ticks
|
||||
if (!worldWaitMap.containsKey(world) || worldWaitMap.get(world) == 0L) {
|
||||
worldWaitMap.put(world, GameServer.INSTANCE.getUniverse().getTime() + waitTime);
|
||||
worldWaitMap.put(world, GameServer.INSTANCE.getGameUniverse().getTime() + waitTime);
|
||||
} else {
|
||||
|
||||
long waitUntil = worldWaitMap.get(world);
|
||||
|
||||
if (GameServer.INSTANCE.getUniverse().getTime() >= waitUntil) {
|
||||
if (GameServer.INSTANCE.getGameUniverse().getTime() >= waitUntil) {
|
||||
|
||||
//If the timer was set less than respawn_time ticks ago, respawn the blobs
|
||||
ArrayList<ElectricBox> newBoxes = VaultWorldUtils.generateElectricBoxes(world, minElectricBoxCount,
|
||||
@@ -1,12 +1,13 @@
|
||||
package net.simon987.mar.npc.event;
|
||||
package net.simon987.npcplugin.event;
|
||||
|
||||
import net.simon987.mar.npc.Settlement;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.mar.server.event.WorldGenerationEvent;
|
||||
import net.simon987.mar.server.game.world.World;
|
||||
import net.simon987.mar.server.game.world.WorldGenerationException;
|
||||
import net.simon987.mar.server.logging.LogManager;
|
||||
import net.simon987.npcplugin.NpcPlugin;
|
||||
import net.simon987.npcplugin.Settlement;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.event.WorldGenerationEvent;
|
||||
import net.simon987.server.game.world.World;
|
||||
import net.simon987.server.game.world.WorldGenerationException;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@@ -17,7 +18,7 @@ public class WorldCreationListener implements GameEventListener {
|
||||
*/
|
||||
private static int FACTORY_SPAWN_RATE = 0;
|
||||
|
||||
private final Random random = new Random();
|
||||
private Random random = new Random();
|
||||
|
||||
public WorldCreationListener(int factorySpawnRate) {
|
||||
FACTORY_SPAWN_RATE = factorySpawnRate;
|
||||
@@ -37,7 +38,7 @@ public class WorldCreationListener implements GameEventListener {
|
||||
|
||||
try {
|
||||
Settlement settlement = new Settlement(world);
|
||||
Settlement.MAP.put(world.getId(), settlement);
|
||||
NpcPlugin.settlementMap.put(world.getId(), settlement);
|
||||
} catch (WorldGenerationException e) {
|
||||
LogManager.LOGGER.fine(String.format("Exception during settlement generation: %s.",
|
||||
e.getMessage()));
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.simon987.mar.npc.world;
|
||||
package net.simon987.npcplugin.world;
|
||||
|
||||
import net.simon987.mar.server.game.world.Tile;
|
||||
import net.simon987.server.game.world.Tile;
|
||||
|
||||
public class TileVaultFloor extends Tile {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.simon987.mar.npc.world;
|
||||
package net.simon987.npcplugin.world;
|
||||
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.mar.server.game.world.Tile;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.world.Tile;
|
||||
|
||||
public class TileVaultWall extends Tile {
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
{
|
||||
"hardware": [
|
||||
{
|
||||
"type": "net.simon987.mar.cubot.CubotLeg",
|
||||
"type": "net.simon987.cubotplugin.CubotLeg",
|
||||
"address": 1
|
||||
},
|
||||
{
|
||||
"type": "net.simon987.mar.cubot.CubotLaser",
|
||||
"type": "net.simon987.cubotplugin.CubotLaser",
|
||||
"address": 2
|
||||
},
|
||||
{
|
||||
"type": "net.simon987.mar.cubot.CubotLidar",
|
||||
"type": "net.simon987.cubotplugin.CubotLidar",
|
||||
"address": 3
|
||||
},
|
||||
{
|
||||
"type": "net.simon987.mar.cubot.CubotDrill",
|
||||
"type": "net.simon987.cubotplugin.CubotDrill",
|
||||
"address": 5
|
||||
},
|
||||
{
|
||||
"type": "net.simon987.mar.cubot.NpcInventory",
|
||||
"type": "net.simon987.npcplugin.NpcInventory",
|
||||
"item": null,
|
||||
"address": 6
|
||||
},
|
||||
{
|
||||
"type": "net.simon987.mar.mischwplugin.RandomNumberGenerator",
|
||||
"type": "net.simon987.mischwplugin.RandomNumberGenerator",
|
||||
"address": 7
|
||||
},
|
||||
{
|
||||
@@ -30,7 +30,7 @@
|
||||
"address": 8
|
||||
},
|
||||
{
|
||||
"type": "net.simon987.mar.cubot.CubotHologram",
|
||||
"type": "net.simon987.cubotplugin.CubotHologram",
|
||||
"color": 0,
|
||||
"value": 0,
|
||||
"string": "",
|
||||
@@ -38,24 +38,24 @@
|
||||
"address": 9
|
||||
},
|
||||
{
|
||||
"type": "net.simon987.mar.npc.NpcBattery",
|
||||
"type": "net.simon987.npcplugin.NpcBattery",
|
||||
"energy": 60000,
|
||||
"max_energy": 60000,
|
||||
"address": 262
|
||||
},
|
||||
{
|
||||
"type": "net.simon987.mar.npc.RadioReceiverHardware",
|
||||
"type": "net.simon987.npcplugin.RadioReceiverHardware",
|
||||
"cubot": {
|
||||
"$oid": "5c1d43e40d3d2530aba636df"
|
||||
},
|
||||
"address": 12
|
||||
},
|
||||
{
|
||||
"type": "net.simon987.mar.npc.CubotComPort",
|
||||
"type": "net.simon987.cubotplugin.CubotComPort",
|
||||
"address": 13
|
||||
},
|
||||
{
|
||||
"type": "net.simon987.mar.npc.CubotCore",
|
||||
"type": "net.simon987.cubotplugin.CubotCore",
|
||||
"address": 14
|
||||
}
|
||||
]
|
||||
4
Plugin NPC/src/main/resources/plugin.properties
Normal file
4
Plugin NPC/src/main/resources/plugin.properties
Normal file
@@ -0,0 +1,4 @@
|
||||
classpath=net.simon987.npcplugin.NpcPlugin
|
||||
name=NPC Plugin
|
||||
version=1.1
|
||||
depend=Cubot Plugin
|
||||
58
Plugin Plant/Plugin Plant.iml
Normal file
58
Plugin Plant/Plugin Plant.iml
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="Spring" name="Spring">
|
||||
<configuration />
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
<orderEntry type="module" module-name="Server" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.8.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-sync:3.9.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:bson:3.9.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-core:3.9.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.1.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.1.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-http:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-util:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-io:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-webapp:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-xml:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-servlet:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-security:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-server:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-common:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-client:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-client:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-servlet:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-api:9.4.12.v20180830" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sparkjava:spark-template-velocity:2.7.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.velocity:velocity:1.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.25" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
30
Plugin Plant/pom.xml
Normal file
30
Plugin Plant/pom.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.simon987.server</groupId>
|
||||
<artifactId>server_root</artifactId>
|
||||
<version>1.4a</version>
|
||||
</parent>
|
||||
|
||||
<groupId>net.simon987.pluginplant</groupId>
|
||||
<artifactId>plugin-biomassBlob</artifactId>
|
||||
<version>1.4a</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.simon987.server</groupId>
|
||||
<artifactId>server</artifactId>
|
||||
<version>1.4a</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.simon987.mar.biomass;
|
||||
package net.simon987.biomassplugin;
|
||||
|
||||
import net.simon987.mar.server.game.item.Item;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.mar.server.game.objects.InventoryHolder;
|
||||
import net.simon987.server.game.item.Item;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.InventoryHolder;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.simon987.biomassplugin;
|
||||
|
||||
import net.simon987.biomassplugin.event.ObjectDeathListener;
|
||||
import net.simon987.biomassplugin.event.WorldCreationListener;
|
||||
import net.simon987.biomassplugin.event.WorldUpdateListener;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.IServerConfiguration;
|
||||
import net.simon987.server.game.objects.GameRegistry;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.plugin.ServerPlugin;
|
||||
|
||||
|
||||
public class BiomassPlugin extends ServerPlugin {
|
||||
|
||||
|
||||
@Override
|
||||
public void init(GameServer gameServer) {
|
||||
|
||||
IServerConfiguration config = gameServer.getConfig();
|
||||
GameRegistry registry = gameServer.getRegistry();
|
||||
|
||||
listeners.add(new WorldCreationListener());
|
||||
listeners.add(new WorldUpdateListener(config));
|
||||
listeners.add(new ObjectDeathListener(config));
|
||||
|
||||
registry.registerGameObject(BiomassBlob.class);
|
||||
registry.registerItem(ItemBiomass.ID, ItemBiomass.class);
|
||||
|
||||
LogManager.LOGGER.info("(BiomassPlugin) Initialised Biomass plugin");
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package net.simon987.mar.biomass;
|
||||
package net.simon987.biomassplugin;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.game.item.Item;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.item.Item;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.Rechargeable;
|
||||
import org.bson.Document;
|
||||
|
||||
public class ItemBiomass extends Item {
|
||||
@@ -26,7 +27,9 @@ public class ItemBiomass extends Item {
|
||||
|
||||
@Override
|
||||
public void clear(ControllableUnit unit) {
|
||||
unit.storeEnergy(energy);
|
||||
if (unit instanceof Rechargeable) {
|
||||
((Rechargeable) unit).storeEnergy(energy);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.simon987.mar.biomass;
|
||||
package net.simon987.biomassplugin;
|
||||
|
||||
import net.simon987.mar.server.game.world.TileMap;
|
||||
import net.simon987.mar.server.game.world.TilePlain;
|
||||
import net.simon987.mar.server.game.world.World;
|
||||
import net.simon987.server.game.world.TileMap;
|
||||
import net.simon987.server.game.world.TilePlain;
|
||||
import net.simon987.server.game.world.World;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -1,12 +1,12 @@
|
||||
package net.simon987.mar.biomass.event;
|
||||
package net.simon987.biomassplugin.event;
|
||||
|
||||
import net.simon987.mar.biomass.BiomassBlob;
|
||||
import net.simon987.mar.server.IServerConfiguration;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.mar.server.event.ObjectDeathEvent;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.mar.server.game.world.World;
|
||||
import net.simon987.biomassplugin.BiomassBlob;
|
||||
import net.simon987.server.IServerConfiguration;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.event.ObjectDeathEvent;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.world.World;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@ import org.bson.types.ObjectId;
|
||||
*/
|
||||
public class ObjectDeathListener implements GameEventListener {
|
||||
|
||||
private final int biomassDropCount;
|
||||
private int biomassDropCount;
|
||||
|
||||
public ObjectDeathListener(IServerConfiguration config) {
|
||||
biomassDropCount = config.getInt("harvester_biomass_drop_count");
|
||||
@@ -28,9 +28,9 @@ public class ObjectDeathListener implements GameEventListener {
|
||||
@Override
|
||||
public void handle(GameEvent event) {
|
||||
|
||||
if (event.getSource().getClass().getCanonicalName().equals("net.simon987.mar.npc.HarvesterNPC")) {
|
||||
if (event.getSource().getClass().getCanonicalName().equals("net.simon987.npcplugin.HarvesterNPC")) {
|
||||
//An HarvesterNPC ObjectDeathEvent is received
|
||||
GameObject dyingHarvesterNPC = (GameObject) event.getSource();
|
||||
GameObject dyingHarvesterNPC = (GameObject)event.getSource();
|
||||
|
||||
//Don't spawn biomass on World border
|
||||
if (dyingHarvesterNPC.getX() != 0 && dyingHarvesterNPC.getX() != dyingHarvesterNPC.getWorld().getWorldSize() - 1 &&
|
||||
@@ -1,11 +1,11 @@
|
||||
package net.simon987.mar.biomass.event;
|
||||
package net.simon987.biomassplugin.event;
|
||||
|
||||
import net.simon987.mar.biomass.BiomassBlob;
|
||||
import net.simon987.mar.biomass.WorldUtils;
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.mar.server.event.WorldGenerationEvent;
|
||||
import net.simon987.biomassplugin.BiomassBlob;
|
||||
import net.simon987.biomassplugin.WorldUtils;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.event.WorldGenerationEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.simon987.mar.biomass.event;
|
||||
package net.simon987.biomassplugin.event;
|
||||
|
||||
import net.simon987.mar.biomass.BiomassBlob;
|
||||
import net.simon987.mar.biomass.WorldUtils;
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.IServerConfiguration;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.event.GameEventListener;
|
||||
import net.simon987.mar.server.event.WorldUpdateEvent;
|
||||
import net.simon987.mar.server.game.world.World;
|
||||
import net.simon987.biomassplugin.BiomassBlob;
|
||||
import net.simon987.biomassplugin.WorldUtils;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.IServerConfiguration;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.event.WorldUpdateEvent;
|
||||
import net.simon987.server.game.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -15,7 +15,7 @@ import java.util.HashMap;
|
||||
|
||||
public class WorldUpdateListener implements GameEventListener {
|
||||
|
||||
private final HashMap<World, Long> worldWaitMap = new HashMap<>(200);
|
||||
private HashMap<World, Long> worldWaitMap = new HashMap<>(200);
|
||||
|
||||
private static int minBlobCount;
|
||||
private static int maxBlobCount;
|
||||
@@ -50,12 +50,12 @@ public class WorldUpdateListener implements GameEventListener {
|
||||
|
||||
//Set a timer for respawn_time ticks
|
||||
if (!worldWaitMap.containsKey(world) || worldWaitMap.get(world) == 0L) {
|
||||
worldWaitMap.put(world, GameServer.INSTANCE.getUniverse().getTime() + waitTime);
|
||||
worldWaitMap.put(world, GameServer.INSTANCE.getGameUniverse().getTime() + waitTime);
|
||||
} else {
|
||||
|
||||
long waitUntil = worldWaitMap.get(world);
|
||||
|
||||
if (GameServer.INSTANCE.getUniverse().getTime() >= waitUntil) {
|
||||
if (GameServer.INSTANCE.getGameUniverse().getTime() >= waitUntil) {
|
||||
|
||||
//If the timer was set less than respawn_time ticks ago, respawn the blobs
|
||||
ArrayList<BiomassBlob> newBlobs = WorldUtils.generateBlobs(world, minBlobCount,
|
||||
4
Plugin Plant/src/main/resources/plugin.properties
Normal file
4
Plugin Plant/src/main/resources/plugin.properties
Normal file
@@ -0,0 +1,4 @@
|
||||
classpath=net.simon987.biomassplugin.BiomassPlugin
|
||||
name=Biomass Plugin
|
||||
version=1.0
|
||||
depend=NPC Plugin
|
||||
31
Plugin Radioactive Cloud/pom.xml
Normal file
31
Plugin Radioactive Cloud/pom.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.simon987.server</groupId>
|
||||
<artifactId>server_root</artifactId>
|
||||
<version>1.4a</version>
|
||||
</parent>
|
||||
|
||||
<groupId>net.simon987.pluginradioactivecloud</groupId>
|
||||
<artifactId>plugin-radioactiveCloud</artifactId>
|
||||
<version>1.4a</version>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.simon987.server</groupId>
|
||||
<artifactId>server</artifactId>
|
||||
<version>1.4a</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.simon987.mar.radioactivecloud;
|
||||
package net.simon987.pluginradioactivecloud;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.mar.server.game.objects.Enterable;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.mar.server.game.objects.Radioactive;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.Enterable;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.Radioactive;
|
||||
|
||||
public class RadioactiveCloud extends GameObject implements Radioactive, Enterable {
|
||||
private final static int CORRUPTION_BLOCK_SIZE =
|
||||
@@ -0,0 +1,14 @@
|
||||
package net.simon987.pluginradioactivecloud;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.plugin.ServerPlugin;
|
||||
|
||||
public class RadioactiveCloudPlugin extends ServerPlugin {
|
||||
|
||||
@Override
|
||||
public void init(GameServer gameServer) {
|
||||
|
||||
LogManager.LOGGER.info("(Radioactive cloud Plugin) Initialised Radioactive cloud plugin.");
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.simon987.mar.radioactivecloud;
|
||||
package net.simon987.pluginradioactivecloud;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.mar.server.game.objects.Enterable;
|
||||
import net.simon987.mar.server.game.objects.GameObject;
|
||||
import net.simon987.mar.server.game.objects.Radioactive;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.Enterable;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.Radioactive;
|
||||
|
||||
public class RadioactiveObstacle extends GameObject implements Radioactive, Enterable {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
classpath=net.simon987.pluginradioactivecloud.RadioactiveCloudPlugin
|
||||
name=Radioactive cloud Plugin
|
||||
version=1.4
|
||||
36
README.md
36
README.md
@@ -1,10 +1,9 @@
|
||||
### [Official website](https://muchassemblyrequired.com)
|
||||
# Much-Assembly-Required
|
||||
|
||||
[](https://www.codefactor.io/repository/github/simon987/much-assembly-required)
|
||||
[](https://ci.simon987.net/job/Much-Assembly-Required/)
|
||||
|
||||
Program the 8086-like microprocessor of a robot in a grid-based multiplayer world. The game is web based so no installation is required.
|
||||
In its current state, players can walk around the game universe and collect Biomass blobs & Iron/copper ore using the online code editor.
|
||||
**Much Assembly Required** allows you to program the 8086-like microprocessor of a robot in a grid-based multiplayer world. The game is web based so no installation is required. In its current state, players can walk around the game universe and collect Biomass blobs and Iron/copper ore using the online code editor.
|
||||
|
||||

|
||||
|
||||
@@ -20,19 +19,18 @@ Chat: [Slack](https://join.slack.com/t/muchassemblyrequired/shared_invite/enQtMj
|
||||
On Ubuntu 16.04:
|
||||
```bash
|
||||
sudo apt install git maven openjdk-8-jdk mongodb
|
||||
sudo npm install -g typescript
|
||||
```
|
||||
|
||||
On Arch:
|
||||
``` bash
|
||||
sudo pacman -S git maven mongodb jdk8-opendjk
|
||||
sudo npm install -g typescript
|
||||
sudo pacman -S git maven jdk8-opendjk
|
||||
yay -S mongodb-bin
|
||||
|
||||
# Don't forget to start mongodb
|
||||
sudo systemctl start mongodb.service
|
||||
```
|
||||
|
||||
*If needed, visit [troubleshooting mongodb](https://wiki.archlinux.org/index.php/MongoDB#Troubleshooting).*
|
||||
*If needed, visit [yay installation](https://github.com/Jguer/yay#installation) and [troubleshooting mongodb](https://wiki.archlinux.org/index.php/MongoDB#Troubleshooting).*
|
||||
|
||||
**Deploying server**
|
||||
|
||||
@@ -46,19 +44,19 @@ mvn package
|
||||
|
||||
# Run
|
||||
cd target
|
||||
java -jar muchassemblyrequired-*.jar
|
||||
java -jar server-1.4a.jar
|
||||
```
|
||||
|
||||
## Windows (tested on Windows 10)
|
||||
|
||||
Installation instructions:
|
||||
1. Download the JDK from [here](http://www.oracle.com/technetwork/java/javase/downloads/index.html).
|
||||
Install the JDK and update your PATH and JAVA_HOME enviroment variables.
|
||||
Install the JDK and update your PATH and JAVA_HOME environment variables.
|
||||
2. Download Maven from [here](https://maven.apache.org/).
|
||||
Install Maven (following the README) and update your PATH enviroment variable.
|
||||
Install Maven (following the README) and update your PATH environment variable.
|
||||
3. Download Mongo DB Community from [here](https://www.mongodb.com/download-center#community).
|
||||
Install Mongo DB following the instructions [here](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/).
|
||||
Update your PATH enviroment variable.
|
||||
Update your PATH environment variable.
|
||||
|
||||
Building instructions:
|
||||
```batch
|
||||
@@ -77,7 +75,7 @@ mongod
|
||||
```batch
|
||||
:: Runs the MAR server
|
||||
cd Much-Assembly-Required\target
|
||||
java -jar muchassemblyrequired-*.jar
|
||||
java -jar server-1.4a.jar
|
||||
```
|
||||
|
||||
## macOS (tested on Sierra 10.12.6)
|
||||
@@ -138,7 +136,7 @@ If you do not wish to use the default data directory (/data/db), follow the step
|
||||
|
||||
# Run
|
||||
cd target
|
||||
java -jar muchassemblyrequired-*.jar
|
||||
java -jar server-1.4a.jar
|
||||
```
|
||||
|
||||
## Docker
|
||||
@@ -157,6 +155,18 @@ application's directory:
|
||||
Make sure to change `mongo_address` in `config.properties` to `mongodb`.
|
||||
|
||||
|
||||
## Vagrant
|
||||
### Requirements
|
||||
1. [Vagrant](https://www.vagrantup.com/downloads.html)
|
||||
2. [VirtualBox](https://www.virtualbox.org/wiki/Downloads)
|
||||
|
||||
### Installation
|
||||
|
||||
When vagrant is installed, you can build and start this application by running the following
|
||||
command inside this application's directory:
|
||||
|
||||
`vagrant up`
|
||||
|
||||
# Running
|
||||
|
||||
Once the server is running, you should be able to connect to `http://localhost:4567` with your browser
|
||||
|
||||
142
Server/pom.xml
Normal file
142
Server/pom.xml
Normal file
@@ -0,0 +1,142 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
<build>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-resources</id>
|
||||
<!-- here the phase you need -->
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>../target/</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>../Server/src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<version>3.6.2</version>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>../target/libs</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<configuration>
|
||||
<outputDirectory>../target</outputDirectory>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>net.simon987.server.Main</mainClass>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>libs/</classpathPrefix>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.7.2</version>
|
||||
<configuration>
|
||||
<forkMode>never</forkMode>
|
||||
<workingDirectory>./src/main/resources</workingDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<groupId>net.simon987.server</groupId>
|
||||
<artifactId>server</artifactId>
|
||||
<version>1.4a</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-text</artifactId>
|
||||
<version>1.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongodb-driver-sync</artifactId>
|
||||
<version>3.9.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-core</artifactId>
|
||||
<version>5.1.11.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sparkjava</groupId>
|
||||
<artifactId>spark-core</artifactId>
|
||||
<version>2.8.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sparkjava</groupId>
|
||||
<artifactId>spark-template-velocity</artifactId>
|
||||
<version>2.7.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<!-- explicitly set build encoding so not altered by build platform defaults -->
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
350
Server/src/main/java/net/simon987/server/GameServer.java
Normal file
350
Server/src/main/java/net/simon987/server/GameServer.java
Normal file
@@ -0,0 +1,350 @@
|
||||
package net.simon987.server;
|
||||
|
||||
import com.mongodb.MongoClientException;
|
||||
import com.mongodb.client.*;
|
||||
import com.mongodb.client.model.ReplaceOptions;
|
||||
import net.simon987.server.crypto.CryptoProvider;
|
||||
import net.simon987.server.crypto.SecretKeyGenerator;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventDispatcher;
|
||||
import net.simon987.server.event.TickEvent;
|
||||
import net.simon987.server.game.GameUniverse;
|
||||
import net.simon987.server.game.debug.*;
|
||||
import net.simon987.server.game.item.ItemCopper;
|
||||
import net.simon987.server.game.item.ItemIron;
|
||||
import net.simon987.server.game.objects.GameRegistry;
|
||||
import net.simon987.server.game.world.*;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.plugin.PluginManager;
|
||||
import net.simon987.server.plugin.ServerPlugin;
|
||||
import net.simon987.server.user.User;
|
||||
import net.simon987.server.user.UserManager;
|
||||
import net.simon987.server.user.UserStatsHelper;
|
||||
import net.simon987.server.websocket.SocketServer;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GameServer implements Runnable {
|
||||
|
||||
public final static GameServer INSTANCE = new GameServer();
|
||||
|
||||
private GameUniverse gameUniverse;
|
||||
private GameEventDispatcher eventDispatcher;
|
||||
private PluginManager pluginManager;
|
||||
|
||||
private IServerConfiguration config;
|
||||
|
||||
private SocketServer socketServer;
|
||||
|
||||
private int maxExecutionTime;
|
||||
|
||||
private DayNightCycle dayNightCycle;
|
||||
|
||||
private CryptoProvider cryptoProvider;
|
||||
|
||||
private MongoClient mongo;
|
||||
|
||||
private UserManager userManager;
|
||||
|
||||
private UserStatsHelper userStatsHelper;
|
||||
|
||||
private GameRegistry gameRegistry;
|
||||
|
||||
private String secretKey;
|
||||
|
||||
public GameServer() {
|
||||
this.config = new ServerConfiguration("config.properties");
|
||||
|
||||
String connString = String.format("mongodb://%s:%d",
|
||||
config.getString("mongo_address"), config.getInt("mongo_port"));
|
||||
mongo = MongoClients.create(connString);
|
||||
MongoDatabase db = mongo.getDatabase(config.getString("mongo_dbname"));
|
||||
|
||||
MongoCollection<Document> userCollection = db.getCollection("user");
|
||||
|
||||
userManager = new UserManager(userCollection);
|
||||
userStatsHelper = new UserStatsHelper(userCollection);
|
||||
|
||||
gameUniverse = new GameUniverse(config);
|
||||
gameUniverse.setMongo(mongo);
|
||||
gameRegistry = new GameRegistry();
|
||||
pluginManager = new PluginManager(this);
|
||||
|
||||
maxExecutionTime = config.getInt("user_timeout");
|
||||
|
||||
cryptoProvider = new CryptoProvider();
|
||||
|
||||
dayNightCycle = new DayNightCycle();
|
||||
|
||||
SecretKeyGenerator keyGenerator = new SecretKeyGenerator();
|
||||
secretKey = config.getString("secret_key");
|
||||
if (secretKey == null) {
|
||||
secretKey = keyGenerator.generate();
|
||||
config.setString("secret_key", secretKey);
|
||||
}
|
||||
|
||||
if (!pluginManager.loadInFolder("plugins/")) {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
eventDispatcher = new GameEventDispatcher(pluginManager);
|
||||
eventDispatcher.getListeners().add(dayNightCycle);
|
||||
|
||||
//Debug command Listeners
|
||||
eventDispatcher.getListeners().add(new ComPortMsgCommandListener());
|
||||
eventDispatcher.getListeners().add(new CreateWorldCommandListener());
|
||||
eventDispatcher.getListeners().add(new KillAllCommandListener());
|
||||
eventDispatcher.getListeners().add(new MoveObjCommandListener());
|
||||
eventDispatcher.getListeners().add(new ObjInfoCommandListener());
|
||||
eventDispatcher.getListeners().add(new SetTileAtCommandListener());
|
||||
eventDispatcher.getListeners().add(new SpawnObjCommandListener());
|
||||
eventDispatcher.getListeners().add(new TpObjectCommandListener());
|
||||
eventDispatcher.getListeners().add(new UserInfoCommandListener());
|
||||
eventDispatcher.getListeners().add(new HealObjCommandListener());
|
||||
eventDispatcher.getListeners().add(new DamageObjCommandListener());
|
||||
eventDispatcher.getListeners().add(new SetEnergyCommandListener());
|
||||
eventDispatcher.getListeners().add(new SaveGameCommandListener());
|
||||
|
||||
gameRegistry.registerItem(ItemCopper.ID, ItemCopper.class);
|
||||
gameRegistry.registerItem(ItemIron.ID, ItemIron.class);
|
||||
|
||||
gameRegistry.registerTile(TileVoid.ID, TileVoid.class);
|
||||
gameRegistry.registerTile(TilePlain.ID, TilePlain.class);
|
||||
gameRegistry.registerTile(TileWall.ID, TileWall.class);
|
||||
gameRegistry.registerTile(TileCopper.ID, TileCopper.class);
|
||||
gameRegistry.registerTile(TileIron.ID, TileIron.class);
|
||||
gameRegistry.registerTile(TileFluid.ID, TileFluid.class);
|
||||
}
|
||||
|
||||
public GameUniverse getGameUniverse() {
|
||||
return gameUniverse;
|
||||
}
|
||||
|
||||
public GameEventDispatcher getEventDispatcher() {
|
||||
return eventDispatcher;
|
||||
}
|
||||
|
||||
public CryptoProvider getCryptoProvider() {
|
||||
return cryptoProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
LogManager.LOGGER.info("(G) Started game loop");
|
||||
|
||||
long startTime; //Start time of the loop
|
||||
long uTime; //update time
|
||||
long waitTime; //time to wait
|
||||
|
||||
boolean running = true;
|
||||
|
||||
while (running) {
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
|
||||
tick();
|
||||
|
||||
uTime = System.currentTimeMillis() - startTime;
|
||||
waitTime = config.getInt("tick_length") - uTime;
|
||||
|
||||
try {
|
||||
if (waitTime >= 0) {
|
||||
Thread.sleep(waitTime);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void tick() {
|
||||
gameUniverse.incrementTime();
|
||||
|
||||
//Dispatch tick event
|
||||
GameEvent event = new TickEvent(gameUniverse.getTime());
|
||||
eventDispatcher.dispatch(event); //Ignore cancellation
|
||||
|
||||
//Process user code
|
||||
for (User user : gameUniverse.getUsers()) {
|
||||
|
||||
if (user.getControlledUnit() != null && user.getControlledUnit().getCpu() != null) {
|
||||
try {
|
||||
|
||||
int timeout = Math.min(user.getControlledUnit().getEnergy(), maxExecutionTime);
|
||||
|
||||
user.getControlledUnit().getCpu().reset();
|
||||
int cost = user.getControlledUnit().getCpu().execute(timeout);
|
||||
user.getControlledUnit().spendEnergy(cost);
|
||||
user.addTime(cost);
|
||||
|
||||
} catch (Exception e) {
|
||||
LogManager.LOGGER.severe("Error executing " + user.getUsername() + "'s code");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Process each worlds
|
||||
for (World world : gameUniverse.getWorlds()) {
|
||||
if (world.shouldUpdate()) {
|
||||
world.update();
|
||||
}
|
||||
}
|
||||
|
||||
//Save
|
||||
if (gameUniverse.getTime() % config.getInt("save_interval") == 0) {
|
||||
save();
|
||||
}
|
||||
|
||||
socketServer.tick();
|
||||
}
|
||||
|
||||
void load() {
|
||||
|
||||
LogManager.LOGGER.info("Loading all data from MongoDB");
|
||||
|
||||
MongoDatabase db = mongo.getDatabase(config.getString("mongo_dbname"));
|
||||
|
||||
MongoCollection<Document> worlds = db.getCollection("world");
|
||||
MongoCollection<Document> server = db.getCollection("server");
|
||||
|
||||
Document whereQuery = new Document();
|
||||
whereQuery.put("shouldUpdate", true);
|
||||
MongoCursor<Document> cursor = worlds.find(whereQuery).iterator();
|
||||
GameUniverse universe = GameServer.INSTANCE.getGameUniverse();
|
||||
while (cursor.hasNext()) {
|
||||
World w = World.deserialize(cursor.next());
|
||||
universe.addWorld(w);
|
||||
}
|
||||
|
||||
//Load users
|
||||
ArrayList<User> userList = userManager.getUsers();
|
||||
for (User user : userList) {
|
||||
universe.addUser(user);
|
||||
}
|
||||
|
||||
//Load server & plugin data
|
||||
cursor = server.find().iterator();
|
||||
if (cursor.hasNext()) {
|
||||
Document serverObj = cursor.next();
|
||||
gameUniverse.setTime((long) serverObj.get("time"));
|
||||
|
||||
Document plugins = (Document) serverObj.get("plugins");
|
||||
|
||||
for (String pluginName : plugins.keySet()) {
|
||||
ServerPlugin plugin = pluginManager.getPluginByName(pluginName);
|
||||
plugin.load((Document) plugins.get(pluginName));
|
||||
}
|
||||
}
|
||||
|
||||
LogManager.LOGGER.info("Done loading! W:" + GameServer.INSTANCE.getGameUniverse().getWorldCount() +
|
||||
" | U:" + GameServer.INSTANCE.getGameUniverse().getUserCount());
|
||||
}
|
||||
|
||||
public void save() {
|
||||
|
||||
LogManager.LOGGER.info("Saving to MongoDB | W:" + gameUniverse.getWorldCount() + " | U:" + gameUniverse.getUserCount());
|
||||
|
||||
ClientSession session = null;
|
||||
try {
|
||||
try {
|
||||
session = mongo.startSession();
|
||||
session.startTransaction();
|
||||
} catch (MongoClientException e) {
|
||||
LogManager.LOGGER.fine("Could not create mongoDB session, will not use transaction feature. " +
|
||||
"(This message can be safely ignored)");
|
||||
}
|
||||
|
||||
MongoDatabase db = mongo.getDatabase(config.getString("mongo_dbname"));
|
||||
ReplaceOptions updateOptions = new ReplaceOptions();
|
||||
updateOptions.upsert(true);
|
||||
|
||||
int unloaded_worlds = 0;
|
||||
|
||||
MongoCollection<Document> worlds = db.getCollection("world");
|
||||
MongoCollection<Document> users = db.getCollection("user");
|
||||
MongoCollection<Document> server = db.getCollection("server");
|
||||
|
||||
int insertedWorlds = 0;
|
||||
GameUniverse universe = GameServer.INSTANCE.getGameUniverse();
|
||||
for (World w : universe.getWorlds()) {
|
||||
insertedWorlds++;
|
||||
worlds.replaceOne(new Document("_id", w.getId()), w.mongoSerialise(), updateOptions);
|
||||
|
||||
//If the world should unload, it is removed from the Universe after having been saved.
|
||||
if (w.shouldUnload()) {
|
||||
unloaded_worlds++;
|
||||
universe.removeWorld(w);
|
||||
}
|
||||
}
|
||||
|
||||
for (User u : GameServer.INSTANCE.getGameUniverse().getUsers()) {
|
||||
if (!u.isGuest()) {
|
||||
users.replaceOne(new Document("_id", u.getUsername()), u.mongoSerialise(), updateOptions);
|
||||
}
|
||||
}
|
||||
|
||||
Document serverObj = new Document();
|
||||
serverObj.put("time", gameUniverse.getTime());
|
||||
|
||||
Document plugins = new Document();
|
||||
for (ServerPlugin plugin : pluginManager.getPlugins()) {
|
||||
plugins.put(plugin.getName(), plugin.mongoSerialise());
|
||||
}
|
||||
serverObj.put("plugins", plugins);
|
||||
|
||||
//A constant id ensures only one entry is kept and updated, instead of a new entry created every save.
|
||||
server.replaceOne(new Document("_id", "serverinfo"), serverObj, updateOptions);
|
||||
if (session != null) {
|
||||
session.commitTransaction();
|
||||
}
|
||||
|
||||
LogManager.LOGGER.info("" + insertedWorlds + " worlds saved, " + unloaded_worlds + " unloaded");
|
||||
} catch (Exception e) {
|
||||
LogManager.LOGGER.severe("Problem happened during save function");
|
||||
e.printStackTrace();
|
||||
|
||||
if (session != null) {
|
||||
session.commitTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IServerConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public PluginManager getPluginManager() {
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
public void setSocketServer(SocketServer socketServer) {
|
||||
this.socketServer = socketServer;
|
||||
}
|
||||
|
||||
public DayNightCycle getDayNightCycle() {
|
||||
return dayNightCycle;
|
||||
}
|
||||
|
||||
public UserManager getUserManager() {
|
||||
return userManager;
|
||||
}
|
||||
|
||||
public UserStatsHelper getUserStatsHelper() {
|
||||
return userStatsHelper;
|
||||
}
|
||||
|
||||
public GameRegistry getRegistry() {
|
||||
return gameRegistry;
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
config.setString("secret_key", secretKey);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.simon987.mar.server;
|
||||
package net.simon987.server;
|
||||
|
||||
public interface IServerConfiguration {
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
package net.simon987.mar.server;
|
||||
package net.simon987.server;
|
||||
|
||||
import net.simon987.mar.server.logging.LogManager;
|
||||
import net.simon987.mar.server.web.WebServer;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.web.WebServer;
|
||||
import spark.Spark;
|
||||
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
ServerConfiguration config = new ServerConfiguration("config.properties");
|
||||
LogManager.initialize(config);
|
||||
|
||||
GameServer.INSTANCE.load();
|
||||
|
||||
//Web server
|
||||
WebServer webServer = new WebServer(GameServer.INSTANCE.getConfig());
|
||||
|
||||
Spark.awaitInitialization();
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.simon987.mar.server;
|
||||
package net.simon987.server;
|
||||
|
||||
|
||||
import net.simon987.mar.server.logging.LogManager;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Properties;
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.simon987.mar.server.assembly;
|
||||
package net.simon987.server.assembly;
|
||||
|
||||
import net.simon987.mar.server.IServerConfiguration;
|
||||
import net.simon987.mar.server.assembly.exception.*;
|
||||
import net.simon987.mar.server.logging.LogManager;
|
||||
import net.simon987.server.IServerConfiguration;
|
||||
import net.simon987.server.assembly.exception.*;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -18,13 +18,15 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class Assembler {
|
||||
|
||||
private static final String labelPattern = "^\\s*[a-zA-Z_]\\w*:";
|
||||
private static final Pattern commentPattern = Pattern.compile("\"[^\"]*\"|(;)");
|
||||
private final IServerConfiguration config;
|
||||
private IServerConfiguration config;
|
||||
|
||||
private InstructionSet instructionSet;
|
||||
|
||||
private RegisterSet registerSet;
|
||||
|
||||
private static int MEM_SIZE;
|
||||
private final InstructionSet instructionSet;
|
||||
private final RegisterSet registerSet;
|
||||
private static String labelPattern = "^\\s*[a-zA-Z_]\\w*:";
|
||||
private static Pattern commentPattern = Pattern.compile("\"[^\"]*\"|(;)");
|
||||
|
||||
public Assembler(InstructionSet instructionSet, RegisterSet registerSet, IServerConfiguration config) {
|
||||
this.instructionSet = instructionSet;
|
||||
@@ -61,6 +63,7 @@ public class Assembler {
|
||||
* @return The line without its label part
|
||||
*/
|
||||
private static String removeLabel(String line) {
|
||||
|
||||
return line.replaceAll(labelPattern, "");
|
||||
}
|
||||
|
||||
@@ -245,7 +248,7 @@ public class Assembler {
|
||||
int factor = Integer.decode(valueTokens[0]);
|
||||
|
||||
if (factor > MEM_SIZE) {
|
||||
throw new InvalidOperandException("Factor '" + factor + "' exceeds total memory size", currentLine);
|
||||
throw new InvalidOperandException("Factor '"+factor+"' exceeds total memory size", currentLine);
|
||||
}
|
||||
|
||||
String value = valueTokens[1].substring(4, valueTokens[1].lastIndexOf(')'));
|
||||
@@ -284,15 +287,14 @@ public class Assembler {
|
||||
*
|
||||
* @param line Current line
|
||||
*/
|
||||
private void checkForSectionDeclaration(String line, AssemblyResult result,
|
||||
int currentLine, int currentOffset) throws AssemblyException {
|
||||
private static void checkForSectionDeclaration(String line, AssemblyResult result,
|
||||
int currentLine, int currentOffset) throws AssemblyException {
|
||||
|
||||
String[] tokens = line.split("\\s+");
|
||||
|
||||
if (tokens[0].toUpperCase().equals(".TEXT")) {
|
||||
|
||||
result.defineSection(Section.TEXT, currentLine, currentOffset);
|
||||
result.disassemblyLines.add(".text");
|
||||
throw new PseudoInstructionException(currentLine);
|
||||
|
||||
} else if (tokens[0].toUpperCase().equals(".DATA")) {
|
||||
@@ -417,10 +419,10 @@ public class Assembler {
|
||||
int currentOffset = 0;
|
||||
for (int currentLine = 0; currentLine < lines.length; currentLine++) {
|
||||
try {
|
||||
checkForLabel(lines[currentLine], result, (char) currentOffset);
|
||||
checkForLabel(lines[currentLine], result, (char)currentOffset);
|
||||
|
||||
//Increment offset
|
||||
currentOffset += parseInstruction(result, lines[currentLine], currentLine, currentOffset, instructionSet).length / 2;
|
||||
currentOffset += parseInstruction(lines[currentLine], currentLine, instructionSet).length / 2;
|
||||
|
||||
if (currentOffset >= MEM_SIZE) {
|
||||
throw new OffsetOverflowException(currentOffset, MEM_SIZE, currentLine);
|
||||
@@ -455,15 +457,8 @@ public class Assembler {
|
||||
checkForEQUInstruction(line, result.labels, currentLine);
|
||||
checkForORGInstruction(line, result, currentLine);
|
||||
|
||||
for (String label : result.labels.keySet()) {
|
||||
if (result.labels.get(label) == result.origin + currentOffset) {
|
||||
result.disassemblyLines.add(String.format(" %s:", label));
|
||||
}
|
||||
}
|
||||
|
||||
//Encode instruction
|
||||
byte[] bytes = parseInstruction(result, line, currentLine, result.origin + currentOffset, result.labels, instructionSet);
|
||||
result.codeLineMap.put(result.origin + currentOffset, result.disassemblyLines.size() - 1);
|
||||
byte[] bytes = parseInstruction(line, currentLine, result.labels, instructionSet);
|
||||
currentOffset += bytes.length / 2;
|
||||
|
||||
if (currentOffset >= MEM_SIZE) {
|
||||
@@ -494,8 +489,8 @@ public class Assembler {
|
||||
* @param currentLine Current line
|
||||
* @return The encoded instruction
|
||||
*/
|
||||
private byte[] parseInstruction(AssemblyResult result, String line, int currentLine, int offset, InstructionSet instructionSet) throws AssemblyException {
|
||||
return parseInstruction(result, line, currentLine, offset, null, instructionSet, true);
|
||||
private byte[] parseInstruction(String line, int currentLine, InstructionSet instructionSet) throws AssemblyException {
|
||||
return parseInstruction(line, currentLine, null, instructionSet, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -506,10 +501,10 @@ public class Assembler {
|
||||
* @param labels List of labels
|
||||
* @return The encoded instruction
|
||||
*/
|
||||
private byte[] parseInstruction(AssemblyResult result, String line, int currentLine, int offset,
|
||||
HashMap<String, Character> labels, InstructionSet instructionSet)
|
||||
private byte[] parseInstruction(String line, int currentLine, HashMap<String, Character> labels,
|
||||
InstructionSet instructionSet)
|
||||
throws AssemblyException {
|
||||
return parseInstruction(result, line, currentLine, offset, labels, instructionSet, false);
|
||||
return parseInstruction(line, currentLine, labels, instructionSet, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -521,7 +516,7 @@ public class Assembler {
|
||||
* @param assumeLabels Assume that unknown operands are labels
|
||||
* @return The encoded instruction
|
||||
*/
|
||||
private byte[] parseInstruction(AssemblyResult result, String line, int currentLine, int offset, HashMap<String, Character> labels,
|
||||
private byte[] parseInstruction(String line, int currentLine, HashMap<String, Character> labels,
|
||||
InstructionSet instructionSet, boolean assumeLabels)
|
||||
throws AssemblyException {
|
||||
|
||||
@@ -562,8 +557,6 @@ public class Assembler {
|
||||
throw new InvalidMnemonicException(mnemonic, currentLine);
|
||||
}
|
||||
|
||||
StringBuilder disassembly = new StringBuilder();
|
||||
|
||||
//Check operands and encode instruction
|
||||
final int beginIndex = line.indexOf(mnemonic) + mnemonic.length();
|
||||
if (line.contains(",")) {
|
||||
@@ -585,17 +578,6 @@ public class Assembler {
|
||||
//Get instruction by name
|
||||
instructionSet.get(mnemonic).encode(out, o1, o2, currentLine);
|
||||
|
||||
if (!assumeLabels) {
|
||||
byte[] bytes = out.toByteArray();
|
||||
for (int i = 0; i < bytes.length; i += 2) {
|
||||
disassembly.append(String.format("%02X%02X ", bytes[i], bytes[i + 1]));
|
||||
}
|
||||
result.disassemblyLines.add(String.format(
|
||||
"%04X %-15s %s %s, %s", offset, disassembly, mnemonic.toUpperCase(),
|
||||
o1.toString(registerSet), o2.toString(registerSet)
|
||||
));
|
||||
}
|
||||
|
||||
} else if (tokens.length > 1) {
|
||||
//1 operand
|
||||
|
||||
@@ -611,32 +593,12 @@ public class Assembler {
|
||||
//Encode instruction
|
||||
//Get instruction by name
|
||||
instructionSet.get(mnemonic).encode(out, o1, currentLine);
|
||||
|
||||
if (!assumeLabels) {
|
||||
byte[] bytes = out.toByteArray();
|
||||
for (int i = 0; i < bytes.length; i += 2) {
|
||||
disassembly.append(String.format("%02X%02X ", bytes[i], bytes[i + 1]));
|
||||
}
|
||||
result.disassemblyLines.add(String.format(
|
||||
"%04X %-15s %s %s", offset, disassembly, mnemonic.toUpperCase(), o1.toString(registerSet)
|
||||
));
|
||||
}
|
||||
} else {
|
||||
//No operand
|
||||
|
||||
//Encode instruction
|
||||
//Get instruction by name
|
||||
instructionSet.get(mnemonic).encode(out, currentLine);
|
||||
|
||||
if (!assumeLabels) {
|
||||
byte[] bytes = out.toByteArray();
|
||||
for (int i = 0; i < bytes.length; i += 2) {
|
||||
disassembly.append(String.format("%02X%02X ", bytes[i], bytes[i + 1]));
|
||||
}
|
||||
result.disassemblyLines.add(String.format(
|
||||
"%04X %-15s %s", offset, disassembly, mnemonic.toUpperCase()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return out.toByteArray();
|
||||
@@ -1,16 +1,14 @@
|
||||
package net.simon987.mar.server.assembly;
|
||||
package net.simon987.server.assembly;
|
||||
|
||||
import net.simon987.mar.server.IServerConfiguration;
|
||||
import net.simon987.mar.server.assembly.exception.AssemblyException;
|
||||
import net.simon987.mar.server.assembly.exception.DuplicateSectionException;
|
||||
import net.simon987.mar.server.logging.LogManager;
|
||||
import net.simon987.server.IServerConfiguration;
|
||||
import net.simon987.server.assembly.exception.AssemblyException;
|
||||
import net.simon987.server.assembly.exception.DuplicateSectionException;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Result of an assembly attempt
|
||||
@@ -24,7 +22,7 @@ public class AssemblyResult {
|
||||
/**
|
||||
* A list of labels
|
||||
*/
|
||||
public HashMap<String, Character> labels = new HashMap<>(20);
|
||||
HashMap<String, Character> labels = new HashMap<>(20);
|
||||
/**
|
||||
* List of exceptions encountered during the assembly attempt,
|
||||
* they will be displayed in the editor
|
||||
@@ -61,14 +59,8 @@ public class AssemblyResult {
|
||||
*/
|
||||
private boolean dataSectionSet = false;
|
||||
|
||||
public final Map<Integer, Integer> codeLineMap;
|
||||
|
||||
public List<String> disassemblyLines;
|
||||
|
||||
AssemblyResult(IServerConfiguration config) {
|
||||
origin = config.getInt("org_offset");
|
||||
codeLineMap = new HashMap<>();
|
||||
disassemblyLines = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1,16 +1,15 @@
|
||||
package net.simon987.mar.server.assembly;
|
||||
package net.simon987.server.assembly;
|
||||
|
||||
import net.simon987.mar.server.GameServer;
|
||||
import net.simon987.mar.server.IServerConfiguration;
|
||||
import net.simon987.mar.server.assembly.exception.CancelledException;
|
||||
import net.simon987.mar.server.assembly.instruction.*;
|
||||
import net.simon987.mar.server.event.CpuInitialisationEvent;
|
||||
import net.simon987.mar.server.event.GameEvent;
|
||||
import net.simon987.mar.server.game.GameUniverse;
|
||||
import net.simon987.mar.server.game.objects.ControllableUnit;
|
||||
import net.simon987.mar.server.game.objects.HardwareHost;
|
||||
import net.simon987.mar.server.io.MongoSerializable;
|
||||
import net.simon987.mar.server.logging.LogManager;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.IServerConfiguration;
|
||||
import net.simon987.server.assembly.exception.CancelledException;
|
||||
import net.simon987.server.assembly.instruction.*;
|
||||
import net.simon987.server.event.CpuInitialisationEvent;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.HardwareHost;
|
||||
import net.simon987.server.io.MongoSerializable;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
@@ -20,10 +19,10 @@ import org.bson.Document;
|
||||
*/
|
||||
public class CPU implements MongoSerializable {
|
||||
|
||||
private final Status status;
|
||||
|
||||
private boolean trapFlag = false;
|
||||
private boolean executing = false;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Status status;
|
||||
|
||||
/**
|
||||
* Memory associated with the CPU, 64kb max
|
||||
@@ -33,7 +32,7 @@ public class CPU implements MongoSerializable {
|
||||
/**
|
||||
* set of instructions of this CPU
|
||||
*/
|
||||
private final InstructionSet instructionSet;
|
||||
private InstructionSet instructionSet;
|
||||
|
||||
/**
|
||||
* set of registers of this CPU
|
||||
@@ -46,19 +45,11 @@ public class CPU implements MongoSerializable {
|
||||
*/
|
||||
private int codeSectionOffset;
|
||||
|
||||
private int interruptVectorTableOffset;
|
||||
private final int graceInstructionCount;
|
||||
private int graceInstructionsLeft;
|
||||
private boolean isGracePeriod;
|
||||
private int instructionAllocation;
|
||||
|
||||
/**
|
||||
* Instruction pointer, always points to the next instruction
|
||||
*/
|
||||
private int ip;
|
||||
|
||||
public static final int INSTRUCTION_COST = 10000;
|
||||
|
||||
/**
|
||||
* Hardware is connected to the hardwareHost
|
||||
*/
|
||||
@@ -66,10 +57,14 @@ public class CPU implements MongoSerializable {
|
||||
|
||||
private int registerSetSize;
|
||||
|
||||
private static final char EXECUTION_COST_ADDR = 0x0150;
|
||||
private static final char EXECUTED_INS_ADDR = 0x0151;
|
||||
private static final char EXECUTION_COST_ADDR = 0x0050;
|
||||
private static final char EXECUTED_INS_ADDR = 0x0051;
|
||||
|
||||
public CPU() {
|
||||
instructionSet = new DefaultInstructionSet();
|
||||
registerSet = new DefaultRegisterSet();
|
||||
codeSectionOffset = GameServer.INSTANCE.getConfig().getInt("org_offset");
|
||||
|
||||
private void addInstructions() {
|
||||
instructionSet.add(new JmpInstruction(this));
|
||||
instructionSet.add(new JnzInstruction(this));
|
||||
instructionSet.add(new JzInstruction(this));
|
||||
@@ -96,131 +91,112 @@ public class CPU implements MongoSerializable {
|
||||
instructionSet.add(new PopfInstruction(this));
|
||||
instructionSet.add(new JnaInstruction(this));
|
||||
instructionSet.add(new JaInstruction(this));
|
||||
instructionSet.add(new IntInstruction(this));
|
||||
instructionSet.add(new IntoInstruction(this));
|
||||
instructionSet.add(new IretInstruction(this));
|
||||
}
|
||||
|
||||
public CPU() {
|
||||
instructionSet = new DefaultInstructionSet();
|
||||
registerSet = new DefaultRegisterSet();
|
||||
IServerConfiguration config = GameServer.INSTANCE.getConfig();
|
||||
codeSectionOffset = config.getInt("org_offset");
|
||||
graceInstructionCount = config.getInt("grace_instruction_count");
|
||||
|
||||
interruptVectorTableOffset = config.getInt("ivt_offset");
|
||||
|
||||
addInstructions();
|
||||
status = new Status();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new CPU
|
||||
*/
|
||||
public CPU(IServerConfiguration config) throws CancelledException {
|
||||
public CPU(IServerConfiguration config, ControllableUnit unit) throws CancelledException {
|
||||
instructionSet = new DefaultInstructionSet();
|
||||
registerSet = new DefaultRegisterSet();
|
||||
codeSectionOffset = config.getInt("org_offset");
|
||||
graceInstructionCount = config.getInt("grace_instruction_count");
|
||||
|
||||
interruptVectorTableOffset = config.getInt("ivt_offset");
|
||||
|
||||
addInstructions();
|
||||
instructionSet.add(new JmpInstruction(this));
|
||||
instructionSet.add(new JnzInstruction(this));
|
||||
instructionSet.add(new JzInstruction(this));
|
||||
instructionSet.add(new JgInstruction(this));
|
||||
instructionSet.add(new JgeInstruction(this));
|
||||
instructionSet.add(new JleInstruction(this));
|
||||
instructionSet.add(new JlInstruction(this));
|
||||
instructionSet.add(new PushInstruction(this));
|
||||
instructionSet.add(new PopInstruction(this));
|
||||
instructionSet.add(new CallInstruction(this));
|
||||
instructionSet.add(new RetInstruction(this));
|
||||
instructionSet.add(new MulInstruction(this));
|
||||
instructionSet.add(new DivInstruction(this));
|
||||
instructionSet.add(new JnsInstruction(this));
|
||||
instructionSet.add(new JsInstruction(this));
|
||||
instructionSet.add(new HwiInstruction(this));
|
||||
instructionSet.add(new HwqInstruction(this));
|
||||
instructionSet.add(new XchgInstruction(this));
|
||||
instructionSet.add(new JcInstruction(this));
|
||||
instructionSet.add(new JncInstruction(this));
|
||||
instructionSet.add(new JnoInstruction(this));
|
||||
instructionSet.add(new JoInstruction(this));
|
||||
instructionSet.add(new PushfInstruction(this));
|
||||
instructionSet.add(new PopfInstruction(this));
|
||||
instructionSet.add(new JnaInstruction(this));
|
||||
instructionSet.add(new JaInstruction(this));
|
||||
|
||||
status = new Status();
|
||||
memory = new Memory(config.getInt("memory_size"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the IP to IVT + number and pushes flags then the old IP
|
||||
*/
|
||||
public void interrupt(int number) {
|
||||
|
||||
if (number == 3) {
|
||||
trapFlag = true;
|
||||
return;
|
||||
GameEvent event = new CpuInitialisationEvent(this, unit);
|
||||
GameServer.INSTANCE.getEventDispatcher().dispatch(event);
|
||||
if (event.isCancelled()) {
|
||||
throw new CancelledException();
|
||||
}
|
||||
|
||||
Instruction push = instructionSet.get(PushInstruction.OPCODE);
|
||||
push.execute(status.toWord(), status);
|
||||
push.execute(ip, status);
|
||||
|
||||
this.setIp((char) memory.get(interruptVectorTableOffset + number));
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
status.clear();
|
||||
ip = codeSectionOffset;
|
||||
graceInstructionsLeft = graceInstructionCount;
|
||||
isGracePeriod = false;
|
||||
trapFlag = false;
|
||||
}
|
||||
|
||||
public void setInstructionAlloction(int instructionAllocation) {
|
||||
this.instructionAllocation = instructionAllocation;
|
||||
}
|
||||
public int execute(int timeout) {
|
||||
|
||||
public int execute() {
|
||||
|
||||
executing = true;
|
||||
long startTime = System.currentTimeMillis();
|
||||
int counter = 0;
|
||||
status.clear();
|
||||
|
||||
registerSetSize = registerSet.size();
|
||||
|
||||
// status.breakFlag = true;
|
||||
while (!status.isBreakFlag()) {
|
||||
counter++;
|
||||
|
||||
if (isGracePeriod) {
|
||||
if (graceInstructionsLeft-- <= 0) {
|
||||
writeExecutionStats(counter);
|
||||
return counter / INSTRUCTION_COST;
|
||||
if (counter % 10000 == 0) {
|
||||
if (System.currentTimeMillis() > (startTime + timeout)) {
|
||||
LogManager.LOGGER.fine("CPU Timeout " + this + " after " + counter + "instructions (" + timeout + "ms): " + (double) counter / ((double) timeout / 1000) / 1000000 + "MHz");
|
||||
|
||||
//Write execution cost and instruction count to memory
|
||||
memory.set(EXECUTION_COST_ADDR, timeout);
|
||||
memory.set(EXECUTED_INS_ADDR, Util.getHigherWord(counter));
|
||||
memory.set(EXECUTED_INS_ADDR + 1, Util.getLowerWord(counter));
|
||||
|
||||
return timeout;
|
||||
}
|
||||
} else if (instructionAllocation-- <= 0) {
|
||||
interrupt(IntInstruction.INT_EXEC_LIMIT_REACHED);
|
||||
isGracePeriod = true;
|
||||
}
|
||||
|
||||
step();
|
||||
//fetch instruction
|
||||
int machineCode = memory.get(ip);
|
||||
|
||||
if (trapFlag) {
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Contents of machineCode should look like this:
|
||||
* SSSS SDDD DDOO OOOO
|
||||
* Where S is source, D is destination and O is the opCode
|
||||
*/
|
||||
Instruction instruction = instructionSet.get(machineCode & 0x03F); // 0000 0000 00XX XXXX
|
||||
|
||||
int source = (machineCode >> 11) & 0x001F; // XXXX X000 0000 0000
|
||||
int destination = (machineCode >> 6) & 0x001F; // 0000 0XXX XX00 0000
|
||||
|
||||
executeInstruction(instruction, source, destination);
|
||||
// LogManager.LOGGER.info(instruction.getMnemonic());
|
||||
}
|
||||
int elapsed = (int) (System.currentTimeMillis() - startTime);
|
||||
|
||||
// LogManager.LOGGER.fine(counter + " instruction in " + elapsed + "ms : " + (double) counter / (elapsed / 1000) / 1000000 + "MHz");
|
||||
|
||||
writeExecutionStats(counter);
|
||||
|
||||
executing = false;
|
||||
return counter / INSTRUCTION_COST;
|
||||
}
|
||||
|
||||
public void step() {
|
||||
//fetch instruction
|
||||
int machineCode = memory.get(ip);
|
||||
|
||||
/*
|
||||
* Contents of machineCode should look like this:
|
||||
* SSSS SDDD DDOO OOOO
|
||||
* Where S is source, D is destination and O is the opCode
|
||||
*/
|
||||
Instruction instruction = instructionSet.get(machineCode & 0x03F); // 0000 0000 00XX XXXX
|
||||
|
||||
int source = (machineCode >> 11) & 0x001F; // XXXX X000 0000 0000
|
||||
int destination = (machineCode >> 6) & 0x001F; // 0000 0XXX XX00 0000
|
||||
|
||||
executeInstruction(instruction, source, destination);
|
||||
// LogManager.LOGGER.info(instruction.getMnemonic());
|
||||
|
||||
if (status.isBreakFlag()) {
|
||||
trapFlag = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void writeExecutionStats(int counter) {
|
||||
//Write execution cost and instruction count to memory
|
||||
memory.set(EXECUTION_COST_ADDR, elapsed);
|
||||
memory.set(EXECUTED_INS_ADDR, Util.getHigherWord(counter));
|
||||
memory.set(EXECUTED_INS_ADDR + 1, Util.getLowerWord(counter));
|
||||
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
public void executeInstruction(Instruction instruction, int source, int destination) {
|
||||
@@ -422,20 +398,15 @@ public class CPU implements MongoSerializable {
|
||||
|
||||
public static CPU deserialize(Document obj, ControllableUnit unit) throws CancelledException {
|
||||
|
||||
CPU cpu = new CPU(GameServer.INSTANCE.getConfig());
|
||||
CPU cpu = new CPU(GameServer.INSTANCE.getConfig(), unit);
|
||||
|
||||
cpu.codeSectionOffset = obj.getInteger("codeSegmentOffset");
|
||||
|
||||
cpu.memory = new Memory((Document) obj.get("memory"));
|
||||
cpu.registerSet = RegisterSet.deserialize((Document) obj.get("registerSet"));
|
||||
|
||||
GameEvent event = new CpuInitialisationEvent(cpu, unit);
|
||||
GameServer.INSTANCE.getEventDispatcher().dispatch(event);
|
||||
if (event.isCancelled()) {
|
||||
throw new CancelledException();
|
||||
}
|
||||
|
||||
return cpu;
|
||||
|
||||
}
|
||||
|
||||
public InstructionSet getInstructionSet() {
|
||||
@@ -481,6 +452,7 @@ public class CPU implements MongoSerializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
String str = registerSet.toString();
|
||||
str += status.toString();
|
||||
|
||||
@@ -494,27 +466,4 @@ public class CPU implements MongoSerializable {
|
||||
public void setHardwareHost(HardwareHost hardwareHost) {
|
||||
this.hardwareHost = hardwareHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* For testing/debugging, this creates an copy (please be mindful of the memory usage)
|
||||
*/
|
||||
public CpuState getState() {
|
||||
return new CpuState(
|
||||
registerSet.clone(),
|
||||
memory.clone(),
|
||||
status.clone()
|
||||
);
|
||||
}
|
||||
|
||||
public boolean isPaused() {
|
||||
return trapFlag;
|
||||
}
|
||||
|
||||
public boolean isExecuting() {
|
||||
return executing;
|
||||
}
|
||||
|
||||
public void setTrapFlag(boolean trapFlag) {
|
||||
this.trapFlag = trapFlag;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.simon987.mar.server.assembly;
|
||||
package net.simon987.server.assembly;
|
||||
|
||||
import net.simon987.mar.server.assembly.instruction.*;
|
||||
import net.simon987.server.assembly.instruction.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -13,14 +13,14 @@ public class DefaultInstructionSet implements InstructionSet {
|
||||
/**
|
||||
* Map of instructions, stored in opcode : Instruction format
|
||||
*/
|
||||
private final Map<Integer, Instruction> instructionMap = new HashMap<>(32);
|
||||
private Map<Integer, Instruction> instructionMap = new HashMap<>(32);
|
||||
|
||||
/**
|
||||
* Map of aliasses, stored in mnemonic : Instruction format
|
||||
*/
|
||||
private final Map<String, Instruction> aliasesMap = new HashMap<>(16);
|
||||
private Map<String, Instruction> aliasesMap = new HashMap<>(16);
|
||||
|
||||
private final Instruction defaultInstruction;
|
||||
private Instruction defaultInstruction;
|
||||
|
||||
/**
|
||||
* Create an empty instruction set
|
||||
@@ -116,7 +116,11 @@ public class DefaultInstructionSet implements InstructionSet {
|
||||
}
|
||||
|
||||
Instruction aliasedInstruction = aliasesMap.get(mnemonic.toLowerCase());
|
||||
return aliasedInstruction;
|
||||
if (aliasedInstruction != null) {
|
||||
return aliasedInstruction;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Add a new instruction to the instructionSet
|
||||
22
Server/src/main/java/net/simon987/server/assembly/DefaultRegisterSet.java
Executable file
22
Server/src/main/java/net/simon987/server/assembly/DefaultRegisterSet.java
Executable file
@@ -0,0 +1,22 @@
|
||||
package net.simon987.server.assembly;
|
||||
|
||||
/**
|
||||
* RegisterSet with default values
|
||||
*/
|
||||
class DefaultRegisterSet extends RegisterSet {
|
||||
|
||||
|
||||
DefaultRegisterSet() {
|
||||
super();
|
||||
|
||||
addRegister(1, new Register("A"));
|
||||
addRegister(2, new Register("B"));
|
||||
addRegister(3, new Register("C"));
|
||||
addRegister(4, new Register("D"));
|
||||
addRegister(5, new Register("X"));
|
||||
addRegister(6, new Register("Y"));
|
||||
addRegister(7, new Register("SP"));
|
||||
addRegister(8, new Register("BP"));
|
||||
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user