4 Commits

Author SHA1 Message Date
d5b10b9b04 More obstacle WIP 2019-11-08 09:40:38 -05:00
3266cbd32d Update .gitignore 2019-11-08 09:40:38 -05:00
a189fbfc90 blueprint wip 2019-11-08 09:40:38 -05:00
simon987
6a8d2bd0d6 wip 2019-11-08 09:40:38 -05:00
37 changed files with 587 additions and 476 deletions

18
.gitignore vendored
View File

@@ -1,22 +1,18 @@
plugins/Plugin NPC.jar
plugins/Plugin Misc HW.jar
plugins/Plant.jar
plugins/Cubot.jar
.idea/*
.idea/
out/
data/
history
mar.log
mar.log.lck
*.iml
*.class
*/target/*
plugins/*.jar
save.json
Server/Server.iml
target/*
Server/Server.iml
Server/src/main/java/META-INF/MANIFEST.MF
META-INF/
.settings
.project
.classpath
# VSCode Workspace
.vscode/
.vscode/

View File

@@ -1,59 +0,0 @@
<?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>

View File

@@ -11,7 +11,6 @@ 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;
@@ -201,7 +200,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
JSONObject json = super.jsonSerialise();
json.put("direction", getDirection().ordinal());
CubotInventory inv = (CubotInventory) getHardware(CubotInventory.class);
int heldItem = inv.getInventory().getOrDefault(inv.getPosition(), new ItemVoid()).getId();
int heldItem = inv.getCurrentItem().getId();
json.put("heldItem", heldItem);
json.put("hp", hp);
json.put("shield", shield);

View File

@@ -4,6 +4,7 @@ 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.item.ItemVoid;
import net.simon987.server.game.objects.ControllableUnit;
import org.bson.Document;
@@ -55,11 +56,30 @@ public class CubotInventory extends HardwareModule {
private void scanItem() {
int x = getCpu().getRegisterSet().getRegister("X").getValue();
Item item = inventory.get(position);
if (item == null) {
return;
}
item.digitize(unit.getCpu().getMemory(), x);
}
public Item getCurrentItem() {
return inventory.getOrDefault(position, new ItemVoid());
}
public Item removeItem() {
Item item = inventory.get(position);
if (item == null) {
return new ItemVoid();
}
inventory.remove(position);
return item;
}
public Item clearItem() {
Item item = inventory.get(position);
if (item == null) {
return new ItemVoid();
}
item.clear(unit);
inventory.remove(position);

View File

@@ -3,6 +3,7 @@ package net.simon987.cubotplugin;
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.*;
import org.bson.Document;
@@ -24,7 +25,7 @@ public class CubotLaser extends HardwareModule {
private static final int LASER_DAMAGE = 25;
public CubotLaser(ControllableUnit unit) {
public CubotLaser(Cubot unit) {
super(null, unit);
}
@@ -32,26 +33,28 @@ public class CubotLaser extends HardwareModule {
super(document, cubot);
}
private Cubot getCubot() {
return (Cubot) unit;
}
@Override
public char getId() {
return HWID;
}
@Override
//TODO: Refactor this method..
public void handleInterrupt(Status status) {
int a = getCpu().getRegisterSet().getRegister("A").getValue();
int b = getCpu().getRegisterSet().getRegister("B").getValue();
if (a == LASER_WITHDRAW) {
Point frontTile = unit.getFrontTile();
ArrayList<GameObject> objects = unit.getWorld().getGameObjectsBlockingAt(frontTile.x, frontTile.y);
if (unit.getCurrentAction() == Action.IDLE && objects.size() > 0) {
//FIXME: Problem here if more than 1 object
if (objects.get(0) instanceof InventoryHolder) {
if (((InventoryHolder) objects.get(0)).canTakeItem(b)) {
@@ -65,9 +68,24 @@ public class CubotLaser extends HardwareModule {
}
}
} else if (a == LASER_DEPOSIT) {
// TODO
Point frontTile = unit.getFrontTile();
ArrayList<GameObject> objects = unit.getWorld().getGameObjectsBlockingAt(frontTile.x, frontTile.y);
CubotInventory inv = ((CubotInventory) getCubot().getHardware(CubotInventory.class));
Item item = inv.getCurrentItem();
if (unit.getCurrentAction() == Action.IDLE && objects.size() > 0) {
if (objects.get(0) instanceof InventoryHolder) {
if (((InventoryHolder) objects.get(0)).canPlaceItem(item.getId())) {
if (unit.spendEnergy(30)) {
//Place the item
((InventoryHolder) objects.get(0)).placeItem(inv.removeItem());
unit.setCurrentAction(Action.DEPOSITING);
}
}
}
}
} else if (a == LASER_ATTACK) {
if (unit.getCurrentAction() == Action.IDLE) {
@@ -81,12 +99,10 @@ public class CubotLaser extends HardwareModule {
if (objects.size() > 0 && objects.get(0) instanceof Attackable && !(objects.get(0) instanceof Cubot)) {
((Attackable) objects.get(0)).damage(LASER_DAMAGE);
}
}
unit.setCurrentAction(Action.ATTACKING);
}
}
}
}

View File

@@ -1,58 +0,0 @@
<?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>

View File

@@ -1,58 +0,0 @@
<?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>

View File

@@ -1,58 +0,0 @@
<?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>

View File

@@ -69,6 +69,11 @@ public class BiomassBlob extends GameObject implements InventoryHolder {
return false;
}
@Override
public boolean canPlaceItem(int itemId) {
return false;
}
@Override
public boolean canTakeItem(int itemId) {
return itemId == ItemBiomass.ID && biomassCount >= 1;

View File

@@ -1,32 +1,4 @@
package net.simon987.pluginradioactivecloud;
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 =
GameServer.INSTANCE.getConfig().getInt("radioactive_cloud_corruption_block_size");
/**
* Called when an object attempts to walk directly into a Enterable object
*
* @param object The game object that attempted to enter
* @return true if successful, false to block the object
*/
@Override
public boolean enter(GameObject object) {
if (object instanceof ControllableUnit) {
((ControllableUnit) object).getCpu().getMemory().corrupt(CORRUPTION_BLOCK_SIZE);
}
return true;
}
@Override
public char getMapInfo() {
return 0;
}
public class RadioactiveCloud {
}

