Initial Void Bastion 0.20 prototype
This commit is contained in:
commit
7362ca0f02
251 files changed
+29688
No files matched your search
@@ -0,0 +1,54 @@
|
||||
const assert = require("assert");
|
||||
const fs = require("fs");
|
||||
const vm = require("vm");
|
||||
const path = require("path");
|
||||
|
||||
const source = fs.readFileSync(path.join(__dirname, "..", "runtime", "build", "index.js"), "utf8");
|
||||
const context = { console, Math, Date, JSON, isFinite };
|
||||
vm.createContext(context);
|
||||
vm.runInContext(source, context);
|
||||
|
||||
const sent = [];
|
||||
const dispatcher = {
|
||||
broadcastMessage(opCode, data) {
|
||||
sent.push({ opCode, data: JSON.parse(data) });
|
||||
}
|
||||
};
|
||||
const nk = { binaryToString: data => Buffer.from(data).toString("utf8") };
|
||||
const logger = { info() {} };
|
||||
const presenceA = { userId: "pilot-a", sessionId: "a", username: "Pilot A" };
|
||||
const presenceB = { userId: "pilot-b", sessionId: "b", username: "Pilot B" };
|
||||
|
||||
let state = context.matchInit({}, logger, nk, { difficulty: 1 }).state;
|
||||
state = context.matchJoin({}, logger, nk, dispatcher, 1, state, [presenceA]).state;
|
||||
state = context.matchJoin({}, logger, nk, dispatcher, 2, state, [presenceB]).state;
|
||||
assert.strictEqual(state.started, true);
|
||||
assert.strictEqual(state.slots["pilot-a"], 0);
|
||||
assert.strictEqual(state.slots["pilot-b"], 1);
|
||||
|
||||
function message(sender, opCode, payload) {
|
||||
return { sender, opCode, data: Buffer.from(JSON.stringify(payload)) };
|
||||
}
|
||||
|
||||
state = context.matchLoop({}, logger, nk, dispatcher, 3, state, [
|
||||
message(presenceA, 10, { tower_type: 0, x: 200, y: 200 }),
|
||||
message(presenceB, 10, { tower_type: 1, x: 2760, y: 200 })
|
||||
]).state;
|
||||
assert.strictEqual(state.towers.length, 2);
|
||||
assert.strictEqual(state.credits[0], 310);
|
||||
assert.strictEqual(state.credits[1], 250);
|
||||
|
||||
state = context.matchLoop({}, logger, nk, dispatcher, 4, state, [message(presenceA, 13, {})]).state;
|
||||
assert.strictEqual(state.wave, 1);
|
||||
assert.strictEqual(state.waveActive, true);
|
||||
for (let tick = 5; tick < 30; tick++) state = context.matchLoop({}, logger, nk, dispatcher, tick, state, []).state;
|
||||
assert.ok(state.enemies.length > 0 || state.spawnRemaining > 0);
|
||||
assert.ok(sent.some(entry => entry.opCode === 1 && entry.data.started === true));
|
||||
|
||||
const towerA = state.towers.find(tower => tower.owner === 0);
|
||||
state = context.matchLoop({}, logger, nk, dispatcher, 30, state, [message(presenceA, 11, { tower_id: towerA.id })]).state;
|
||||
assert.strictEqual(state.towers.find(tower => tower.id === towerA.id).level, 2);
|
||||
state = context.matchLoop({}, logger, nk, dispatcher, 31, state, [message(presenceA, 12, { tower_id: towerA.id })]).state;
|
||||
assert.ok(!state.towers.some(tower => tower.id === towerA.id));
|
||||
|
||||
console.log("VOID_BASTION_SERVER_SIM_OK");
|
||||
Reference in new issue
Block a user