Calculate the Real X,Y,Z Coordinates

10/19/2019 17:09 PisqoLoq#1
Hi friends, as you know, PosX, PosY and PosZ values in the _Char table are not the same as X, Y, Z in the game.

I know that there is a calculation formula to calculate it. And I think we can do this using the X and Z values in _RefRegion.

I was able to calculate the actual X in the game using the X value in _RefRegion and the PosX value in the _Char table. However, the _RefRegion table does not have a Y coordinate.

In this case, I ask you. How can I get real X, Y, Z in the game using RegionID, PosX, PosY, PosZ in _Char table.


The formula I use for X.

Code:
        $regionX = 158; // _RefRegion.X

        $posX =  210; // _Char.PosX

        $x = ($regionX - 135) * 192 + $posX / 10; // it will give real X in the game
10/20/2019 05:58 JellyBitz#2
Only two types of coords can be handled.

- Game coords : ( Region, X, Z, Y )
- User coords : ( X, Y ) There is no Z

User coords can be used only if you are not at external map layer (caves/dungeon). As his name, it's only used by the player to know his location at the main world map.

Game coords, are used for everything. Most important, Region will specify the map layer being used.
If it's lower then short.MaxValue (32767) means that you are at the main world map, you can convert it to User coords. As example:

Game: R: 26959, X: 952, Z: 1074, Y: 83
User: PosX: -10657, PosY: 2603 (Constantinople, name given by the Region number)

How to ?
PHP Code:
byte ySector = (byte)(Region >> 8);
byte xSector = (byte)(Region 0xFF);

if (
Region short.MaxValue// At world map? convert it!
{
    
// 192px 1:10 scale, center (135,92)
    
PosX = (xSector 135) * 192 10;
    
PosY = (ySector 92) * 192 10;

The ySector, and xSector as you noticed, it's the {Y}x{X} image map from minimap files.
If the Region it's higher or equal than short.MaxValue, the conversion will be different and the scale can change, also the center will be always defined (128,128).

I'm still learning about this conversions at dungeon layers so I can't help you more than this.