mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-12-14 23:29:09 +00:00
Compare commits
27 Commits
constructi
...
401190e1d8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
401190e1d8 | ||
| ac374f5b52 | |||
|
|
d01eac646f | ||
| 35b48ddd95 | |||
|
|
5a0c5b6911 | ||
| a85e672eb9 | |||
| 053d3e35ec | |||
|
|
35140cc834 | ||
| 6a9c656e66 | |||
|
|
d07a59607f | ||
|
|
3b12e2aeca | ||
|
|
0c3a3f06f0 | ||
|
|
2aeca6c9ce | ||
|
|
3c16bd3f30 | ||
|
|
a3c4c33300 | ||
|
|
72ea92ffb3 | ||
|
|
f526f369c4 | ||
|
|
e97770f860 | ||
| cd9e555e86 | |||
|
|
7c0187f514 | ||
| ac27250f98 | |||
|
|
84f59a5fa2 | ||
| a0193621a8 | |||
| 922162660f | |||
| 014dab49da | |||
|
|
4c81937edc | ||
| 2597b558e6 |
@@ -0,0 +1,176 @@
|
|||||||
|
package net.simon987.pluginradioactivecloud;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
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.Radioactive;
|
||||||
|
|
||||||
|
public class RadiationDetector extends HardwareModule {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be unique and same as HWID
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_ADDRESS = 0x000E;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hardware ID (Should be unique)
|
||||||
|
*/
|
||||||
|
public static final char HWID = 0x000E;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Radiation Constants
|
||||||
|
*/
|
||||||
|
private static final int ALPHA_BLOCKED_VALUE = 5;
|
||||||
|
private static final int BETA_BLOCKED_VALUE = 2;
|
||||||
|
private static final int GAMMA_BLOCKED_VALUE = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class for getTiles
|
||||||
|
*/
|
||||||
|
private class Tuple {
|
||||||
|
public final int x;
|
||||||
|
public final int y;
|
||||||
|
|
||||||
|
public Tuple(int x, int y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the tiles between the two tiles located at the given coordinates. The
|
||||||
|
* tiles located at the coordinates are not included in the list.
|
||||||
|
*
|
||||||
|
* @param x0 x-coordinate of first point
|
||||||
|
* @param y0 y-coordinate of first point
|
||||||
|
* @param x1 x-coordinate of second point
|
||||||
|
* @param y1 y-coordinate of second point
|
||||||
|
* @return List of tile coordinates. An empty list indicates tiles are next to
|
||||||
|
* each other.
|
||||||
|
*/
|
||||||
|
public ArrayList<Tuple> getTiles(int x0, int y0, int x1, int y1) {
|
||||||
|
|
||||||
|
ArrayList<Tuple> ret = new ArrayList<>();
|
||||||
|
double slope;
|
||||||
|
if (x1 > x0) {
|
||||||
|
slope = (y1 - y0) / (double) (x1 - x0);
|
||||||
|
} else {
|
||||||
|
slope = (y0 - y1) / (double) (x0 - x1);
|
||||||
|
|
||||||
|
// Swap values so that x0 < x1. This preps the following code where y is
|
||||||
|
// determined by adding a step value (1) to x0 till it reaches x1.
|
||||||
|
int tmp = x1;
|
||||||
|
x1 = x0;
|
||||||
|
x0 = tmp;
|
||||||
|
|
||||||
|
tmp = y1;
|
||||||
|
y1 = y0;
|
||||||
|
y0 = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If slope is zero or undefined, return tiles directly along the
|
||||||
|
// appropriate cardinal direction.
|
||||||
|
if (x0 == x1) {
|
||||||
|
int smaller = Math.min(y0, y1);
|
||||||
|
int larger = Math.max(y0, y1);
|
||||||
|
System.out.printf("%d %d", smaller, larger);
|
||||||
|
for (int i = smaller + 1; i < larger; i++) {
|
||||||
|
ret.add(new Tuple(x0, i));
|
||||||
|
}
|
||||||
|
} else if (y0 == y1) {
|
||||||
|
int smaller = Math.min(x0, x1);
|
||||||
|
int larger = Math.max(x0, x1);
|
||||||
|
for (int i = smaller + 1; i < larger; i++) {
|
||||||
|
ret.add(new Tuple(i, y0));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Find all coordinates with 0.1 step
|
||||||
|
int lastX = x0;
|
||||||
|
int lastY = y0;
|
||||||
|
for (int i = x0 * 10; i < x1 * 10; i += 1) {
|
||||||
|
if (i / 10 != lastX || (int) (slope * i / 10) != lastY) {
|
||||||
|
// Update last values
|
||||||
|
lastX = i / 10;
|
||||||
|
lastY = (int) (slope * i / 10);
|
||||||
|
|
||||||
|
// Add new values to array
|
||||||
|
ret.add(new Tuple(lastX, lastY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the Euclidean Distance between two coordinates.
|
||||||
|
*
|
||||||
|
* @param x0 x-coordinate of first point
|
||||||
|
* @param y0 y-coordinate of first point
|
||||||
|
* @param x1 x-coordinate of second point
|
||||||
|
* @param y1 y-coordinate of second point
|
||||||
|
* @return distance between two points
|
||||||
|
*/
|
||||||
|
public double getDistanceOfCoords(int x0, int y0, int x1, int y1) {
|
||||||
|
return Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public RadiationDetector(ControllableUnit unit) {
|
||||||
|
super(null, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RadiationDetector(Document document, ControllableUnit cubot) {
|
||||||
|
super(document, cubot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleInterrupt(Status status) {
|
||||||
|
|
||||||
|
// Find all game entities in world
|
||||||
|
ArrayList<GameObject> entities = new ArrayList<>(unit.getWorld().getGameObjects());
|
||||||
|
|
||||||
|
// Check for alpha particles by finding Radioactive entities
|
||||||
|
int alphaParticles = 0;
|
||||||
|
int betaParticles = 0;
|
||||||
|
int gammaParticles = 0;
|
||||||
|
for (GameObject entity : entities) {
|
||||||
|
if (entity instanceof Radioactive) {
|
||||||
|
// Calculate distance between object and cubot
|
||||||
|
double pathLength = getDistanceOfCoords(unit.getX(), unit.getY(), entity.getX(), entity.getY());
|
||||||
|
alphaParticles += ((Radioactive) entity).getAlphaCounts(pathLength);
|
||||||
|
betaParticles += ((Radioactive) entity).getBetaCounts(pathLength);
|
||||||
|
gammaParticles += ((Radioactive) entity).getGammaCounts(pathLength);
|
||||||
|
|
||||||
|
// Get all tiles in between cubot and Radioactive entity
|
||||||
|
ArrayList<Tuple> tiles = getTiles(unit.getX(), unit.getY(), entity.getX(), entity.getY());
|
||||||
|
for (Tuple tup : tiles) {
|
||||||
|
// If intermediary tile is blocked, reduce alphaParticles by 5
|
||||||
|
if (unit.getWorld().isTileBlocked(tup.x, tup.y)) {
|
||||||
|
alphaParticles -= ALPHA_BLOCKED_VALUE;
|
||||||
|
betaParticles -= BETA_BLOCKED_VALUE;
|
||||||
|
gammaParticles -= GAMMA_BLOCKED_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save Alpha Radioactive Particles to register A
|
||||||
|
getCpu().getRegisterSet().getRegister("A").setValue(alphaParticles);
|
||||||
|
|
||||||
|
// Save Beta Radioactive Particles to register B
|
||||||
|
getCpu().getRegisterSet().getRegister("B").setValue(betaParticles);
|
||||||
|
|
||||||
|
// Save Gamma Radioactive Particles to register C
|
||||||
|
getCpu().getRegisterSet().getRegister("C").setValue(gammaParticles);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public char getId() {
|
||||||
|
return HWID;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,32 @@
|
|||||||
package net.simon987.pluginradioactivecloud;
|
package net.simon987.pluginradioactivecloud;
|
||||||
|
|
||||||
public class RadioactiveCloud {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
README.md
16
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://www.codefactor.io/repository/github/simon987/much-assembly-required)
|
||||||
[](https://ci.simon987.net/job/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.
|
**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.
|
||||||
In its current state, players can walk around the game universe and collect Biomass blobs & Iron/copper ore using the online code editor.
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -24,13 +23,14 @@ sudo apt install git maven openjdk-8-jdk mongodb
|
|||||||
|
|
||||||
On Arch:
|
On Arch:
|
||||||
``` bash
|
``` bash
|
||||||
sudo pacman -S git maven mongodb jdk8-opendjk
|
sudo pacman -S git maven jdk8-opendjk
|
||||||
|
yay -S mongodb-bin
|
||||||
|
|
||||||
# Don't forget to start mongodb
|
# Don't forget to start mongodb
|
||||||
sudo systemctl start mongodb.service
|
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**
|
**Deploying server**
|
||||||
|
|
||||||
@@ -51,12 +51,12 @@ java -jar server-1.4a.jar
|
|||||||
|
|
||||||
Installation instructions:
|
Installation instructions:
|
||||||
1. Download the JDK from [here](http://www.oracle.com/technetwork/java/javase/downloads/index.html).
|
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/).
|
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).
|
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/).
|
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:
|
Building instructions:
|
||||||
```batch
|
```batch
|
||||||
|
|||||||
@@ -92,7 +92,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.12</version>
|
<version>4.13.1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -114,7 +114,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.security</groupId>
|
<groupId>org.springframework.security</groupId>
|
||||||
<artifactId>spring-security-core</artifactId>
|
<artifactId>spring-security-core</artifactId>
|
||||||
<version>5.1.5.RELEASE</version>
|
<version>5.1.11.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sparkjava</groupId>
|
<groupId>com.sparkjava</groupId>
|
||||||
|
|||||||
@@ -6,5 +6,15 @@ package net.simon987.server.game.objects;
|
|||||||
|
|
||||||
public interface Radioactive {
|
public interface Radioactive {
|
||||||
|
|
||||||
|
public default int getAlphaCounts(double distance) {
|
||||||
|
return (int) (1000 * 1.0 / (distance * distance));
|
||||||
|
}
|
||||||
|
|
||||||
|
public default int getBetaCounts(double distance) {
|
||||||
|
return (int) (2000 * 1.0 / (distance * distance));
|
||||||
|
}
|
||||||
|
|
||||||
|
public default int getGammaCounts(double distance) {
|
||||||
|
return (int) (5000 * 1.0 / (distance * distance));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ electric_box_damage=5
|
|||||||
electric_box_energy_given=70
|
electric_box_energy_given=70
|
||||||
#RadioactiveObstacle
|
#RadioactiveObstacle
|
||||||
radioactive_obstacle_corruption_block_size=10
|
radioactive_obstacle_corruption_block_size=10
|
||||||
|
radioactive_cloud_corruption_block_size=40
|
||||||
|
|
||||||
#SecretKey
|
#SecretKey
|
||||||
secret_key=<your_secret_key>
|
secret_key=<your_secret_key>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<span class="text-muted">©2019 Simon Fortier</span>
|
<span class="text-muted">©2020 simon987</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="js/popper.min.js"></script>
|
<script src="js/popper.min.js"></script>
|
||||||
|
|||||||
@@ -32,10 +32,10 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link regular-screen" target="_blank"
|
<a class="nav-link regular-screen" target="_blank"
|
||||||
href="https://join.slack.com/t/muchassemblyrequired/shared_invite/enQtMjY3Mjc1OTUwNjEwLTkyOTIwOTA5OGY4MDVlMGI4NzM5YzlhMWJiMGY1OWE2NjUxODQ1NWQ1YTcxMTA1NGZkYzNjYzMyM2E1ODdmNzg"><i
|
href="https://join.slack.com/t/muchassemblyrequired/shared_invite/enQtMjY3Mjc1OTUwNjEwLWRjMjRkZTg2N2EyNWRjN2YyMDc0YzIyMTUyYzFiNTBmMTU3OGQ1ZjA0MWY0M2IyYjUxZTA4NjRkMWVkNDk2NzY"><i
|
||||||
class="mi">chat</i> Slack</a>
|
class="mi">chat</i> Slack</a>
|
||||||
<a class="nav-link small-screen" target="_blank"
|
<a class="nav-link small-screen" target="_blank"
|
||||||
href="https://join.slack.com/t/muchassemblyrequired/shared_invite/enQtMjY3Mjc1OTUwNjEwLTkyOTIwOTA5OGY4MDVlMGI4NzM5YzlhMWJiMGY1OWE2NjUxODQ1NWQ1YTcxMTA1NGZkYzNjYzMyM2E1ODdmNzg"><i
|
href="https://join.slack.com/t/muchassemblyrequired/shared_invite/enQtMjY3Mjc1OTUwNjEwLWRjMjRkZTg2N2EyNWRjN2YyMDc0YzIyMTUyYzFiNTBmMTU3OGQ1ZjA0MWY0M2IyYjUxZTA4NjRkMWVkNDk2NzY"><i
|
||||||
class="mi">chat</i></a>
|
class="mi">chat</i></a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class TickListener implements MessageListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Update console screen
|
//Update console screen
|
||||||
if (message.c != undefined) {
|
if (message.console_message_buffer != undefined) {
|
||||||
mar.client.consoleScreen.handleConsoleBufferUpdate(
|
mar.client.consoleScreen.handleConsoleBufferUpdate(
|
||||||
message.console_message_buffer,
|
message.console_message_buffer,
|
||||||
message.console_mode as ConsoleMode);
|
message.console_mode as ConsoleMode);
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ services:
|
|||||||
- ./data/db:/data/db
|
- ./data/db:/data/db
|
||||||
ports:
|
ports:
|
||||||
- 27017:27017
|
- 27017:27017
|
||||||
command: mongod --smallfiles --logpath=/dev/null --port 27017
|
command: mongod --logpath=/dev/null --port 27017
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: echo 'db.stats().ok' | mongo localhost:27017/mar --quiet
|
test: echo 'db.stats().ok' | mongo localhost:27017/mar --quiet
|
||||||
interval: 2s
|
interval: 2s
|
||||||
timeout: 2s
|
timeout: 2s
|
||||||
retries: 2
|
retries: 2
|
||||||
|
|||||||
33
jenkins/Jenkinsfile
vendored
33
jenkins/Jenkinsfile
vendored
@@ -1,33 +0,0 @@
|
|||||||
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'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
mvn package
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#!/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
|
|
||||||
Reference in New Issue
Block a user