1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
class Council { |
4
|
|
|
protected static array $COUNCILS = []; |
5
|
|
|
protected static array $PRESIDENTS = []; |
6
|
|
|
protected static Smr\Database $db; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Returns an array of Account ID's of the Council for this race. |
10
|
|
|
*/ |
11
|
|
|
public static function getRaceCouncil(int $gameID, int $raceID) : array { |
12
|
|
|
if (!isset(self::$COUNCILS[$gameID][$raceID])) { |
13
|
|
|
self::$db = Smr\Database::getInstance(); |
14
|
|
|
self::$COUNCILS[$gameID][$raceID] = array(); |
15
|
|
|
self::$PRESIDENTS[$gameID][$raceID] = false; |
16
|
|
|
|
17
|
|
|
// Require council members to have > 0 exp to ensure that players |
18
|
|
|
// cannot perform council activities before the game starts. |
19
|
|
|
$i = 1; |
20
|
|
|
self::$db->query('SELECT account_id, alignment |
21
|
|
|
FROM player |
22
|
|
|
WHERE game_id = ' . self::$db->escapeNumber($gameID) . ' |
23
|
|
|
AND race_id = ' . self::$db->escapeNumber($raceID) . ' |
24
|
|
|
AND npc = \'FALSE\' |
25
|
|
|
AND experience > 0 |
26
|
|
|
ORDER by experience DESC |
27
|
|
|
LIMIT ' . MAX_COUNCIL_MEMBERS); |
28
|
|
|
while (self::$db->nextRecord()) { |
29
|
|
|
// Add this player to the council |
30
|
|
|
self::$COUNCILS[$gameID][$raceID][$i++] = self::$db->getInt('account_id'); |
31
|
|
|
|
32
|
|
|
// Determine if this player is also the president |
33
|
|
|
if (self::$PRESIDENTS[$gameID][$raceID] === false) { |
34
|
|
|
if (self::$db->getInt('alignment') >= ALIGNMENT_PRESIDENT) { |
35
|
|
|
self::$PRESIDENTS[$gameID][$raceID] = self::$db->getInt('account_id'); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
return self::$COUNCILS[$gameID][$raceID]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Returns the Account ID of the President for this race (or false if no President). |
45
|
|
|
*/ |
46
|
|
|
public static function getPresidentID(int $gameID, int $raceID) : int|false { |
47
|
|
|
self::getRaceCouncil($gameID, $raceID); // determines the president |
48
|
|
|
return self::$PRESIDENTS[$gameID][$raceID]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public static function isOnCouncil(int $gameID, int $raceID, int $accountID) : bool { |
52
|
|
|
return in_array($accountID, self::getRaceCouncil($gameID, $raceID)); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|