mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-12-13 14:49:03 +00:00
Hacked NPC minimum viable
This commit is contained in:
@@ -60,6 +60,41 @@ public class CPU implements MongoSerializable {
|
||||
private static final char EXECUTION_COST_ADDR = 0x0050;
|
||||
private static final char EXECUTED_INS_ADDR = 0x0051;
|
||||
|
||||
public CPU() {
|
||||
instructionSet = new DefaultInstructionSet();
|
||||
registerSet = new DefaultRegisterSet();
|
||||
codeSectionOffset = 0;
|
||||
|
||||
instructionSet.add(new JmpInstruction(this));
|
||||
instructionSet.add(new JnzInstruction(this));
|
||||
instructionSet.add(new JzInstruction(this));
|
||||
instructionSet.add(new JgInstruction(this));
|
||||
instructionSet.add(new JgeInstruction(this));
|
||||
instructionSet.add(new JleInstruction(this));
|
||||
instructionSet.add(new JlInstruction(this));
|
||||
instructionSet.add(new PushInstruction(this));
|
||||
instructionSet.add(new PopInstruction(this));
|
||||
instructionSet.add(new CallInstruction(this));
|
||||
instructionSet.add(new RetInstruction(this));
|
||||
instructionSet.add(new MulInstruction(this));
|
||||
instructionSet.add(new DivInstruction(this));
|
||||
instructionSet.add(new JnsInstruction(this));
|
||||
instructionSet.add(new JsInstruction(this));
|
||||
instructionSet.add(new HwiInstruction(this));
|
||||
instructionSet.add(new HwqInstruction(this));
|
||||
instructionSet.add(new XchgInstruction(this));
|
||||
instructionSet.add(new JcInstruction(this));
|
||||
instructionSet.add(new JncInstruction(this));
|
||||
instructionSet.add(new JnoInstruction(this));
|
||||
instructionSet.add(new JoInstruction(this));
|
||||
instructionSet.add(new PushfInstruction(this));
|
||||
instructionSet.add(new PopfInstruction(this));
|
||||
instructionSet.add(new JnaInstruction(this));
|
||||
instructionSet.add(new JaInstruction(this));
|
||||
|
||||
status = new Status();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new CPU
|
||||
*/
|
||||
@@ -359,7 +394,6 @@ public class CPU implements MongoSerializable {
|
||||
|
||||
cpu.codeSectionOffset = obj.getInteger("codeSegmentOffset");
|
||||
|
||||
|
||||
cpu.memory = new Memory((Document) obj.get("memory"));
|
||||
cpu.registerSet = RegisterSet.deserialize((Document) obj.get("registerSet"));
|
||||
|
||||
@@ -379,6 +413,14 @@ public class CPU implements MongoSerializable {
|
||||
return memory;
|
||||
}
|
||||
|
||||
public void setMemory(Memory memory) {
|
||||
this.memory = memory;
|
||||
}
|
||||
|
||||
public void setRegisterSet(RegisterSet registerSet) {
|
||||
this.registerSet = registerSet;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -11,13 +11,14 @@ import org.json.simple.JSONObject;
|
||||
public abstract class HardwareModule implements MongoSerializable, JSONSerializable {
|
||||
|
||||
private CPU cpu;
|
||||
protected ControllableUnit unit;
|
||||
|
||||
public HardwareModule() {
|
||||
|
||||
}
|
||||
|
||||
public HardwareModule(Document document, ControllableUnit unit) {
|
||||
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,4 +59,12 @@ public abstract class HardwareModule implements MongoSerializable, JSONSerializa
|
||||
public JSONObject debugJsonSerialise() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
Document document = new Document();
|
||||
|
||||
document.put("type", getClass().getCanonicalName());
|
||||
return document;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,10 @@ import net.simon987.server.game.world.World;
|
||||
import net.simon987.server.user.User;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface ControllableUnit {
|
||||
public interface ControllableUnit extends MessageReceiver, Rechargeable, Attackable {
|
||||
|
||||
ObjectId getObjectId();
|
||||
|
||||
@@ -31,7 +32,11 @@ public interface ControllableUnit {
|
||||
|
||||
int getY();
|
||||
|
||||
void setAction(Action listening);
|
||||
void setAction(Action action);
|
||||
|
||||
void setCurrentAction(Action action);
|
||||
|
||||
Action getCurrentAction();
|
||||
|
||||
World getWorld();
|
||||
|
||||
@@ -42,4 +47,9 @@ public interface ControllableUnit {
|
||||
CPU getCpu();
|
||||
|
||||
void giveItem(Item item);
|
||||
|
||||
Point getFrontTile();
|
||||
|
||||
void setDirection(Direction direction);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ harvester_hp_max=100
|
||||
harvester_regen=5
|
||||
harvester_biomass_drop_count=8
|
||||
radio_tower_range=3
|
||||
hacked_npc_mem_size=5120
|
||||
#Vaults
|
||||
vault_door_open_time=4
|
||||
min_electric_box_count=1
|
||||
|
||||
40
Server/src/main/resources/static/js/mar.js
vendored
40
Server/src/main/resources/static/js/mar.js
vendored
@@ -830,6 +830,7 @@ var ObjectType;
|
||||
ObjectType["OBSTACLE"] = "net.simon987.npcplugin.Obstacle";
|
||||
ObjectType["ELECTRIC_BOX"] = "net.simon987.npcplugin.ElectricBox";
|
||||
ObjectType["PORTAL"] = "net.simon987.npcplugin.Portal";
|
||||
ObjectType["HACKED_NPC"] = "net.simon987.npcplugin.HackedNPC";
|
||||
})(ObjectType || (ObjectType = {}));
|
||||
var ItemType;
|
||||
(function (ItemType) {
|
||||
@@ -873,6 +874,8 @@ var GameObject = (function (_super) {
|
||||
return new ElectricBox(json);
|
||||
case ObjectType.PORTAL:
|
||||
return new Portal(json);
|
||||
case ObjectType.HACKED_NPC:
|
||||
return new HackedNPC(json);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -917,7 +920,7 @@ var Cubot = (function (_super) {
|
||||
_this.heldItem = json.heldItem;
|
||||
_this.direction = json.direction;
|
||||
_this.action = json.action;
|
||||
_this.energy = json.energy;
|
||||
_this.energy = _this.getEnergy(json);
|
||||
_this.cubotSprite = mar.game.make.sprite(0, 0, "sheet", null);
|
||||
_this.cubotSprite.anchor.set(0.5, 0);
|
||||
_this.addChild(_this.cubotSprite);
|
||||
@@ -949,6 +952,10 @@ var Cubot = (function (_super) {
|
||||
_this.setShield(false);
|
||||
return _this;
|
||||
}
|
||||
|
||||
Cubot.prototype.getEnergy = function (json) {
|
||||
return json["net.simon987.cubotplugin.CubotBattery"].energy;
|
||||
};
|
||||
Cubot.prototype.setShield = function (shield) {
|
||||
this.shieldBackSprite.visible = shield;
|
||||
this.shieldFrontSprite.visible = shield;
|
||||
@@ -1012,7 +1019,7 @@ var Cubot = (function (_super) {
|
||||
console.log("Updating Cubot object");
|
||||
}
|
||||
this.action = json.action;
|
||||
this.energy = json.energy;
|
||||
this.energy = this.getEnergy(json);
|
||||
this.direction = json.direction;
|
||||
this.shield = json.shield;
|
||||
this.createInventory([json.heldItem]);
|
||||
@@ -1207,6 +1214,13 @@ var HarvesterNPC = (function (_super) {
|
||||
break;
|
||||
}
|
||||
};
|
||||
HarvesterNPC.prototype.getEnergy = function (json) {
|
||||
if (json.hasOwnProperty("net.simon987.npcplugin.NpcBattery")) {
|
||||
return json["net.simon987.npcplugin.NpcBattery"].energy;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
HarvesterNPC.prototype.updateObject = function (json) {
|
||||
if (DEBUG) {
|
||||
console.log("Updating Harvester NPC object");
|
||||
@@ -1226,6 +1240,28 @@ var HarvesterNPC = (function (_super) {
|
||||
};
|
||||
return HarvesterNPC;
|
||||
}(Cubot));
|
||||
var HackedNPC = (function (_super) {
|
||||
__extends(HackedNPC, _super);
|
||||
|
||||
function HackedNPC(json) {
|
||||
var _this = _super.call(this, json) || this;
|
||||
_this.updateDirection();
|
||||
_this.setText("Hacked NPC");
|
||||
_this.text.visible = false;
|
||||
_this.tint = 0xE040FB;
|
||||
return _this;
|
||||
}
|
||||
|
||||
HackedNPC.prototype.updateObject = function (json) {
|
||||
_super.prototype.updateObject.call(this, json);
|
||||
var holoHw = json["net.simon987.cubotplugin.CubotHologram"];
|
||||
this.updateHologram(holoHw.mode, holoHw.color, holoHw.value, holoHw.string);
|
||||
};
|
||||
HackedNPC.prototype.getEnergy = function (json) {
|
||||
return json["net.simon987.npcplugin.NpcBattery"].energy;
|
||||
};
|
||||
return HackedNPC;
|
||||
}(HarvesterNPC));
|
||||
var BiomassBlob = (function (_super) {
|
||||
__extends(BiomassBlob, _super);
|
||||
function BiomassBlob(json) {
|
||||
|
||||
@@ -7,7 +7,8 @@ enum ObjectType {
|
||||
VAULT_DOOR = "net.simon987.npcplugin.VaultDoor",
|
||||
OBSTACLE = "net.simon987.npcplugin.Obstacle",
|
||||
ELECTRIC_BOX = "net.simon987.npcplugin.ElectricBox",
|
||||
PORTAL = "net.simon987.npcplugin.Portal"
|
||||
PORTAL = "net.simon987.npcplugin.Portal",
|
||||
HACKED_NPC = "net.simon987.npcplugin.HackedNPC"
|
||||
}
|
||||
|
||||
enum ItemType {
|
||||
@@ -59,7 +60,6 @@ abstract class GameObject extends Phaser.Plugin.Isometric.IsoSprite {
|
||||
switch (json.t) {
|
||||
case ObjectType.CUBOT:
|
||||
return new Cubot(json);
|
||||
|
||||
case ObjectType.BIOMASS:
|
||||
return new BiomassBlob(json);
|
||||
case ObjectType.HARVESTER_NPC:
|
||||
@@ -76,6 +76,8 @@ abstract class GameObject extends Phaser.Plugin.Isometric.IsoSprite {
|
||||
return new ElectricBox(json);
|
||||
case ObjectType.PORTAL:
|
||||
return new Portal(json);
|
||||
case ObjectType.HACKED_NPC:
|
||||
return new HackedNPC(json);
|
||||
|
||||
default:
|
||||
return null;
|
||||
@@ -155,7 +157,7 @@ class Cubot extends GameObject {
|
||||
this.heldItem = json.heldItem;
|
||||
this.direction = json.direction;
|
||||
this.action = json.action;
|
||||
this.energy = json.energy;
|
||||
this.energy = this.getEnergy(json);
|
||||
|
||||
this.cubotSprite = mar.game.make.sprite(0, 0, "sheet", null);
|
||||
this.cubotSprite.anchor.set(0.5, 0);
|
||||
@@ -197,6 +199,10 @@ class Cubot extends GameObject {
|
||||
this.setShield(false);
|
||||
}
|
||||
|
||||
protected getEnergy(json): number {
|
||||
return json["net.simon987.cubotplugin.CubotBattery"].energy
|
||||
}
|
||||
|
||||
public setShield(shield: boolean) {
|
||||
this.shieldBackSprite.visible = shield;
|
||||
this.shieldFrontSprite.visible = shield;
|
||||
@@ -277,7 +283,7 @@ class Cubot extends GameObject {
|
||||
}
|
||||
|
||||
this.action = json.action;
|
||||
this.energy = json.energy;
|
||||
this.energy = this.getEnergy(json);
|
||||
this.direction = json.direction;
|
||||
this.shield = json.shield;
|
||||
|
||||
@@ -333,7 +339,7 @@ class Cubot extends GameObject {
|
||||
this.setShield(this.shield > 0)
|
||||
}
|
||||
|
||||
private updateHologram(holoMode: HologramMode, holoColor: number, holoValue: number, holoStr: string): void {
|
||||
protected updateHologram(holoMode: HologramMode, holoColor: number, holoValue: number, holoStr: string): void {
|
||||
|
||||
let fillColor: string = (holoColor & 0xFFFFFF).toString(16);
|
||||
fillColor = "#" + ("000000".substr(fillColor.length) + fillColor);
|
||||
@@ -548,6 +554,14 @@ class HarvesterNPC extends Cubot {
|
||||
}
|
||||
}
|
||||
|
||||
protected getEnergy(json): number {
|
||||
if (json.hasOwnProperty("net.simon987.npcplugin.NpcBattery")) {
|
||||
return json["net.simon987.npcplugin.NpcBattery"].energy;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
updateObject(json) {
|
||||
if (DEBUG) {
|
||||
console.log("Updating Harvester NPC object")
|
||||
@@ -578,6 +592,30 @@ class HarvesterNPC extends Cubot {
|
||||
|
||||
}
|
||||
|
||||
class HackedNPC extends HarvesterNPC {
|
||||
|
||||
constructor(json) {
|
||||
super(json);
|
||||
|
||||
this.updateDirection();
|
||||
this.setText("Hacked NPC");
|
||||
this.text.visible = false;
|
||||
this.tint = 0xE040FB;
|
||||
}
|
||||
|
||||
updateObject(json) {
|
||||
super.updateObject(json);
|
||||
|
||||
let holoHw = json["net.simon987.cubotplugin.CubotHologram"];
|
||||
this.updateHologram(holoHw.mode, holoHw.color, holoHw.value, holoHw.string);
|
||||
}
|
||||
|
||||
protected getEnergy(json): number {
|
||||
return json["net.simon987.npcplugin.NpcBattery"].energy
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class BiomassBlob extends GameObject {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user