Various bug fixes

This commit is contained in:
simon 2017-11-05 14:13:53 -05:00
parent 626c55bcce
commit 98b0c480b9
19 changed files with 145 additions and 68 deletions

View File

@ -70,7 +70,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
json.put("heldItem", heldItem);
json.put("hp", hp);
json.put("action", lastAction.ordinal());
if(parent != null){
if (parent != null) {
json.put("parent", parent.getUsername()); //Only used client-side for now
}
@ -86,7 +86,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
cubot.hp = (int)(long)json.get("hp");
cubot.setDirection(Direction.getDirection((int)(long)json.get("direction")));
cubot.heldItem = (int)(long)json.get("heldItem");
cubot.heldItem = (int)(long)json.get("heldItem");
return cubot;
@ -125,4 +124,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
public void setParent(User parent) {
this.parent = parent;
}
public CubotAction getAction() {
return lastAction;
}
}

View File

@ -3,6 +3,8 @@ package net.simon987.cubotplugin;
public enum CubotAction {
IDLE,
DIGGING,
WALKING
WALKING,
WITHDRAWING,
DEPOSITING
}

View File

@ -11,7 +11,7 @@ public class CubotDrill extends CpuHardware {
/**
* Hardware ID (Should be unique)
*/
public static final int HWID = 0x0005;
static final char HWID = 0x0005;
public static final int DEFAULT_ADDRESS = 5;
@ -23,24 +23,35 @@ public class CubotDrill extends CpuHardware {
this.cubot = cubot;
}
@Override
public char getId() {
return HWID;
}
@Override
public void handleInterrupt(Status status) {
int a = getCpu().getRegisterSet().getRegister("A").getValue();
if (a == GATHER) {
int tile = cubot.getWorld().getTileMap().getTileAt(cubot.getX(), cubot.getY());
if (cubot.getAction() != CubotAction.IDLE) {
int tile = cubot.getWorld().getTileMap().getTileAt(cubot.getX(), cubot.getY());
if (tile == TileMap.IRON_TILE) {
cubot.setHeldItem(TileMap.ITEM_IRON);
if (tile == TileMap.IRON_TILE) {
cubot.setHeldItem(TileMap.ITEM_IRON);
cubot.setCurrentAction(CubotAction.DIGGING);
} else if (tile == TileMap.COPPER_TILE) {
cubot.setHeldItem(TileMap.ITEM_COPPER);
} else if (tile == TileMap.COPPER_TILE) {
cubot.setHeldItem(TileMap.ITEM_COPPER);
cubot.setCurrentAction(CubotAction.DIGGING);
} else {
System.out.println("FAILED: dig");
} else {
System.out.println("FAILED: dig");
}
}
}
}

View File

@ -10,7 +10,7 @@ public class CubotInventory extends CpuHardware {
/**
* Hardware ID (Should be unique)
*/
public static final int HWID = 0x0006;
static final int HWID = 0x0006;
public static final int DEFAULT_ADDRESS = 6;
@ -23,6 +23,11 @@ public class CubotInventory extends CpuHardware {
this.cubot = cubot;
}
@Override
public char getId() {
return HWID;
}
@Override
public void handleInterrupt(Status status) {

View File

@ -15,7 +15,7 @@ public class CubotLaser extends CpuHardware {
/**
* Hardware ID (Should be unique)
*/
public static final int HWID = 0x0002;
static final int HWID = 0x0002;
public static final int DEFAULT_ADDRESS = 2;
@ -28,6 +28,11 @@ public class CubotLaser extends CpuHardware {
this.cubot = cubot;
}
@Override
public char getId() {
return HWID;
}
@Override
public void handleInterrupt(Status status) {
@ -42,7 +47,8 @@ public class CubotLaser extends CpuHardware {
Point frontTile = cubot.getFrontTile();
ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsAt(frontTile.x, frontTile.y);
if(objects.size() > 0){
if (cubot.getAction() != CubotAction.IDLE && objects.size() > 0) {
if (objects.get(0) instanceof InventoryHolder) {
//Take the item
@ -50,6 +56,7 @@ public class CubotLaser extends CpuHardware {
cubot.setHeldItem(b);
System.out.println("took " + b);
cubot.setCurrentAction(CubotAction.WITHDRAWING);
} else {
//The inventory holder can't provide this item
@ -60,8 +67,7 @@ public class CubotLaser extends CpuHardware {
}
} else {
//Nothing in front
//todo Add emote here
System.out.println("DEBUG: FAILED: take (Nothing in front)");
System.out.println("DEBUG: FAILED: take (Nothing in front or Cubot is busy)");
}
}

View File

@ -19,7 +19,7 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
/**
* Hardware ID (Should be unique)
*/
public static final int HWID = 0x0001;
static final int HWID = 0x0001;
private Cubot cubot;
@ -27,6 +27,11 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
this.cubot = cubot;
}
@Override
public char getId() {
return HWID;
}
@Override
public void handleInterrupt(Status status) {
int a = getCpu().getRegisterSet().getRegister("A").getValue();

View File

@ -16,7 +16,7 @@ public class CubotRadar extends CpuHardware implements JSONSerialisable {
/**
* Hardware ID (Should be unique)
*/
public static final int HWID = 0x0003;
public static final char HWID = 0x0003;
public static final int DEFAULT_ADDRESS = 3;
@ -30,6 +30,12 @@ public class CubotRadar extends CpuHardware implements JSONSerialisable {
this.cubot = cubot;
}
@Override
public char getId() {
return HWID;
}
@Override
public void handleInterrupt(Status status) {

View File

@ -18,7 +18,7 @@ public class Keyboard extends CpuHardware {
/**
* Hardware ID (Should be unique)
*/
public static final int HWID = 0x0004;
public static final char HWID = 0x0004;
private Cubot cubot;
@ -26,6 +26,11 @@ public class Keyboard extends CpuHardware {
this.cubot = cubot;
}
@Override
public char getId() {
return HWID;
}
@Override
public void handleInterrupt(Status status) {

View File

@ -6,7 +6,6 @@ import net.simon987.server.event.GameEvent;
import net.simon987.server.event.GameEventListener;
import net.simon987.server.event.WorldGenerationEvent;
import net.simon987.server.game.World;
import net.simon987.server.game.WorldGenerator;
import net.simon987.server.logging.LogManager;
import java.awt.*;
@ -62,9 +61,13 @@ public class WorldCreationListener implements GameEventListener {
for (int i = 0; i < treeCount; i++) {
Point p = world.getTileMap().getRandomPlainTile();
if (p != null) {
//Don't block worlds
while (p.x == 0 || p.y == 0 || p.x == World.WORLD_SIZE - 1 || p.y == World.WORLD_SIZE - 1) {
p = world.getTileMap().getRandomPlainTile();
}
for (Plant plant : plants) {
if (plant.getX() == p.x && plant.getY() == p.y) {
//There is already a plant here

View File

@ -10,21 +10,17 @@ import java.net.InetSocketAddress;
public class Main {
public static void main(String[] args){
//TODO: Object information Window (Hover, click ?)
//TODO: Docs
/*
* - Intel 8086 p.14 design
* - Memory: Storage organisation: From a storage pov, 8086 memory spaces are
* organised as identical arrays of 16-bit words
*/
//TODO: Object information Window (Hover, click ?)
//TODO: Website front page
//TODO: Account page
//TODO: Chat (Slack?)
//TODO: Inventory indicator
//TODO: Dig animations
//TODO: Withdraw animation / action
//TODO: HWN, HWQ Instruction
//TODO: Prevent Biomass from blocking Worlds
//TODO: Change code documentation (Check for "Database" etc..)
//TODO: Load and save: handle no save / invalid save
// - Make sure the Hardware is saved and can be loaded
@ -33,6 +29,7 @@ public class Main {
//---------------------------------
//TODO: Inventory indicator (Multiple items)
//TODO: Software Interrupts (PIC): Interupt flag?
/*
* - INT/INTO instruction
@ -53,6 +50,11 @@ public class Main {
//TODO: Cache objects requests?
//TODO: Ability to toggle debug stuff
//TODO: Data segment, DB, DW, DD, DQ
//TODO: Set client animation speed relative to TICK_LENGTH
//TODO: Withdraw animation / action
//TODO: Prevent World creation out of bounds, warp around universe
//TODO: Multiple Biomass style (and yield, rarity)
LogManager.initialize();
@ -69,5 +71,4 @@ public class Main {
(new Thread(socketServer)).start();
(new Thread(GameServer.INSTANCE)).start();
}
}

View File

@ -92,6 +92,7 @@ public class CPU implements JSONSerialisable{
instructionSet.add(new JnsInstruction(this));
instructionSet.add(new JsInstruction(this));
instructionSet.add(new HwiInstruction(this));
instructionSet.add(new HwqInstruction(this));
status = new Status();
memory = new Memory(config.getInt("memory_size"));
@ -423,6 +424,17 @@ public class CPU implements JSONSerialisable{
}
}
public void hardwareQuery(int address) {
CpuHardware hardware = attachedHardware.get(address);
if (hardware != null) {
registerSet.getRegister("B").setValue(hardware.getId());
} else {
registerSet.getRegister("B").setValue(0);
}
}
@Override
public String toString() {
@ -433,4 +445,6 @@ public class CPU implements JSONSerialisable{
return str;
}
}

View File

@ -24,6 +24,8 @@ public abstract class CpuHardware implements JSONSerialisable {
this.cpu = cpu;
}
public abstract char getId();
public static CpuHardware deserialize(JSONObject hwJson){
for(ServerPlugin plugin : GameServer.INSTANCE.getPluginManager().getPlugins()){

View File

@ -3,6 +3,7 @@ package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.CPU;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
/**
* Send hardware interupt
@ -20,6 +21,13 @@ public class HwiInstruction extends Instruction {
this.cpu = cpu;
}
@Override
public Status execute(Target src, int srcIndex, Status status) {
status.setErrorFlag(cpu.hardwareInterrupt(src.get(srcIndex)));
return status;
}
@Override
public Status execute(int src, Status status) {

View File

@ -0,0 +1,32 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.CPU;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
public class HwqInstruction extends Instruction {
private static final int OPCODE = 28;
private CPU cpu;
public HwqInstruction(CPU cpu) {
super("hwq", OPCODE);
this.cpu = cpu;
}
@Override
public Status execute(Target src, int srcIndex, Status status) {
cpu.hardwareQuery(src.get(srcIndex));
return status;
}
@Override
public Status execute(int src, Status status) {
cpu.hardwareQuery(src);
return status;
}
}

View File

@ -67,13 +67,13 @@ public class World implements JSONSerialisable{
ArrayList<GameObject> gameObjects_ = new ArrayList<>(gameObjects);
for(GameObject object : gameObjects_){
if(object instanceof Updatable){
((Updatable) object).update();
}
if(object.isDead()){
System.out.println("Removed" + object.getObjectId());
gameObjects.remove(object);
}
if (object instanceof Updatable) {
((Updatable) object).update();
}
}
}
@ -145,17 +145,17 @@ public class World implements JSONSerialisable{
for (int y = 0; y < World.WORLD_SIZE; y++) {
for (int x = 0; x < World.WORLD_SIZE; x++) {
if (tiles[y][x] == TileMap.PLAIN_TILE) {
if (tiles[x][y] == TileMap.PLAIN_TILE) {
mapInfo[x][y] = 0;
} else if (tiles[y][x] == TileMap.WALL_TILE) {
} else if (tiles[x][y] == TileMap.WALL_TILE) {
mapInfo[x][y] = INFO_BLOCKED;
} else if (tiles[y][x] == TileMap.COPPER_TILE) {
} else if (tiles[x][y] == TileMap.COPPER_TILE) {
mapInfo[x][y] = INFO_COPPER;
} else if (tiles[y][x] == TileMap.IRON_TILE) {
} else if (tiles[x][y] == TileMap.IRON_TILE) {
mapInfo[x][y] = INFO_IRON;
}
}

View File

@ -1,6 +1,5 @@
package net.simon987.server.webserver;
import net.simon987.server.GameServer;
import org.java_websocket.WebSocket;
import java.util.ArrayList;
@ -42,7 +41,6 @@ public class OnlineUserManager {
*/
public void remove(OnlineUser user) {
onlineUsers.remove(user);
GameServer.INSTANCE.getGameUniverse().removeUser(user.getUser());
}
public ArrayList<OnlineUser> getOnlineUsers() {

View File

@ -110,6 +110,7 @@ public class SocketServer extends WebSocketServer {
public void onError(WebSocket conn, Exception ex) {
System.err.println("an error occured on connection " + conn.getRemoteSocketAddress() + ':' + ex);
userManager.remove(userManager.getUser(conn));
conn.close();
ex.printStackTrace();
}

View File

@ -20,8 +20,6 @@ public class UserInfoRequestHandler implements MessageHandler {
json.put("t", "userInfo");
json.put("worldX", GameServer.INSTANCE.getConfig().getInt("new_user_worldX"));
json.put("worldY", GameServer.INSTANCE.getConfig().getInt("new_user_worldY"));
json.put("x", 1);
json.put("y", 1);
user.getWebSocket().send(json.toJSONString());
} else {
@ -31,8 +29,6 @@ public class UserInfoRequestHandler implements MessageHandler {
json.put("t", "userInfo");
json.put("worldX", object.getWorld().getX());
json.put("worldY", object.getWorld().getY());
json.put("x", object.getX());
json.put("y", object.getY());
user.getWebSocket().send(json.toJSONString());
}

View File

@ -18,14 +18,9 @@ org_offset=1024
stack_bottom=32768
# Size of the memory in bytes
memory_size=65536
# The game server will process the new user every 'new_user_interval' ticks
new_user_interval=10
# todo set to 10^
# Initial location of new user's controlled unit
new_user_worldX = 0
new_user_worldY = 0
# Effect when the new user's controlled unit spawns
new_user_effect=WARNING
# Default user code
new_user_code=; Welcome to Much Assembly required!\n\
; You will find useful information on the game here: https://github.com/simon987/Much-Assembly-Required/wiki\n\
@ -35,7 +30,6 @@ new_user_code=; Welcome to Much Assembly required!\n\
# Default held item
new_user_item=0
# ----------------------------------------------
# Biomass units yield for a plant
plant_yield=2
# Grow time in ticks for a plant to grow
@ -45,20 +39,6 @@ minTreeCount=3
# Maximum tree count for the WorldGenerator
maxTreeCount=10
# ----------------------------------------------
#Number of ticks of cooking for 1 unit of biomass
biomass_fuel_value=32
#Number of ticks required to cook iron (1-255)
iron_cook_time=8
#Number of ticks required to cook copper (1-255)
copper_cook_time=8
# Hit points of the Tortoise GameObject
tortoise_hp=10
# Number of biomass parts required to make a biogas unit
# The number of biomass units required to make a biogas unit=
# biomass_cost / biomass_fuel_value
biogas_cost=48
# ----------------------------------------------
# Minimum center point count for the WorldGenerator
wg_centerPointCountMin=5
# Maximum center point count for the WorldGenerator
@ -66,14 +46,13 @@ wg_centerPointCountMax=15
# Wall/Plain tile ratio for the WorldGenerator
wg_wallPlainRatio=4
# Minimum iron tiles count for the WorldGenerator
wg_minIronCount=1
wg_minIronCount=0
# Minimum iron tile count for the WorldGenerator
wg_maxIronCount=3
wg_maxIronCount=2
# Minimum copper tile count for the WorldGenerator
wg_minCopperCount=1
wg_minCopperCount=0
# Maximum copper tile count for the WorldGenerator
wg_maxCopperCount=3
wg_maxCopperCount=2
# ----------------------------------------------
# Maximum execution time of user code in ms
user_timeout=40