1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Smr\Pages\Player\Planet; |
4
|
|
|
|
5
|
|
|
use AbstractSmrPlayer; |
6
|
|
|
use Smr\Database; |
7
|
|
|
use Smr\Page\PlayerPageProcessor; |
8
|
|
|
use Smr\Request; |
9
|
|
|
|
10
|
|
|
class OwnershipProcessor extends PlayerPageProcessor { |
11
|
|
|
|
12
|
|
|
public function build(AbstractSmrPlayer $player): never { |
13
|
|
|
if (!$player->isLandedOnPlanet()) { |
14
|
|
|
create_error('You are not on a planet!'); |
15
|
|
|
} |
16
|
|
|
// get a planet from the sector where the player is in |
17
|
|
|
$planet = $player->getSectorPlanet(); |
18
|
|
|
$action = Request::get('action'); |
19
|
|
|
|
20
|
|
|
if ($action == 'Take Ownership') { |
21
|
|
|
if ($planet->hasOwner() && $planet->getPassword() != Request::get('password')) { |
22
|
|
|
create_error('You entered an incorrect password for this planet!'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
// delete all previous ownerships |
26
|
|
|
$db = Database::getInstance(); |
27
|
|
|
$db->write('UPDATE planet SET owner_id = 0, password = NULL |
28
|
|
|
WHERE owner_id = ' . $db->escapeNumber($player->getAccountID()) . ' |
29
|
|
|
AND game_id = ' . $db->escapeNumber($player->getGameID())); |
30
|
|
|
|
31
|
|
|
// set ownership |
32
|
|
|
$planet->setOwnerID($player->getAccountID()); |
33
|
|
|
$planet->removePassword(); |
34
|
|
|
$player->log(LOG_TYPE_PLANETS, 'Player takes ownership of planet.'); |
35
|
|
|
} elseif ($action == 'Rename') { |
36
|
|
|
$name = Request::get('name'); |
37
|
|
|
if (empty($name)) { |
38
|
|
|
create_error('You cannot leave your planet nameless!'); |
39
|
|
|
} |
40
|
|
|
// rename planet |
41
|
|
|
$planet->setName($name); |
42
|
|
|
$player->log(LOG_TYPE_PLANETS, 'Player renames planet to ' . $name . '.'); |
43
|
|
|
|
44
|
|
|
} elseif ($action == 'Set Password') { |
45
|
|
|
// set password |
46
|
|
|
$password = Request::get('password'); |
47
|
|
|
$planet->setPassword($password); |
48
|
|
|
$player->log(LOG_TYPE_PLANETS, 'Player sets planet password to ' . $password); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
(new Ownership())->go(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
} |
55
|
|
|
|