NPC Plugin refactoring

This commit is contained in:
simon
2018-12-22 15:29:58 -05:00
parent e4a06e79d4
commit b361f87154
14 changed files with 146 additions and 101 deletions

View File

@@ -10,7 +10,7 @@ import org.bson.types.ObjectId;
import java.awt.*;
import java.util.ArrayList;
public interface ControllableUnit extends MessageReceiver, Rechargeable, Attackable {
public interface ControllableUnit extends MessageReceiver, Rechargeable, Attackable, HardwareHost {
ObjectId getObjectId();

View File

@@ -138,9 +138,9 @@ public class SocketServer {
} else {
ControllableUnit unit = user.getUser().getControlledUnit();
json.put("c", charArraysToJSON(unit.getConsoleMessagesBuffer()));
json.put("console_message_buffer", charArraysToJSON(unit.getConsoleMessagesBuffer()));
json.put("keys", intListToJSON(unit.getKeyboardBuffer()));
json.put("cm", unit.getConsoleMode());
json.put("console_mode", unit.getConsoleMode());
sendJSONObject(user, json);
}

View File

@@ -66,12 +66,15 @@ shield_energy_cost=50
npc_lifetime=1024
npc_max_factory_distance=3
factory_max_npc_count=16
factory_spawn_rate=5
factory_program_size=1024
settlement_spawn_rate=5
harvester_hp_max=100
harvester_regen=5
harvester_biomass_drop_count=8
radio_tower_range=3
hacked_npc_mem_size=5120
npc_exec_time=5
hacked_npc_die_on_no_energy=1
#Vaults
vault_door_open_time=4
min_electric_box_count=1

View File

@@ -276,6 +276,9 @@ var config = {
lowEnergy: 100,
otherCubotAlpha: 0.6,
},
hackedNpc: {
tint: 0xE040FB,
},
biomass: {
tint: 0x63B85F,
tintHover: 0x00FF00,
@@ -537,9 +540,9 @@ var TickListener = (function () {
mar.client.keyboardBuffer.keys = message.keys;
}
if (message.c != undefined) {
mar.client.consoleScreen.handleConsoleBufferUpdate(message.c, message.cm);
mar.client.consoleScreen.handleConsoleBufferUpdate(message.console_message_buffer, message.console_mode);
if (DEBUG) {
console.log("[MAR] Received " + message.c.length + " console message(s)");
console.log("[MAR] Received " + message.console_message_buffer.length + " console message(s)");
}
}
};
@@ -921,6 +924,7 @@ var Cubot = (function (_super) {
_this.direction = json.direction;
_this.action = json.action;
_this.energy = _this.getEnergy(json);
_this.baseTint = config.cubot.tint;
_this.cubotSprite = mar.game.make.sprite(0, 0, "sheet", null);
_this.cubotSprite.anchor.set(0.5, 0);
_this.addChild(_this.cubotSprite);
@@ -952,7 +956,6 @@ var Cubot = (function (_super) {
_this.setShield(false);
return _this;
}
Cubot.prototype.getEnergy = function (json) {
return json["net.simon987.cubotplugin.CubotBattery"].energy;
};
@@ -963,11 +966,11 @@ var Cubot = (function (_super) {
Cubot.prototype.onTileHover = function () {
mar.game.add.tween(this).to({ isoZ: 45 }, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({ x: 1.2, y: 1.2 }, 200, Phaser.Easing.Linear.None, true);
this.cubotSprite.tint = config.cubot.hoverTint;
if (this.text !== undefined) {
this.text.visible = true;
}
this.hovered = true;
this.cubotSprite.tint = this.getTint();
};
Cubot.prototype.onTileExit = function () {
mar.game.add.tween(this).to({ isoZ: 15 }, 400, Phaser.Easing.Bounce.Out, true);
@@ -1007,7 +1010,7 @@ var Cubot = (function (_super) {
return config.cubot.lowEnergyTint;
}
else {
return config.cubot.tint;
return this.baseTint;
}
}
else {
@@ -1195,9 +1198,6 @@ var HarvesterNPC = (function (_super) {
_this.text.visible = false;
return _this;
}
HarvesterNPC.prototype.getTint = function () {
return config.cubot.tint;
};
HarvesterNPC.prototype.updateDirection = function () {
switch (this.direction) {
case Direction.NORTH:
@@ -1218,7 +1218,7 @@ var HarvesterNPC = (function (_super) {
if (json.hasOwnProperty("net.simon987.npcplugin.NpcBattery")) {
return json["net.simon987.npcplugin.NpcBattery"].energy;
} else {
return 0;
return 1000;
}
};
HarvesterNPC.prototype.updateObject = function (json) {
@@ -1242,24 +1242,20 @@ var HarvesterNPC = (function (_super) {
}(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;
_this.baseTint = config.hackedNpc.tint;
_this.cubotSprite.tint = _this.baseTint;
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) {

View File

@@ -85,10 +85,12 @@ class TickListener implements MessageListener {
//Update console screen
if (message.c != undefined) {
mar.client.consoleScreen.handleConsoleBufferUpdate(message.c, message.cm as ConsoleMode);
mar.client.consoleScreen.handleConsoleBufferUpdate(
message.console_message_buffer,
message.console_mode as ConsoleMode);
if (DEBUG) {
console.log("[MAR] Received " + message.c.length + " console message(s)")
console.log("[MAR] Received " + message.console_message_buffer.length + " console message(s)")
}
}
}

View File

@@ -138,6 +138,7 @@ class Cubot extends GameObject {
protected cubotSprite: Phaser.Sprite;
private shieldBackSprite: Phaser.Sprite;
private shieldFrontSprite: Phaser.Sprite;
protected baseTint: number;
constructor(json) {
//workaround for topological sort, needs sprite dimensions
@@ -158,6 +159,7 @@ class Cubot extends GameObject {
this.direction = json.direction;
this.action = json.action;
this.energy = this.getEnergy(json);
this.baseTint = config.cubot.tint;
this.cubotSprite = mar.game.make.sprite(0, 0, "sheet", null);
this.cubotSprite.anchor.set(0.5, 0);
@@ -213,13 +215,12 @@ class Cubot extends GameObject {
mar.game.add.tween(this).to({isoZ: 45}, 200, Phaser.Easing.Quadratic.InOut, true);
mar.game.add.tween(this.scale).to({x: 1.2, y: 1.2}, 200, Phaser.Easing.Linear.None, true);
this.cubotSprite.tint = config.cubot.hoverTint;
if (this.text !== undefined) {
this.text.visible = true;
}
this.hovered = true;
this.cubotSprite.tint = this.getTint();
}
@@ -269,7 +270,7 @@ class Cubot extends GameObject {
if (this.energy <= config.cubot.lowEnergy) {
return config.cubot.lowEnergyTint;
} else {
return config.cubot.tint;
return this.baseTint;
}
} else {
return config.cubot.hoverTint;
@@ -530,13 +531,6 @@ class HarvesterNPC extends Cubot {
this.text.visible = false;
}
/**
* Needs to be overridden because Cubot() calls getTint() when initialised
*/
public getTint() {
return config.cubot.tint;
}
public updateDirection() {
switch (this.direction) {
case Direction.NORTH:
@@ -558,7 +552,7 @@ class HarvesterNPC extends Cubot {
if (json.hasOwnProperty("net.simon987.npcplugin.NpcBattery")) {
return json["net.simon987.npcplugin.NpcBattery"].energy;
} else {
return 0;
return 1000; //arbitrary number so that the lowEnergy color thresh doesn't trigger
}
}
@@ -600,7 +594,8 @@ class HackedNPC extends HarvesterNPC {
this.updateDirection();
this.setText("Hacked NPC");
this.text.visible = false;
this.tint = 0xE040FB;
this.baseTint = config.hackedNpc.tint;
this.cubotSprite.tint = this.baseTint;
}
updateObject(json) {
@@ -609,11 +604,6 @@ class HackedNPC extends HarvesterNPC {
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
}
}

View File

@@ -18,6 +18,9 @@ let config = {
lowEnergy: 100, //Low energy threshold to change color
otherCubotAlpha: 0.6,
},
hackedNpc: {
tint: 0xE040FB,
},
biomass: {
tint: 0x63B85F,
tintHover: 0x00FF00,