mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-10 14:26:45 +00:00
Added javadocs
This commit is contained in:
parent
083af31b84
commit
e97ecbe380
@ -1,10 +1,5 @@
|
||||
<?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" />
|
||||
|
@ -19,42 +19,160 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
private static final char MAP_INFO = 0x0080;
|
||||
public static final int ID = 1;
|
||||
|
||||
/**
|
||||
* Hologram value that is displayed
|
||||
* <br>TODO: Move to CubotHologram class
|
||||
*/
|
||||
private int hologram = 0;
|
||||
/**
|
||||
* Hologram string that is displayed
|
||||
* <br>TODO: Move to CubotHologram class
|
||||
*/
|
||||
private String hologramString = "";
|
||||
/**
|
||||
* Hologram mode that was set during this tick
|
||||
* <br>TODO: Move to CubotHologram class
|
||||
*/
|
||||
private HologramMode hologramMode = HologramMode.CLEARED;
|
||||
/**
|
||||
* Hologram mode at the end of the last tick
|
||||
* <br>TODO: Move to CubotHologram class
|
||||
*/
|
||||
private HologramMode lastHologramMode = HologramMode.CLEARED;
|
||||
/**
|
||||
* Hologram color code. Format is handled by the client
|
||||
* <br>TODO: Move to CubotHologram class
|
||||
*/
|
||||
private int hologramColor = 0;
|
||||
|
||||
/**
|
||||
* Hit points
|
||||
*/
|
||||
private int hp;
|
||||
/**
|
||||
* Maximum hit points
|
||||
*/
|
||||
private int maxHp;
|
||||
|
||||
/**
|
||||
* Shield points
|
||||
*/
|
||||
private int shield;
|
||||
|
||||
/**
|
||||
* Maximum shield points
|
||||
*/
|
||||
private int maxShield;
|
||||
|
||||
/**
|
||||
* Item ID of the current 'active' item
|
||||
*/
|
||||
private int heldItem;
|
||||
|
||||
/**
|
||||
* Action that was set during the current tick. It is set to IDLE by default
|
||||
*/
|
||||
private Action currentAction = Action.IDLE;
|
||||
|
||||
/**
|
||||
* Action at the end of the last tick
|
||||
*/
|
||||
private Action lastAction = Action.IDLE;
|
||||
|
||||
/**
|
||||
* Status bit field that was set during the current tick. It is set to 0 by default
|
||||
* <br>See CubotStatus and addStatus() method
|
||||
*/
|
||||
private char currentStatus;
|
||||
|
||||
/**
|
||||
* Status bit field at the end of the last tick
|
||||
*/
|
||||
private char lastStatus;
|
||||
|
||||
/**
|
||||
* Buffer of keypress codes. It is not changed between ticks and it is reset when
|
||||
* the player uploads their code
|
||||
*/
|
||||
private ArrayList<Integer> keyboardBuffer = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Buffer of console messages (also called 'internal buffer') that was set during the current tick
|
||||
*/
|
||||
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
|
||||
*/
|
||||
private ArrayList<char[]> lastConsoleMessagesBuffer = new ArrayList<>(CONSOLE_BUFFER_MAX_SIZE);
|
||||
/**
|
||||
* Console mode that was set during the current tick. It is set to NORMAL by default
|
||||
*/
|
||||
private ConsoleMode consoleMode = ConsoleMode.NORMAL;
|
||||
/**
|
||||
* Console mode at the end of the last tick
|
||||
*/
|
||||
private ConsoleMode lastConsoleMode = ConsoleMode.NORMAL;
|
||||
|
||||
/**
|
||||
* User that controls this Cubot
|
||||
*/
|
||||
private User parent;
|
||||
|
||||
/**
|
||||
* Energy units in kJ
|
||||
*/
|
||||
private int energy;
|
||||
|
||||
/**
|
||||
* Maximum energy units in kJ
|
||||
*/
|
||||
private int maxEnergy;
|
||||
|
||||
/**
|
||||
* Solar panel multiplier
|
||||
* <br>TODO: Set this constant in dimension
|
||||
*/
|
||||
private static final float SOLAR_PANEL_MULTIPLIER = 1;
|
||||
/**
|
||||
* Maximum size of the console buffer (also called 'internal buffer')
|
||||
*/
|
||||
private static final int CONSOLE_BUFFER_MAX_SIZE = 40;
|
||||
|
||||
/**
|
||||
* Display mode of the hologram hardware
|
||||
* <br>TODO: move this inside CubotHologram class
|
||||
*/
|
||||
public enum HologramMode {
|
||||
/**
|
||||
* Display nothing
|
||||
*/
|
||||
CLEARED,
|
||||
/**
|
||||
* Display value as hexadecimal in format 0x0000
|
||||
*/
|
||||
HEX,
|
||||
/**
|
||||
* Display string
|
||||
*/
|
||||
STRING,
|
||||
/**
|
||||
* Display value as decimal
|
||||
*/
|
||||
DEC
|
||||
}
|
||||
|
||||
public enum ConsoleMode {
|
||||
/**
|
||||
* Used by the ComPort hardware - clears the console screen (client-side)
|
||||
*/
|
||||
CLEAR,
|
||||
/**
|
||||
* No specific client-side action
|
||||
*/
|
||||
NORMAL
|
||||
}
|
||||
|
||||
|
||||
public Cubot() {
|
||||
|
||||
}
|
||||
@ -64,6 +182,9 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
return MAP_INFO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called every tick
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
@ -176,6 +297,52 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset to 'factory settings', as it were when it was first created
|
||||
*/
|
||||
private void reset() {
|
||||
setDead(false);
|
||||
setHp(maxHp);
|
||||
setShield(0);
|
||||
setHeldItem(0);
|
||||
setEnergy(maxEnergy);
|
||||
clearKeyboardBuffer();
|
||||
consoleMessagesBuffer.clear();
|
||||
lastConsoleMessagesBuffer.clear();
|
||||
hologramColor = 0;
|
||||
currentStatus = 0;
|
||||
lastStatus = 0;
|
||||
addStatus(CubotStatus.FACTORY_NEW);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDeadCallback() {
|
||||
LogManager.LOGGER.info(getParent().getUsername() + "'s Cubot died");
|
||||
|
||||
reset();
|
||||
|
||||
//Teleport to spawn point
|
||||
this.getWorld().removeObject(this);
|
||||
this.getWorld().decUpdatable();
|
||||
|
||||
ServerConfiguration config = GameServer.INSTANCE.getConfig();
|
||||
Random random = new Random();
|
||||
|
||||
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.getGameUniverse().getWorld(spawnX, spawnY, true, dimension));
|
||||
|
||||
Point point = this.getWorld().getRandomPassableTile();
|
||||
this.setX(point.x);
|
||||
this.setY(point.y);
|
||||
|
||||
this.getWorld().addObject(this);
|
||||
this.getWorld().incUpdatable();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setHeldItem(int heldItem) {
|
||||
this.heldItem = heldItem;
|
||||
}
|
||||
@ -314,18 +481,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
this.hologramMode = hologramMode;
|
||||
}
|
||||
|
||||
public enum HologramMode {
|
||||
CLEARED,
|
||||
HEX,
|
||||
STRING,
|
||||
DEC
|
||||
}
|
||||
|
||||
public enum ConsoleMode {
|
||||
CLEAR,
|
||||
NORMAL
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAction(Action action) {
|
||||
currentAction = action;
|
||||
@ -373,6 +528,9 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
return lastStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently has no effect
|
||||
*/
|
||||
@Override
|
||||
public void setHealRate(int hp) {
|
||||
//no op
|
||||
@ -398,6 +556,13 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
this.maxHp = hp;
|
||||
}
|
||||
|
||||
public int getMaxShield() {
|
||||
return maxShield;
|
||||
}
|
||||
|
||||
public void setMaxShield(int maxShield) {
|
||||
this.maxShield = maxShield;
|
||||
}
|
||||
@Override
|
||||
public void heal(int amount) {
|
||||
hp += amount;
|
||||
@ -420,55 +585,4 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
setDead(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
setDead(false);
|
||||
setHp(maxHp);
|
||||
setShield(0);
|
||||
setHeldItem(0);
|
||||
setEnergy(maxEnergy);
|
||||
clearKeyboardBuffer();
|
||||
consoleMessagesBuffer.clear();
|
||||
lastConsoleMessagesBuffer.clear();
|
||||
hologramColor = 0;
|
||||
currentStatus = 0;
|
||||
lastStatus = 0;
|
||||
addStatus(CubotStatus.FACTORY_NEW);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDeadCallback() {
|
||||
LogManager.LOGGER.info(getParent().getUsername() + "'s Cubot died");
|
||||
|
||||
reset();
|
||||
|
||||
//Teleport to spawn point
|
||||
this.getWorld().removeObject(this);
|
||||
this.getWorld().decUpdatable();
|
||||
|
||||
ServerConfiguration config = GameServer.INSTANCE.getConfig();
|
||||
Random random = new Random();
|
||||
|
||||
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.getGameUniverse().getWorld(spawnX, spawnY, true, dimension));
|
||||
|
||||
Point point = this.getWorld().getRandomPassableTile();
|
||||
this.setX(point.x);
|
||||
this.setY(point.y);
|
||||
|
||||
this.getWorld().addObject(this);
|
||||
this.getWorld().incUpdatable();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getMaxShield() {
|
||||
return maxShield;
|
||||
}
|
||||
|
||||
public void setMaxShield(int maxShield) {
|
||||
this.maxShield = maxShield;
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.game.GameObject;
|
||||
|
||||
/**
|
||||
* Debug command to add shield points to a Cubot
|
||||
*/
|
||||
public class ChargeShieldCommandListener implements GameEventListener {
|
||||
@Override
|
||||
public Class getListenedEventType() {
|
||||
|
@ -15,7 +15,6 @@ public class CpuInitialisationListener implements GameEventListener {
|
||||
|
||||
@Override
|
||||
public void handle(GameEvent event) {
|
||||
//LogManager.LOGGER.fine("(Plugin) Handled CPU Initialisation event (Cubot Plugin)");
|
||||
|
||||
CPU cpu = (CPU) event.getSource();
|
||||
User user = ((CpuInitialisationEvent) event).getUser();
|
||||
|
@ -57,7 +57,5 @@ public class UserCreationListener implements GameEventListener {
|
||||
user.setControlledUnit(cubot);
|
||||
|
||||
LogManager.LOGGER.fine("(Plugin) Handled User creation event (Cubot Plugin)");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,5 @@
|
||||
<?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" />
|
||||
|
@ -6,6 +6,9 @@ import net.simon987.server.assembly.CpuHardware;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Util;
|
||||
|
||||
/**
|
||||
* Hardware to get game time
|
||||
*/
|
||||
public class Clock extends CpuHardware {
|
||||
|
||||
public static final char HWID = 0x0008;
|
||||
|
@ -8,6 +8,9 @@ import net.simon987.server.io.CpuHardwareDeserializer;
|
||||
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 implements CpuHardwareDeserializer {
|
||||
|
||||
|
||||
|
@ -6,6 +6,9 @@ import net.simon987.server.assembly.Status;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Hardware to generate random numbers
|
||||
*/
|
||||
public class RandomNumberGenerator extends CpuHardware {
|
||||
|
||||
public static final char HWID = 0x0007;
|
||||
|
@ -1,10 +1,5 @@
|
||||
<?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" />
|
||||
|
@ -13,24 +13,43 @@ import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Game object that deals damage to nearby objects and gives them energy
|
||||
*/
|
||||
public class ElectricBox extends GameObject implements Updatable, Attackable {
|
||||
|
||||
public static final int ID = 7;
|
||||
|
||||
/**
|
||||
* Hit points
|
||||
*/
|
||||
private int hp;
|
||||
/**
|
||||
* Maximum hit points
|
||||
*/
|
||||
private static final int maxHp = GameServer.INSTANCE.getConfig().getInt("electric_box_hp");
|
||||
/**
|
||||
* Number of hit points dealt to nearby objects each tick
|
||||
*/
|
||||
private static final int damageDealt = GameServer.INSTANCE.getConfig().getInt("electric_box_damage");
|
||||
/**
|
||||
* Number of energy points given to nearby objects each tick
|
||||
*/
|
||||
private static final int energyGiven = GameServer.INSTANCE.getConfig().getInt("electric_box_energy_given");
|
||||
|
||||
private int hp;
|
||||
|
||||
/**
|
||||
* List of nearby objects. Is updated every tick
|
||||
*/
|
||||
private ArrayList<Attackable> nearObjects = new ArrayList<>();
|
||||
|
||||
public ElectricBox() {
|
||||
|
||||
this.hp = maxHp;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently has no effect
|
||||
*/
|
||||
@Override
|
||||
public void setHealRate(int hp) {
|
||||
//no op
|
||||
@ -51,11 +70,17 @@ public class ElectricBox extends GameObject implements Updatable, Attackable {
|
||||
return hp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently has no effect
|
||||
*/
|
||||
@Override
|
||||
public void setMaxHp(int hp) {
|
||||
//No op
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently has no effect
|
||||
*/
|
||||
@Override
|
||||
public void heal(int amount) {
|
||||
//No op
|
||||
@ -77,6 +102,10 @@ public class ElectricBox extends GameObject implements Updatable, Attackable {
|
||||
return Obstacle.MAP_INFO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the current list nearby objects
|
||||
* <br>An object is considered 'nearby' if its Manhattan distance is {@literal <= @} 1 and is Attackable
|
||||
*/
|
||||
private void updateNearObjects() {
|
||||
|
||||
nearObjects.clear();
|
||||
@ -89,6 +118,9 @@ public class ElectricBox extends GameObject implements Updatable, Attackable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called every tick
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
|
@ -11,15 +11,27 @@ import org.json.simple.JSONObject;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Game objects that regularly creates NonPlayerCharacters
|
||||
*/
|
||||
public class Factory extends GameObject implements Updatable {
|
||||
|
||||
private static final int MAP_INFO = 0x0200;
|
||||
static final int ID = 3;
|
||||
|
||||
/**
|
||||
* Maximum number of NonPlayerCharacters assigned to this Factory
|
||||
*/
|
||||
private static final int MAX_NPC_COUNT = GameServer.INSTANCE.getConfig().getInt("factory_max_npc_count");
|
||||
|
||||
/**
|
||||
* Number of ticks to wait after creating a NonPlayerCharacter
|
||||
*/
|
||||
private static final int NPC_CREATION_COOLDOWN = NonPlayerCharacter.LIFETIME / MAX_NPC_COUNT;
|
||||
|
||||
/**
|
||||
* List of associated NonPlayerCharacters
|
||||
*/
|
||||
private ArrayList<NonPlayerCharacter> npcs = new ArrayList<>();
|
||||
|
||||
/**
|
||||
@ -43,6 +55,10 @@ public class Factory extends GameObject implements Updatable {
|
||||
return MAP_INFO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called every tick
|
||||
* <br>The fist time this is called, NPCs retrieved from the database are linked to the Factory
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
@ -61,6 +77,8 @@ public class Factory extends GameObject implements Updatable {
|
||||
|
||||
}
|
||||
|
||||
tmpNpcArray = null;
|
||||
|
||||
} else {
|
||||
|
||||
if (cooldown == 0) {
|
||||
@ -141,7 +159,7 @@ public class Factory extends GameObject implements Updatable {
|
||||
factory.setX((int) obj.get("x"));
|
||||
factory.setY((int) obj.get("y"));
|
||||
|
||||
factory.tmpNpcArray = ((BasicDBList) obj.get("n")).toArray();
|
||||
factory.tmpNpcArray = ((BasicDBList) obj.get("tmpNpcArray")).toArray();
|
||||
|
||||
return factory;
|
||||
}
|
||||
|
@ -10,19 +10,31 @@ import net.simon987.server.logging.LogManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Find Biomass, move towards it, collect it, repeat
|
||||
*/
|
||||
public class HarvestTask extends NPCTask {
|
||||
|
||||
private Random random;
|
||||
|
||||
/**
|
||||
* Number of ticks to wait before continuing
|
||||
*/
|
||||
private int pause;
|
||||
|
||||
/**
|
||||
* Direction of the next world to visit (randomly chosen)
|
||||
*/
|
||||
private Direction nextWorldDirection = null;
|
||||
|
||||
public HarvestTask() {
|
||||
random = new Random();
|
||||
pause = 0;
|
||||
}
|
||||
|
||||
private Direction nextWorldDirection = null;
|
||||
|
||||
/**
|
||||
* This task never finishes
|
||||
*/
|
||||
@Override
|
||||
public boolean checkCompleted() {
|
||||
return false;
|
||||
|
@ -12,6 +12,9 @@ public class HarvesterNPC extends NonPlayerCharacter {
|
||||
|
||||
public static final int ID = 10;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final int MAX_HEALTH = GameServer.INSTANCE.getConfig().getInt("harvester_hp_max");
|
||||
public static final int HEAL_RATE = GameServer.INSTANCE.getConfig().getInt("harvester_regen");
|
||||
|
||||
@ -85,7 +88,6 @@ public class HarvesterNPC extends NonPlayerCharacter {
|
||||
dbObject.put("y", getY());
|
||||
dbObject.put("direction", getDirection().ordinal());
|
||||
dbObject.put("hp", getHp());
|
||||
// dbObject.put("energy", energy);
|
||||
dbObject.put("action", getAction().ordinal());
|
||||
dbObject.put("t", ID);
|
||||
|
||||
@ -100,8 +102,6 @@ public class HarvesterNPC extends NonPlayerCharacter {
|
||||
npc.setY((int) obj.get("y"));
|
||||
npc.setHp((int) obj.get("hp"));
|
||||
npc.setDirection(Direction.getDirection((int) obj.get("direction")));
|
||||
// npc.energy = (int) obj.get("energy");
|
||||
// npc.maxEnergy = GameServer.INSTANCE.getConfig().getInt("battery_max_energy");
|
||||
|
||||
return npc;
|
||||
|
||||
|
@ -9,27 +9,40 @@ import net.simon987.server.logging.LogManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Game object that actively interacts with the game world by doing tasks
|
||||
*/
|
||||
public abstract class NonPlayerCharacter extends GameObject implements Updatable, Attackable {
|
||||
|
||||
private static final int MAP_INFO = 0x0040;
|
||||
|
||||
/**
|
||||
* Maximum distance to travel from its factory, in Worlds
|
||||
*/
|
||||
private static final int MAX_FACTORY_DISTANCE = GameServer.INSTANCE.getConfig().getInt("npc_max_factory_distance");
|
||||
|
||||
/**
|
||||
* Number of ticks to live
|
||||
*/
|
||||
public static final int LIFETIME = GameServer.INSTANCE.getConfig().getInt("npc_lifetime");
|
||||
|
||||
// Set these just in case they aren't overridden in the subclass
|
||||
public static final int HP_MAX_DEFAULT = 100;
|
||||
public static final int HP_REGEN_RATE_DEFAULT = 0;
|
||||
|
||||
//Unused
|
||||
/**
|
||||
* Currently unused
|
||||
*/
|
||||
int energy;
|
||||
int maxEnergy;
|
||||
|
||||
/**
|
||||
* Current task
|
||||
*/
|
||||
private NPCTask task;
|
||||
|
||||
/**
|
||||
* Action at the end of the last tick
|
||||
*/
|
||||
private Action lastAction = Action.IDLE;
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,6 @@ import com.mongodb.DBObject;
|
||||
import net.simon987.npcplugin.event.CpuInitialisationListener;
|
||||
import net.simon987.npcplugin.event.VaultWorldUpdateListener;
|
||||
import net.simon987.npcplugin.event.WorldCreationListener;
|
||||
import net.simon987.npcplugin.io.StatsDatabaseManager;
|
||||
import net.simon987.server.ServerConfiguration;
|
||||
import net.simon987.server.assembly.CpuHardware;
|
||||
import net.simon987.server.game.GameObject;
|
||||
@ -22,8 +21,6 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C
|
||||
*/
|
||||
private static ArrayList<RadioTower> radioTowers;
|
||||
|
||||
private static StatsDatabaseManager statsDbManager;
|
||||
|
||||
@Override
|
||||
public void init(ServerConfiguration configuration) {
|
||||
|
||||
@ -33,8 +30,6 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C
|
||||
|
||||
radioTowers = new ArrayList<>(32);
|
||||
|
||||
statsDbManager = new StatsDatabaseManager(configuration);
|
||||
|
||||
LogManager.LOGGER.info("Initialised NPC plugin");
|
||||
}
|
||||
|
||||
@ -80,7 +75,4 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C
|
||||
return radioTowers;
|
||||
}
|
||||
|
||||
public static StatsDatabaseManager getStatsDbManager() {
|
||||
return statsDbManager;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import org.json.simple.JSONObject;
|
||||
|
||||
/**
|
||||
* Generic game object that blocks the path.
|
||||
* Some types of obstacles might have some more interesting features (see ElectricBox)
|
||||
*/
|
||||
public class Obstacle extends GameObject implements Attackable {
|
||||
|
||||
|
@ -8,16 +8,25 @@ import org.json.simple.JSONObject;
|
||||
|
||||
public class Portal extends GameObject implements Enterable {
|
||||
|
||||
private Location dst;
|
||||
/**
|
||||
* Destination location
|
||||
*/
|
||||
private Location destination;
|
||||
|
||||
public static final int MAP_INFO = 0x0020;
|
||||
|
||||
public static final int ID = 8;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
World world = GameServer.INSTANCE.getGameUniverse().getWorld(dst.worldX, dst.worldY, false, dst.dimension);
|
||||
World world = GameServer.INSTANCE.getGameUniverse().getWorld(destination.worldX, destination.worldY, false, destination.dimension);
|
||||
|
||||
if (object instanceof Updatable) {
|
||||
object.getWorld().decUpdatable();
|
||||
@ -27,8 +36,8 @@ public class Portal extends GameObject implements Enterable {
|
||||
object.setWorld(world);
|
||||
world.addObject(object);
|
||||
|
||||
object.setX(dst.x);
|
||||
object.setY(dst.y);
|
||||
object.setX(destination.x);
|
||||
object.setY(destination.y);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -46,11 +55,11 @@ public class Portal extends GameObject implements Enterable {
|
||||
dbObject.put("x", getX());
|
||||
dbObject.put("y", getY());
|
||||
dbObject.put("t", ID);
|
||||
dbObject.put("dstWorldX", dst.worldX);
|
||||
dbObject.put("dstWorldY", dst.worldY);
|
||||
dbObject.put("dstX", dst.x);
|
||||
dbObject.put("dstY", dst.y);
|
||||
dbObject.put("dstDimension", dst.dimension);
|
||||
dbObject.put("dstWorldX", destination.worldX);
|
||||
dbObject.put("dstWorldY", destination.worldY);
|
||||
dbObject.put("dstX", destination.x);
|
||||
dbObject.put("dstY", destination.y);
|
||||
dbObject.put("dstDimension", destination.dimension);
|
||||
|
||||
return dbObject;
|
||||
}
|
||||
@ -59,7 +68,7 @@ public class Portal extends GameObject implements Enterable {
|
||||
|
||||
Portal portal = new Portal();
|
||||
|
||||
portal.dst = new Location(
|
||||
portal.destination = new Location(
|
||||
(int) obj.get("dstWorldX"),
|
||||
(int) obj.get("dstWorldY"),
|
||||
(String) obj.get("dstDimension"),
|
||||
@ -83,11 +92,11 @@ public class Portal extends GameObject implements Enterable {
|
||||
return json;
|
||||
}
|
||||
|
||||
public Location getDst() {
|
||||
return dst;
|
||||
public Location getDestination() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
public void setDst(Location dst) {
|
||||
this.dst = dst;
|
||||
public void setDestination(Location destination) {
|
||||
this.destination = destination;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ public class RadioTower extends GameObject implements Programmable, Updatable {
|
||||
return MAP_INFO;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Messages from the current tick
|
||||
*/
|
||||
|
@ -141,7 +141,7 @@ public class VaultDimension {
|
||||
if (exitPortalPt != null) {
|
||||
|
||||
VaultExitPortal exitPortal = new VaultExitPortal();
|
||||
exitPortal.setDst(exitLocation);
|
||||
exitPortal.setDestination(exitLocation);
|
||||
exitPortal.setX(exitPortalPt.x);
|
||||
exitPortal.setY(exitPortalPt.y);
|
||||
exitPortal.setWorld(objectiveWorld);
|
||||
@ -158,7 +158,7 @@ public class VaultDimension {
|
||||
if (homePortalPt != null) {
|
||||
|
||||
Portal homePortal = new Portal();
|
||||
homePortal.setDst(exitLocation);
|
||||
homePortal.setDestination(exitLocation);
|
||||
homePortal.setX(homePortalPt.x);
|
||||
homePortal.setY(homePortalPt.y);
|
||||
homePortal.setWorld(homeWorld);
|
||||
|
@ -22,11 +22,11 @@ public class VaultExitPortal extends Portal {
|
||||
dbObject.put("x", getX());
|
||||
dbObject.put("y", getY());
|
||||
dbObject.put("t", ID);
|
||||
dbObject.put("dstWorldX", getDst().worldX);
|
||||
dbObject.put("dstWorldY", getDst().worldY);
|
||||
dbObject.put("dstX", getDst().x);
|
||||
dbObject.put("dstY", getDst().y);
|
||||
dbObject.put("dstDimension", getDst().dimension);
|
||||
dbObject.put("dstWorldX", getDestination().worldX);
|
||||
dbObject.put("dstWorldY", getDestination().worldY);
|
||||
dbObject.put("dstX", getDestination().x);
|
||||
dbObject.put("dstY", getDestination().y);
|
||||
dbObject.put("dstDimension", getDestination().dimension);
|
||||
|
||||
return dbObject;
|
||||
}
|
||||
@ -37,8 +37,7 @@ public class VaultExitPortal extends Portal {
|
||||
LogManager.LOGGER.info(((ControllableUnit) object).getParent().getUsername() + " Completed vault " +
|
||||
object.getWorld().getDimension());
|
||||
|
||||
NpcPlugin.getStatsDbManager().saveVaultCompletion((ControllableUnit) object, object.getWorld().getDimension());
|
||||
|
||||
//todo: save vault completion stat
|
||||
|
||||
return super.enter(object);
|
||||
}
|
||||
@ -47,7 +46,7 @@ public class VaultExitPortal extends Portal {
|
||||
|
||||
VaultExitPortal portal = new VaultExitPortal();
|
||||
|
||||
portal.setDst(new Location(
|
||||
portal.setDestination(new Location(
|
||||
(int) obj.get("dstWorldX"),
|
||||
(int) obj.get("dstWorldY"),
|
||||
(String) obj.get("dstDimension"),
|
||||
|
@ -14,11 +14,26 @@ import java.util.HashMap;
|
||||
|
||||
public class VaultWorldUpdateListener implements GameEventListener {
|
||||
|
||||
/**
|
||||
* Map of worlds and their time to wait until next respawn event
|
||||
*/
|
||||
private HashMap<World, Long> worldWaitMap = new HashMap<>(200);
|
||||
|
||||
/**
|
||||
* Lower bound of ElectricBox to be created on a respawn event
|
||||
*/
|
||||
private static int minElectricBoxCount;
|
||||
/**
|
||||
* Upper bound of ElectricBox to be created on a respawn event
|
||||
*/
|
||||
private static int maxElectricBoxCount;
|
||||
/**
|
||||
* Number of game ticks to wait after the threshold has been met
|
||||
*/
|
||||
private static int waitTime;
|
||||
/**
|
||||
* Threshold before starting the
|
||||
*/
|
||||
private static int electricBoxThreshold;
|
||||
|
||||
public VaultWorldUpdateListener(ServerConfiguration config) {
|
||||
@ -37,6 +52,7 @@ public class VaultWorldUpdateListener implements GameEventListener {
|
||||
@Override
|
||||
public void handle(GameEvent event) {
|
||||
|
||||
//TODO: Move this and the Biomass UpdateListener to a 'RespawnManager' kind of deal
|
||||
World world = ((WorldUpdateEvent) event).getWorld();
|
||||
|
||||
if (world.getDimension().startsWith("v")) {
|
||||
@ -66,6 +82,5 @@ public class VaultWorldUpdateListener implements GameEventListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public class WorldCreationListener implements GameEventListener {
|
||||
|
||||
/**
|
||||
* Spawn rate. Higher = rarer: A factory will be spawn about every FACTORY_SPAWN_RATE generated Worlds
|
||||
* <br>TODO: Get from config.properties
|
||||
*/
|
||||
private static final int FACTORY_SPAWN_RATE = 35;
|
||||
|
||||
|
@ -1,18 +0,0 @@
|
||||
package net.simon987.npcplugin.io;
|
||||
|
||||
import net.simon987.server.ServerConfiguration;
|
||||
import net.simon987.server.game.ControllableUnit;
|
||||
import net.simon987.server.io.DatabaseManager;
|
||||
|
||||
public class StatsDatabaseManager extends DatabaseManager {
|
||||
|
||||
public StatsDatabaseManager(ServerConfiguration config) {
|
||||
super(config);
|
||||
}
|
||||
|
||||
public void saveVaultCompletion(ControllableUnit unit, String dimension) {
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,10 +1,5 @@
|
||||
<?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" />
|
||||
|
@ -1,10 +1,5 @@
|
||||
<?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" />
|
||||
|
@ -21,5 +21,4 @@ public class Main {
|
||||
|
||||
(new Thread(GameServer.INSTANCE)).start();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class Assembler {
|
||||
/**
|
||||
* Check for and save the origin
|
||||
*
|
||||
* @param line Current line. Assuming that the comments & labels are removed
|
||||
* @param line Current line. Assuming that the comments and labels are removed
|
||||
* @param result Current line number
|
||||
*/
|
||||
private static void checkForORGInstruction(String line, AssemblyResult result, int currentLine)
|
||||
@ -121,7 +121,7 @@ public class Assembler {
|
||||
/**
|
||||
* Parse the DW instruction (Define word). Handles DUP operator
|
||||
*
|
||||
* @param line Current line. assuming that comments & labels are removed
|
||||
* @param line Current line. assuming that comments and labels are removed
|
||||
* @param currentLine Current line number
|
||||
* @param labels Map of labels
|
||||
* @return Encoded instruction, null if the line is not a DW instruction
|
||||
@ -258,7 +258,7 @@ public class Assembler {
|
||||
/**
|
||||
* Parse the DW instruction (Define word). Handles DUP operator
|
||||
*
|
||||
* @param line Current line. assuming that comments & labels are removed
|
||||
* @param line Current line. assuming that comments and labels are removed
|
||||
* @param currentLine Current line number
|
||||
* @return Encoded instruction, null if the line is not a DW instruction
|
||||
*/
|
||||
@ -267,7 +267,7 @@ public class Assembler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for and handle section declarations (.text & .data)
|
||||
* Check for and handle section declarations (.text and .data)
|
||||
*
|
||||
* @param line Current line
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* CPU: Central Processing Unit. A CPU is capable of reading bytes from
|
||||
* a Memory object and execute them. A CPU object holds registers objects &
|
||||
* a Memory object and execute them. A CPU object holds registers objects and
|
||||
* a Memory object.
|
||||
*/
|
||||
public class CPU implements MongoSerialisable {
|
||||
|
@ -7,10 +7,11 @@ import net.simon987.server.assembly.Util;
|
||||
|
||||
/**
|
||||
* AND two numbers together, the result is stored in the destination operand
|
||||
* <p>
|
||||
* <br>
|
||||
* AND A, B
|
||||
* A = A & B
|
||||
* </p>
|
||||
* <br>
|
||||
* {@literal A = A & B @}
|
||||
* <br>
|
||||
* FLAGS: OF=0 S=* Z=* X=0
|
||||
*/
|
||||
public class AndInstruction extends Instruction {
|
||||
|
@ -6,9 +6,9 @@ import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
|
||||
/**
|
||||
* Send hardware interupt
|
||||
* Used to interact with the World using hardware
|
||||
* </p>
|
||||
* Send hardware interrupt
|
||||
* <br>Used to interact with the World using hardware
|
||||
*
|
||||
*/
|
||||
public class HwiInstruction extends Instruction {
|
||||
|
||||
|
@ -6,9 +6,9 @@ import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
|
||||
/**
|
||||
* +---------------------+
|
||||
* | |
|
||||
* CF < 0<0<0<0<0<0<0<0 <-+
|
||||
*<br> +---------------------+
|
||||
*<br> | |
|
||||
*<br> {@literal CF < 0<0<0<0<0<0<0<0 <-+ @}
|
||||
*/
|
||||
public class RclInstruction extends Instruction {
|
||||
|
||||
|
@ -5,9 +5,9 @@ import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
|
||||
/**
|
||||
* +---------------------+
|
||||
* | |
|
||||
* CF < 0<0<0<0<0<0<0<0 <-+
|
||||
* <br> +---------------------+
|
||||
* <br> | |
|
||||
* <br> {@literal CF < 0<0<0<0<0<0<0<0 <-+ @}
|
||||
*/
|
||||
public class RcrInstruction extends Instruction {
|
||||
|
||||
|
@ -5,9 +5,9 @@ import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
|
||||
/**
|
||||
* +-----------------+
|
||||
* | |
|
||||
* CF < 0<0<0<0<0<0<0<0 <-+
|
||||
* <br> +-----------------+
|
||||
* <br> | |
|
||||
* <br> {@literal CF < 0<0<0<0<0<0<0<0 <-+ @}
|
||||
*/
|
||||
public class RolInstruction extends Instruction {
|
||||
|
||||
|
@ -5,9 +5,9 @@ import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
|
||||
/**
|
||||
* +-----------------+
|
||||
* | |
|
||||
* +-> 0>0>0>0>0>0>0>0 > CF
|
||||
* <br> +-----------------+
|
||||
* <br> | |
|
||||
* <br> {@literal +-> 0>0>0>0>0>0>0>0 > CF @}
|
||||
*/
|
||||
public class RorInstruction extends Instruction {
|
||||
|
||||
|
@ -6,7 +6,7 @@ public interface Enterable {
|
||||
* Called when an object attempts to walk directly into a Enterable object
|
||||
*
|
||||
* @param object The game object that attempted to enter
|
||||
* @return true if successful,
|
||||
* @return true if successful, false to block the object
|
||||
*/
|
||||
boolean enter(GameObject object);
|
||||
|
||||
|
@ -37,6 +37,7 @@ public class WebServer {
|
||||
LogManager.LOGGER.info("(Web) Enabled ssl");
|
||||
}
|
||||
|
||||
|
||||
socketServer = new SocketServer();
|
||||
Spark.webSocket("/socket", socketServer);
|
||||
|
||||
|
@ -114,6 +114,7 @@
|
||||
|
||||
.bottom-panel {
|
||||
min-height: 18px;
|
||||
max-height: 100%;
|
||||
height: 235px;
|
||||
width: 100%;
|
||||
position: fixed;
|
||||
|
@ -329,7 +329,7 @@ class GameClient {
|
||||
}
|
||||
}
|
||||
|
||||
à
|
||||
|
||||
public requestObjects(): void {
|
||||
if (DEBUG) {
|
||||
console.log("[MAR] Requesting game objects");
|
||||
|
Loading…
x
Reference in New Issue
Block a user