Skip to content

Commit

Permalink
Map rendering chunks correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoescribano committed Jan 13, 2019
1 parent 872df2b commit 61fe93f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
2 changes: 2 additions & 0 deletions core/commands/mapdump.command.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public function __construct($client = null, $args = []) {
$player = UltimaPHP::$socketClients[$client]['account']->player;

$position = $player->position;

print_r($position);
// $position['x']--;

$viewRange = [
Expand Down
1 change: 1 addition & 0 deletions core/defs/encryption.def.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

abstract class EncryptionDefs {
const VERSION = [
'7074' => [0x3F89695D, 0xABCCA27F],
'7073' => [0x2042036D, 0xA5D1BE7F],
'7072' => [0x207B217D, 0xA5C7527F],
'7071' => [0x203CC38D, 0xA5FDFE7F],
Expand Down
19 changes: 16 additions & 3 deletions core/map.core.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Map {
public static $maps = [];
public static $mapSizes = [];
public static $chunks = [];
public static $chunkSize = 512; // Number in square
public static $chunkSize = 128; // Number in square
public static $tileMatrix = [];
public static $serialData = [];
public static $serialDataHolded = [];
Expand Down Expand Up @@ -523,7 +523,7 @@ public static function addPlayerToMap(Player $player) {
'type' => "player",
'client' => $player->client,
'instance' => null,
];
];

self::$serialData[(int) $player->serial] = ['map' => $player->position['map'], 'x' => $chunk['x'], 'y' => $chunk['y']];

Expand Down Expand Up @@ -776,12 +776,25 @@ public static function sendPacketRangePosition($packet = null, $position = null)
}
}

public static function sendEventRangePosition($map, $chunk, $event) {
foreach (self::$chunks[$map][$chunk['x']][$chunk['y']] as $serial => $data) {
if ($data['type'] == 'player') {
$method = $event['method'];
$args = $event['args'];
if (UltimaPHP::$conf['logs']['debug']) {
echo "Running event {$method}({$args}) at player " . UltimaPHP::$socketClients[$data['client']]['account']->player->name . "\n";
}
UltimaPHP::$socketClients[$data['client']]['account']->player->$method($args);
}
}
}

/**
* Update players with objects from desired chunk
* $map is only used in case of the request come from a mobile or items
*/
//self::updateChunk($chunk, false, $position['map'], true);
public static function updateChunk($chunk = null, $client = false, $map = null, $forceItemUpdate = false) {
public static function updateChunk($chunk = null, $client = false, $map = null) {
if ($chunk === null && $client !== false) {
$chunk = self::getChunk(UltimaPHP::$socketClients[$client]['account']->player->position['x'], UltimaPHP::$socketClients[$client]['account']->player->position['y']);
$map = UltimaPHP::$socketClients[$client]['account']->player->position['map'];
Expand Down
26 changes: 24 additions & 2 deletions core/player.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,8 @@ public function movePlayer($runInLot = false, $direction = false, $sequence = fa

$tmpPosition = $this->position;

$oldChunk = Map::getChunk($this->position['x'], $this->position['y']);

if ((int) $direction >= 80) {
$tmpPosition['running'] = true;
} else {
Expand Down Expand Up @@ -737,6 +739,20 @@ public function movePlayer($runInLot = false, $direction = false, $sequence = fa
$this->position = $tmpPosition;
$this->lastMove = time();

$newChunk = Map::getChunk($this->position['x'], $this->position['y']);

if ($oldChunk['x'] != $newChunk['x'] || $oldChunk['y'] != $newChunk['y']) {
if (isset(Map::$chunks[$this->position['map']][$oldChunk['x']][$oldChunk['y']][(int) $this->serial])) {
$instance = Map::$chunks[$this->position['map']][$oldChunk['x']][$oldChunk['y']][(int) $this->serial];

// Remover o player do chunk antigo (da memória)
Map::removeSerialData($this->serial);

// Adicionar o player do chunk novo (em memória, ligando o chunk no server)
Map::$chunks[$this->position['map']][$newChunk['x']][$newChunk['y']][(int) $this->serial] = $instance;
}
}

$packet = "22" . str_pad($sequence, 2, "0", STR_PAD_LEFT) . "01";
Sockets::out($this->client, $packet, false);

Expand Down Expand Up @@ -840,7 +856,7 @@ public function pickUp($serial = null, $amount = 1) {

Map::removeSerialData($serial, ($instance->holder === null ? false : true));

/* Remove the intem from the container */
/* Remove item from container */
if ($instance->holder !== null) {
$container = Map::getBySerial($instance->holder);

Expand All @@ -854,7 +870,13 @@ public function pickUp($serial = null, $amount = 1) {
}
}
} else {
$this->removeObjectFromView($serial);
//$this->removeObjectFromView($serial);
$event = [
'method' => 'removeObjectFromView',
'args' => $serial
];
Map::sendEventRangePosition($this->position['map'], Map::getChunk($this->position['x'], $this->position['y']), $event);
//Map::updateChunk(null, $this->client);
}

$this->layers[LayersDefs::DRAGGING] = $instance->serial;
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This server was created for those who ever wanted to create different adaptation

I decided to build this project for study propose I've re-scripted the entire socket server to understand how it works and after that i decided to create a lightweight standalone version of the server that runs in any OS easily.

Note: The server only works with the last updated Ultima Online client (7.0.70.10) and we will not spend time with older clients for now.
Note: The server only works with the last updated Ultima Online client (7.0.74.28) and we will not spend time with older clients for now.

## How to install?

Expand Down
2 changes: 1 addition & 1 deletion ultimaphp.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ timezone=-3
lang=pt_br
max_players=20
save_time=30*60
client=7.0.70.10,67.0.70.0
client=7.0.74.28,67.0.74.0
commandPrefix=.

[mongodb]
Expand Down

0 comments on commit 61fe93f

Please sign in to comment.