From 7296454971133200e179f73ce3cdb73a21c68b11 Mon Sep 17 00:00:00 2001 From: Shaun Date: Sat, 4 Jul 2020 11:41:49 +0200 Subject: [PATCH] random map room templates now have different randomised mappings for tiles, walls and doodads --- src/server/world/instancer.js | 3 +- src/server/world/map.js | 80 ++++++++++++++++++----------------- src/server/world/randomMap.js | 22 +++++++--- 3 files changed, 58 insertions(+), 47 deletions(-) diff --git a/src/server/world/instancer.js b/src/server/world/instancer.js index c213026e..7e745e43 100644 --- a/src/server/world/instancer.js +++ b/src/server/world/instancer.js @@ -6,7 +6,6 @@ let physics = require('./physics'); let resourceSpawner = require('./resourceSpawner'); let spellCallbacks = require('../config/spells/spellCallbacks'); let questBuilder = require('../config/quests/questBuilder'); -let randomMap = require('./randomMap'); let events = require('../events/events'); let scheduler = require('../misc/scheduler'); let mail = require('../mail/mail'); @@ -53,7 +52,7 @@ module.exports = { if (!map.oldCollisionMap) map.oldCollisionMap = map.collisionMap; - randomMap.generate({ + map.randomMap.generate({ map: map, physics: physics, spawners: spawners diff --git a/src/server/world/map.js b/src/server/world/map.js index a4a0c625..f18fa3ac 100644 --- a/src/server/world/map.js +++ b/src/server/world/map.js @@ -131,58 +131,60 @@ module.exports = { getMapFile: function () { this.build(); - randomMap = extend({}, randomMap); + this.randomMap = extend({}, randomMap); this.oldMap = this.layers; - randomMap.templates = extend([], this.rooms); - randomMap.generateMappings(this); - - for (let i = 0; i < this.size.w; i++) { - let row = this.layers[i]; - for (let j = 0; j < this.size.h; j++) { - let cell = row[j]; - if (!cell) - continue; - - cell = cell.split(','); - let cLen = cell.length; - - let newCell = ''; - for (let k = 0; k < cLen; k++) { - let c = cell[k]; - let newC = randomMap.randomizeTile(c); - newCell += newC; - - //Wall? - if ((c >= 160) && (c <= 352) && (newC === 0)) - this.collisionMap[i][j] = 0; - - if (k < cLen - 1) - newCell += ','; - } + this.randomMap.templates = extend([], this.rooms); + this.randomMap.generateMappings(this); + + if (!mapFile.properties.isRandom) { + for (let i = 0; i < this.size.w; i++) { + let row = this.layers[i]; + for (let j = 0; j < this.size.h; j++) { + let cell = row[j]; + if (!cell) + continue; + + cell = cell.split(','); + let cLen = cell.length; + + let newCell = ''; + for (let k = 0; k < cLen; k++) { + let c = cell[k]; + let newC = this.randomMap.randomizeTile(c); + newCell += newC; + + //Wall? + if ((c >= 160) && (c <= 352) && (newC === 0)) + this.collisionMap[i][j] = 0; + + if (k < cLen - 1) + newCell += ','; + } - let fakeContents = []; - const hiddenWall = this.hiddenWalls[i][j]; - const hiddenTile = this.hiddenTiles[i][j]; + let fakeContents = []; + const hiddenWall = this.hiddenWalls[i][j]; + const hiddenTile = this.hiddenTiles[i][j]; - if (hiddenTile) - fakeContents.push(-randomMap.randomizeTile(hiddenTile)); - if (hiddenWall) - fakeContents.push(-randomMap.randomizeTile(hiddenWall)); + if (hiddenTile) + fakeContents.push(-this.randomMap.randomizeTile(hiddenTile)); + if (hiddenWall) + fakeContents.push(-this.randomMap.randomizeTile(hiddenWall)); - if (fakeContents.length) - newCell += ',' + fakeContents.join(','); + if (fakeContents.length) + newCell += ',' + fakeContents.join(','); - row[j] = newCell; + row[j] = newCell; + } } } //Fix for newer versions of Tiled - randomMap.templates + this.randomMap.templates .forEach(r => { r.properties = objectifyProperties(r.properties); }); - randomMap.templates + this.randomMap.templates .filter(r => r.properties.mapping) .forEach(function (m) { let x = m.x; diff --git a/src/server/world/randomMap.js b/src/server/world/randomMap.js index 3235eb57..8574dd12 100644 --- a/src/server/world/randomMap.js +++ b/src/server/world/randomMap.js @@ -25,7 +25,6 @@ module.exports = { this.rooms = []; this.exitAreas = []; - this.tileMappings = {}; this.bounds = [0, 0, 0, 0]; this.templates = extend([], map.rooms); @@ -285,11 +284,8 @@ module.exports = { return tile; tile = mapping[this.randInt(0, mapping.length)]; - if (!tile) { - if (floorTile) - return this.randomizeTile(floorTile); + if (!tile) return 0; - } return tile; }, @@ -313,7 +309,21 @@ module.exports = { let floorTile = template.tiles[i][j]; if (!currentTile) { - map[x][y] = this.randomizeTile(tile, floorTile); + let cell = tile.split(','); + let cLen = cell.length; + + let newCell = ''; + for (let k = 0; k < cLen; k++) { + let c = cell[k]; + let newC = this.randomizeTile(c); + newCell += newC; + + if (k < cLen - 1) + newCell += ','; + } + + map[x][y] = newCell; + collisionMap[x][y] = collides; continue; } else {