Browse Source

random map room templates now have different randomised mappings for tiles, walls and doodads

tags/v0.8.0
Shaun 4 years ago
parent
commit
7296454971
3 changed files with 58 additions and 47 deletions
  1. +1
    -2
      src/server/world/instancer.js
  2. +41
    -39
      src/server/world/map.js
  3. +16
    -6
      src/server/world/randomMap.js

+ 1
- 2
src/server/world/instancer.js View File

@@ -6,7 +6,6 @@ let physics = require('./physics');
let resourceSpawner = require('./resourceSpawner'); let resourceSpawner = require('./resourceSpawner');
let spellCallbacks = require('../config/spells/spellCallbacks'); let spellCallbacks = require('../config/spells/spellCallbacks');
let questBuilder = require('../config/quests/questBuilder'); let questBuilder = require('../config/quests/questBuilder');
let randomMap = require('./randomMap');
let events = require('../events/events'); let events = require('../events/events');
let scheduler = require('../misc/scheduler'); let scheduler = require('../misc/scheduler');
let mail = require('../mail/mail'); let mail = require('../mail/mail');
@@ -53,7 +52,7 @@ module.exports = {
if (!map.oldCollisionMap) if (!map.oldCollisionMap)
map.oldCollisionMap = map.collisionMap; map.oldCollisionMap = map.collisionMap;


randomMap.generate({
map.randomMap.generate({
map: map, map: map,
physics: physics, physics: physics,
spawners: spawners spawners: spawners


+ 41
- 39
src/server/world/map.js View File

@@ -131,58 +131,60 @@ module.exports = {
getMapFile: function () { getMapFile: function () {
this.build(); this.build();


randomMap = extend({}, randomMap);
this.randomMap = extend({}, randomMap);
this.oldMap = this.layers; 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 //Fix for newer versions of Tiled
randomMap.templates
this.randomMap.templates
.forEach(r => { .forEach(r => {
r.properties = objectifyProperties(r.properties); r.properties = objectifyProperties(r.properties);
}); });


randomMap.templates
this.randomMap.templates
.filter(r => r.properties.mapping) .filter(r => r.properties.mapping)
.forEach(function (m) { .forEach(function (m) {
let x = m.x; let x = m.x;


+ 16
- 6
src/server/world/randomMap.js View File

@@ -25,7 +25,6 @@ module.exports = {


this.rooms = []; this.rooms = [];
this.exitAreas = []; this.exitAreas = [];
this.tileMappings = {};
this.bounds = [0, 0, 0, 0]; this.bounds = [0, 0, 0, 0];
this.templates = extend([], map.rooms); this.templates = extend([], map.rooms);


@@ -285,11 +284,8 @@ module.exports = {
return tile; return tile;


tile = mapping[this.randInt(0, mapping.length)]; tile = mapping[this.randInt(0, mapping.length)];
if (!tile) {
if (floorTile)
return this.randomizeTile(floorTile);
if (!tile)
return 0; return 0;
}


return tile; return tile;
}, },
@@ -313,7 +309,21 @@ module.exports = {
let floorTile = template.tiles[i][j]; let floorTile = template.tiles[i][j];


if (!currentTile) { 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; collisionMap[x][y] = collides;
continue; continue;
} else { } else {


Loading…
Cancel
Save