瀏覽代碼

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

tags/v0.8.0
Shaun 3 年之前
父節點
當前提交
7296454971
共有 3 個檔案被更改,包括 58 行新增47 行删除
  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 查看文件

@@ -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


+ 41
- 39
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;


+ 16
- 6
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 {


Loading…
取消
儲存