From 6cf99a8a6b4d15135e9ffc394e0014326013506b Mon Sep 17 00:00:00 2001 From: Big Bad Waffle Date: Fri, 27 May 2022 19:13:56 +0000 Subject: [PATCH] Revert "chore: removed unused code" This reverts commit 1537f4c5dab7f2f047e31ec7f36ba7e612dfcc83 --- src/server/world/atlas.js | 4 +- src/server/world/customMap.js | 105 ++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 src/server/world/customMap.js diff --git a/src/server/world/atlas.js b/src/server/world/atlas.js index 0062e06d..1ad943cd 100644 --- a/src/server/world/atlas.js +++ b/src/server/world/atlas.js @@ -49,8 +49,6 @@ module.exports = { serverObj.zoneId = thread.id; serverObj.zoneName = thread.name; - serverObj.player.broadcastSelf(); - const simpleObj = obj.getSimple ? obj.getSimple(true, true) : obj; this.send(obj.zoneId, { @@ -292,6 +290,8 @@ module.exports = { delete serverObj.zoneId; delete obj.zoneId; + serverObj.player.broadcastSelf(); + const isRezone = true; await this.addObject(obj, keepPos, isRezone); }, diff --git a/src/server/world/customMap.js b/src/server/world/customMap.js new file mode 100644 index 00000000..dc60cb11 --- /dev/null +++ b/src/server/world/customMap.js @@ -0,0 +1,105 @@ +module.exports = { + instance: null, + ent: null, + tiles: [], + oldTiles: {}, + + load: function (instance, objToAdd, callback) { + this.instance = instance; + + this.ent = instance.mapName + '-' + objToAdd.components.find(c => c.type === 'auth').username; + + io.get({ + ent: this.ent, + field: 'customMap', + callback: this.onLoad.bind(this, callback) + }); + }, + + onLoad: function (callback, result) { + this.tiles = JSON.parse(result || '[]'); + this.build(callback); + }, + + save: async function () { + await io.setAsync({ + key: this.ent, + table: 'customMap', + value: this.tiles, + serialize: true + }); + }, + + build: function (callback) { + this.tiles.forEach(function (t) { + t = t.split('|'); + this.customize(t[0], t[1], t[2], true); + }, this); + + this.save(); + + callback(); + }, + + customize: function (x, y, tile, noStore) { + let action = null; + if (arguments.length === 1) { + action = x; + let obj = action.obj; + tile = action.tile; + x = obj.x; + y = obj.y; + + if (action.destroy) { + x += action.direction.x; + y += action.direction.y; + } + } + + let collide = true; + + if (!noStore) { + let exists = this.tiles.find(function (t) { + t = t.split('|'); + if ((t[0] === x) && (t[1] === y)) + return true; + }); + if (exists) { + tile = this.oldTiles[x + '|' + y]; + collide = false; + + this.tiles.spliceWhere(t => t === exists); + } else if (this.instance.map.clientMap.collisionMap[x][y]) { + //Can't build on natural collisions + return; + } else + this.tiles.push(x + '|' + y + '|' + tile); + } + + if ((collide) && (!this.oldTiles[x + '|' + y])) { + let oldTile = this.instance.map.clientMap.map[x][y]; + this.oldTiles[x + '|' + y] = oldTile - 1; + } + + this.instance.map.clientMap.map[x][y] = tile; + + this.instance.map.clientMap.collisionMap[x][y] = collide; + this.instance.physics.graph.grid[x][y] = !collide; + + if (!noStore) + this.save(); + + if (action) { + action.result = { + x: x, + y: y, + tile: tile, + collide: collide + }; + } + }, + + placeTile: function (obj) { + this.customize(obj.x, obj.y, 52); + } +};