diff --git a/server/game/room/world/body/body.js b/server/game/room/world/body/body.js index 8300d30..8467737 100644 --- a/server/game/room/world/body/body.js +++ b/server/game/room/world/body/body.js @@ -11,11 +11,17 @@ class Body { this.r = 0; this.b2body = false; this.type = 'asteroid'; + this.mounts = []; this.health = 1; this.world = world; this.id = uuid.v4().slice(0, 8); } + destruct() { + this.mounts.forEach(mount => mount.destruct()); + this.world.physics.remove(this); + } + applyDelta() { this.world.applyDelta(this.id, this.packDelta()); } diff --git a/server/game/room/world/body/rope.js b/server/game/room/world/body/rope.js deleted file mode 100644 index e69de29..0000000 diff --git a/server/game/room/world/body/ship.js b/server/game/room/world/body/ship.js index 19b8789..b0fdcd1 100644 --- a/server/game/room/world/body/ship.js +++ b/server/game/room/world/body/ship.js @@ -4,27 +4,39 @@ const defaults = require('../traits/defaults.json'); const shipTraits = require('../traits/ships.json'); const Body = require('./body.js'); +const Mount = require('./turret/mount.js'); class Ship extends Body { constructor(world, pos, player, build) { super(world); + build = build || defaults.spawnShip; + + // Body data. this.x = pos.x || 0; this.y = pos.y || 0; - build = build || {}; - this.class = build.ship || defaults.spawnShip.ship; - this.turrets = build.turrets || defaults.spawnShip.turrets; - let traits = shipTraits[this.class]; - this.frame = traits.hull; - this.power = traits.power; - this.mounts = traits.mounts; - this.size = traits.size; - this.player = player; this.type = 'ship'; + this.class = build.ship; + this.player = player; this.inputs = {}; this.grapple = false; + // Traits. + let traits = shipTraits[this.class]; + this.traits = traits; + this.frame = traits.frame; + this.power = traits.power; + this.size = traits.size; + + // Mounts + traits.mounts.forEach((mount, i) => { + let mounts = new Mount(this, mount); + this.mounts.push(mount); + }); + + this.turrets = []; + this.thrust = { forward: 0, left: 0, @@ -100,7 +112,7 @@ class Ship extends Body { name: this.player.name, frame: this.frame, power: this.power, - mounts: this.mounts, + mounts: this.traits.mounts, turrets: this.turrets, size: this.size, delta: this.packDelta() diff --git a/server/game/room/world/body/turret/blaster.js b/server/game/room/world/body/turret/blaster.js new file mode 100644 index 0000000..925daef --- /dev/null +++ b/server/game/room/world/body/turret/blaster.js @@ -0,0 +1,20 @@ +'use strict'; + +const Fixture = require('./fixture.js'); +const Laser = require('./shot/laser.js'); + +class Blaster extends Fixture { + constructor(hardpoint, data) { + super(hardpoint, data); + } + + fire() { + wingbase.debug('pew pew'); + let data = { + speed: 1 + + }; + } +} + +module.exports = Blaster; diff --git a/server/game/room/world/body/turret/fixture.js b/server/game/room/world/body/turret/fixture.js new file mode 100644 index 0000000..5e3f0fa --- /dev/null +++ b/server/game/room/world/body/turret/fixture.js @@ -0,0 +1,34 @@ +'use strict'; + +const traits = require('../../traits/turrets.json'); + +class Fixture { + constructor(hardpoint, data) { + this.hardpoint = hardpoint; + + this.projectiles = new WeakSet(); + + let turretTraits = traits[data.type]; + + this.rof = turretTraits.rateOfFire; + + this.traversal = this.hardpoint.traversal || false; + this._angle = this.traversal ? this.traversal.cw : 0; + } + + destruct() { + this.projectiles.forEach(p => p.world.removeBody(p)); + } + + get angle() { + return this._angle; + } + + set angle(angle) { + // TODO: Check if within traversal limit if on mount. + if (this.type == 'fixed') return; + this._angle = angle; + } +} + +module.exports = Fixture; diff --git a/server/game/room/world/body/turret/mount.js b/server/game/room/world/body/turret/mount.js new file mode 100644 index 0000000..5adb347 --- /dev/null +++ b/server/game/room/world/body/turret/mount.js @@ -0,0 +1,24 @@ +'use strict'; + +const Blaster = require('./blaster.js'); + +class Mount { + constructor(ship, data, fixture) { + this.ship = ship; + + this.type = data.type || 'turret'; + this.fixture = false; // TODO: Create fixture. + + this.traversal = data.traversal ? { + cw: data.bounds[0], + ccw: data.bounds[1] + } : false; + } + + destruct() { + if (!this.fixture) return; + this.fixture.destruct(); + } +} + +module.exports = Mount; diff --git a/server/game/room/world/shot/beam.js b/server/game/room/world/body/turret/shot/beam.js similarity index 100% rename from server/game/room/world/shot/beam.js rename to server/game/room/world/body/turret/shot/beam.js diff --git a/server/game/room/world/shot/bullet.js b/server/game/room/world/body/turret/shot/bullet.js similarity index 100% rename from server/game/room/world/shot/bullet.js rename to server/game/room/world/body/turret/shot/bullet.js diff --git a/server/game/room/world/body/turret/shot/laser.js b/server/game/room/world/body/turret/shot/laser.js new file mode 100644 index 0000000..b5cfd00 --- /dev/null +++ b/server/game/room/world/body/turret/shot/laser.js @@ -0,0 +1,11 @@ +'use strict'; + +const Shot = require('./shot.js'); + +class Laser extends Shot { + constructor() { + super(); + } +} + +module.exports = Laser; diff --git a/server/game/room/world/shot/shot.js b/server/game/room/world/body/turret/shot/shot.js similarity index 66% rename from server/game/room/world/shot/shot.js rename to server/game/room/world/body/turret/shot/shot.js index 4acd7d7..6af3373 100644 --- a/server/game/room/world/shot/shot.js +++ b/server/game/room/world/body/turret/shot/shot.js @@ -2,8 +2,8 @@ class Shot { constructor() { - + } } -module.exports = Beam; +module.exports = Shot; diff --git a/server/game/room/world/index.js b/server/game/room/world/index.js index 06a02af..33b82f8 100644 --- a/server/game/room/world/index.js +++ b/server/game/room/world/index.js @@ -124,7 +124,7 @@ class World { } removeBody(body) { - this.physics.remove(body); + body.destruct(); this.bodies.delete(body); this.ships.delete(body); this.structures.delete(body); diff --git a/server/game/room/world/traits/defaults.json b/server/game/room/world/traits/defaults.json index 1e29708..28ad906 100644 --- a/server/game/room/world/traits/defaults.json +++ b/server/game/room/world/traits/defaults.json @@ -1,6 +1,6 @@ { "spawnShip": { "ship": "01", - "turrets": ["01", "01"] + "fixtures": ["01", "01"] } } diff --git a/server/game/room/world/traits/ships.json b/server/game/room/world/traits/ships.json index bbb5093..6a25ea4 100644 --- a/server/game/room/world/traits/ships.json +++ b/server/game/room/world/traits/ships.json @@ -7,7 +7,7 @@ "back": 0, "rotation": 0.003 }, - "hull": [ + "frame": [ [ [12, 1], [29, 13], @@ -18,8 +18,11 @@ ] ], "mounts": [ - [18, 4], - [18, 28] + { + "pos": [18, 4], + "type": "fixed", + "traversal": false + } ] } } diff --git a/server/game/room/world/traits/turrets.json b/server/game/room/world/traits/turrets.json new file mode 100644 index 0000000..031e9c2 --- /dev/null +++ b/server/game/room/world/traits/turrets.json @@ -0,0 +1,27 @@ +{ + "01": { + "name": "Basic Blaster", + "type": "blaster", + "damage": { + "thermal": 5, + "kinetic": 1 + }, + "speed": 1, + "range": 10, + "autofire": true, + "rateOfFire": 4, + "overheat": { + "cooldown": 0.01, + "heat": 0.1 + }, + "cost": { + + }, + "appearance": { + "type": "laser", + "color": "#ff5f45", + "trail": 3, + "size": 2 + } + } +} diff --git a/server/interface.js b/server/interface.js index 04098a4..b4f2335 100644 --- a/server/interface.js +++ b/server/interface.js @@ -23,6 +23,10 @@ class ServerInterface { `${pad(('' + d.getUTCMilliseconds()).slice(0, 2), 2, true)}> `; console.log(timestamp.gray, msg); } + + debug(msg) { + this.log(msg.cyan); + } } module.exports = ServerInterface;