|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
class DummyPlayer extends AbstractSmrPlayer { |
|
4
|
|
|
|
|
5
|
|
|
public function __construct(string $playerName, int $experience = 1000, int $shipTypeID = 60) { |
|
6
|
|
|
$this->playerName = $playerName; |
|
7
|
|
|
$this->experience = $experience; |
|
8
|
|
|
$this->shipID = $shipTypeID; |
|
9
|
|
|
$this->setConstantProperties(); |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Sets properties that are needed for combat, but do not need to |
|
14
|
|
|
* be stored in the database. |
|
15
|
|
|
*/ |
|
16
|
|
|
protected function setConstantProperties() : void { |
|
17
|
|
|
$this->gameID = 0; |
|
18
|
|
|
$this->accountID = 0; |
|
19
|
|
|
$this->playerID = 0; |
|
20
|
|
|
$this->alignment = 0; |
|
21
|
|
|
$this->underAttack = false; |
|
22
|
|
|
$this->npc = true; |
|
23
|
|
|
$this->dead = false; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function __sleep() { |
|
27
|
|
|
return ['playerName', 'experience', 'shipID']; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function __wakeup() { |
|
31
|
|
|
$this->setConstantProperties(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function increaseHOF(float $amount, array $typeList, string $visibility) : void {} |
|
35
|
|
|
|
|
36
|
|
|
public function killPlayerByPlayer(AbstractSmrPlayer $killer) : array { |
|
37
|
|
|
$this->dead = true; |
|
38
|
|
|
return ['DeadExp' => 0, 'KillerCredits' => 0, 'KillerExp' => 0]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getShip(bool $forceUpdate = false) : AbstractSmrShip { |
|
42
|
|
|
return DummyShip::getCachedDummyShip($this); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function cacheDummyPlayer() : void { |
|
46
|
|
|
$this->getShip()->cacheDummyShip(); |
|
|
|
|
|
|
47
|
|
|
$db = Smr\Database::getInstance(); |
|
48
|
|
|
$db->query('REPLACE INTO cached_dummys ' . |
|
49
|
|
|
'(type, id, info) ' . |
|
50
|
|
|
'VALUES (\'DummyPlayer\', ' . $db->escapeString($this->getPlayerName()) . ', ' . $db->escapeObject($this) . ')'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public static function getCachedDummyPlayer(string $name) : self { |
|
54
|
|
|
$db = Smr\Database::getInstance(); |
|
55
|
|
|
$db->query('SELECT info FROM cached_dummys |
|
56
|
|
|
WHERE type = \'DummyPlayer\' |
|
57
|
|
|
AND id = ' . $db->escapeString($name) . ' LIMIT 1'); |
|
58
|
|
|
if ($db->nextRecord()) { |
|
59
|
|
|
return $db->getObject('info'); |
|
60
|
|
|
} else { |
|
61
|
|
|
return new DummyPlayer($name); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public static function getDummyPlayerNames() : array { |
|
66
|
|
|
$db = Smr\Database::getInstance(); |
|
67
|
|
|
$db->query('SELECT id FROM cached_dummys |
|
68
|
|
|
WHERE type = \'DummyPlayer\''); |
|
69
|
|
|
$dummyNames = array(); |
|
70
|
|
|
while ($db->nextRecord()) { |
|
71
|
|
|
$dummyNames[] = $db->getField('id'); |
|
72
|
|
|
} |
|
73
|
|
|
return $dummyNames; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|