Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Commit

Permalink
fixed chunkHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
lamo2k123 committed Jan 11, 2017
1 parent a8104f7 commit f73b51f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
uo/
68 changes: 66 additions & 2 deletions map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const FileIndexReader = require('./fileindexreader');
const pad = require('./pad');

class Map {

constructor(options) {
this.options = options;
this.index = new FileIndexReader({
Expand All @@ -13,6 +14,18 @@ class Map {
mulFile: `map${options.mapId}.mul`,
uopFileExtension: 'dat'
});

this.chunkHeightList = [
512,
512,
200,
256,
181
];
}

get chunkHeight() {
return this.chunkHeightList[this.options.mapId];
}

getLandBlock(x, y) {
Expand All @@ -23,9 +36,60 @@ class Map {
return this.readLandBlock(x, y);
}

readMyMethod(x, y) {
/*
SizeOfLandChunk = 196
Block:
Y: real position (Y / 8)
X: real position (X / 8)
SIZE-CHUNK : 196
HEIGHT-CHUNK : map id: 0 = 512, 1 = 512, 2 = 200, 3 = 256, 4 = 181
(({X} * {HEIGHT-CHUNK}) + {Y}) * {SIZE-CHUNK} + 4
Cell:
Y: min `0` max `7`
X: min `0` max `7`
(({Y} * 8) + {X}) * 3
Block + Cell:
((({X} * {HEIGHT-CHUNK}) + {Y}) * {SIZE-CHUNK} + 4) + (({Y} * 8) + {X}) * 3
*/

// let offset = (((~~(x / 8) * this.chunkHeight) + ~~(y / 8)) * 196 + 4) + ((8 * 8) + 7) * 3;
let offset = ((~~(x / 8) * this.chunkHeight) + ~~(y / 8)) * 196 + 4;

console.log(1, offset);
if (this.index.isUOP) {
offset = this.calculateOffset(offset);
}

console.log(2, offset);
if (!this.index.reader.seek(offset)) {
throw `could not seek to ${offset}`;
}

console.log(3, offset);
/*console.log({
id : this.index.reader.nextUShort(),
z : this.index.reader.nextSByte()
});*/
return Array(64).fill(null).map((x, index) => {
const id = this.index.reader.nextUShort();
const z = this.index.reader.nextSByte();

return {
id,
z
};
});

}

readLandBlock(x, y) {
const blockHeight = this.height >> 3;
let offset = ((x * blockHeight) + y) * 196 + 4;
let offset = ((x * this.chunkHeight) + y) * 196 + 4;

if (this.index.isUOP) {
offset = this.calculateOffset(offset);
Expand Down
18 changes: 11 additions & 7 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
const uodatareader = require('./index');
const uodatareader = require('./index')({
baseDirectory: './uo',
maps: [{id: 0}, {id: 1}]
});

// load map block:
const felucca = new uodatareader.Map({
baseDirectory: '../tmp/uo',
mapId: 0
});
const felucca = uodatareader.maps[0];

const area = felucca.getLandBlock(1, 1);
console.log(area);
const area = felucca.getLandBlock(~~(3615 / 8), ~~(2484 / 8));
const my = felucca.readMyMethod(3615, 2484);
console.log('ME', my, JSON.stringify(area));
// console.log('REAL', JSON.stringify([{"ID":209,"Z":0},{"ID":6,"Z":0},{"ID":5,"Z":0},{"ID":5,"Z":0},{"ID":4,"Z":0},{"ID":138,"Z":0},{"ID":119,"Z":0},{"ID":1017,"Z":0},{"ID":203,"Z":0},{"ID":3,"Z":0},{"ID":211,"Z":0},{"ID":219,"Z":0},{"ID":4,"Z":0},{"ID":137,"Z":0},{"ID":120,"Z":0},{"ID":1024,"Z":0},{"ID":214,"Z":0},{"ID":209,"Z":0},{"ID":196,"Z":0},{"ID":203,"Z":0},{"ID":3,"Z":0},{"ID":137,"Z":0},{"ID":120,"Z":0},{"ID":1024,"Z":0},{"ID":215,"Z":0},{"ID":199,"Z":0},{"ID":199,"Z":0},{"ID":214,"Z":0},{"ID":219,"Z":0},{"ID":137,"Z":0},{"ID":118,"Z":0},{"ID":1024,"Z":0},{"ID":5,"Z":0},{"ID":215,"Z":0},{"ID":199,"Z":0},{"ID":196,"Z":0},{"ID":204,"Z":0},{"ID":138,"Z":0},{"ID":118,"Z":0},{"ID":1024,"Z":0},{"ID":4,"Z":0},{"ID":3,"Z":0},{"ID":206,"Z":0},{"ID":196,"Z":0},{"ID":203,"Z":0},{"ID":138,"Z":0},{"ID":117,"Z":0},{"ID":1024,"Z":0},{"ID":4,"Z":0},{"ID":6,"Z":0},{"ID":202,"Z":0},{"ID":201,"Z":0},{"ID":216,"Z":0},{"ID":138,"Z":0},{"ID":114,"Z":0},{"ID":1024,"Z":0},{"ID":6,"Z":0},{"ID":6,"Z":0},{"ID":3,"Z":0},{"ID":217,"Z":0},{"ID":210,"Z":0},{"ID":138,"Z":0},{"ID":117,"Z":0},{"ID":1024,"Z":0}]))

/*
// load land image as sharp image:
const art = new uodatareader.Art({
baseDirectory: '../tmp/uo'
Expand All @@ -17,3 +20,4 @@ const art = new uodatareader.Art({
const image = art.loadLand(2);
image.toFile('test.png');
*/

0 comments on commit f73b51f

Please sign in to comment.