View File

@@ -1,9 +1,10 @@
# Much-Assembly-Required
### [Official website](https://muchassemblyrequired.com)
[![CodeFactor](https://www.codefactor.io/repository/github/simon987/much-assembly-required/badge)](https://www.codefactor.io/repository/github/simon987/much-assembly-required)
[![Build Status](https://ci.simon987.net/buildStatus/icon?job=Much-Assembly-Required)](https://ci.simon987.net/job/Much-Assembly-Required/)
**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.
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.
![screenshot from 2017-11-12 13-01-43](https://user-images.githubusercontent.com/7120851/32701793-e5d07e98-c7a9-11e7-9931-f8db7b287994.png)
@@ -23,14 +24,13 @@ sudo apt install git maven openjdk-8-jdk mongodb
On Arch:
``` bash
sudo pacman -S git maven jdk8-opendjk
yay -S mongodb-bin
sudo pacman -S git maven mongodb jdk8-opendjk
# Don't forget to start mongodb
sudo systemctl start mongodb.service
```
*If needed, visit [yay installation](https://github.com/Jguer/yay#installation) and [troubleshooting mongodb](https://wiki.archlinux.org/index.php/MongoDB#Troubleshooting).*
*If needed, visit [troubleshooting mongodb](https://wiki.archlinux.org/index.php/MongoDB#Troubleshooting).*
**Deploying server**
@@ -51,12 +51,12 @@ java -jar server-1.4a.jar
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 environment variables.
Install the JDK and update your PATH and JAVA_HOME enviroment variables.
2. Download Maven from [here](https://maven.apache.org/).
Install Maven (following the README) and update your PATH environment variable.
Install Maven (following the README) and update your PATH enviroment 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 environment variable.
Update your PATH enviroment variable.
Building instructions:
```batch

View File

@@ -6,7 +6,6 @@
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
@@ -92,7 +91,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -114,7 +113,7 @@
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.1.11.RELEASE</version>
<version>5.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>com.sparkjava</groupId>

View File

@@ -94,6 +94,23 @@ public class Memory implements Target, MongoSerializable {
return true;
}
/**
* Read count words from the memory
*
* @return null if out of bounds
*/
public char[] read(int offset, int count) {
if (offset + count > this.words.length || count < 0 || offset < 0) {
return null;
}
char[] chars = new char[count];
System.arraycopy(words, offset, chars, 0, count);
return chars;
}
/**
* Set the value at an address
*

View File

@@ -20,4 +20,9 @@ public interface InventoryHolder {
* @return true if the InventoryHolder can provide this item
*/
boolean canTakeItem(int itemId);
/**
* @return true if the InventoryHolder can receive this item
*/
boolean canPlaceItem(int itemId);
}

View File

@@ -32,7 +32,7 @@ public class ItemsContainer extends GameObject implements InventoryHolder {
@Override
public boolean placeItem(Item item) {
if (items.size() < containerCapacity) {
if (canPlaceItem(item.getId())) {
items.add(item);
return true;
} else {
@@ -40,6 +40,11 @@ public class ItemsContainer extends GameObject implements InventoryHolder {
}
}
@Override
public boolean canPlaceItem(int itemId) {
return (items.size() < containerCapacity);
}
@Override
public void takeItem(int itemId) {
Optional<Item> first = items.stream()

View File

@@ -67,6 +67,10 @@ public class World implements MongoSerializable {
return getGameObjectsBlockingAt(x, y).size() > 0 || tileMap.getTileAt(x, y).isBlocked();
}
public boolean canBuild(int x, int y) {
return x == 0 || y == 0 || x == worldSize-1 || y == worldSize-1;
}
/**
* Computes the world's unique id from its coordinates.
*

View File

@@ -12,7 +12,7 @@ server_name=MAR dev
# ALLOW | BLOCK
guest_policy=ALLOW
# DEBUG
#autologin=simon
autologin=simon
#Database
mongo_dbname=mar_beta
@@ -93,9 +93,11 @@ electric_box_damage=5
electric_box_energy_given=70
#RadioactiveObstacle
radioactive_obstacle_corruption_block_size=10
radioactive_cloud_corruption_block_size=40
#SecretKey
secret_key=<your_secret_key>
# Construction
construction_site_ttl=512
construction_site_ttl=1024
obstacle_regen=1
obstacle_hp=150

View File

@@ -11376,120 +11376,24 @@
"y": 0.5
}
},
"objects/GOURD_PLANT": {
"objects/obstacle": {
"frame": {
"x": 768,
"y": 1050,
"w": 32,
"h": 32
"w": 128,
"h": 114
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 32,
"h": 32
"w": 128,
"h": 114
},
"sourceSize": {
"w": 32,
"h": 32
},
"pivot": {
"x": 0.5,
"y": 0.5
}
},
"objects/kiln": {
"frame": {
"x": 800,
"y": 1050,
"w": 116,
"h": 117
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 116,
"h": 117
},
"sourceSize": {
"w": 116,
"h": 117
},
"pivot": {
"x": 0.5,
"y": 0.5
}
},
"objects/kiln_s": {
"frame": {
"x": 916,
"y": 1050,
"w": 116,
"h": 117
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 116,
"h": 117
},
"sourceSize": {
"w": 116,
"h": 117
},
"pivot": {
"x": 0.5,
"y": 0.5
}
},
"objects/plant1": {
"frame": {
"x": 1032,
"y": 1050,
"w": 64,
"h": 64
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 64,
"h": 64
},
"sourceSize": {
"w": 64,
"h": 64
},
"pivot": {
"x": 0.5,
"y": 0.5
}
},
"objects/plant1_s": {
"frame": {
"x": 1096,
"y": 1050,
"w": 64,
"h": 64
},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 64,
"h": 64
},
"sourceSize": {
"w": 64,
"h": 64
"w": 128,
"h": 114
},
"pivot": {
"x": 0.5,
@@ -11498,7 +11402,7 @@
},
"objects/portal": {
"frame": {
"x": 1160,
"x": 896,
"y": 1050,
"w": 128,
"h": 110
@@ -11522,7 +11426,7 @@
},
"objects/RadioTower": {
"frame": {
"x": 1288,
"x": 1024,
"y": 1050,
"w": 168,
"h": 237
@@ -11546,7 +11450,7 @@
},
"objects/rocket": {
"frame": {
"x": 1456,
"x": 1192,
"y": 1050,
"w": 135,
"h": 189
@@ -11570,7 +11474,7 @@
},
"objects/shieldBack": {
"frame": {
"x": 1591,
"x": 1327,
"y": 1050,
"w": 128,
"h": 70
@@ -11594,7 +11498,7 @@
},
"objects/shieldFront": {
"frame": {
"x": 1719,
"x": 1455,
"y": 1050,
"w": 128,
"h": 70
@@ -11618,7 +11522,7 @@
},
"objects/VaultDoor": {
"frame": {
"x": 1847,
"x": 1583,
"y": 1050,
"w": 213,
"h": 170
@@ -11642,7 +11546,7 @@
},
"objects/VaultDoor1": {
"frame": {
"x": 2060,
"x": 1796,
"y": 1050,
"w": 139,
"h": 150
@@ -11666,7 +11570,7 @@
},
"objects/VaultDoorCrop": {
"frame": {
"x": 2199,
"x": 1935,
"y": 1050,
"w": 137,
"h": 150
@@ -11690,7 +11594,7 @@
},
"objects/VaultDoorScreen/1": {
"frame": {
"x": 2336,
"x": 2072,
"y": 1050,
"w": 20,
"h": 18
@@ -11714,7 +11618,7 @@
},
"objects/VaultDoorScreen/2": {
"frame": {
"x": 2356,
"x": 2092,
"y": 1050,
"w": 20,
"h": 18
@@ -11738,7 +11642,7 @@
},
"objects/VaultDoorScreen/3": {
"frame": {
"x": 2376,
"x": 2112,
"y": 1050,
"w": 20,
"h": 18
@@ -11762,7 +11666,7 @@
},
"objects/VaultDoorScreen/4": {
"frame": {
"x": 2396,
"x": 2132,
"y": 1050,
"w": 20,
"h": 18
@@ -11786,7 +11690,7 @@
},
"objects/VaultDoorScreen/5": {
"frame": {
"x": 2416,
"x": 2152,
"y": 1050,
"w": 20,
"h": 18
@@ -11810,7 +11714,7 @@
},
"objects/VaultDoorScreen/6": {
"frame": {
"x": 2436,
"x": 2172,
"y": 1050,
"w": 20,
"h": 18
@@ -11834,7 +11738,7 @@
},
"tiles/bigTile": {
"frame": {
"x": 2456,
"x": 2192,
"y": 1050,
"w": 128,
"h": 140
@@ -11858,7 +11762,7 @@
},
"tiles/bigTile2": {
"frame": {
"x": 2584,
"x": 2320,
"y": 1050,
"w": 128,
"h": 153
@@ -11882,7 +11786,7 @@
},
"tiles/magneticTile": {
"frame": {
"x": 2712,
"x": 2448,
"y": 1050,
"w": 128,
"h": 114
@@ -11906,7 +11810,7 @@
},
"tiles/tile": {
"frame": {
"x": 2840,
"x": 2576,
"y": 1050,
"w": 128,
"h": 114
@@ -11930,7 +11834,7 @@
},
"ui/arrow_east": {
"frame": {
"x": 2968,
"x": 2704,
"y": 1050,
"w": 102,
"h": 51
@@ -11954,7 +11858,7 @@
},
"ui/arrow_east_s": {
"frame": {
"x": 3070,
"x": 2806,
"y": 1050,
"w": 102,
"h": 51
@@ -11978,7 +11882,7 @@
},
"ui/arrow_north": {
"frame": {
"x": 3172,
"x": 2908,
"y": 1050,
"w": 102,
"h": 51
@@ -12002,7 +11906,7 @@
},
"ui/arrow_north_s": {
"frame": {
"x": 3274,
"x": 3010,
"y": 1050,
"w": 102,
"h": 51
@@ -12026,7 +11930,7 @@
},
"ui/arrow_south": {
"frame": {
"x": 3376,
"x": 3112,
"y": 1050,
"w": 102,
"h": 51
@@ -12050,7 +11954,7 @@
},
"ui/arrow_south_s": {
"frame": {
"x": 3478,
"x": 3214,
"y": 1050,
"w": 102,
"h": 51
@@ -12074,7 +11978,7 @@
},
"ui/arrow_west": {
"frame": {
"x": 3580,
"x": 3316,
"y": 1050,
"w": 102,
"h": 51
@@ -12098,7 +12002,7 @@
},
"ui/arrow_west_s": {
"frame": {
"x": 3682,
"x": 3418,
"y": 1050,
"w": 102,
"h": 51
@@ -12122,7 +12026,7 @@
},
"ui/compass": {
"frame": {
"x": 3784,
"x": 3520,
"y": 1050,
"w": 162,
"h": 147
@@ -12155,6 +12059,6 @@
"h": 1287
},
"scale": "1",
"smartupdate": "$TexturePacker:SmartUpdate:73c963294f55ee095af7f9f7c60b9d3d:93610d7ee804aa39ff18e2974a508abb:1eabdf11f75e3a4fe3147baf7b5be24b$"
"smartupdate": "$TexturePacker:SmartUpdate:cabd9bbebff623bfa01a63c764edf16e:8b226981e250398faa4378b63606c23e:1eabdf11f75e3a4fe3147baf7b5be24b$"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 581 KiB

After

Width:  |  Height:  |  Size: 573 KiB

View File

@@ -1,14 +1,10 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({__proto__: []} instanceof Array && function (d, b) {
d.__proto__ = b;
}) ||
function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
};
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
}
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
@@ -336,6 +332,12 @@ var config = {
},
world: {
defaultSize: 16
},
obstacle: {
tint: 0x0aced6,
},
constructionSite: {
tint: 0x0aced6,
}
};
var Util = (function () {
@@ -470,13 +472,13 @@ var Debug = (function () {
mar.client.sendDebugCommand({ t: "debug", command: "setEnergy", objectId: objectId, amount: amount });
};
Debug.saveGame = function () {
mar.client.sendDebugCommand({t: "debug", command: "saveGame"});
mar.client.sendDebugCommand({ t: "debug", command: "saveGame" });
};
Debug.popItem = function (objectId) {
mar.client.sendDebugCommand({t: "debug", command: "popItem", objectId: objectId});
mar.client.sendDebugCommand({ t: "debug", command: "popItem", objectId: objectId });
};
Debug.putItem = function (objectId, item) {
mar.client.sendDebugCommand({t: "debug", command: "putItem", objectId: objectId, item: item});
mar.client.sendDebugCommand({ t: "debug", command: "putItem", objectId: objectId, item: item });
};
Debug.setInventoryPosition = function (objectId, position) {
mar.client.sendDebugCommand({
@@ -582,9 +584,11 @@ var AuthListener = (function () {
console.log("[MAR] Auth successful");
}
mar.client.requestUserInfo();
} else if (message.m == "forbidden") {
}
else if (message.m == "forbidden") {
alert("Authentication failed. Guest accounts are blocked on this server");
} else {
}
else {
alert("Authentication failed. Please make sure you are logged in and reload the page.");
}
};
@@ -740,9 +744,7 @@ var GameClient = (function () {
if (DEBUG) {
console.log("[MAR] Received server info " + xhr.responseText);
}
setTimeout(function () {
return self.connectToGameServer(JSON.parse(xhr.responseText));
}, 100);
setTimeout(function () { return self.connectToGameServer(JSON.parse(xhr.responseText)); }, 100);
}
};
xhr.send(null);
@@ -830,10 +832,11 @@ var ObjectType;
ObjectType["FACTORY"] = "net.simon987.npcplugin.Factory";
ObjectType["RADIO_TOWER"] = "net.simon987.npcplugin.RadioTower";
ObjectType["VAULT_DOOR"] = "net.simon987.npcplugin.VaultDoor";
ObjectType["OBSTACLE"] = "net.simon987.npcplugin.Obstacle";
ObjectType["OBSTACLE"] = "net.simon987.constructionplugin.Obstacle";
ObjectType["ELECTRIC_BOX"] = "net.simon987.npcplugin.ElectricBox";
ObjectType["PORTAL"] = "net.simon987.npcplugin.Portal";
ObjectType["HACKED_NPC"] = "net.simon987.npcplugin.HackedNPC";
ObjectType["CONSTRUCTION_SITE"] = "net.simon987.constructionplugin.ConstructionSite";
})(ObjectType || (ObjectType = {}));
var ItemType;
(function (ItemType) {
@@ -872,13 +875,15 @@ var GameObject = (function (_super) {
case ObjectType.VAULT_DOOR:
return new VaultDoor(json);
case ObjectType.OBSTACLE:
return null;
return new Obstacle(json);
case ObjectType.ELECTRIC_BOX:
return new ElectricBox(json);
case ObjectType.PORTAL:
return new Portal(json);
case ObjectType.HACKED_NPC:
return new HackedNPC(json);
case ObjectType.CONSTRUCTION_SITE:
return new ConstructionSite(json);
default:
return null;
}
@@ -1217,7 +1222,8 @@ var HarvesterNPC = (function (_super) {
HarvesterNPC.prototype.getEnergy = function (json) {
if (json.hasOwnProperty("net.simon987.npcplugin.NpcBattery")) {
return json["net.simon987.npcplugin.NpcBattery"].energy;
} else {
}
else {
return 1000;
}
};
@@ -1287,7 +1293,7 @@ var BiomassBlob = (function (_super) {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.biomass.tintHover;
this.tint = config.biomass.tint;
this.text.visible = false;
};
BiomassBlob.prototype.updateObject = function (json) {
@@ -1446,6 +1452,79 @@ var ElectricBox = (function (_super) {
};
return ElectricBox;
}(GameObject));
var Obstacle = (function (_super) {
__extends(Obstacle, _super);
function Obstacle(json) {
var _this = _super.call(this, Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", "objects/obstacle") || this;
_this.anchor.set(0.5, 0.3);
_this.tint = config.obstacle.tint;
_this.setText("Obstacle");
_this.text.visible = false;
_this.id = json.i;
_this.tileX = json.x;
_this.tileY = json.y;
return _this;
}
Obstacle.prototype.updateObject = function (json) {
};
Obstacle.prototype.onTileHover = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({ isoZ: 25 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({ x: 1.1, y: 1.1 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubot.hoverTint;
this.text.visible = true;
};
Obstacle.prototype.onTileExit = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({ x: 1, y: 1 }, 200, Phaser.Easing.Linear.None, true);
this.tint = config.obstacle.tint;
this.text.visible = false;
};
return Obstacle;
}(GameObject));
var ConstructionSite = (function (_super) {
__extends(ConstructionSite, _super);
function ConstructionSite(json) {
var _this = _super.call(this, Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", ConstructionSite.getTargetSprite(json.blueprint.target)) || this;
_this.anchor.set(0.5, 0.31);
_this.tint = config.constructionSite.tint;
_this.setText("Construction site");
_this.text.visible = false;
_this.setUpAlphaTween();
_this.id = json.i;
_this.tileX = json.x;
_this.tileY = json.y;
return _this;
}
ConstructionSite.getTargetSprite = function (targetType) {
switch (targetType) {
case ObjectType.OBSTACLE:
return "objects/obstacle";
}
};
ConstructionSite.prototype.updateObject = function (json) {
};
ConstructionSite.prototype.setUpAlphaTween = function () {
var alphaTween = mar.game.add.tween(this).to({ alpha: 0.5 }, 2000, Phaser.Easing.Linear.None, true, 0, -1);
alphaTween.yoyo(true, 3000);
};
ConstructionSite.prototype.onTileHover = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({ isoZ: 19 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({ x: 1.03, y: 1.03 }, 200, Phaser.Easing.Linear.None, true);
this.setUpAlphaTween();
this.text.visible = true;
};
ConstructionSite.prototype.onTileExit = function () {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({ x: 1.03, y: 1.03 }, 200, Phaser.Easing.Linear.None, true);
this.setUpAlphaTween();
this.text.visible = false;
};
return ConstructionSite;
}(GameObject));
var Portal = (function (_super) {
__extends(Portal, _super);
function Portal(json) {
@@ -1643,7 +1722,7 @@ var MagneticTile = (function (_super) {
return _this;
}
MagneticTile.prototype.onHover = function () {
mar.game.add.tween(this).to({isoZ: this.baseZ + 30}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this).to({ isoZ: this.baseZ + 30 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.tileIndicator.tileX = this.tileX;
mar.tileIndicator.tileY = this.tileY;
mar.tileIndicator.tileType = this.tileType;

View File

@@ -1,5 +1,5 @@
<div class="container">
<span class="text-muted">©2020 simon987</span>
<span class="text-muted">©2019 Simon Fortier</span>
</div>
<script src="js/popper.min.js"></script>

View File

@@ -32,10 +32,10 @@
</li>
<li class="nav-item">
<a class="nav-link regular-screen" target="_blank"
href="https://join.slack.com/t/muchassemblyrequired/shared_invite/enQtMjY3Mjc1OTUwNjEwLWRjMjRkZTg2N2EyNWRjN2YyMDc0YzIyMTUyYzFiNTBmMTU3OGQ1ZjA0MWY0M2IyYjUxZTA4NjRkMWVkNDk2NzY"><i
href="https://join.slack.com/t/muchassemblyrequired/shared_invite/enQtMjY3Mjc1OTUwNjEwLTkyOTIwOTA5OGY4MDVlMGI4NzM5YzlhMWJiMGY1OWE2NjUxODQ1NWQ1YTcxMTA1NGZkYzNjYzMyM2E1ODdmNzg"><i
class="mi">chat</i> Slack</a>
<a class="nav-link small-screen" target="_blank"
href="https://join.slack.com/t/muchassemblyrequired/shared_invite/enQtMjY3Mjc1OTUwNjEwLWRjMjRkZTg2N2EyNWRjN2YyMDc0YzIyMTUyYzFiNTBmMTU3OGQ1ZjA0MWY0M2IyYjUxZTA4NjRkMWVkNDk2NzY"><i
href="https://join.slack.com/t/muchassemblyrequired/shared_invite/enQtMjY3Mjc1OTUwNjEwLTkyOTIwOTA5OGY4MDVlMGI4NzM5YzlhMWJiMGY1OWE2NjUxODQ1NWQ1YTcxMTA1NGZkYzNjYzMyM2E1ODdmNzg"><i
class="mi">chat</i></a>
</li>
<li class="nav-item">

View File

@@ -84,7 +84,7 @@ class TickListener implements MessageListener {
}
//Update console screen
if (message.console_message_buffer != undefined) {
if (message.c != undefined) {
mar.client.consoleScreen.handleConsoleBufferUpdate(
message.console_message_buffer,
message.console_mode as ConsoleMode);

View File

@@ -5,10 +5,11 @@ enum ObjectType {
FACTORY = "net.simon987.npcplugin.Factory",
RADIO_TOWER = "net.simon987.npcplugin.RadioTower",
VAULT_DOOR = "net.simon987.npcplugin.VaultDoor",
OBSTACLE = "net.simon987.npcplugin.Obstacle",
OBSTACLE = "net.simon987.constructionplugin.Obstacle",
ELECTRIC_BOX = "net.simon987.npcplugin.ElectricBox",
PORTAL = "net.simon987.npcplugin.Portal",
HACKED_NPC = "net.simon987.npcplugin.HackedNPC"
HACKED_NPC = "net.simon987.npcplugin.HackedNPC",
CONSTRUCTION_SITE = "net.simon987.constructionplugin.ConstructionSite"
}
enum ItemType {
@@ -71,13 +72,15 @@ abstract class GameObject extends Phaser.Plugin.Isometric.IsoSprite {
case ObjectType.VAULT_DOOR:
return new VaultDoor(json);
case ObjectType.OBSTACLE:
return null;
return new Obstacle(json);
case ObjectType.ELECTRIC_BOX:
return new ElectricBox(json);
case ObjectType.PORTAL:
return new Portal(json);
case ObjectType.HACKED_NPC:
return new HackedNPC(json);
case ObjectType.CONSTRUCTION_SITE:
return new ConstructionSite(json);
default:
return null;
@@ -622,7 +625,7 @@ class BiomassBlob extends GameObject {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1, y: 1}, 200, Phaser.Easing.Linear.None, true);
this.tint = config.biomass.tintHover;
this.tint = config.biomass.tint;
this.text.visible = false;
}
@@ -848,6 +851,97 @@ class ElectricBox extends GameObject {
}
}
class Obstacle extends GameObject {
constructor(json) {
super(Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", "objects/obstacle");
this.anchor.set(0.5, 0.3);
this.tint = config.obstacle.tint;
this.setText("Obstacle");
this.text.visible = false;
this.id = json.i;
this.tileX = json.x;
this.tileY = json.y;
}
updateObject(json): void {
//noop
}
public onTileHover() {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 25}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({x: 1.1, y: 1.1}, 200, Phaser.Easing.Linear.None, true);
this.tint = config.cubot.hoverTint;
this.text.visible = true;
}
public onTileExit() {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1, y: 1}, 200, Phaser.Easing.Linear.None, true);
this.tint = config.obstacle.tint;
this.text.visible = false;
}
}
class ConstructionSite extends GameObject {
private static getTargetSprite(targetType: string): string {
switch (targetType) {
case ObjectType.OBSTACLE:
return "objects/obstacle";
}
}
constructor(json) {
super(Util.getIsoX(json.x), Util.getIsoY(json.y), 15, "sheet", ConstructionSite.getTargetSprite(json.blueprint.target));
this.anchor.set(0.5, 0.31);
this.tint = config.constructionSite.tint;
this.setText("Construction site");
this.text.visible = false;
this.setUpAlphaTween();
this.id = json.i;
this.tileX = json.x;
this.tileY = json.y;
}
updateObject(json): void {
//noop
}
private setUpAlphaTween() {
let alphaTween = mar.game.add.tween(this).to({alpha: 0.5},
2000, Phaser.Easing.Linear.None, true, 0, -1);
alphaTween.yoyo(true, 3000);
}
public onTileHover() {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 19}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({x: 1.03, y: 1.03}, 200, Phaser.Easing.Linear.None, true);
this.setUpAlphaTween();
this.text.visible = true;
}
public onTileExit() {
mar.game.tweens.removeFrom(this);
mar.game.add.tween(this).to({isoZ: 15}, 400, Phaser.Easing.Bounce.Out, true);
mar.game.add.tween(this.scale).to({x: 1.03, y: 1.03}, 200, Phaser.Easing.Linear.None, true);
this.setUpAlphaTween();
this.text.visible = false;
}
}
class Portal extends GameObject {
public onTileHover() {

View File

@@ -78,6 +78,12 @@ let config = {
},
world: {
defaultSize: 16 //Will fallback to this when server does not provide world width
},
obstacle: {
tint: 0x0aced6, //todo
},
constructionSite: {
tint: 0x0aced6, //todo
}
};

View File

@@ -19,9 +19,9 @@ services:
- ./data/db:/data/db
ports:
- 27017:27017
command: mongod --logpath=/dev/null --port 27017
command: mongod --smallfiles --logpath=/dev/null --port 27017
healthcheck:
test: echo 'db.stats().ok' | mongo localhost:27017/mar --quiet
interval: 2s
timeout: 2s
retries: 2
retries: 2

33
jenkins/Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,33 @@
def remote = [:]
remote.name = 'remote'
remote.host = env.DEPLOY_HOST
remote.user = env.DEPLOY_USER
remote.identityFile = '/var/lib/jenkins/.ssh/id_rsa'
remote.knownHosts = '/var/lib/jenkins/.ssh/known_hosts'
remote.allowAnyHosts = true
remote.retryCount = 3
remote.retryWaitSec = 3
logLevel = 'FINER'
remote.port = 2299
pipeline {
agent any
stages {
stage('Build') {
steps {
sh './jenkins/build.sh'
//stash includes: 'target/', name: 'target'
}
}
stage('Deploy') {
steps {
//unstash 'target'
sshCommand remote: remote, command: 'rm -rf mar/target mar/deploy.sh'
sshPut remote: remote, from: 'target', into: 'mar'
sshPut remote: remote, from: 'jenkins/deploy.sh', into: 'mar/deploy.sh'
sshCommand remote: remote, command: 'chmod +x mar/deploy.sh && ./mar/deploy.sh'
}
}
}
}

3
jenkins/build.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
mvn package

13
jenkins/deploy.sh Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
export MARROOT="mar"
screen -S mar -X quit
echo "Starting MAR"
cp ${MARROOT}/marConfig.properties ${MARROOT}/target/config.properties
cp -r ${MARROOT}/marCerts/ ${MARROOT}/target/certificates
screen -S mar -d -m bash -c "cd ${MARROOT}/target && java -jar server-*.jar"
sleep 1
screen -list

View File

@@ -24,17 +24,25 @@ public abstract class BluePrint implements InventoryHolder, JSONSerializable, Mo
*/
protected Class<? extends GameObject> targetObject;
static final int DATA_LENGTH = 1024;
/**
* Set to true when all the requirements are met
*/
private boolean completed;
public BluePrint() {
BluePrint() {
requiredItems = new HashMap<>();
}
public BluePrint(Document document) {
requiredItems = (Map<Integer, Integer>) document.get("required_items");
Map<String, Integer> bsonCompatibleRequiredItems = (Map<String, Integer>) document.get("required_items");
requiredItems = new HashMap<>(bsonCompatibleRequiredItems.size());
for (String key : bsonCompatibleRequiredItems.keySet()) {
requiredItems.put(Integer.valueOf(key), bsonCompatibleRequiredItems.get(key));
}
completed = document.getBoolean("completed");
try {
targetObject = Class.forName(document.getString("target")).asSubclass(GameObject.class);
@@ -57,7 +65,7 @@ public abstract class BluePrint implements InventoryHolder, JSONSerializable, Mo
@Override
public boolean placeItem(Item item) {
if (requiredItems.containsKey(item.getId()) && requiredItems.get(item.getId()) > 0) {
if (canPlaceItem(item.getId())) {
requiredItems.put(item.getId(), requiredItems.get(item.getId()) - 1);
checkCompleted();
return true;
@@ -65,6 +73,11 @@ public abstract class BluePrint implements InventoryHolder, JSONSerializable, Mo
return false;
}
@Override
public boolean canPlaceItem(int itemId) {
return requiredItems.containsKey(itemId) && requiredItems.get(itemId) > 0;
}
@Override
public void takeItem(int itemId) {
@@ -92,7 +105,7 @@ public abstract class BluePrint implements InventoryHolder, JSONSerializable, Mo
public JSONObject jsonSerialise() {
JSONObject json = new JSONObject();
json.put("target", targetObject);
json.put("target", targetObject.getName());
json.put("required_items", requiredItems);
return json;
@@ -103,8 +116,15 @@ public abstract class BluePrint implements InventoryHolder, JSONSerializable, Mo
Document document = new Document();
document.put("completed", completed);
document.put("target", targetObject);
document.put("required_items", requiredItems);
document.put("target", targetObject.getName());
document.put("type", this.getClass().getName());
Map<String, Integer> bsonCompatibleRequiredItems = new HashMap<>();
for (Integer key : requiredItems.keySet()) {
bsonCompatibleRequiredItems.put(String.valueOf(key), requiredItems.get(key));
}
document.put("required_items", bsonCompatibleRequiredItems);
return document;
}

View File

@@ -9,7 +9,7 @@ import java.util.Map;
public class BluePrintRegistry {
public static final BluePrintRegistry INSTANCE = new BluePrintRegistry();
static final BluePrintRegistry INSTANCE = new BluePrintRegistry();
private Map<String, Class<? extends BluePrint>> blueprints;
private Map<String, String> digitizedBlueprints;
@@ -19,13 +19,13 @@ public class BluePrintRegistry {
digitizedBlueprints = new HashMap<>();
}
public void registerBluePrint(Class<? extends BluePrint> clazz) {
void registerBluePrint(Class<? extends BluePrint> clazz) {
blueprints.put(clazz.getCanonicalName(), clazz);
String bpData = new String(BluePrintUtil.bluePrintData(clazz));
digitizedBlueprints.put(bpData, clazz.getCanonicalName());
}
public BluePrint deserializeBlueprint(Document document) {
BluePrint deserializeBlueprint(Document document) {
String type = document.getString("type");
@@ -48,7 +48,7 @@ public class BluePrintRegistry {
}
}
public BluePrint deserializeBluePrint(char[] chars) {
BluePrint deserializeBluePrint(char[] chars) {
String bpData = new String(chars);

View File

@@ -52,7 +52,7 @@ class BluePrintUtil {
char[] result = new char[ARBITRARY_STRING.length * 32];
for (int i = ARBITRARY_STRING.length - 1; i > 0; --i) {
for (int i = ARBITRARY_STRING.length - 1; i >= 0; --i) {
char[] hashedBlueprint = hashMessage(ARBITRARY_STRING[i] + blueprint.getName());
if (hashedBlueprint != null) {
System.arraycopy(hashedBlueprint, 0, result,

View File

@@ -0,0 +1,87 @@
package net.simon987.constructionplugin;
import net.simon987.server.assembly.HardwareModule;
import net.simon987.server.assembly.Register;
import net.simon987.server.assembly.Status;
import net.simon987.server.game.objects.ControllableUnit;
import net.simon987.server.game.objects.GameObject;
import org.bson.Document;
import org.bson.types.ObjectId;
import java.awt.*;
public class ConstructionArmHardware extends HardwareModule {
public static final char HWID = 0x0010;
public static final int DEFAULT_ADDRESS = 0x0010;
private static final int OK = 0;
private static final int ERR_TILE_BLOCKED = 1;
private static final int ERR_NOT_ENOUGH_ENERGY = 2;
private static final int ERR_MEM_READ = 3;
private static final int ERR_INVALID_BLUEPRINT = 4;
private static final int PLACE_CONSTRUCTION_SITE = 1;
private static final int PLACE_CONSTRUCTION_SITE_COST = 10;
public ConstructionArmHardware(ControllableUnit unit) {
super(null, unit);
}
public ConstructionArmHardware(Document document, ControllableUnit unit) {
super(document, unit);
}
@Override
public void handleInterrupt(Status status) {
int a = getCpu().getRegisterSet().getRegister("A").getValue();
int x = getCpu().getRegisterSet().getRegister("X").getValue();
Register regB = getCpu().getRegisterSet().getRegister("B");
if (a == PLACE_CONSTRUCTION_SITE) {
char[] bluePrintData = getCpu().getMemory().read(x, BluePrint.DATA_LENGTH);
if (bluePrintData == null) {
regB.setValue(ERR_MEM_READ);
return;
}
BluePrint bluePrint = BluePrintRegistry.INSTANCE.deserializeBluePrint(bluePrintData);
if (bluePrint == null) {
regB.setValue(ERR_INVALID_BLUEPRINT);
return;
}
Point frontTile = unit.getFrontTile();
if (unit.getWorld().isTileBlocked(frontTile.x, frontTile.y) ||
unit.getWorld().canBuild(frontTile.x, frontTile.y)) {
regB.setValue(ERR_TILE_BLOCKED);
return;
}
if (!unit.spendEnergy(PLACE_CONSTRUCTION_SITE_COST)) {
regB.setValue(ERR_NOT_ENOUGH_ENERGY);
return;
}
GameObject constructionSite = new ConstructionSite(bluePrint);
constructionSite.setObjectId(new ObjectId());
constructionSite.setWorld(unit.getWorld());
constructionSite.setX(frontTile.x);
constructionSite.setY(frontTile.y);
unit.getWorld().addObject(constructionSite);
regB.setValue(OK);
}
}
@Override
public char getId() {
return HWID;
}
}

View File

@@ -1,5 +1,6 @@
package net.simon987.constructionplugin;
import net.simon987.constructionplugin.event.CpuInitialisationListener;
import net.simon987.server.GameServer;
import net.simon987.server.game.objects.GameRegistry;
import net.simon987.server.logging.LogManager;
@@ -17,8 +18,12 @@ public class ConstructionPlugin extends ServerPlugin {
gameRegistry.registerGameObject(Obstacle.class);
gameRegistry.registerGameObject(ConstructionSite.class);
gameRegistry.registerHardware(ConstructionArmHardware.class);
BluePrintRegistry.INSTANCE.registerBluePrint(ObstacleBlueprint.class);
listeners.add(new CpuInitialisationListener());
LogManager.LOGGER.info("(Construction Plugin) Initialized construction plugin");
}
}

View File

@@ -2,12 +2,14 @@ package net.simon987.constructionplugin;
import net.simon987.server.GameServer;
import net.simon987.server.game.item.Item;
import net.simon987.server.game.objects.InventoryHolder;
import net.simon987.server.game.objects.Structure;
import net.simon987.server.game.objects.Updatable;
import net.simon987.server.game.objects.*;
import net.simon987.server.game.world.World;
import org.bson.Document;
import org.bson.types.ObjectId;
import org.json.simple.JSONObject;
import java.lang.reflect.InvocationTargetException;
public class ConstructionSite extends Structure implements Updatable, InventoryHolder {
public static final int MAP_INFO = 0xFFFF; //TODO: determine
@@ -47,7 +49,36 @@ public class ConstructionSite extends Structure implements Updatable, InventoryH
@Override
public boolean placeItem(Item item) {
return bluePrint.placeItem(item);
boolean ok = bluePrint.placeItem(item);
if (ok && bluePrint.isCompleted()) {
instantiateTargetObject();
setDead(true);
}
return ok;
}
private void instantiateTargetObject() {
Class<? extends GameObject> targetClass = bluePrint.getTargetObject();
try {
GameObject targetObj = targetClass.getConstructor().newInstance();
targetObj.setWorld(getWorld());
targetObj.setObjectId(new ObjectId());
targetObj.setX(getX());
targetObj.setY(getY());
getWorld().addObject(targetObj);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
}
@Override
public boolean canPlaceItem(int itemId) {
return bluePrint.canPlaceItem(itemId);
}
@Override

View File

@@ -18,13 +18,15 @@ public class Obstacle extends Structure implements Attackable, Updatable {
public Obstacle() {
super(1, 1);
setHp(MAX_HP);
}
public Obstacle(Document document) {
super(document, 1, 1);
hp = document.getInteger(hp);
color = document.getInteger(color);
hp = document.getInteger("hp");
color = document.getInteger("color");
}
@Override

View File

@@ -0,0 +1,27 @@
package net.simon987.constructionplugin.event;
import net.simon987.constructionplugin.ConstructionArmHardware;
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;
public class CpuInitialisationListener implements GameEventListener {
@Override
public Class getListenedEventType() {
return CpuInitialisationEvent.class;
}
@Override
public void handle(GameEvent event) {
CPU cpu = (CPU) event.getSource();
ControllableUnit unit = ((CpuInitialisationEvent) event).getUnit();
ConstructionArmHardware constructionArmHardware = new ConstructionArmHardware(unit);
constructionArmHardware.setCpu(cpu);
unit.attachHardware(constructionArmHardware, ConstructionArmHardware.DEFAULT_ADDRESS);
}
}