We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -5,7 +5,7 @@ |
||
5 | 5 | */ |
6 | 6 | function getBounties($type) { |
7 | 7 | $db = new SmrMySqlDatabase(); |
8 | - $db->query('SELECT * FROM bounty WHERE game_id = '.$db->escapeNumber(SmrSession::getGameID()).' AND type ='.$db->escapeString($type).' AND claimer_id = 0 ORDER BY amount DESC'); |
|
8 | + $db->query('SELECT * FROM bounty WHERE game_id = ' . $db->escapeNumber(SmrSession::getGameID()) . ' AND type =' . $db->escapeString($type) . ' AND claimer_id = 0 ORDER BY amount DESC'); |
|
9 | 9 | $bounties = []; |
10 | 10 | while ($db->nextRecord()) { |
11 | 11 | $bounties[] = [ |
@@ -12,12 +12,12 @@ discard block |
||
12 | 12 | |
13 | 13 | |
14 | 14 | protected static function initialiseDatabase() { |
15 | - if(self::$db==null) |
|
15 | + if (self::$db == null) |
|
16 | 16 | self::$db = new SmrMySqlDatabase(); |
17 | 17 | } |
18 | 18 | |
19 | - public static function &getWeapon($weaponTypeID, $forceUpdate=false, $db=null) { |
|
20 | - if($forceUpdate || !isset(self::$CACHE_WEAPONS[$weaponTypeID])) { |
|
19 | + public static function &getWeapon($weaponTypeID, $forceUpdate = false, $db = null) { |
|
20 | + if ($forceUpdate || !isset(self::$CACHE_WEAPONS[$weaponTypeID])) { |
|
21 | 21 | $w = new SmrWeapon($weaponTypeID, $db); |
22 | 22 | if ($w->exists()) |
23 | 23 | self::$CACHE_WEAPONS[$weaponTypeID] = $w; |
@@ -27,17 +27,17 @@ discard block |
||
27 | 27 | return self::$CACHE_WEAPONS[$weaponTypeID]; |
28 | 28 | } |
29 | 29 | |
30 | - public static function &getAllWeapons($forceUpdate=false) { |
|
30 | + public static function &getAllWeapons($forceUpdate = false) { |
|
31 | 31 | $db = new SmrMySqlDatabase(); |
32 | 32 | $db->query('SELECT * FROM weapon_type'); |
33 | - $weapons=array(); |
|
34 | - while($db->nextRecord()) { |
|
33 | + $weapons = array(); |
|
34 | + while ($db->nextRecord()) { |
|
35 | 35 | $weapons[] = self::getWeapon($db->getInt('weapon_type_id'), $forceUpdate, $db); |
36 | 36 | } |
37 | 37 | return $weapons; |
38 | 38 | } |
39 | 39 | |
40 | - protected function __construct($weaponTypeID, $db=null) { |
|
40 | + protected function __construct($weaponTypeID, $db = null) { |
|
41 | 41 | |
42 | 42 | $this->weaponTypeID = $weaponTypeID; |
43 | 43 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $this->buyerRestriction = $db->getInt('buyer_restriction'); |
62 | 62 | $this->damageRollover = false; |
63 | 63 | $this->raidWeapon = false; |
64 | - $this->maxDamage = max($this->shieldDamage,$this->armourDamage); |
|
64 | + $this->maxDamage = max($this->shieldDamage, $this->armourDamage); |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | } |
102 | 102 | |
103 | 103 | protected function &getWeightedRandomForPlayer(AbstractSmrPlayer $player) { |
104 | - return WeightedRandom::getWeightedRandomForPlayer($player,'Weapon',$this->getWeaponTypeID()); |
|
104 | + return WeightedRandom::getWeightedRandomForPlayer($player, 'Weapon', $this->getWeaponTypeID()); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | protected function checkMiss(AbstractSmrPlayer $player, $percent) { |
@@ -109,14 +109,14 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | public static function getPlayerLevelAccuracyMod(AbstractSmrPlayer $player) { |
112 | - return ($player->getLevelID()*$player->getLevelID()/60+$player->getLevelID()/2+2) / 100; |
|
112 | + return ($player->getLevelID() * $player->getLevelID() / 60 + $player->getLevelID() / 2 + 2) / 100; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | public function getModifiedAccuracy(AbstractSmrPlayer $weaponPlayer) { |
116 | 116 | $modifiedAccuracy = $this->getBaseAccuracy(); |
117 | 117 | $modifiedAccuracy += $this->getBaseAccuracy() * self::getPlayerLevelAccuracyMod($weaponPlayer); |
118 | 118 | if ($weaponPlayer->isGadgetEquipped('Increased Accuracy')) |
119 | - $modifiedAccuracy += $this->getBaseAccuracy() * INCREASED_ACC_GADGET_FACTOR/100; |
|
119 | + $modifiedAccuracy += $this->getBaseAccuracy() * INCREASED_ACC_GADGET_FACTOR / 100; |
|
120 | 120 | return $modifiedAccuracy; |
121 | 121 | } |
122 | 122 | |
@@ -127,13 +127,13 @@ discard block |
||
127 | 127 | |
128 | 128 | public function getModifiedAccuracyAgainstPort(AbstractSmrPlayer $weaponPlayer, SmrPort $port) { |
129 | 129 | $modifiedAccuracy = $this->getModifiedAccuracy($weaponPlayer); |
130 | - $modifiedAccuracy -= $this->getBaseAccuracy() * $port->getLevel()/50; |
|
130 | + $modifiedAccuracy -= $this->getBaseAccuracy() * $port->getLevel() / 50; |
|
131 | 131 | return $modifiedAccuracy; |
132 | 132 | } |
133 | 133 | |
134 | 134 | public function getModifiedAccuracyAgainstPlanet(AbstractSmrPlayer $weaponPlayer, SmrPlanet $planet) { |
135 | 135 | $modifiedAccuracy = $this->getModifiedAccuracy($weaponPlayer); |
136 | - $modifiedAccuracy -= $this->getBaseAccuracy() * $planet->getLevel()/350; |
|
136 | + $modifiedAccuracy -= $this->getBaseAccuracy() * $planet->getLevel() / 350; |
|
137 | 137 | return $modifiedAccuracy; |
138 | 138 | } |
139 | 139 | |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | $modifiedAccuracy = $this->getModifiedAccuracy($weaponPlayer); |
142 | 142 | $modifiedAccuracy -= $this->getBaseAccuracy() * self::getPlayerLevelAccuracyMod($targetPlayer) / 2; |
143 | 143 | if ($targetPlayer->isGadgetEquipped('Increased Maneuverability')) |
144 | - $modifiedAccuracy -= $this->getBaseAccuracy() * INCREASED_MAN_GADGET_FACTOR/100; |
|
144 | + $modifiedAccuracy -= $this->getBaseAccuracy() * INCREASED_MAN_GADGET_FACTOR / 100; |
|
145 | 145 | |
146 | 146 | $weaponShip = $weaponPlayer->getShip(); |
147 | 147 | $targetShip = $targetPlayer->getShip(); |
148 | 148 | $mrDiff = $targetShip->getMR() - $weaponShip->getMR(); |
149 | - if($mrDiff > 0) |
|
150 | - $modifiedAccuracy -= $this->getBaseAccuracy() * ($mrDiff/MR_FACTOR)/100; |
|
149 | + if ($mrDiff > 0) |
|
150 | + $modifiedAccuracy -= $this->getBaseAccuracy() * ($mrDiff / MR_FACTOR) / 100; |
|
151 | 151 | |
152 | 152 | return $modifiedAccuracy; |
153 | 153 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | public function &getModifiedDamage(AbstractSmrPlayer $weaponPlayer) { |
183 | 183 | $damage = $this->getDamage(); |
184 | 184 | //do they have the weapon damage gadget? |
185 | - if($weaponPlayer->isGadgetEquipped('Increased Weapon Damage')) { |
|
185 | + if ($weaponPlayer->isGadgetEquipped('Increased Weapon Damage')) { |
|
186 | 186 | $damage['MaxDamage'] += $this->getMaxDamage() * INCREASED_DAMAGE_GADGET_FACTOR; |
187 | 187 | $damage['Shield'] += $this->getShieldDamage() * INCREASED_DAMAGE_GADGET_FACTOR; |
188 | 188 | $damage['Armour'] += $this->getArmourDamage() * INCREASED_DAMAGE_GADGET_FACTOR; |
@@ -191,23 +191,23 @@ discard block |
||
191 | 191 | } |
192 | 192 | |
193 | 193 | public function &getModifiedDamageAgainstForces(AbstractSmrPlayer $weaponPlayer, SmrForce $forces) { |
194 | - if(!$this->canShootForces()) // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
|
194 | + if (!$this->canShootForces()) // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
|
195 | 195 | return array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()); |
196 | - $damage =& $this->getModifiedDamage($weaponPlayer); |
|
196 | + $damage = & $this->getModifiedDamage($weaponPlayer); |
|
197 | 197 | return $damage; |
198 | 198 | } |
199 | 199 | |
200 | 200 | public function &getModifiedDamageAgainstPort(AbstractSmrPlayer $weaponPlayer, SmrPort $port) { |
201 | - if(!$this->canShootPorts()) // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
|
201 | + if (!$this->canShootPorts()) // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
|
202 | 202 | return array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()); |
203 | - $damage =& $this->getModifiedDamage($weaponPlayer); |
|
203 | + $damage = & $this->getModifiedDamage($weaponPlayer); |
|
204 | 204 | return $damage; |
205 | 205 | } |
206 | 206 | |
207 | 207 | public function &getModifiedDamageAgainstPlanet(AbstractSmrPlayer $weaponPlayer, SmrPlanet $planet) { |
208 | - if(!$this->canShootPlanets()) // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
|
208 | + if (!$this->canShootPlanets()) // If we can't shoot forces then just return a damageless array and don't waste resources calculated any damage mods. |
|
209 | 209 | return array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()); |
210 | - $damage =& $this->getModifiedDamage($weaponPlayer); |
|
210 | + $damage = & $this->getModifiedDamage($weaponPlayer); |
|
211 | 211 | |
212 | 212 | $planetMod = self::PLANET_DAMAGE_MOD; |
213 | 213 | $damage['MaxDamage'] = ceil($damage['MaxDamage'] * $planetMod); |
@@ -223,16 +223,16 @@ discard block |
||
223 | 223 | } |
224 | 224 | |
225 | 225 | public function &getModifiedDamageAgainstPlayer(AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer) { |
226 | - if(!$this->canShootTraders()) { // If we can't shoot traders then just return a damageless array and don't waste resources calculating any damage mods. |
|
226 | + if (!$this->canShootTraders()) { // If we can't shoot traders then just return a damageless array and don't waste resources calculating any damage mods. |
|
227 | 227 | $return = array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()); |
228 | 228 | return $return; |
229 | 229 | } |
230 | - $damage =& $this->getModifiedDamage($weaponPlayer); |
|
230 | + $damage = & $this->getModifiedDamage($weaponPlayer); |
|
231 | 231 | return $damage; |
232 | 232 | } |
233 | 233 | |
234 | 234 | public function &getModifiedPortDamageAgainstPlayer(SmrPort $port, AbstractSmrPlayer $targetPlayer) { |
235 | - if(!$this->canShootTraders()) { // If we can't shoot traders then just return a damageless array and don't waste resources calculating any damage mods. |
|
235 | + if (!$this->canShootTraders()) { // If we can't shoot traders then just return a damageless array and don't waste resources calculating any damage mods. |
|
236 | 236 | $return = array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()); |
237 | 237 | return $return; |
238 | 238 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | } |
242 | 242 | |
243 | 243 | public function &getModifiedPlanetDamageAgainstPlayer(SmrPlanet $planet, AbstractSmrPlayer $targetPlayer) { |
244 | - if(!$this->canShootTraders()) { // If we can't shoot traders then just return a damageless array and don't waste resources calculating any damage mods. |
|
244 | + if (!$this->canShootTraders()) { // If we can't shoot traders then just return a damageless array and don't waste resources calculating any damage mods. |
|
245 | 245 | $return = array('MaxDamage' => 0, 'Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()); |
246 | 246 | return $return; |
247 | 247 | } |
@@ -251,42 +251,42 @@ discard block |
||
251 | 251 | |
252 | 252 | public function &shootForces(AbstractSmrPlayer $weaponPlayer, SmrForce $forces) { |
253 | 253 | $return = array('Weapon' => $this, 'TargetForces' => $forces); |
254 | - if($this->checkMiss($weaponPlayer, $this->getModifiedAccuracyAgainstForces($weaponPlayer,$forces))) { //Check if we miss |
|
254 | + if ($this->checkMiss($weaponPlayer, $this->getModifiedAccuracyAgainstForces($weaponPlayer, $forces))) { //Check if we miss |
|
255 | 255 | $return['Hit'] = false; |
256 | 256 | return $return; |
257 | 257 | } |
258 | 258 | $return['Hit'] = true; |
259 | - return $this->doPlayerDamageToForce($return,$weaponPlayer, $forces); |
|
259 | + return $this->doPlayerDamageToForce($return, $weaponPlayer, $forces); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | public function &shootPort(AbstractSmrPlayer $weaponPlayer, SmrPort $port) { |
263 | 263 | $return = array('Weapon' => $this, 'TargetPort' => $port); |
264 | - if($this->checkMiss($weaponPlayer, $this->getModifiedAccuracyAgainstPort($weaponPlayer,$port))) { //Check if we miss |
|
264 | + if ($this->checkMiss($weaponPlayer, $this->getModifiedAccuracyAgainstPort($weaponPlayer, $port))) { //Check if we miss |
|
265 | 265 | $return['Hit'] = false; |
266 | 266 | return $return; |
267 | 267 | } |
268 | 268 | $return['Hit'] = true; |
269 | - return $this->doPlayerDamageToPort($return,$weaponPlayer, $port); |
|
269 | + return $this->doPlayerDamageToPort($return, $weaponPlayer, $port); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | public function &shootPlanet(AbstractSmrPlayer $weaponPlayer, SmrPlanet $planet, $delayed) { |
273 | 273 | $return = array('Weapon' => $this, 'TargetPlanet' => $planet); |
274 | - if($this->checkMiss($weaponPlayer, $this->getModifiedAccuracyAgainstPlanet($weaponPlayer,$planet))) { //Check if we miss |
|
274 | + if ($this->checkMiss($weaponPlayer, $this->getModifiedAccuracyAgainstPlanet($weaponPlayer, $planet))) { //Check if we miss |
|
275 | 275 | $return['Hit'] = false; |
276 | 276 | return $return; |
277 | 277 | } |
278 | 278 | $return['Hit'] = true; |
279 | - return $this->doPlayerDamageToPlanet($return,$weaponPlayer, $planet, $delayed); |
|
279 | + return $this->doPlayerDamageToPlanet($return, $weaponPlayer, $planet, $delayed); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | public function &shootPlayer(AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer) { |
283 | 283 | $return = array('Weapon' => $this, 'TargetPlayer' => $targetPlayer); |
284 | - if($this->checkMiss($weaponPlayer, $this->getModifiedAccuracyAgainstPlayer($weaponPlayer,$targetPlayer))) { //Check if we miss |
|
284 | + if ($this->checkMiss($weaponPlayer, $this->getModifiedAccuracyAgainstPlayer($weaponPlayer, $targetPlayer))) { //Check if we miss |
|
285 | 285 | $return['Hit'] = false; |
286 | 286 | return $return; |
287 | 287 | } |
288 | 288 | $return['Hit'] = true; |
289 | - return $this->doPlayerDamageToPlayer($return,$weaponPlayer, $targetPlayer); |
|
289 | + return $this->doPlayerDamageToPlayer($return, $weaponPlayer, $targetPlayer); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | public function &shootPlayerAsForce(SmrForce $forces, AbstractSmrPlayer $targetPlayer) { |
@@ -296,22 +296,22 @@ discard block |
||
296 | 296 | |
297 | 297 | public function &shootPlayerAsPort(SmrPort $port, AbstractSmrPlayer $targetPlayer) { |
298 | 298 | $return = array('Weapon' => $this, 'TargetPlayer' => $targetPlayer); |
299 | - if($this->checkMiss($targetPlayer, $this->getModifiedPortAccuracyAgainstPlayer($port,$targetPlayer))) { //Check if the port misses, weight based upon the player being shot at. |
|
299 | + if ($this->checkMiss($targetPlayer, $this->getModifiedPortAccuracyAgainstPlayer($port, $targetPlayer))) { //Check if the port misses, weight based upon the player being shot at. |
|
300 | 300 | $return['Hit'] = false; |
301 | 301 | return $return; |
302 | 302 | } |
303 | 303 | $return['Hit'] = true; |
304 | - return $this->doPortDamageToPlayer($return,$port, $targetPlayer); |
|
304 | + return $this->doPortDamageToPlayer($return, $port, $targetPlayer); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | public function &shootPlayerAsPlanet(SmrPlanet $planet, AbstractSmrPlayer $targetPlayer) { |
308 | 308 | $return = array('Weapon' => $this, 'TargetPlayer' => $targetPlayer); |
309 | - if($this->checkMiss($targetPlayer, $this->getModifiedPlanetAccuracyAgainstPlayer($planet,$targetPlayer))) { //Check if the planet misses, weight based upon the player being shot at. |
|
309 | + if ($this->checkMiss($targetPlayer, $this->getModifiedPlanetAccuracyAgainstPlayer($planet, $targetPlayer))) { //Check if the planet misses, weight based upon the player being shot at. |
|
310 | 310 | $return['Hit'] = false; |
311 | 311 | return $return; |
312 | 312 | } |
313 | 313 | $return['Hit'] = true; |
314 | - return $this->doPlanetDamageToPlayer($return,$planet, $targetPlayer); |
|
314 | + return $this->doPlanetDamageToPlayer($return, $planet, $targetPlayer); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | } |
@@ -52,13 +52,13 @@ discard block |
||
52 | 52 | |
53 | 53 | protected $SQL; |
54 | 54 | |
55 | - protected $hasChanged=false; |
|
56 | - protected $isNew=false; |
|
55 | + protected $hasChanged = false; |
|
56 | + protected $isNew = false; |
|
57 | 57 | |
58 | 58 | public static function refreshCache() { |
59 | - foreach(self::$CACHE_PORTS as $gameID => &$gamePorts) { |
|
60 | - foreach($gamePorts as $sectorID => &$port) { |
|
61 | - $port = self::getPort($gameID,$sectorID,true); |
|
59 | + foreach (self::$CACHE_PORTS as $gameID => &$gamePorts) { |
|
60 | + foreach ($gamePorts as $sectorID => &$port) { |
|
61 | + $port = self::getPort($gameID, $sectorID, true); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | } |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | self::$CACHE_CACHED_PORTS = array(); |
69 | 69 | } |
70 | 70 | |
71 | - public static function &getPort($gameID, $sectorID, $forceUpdate=false, $db=null) { |
|
72 | - if($forceUpdate || !isset(self::$CACHE_PORTS[$gameID][$sectorID])) { |
|
71 | + public static function &getPort($gameID, $sectorID, $forceUpdate = false, $db = null) { |
|
72 | + if ($forceUpdate || !isset(self::$CACHE_PORTS[$gameID][$sectorID])) { |
|
73 | 73 | self::$CACHE_PORTS[$gameID][$sectorID] = new SmrPort($gameID, $sectorID, $db); |
74 | 74 | } |
75 | 75 | return self::$CACHE_PORTS[$gameID][$sectorID]; |
76 | 76 | } |
77 | 77 | |
78 | - public static function removePort($gameID,$sectorID) { |
|
78 | + public static function removePort($gameID, $sectorID) { |
|
79 | 79 | $db = new SmrMySqlDatabase(); |
80 | 80 | $SQL = 'game_id = ' . $db->escapeNumber($gameID) . ' |
81 | 81 | AND sector_id = ' . $db->escapeNumber($sectorID); |
@@ -87,17 +87,17 @@ discard block |
||
87 | 87 | unset(self::$CACHE_PORTS[$gameID][$sectorID]); |
88 | 88 | } |
89 | 89 | |
90 | - public static function &createPort($gameID,$sectorID) { |
|
91 | - if(!isset(self::$CACHE_PORTS[$gameID][$sectorID])) { |
|
92 | - $p = new SmrPort($gameID,$sectorID); |
|
90 | + public static function &createPort($gameID, $sectorID) { |
|
91 | + if (!isset(self::$CACHE_PORTS[$gameID][$sectorID])) { |
|
92 | + $p = new SmrPort($gameID, $sectorID); |
|
93 | 93 | self::$CACHE_PORTS[$gameID][$sectorID] = $p; |
94 | 94 | } |
95 | 95 | return self::$CACHE_PORTS[$gameID][$sectorID]; |
96 | 96 | } |
97 | 97 | |
98 | 98 | public static function savePorts() { |
99 | - foreach(self::$CACHE_PORTS as $gamePorts) { |
|
100 | - foreach($gamePorts as $port) { |
|
99 | + foreach (self::$CACHE_PORTS as $gamePorts) { |
|
100 | + foreach ($gamePorts as $port) { |
|
101 | 101 | $port->update(); |
102 | 102 | } |
103 | 103 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | return ($cargo / 13) * $distance; |
108 | 108 | } |
109 | 109 | |
110 | - protected function __construct($gameID, $sectorID, $db=null) { |
|
110 | + protected function __construct($gameID, $sectorID, $db = null) { |
|
111 | 111 | $this->db = new SmrMySqlDatabase(); |
112 | 112 | $this->SQL = 'sector_id = ' . $this->db->escapeNumber($sectorID) . ' AND game_id = ' . $this->db->escapeNumber($gameID); |
113 | 113 | |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | $this->isNew = !$db->nextRecord(); |
120 | 120 | } |
121 | 121 | |
122 | - $this->gameID = (int) $gameID; |
|
123 | - $this->sectorID = (int) $sectorID; |
|
122 | + $this->gameID = (int)$gameID; |
|
123 | + $this->sectorID = (int)$sectorID; |
|
124 | 124 | if (!$this->isNew) { |
125 | 125 | $this->shields = $db->getInt('shields'); |
126 | 126 | $this->combatDrones = $db->getInt('combat_drones'); |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | } |
153 | 153 | |
154 | 154 | public function checkDefenses() { |
155 | - if(!$this->isUnderAttack()) { |
|
155 | + if (!$this->isUnderAttack()) { |
|
156 | 156 | $defences = self::BASE_DEFENCES + $this->getLevel() * self::DEFENCES_PER_LEVEL; |
157 | 157 | $cds = self::BASE_CDS + $this->getLevel() * self::CDS_PER_LEVEL; |
158 | 158 | // Upgrade modifier |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | $defences += max(0, round(self::DEFENCES_PER_TEN_MIL_CREDITS * $this->getCredits() / 10000000)); |
163 | 163 | $cds += max(0, round(self::CDS_PER_TEN_MIL_CREDITS * $this->getCredits() / 10000000)); |
164 | 164 | // Defences restock (check for fed arrival) |
165 | - if(TIME < $this->getReinforceTime() + self::TIME_FEDS_STAY) { |
|
165 | + if (TIME < $this->getReinforceTime() + self::TIME_FEDS_STAY) { |
|
166 | 166 | $federalMod = (self::TIME_FEDS_STAY - (TIME - $this->getReinforceTime())) / self::TIME_FEDS_STAY; |
167 | 167 | $federalMod = max(0, round($federalMod * self::MAX_FEDS_BONUS)); |
168 | 168 | $defences += $federalMod; |
@@ -171,10 +171,10 @@ discard block |
||
171 | 171 | $this->setShields($defences); |
172 | 172 | $this->setArmour($defences); |
173 | 173 | $this->setCDs($cds); |
174 | - if($this->getCredits() == 0) { |
|
174 | + if ($this->getCredits() == 0) { |
|
175 | 175 | $this->setCreditsToDefault(); |
176 | 176 | } |
177 | - $this->db->query('DELETE FROM player_attacks_port WHERE '.$this->SQL); |
|
177 | + $this->db->query('DELETE FROM player_attacks_port WHERE ' . $this->SQL); |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | // that affect the stock. This avoids many unnecessary db queries. |
198 | 198 | $doUpdateDB = false; |
199 | 199 | $amount = $this->getGoodAmount($goodID); |
200 | - $this->setGoodAmount($goodID, $amount+$amountToAdd, $doUpdateDB); |
|
200 | + $this->setGoodAmount($goodID, $amount + $amountToAdd, $doUpdateDB); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | // Sets the class members that identify port trade goods |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | - private function getVisibleGoods($transaction, AbstractSmrPlayer $player=null) { |
|
223 | + private function getVisibleGoods($transaction, AbstractSmrPlayer $player = null) { |
|
224 | 224 | $goodIDs = $this->goodIDs[$transaction]; |
225 | 225 | if ($player == null) { |
226 | 226 | return $goodIDs; |
@@ -236,14 +236,14 @@ discard block |
||
236 | 236 | /** |
237 | 237 | * Get IDs of goods that can be sold by $player to the port |
238 | 238 | */ |
239 | - public function getVisibleGoodsSold(AbstractSmrPlayer $player=null) { |
|
239 | + public function getVisibleGoodsSold(AbstractSmrPlayer $player = null) { |
|
240 | 240 | return $this->getVisibleGoods('Sell', $player); |
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
244 | 244 | * Get IDs of goods that can be bought by $player from the port |
245 | 245 | */ |
246 | - public function getVisibleGoodsBought(AbstractSmrPlayer $player=null) { |
|
246 | + public function getVisibleGoodsBought(AbstractSmrPlayer $player = null) { |
|
247 | 247 | return $this->getVisibleGoods('Buy', $player); |
248 | 248 | } |
249 | 249 | |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | $x['TransactionType'] = 'Buy'; |
287 | 287 | } |
288 | 288 | $di = Plotter::findDistanceToX($x, $this->getSector(), true); |
289 | - if(is_object($di)) |
|
289 | + if (is_object($di)) |
|
290 | 290 | $di = $di->getRelativeDistance(); |
291 | 291 | $this->goodDistances[$goodID] = max(1, $di); |
292 | 292 | } |
@@ -305,19 +305,19 @@ discard block |
||
305 | 305 | } |
306 | 306 | } |
307 | 307 | |
308 | - public function hasGood($goodID,$type=false) { |
|
308 | + public function hasGood($goodID, $type = false) { |
|
309 | 309 | if ($type === false) { |
310 | 310 | $type = 'All'; |
311 | 311 | } |
312 | 312 | return in_array($goodID, $this->goodIDs[$type]); |
313 | 313 | } |
314 | 314 | |
315 | - private function setGoodAmount($goodID, $amount, $doUpdate=true) { |
|
316 | - if($this->isCachedVersion()) |
|
315 | + private function setGoodAmount($goodID, $amount, $doUpdate = true) { |
|
316 | + if ($this->isCachedVersion()) |
|
317 | 317 | throw new Exception('Cannot update a cached port!'); |
318 | 318 | // The new amount must be between 0 and the max for this good |
319 | 319 | $amount = max(0, min($amount, $this->getGood($goodID)['Max'])); |
320 | - if($this->getGoodAmount($goodID) == $amount) |
|
320 | + if ($this->getGoodAmount($goodID) == $amount) |
|
321 | 321 | return; |
322 | 322 | $this->goodAmounts[$goodID] = $amount; |
323 | 323 | |
@@ -331,29 +331,29 @@ discard block |
||
331 | 331 | return $this->goodAmounts[$goodID]; |
332 | 332 | } |
333 | 333 | |
334 | - public function decreaseGood(array $good,$amount,$doRefresh) { |
|
335 | - $this->setGoodAmount($good['ID'],$this->getGoodAmount($good['ID']) - $amount); |
|
336 | - if($doRefresh===true) { |
|
334 | + public function decreaseGood(array $good, $amount, $doRefresh) { |
|
335 | + $this->setGoodAmount($good['ID'], $this->getGoodAmount($good['ID']) - $amount); |
|
336 | + if ($doRefresh === true) { |
|
337 | 337 | //get id of goods to replenish |
338 | - $this->refreshGoods($good['Class'],$amount); |
|
338 | + $this->refreshGoods($good['Class'], $amount); |
|
339 | 339 | } |
340 | 340 | } |
341 | 341 | |
342 | - public function increaseGoodAmount($goodID,$amount) { |
|
343 | - $this->setGoodAmount($goodID,$this->getGoodAmount($goodID) + $amount); |
|
342 | + public function increaseGoodAmount($goodID, $amount) { |
|
343 | + $this->setGoodAmount($goodID, $this->getGoodAmount($goodID) + $amount); |
|
344 | 344 | } |
345 | 345 | |
346 | - public function decreaseGoodAmount($goodID,$amount) { |
|
347 | - $this->setGoodAmount($goodID,$this->getGoodAmount($goodID) - $amount); |
|
346 | + public function decreaseGoodAmount($goodID, $amount) { |
|
347 | + $this->setGoodAmount($goodID, $this->getGoodAmount($goodID) - $amount); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
351 | 351 | * Adds extra stock to goods in the tier above a good that was traded |
352 | 352 | */ |
353 | - protected function refreshGoods($classTraded,$amountTraded) { |
|
353 | + protected function refreshGoods($classTraded, $amountTraded) { |
|
354 | 354 | $refreshAmount = round($amountTraded * self::REFRESH_PER_GOOD); |
355 | 355 | //refresh goods that need it |
356 | - $refreshClass = $classTraded+1; |
|
356 | + $refreshClass = $classTraded + 1; |
|
357 | 357 | foreach ($this->getAllGoodIDs() as $goodID) { |
358 | 358 | $goodClass = Globals::getGood($goodID)['Class']; |
359 | 359 | if ($goodClass == $refreshClass) { |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | $this->increaseUpgrade($goodsTradedMoney); |
368 | 368 | $this->increaseCredits($goodsTradedMoney); |
369 | 369 | $this->increaseExperience($exp); |
370 | - $this->decreaseGood($good,$goodsTraded,true); |
|
370 | + $this->decreaseGood($good, $goodsTraded, true); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | public function buyGoods(array $good, $goodsTraded, $idealPrice, $bargainPrice, $exp) { |
@@ -381,10 +381,10 @@ discard block |
||
381 | 381 | } |
382 | 382 | |
383 | 383 | public function checkForUpgrade() { |
384 | - if($this->isCachedVersion()) |
|
384 | + if ($this->isCachedVersion()) |
|
385 | 385 | throw new Exception('Cannot upgrade a cached port!'); |
386 | 386 | $upgrades = 0; |
387 | - while($this->upgrade >= $this->getUpgradeRequirement() && $this->level < 9) { |
|
387 | + while ($this->upgrade >= $this->getUpgradeRequirement() && $this->level < 9) { |
|
388 | 388 | ++$upgrades; |
389 | 389 | $this->decreaseUpgrade($this->getUpgradeRequirement()); |
390 | 390 | $this->decreaseCredits($this->getUpgradeRequirement()); |
@@ -398,12 +398,12 @@ discard block |
||
398 | 398 | * ports to a specific level. |
399 | 399 | */ |
400 | 400 | public function upgradeToLevel($level) { |
401 | - if($this->isCachedVersion()) |
|
401 | + if ($this->isCachedVersion()) |
|
402 | 402 | throw new Exception('Cannot upgrade a cached port!'); |
403 | - while($this->getLevel()<$level) { |
|
403 | + while ($this->getLevel() < $level) { |
|
404 | 404 | $this->doUpgrade(); |
405 | 405 | } |
406 | - while($this->getLevel()>$level) { |
|
406 | + while ($this->getLevel() > $level) { |
|
407 | 407 | $this->doDowngrade(); |
408 | 408 | } |
409 | 409 | } |
@@ -412,20 +412,20 @@ discard block |
||
412 | 412 | $GOODS = Globals::getGoods(); |
413 | 413 | shuffle($GOODS); |
414 | 414 | do { |
415 | - if(count($GOODS) == 0) return false; |
|
415 | + if (count($GOODS) == 0) return false; |
|
416 | 416 | $newGood = array_shift($GOODS); |
417 | - } while( $this->hasGood($newGood['ID']) || $newGood['Class'] != $goodClass ); |
|
417 | + } while ($this->hasGood($newGood['ID']) || $newGood['Class'] != $goodClass); |
|
418 | 418 | |
419 | - $transactionType = mt_rand(1,2) == 1 ? 'Buy' : 'Sell'; |
|
420 | - $this->addPortGood($newGood['ID'],$transactionType); |
|
419 | + $transactionType = mt_rand(1, 2) == 1 ? 'Buy' : 'Sell'; |
|
420 | + $this->addPortGood($newGood['ID'], $transactionType); |
|
421 | 421 | return $newGood; |
422 | 422 | } |
423 | 423 | |
424 | 424 | protected function doUpgrade() { |
425 | - switch($this->getLevel()) { |
|
425 | + switch ($this->getLevel()) { |
|
426 | 426 | case 0: |
427 | - for($i=0;$i<3;++$i) { // Add 3 goods for upgrading to level 1 |
|
428 | - if( $this->selectAndAddGood(1) === false ) break; |
|
427 | + for ($i = 0; $i < 3; ++$i) { // Add 3 goods for upgrading to level 1 |
|
428 | + if ($this->selectAndAddGood(1) === false) break; |
|
429 | 429 | } |
430 | 430 | break; |
431 | 431 | |
@@ -463,10 +463,10 @@ discard block |
||
463 | 463 | * NOTE: make sure to adjust the port level appropriately if |
464 | 464 | * calling this function directly. |
465 | 465 | */ |
466 | - public function addPortGood($goodID,$type) { |
|
467 | - if($this->isCachedVersion()) |
|
466 | + public function addPortGood($goodID, $type) { |
|
467 | + if ($this->isCachedVersion()) |
|
468 | 468 | throw new Exception('Cannot update a cached port!'); |
469 | - if(!is_numeric($goodID)) |
|
469 | + if (!is_numeric($goodID)) |
|
470 | 470 | return false; |
471 | 471 | $this->goodIDs['All'][] = $goodID; |
472 | 472 | $this->goodIDs[$type][] = $goodID; |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | $this->goodAmounts[$goodID] = Globals::getGood($goodID)['Max']; |
478 | 478 | $this->cacheIsValid = false; |
479 | 479 | $this->db->query('REPLACE INTO port_has_goods (game_id, sector_id, good_id, transaction_type, amount, last_update) VALUES (' . $this->db->escapeNumber($this->getGameID()) . ',' . $this->db->escapeNumber($this->getSectorID()) . ',' . $this->db->escapeNumber($goodID) . ',' . $this->db->escapeString($type) . ',' . $this->db->escapeNumber($this->getGoodAmount($goodID)) . ',' . $this->db->escapeNumber(TIME) . ')'); |
480 | - $this->db->query('DELETE FROM route_cache WHERE game_id='.$this->db->escapeNumber($this->getGameID())); |
|
480 | + $this->db->query('DELETE FROM route_cache WHERE game_id=' . $this->db->escapeNumber($this->getGameID())); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | * calling this function directly. |
487 | 487 | */ |
488 | 488 | public function removePortGood($goodID) { |
489 | - if($this->isCachedVersion()) |
|
489 | + if ($this->isCachedVersion()) |
|
490 | 490 | throw new Exception('Cannot update a cached port!'); |
491 | 491 | if (($key = array_search($goodID, $this->goodIDs['All'])) !== false) { |
492 | 492 | array_splice($this->goodIDs['All'], $key, 1); |
@@ -499,14 +499,14 @@ discard block |
||
499 | 499 | } |
500 | 500 | |
501 | 501 | $this->cacheIsValid = false; |
502 | - $this->db->query('DELETE FROM port_has_goods WHERE '.$this->SQL.' AND good_id=' . $this->db->escapeNumber($goodID) . ';'); |
|
503 | - $this->db->query('DELETE FROM route_cache WHERE game_id='.$this->db->escapeNumber($this->getGameID())); |
|
502 | + $this->db->query('DELETE FROM port_has_goods WHERE ' . $this->SQL . ' AND good_id=' . $this->db->escapeNumber($goodID) . ';'); |
|
503 | + $this->db->query('DELETE FROM route_cache WHERE game_id=' . $this->db->escapeNumber($this->getGameID())); |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | public function checkForDowngrade($damageDone) { |
507 | 507 | $downgrades = 0; |
508 | - for(;$damageDone>self::DAMAGE_NEEDED_FOR_DOWNGRADE_CHANCE;$damageDone-=self::DAMAGE_NEEDED_FOR_DOWNGRADE_CHANCE) { |
|
509 | - if (mt_rand(1,100) <= self::CHANCE_TO_DOWNGRADE && $this->level > 1) { |
|
508 | + for (;$damageDone > self::DAMAGE_NEEDED_FOR_DOWNGRADE_CHANCE; $damageDone -= self::DAMAGE_NEEDED_FOR_DOWNGRADE_CHANCE) { |
|
509 | + if (mt_rand(1, 100) <= self::CHANCE_TO_DOWNGRADE && $this->level > 1) { |
|
510 | 510 | ++$downgrades; |
511 | 511 | $this->doDowngrade(); |
512 | 512 | } |
@@ -530,10 +530,10 @@ discard block |
||
530 | 530 | } |
531 | 531 | |
532 | 532 | protected function doDowngrade() { |
533 | - if($this->isCachedVersion()) |
|
533 | + if ($this->isCachedVersion()) |
|
534 | 534 | throw new Exception('Cannot downgrade a cached port!'); |
535 | 535 | |
536 | - switch($this->level) { |
|
536 | + switch ($this->level) { |
|
537 | 537 | case 1: |
538 | 538 | // Replace one class 1 good with another |
539 | 539 | $this->selectAndRemoveGood(1); |
@@ -572,12 +572,12 @@ discard block |
||
572 | 572 | } |
573 | 573 | |
574 | 574 | public function attackedBy(AbstractSmrPlayer $trigger, array $attackers) { |
575 | - if($this->isCachedVersion()) |
|
575 | + if ($this->isCachedVersion()) |
|
576 | 576 | throw new Exception('Cannot attack a cached port!'); |
577 | 577 | |
578 | - $trigger->increaseHOF(1,array('Combat','Port','Number Of Triggers'), HOF_PUBLIC); |
|
578 | + $trigger->increaseHOF(1, array('Combat', 'Port', 'Number Of Triggers'), HOF_PUBLIC); |
|
579 | 579 | foreach ($attackers as $attacker) { |
580 | - $attacker->increaseHOF(1,array('Combat','Port','Number Of Attacks'), HOF_PUBLIC); |
|
580 | + $attacker->increaseHOF(1, array('Combat', 'Port', 'Number Of Attacks'), HOF_PUBLIC); |
|
581 | 581 | $this->db->query('REPLACE INTO player_attacks_port (game_id, account_id, sector_id, time, level) VALUES |
582 | 582 | (' . $this->db->escapeNumber($this->getGameID()) . ', ' . $this->db->escapeNumber($attacker->getAccountID()) . ', ' . $this->db->escapeNumber($this->getSectorID()) . ', ' . $this->db->escapeNumber(TIME) . ', ' . $this->db->escapeNumber($this->getLevel()) . ')'); |
583 | 583 | } |
@@ -590,8 +590,8 @@ discard block |
||
590 | 590 | $this->updateAttackStarted(); |
591 | 591 | //add news |
592 | 592 | $newsMessage = '<span class="red bold">*MAYDAY* *MAYDAY*</span> A distress beacon has been activated by the port in sector ' . Globals::getSectorBBLink($this->getSectorID()) . '. It is under attack by '; |
593 | - if($trigger->hasAlliance()) { |
|
594 | - $newsMessage .= 'members of '.$trigger->getAllianceBBLink(); |
|
593 | + if ($trigger->hasAlliance()) { |
|
594 | + $newsMessage .= 'members of ' . $trigger->getAllianceBBLink(); |
|
595 | 595 | } |
596 | 596 | else { |
597 | 597 | $newsMessage .= $trigger->getBBLink(); |
@@ -600,11 +600,11 @@ discard block |
||
600 | 600 | $newsMessage .= '. The Federal Government is offering '; |
601 | 601 | $bounty = number_format(round($trigger->getLevelID() * DEFEND_PORT_BOUNTY_PER_LEVEL)); |
602 | 602 | |
603 | - if($trigger->hasAlliance()) { |
|
604 | - $newsMessage .= 'bounties of <span class="creds">' . $bounty . '</span> credits for the deaths of any raiding members of '.$trigger->getAllianceBBLink(); |
|
603 | + if ($trigger->hasAlliance()) { |
|
604 | + $newsMessage .= 'bounties of <span class="creds">' . $bounty . '</span> credits for the deaths of any raiding members of ' . $trigger->getAllianceBBLink(); |
|
605 | 605 | } |
606 | 606 | else { |
607 | - $newsMessage .= 'a bounty of <span class="creds">' . $bounty . '</span> credits for the death of '.$trigger->getBBLink(); |
|
607 | + $newsMessage .= 'a bounty of <span class="creds">' . $bounty . '</span> credits for the death of ' . $trigger->getBBLink(); |
|
608 | 608 | } |
609 | 609 | $newsMessage .= ' prior to the destruction of the port, or until federal forces arrive to defend the port.'; |
610 | 610 | // $irc_message = '[k00,01]The port in sector [k11]'.$this->sectorID.'[k00] is under attack![/k]'; |
@@ -617,122 +617,122 @@ discard block |
||
617 | 617 | } |
618 | 618 | |
619 | 619 | public function setShields($shields) { |
620 | - if($this->isCachedVersion()) |
|
620 | + if ($this->isCachedVersion()) |
|
621 | 621 | throw new Exception('Cannot update a cached port!'); |
622 | - if($shields<0) |
|
623 | - $shields=0; |
|
624 | - if($this->shields == $shields) |
|
622 | + if ($shields < 0) |
|
623 | + $shields = 0; |
|
624 | + if ($this->shields == $shields) |
|
625 | 625 | return; |
626 | - $this->shields=$shields; |
|
627 | - $this->hasChanged=true; |
|
626 | + $this->shields = $shields; |
|
627 | + $this->hasChanged = true; |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | public function setArmour($armour) { |
631 | - if($this->isCachedVersion()) |
|
631 | + if ($this->isCachedVersion()) |
|
632 | 632 | throw new Exception('Cannot update a cached port!'); |
633 | - if($armour<0) |
|
634 | - $armour=0; |
|
635 | - if($this->armour == $armour) |
|
633 | + if ($armour < 0) |
|
634 | + $armour = 0; |
|
635 | + if ($this->armour == $armour) |
|
636 | 636 | return; |
637 | - $this->armour=$armour; |
|
638 | - $this->hasChanged=true; |
|
637 | + $this->armour = $armour; |
|
638 | + $this->hasChanged = true; |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | public function setCDs($combatDrones) { |
642 | - if($this->isCachedVersion()) |
|
642 | + if ($this->isCachedVersion()) |
|
643 | 643 | throw new Exception('Cannot update a cached port!'); |
644 | - if($combatDrones<0) |
|
645 | - $combatDrones=0; |
|
646 | - if($this->combatDrones == $combatDrones) |
|
644 | + if ($combatDrones < 0) |
|
645 | + $combatDrones = 0; |
|
646 | + if ($this->combatDrones == $combatDrones) |
|
647 | 647 | return; |
648 | - $this->combatDrones=$combatDrones; |
|
649 | - $this->hasChanged=true; |
|
648 | + $this->combatDrones = $combatDrones; |
|
649 | + $this->hasChanged = true; |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | public function setCreditsToDefault() { |
653 | - $this->setCredits(2700000 + $this->getLevel()*1500000 + pow($this->getLevel(), 2) * 300000); |
|
653 | + $this->setCredits(2700000 + $this->getLevel() * 1500000 + pow($this->getLevel(), 2) * 300000); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | public function setCredits($credits) { |
657 | - if($this->isCachedVersion()) |
|
657 | + if ($this->isCachedVersion()) |
|
658 | 658 | throw new Exception('Cannot update a cached port!'); |
659 | - if($this->credits == $credits) |
|
659 | + if ($this->credits == $credits) |
|
660 | 660 | return; |
661 | 661 | $this->credits = $credits; |
662 | - $this->hasChanged=true; |
|
662 | + $this->hasChanged = true; |
|
663 | 663 | } |
664 | 664 | |
665 | 665 | public function decreaseCredits($credits) { |
666 | - if($credits<0) |
|
666 | + if ($credits < 0) |
|
667 | 667 | throw new Exception('Cannot decrease negative credits.'); |
668 | - $this->setCredits($this->getCredits()-$credits); |
|
668 | + $this->setCredits($this->getCredits() - $credits); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | public function increaseCredits($credits) { |
672 | - if($credits<0) |
|
672 | + if ($credits < 0) |
|
673 | 673 | throw new Exception('Cannot increase negative credits.'); |
674 | - $this->setCredits($this->getCredits()+$credits); |
|
674 | + $this->setCredits($this->getCredits() + $credits); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | public function setUpgrade($upgrade) { |
678 | - if($this->isCachedVersion()) |
|
678 | + if ($this->isCachedVersion()) |
|
679 | 679 | throw new Exception('Cannot update a cached port!'); |
680 | - if($this->getLevel() == $this->getMaxLevel()) { |
|
680 | + if ($this->getLevel() == $this->getMaxLevel()) { |
|
681 | 681 | $upgrade = 0; |
682 | 682 | } |
683 | - if($this->upgrade == $upgrade) |
|
683 | + if ($this->upgrade == $upgrade) |
|
684 | 684 | return; |
685 | 685 | $this->upgrade = $upgrade; |
686 | - $this->hasChanged=true; |
|
686 | + $this->hasChanged = true; |
|
687 | 687 | $this->checkForUpgrade(); |
688 | 688 | } |
689 | 689 | |
690 | 690 | public function decreaseUpgrade($upgrade) { |
691 | - if($upgrade<0) |
|
691 | + if ($upgrade < 0) |
|
692 | 692 | throw new Exception('Cannot decrease negative upgrade.'); |
693 | - $this->setUpgrade($this->getUpgrade()-$upgrade); |
|
693 | + $this->setUpgrade($this->getUpgrade() - $upgrade); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | public function increaseUpgrade($upgrade) { |
697 | - if($upgrade<0) |
|
697 | + if ($upgrade < 0) |
|
698 | 698 | throw new Exception('Cannot increase negative upgrade.'); |
699 | - $this->setUpgrade($this->getUpgrade()+$upgrade); |
|
699 | + $this->setUpgrade($this->getUpgrade() + $upgrade); |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | public function setLevel($level) { |
703 | - if($this->isCachedVersion()) |
|
703 | + if ($this->isCachedVersion()) |
|
704 | 704 | throw new Exception('Cannot update a cached port!'); |
705 | - if($this->level == $level) |
|
705 | + if ($this->level == $level) |
|
706 | 706 | return; |
707 | 707 | $this->level = $level; |
708 | - $this->hasChanged=true; |
|
708 | + $this->hasChanged = true; |
|
709 | 709 | } |
710 | 710 | |
711 | 711 | public function increaseLevel($level) { |
712 | - if($level<0) |
|
712 | + if ($level < 0) |
|
713 | 713 | throw new Exception('Cannot increase negative level.'); |
714 | - $this->setLevel($this->getLevel()+$level); |
|
714 | + $this->setLevel($this->getLevel() + $level); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | public function decreaseLevel($level) { |
718 | - if($level<0) |
|
718 | + if ($level < 0) |
|
719 | 719 | throw new Exception('Cannot increase negative level.'); |
720 | - $this->setLevel($this->getLevel()-$level); |
|
720 | + $this->setLevel($this->getLevel() - $level); |
|
721 | 721 | } |
722 | 722 | |
723 | 723 | public function setExperience($experience) { |
724 | - if($this->isCachedVersion()) |
|
724 | + if ($this->isCachedVersion()) |
|
725 | 725 | throw new Exception('Cannot update a cached port!'); |
726 | - if($this->experience == $experience) |
|
726 | + if ($this->experience == $experience) |
|
727 | 727 | return; |
728 | 728 | $this->experience = $experience; |
729 | - $this->hasChanged=true; |
|
729 | + $this->hasChanged = true; |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | public function increaseExperience($experience) { |
733 | - if($experience<0) |
|
733 | + if ($experience < 0) |
|
734 | 734 | throw new Exception('Cannot increase negative experience.'); |
735 | - $this->setExperience($this->getExperience()+$experience); |
|
735 | + $this->setExperience($this->getExperience() + $experience); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | public function getGameID() { |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | } |
745 | 745 | |
746 | 746 | public function &getSector() { |
747 | - return SmrSector::getSector($this->getGameID(),$this->getSectorID()); |
|
747 | + return SmrSector::getSector($this->getGameID(), $this->getSectorID()); |
|
748 | 748 | } |
749 | 749 | |
750 | 750 | public function getRaceID() { |
@@ -752,13 +752,13 @@ discard block |
||
752 | 752 | } |
753 | 753 | |
754 | 754 | public function setRaceID($raceID) { |
755 | - if($this->raceID == $raceID) |
|
755 | + if ($this->raceID == $raceID) |
|
756 | 756 | return; |
757 | 757 | $this->raceID = $raceID; |
758 | 758 | $this->hasChanged = true; |
759 | 759 | $this->cacheIsValid = false; |
760 | 760 | // route_cache tells NPC's where they can trade |
761 | - $this->db->query('DELETE FROM route_cache WHERE game_id='.$this->db->escapeNumber($this->getGameID())); |
|
761 | + $this->db->query('DELETE FROM route_cache WHERE game_id=' . $this->db->escapeNumber($this->getGameID())); |
|
762 | 762 | } |
763 | 763 | |
764 | 764 | public function getRaceName() { |
@@ -816,24 +816,24 @@ discard block |
||
816 | 816 | |
817 | 817 | public function &getWeapons() { |
818 | 818 | $weapons = array(); |
819 | - for ($i=0; $i<$this->getNumWeapons(); ++$i) { |
|
819 | + for ($i = 0; $i < $this->getNumWeapons(); ++$i) { |
|
820 | 820 | $weapons[$i] = SmrWeapon::getWeapon(WEAPON_PORT_TURRET); |
821 | 821 | } |
822 | 822 | return $weapons; |
823 | 823 | } |
824 | 824 | |
825 | 825 | public function getUpgradePercent() { |
826 | - return min(1,max(0,$this->upgrade / $this->getUpgradeRequirement())); |
|
826 | + return min(1, max(0, $this->upgrade / $this->getUpgradeRequirement())); |
|
827 | 827 | } |
828 | 828 | |
829 | 829 | public function getCreditsPercent() { |
830 | - return min(1,max(0,$this->credits / 32000000)); |
|
830 | + return min(1, max(0, $this->credits / 32000000)); |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | public function getReinforcePercent() { |
834 | - if(!$this->isUnderAttack()) |
|
834 | + if (!$this->isUnderAttack()) |
|
835 | 835 | return 0; |
836 | - return min(1,max(0,($this->getReinforceTime() - TIME) / ($this->getReinforceTime() - $this->getAttackStarted()))); |
|
836 | + return min(1, max(0, ($this->getReinforceTime() - TIME) / ($this->getReinforceTime() - $this->getAttackStarted()))); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | public function getReinforceTime() { |
@@ -841,7 +841,7 @@ discard block |
||
841 | 841 | } |
842 | 842 | |
843 | 843 | public function setReinforceTime($reinforceTime) { |
844 | - $this->reinforceTime=$reinforceTime; |
|
844 | + $this->reinforceTime = $reinforceTime; |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | public function getAttackStarted() { |
@@ -853,10 +853,10 @@ discard block |
||
853 | 853 | } |
854 | 854 | |
855 | 855 | public function setAttackStarted($time) { |
856 | - if($this->attackStarted==$time) |
|
856 | + if ($this->attackStarted == $time) |
|
857 | 857 | return; |
858 | - $this->attackStarted=TIME; |
|
859 | - $this->hasChanged=true; |
|
858 | + $this->attackStarted = TIME; |
|
859 | + $this->hasChanged = true; |
|
860 | 860 | } |
861 | 861 | |
862 | 862 | public function isUnderAttack() { |
@@ -864,11 +864,11 @@ discard block |
||
864 | 864 | } |
865 | 865 | |
866 | 866 | public function isDestroyed() { |
867 | - return ($this->getArmour()<1 && $this->isUnderAttack()); |
|
867 | + return ($this->getArmour() < 1 && $this->isUnderAttack()); |
|
868 | 868 | } |
869 | 869 | |
870 | 870 | public function exists() { |
871 | - return $this->isNew===false||$this->hasChanged===true; |
|
871 | + return $this->isNew === false || $this->hasChanged === true; |
|
872 | 872 | } |
873 | 873 | |
874 | 874 | public function decreaseShields($number) { |
@@ -885,8 +885,8 @@ discard block |
||
885 | 885 | |
886 | 886 | public function getIdealPrice($goodID, $transactionType, $numGoods, $relations) { |
887 | 887 | // echo 'Good:'.$goodID.',Dist::'.$dist.',Type:'.$transactionType.',NumGoods:'.$numGoods.',Relations:'.$relations.','; |
888 | - if($relations>1000) |
|
889 | - $relations=1000; |
|
888 | + if ($relations > 1000) |
|
889 | + $relations = 1000; |
|
890 | 890 | $good = $this->getGood($goodID); |
891 | 891 | $base = $good['BasePrice']; |
892 | 892 | $maxSupply = $good['Max']; |
@@ -895,26 +895,26 @@ discard block |
||
895 | 895 | |
896 | 896 | // $relations_factor_buy = 2-(($relations + 500) / 1500); |
897 | 897 | // $relations_factor_sell = ($relations + 500) / 1500; |
898 | - if($transactionType == 'Sell') |
|
899 | - $idealPrice = round($numGoods * $base * 0.6 * (pow($dist + .5, 1.8)) * (2.5-($supply / $maxSupply)) * (($relations + 350) / 8415) ); |
|
900 | - else if($transactionType == 'Buy') |
|
901 | - $idealPrice = round($numGoods * $base * 0.7 * pow($dist, 1.84) * (2.5-($supply / $maxSupply)) * (2-($relations + 50) / 850) * (($relations + 350) / 1500) / 38.56 * (1 + (10 - $this->getLevel()) / 50)); |
|
898 | + if ($transactionType == 'Sell') |
|
899 | + $idealPrice = round($numGoods * $base * 0.6 * (pow($dist + .5, 1.8)) * (2.5 - ($supply / $maxSupply)) * (($relations + 350) / 8415)); |
|
900 | + else if ($transactionType == 'Buy') |
|
901 | + $idealPrice = round($numGoods * $base * 0.7 * pow($dist, 1.84) * (2.5 - ($supply / $maxSupply)) * (2 - ($relations + 50) / 850) * (($relations + 350) / 1500) / 38.56 * (1 + (10 - $this->getLevel()) / 50)); |
|
902 | 902 | return $idealPrice; |
903 | 903 | } |
904 | 904 | |
905 | 905 | public function getOfferPrice($idealPrice, $relations, $transactionType) { |
906 | - $moneyRelations=max(0,min(2000,$relations)); |
|
907 | - $expRelations=max(0,min(1000,$relations)); |
|
908 | - $relationsEffect = pow(1+($expRelations-1000)/10000,1.2-$expRelations/1000); |
|
909 | - $relationsEffect -= max(0,min(self::BARGAIN_LENIENCY_PERCENT,self::BARGAIN_LENIENCY_PERCENT*(2000-$moneyRelations)/1000)); //Gradual increase getting closer and closer to actual ideal price as relations increase to 2000 (will only be an increase of self::BARGAIN_LENIENCY_PERCENT percent extra cash) |
|
906 | + $moneyRelations = max(0, min(2000, $relations)); |
|
907 | + $expRelations = max(0, min(1000, $relations)); |
|
908 | + $relationsEffect = pow(1 + ($expRelations - 1000) / 10000, 1.2 - $expRelations / 1000); |
|
909 | + $relationsEffect -= max(0, min(self::BARGAIN_LENIENCY_PERCENT, self::BARGAIN_LENIENCY_PERCENT * (2000 - $moneyRelations) / 1000)); //Gradual increase getting closer and closer to actual ideal price as relations increase to 2000 (will only be an increase of self::BARGAIN_LENIENCY_PERCENT percent extra cash) |
|
910 | 910 | |
911 | - if($transactionType == 'Buy') |
|
911 | + if ($transactionType == 'Buy') |
|
912 | 912 | { |
913 | - $relationsEffect = 2-$relationsEffect; |
|
914 | - return max($idealPrice,floor($idealPrice * $relationsEffect)); |
|
913 | + $relationsEffect = 2 - $relationsEffect; |
|
914 | + return max($idealPrice, floor($idealPrice * $relationsEffect)); |
|
915 | 915 | } |
916 | 916 | else |
917 | - return min($idealPrice,ceil($idealPrice * $relationsEffect)); |
|
917 | + return min($idealPrice, ceil($idealPrice * $relationsEffect)); |
|
918 | 918 | // $range = .11 - .095; |
919 | 919 | // $rand = .095 + $range * mt_rand(0, 32767)/32767; |
920 | 920 | // |
@@ -925,29 +925,29 @@ discard block |
||
925 | 925 | // return $offeredPrice; |
926 | 926 | } |
927 | 927 | |
928 | - public function calculateExperiencePercent($idealPrice,$offerPrice,$bargainPrice,$transactionType) { |
|
929 | - if(($transactionType == 'Sell' && $bargainPrice < $offerPrice) || ($transactionType == 'Buy' && $bargainPrice > $offerPrice)) |
|
928 | + public function calculateExperiencePercent($idealPrice, $offerPrice, $bargainPrice, $transactionType) { |
|
929 | + if (($transactionType == 'Sell' && $bargainPrice < $offerPrice) || ($transactionType == 'Buy' && $bargainPrice > $offerPrice)) |
|
930 | 930 | return 0; |
931 | 931 | if ($bargainPrice == $idealPrice) |
932 | 932 | return 1; |
933 | - $bargainLeniency = min($idealPrice*self::BARGAIN_LENIENCY_PERCENT,abs($idealPrice-$bargainPrice)); |
|
933 | + $bargainLeniency = min($idealPrice * self::BARGAIN_LENIENCY_PERCENT, abs($idealPrice - $bargainPrice)); |
|
934 | 934 | if ($transactionType == 'Sell') |
935 | 935 | $bargainLeniency = -$bargainLeniency; |
936 | 936 | $bargainPrice -= $bargainLeniency; |
937 | 937 | |
938 | - $val = ($idealPrice-$bargainPrice)/($idealPrice-$this->getOfferPrice($idealPrice,0,$transactionType)); |
|
938 | + $val = ($idealPrice - $bargainPrice) / ($idealPrice - $this->getOfferPrice($idealPrice, 0, $transactionType)); |
|
939 | 939 | // if ($transactionType == 'Sell' && $val>0) |
940 | 940 | // $val=1; |
941 | 941 | // else if($transactionType == 'Buy' && $val<0) |
942 | 942 | // $val=1; |
943 | - $val=abs($val); |
|
944 | - if($val>1) |
|
945 | - $val=1; |
|
946 | - $expPercent = pow(1-$val,15); |
|
947 | - if($expPercent>1) |
|
948 | - $expPercent=1; |
|
949 | - else if($expPercent<0) |
|
950 | - $expPercent=0; |
|
943 | + $val = abs($val); |
|
944 | + if ($val > 1) |
|
945 | + $val = 1; |
|
946 | + $expPercent = pow(1 - $val, 15); |
|
947 | + if ($expPercent > 1) |
|
948 | + $expPercent = 1; |
|
949 | + else if ($expPercent < 0) |
|
950 | + $expPercent = 0; |
|
951 | 951 | return $expPercent; |
952 | 952 | } |
953 | 953 | |
@@ -968,18 +968,18 @@ discard block |
||
968 | 968 | } |
969 | 969 | |
970 | 970 | public function getRazeHREF($justContainer = false) { |
971 | - $container = create_container('skeleton.php','port_payout_processing.php'); |
|
971 | + $container = create_container('skeleton.php', 'port_payout_processing.php'); |
|
972 | 972 | $container['PayoutType'] = 'Raze'; |
973 | 973 | return $justContainer === false ? SmrSession::getNewHREF($container) : $container; |
974 | 974 | } |
975 | 975 | |
976 | 976 | public function getLootHREF($justContainer = false) { |
977 | - if($this->getCredits() > 0) { |
|
978 | - $container = create_container('skeleton.php','port_payout_processing.php'); |
|
977 | + if ($this->getCredits() > 0) { |
|
978 | + $container = create_container('skeleton.php', 'port_payout_processing.php'); |
|
979 | 979 | $container['PayoutType'] = 'Loot'; |
980 | 980 | } |
981 | 981 | else { |
982 | - $container = create_container('skeleton.php','current_sector.php'); |
|
982 | + $container = create_container('skeleton.php', 'current_sector.php'); |
|
983 | 983 | $container['msg'] = 'This port has already been looted.'; |
984 | 984 | } |
985 | 985 | return $justContainer === false ? SmrSession::getNewHREF($container) : $container; |
@@ -997,12 +997,12 @@ discard block |
||
997 | 997 | return $this->cachedTime; |
998 | 998 | } |
999 | 999 | protected function setCachedTime($cachedTime) { |
1000 | - return $this->cachedTime=$cachedTime; |
|
1000 | + return $this->cachedTime = $cachedTime; |
|
1001 | 1001 | } |
1002 | 1002 | public function updateSectorPlayersCache() { |
1003 | 1003 | $accountIDs = array(); |
1004 | 1004 | $sectorPlayers = $this->getSector()->getPlayers(); |
1005 | - foreach($sectorPlayers as $sectorPlayer) { |
|
1005 | + foreach ($sectorPlayers as $sectorPlayer) { |
|
1006 | 1006 | $accountIDs[] = $sectorPlayer->getAccountID(); |
1007 | 1007 | } |
1008 | 1008 | $this->addCachePorts($accountIDs); |
@@ -1011,22 +1011,22 @@ discard block |
||
1011 | 1011 | $this->addCachePorts(array($accountID)); |
1012 | 1012 | } |
1013 | 1013 | public function addCachePorts(array $accountIDs) { |
1014 | - if (count($accountIDs)>0 && $this->exists()) { |
|
1014 | + if (count($accountIDs) > 0 && $this->exists()) { |
|
1015 | 1015 | $cache = $this->db->escapeBinary(gzcompress(serialize($this))); |
1016 | 1016 | $cacheHash = $this->db->escapeString(md5($cache)); |
1017 | 1017 | //give them the port info |
1018 | 1018 | $query = 'INSERT IGNORE INTO player_visited_port ' . |
1019 | 1019 | '(account_id, game_id, sector_id, visited, port_info_hash) ' . |
1020 | 1020 | 'VALUES '; |
1021 | - foreach($accountIDs as $accountID) { |
|
1022 | - $query .= '('.$accountID.', '.$this->getGameID().', '.$this->getSectorID().', 0, \'\'),'; |
|
1021 | + foreach ($accountIDs as $accountID) { |
|
1022 | + $query .= '(' . $accountID . ', ' . $this->getGameID() . ', ' . $this->getSectorID() . ', 0, \'\'),'; |
|
1023 | 1023 | } |
1024 | - $query = substr($query,0,-1); |
|
1024 | + $query = substr($query, 0, -1); |
|
1025 | 1025 | $this->db->query($query); |
1026 | 1026 | |
1027 | 1027 | $this->db->query('INSERT IGNORE INTO port_info_cache |
1028 | 1028 | (game_id, sector_id, port_info_hash, port_info) |
1029 | - VALUES (' . $this->db->escapeNumber($this->getGameID()) . ', ' . $this->db->escapeNumber($this->getSectorID()) . ', ' . $cacheHash . ', ' . $cache.')'); |
|
1029 | + VALUES (' . $this->db->escapeNumber($this->getGameID()) . ', ' . $this->db->escapeNumber($this->getSectorID()) . ', ' . $cacheHash . ', ' . $cache . ')'); |
|
1030 | 1030 | |
1031 | 1031 | // We can't use the SQL member here because CachePorts don't have it |
1032 | 1032 | $this->db->query('UPDATE player_visited_port SET visited=' . $this->db->escapeNumber($this->getCachedTime()) . ', port_info_hash=' . $cacheHash . ' WHERE visited<=' . $this->db->escapeNumber($this->getCachedTime()) . ' AND account_id IN (' . $this->db->escapeArray($accountIDs) . ') AND sector_id=' . $this->db->escapeNumber($this->getSectorID()) . ' AND game_id=' . $this->db->escapeNumber($this->getGameID()) . ' LIMIT ' . count($accountIDs)); |
@@ -1036,8 +1036,8 @@ discard block |
||
1036 | 1036 | } |
1037 | 1037 | return false; |
1038 | 1038 | } |
1039 | - public static function &getCachedPort($gameID,$sectorID,$accountID,$forceUpdate=false) { |
|
1040 | - if($forceUpdate || !isset(self::$CACHE_CACHED_PORTS[$gameID][$sectorID][$accountID])) { |
|
1039 | + public static function &getCachedPort($gameID, $sectorID, $accountID, $forceUpdate = false) { |
|
1040 | + if ($forceUpdate || !isset(self::$CACHE_CACHED_PORTS[$gameID][$sectorID][$accountID])) { |
|
1041 | 1041 | $db = new SmrMySqlDatabase(); |
1042 | 1042 | $db->query('SELECT visited, port_info |
1043 | 1043 | FROM player_visited_port |
@@ -1046,7 +1046,7 @@ discard block |
||
1046 | 1046 | AND game_id = ' . $db->escapeNumber($gameID) . ' |
1047 | 1047 | AND sector_id = ' . $db->escapeNumber($sectorID) . ' LIMIT 1'); |
1048 | 1048 | |
1049 | - if($db->nextRecord()) { |
|
1049 | + if ($db->nextRecord()) { |
|
1050 | 1050 | self::$CACHE_CACHED_PORTS[$gameID][$sectorID][$accountID] = unserialize(gzuncompress($db->getField('port_info'))); |
1051 | 1051 | self::$CACHE_CACHED_PORTS[$gameID][$sectorID][$accountID]->setCachedTime($db->getInt('visited')); |
1052 | 1052 | } |
@@ -1084,8 +1084,8 @@ discard block |
||
1084 | 1084 | } |
1085 | 1085 | |
1086 | 1086 | // If any fields in the `port` table have changed, update table |
1087 | - if($this->hasChanged) { |
|
1088 | - if($this->isNew===false) { |
|
1087 | + if ($this->hasChanged) { |
|
1088 | + if ($this->isNew === false) { |
|
1089 | 1089 | $this->db->query('UPDATE port SET experience = ' . $this->db->escapeNumber($this->getExperience()) . |
1090 | 1090 | ', shields = ' . $this->db->escapeNumber($this->getShields()) . |
1091 | 1091 | ', armour = ' . $this->db->escapeNumber($this->getArmour()) . |
@@ -1113,9 +1113,9 @@ discard block |
||
1113 | 1113 | ',' . $this->db->escapeNumber($this->getReinforceTime()) . |
1114 | 1114 | ',' . $this->db->escapeNumber($this->getAttackStarted()) . |
1115 | 1115 | ',' . $this->db->escapeNumber($this->getRaceID()) . ')'); |
1116 | - $this->isNew=false; |
|
1116 | + $this->isNew = false; |
|
1117 | 1117 | } |
1118 | - $this->hasChanged=false; |
|
1118 | + $this->hasChanged = false; |
|
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | // Update the port good amounts if they have been changed |
@@ -1134,30 +1134,30 @@ discard block |
||
1134 | 1134 | |
1135 | 1135 | public function &shootPlayers(array $targetPlayers) { |
1136 | 1136 | $results = array('Port' => $this, 'TotalDamage' => 0, 'TotalDamagePerTargetPlayer' => array()); |
1137 | - foreach($targetPlayers as $targetPlayer) { |
|
1137 | + foreach ($targetPlayers as $targetPlayer) { |
|
1138 | 1138 | $results['TotalDamagePerTargetPlayer'][$targetPlayer->getAccountID()] = 0; |
1139 | 1139 | $results['TotalShotsPerTargetPlayer'][$targetPlayer->getAccountID()] = 0; |
1140 | 1140 | } |
1141 | - if($this->isDestroyed()) { |
|
1141 | + if ($this->isDestroyed()) { |
|
1142 | 1142 | $results['DeadBeforeShot'] = true; |
1143 | 1143 | return $results; |
1144 | 1144 | } |
1145 | 1145 | $results['DeadBeforeShot'] = false; |
1146 | 1146 | $weapons = $this->getWeapons(); |
1147 | - foreach($weapons as $orderID => $weapon) { |
|
1147 | + foreach ($weapons as $orderID => $weapon) { |
|
1148 | 1148 | do { |
1149 | 1149 | $targetPlayer = $targetPlayers[array_rand($targetPlayers)]; |
1150 | - } while($results['TotalShotsPerTargetPlayer'][$targetPlayer->getAccountID()] > min($results['TotalShotsPerTargetPlayer'])); |
|
1151 | - $results['Weapons'][$orderID] =& $weapon->shootPlayerAsPort($this, $targetPlayer); |
|
1150 | + } while ($results['TotalShotsPerTargetPlayer'][$targetPlayer->getAccountID()] > min($results['TotalShotsPerTargetPlayer'])); |
|
1151 | + $results['Weapons'][$orderID] = & $weapon->shootPlayerAsPort($this, $targetPlayer); |
|
1152 | 1152 | $results['TotalShotsPerTargetPlayer'][$targetPlayer->getAccountID()]++; |
1153 | - if($results['Weapons'][$orderID]['Hit']) { |
|
1153 | + if ($results['Weapons'][$orderID]['Hit']) { |
|
1154 | 1154 | $results['TotalDamage'] += $results['Weapons'][$orderID]['ActualDamage']['TotalDamage']; |
1155 | 1155 | $results['TotalDamagePerTargetPlayer'][$targetPlayer->getAccountID()] += $results['Weapons'][$orderID]['ActualDamage']['TotalDamage']; |
1156 | 1156 | } |
1157 | 1157 | } |
1158 | - if($this->hasCDs()) { |
|
1159 | - $thisCDs = new SmrCombatDrones($this->getGameID(),$this->getCDs(),true); |
|
1160 | - $results['Drones'] =& $thisCDs->shootPlayerAsPort($this, $targetPlayers[array_rand($targetPlayers)]); |
|
1158 | + if ($this->hasCDs()) { |
|
1159 | + $thisCDs = new SmrCombatDrones($this->getGameID(), $this->getCDs(), true); |
|
1160 | + $results['Drones'] = & $thisCDs->shootPlayerAsPort($this, $targetPlayers[array_rand($targetPlayers)]); |
|
1161 | 1161 | $results['TotalDamage'] += $results['Drones']['ActualDamage']['TotalDamage']; |
1162 | 1162 | $results['TotalDamagePerTargetPlayer'][$results['Drones']['TargetPlayer']->getAccountID()] += $results['Drones']['ActualDamage']['TotalDamage']; |
1163 | 1163 | } |
@@ -1169,20 +1169,20 @@ discard block |
||
1169 | 1169 | $shieldDamage = 0; |
1170 | 1170 | $cdDamage = 0; |
1171 | 1171 | $armourDamage = 0; |
1172 | - if(!$alreadyDead) { |
|
1173 | - if($damage['Shield'] || !$this->hasShields()) { |
|
1174 | - $shieldDamage = $this->doShieldDamage(min($damage['MaxDamage'],$damage['Shield'])); |
|
1172 | + if (!$alreadyDead) { |
|
1173 | + if ($damage['Shield'] || !$this->hasShields()) { |
|
1174 | + $shieldDamage = $this->doShieldDamage(min($damage['MaxDamage'], $damage['Shield'])); |
|
1175 | 1175 | $damage['MaxDamage'] -= $shieldDamage; |
1176 | - if(!$this->hasShields() && ($shieldDamage == 0 || $damage['Rollover'])) { |
|
1177 | - $cdDamage = $this->doCDDamage(min($damage['MaxDamage'],$damage['Armour'])); |
|
1176 | + if (!$this->hasShields() && ($shieldDamage == 0 || $damage['Rollover'])) { |
|
1177 | + $cdDamage = $this->doCDDamage(min($damage['MaxDamage'], $damage['Armour'])); |
|
1178 | 1178 | $damage['Armour'] -= $cdDamage; |
1179 | 1179 | $damage['MaxDamage'] -= $cdDamage; |
1180 | - if(!$this->hasCDs() && ($cdDamage == 0 || $damage['Rollover'])) |
|
1181 | - $armourDamage = $this->doArmourDamage(min($damage['MaxDamage'],$damage['Armour'])); |
|
1180 | + if (!$this->hasCDs() && ($cdDamage == 0 || $damage['Rollover'])) |
|
1181 | + $armourDamage = $this->doArmourDamage(min($damage['MaxDamage'], $damage['Armour'])); |
|
1182 | 1182 | } |
1183 | 1183 | } |
1184 | 1184 | else { //hit drones behind shields |
1185 | - $cdDamage = $this->doCDDamage(floor(min($damage['MaxDamage'],$damage['Armour'])*DRONES_BEHIND_SHIELDS_DAMAGE_PERCENT)); |
|
1185 | + $cdDamage = $this->doCDDamage(floor(min($damage['MaxDamage'], $damage['Armour']) * DRONES_BEHIND_SHIELDS_DAMAGE_PERCENT)); |
|
1186 | 1186 | } |
1187 | 1187 | } |
1188 | 1188 | |
@@ -1192,28 +1192,28 @@ discard block |
||
1192 | 1192 | 'Shield' => $shieldDamage, |
1193 | 1193 | 'HasShields' => $this->hasShields(), |
1194 | 1194 | 'CDs' => $cdDamage, |
1195 | - 'NumCDs' => $cdDamage/CD_ARMOUR, |
|
1195 | + 'NumCDs' => $cdDamage / CD_ARMOUR, |
|
1196 | 1196 | 'HasCDs' => $this->hasCDs(), |
1197 | 1197 | 'Armour' => $armourDamage, |
1198 | - 'TotalDamage' => $shieldDamage+$cdDamage+$armourDamage |
|
1198 | + 'TotalDamage' => $shieldDamage + $cdDamage + $armourDamage |
|
1199 | 1199 | ); |
1200 | 1200 | return $return; |
1201 | 1201 | } |
1202 | 1202 | |
1203 | 1203 | protected function doShieldDamage($damage) { |
1204 | - $actualDamage = min($this->getShields(),$damage); |
|
1204 | + $actualDamage = min($this->getShields(), $damage); |
|
1205 | 1205 | $this->decreaseShields($actualDamage); |
1206 | 1206 | return $actualDamage; |
1207 | 1207 | } |
1208 | 1208 | |
1209 | 1209 | protected function doCDDamage($damage) { |
1210 | - $actualDamage = min($this->getCDs(),floor($damage/CD_ARMOUR)); |
|
1210 | + $actualDamage = min($this->getCDs(), floor($damage / CD_ARMOUR)); |
|
1211 | 1211 | $this->decreaseCDs($actualDamage); |
1212 | - return $actualDamage*CD_ARMOUR; |
|
1212 | + return $actualDamage * CD_ARMOUR; |
|
1213 | 1213 | } |
1214 | 1214 | |
1215 | 1215 | protected function doArmourDamage($damage) { |
1216 | - $actualDamage = min($this->getArmour(),floor($damage)); |
|
1216 | + $actualDamage = min($this->getArmour(), floor($damage)); |
|
1217 | 1217 | $this->decreaseArmour($actualDamage); |
1218 | 1218 | return $actualDamage; |
1219 | 1219 | } |
@@ -1223,7 +1223,7 @@ discard block |
||
1223 | 1223 | $attackers = array(); |
1224 | 1224 | $this->db->query('SELECT account_id,level FROM player_attacks_port WHERE ' . $this->SQL . ' AND time > ' . $this->db->escapeNumber(TIME - self::TIME_TO_CREDIT_RAID)); |
1225 | 1225 | while ($this->db->nextRecord()) { |
1226 | - $attackers[] = SmrPlayer::getPlayer($this->db->getField('account_id'),$this->getGameID()); |
|
1226 | + $attackers[] = SmrPlayer::getPlayer($this->db->getField('account_id'), $this->getGameID()); |
|
1227 | 1227 | } |
1228 | 1228 | return $attackers; |
1229 | 1229 | } |
@@ -1231,21 +1231,21 @@ discard block |
||
1231 | 1231 | protected function creditCurrentAttackersForKill() { |
1232 | 1232 | //get all players involved for HoF |
1233 | 1233 | $attackers = $this->getAttackersToCredit(); |
1234 | - foreach($attackers as $attacker) { |
|
1235 | - $attacker->increaseHOF($this->db->getInt('level'),array('Combat','Port','Levels Raided'), HOF_PUBLIC); |
|
1236 | - $attacker->increaseHOF(1,array('Combat','Port','Total Raided'), HOF_PUBLIC); |
|
1234 | + foreach ($attackers as $attacker) { |
|
1235 | + $attacker->increaseHOF($this->db->getInt('level'), array('Combat', 'Port', 'Levels Raided'), HOF_PUBLIC); |
|
1236 | + $attacker->increaseHOF(1, array('Combat', 'Port', 'Total Raided'), HOF_PUBLIC); |
|
1237 | 1237 | } |
1238 | 1238 | } |
1239 | 1239 | |
1240 | 1240 | protected function payout(AbstractSmrPlayer $killer, $credits, $payoutType) { |
1241 | - if($this->getCredits() == 0) { |
|
1241 | + if ($this->getCredits() == 0) { |
|
1242 | 1242 | return false; |
1243 | 1243 | } |
1244 | 1244 | $killer->increaseCredits($credits); |
1245 | - $killer->increaseHOF($credits, array('Combat','Port','Money','Gained'), HOF_PUBLIC); |
|
1245 | + $killer->increaseHOF($credits, array('Combat', 'Port', 'Money', 'Gained'), HOF_PUBLIC); |
|
1246 | 1246 | $attackers = $this->getAttackersToCredit(); |
1247 | - foreach($attackers as $attacker) { |
|
1248 | - $attacker->increaseHOF(1, array('Combat','Port',$payoutType), HOF_PUBLIC); |
|
1247 | + foreach ($attackers as $attacker) { |
|
1248 | + $attacker->increaseHOF(1, array('Combat', 'Port', $payoutType), HOF_PUBLIC); |
|
1249 | 1249 | } |
1250 | 1250 | $this->setCredits(0); |
1251 | 1251 | return true; |
@@ -1253,7 +1253,7 @@ discard block |
||
1253 | 1253 | |
1254 | 1254 | public function razePort(AbstractSmrPlayer $killer) { |
1255 | 1255 | $credits = floor($this->getCredits() * self::RAZE_MONEY_PERCENT / 100); |
1256 | - if($this->payout($killer, $credits, 'Razed')) { |
|
1256 | + if ($this->payout($killer, $credits, 'Razed')) { |
|
1257 | 1257 | $this->doDowngrade(); |
1258 | 1258 | } |
1259 | 1259 | return $credits; |
@@ -1282,22 +1282,22 @@ discard block |
||
1282 | 1282 | $this->db->query('INSERT INTO news (game_id, time, news_message, type,killer_id,killer_alliance,dead_id) VALUES (' . $this->db->escapeNumber($this->getGameID()) . ', ' . $this->db->escapeNumber(TIME) . ', ' . $this->db->escapeString($news) . ', \'REGULAR\',' . $this->db->escapeNumber($killer->getAccountID()) . ',' . $this->db->escapeNumber($killer->getAllianceID()) . ',' . $this->db->escapeNumber(ACCOUNT_ID_PORT) . ')'); |
1283 | 1283 | // Killer gets a relations change and a bounty if port is taken |
1284 | 1284 | $return['KillerBounty'] = $killer->getExperience() * $this->getLevel(); |
1285 | - $killer->increaseCurrentBountyAmount('HQ',$return['KillerBounty']); |
|
1286 | - $killer->increaseHOF($return['KillerBounty'],array('Combat','Port','Bounties','Gained'), HOF_PUBLIC); |
|
1285 | + $killer->increaseCurrentBountyAmount('HQ', $return['KillerBounty']); |
|
1286 | + $killer->increaseHOF($return['KillerBounty'], array('Combat', 'Port', 'Bounties', 'Gained'), HOF_PUBLIC); |
|
1287 | 1287 | |
1288 | 1288 | if ($this->getRaceID() != RACE_NEUTRAL) { |
1289 | 1289 | $return['KillerRelations'] = 45; |
1290 | - $killer->decreaseRelations($return['KillerRelations'],$this->getRaceID()); |
|
1291 | - $killer->increaseHOF($return['KillerRelations'],array('Combat','Port','Relation','Loss'), HOF_PUBLIC); |
|
1290 | + $killer->decreaseRelations($return['KillerRelations'], $this->getRaceID()); |
|
1291 | + $killer->increaseHOF($return['KillerRelations'], array('Combat', 'Port', 'Relation', 'Loss'), HOF_PUBLIC); |
|
1292 | 1292 | } |
1293 | 1293 | |
1294 | 1294 | return $return; |
1295 | 1295 | } |
1296 | 1296 | |
1297 | 1297 | public function hasX(/*Object*/ $x) { |
1298 | - if (is_array($x) && $x['Type']=='Good') { // instanceof Good) - No Good class yet, so array is the best we can do |
|
1299 | - if(isset($x['ID'])) |
|
1300 | - return $this->hasGood($x['ID'],isset($x['TransactionType'])?$x['TransactionType']:false); |
|
1298 | + if (is_array($x) && $x['Type'] == 'Good') { // instanceof Good) - No Good class yet, so array is the best we can do |
|
1299 | + if (isset($x['ID'])) |
|
1300 | + return $this->hasGood($x['ID'], isset($x['TransactionType']) ? $x['TransactionType'] : false); |
|
1301 | 1301 | } |
1302 | 1302 | return false; |
1303 | 1303 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | /** |
41 | 41 | * Access properties of structures that this planet type can build. |
42 | 42 | */ |
43 | - function structureTypes($structureID=false) { |
|
43 | + function structureTypes($structureID = false) { |
|
44 | 44 | if (!isset($this->structures)) { |
45 | 45 | foreach (static::STRUCTURES as $ID => $Info) { |
46 | 46 | $this->structures[$ID] = new SmrPlanetStructureType($ID, $Info); |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | 'exp_gain' => 540, |
78 | 78 | ], |
79 | 79 | ]; |
80 | - function name() { return "Terran Planet"; } |
|
81 | - function imageLink() { return "images/planet1.png"; } |
|
82 | - function description() { return "A lush world, with forests, seas, sweeping meadows, and indigenous lifeforms."; } |
|
80 | + function name() { return "Terran Planet"; } |
|
81 | + function imageLink() { return "images/planet1.png"; } |
|
82 | + function description() { return "A lush world, with forests, seas, sweeping meadows, and indigenous lifeforms."; } |
|
83 | 83 | function maxAttackers() { return 10; } |
84 | - function maxLanded() { return self::MAX_LANDED_UNLIMITED; } |
|
85 | - function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
84 | + function maxLanded() { return self::MAX_LANDED_UNLIMITED; } |
|
85 | + function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | class AridPlanet extends SmrPlanetType { |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | 'exp_gain' => 180, |
107 | 107 | ], |
108 | 108 | ]; |
109 | - function name() { return "Arid Planet"; } |
|
110 | - function imageLink() { return "images/planet2.png"; } |
|
111 | - function description() { return "A world mostly devoid of surface water, but capable of supporting life."; } |
|
109 | + function name() { return "Arid Planet"; } |
|
110 | + function imageLink() { return "images/planet2.png"; } |
|
111 | + function description() { return "A world mostly devoid of surface water, but capable of supporting life."; } |
|
112 | 112 | function maxAttackers() { return 5; } |
113 | - function maxLanded() { return 5; } |
|
114 | - function menuOptions() { return ['CONSTRUCTION', 'DEFENSE', 'STOCKPILE', 'OWNERSHIP']; } |
|
113 | + function maxLanded() { return 5; } |
|
114 | + function menuOptions() { return ['CONSTRUCTION', 'DEFENSE', 'STOCKPILE', 'OWNERSHIP']; } |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | class DwarfPlanet extends SmrPlanetType { |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | 'exp_gain' => 540, |
136 | 136 | ], |
137 | 137 | ]; |
138 | - function name() { return "Dwarf Planet"; } |
|
139 | - function imageLink() { return "images/planet3.png"; } |
|
140 | - function description() { return "A smaller than usual planet, with no native life present."; } |
|
138 | + function name() { return "Dwarf Planet"; } |
|
139 | + function imageLink() { return "images/planet3.png"; } |
|
140 | + function description() { return "A smaller than usual planet, with no native life present."; } |
|
141 | 141 | function maxAttackers() { return 5; } |
142 | - function maxLanded() { return self::MAX_LANDED_UNLIMITED; } |
|
143 | - function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
142 | + function maxLanded() { return self::MAX_LANDED_UNLIMITED; } |
|
143 | + function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | class ProtoPlanet extends SmrPlanetType { |
@@ -170,12 +170,12 @@ discard block |
||
170 | 170 | 'exp_gain' => 540, |
171 | 171 | ], |
172 | 172 | ]; |
173 | - function name() { return "Protoplanet"; } |
|
174 | - function imageLink() { return "images/planet5.png"; } |
|
175 | - function description() { return "A developing planet, not yet able to support the infrastructure of advanced technologies."; } |
|
173 | + function name() { return "Protoplanet"; } |
|
174 | + function imageLink() { return "images/planet5.png"; } |
|
175 | + function description() { return "A developing planet, not yet able to support the infrastructure of advanced technologies."; } |
|
176 | 176 | function maxAttackers() { return 5; } |
177 | - function maxLanded() { return 5; } |
|
178 | - function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
177 | + function maxLanded() { return 5; } |
|
178 | + function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | class DefenseWorld extends SmrPlanetType { |
@@ -205,10 +205,10 @@ discard block |
||
205 | 205 | 'exp_gain' => 9, |
206 | 206 | ], |
207 | 207 | ]; |
208 | - function name() { return "Defense World"; } |
|
209 | - function imageLink() { return "images/planet4.png"; } |
|
210 | - function description() { return "A fully armed and operational battle station loaded with excessive firepower."; } |
|
208 | + function name() { return "Defense World"; } |
|
209 | + function imageLink() { return "images/planet4.png"; } |
|
210 | + function description() { return "A fully armed and operational battle station loaded with excessive firepower."; } |
|
211 | 211 | function maxAttackers() { return 10; } |
212 | - function maxLanded() { return self::MAX_LANDED_UNLIMITED; } |
|
213 | - function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
212 | + function maxLanded() { return self::MAX_LANDED_UNLIMITED; } |
|
213 | + function menuOptions() { return self::DEFAULT_MENU_OPTIONS; } |
|
214 | 214 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | private $path = array(); |
12 | 12 | private $warpMap = array(); |
13 | 13 | |
14 | - public function __construct($gameID,$_startSectorId) { |
|
14 | + public function __construct($gameID, $_startSectorId) { |
|
15 | 15 | $this->gameID = $gameID; |
16 | 16 | $this->addToPath($_startSectorId); |
17 | 17 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | public function getTotalSectors() { |
32 | - return $this->getDistance()+$this->getNumWarps(); |
|
32 | + return $this->getDistance() + $this->getNumWarps(); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | public function getNumWarps() { |
@@ -48,15 +48,15 @@ discard block |
||
48 | 48 | * @return the endSectorId |
49 | 49 | */ |
50 | 50 | public function getEndSectorID() { |
51 | - return $this->path[count($this->path)-1]; |
|
51 | + return $this->path[count($this->path) - 1]; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | public function &getEndSector() { |
55 | - return SmrSector::getSector($this->gameID,$this->getEndSectorID()); |
|
55 | + return SmrSector::getSector($this->gameID, $this->getEndSectorID()); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | public function compareTo(Distance $d) { |
59 | - if ($this->equals($d)===true) |
|
59 | + if ($this->equals($d) === true) |
|
60 | 60 | return 0; |
61 | 61 | else if ($d->getTurns() > $this->getTurns()) |
62 | 62 | return -1; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | public function isInPath($sectorID) { |
112 | - return in_array($sectorID,$this->getPath()); |
|
112 | + return in_array($sectorID, $this->getPath()); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | public function isAttacking(array &$board, array &$hasMoved, $king, $x = -1, $y = -1) { |
55 | - $moves =& $this->getPossibleMoves($board, $hasMoved, null, true); |
|
56 | - foreach($moves as &$move) { |
|
57 | - $p =& $board[$move[1]][$move[0]]; |
|
58 | - if(($move[0] == $x && $move[1] == $y) || ($king === true && $p != null && $p->pieceID == self::KING && $this->colour != $p->colour)) { |
|
55 | + $moves = & $this->getPossibleMoves($board, $hasMoved, null, true); |
|
56 | + foreach ($moves as &$move) { |
|
57 | + $p = & $board[$move[1]][$move[0]]; |
|
58 | + if (($move[0] == $x && $move[1] == $y) || ($king === true && $p != null && $p->pieceID == self::KING && $this->colour != $p->colour)) { |
|
59 | 59 | return true; |
60 | 60 | } |
61 | 61 | } |
@@ -64,130 +64,130 @@ discard block |
||
64 | 64 | |
65 | 65 | public function &getPossibleMoves(array &$board, array &$hasMoved, $forAccountID = null, $attackingCheck = false) { |
66 | 66 | $moves = array(); |
67 | - if($forAccountID == null || $this->accountID == $forAccountID) { |
|
68 | - if($this->pieceID==self::PAWN) { |
|
69 | - $dirY = $this->colour==ChessGame::PLAYER_BLACK ? 1 : -1; |
|
70 | - $moveY = $this->y+$dirY; |
|
67 | + if ($forAccountID == null || $this->accountID == $forAccountID) { |
|
68 | + if ($this->pieceID == self::PAWN) { |
|
69 | + $dirY = $this->colour == ChessGame::PLAYER_BLACK ? 1 : -1; |
|
70 | + $moveY = $this->y + $dirY; |
|
71 | 71 | //Pawn forward movement is not attacking - so don't check it if doing an attacking check. |
72 | - if(!$attackingCheck) { |
|
73 | - if(ChessGame::isValidCoord($this->x, $moveY, $board) && $board[$moveY][$this->x] == null && $this->isSafeMove($board, $hasMoved, $this->x, $moveY)) { |
|
74 | - $moves[] = array($this->x,$moveY); |
|
72 | + if (!$attackingCheck) { |
|
73 | + if (ChessGame::isValidCoord($this->x, $moveY, $board) && $board[$moveY][$this->x] == null && $this->isSafeMove($board, $hasMoved, $this->x, $moveY)) { |
|
74 | + $moves[] = array($this->x, $moveY); |
|
75 | 75 | } |
76 | 76 | $doubleMoveY = $moveY + $dirY; |
77 | - if($this->y-$dirY == 0 || $this->y-$dirY*2 == count($board)) { //Double move first move |
|
78 | - if($board[$moveY][$this->x] == null && $board[$doubleMoveY][$this->x] == null && $this->isSafeMove($board, $hasMoved, $this->x, $doubleMoveY)) { |
|
79 | - $moves[] = array($this->x,$doubleMoveY); |
|
77 | + if ($this->y - $dirY == 0 || $this->y - $dirY * 2 == count($board)) { //Double move first move |
|
78 | + if ($board[$moveY][$this->x] == null && $board[$doubleMoveY][$this->x] == null && $this->isSafeMove($board, $hasMoved, $this->x, $doubleMoveY)) { |
|
79 | + $moves[] = array($this->x, $doubleMoveY); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | } |
83 | - for($i=-1;$i<2;$i+=2) { |
|
84 | - $moveX = $this->x+$i; |
|
85 | - if(ChessGame::isValidCoord($moveX, $moveY, $board)) { |
|
86 | - if($attackingCheck || |
|
83 | + for ($i = -1; $i < 2; $i += 2) { |
|
84 | + $moveX = $this->x + $i; |
|
85 | + if (ChessGame::isValidCoord($moveX, $moveY, $board)) { |
|
86 | + if ($attackingCheck || |
|
87 | 87 | ((($hasMoved[ChessPiece::PAWN][0] == $moveX && $hasMoved[ChessPiece::PAWN][1] == $this->y) || |
88 | - ($board[$moveY][$moveX] != null && $board[$moveY][$moveX]->colour!=$this->colour)) |
|
88 | + ($board[$moveY][$moveX] != null && $board[$moveY][$moveX]->colour != $this->colour)) |
|
89 | 89 | && $this->isSafeMove($board, $hasMoved, $moveX, $moveY))) { |
90 | - $moves[] = array($moveX,$moveY); |
|
90 | + $moves[] = array($moveX, $moveY); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | } |
94 | 94 | } |
95 | - else if($this->pieceID==self::KING) { |
|
96 | - for($i = -1; $i < 2; $i++) { |
|
97 | - for($j = -1; $j < 2; $j++) { |
|
98 | - if($i!=0 || $j!=0) { |
|
99 | - $this->addMove($this->x+$i, $this->y+$j, $board, $moves, $hasMoved, $attackingCheck); |
|
95 | + else if ($this->pieceID == self::KING) { |
|
96 | + for ($i = -1; $i < 2; $i++) { |
|
97 | + for ($j = -1; $j < 2; $j++) { |
|
98 | + if ($i != 0 || $j != 0) { |
|
99 | + $this->addMove($this->x + $i, $this->y + $j, $board, $moves, $hasMoved, $attackingCheck); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
103 | 103 | //Castling is not attacking - so don't check it if doing an attacking check. |
104 | - if(!$attackingCheck && !$hasMoved[$this->colour][ChessPiece::KING] && !ChessGame::isPlayerChecked($board, $hasMoved, $this->colour)) { |
|
105 | - if(!$hasMoved[$this->colour][ChessPiece::ROOK]['Queen'] && |
|
106 | - ChessGame::isValidCoord($this->x-1, $this->y, $board) && $board[$this->y][$this->x-1] == null && |
|
107 | - ChessGame::isValidCoord($this->x-3, $this->y, $board) && $board[$this->y][$this->x-3] == null && |
|
108 | - $this->isSafeMove($board, $hasMoved, $this->x-1, $this->y)) { |
|
109 | - $this->addMove($this->x-2, $this->y, $board, $moves, $hasMoved, $attackingCheck); |
|
104 | + if (!$attackingCheck && !$hasMoved[$this->colour][ChessPiece::KING] && !ChessGame::isPlayerChecked($board, $hasMoved, $this->colour)) { |
|
105 | + if (!$hasMoved[$this->colour][ChessPiece::ROOK]['Queen'] && |
|
106 | + ChessGame::isValidCoord($this->x - 1, $this->y, $board) && $board[$this->y][$this->x - 1] == null && |
|
107 | + ChessGame::isValidCoord($this->x - 3, $this->y, $board) && $board[$this->y][$this->x - 3] == null && |
|
108 | + $this->isSafeMove($board, $hasMoved, $this->x - 1, $this->y)) { |
|
109 | + $this->addMove($this->x - 2, $this->y, $board, $moves, $hasMoved, $attackingCheck); |
|
110 | 110 | } |
111 | - if(!$hasMoved[$this->colour][ChessPiece::ROOK]['King'] && |
|
112 | - ChessGame::isValidCoord($this->x+1, $this->y, $board) && $board[$this->y][$this->x+1] == null && |
|
113 | - $this->isSafeMove($board, $hasMoved, $this->x+1, $this->y)) { |
|
114 | - $this->addMove($this->x+2, $this->y, $board, $moves, $hasMoved, $attackingCheck); |
|
111 | + if (!$hasMoved[$this->colour][ChessPiece::ROOK]['King'] && |
|
112 | + ChessGame::isValidCoord($this->x + 1, $this->y, $board) && $board[$this->y][$this->x + 1] == null && |
|
113 | + $this->isSafeMove($board, $hasMoved, $this->x + 1, $this->y)) { |
|
114 | + $this->addMove($this->x + 2, $this->y, $board, $moves, $hasMoved, $attackingCheck); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | } |
118 | - else if($this->pieceID==self::QUEEN) { |
|
118 | + else if ($this->pieceID == self::QUEEN) { |
|
119 | 119 | $moveX = $this->x; |
120 | 120 | $moveY = $this->y; |
121 | - while($this->addMove(--$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Left |
|
121 | + while ($this->addMove(--$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Left |
|
122 | 122 | $moveX = $this->x; |
123 | 123 | $moveY = $this->y; |
124 | - while($this->addMove(++$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Right |
|
124 | + while ($this->addMove(++$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Right |
|
125 | 125 | $moveX = $this->x; |
126 | 126 | $moveY = $this->y; |
127 | - while($this->addMove($moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up |
|
127 | + while ($this->addMove($moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up |
|
128 | 128 | $moveX = $this->x; |
129 | 129 | $moveY = $this->y; |
130 | - while($this->addMove($moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down |
|
130 | + while ($this->addMove($moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down |
|
131 | 131 | $moveX = $this->x; |
132 | 132 | $moveY = $this->y; |
133 | - while($this->addMove(--$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
133 | + while ($this->addMove(--$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
134 | 134 | $moveX = $this->x; |
135 | 135 | $moveY = $this->y; |
136 | - while($this->addMove(++$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Right |
|
136 | + while ($this->addMove(++$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Right |
|
137 | 137 | $moveX = $this->x; |
138 | 138 | $moveY = $this->y; |
139 | - while($this->addMove(--$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down-Left |
|
139 | + while ($this->addMove(--$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down-Left |
|
140 | 140 | $moveX = $this->x; |
141 | 141 | $moveY = $this->y; |
142 | - while($this->addMove(++$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
142 | + while ($this->addMove(++$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
143 | 143 | } |
144 | - else if($this->pieceID==self::ROOK) { |
|
144 | + else if ($this->pieceID == self::ROOK) { |
|
145 | 145 | $moveX = $this->x; |
146 | 146 | $moveY = $this->y; |
147 | - while($this->addMove(--$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Left |
|
147 | + while ($this->addMove(--$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Left |
|
148 | 148 | $moveX = $this->x; |
149 | 149 | $moveY = $this->y; |
150 | - while($this->addMove(++$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Right |
|
150 | + while ($this->addMove(++$moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Right |
|
151 | 151 | $moveX = $this->x; |
152 | 152 | $moveY = $this->y; |
153 | - while($this->addMove($moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up |
|
153 | + while ($this->addMove($moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up |
|
154 | 154 | $moveX = $this->x; |
155 | 155 | $moveY = $this->y; |
156 | - while($this->addMove($moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down |
|
156 | + while ($this->addMove($moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down |
|
157 | 157 | } |
158 | - else if($this->pieceID==self::BISHOP) { |
|
158 | + else if ($this->pieceID == self::BISHOP) { |
|
159 | 159 | $moveX = $this->x; |
160 | 160 | $moveY = $this->y; |
161 | - while($this->addMove(--$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
161 | + while ($this->addMove(--$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
162 | 162 | $moveX = $this->x; |
163 | 163 | $moveY = $this->y; |
164 | - while($this->addMove(++$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Right |
|
164 | + while ($this->addMove(++$moveX, --$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Right |
|
165 | 165 | $moveX = $this->x; |
166 | 166 | $moveY = $this->y; |
167 | - while($this->addMove(--$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down-Left |
|
167 | + while ($this->addMove(--$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Down-Left |
|
168 | 168 | $moveX = $this->x; |
169 | 169 | $moveY = $this->y; |
170 | - while($this->addMove(++$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
170 | + while ($this->addMove(++$moveX, ++$moveY, $board, $moves, $hasMoved, $attackingCheck) && $board[$moveY][$moveX] == null); //Up-Left |
|
171 | 171 | } |
172 | - else if($this->pieceID==self::KNIGHT) { |
|
173 | - $moveX = $this->x-1; |
|
174 | - $moveY = $this->y-2; |
|
175 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2up-left |
|
172 | + else if ($this->pieceID == self::KNIGHT) { |
|
173 | + $moveX = $this->x - 1; |
|
174 | + $moveY = $this->y - 2; |
|
175 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2up-left |
|
176 | 176 | $moveX += 2; |
177 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2up-right |
|
178 | - $moveY = $this->y+2; |
|
179 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2down-right |
|
177 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2up-right |
|
178 | + $moveY = $this->y + 2; |
|
179 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2down-right |
|
180 | 180 | $moveX -= 2; |
181 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2down-left |
|
182 | - $moveX = $this->x-2; |
|
183 | - $moveY = $this->y-1; |
|
184 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2left-up |
|
181 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2down-left |
|
182 | + $moveX = $this->x - 2; |
|
183 | + $moveY = $this->y - 1; |
|
184 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2left-up |
|
185 | 185 | $moveY += 2; |
186 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2left-down |
|
187 | - $moveX = $this->x+2; |
|
188 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2right-down |
|
186 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2left-down |
|
187 | + $moveX = $this->x + 2; |
|
188 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2right-down |
|
189 | 189 | $moveY -= 2; |
190 | - $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck);//2right-up |
|
190 | + $this->addMove($moveX, $moveY, $board, $moves, $hasMoved, $attackingCheck); //2right-up |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | } |
196 | 196 | |
197 | 197 | private function addMove($toX, $toY, array &$board, array &$moves, array &$hasMoved = null, $attackingCheck = true) { |
198 | - if(ChessGame::isValidCoord($toX, $toY, $board)) { |
|
199 | - if(($board[$toY][$toX] == null || $board[$toY][$toX]->colour!=$this->colour)) { |
|
198 | + if (ChessGame::isValidCoord($toX, $toY, $board)) { |
|
199 | + if (($board[$toY][$toX] == null || $board[$toY][$toX]->colour != $this->colour)) { |
|
200 | 200 | //We can only actually move to this position if it is safe to do so, however we can pass through it looking for a safe move so we still want to return true. |
201 | - if(($attackingCheck == true || $this->isSafeMove($board, $hasMoved, $toX, $toY))) { |
|
202 | - $moves[] = array($toX,$toY); |
|
201 | + if (($attackingCheck == true || $this->isSafeMove($board, $hasMoved, $toX, $toY))) { |
|
202 | + $moves[] = array($toX, $toY); |
|
203 | 203 | } |
204 | 204 | return true; |
205 | 205 | } |
@@ -208,30 +208,30 @@ discard block |
||
208 | 208 | } |
209 | 209 | |
210 | 210 | public function promote($pawnPromotionPieceID, array &$board) { |
211 | - if($pawnPromotionPieceID==null) { |
|
211 | + if ($pawnPromotionPieceID == null) { |
|
212 | 212 | throw new Exception('Promotion piece cannot be null on a promote.'); |
213 | 213 | } |
214 | 214 | $takenNos = array(); |
215 | - foreach($board as $row) { |
|
216 | - foreach($row as $piece) { |
|
217 | - if($piece != null && $piece->pieceID == $pawnPromotionPieceID && $piece->colour == $this->colour) { |
|
215 | + foreach ($board as $row) { |
|
216 | + foreach ($row as $piece) { |
|
217 | + if ($piece != null && $piece->pieceID == $pawnPromotionPieceID && $piece->colour == $this->colour) { |
|
218 | 218 | $takenNos[$piece->pieceNo] = true; |
219 | 219 | } |
220 | 220 | } |
221 | 221 | } |
222 | - $i=0; |
|
223 | - while(isset($takenNos[$i])) { |
|
222 | + $i = 0; |
|
223 | + while (isset($takenNos[$i])) { |
|
224 | 224 | $i++; |
225 | 225 | } |
226 | 226 | return array('PieceID' => $pawnPromotionPieceID, 'PieceNo' => $i); |
227 | 227 | } |
228 | 228 | |
229 | 229 | public function getPieceLetter() { |
230 | - return self::getLetterForPiece($this->pieceID,$this->colour); |
|
230 | + return self::getLetterForPiece($this->pieceID, $this->colour); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | public function getPieceSymbol() { |
234 | - return self::getSymbolForPiece($this->pieceID,$this->colour); |
|
234 | + return self::getSymbolForPiece($this->pieceID, $this->colour); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | public static function getSymbolForPiece($pieceID, $colour) { |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | } |
240 | 240 | |
241 | 241 | public static function getLetterForPiece($pieceID, $colour) { |
242 | - switch($pieceID) { |
|
242 | + switch ($pieceID) { |
|
243 | 243 | case self::KING: |
244 | 244 | $letter = 'k'; |
245 | 245 | break; |
@@ -260,14 +260,14 @@ discard block |
||
260 | 260 | $letter = 'p'; |
261 | 261 | break; |
262 | 262 | } |
263 | - if($colour == ChessGame::PLAYER_WHITE) { |
|
263 | + if ($colour == ChessGame::PLAYER_WHITE) { |
|
264 | 264 | $letter = strtoupper($letter); |
265 | 265 | } |
266 | 266 | return $letter; |
267 | 267 | } |
268 | 268 | |
269 | 269 | public static function getPieceForLetter($letter) { |
270 | - switch($letter) { |
|
270 | + switch ($letter) { |
|
271 | 271 | case 'k': |
272 | 272 | case 'K': |
273 | 273 | return self::KING; |
@@ -10,23 +10,23 @@ discard block |
||
10 | 10 | protected const USER_RANKINGS_SCORE = array( |
11 | 11 | // [Stat, a, b] |
12 | 12 | // Used as: pow(Stat * a, USER_RANKINGS_EACH_STAT_POW) * b |
13 | - array(array('Trade','Experience','Total'),.1,0.5), |
|
14 | - array(array('Trade','Money','Profit'),0.00005,0.5), |
|
15 | - array(array('Killing','Kills'),1000,1) |
|
13 | + array(array('Trade', 'Experience', 'Total'), .1, 0.5), |
|
14 | + array(array('Trade', 'Money', 'Profit'), 0.00005, 0.5), |
|
15 | + array(array('Killing', 'Kills'), 1000, 1) |
|
16 | 16 | ); |
17 | 17 | |
18 | 18 | protected static $CACHE_ACCOUNTS = array(); |
19 | 19 | protected const DEFAULT_HOTKEYS = array( |
20 | - 'MoveUp' => array('w','up'), |
|
21 | - 'ScanUp' => array('shift+w','shift+up'), |
|
22 | - 'MoveLeft' => array('a','left'), |
|
23 | - 'ScanLeft' => array('shift+a','shift+left'), |
|
24 | - 'MoveRight' => array('d','right'), |
|
25 | - 'ScanRight' => array('shift+d','shift+right'), |
|
26 | - 'MoveDown' => array('s','down'), |
|
27 | - 'ScanDown' => array('shift+s','shift+down'), |
|
28 | - 'MoveWarp' => array('e','0'), |
|
29 | - 'ScanWarp' => array('shift+e','shift+0'), |
|
20 | + 'MoveUp' => array('w', 'up'), |
|
21 | + 'ScanUp' => array('shift+w', 'shift+up'), |
|
22 | + 'MoveLeft' => array('a', 'left'), |
|
23 | + 'ScanLeft' => array('shift+a', 'shift+left'), |
|
24 | + 'MoveRight' => array('d', 'right'), |
|
25 | + 'ScanRight' => array('shift+d', 'shift+right'), |
|
26 | + 'MoveDown' => array('s', 'down'), |
|
27 | + 'ScanDown' => array('shift+s', 'shift+down'), |
|
28 | + 'MoveWarp' => array('e', '0'), |
|
29 | + 'ScanWarp' => array('shift+e', 'shift+0'), |
|
30 | 30 | 'ScanCurrent' => array('shift+1'), |
31 | 31 | 'CurrentSector' => array('1'), |
32 | 32 | 'LocalMap' => array('2'), |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | return self::DEFAULT_HOTKEYS; |
86 | 86 | } |
87 | 87 | |
88 | - public static function &getAccount($accountID,$forceUpdate = false) { |
|
89 | - if($forceUpdate || !isset(self::$CACHE_ACCOUNTS[$accountID])) { |
|
88 | + public static function &getAccount($accountID, $forceUpdate = false) { |
|
89 | + if ($forceUpdate || !isset(self::$CACHE_ACCOUNTS[$accountID])) { |
|
90 | 90 | self::$CACHE_ACCOUNTS[$accountID] = new SmrAccount($accountID); |
91 | 91 | } |
92 | 92 | return self::$CACHE_ACCOUNTS[$accountID]; |
@@ -95,17 +95,17 @@ discard block |
||
95 | 95 | public static function getAccountByName($login, $forceUpdate = false) { |
96 | 96 | if (empty($login)) { return null; } |
97 | 97 | $db = new SmrMySqlDatabase(); |
98 | - $db->query('SELECT account_id FROM account WHERE login = '.$db->escapeString($login).' LIMIT 1'); |
|
99 | - if($db->nextRecord()) |
|
100 | - return self::getAccount($db->getField('account_id'),$forceUpdate); |
|
98 | + $db->query('SELECT account_id FROM account WHERE login = ' . $db->escapeString($login) . ' LIMIT 1'); |
|
99 | + if ($db->nextRecord()) |
|
100 | + return self::getAccount($db->getField('account_id'), $forceUpdate); |
|
101 | 101 | $return = null; |
102 | 102 | return $return; |
103 | 103 | } |
104 | 104 | |
105 | - public static function getAccountByEmail($email, $forceUpdate=false) { |
|
105 | + public static function getAccountByEmail($email, $forceUpdate = false) { |
|
106 | 106 | if (empty($email)) { return null; } |
107 | 107 | $db = new SmrMySqlDatabase(); |
108 | - $db->query('SELECT account_id FROM account WHERE email = '.$db->escapeString($email).' LIMIT 1'); |
|
108 | + $db->query('SELECT account_id FROM account WHERE email = ' . $db->escapeString($email) . ' LIMIT 1'); |
|
109 | 109 | if ($db->nextRecord()) { |
110 | 110 | return self::getAccount($db->getInt('account_id'), $forceUpdate); |
111 | 111 | } else { |
@@ -113,10 +113,10 @@ discard block |
||
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | - public static function getAccountByDiscordId($id, $forceUpdate=false) { |
|
116 | + public static function getAccountByDiscordId($id, $forceUpdate = false) { |
|
117 | 117 | if (empty($id)) { return null; } |
118 | 118 | $db = new SmrMySqlDatabase(); |
119 | - $db->query('SELECT account_id FROM account where discord_id = '.$db->escapeString($id).' LIMIT 1'); |
|
119 | + $db->query('SELECT account_id FROM account where discord_id = ' . $db->escapeString($id) . ' LIMIT 1'); |
|
120 | 120 | if ($db->nextRecord()) { |
121 | 121 | return self::getAccount($db->getField('account_id'), $forceUpdate); |
122 | 122 | } else { |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | public static function getAccountByIrcNick($nick, $forceUpdate = false) { |
128 | 128 | if (empty($nick)) { return null; } |
129 | 129 | $db = new SmrMySqlDatabase(); |
130 | - $db->query('SELECT account_id FROM account WHERE irc_nick = '.$db->escapeString($nick).' LIMIT 1'); |
|
130 | + $db->query('SELECT account_id FROM account WHERE irc_nick = ' . $db->escapeString($nick) . ' LIMIT 1'); |
|
131 | 131 | if ($db->nextRecord()) { |
132 | 132 | return self::getAccount($db->getField('account_id'), $forceUpdate); |
133 | 133 | } else { |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
138 | - public static function getAccountBySocialLogin(SocialLogin $social, $forceUpdate=false) { |
|
138 | + public static function getAccountBySocialLogin(SocialLogin $social, $forceUpdate = false) { |
|
139 | 139 | if (!$social->isValid()) { return null; } |
140 | 140 | $db = new SmrMySqlDatabase(); |
141 | 141 | $db->query('SELECT account_id FROM account JOIN account_auth USING(account_id) |
142 | - WHERE login_type = '.$db->escapeString($social->getLoginType()).' |
|
143 | - AND auth_key = '.$db->escapeString($social->getUserID()).' LIMIT 1'); |
|
142 | + WHERE login_type = '.$db->escapeString($social->getLoginType()) . ' |
|
143 | + AND auth_key = '.$db->escapeString($social->getUserID()) . ' LIMIT 1'); |
|
144 | 144 | if ($db->nextRecord()) { |
145 | 145 | return self::getAccount($db->getInt('account_id'), $forceUpdate); |
146 | 146 | } else { |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | } |
150 | 150 | |
151 | 151 | public static function createAccount($login, $password, $email, $timez, $referral) { |
152 | - if($referral!=0) { |
|
152 | + if ($referral != 0) { |
|
153 | 153 | // Will throw if referral account doesn't exist |
154 | 154 | SmrAccount::getAccount($referral); |
155 | 155 | } |
@@ -157,60 +157,60 @@ discard block |
||
157 | 157 | $passwordHash = password_hash($password, PASSWORD_DEFAULT); |
158 | 158 | $db->query('INSERT INTO account (login, password, email, validation_code, last_login, offset,referral_id,hof_name) VALUES(' . |
159 | 159 | $db->escapeString($login) . ', ' . $db->escapeString($passwordHash) . ', ' . $db->escapeString($email) . ', ' . |
160 | - $db->escapeString(random_string(10)) . ',' . $db->escapeNumber(TIME) . ',' . $db->escapeNumber($timez) . ',' . $db->escapeNumber($referral).','.$db->escapeString($login).')'); |
|
160 | + $db->escapeString(random_string(10)) . ',' . $db->escapeNumber(TIME) . ',' . $db->escapeNumber($timez) . ',' . $db->escapeNumber($referral) . ',' . $db->escapeString($login) . ')'); |
|
161 | 161 | return self::getAccountByName($login); |
162 | 162 | } |
163 | 163 | |
164 | 164 | public static function getUserScoreCaseStatement($db) { |
165 | 165 | $userRankingTypes = array(); |
166 | 166 | $case = 'FLOOR(SUM(CASE type '; |
167 | - foreach(self::USER_RANKINGS_SCORE as $userRankingScore) { |
|
168 | - $userRankingType = $db->escapeArray($userRankingScore[0],false,false,':',false); |
|
167 | + foreach (self::USER_RANKINGS_SCORE as $userRankingScore) { |
|
168 | + $userRankingType = $db->escapeArray($userRankingScore[0], false, false, ':', false); |
|
169 | 169 | $userRankingTypes[] = $userRankingType; |
170 | - $case.= ' WHEN '.$db->escapeString($userRankingType).' THEN POW(amount*'.$userRankingScore[1].','.SmrAccount::USER_RANKINGS_EACH_STAT_POW.')*'.$userRankingScore[2]; |
|
170 | + $case .= ' WHEN ' . $db->escapeString($userRankingType) . ' THEN POW(amount*' . $userRankingScore[1] . ',' . SmrAccount::USER_RANKINGS_EACH_STAT_POW . ')*' . $userRankingScore[2]; |
|
171 | 171 | } |
172 | 172 | $case .= ' END))'; |
173 | - return array('CASE'=>$case,'IN'=>$db->escapeArray($userRankingTypes)); |
|
173 | + return array('CASE'=>$case, 'IN'=>$db->escapeArray($userRankingTypes)); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | function __construct($accountID) { |
177 | 177 | $this->db = new SmrMySqlDatabase(); |
178 | 178 | $this->SQL = 'account_id = ' . $this->db->escapeNumber($accountID); |
179 | - $this->db->query('SELECT * FROM account WHERE '.$this->SQL.' LIMIT 1'); |
|
179 | + $this->db->query('SELECT * FROM account WHERE ' . $this->SQL . ' LIMIT 1'); |
|
180 | 180 | |
181 | 181 | if ($this->db->nextRecord()) { |
182 | 182 | $row = $this->db->getRow(); |
183 | - $this->account_id = $row['account_id']; |
|
183 | + $this->account_id = $row['account_id']; |
|
184 | 184 | |
185 | 185 | $this->login = $row['login']; |
186 | - $this->passwordHash = $row['password']; |
|
186 | + $this->passwordHash = $row['password']; |
|
187 | 187 | $this->email = $row['email']; |
188 | - $this->validated = $this->db->getBoolean('validated'); |
|
188 | + $this->validated = $this->db->getBoolean('validated'); |
|
189 | 189 | |
190 | - $this->last_login = $row['last_login']; |
|
191 | - $this->validation_code = $row['validation_code']; |
|
192 | - $this->veteranForced = $this->db->getBoolean('veteran'); |
|
193 | - $this->logging = $this->db->getBoolean('logging'); |
|
190 | + $this->last_login = $row['last_login']; |
|
191 | + $this->validation_code = $row['validation_code']; |
|
192 | + $this->veteranForced = $this->db->getBoolean('veteran'); |
|
193 | + $this->logging = $this->db->getBoolean('logging'); |
|
194 | 194 | $this->offset = $row['offset']; |
195 | 195 | $this->images = $row['images']; |
196 | - $this->fontSize = $row['fontsize']; |
|
196 | + $this->fontSize = $row['fontsize']; |
|
197 | 197 | |
198 | - $this->passwordReset = $row['password_reset']; |
|
199 | - $this->useAJAX = $this->db->getBoolean('use_ajax'); |
|
200 | - $this->mailBanned = (int)$row['mail_banned']; |
|
198 | + $this->passwordReset = $row['password_reset']; |
|
199 | + $this->useAJAX = $this->db->getBoolean('use_ajax'); |
|
200 | + $this->mailBanned = (int)$row['mail_banned']; |
|
201 | 201 | |
202 | - $this->friendlyColour = $row['friendly_colour']; |
|
203 | - $this->neutralColour = $row['neutral_colour']; |
|
204 | - $this->enemyColour = $row['enemy_colour']; |
|
202 | + $this->friendlyColour = $row['friendly_colour']; |
|
203 | + $this->neutralColour = $row['neutral_colour']; |
|
204 | + $this->enemyColour = $row['enemy_colour']; |
|
205 | 205 | |
206 | - $this->cssLink = $row['css_link']; |
|
207 | - $this->defaultCSSEnabled = $this->db->getBoolean('default_css_enabled'); |
|
208 | - $this->centerGalaxyMapOnPlayer = $this->db->getBoolean('center_galaxy_map_on_player'); |
|
206 | + $this->cssLink = $row['css_link']; |
|
207 | + $this->defaultCSSEnabled = $this->db->getBoolean('default_css_enabled'); |
|
208 | + $this->centerGalaxyMapOnPlayer = $this->db->getBoolean('center_galaxy_map_on_player'); |
|
209 | 209 | |
210 | 210 | $this->messageNotifications = $this->db->getObject('message_notifications'); |
211 | 211 | $this->hotkeys = $this->db->getObject('hotkeys'); |
212 | - foreach(self::DEFAULT_HOTKEYS as $hotkey => $binding) { |
|
213 | - if(!isset($this->hotkeys[$hotkey])) { |
|
212 | + foreach (self::DEFAULT_HOTKEYS as $hotkey => $binding) { |
|
213 | + if (!isset($this->hotkeys[$hotkey])) { |
|
214 | 214 | $this->hotkeys[$hotkey] = $binding; |
215 | 215 | } |
216 | 216 | } |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | $this->oldAccountIDs[$databaseName] = $row[$oldColumn]; |
220 | 220 | } |
221 | 221 | |
222 | - $this->referrerID = $row['referral_id']; |
|
223 | - $this->maxRankAchieved = $row['max_rank_achieved']; |
|
222 | + $this->referrerID = $row['referral_id']; |
|
223 | + $this->maxRankAchieved = $row['max_rank_achieved']; |
|
224 | 224 | |
225 | 225 | $this->hofName = $row['hof_name']; |
226 | 226 | $this->discordId = $row['discord_id']; |
@@ -230,19 +230,19 @@ discard block |
||
230 | 230 | $this->timeShort = $row['time_short']; |
231 | 231 | |
232 | 232 | $this->template = $row['template']; |
233 | - $this->colourScheme = $row['colour_scheme']; |
|
233 | + $this->colourScheme = $row['colour_scheme']; |
|
234 | 234 | |
235 | - if(empty($this->hofName)) |
|
236 | - $this->hofName=$this->login; |
|
235 | + if (empty($this->hofName)) |
|
236 | + $this->hofName = $this->login; |
|
237 | 237 | } |
238 | 238 | else { |
239 | - throw new AccountNotFoundException('Account ID '.$accountID.' does not exist!'); |
|
239 | + throw new AccountNotFoundException('Account ID ' . $accountID . ' does not exist!'); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
243 | 243 | public function isDisabled() { |
244 | 244 | $this->db->query('SELECT * FROM account_is_closed JOIN closing_reason USING(reason_id) ' . |
245 | - 'WHERE '.$this->SQL.' LIMIT 1'); |
|
245 | + 'WHERE ' . $this->SQL . ' LIMIT 1'); |
|
246 | 246 | if ($this->db->nextRecord()) { |
247 | 247 | // get the expire time |
248 | 248 | $expireTime = $this->db->getInt('expires'); |
@@ -264,64 +264,64 @@ discard block |
||
264 | 264 | } |
265 | 265 | |
266 | 266 | function update() { |
267 | - $this->db->query('UPDATE account SET email = '.$this->db->escapeString($this->email). |
|
268 | - ', validation_code = '.$this->db->escapeString($this->validation_code). |
|
269 | - ', validated = '.$this->db->escapeBoolean($this->validated). |
|
270 | - ', password = '.$this->db->escapeString($this->passwordHash). |
|
271 | - ', images = '.$this->db->escapeString($this->images). |
|
272 | - ', password_reset = '.$this->db->escapeString($this->passwordReset). |
|
273 | - ', use_ajax='.$this->db->escapeBoolean($this->useAJAX). |
|
274 | - ', mail_banned='.$this->db->escapeNumber($this->mailBanned). |
|
275 | - ', max_rank_achieved='.$this->db->escapeNumber($this->maxRankAchieved). |
|
276 | - ', default_css_enabled='.$this->db->escapeBoolean($this->defaultCSSEnabled). |
|
277 | - ', center_galaxy_map_on_player='.$this->db->escapeBoolean($this->centerGalaxyMapOnPlayer). |
|
278 | - ', message_notifications='.$this->db->escapeObject($this->messageNotifications). |
|
279 | - ', hotkeys='.$this->db->escapeObject($this->hotkeys). |
|
280 | - ', last_login = '.$this->db->escapeNumber($this->last_login). |
|
281 | - ', logging = '.$this->db->escapeBoolean($this->logging). |
|
282 | - ', time_short = ' . $this->db->escapeString($this->timeShort). |
|
283 | - ', date_short = ' . $this->db->escapeString($this->dateShort). |
|
284 | - ', discord_id = ' . $this->db->escapeString($this->discordId, true, true). |
|
285 | - ', irc_nick = ' . $this->db->escapeString($this->ircNick, true, true). |
|
286 | - ', hof_name = ' . $this->db->escapeString($this->hofName). |
|
287 | - ', colour_scheme = ' . $this->db->escapeString($this->colourScheme). |
|
288 | - ', fontsize = ' . $this->db->escapeNumber($this->fontSize). |
|
289 | - ', css_link = ' . $this->db->escapeString($this->cssLink,true,true). |
|
290 | - ', friendly_colour = ' . $this->db->escapeString($this->friendlyColour, true, true). |
|
291 | - ', neutral_colour = ' . $this->db->escapeString($this->neutralColour, true, true). |
|
292 | - ', enemy_colour = ' . $this->db->escapeString($this->enemyColour, true, true). |
|
293 | - ' WHERE '.$this->SQL.' LIMIT 1'); |
|
267 | + $this->db->query('UPDATE account SET email = ' . $this->db->escapeString($this->email) . |
|
268 | + ', validation_code = ' . $this->db->escapeString($this->validation_code) . |
|
269 | + ', validated = ' . $this->db->escapeBoolean($this->validated) . |
|
270 | + ', password = ' . $this->db->escapeString($this->passwordHash) . |
|
271 | + ', images = ' . $this->db->escapeString($this->images) . |
|
272 | + ', password_reset = ' . $this->db->escapeString($this->passwordReset) . |
|
273 | + ', use_ajax=' . $this->db->escapeBoolean($this->useAJAX) . |
|
274 | + ', mail_banned=' . $this->db->escapeNumber($this->mailBanned) . |
|
275 | + ', max_rank_achieved=' . $this->db->escapeNumber($this->maxRankAchieved) . |
|
276 | + ', default_css_enabled=' . $this->db->escapeBoolean($this->defaultCSSEnabled) . |
|
277 | + ', center_galaxy_map_on_player=' . $this->db->escapeBoolean($this->centerGalaxyMapOnPlayer) . |
|
278 | + ', message_notifications=' . $this->db->escapeObject($this->messageNotifications) . |
|
279 | + ', hotkeys=' . $this->db->escapeObject($this->hotkeys) . |
|
280 | + ', last_login = ' . $this->db->escapeNumber($this->last_login) . |
|
281 | + ', logging = ' . $this->db->escapeBoolean($this->logging) . |
|
282 | + ', time_short = ' . $this->db->escapeString($this->timeShort) . |
|
283 | + ', date_short = ' . $this->db->escapeString($this->dateShort) . |
|
284 | + ', discord_id = ' . $this->db->escapeString($this->discordId, true, true) . |
|
285 | + ', irc_nick = ' . $this->db->escapeString($this->ircNick, true, true) . |
|
286 | + ', hof_name = ' . $this->db->escapeString($this->hofName) . |
|
287 | + ', colour_scheme = ' . $this->db->escapeString($this->colourScheme) . |
|
288 | + ', fontsize = ' . $this->db->escapeNumber($this->fontSize) . |
|
289 | + ', css_link = ' . $this->db->escapeString($this->cssLink, true, true) . |
|
290 | + ', friendly_colour = ' . $this->db->escapeString($this->friendlyColour, true, true) . |
|
291 | + ', neutral_colour = ' . $this->db->escapeString($this->neutralColour, true, true) . |
|
292 | + ', enemy_colour = ' . $this->db->escapeString($this->enemyColour, true, true) . |
|
293 | + ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
294 | 294 | $this->hasChanged = false; |
295 | 295 | } |
296 | 296 | |
297 | 297 | function updateIP() { |
298 | 298 | $curr_ip = getIpAddress(); |
299 | - $this->log(LOG_TYPE_LOGIN, 'logged in from '.$curr_ip); |
|
299 | + $this->log(LOG_TYPE_LOGIN, 'logged in from ' . $curr_ip); |
|
300 | 300 | |
301 | 301 | // more than 50 elements in it? |
302 | 302 | |
303 | - $this->db->query('SELECT time,ip FROM account_has_ip WHERE '.$this->SQL.' ORDER BY time ASC'); |
|
303 | + $this->db->query('SELECT time,ip FROM account_has_ip WHERE ' . $this->SQL . ' ORDER BY time ASC'); |
|
304 | 304 | if ($this->db->getNumRows() > 50 && $this->db->nextRecord()) { |
305 | 305 | $delete_time = $this->db->getField('time'); |
306 | 306 | $delete_ip = $this->db->getField('ip'); |
307 | 307 | |
308 | 308 | $this->db->query('DELETE FROM account_has_ip |
309 | - WHERE '.$this->SQL.' AND |
|
310 | - time = '.$this->db->escapeNumber($delete_time).' AND |
|
309 | + WHERE '.$this->SQL . ' AND |
|
310 | + time = '.$this->db->escapeNumber($delete_time) . ' AND |
|
311 | 311 | ip = '.$this->db->escapeString($delete_ip)); |
312 | 312 | } |
313 | - list($fi,$se,$th,$fo) = preg_split('/[.\s,]/', $curr_ip, 4); |
|
313 | + list($fi, $se, $th, $fo) = preg_split('/[.\s,]/', $curr_ip, 4); |
|
314 | 314 | if ($curr_ip != 'unknown' && $curr_ip != 'unknown...' && $curr_ip != 'unknown, unknown') { |
315 | - $curr_ip = $fi.'.'.$se.'.'.$th.'.'.$fo; |
|
315 | + $curr_ip = $fi . '.' . $se . '.' . $th . '.' . $fo; |
|
316 | 316 | $host = gethostbyaddr($curr_ip); |
317 | 317 | } else $host = 'unknown'; |
318 | 318 | |
319 | 319 | // save...first make sure there isn't one for these keys (someone could double click and get error) |
320 | - $this->db->query('REPLACE INTO account_has_ip (account_id, time, ip, host) VALUES ('.$this->db->escapeNumber($this->account_id).', '.$this->db->escapeNumber(TIME).', '.$this->db->escapeString($curr_ip).', '.$this->db->escapeString($host).')'); |
|
320 | + $this->db->query('REPLACE INTO account_has_ip (account_id, time, ip, host) VALUES (' . $this->db->escapeNumber($this->account_id) . ', ' . $this->db->escapeNumber(TIME) . ', ' . $this->db->escapeString($curr_ip) . ', ' . $this->db->escapeString($host) . ')'); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | public function updateLastLogin() { |
324 | - if($this->last_login == TIME) |
|
324 | + if ($this->last_login == TIME) |
|
325 | 325 | return; |
326 | 326 | $this->last_login = TIME; |
327 | 327 | $this->hasChanged = true; |
@@ -333,9 +333,9 @@ discard block |
||
333 | 333 | } |
334 | 334 | |
335 | 335 | public function setLoggingEnabled($bool) { |
336 | - if($this->logging==$bool) |
|
336 | + if ($this->logging == $bool) |
|
337 | 337 | return; |
338 | - $this->logging=$bool; |
|
338 | + $this->logging = $bool; |
|
339 | 339 | $this->hasChanged = true; |
340 | 340 | $this->update(); |
341 | 341 | } |
@@ -355,26 +355,26 @@ discard block |
||
355 | 355 | } |
356 | 356 | |
357 | 357 | public function isNPC() { |
358 | - if(!isset($this->npc)) { |
|
359 | - $this->db->query('SELECT login FROM npc_logins WHERE login = '.$this->db->escapeString($this->getLogin()).' LIMIT 1;'); |
|
358 | + if (!isset($this->npc)) { |
|
359 | + $this->db->query('SELECT login FROM npc_logins WHERE login = ' . $this->db->escapeString($this->getLogin()) . ' LIMIT 1;'); |
|
360 | 360 | $this->npc = $this->db->nextRecord(); |
361 | 361 | } |
362 | 362 | return $this->npc; |
363 | 363 | } |
364 | 364 | |
365 | 365 | protected function getHOFData() { |
366 | - if(!isset($this->HOF)) { |
|
366 | + if (!isset($this->HOF)) { |
|
367 | 367 | //Get Player HOF |
368 | 368 | $this->db->query('SELECT type,sum(amount) as amount FROM player_hof WHERE ' . $this->SQL . ' AND game_id IN (SELECT game_id FROM game WHERE ignore_stats = \'FALSE\') GROUP BY type'); |
369 | 369 | $this->HOF = array(); |
370 | - while($this->db->nextRecord()) { |
|
371 | - $hof =& $this->HOF; |
|
372 | - $typeList = explode(':',$this->db->getField('type')); |
|
373 | - foreach($typeList as $type) { |
|
374 | - if(!isset($hof[$type])) { |
|
370 | + while ($this->db->nextRecord()) { |
|
371 | + $hof = & $this->HOF; |
|
372 | + $typeList = explode(':', $this->db->getField('type')); |
|
373 | + foreach ($typeList as $type) { |
|
374 | + if (!isset($hof[$type])) { |
|
375 | 375 | $hof[$type] = array(); |
376 | 376 | } |
377 | - $hof =& $hof[$type]; |
|
377 | + $hof = & $hof[$type]; |
|
378 | 378 | } |
379 | 379 | $hof = $this->db->getField('amount'); |
380 | 380 | } |
@@ -383,11 +383,11 @@ discard block |
||
383 | 383 | |
384 | 384 | public function getHOF(array $typeList = null) { |
385 | 385 | $this->getHOFData(); |
386 | - if($typeList==null) |
|
386 | + if ($typeList == null) |
|
387 | 387 | return $this->HOF; |
388 | - $hof=$this->HOF; |
|
389 | - foreach($typeList as $type) { |
|
390 | - if(!isset($hof[$type])) |
|
388 | + $hof = $this->HOF; |
|
389 | + foreach ($typeList as $type) { |
|
390 | + if (!isset($hof[$type])) |
|
391 | 391 | return 0; |
392 | 392 | $hof = $hof[$type]; |
393 | 393 | } |
@@ -396,58 +396,58 @@ discard block |
||
396 | 396 | |
397 | 397 | function getRankName() { |
398 | 398 | $rankings = Globals::getUserRanking(); |
399 | - if(isset($rankings[$this->getRank()])) |
|
399 | + if (isset($rankings[$this->getRank()])) |
|
400 | 400 | return $rankings[$this->getRank()]; |
401 | 401 | else |
402 | 402 | return end($rankings); |
403 | 403 | } |
404 | 404 | |
405 | 405 | public function getScore() { |
406 | - if(!isset($this->score)) { |
|
407 | - $score=0; |
|
408 | - foreach($this->getIndividualScores() as $each) { |
|
409 | - $score+=$each['Score']; |
|
406 | + if (!isset($this->score)) { |
|
407 | + $score = 0; |
|
408 | + foreach ($this->getIndividualScores() as $each) { |
|
409 | + $score += $each['Score']; |
|
410 | 410 | } |
411 | - $this->score=round($score); |
|
411 | + $this->score = round($score); |
|
412 | 412 | } |
413 | 413 | return $this->score; |
414 | 414 | } |
415 | 415 | |
416 | 416 | public function &getIndividualScores(SmrPlayer $player = null) { |
417 | - $gameID=0; |
|
418 | - if($player!=null) |
|
417 | + $gameID = 0; |
|
418 | + if ($player != null) |
|
419 | 419 | $gameID = $player->getGameID(); |
420 | - if(!isset($this->individualScores[$gameID])) { |
|
420 | + if (!isset($this->individualScores[$gameID])) { |
|
421 | 421 | $this->individualScores[$gameID] = array(); |
422 | - foreach(self::USER_RANKINGS_SCORE as $statScore) { |
|
423 | - if($player==null) |
|
422 | + foreach (self::USER_RANKINGS_SCORE as $statScore) { |
|
423 | + if ($player == null) |
|
424 | 424 | $stat = $this->getHOF($statScore[0]); |
425 | 425 | else |
426 | 426 | $stat = $player->getHOF($statScore[0]); |
427 | - $this->individualScores[$gameID][]=array('Stat'=>$statScore[0],'Score'=>pow($stat*$statScore[1],self::USER_RANKINGS_EACH_STAT_POW)*$statScore[2]); |
|
427 | + $this->individualScores[$gameID][] = array('Stat'=>$statScore[0], 'Score'=>pow($stat * $statScore[1], self::USER_RANKINGS_EACH_STAT_POW) * $statScore[2]); |
|
428 | 428 | } |
429 | 429 | } |
430 | 430 | return $this->individualScores[$gameID]; |
431 | 431 | } |
432 | 432 | |
433 | 433 | public function getRank() { |
434 | - $rank = ceil(pow($this->getScore(),self::USER_RANKINGS_TOTAL_SCORE_POW)/self::USER_RANKINGS_RANK_BOUNDARY); |
|
435 | - if($rank<1) |
|
436 | - $rank=1; |
|
437 | - if($rank > $this->maxRankAchieved) |
|
434 | + $rank = ceil(pow($this->getScore(), self::USER_RANKINGS_TOTAL_SCORE_POW) / self::USER_RANKINGS_RANK_BOUNDARY); |
|
435 | + if ($rank < 1) |
|
436 | + $rank = 1; |
|
437 | + if ($rank > $this->maxRankAchieved) |
|
438 | 438 | $this->updateMaxRankAchieved($rank); |
439 | 439 | return $rank; |
440 | 440 | } |
441 | 441 | |
442 | 442 | protected function updateMaxRankAchieved($rank) { |
443 | - if($rank <= $this->maxRankAchieved) |
|
443 | + if ($rank <= $this->maxRankAchieved) |
|
444 | 444 | throw new Exception('Trying to set max rank achieved to a lower value: ' . $rank); |
445 | 445 | $delta = $rank - $this->maxRankAchieved; |
446 | - if($this->hasReferrer()) { |
|
446 | + if ($this->hasReferrer()) { |
|
447 | 447 | $this->getReferrer()->increaseSmrRewardCredits($delta * CREDITS_PER_DOLLAR); |
448 | 448 | } |
449 | - $this->maxRankAchieved+=$delta; |
|
450 | - $this->hasChanged=true; |
|
449 | + $this->maxRankAchieved += $delta; |
|
450 | + $this->hasChanged = true; |
|
451 | 451 | $this->update(); |
452 | 452 | } |
453 | 453 | |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | } |
457 | 457 | |
458 | 458 | public function hasReferrer() { |
459 | - return $this->referrerID>0; |
|
459 | + return $this->referrerID > 0; |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | public function &getReferrer() { |
@@ -467,15 +467,15 @@ discard block |
||
467 | 467 | if ($this->isLoggingEnabled()) { |
468 | 468 | $this->db->query('INSERT INTO account_has_logs ' . |
469 | 469 | '(account_id, microtime, log_type_id, message, sector_id) ' . |
470 | - 'VALUES('.$this->db->escapeNumber($this->account_id).', '. $this->db->escapeMicrotime(MICRO_TIME) . ', '.$this->db->escapeNumber($log_type_id).', ' . $this->db->escapeString($msg) . ', '.$this->db->escapeNumber($sector_id).')'); |
|
470 | + 'VALUES(' . $this->db->escapeNumber($this->account_id) . ', ' . $this->db->escapeMicrotime(MICRO_TIME) . ', ' . $this->db->escapeNumber($log_type_id) . ', ' . $this->db->escapeString($msg) . ', ' . $this->db->escapeNumber($sector_id) . ')'); |
|
471 | 471 | } |
472 | 472 | } |
473 | 473 | |
474 | 474 | protected function getSmrCreditsData() { |
475 | - if(!isset($this->credits)||!isset($this->rewardCredits)) { |
|
475 | + if (!isset($this->credits) || !isset($this->rewardCredits)) { |
|
476 | 476 | $this->credits = 0; |
477 | 477 | $this->rewardCredits = 0; |
478 | - $this->db->query('SELECT * FROM account_has_credits WHERE '.$this->SQL.' LIMIT 1'); |
|
478 | + $this->db->query('SELECT * FROM account_has_credits WHERE ' . $this->SQL . ' LIMIT 1'); |
|
479 | 479 | if ($this->db->nextRecord()) { |
480 | 480 | $this->credits = $this->db->getInt('credits_left'); |
481 | 481 | $this->rewardCredits = $this->db->getInt('reward_credits'); |
@@ -488,26 +488,26 @@ discard block |
||
488 | 488 | } |
489 | 489 | |
490 | 490 | public function decreaseTotalSmrCredits($totalCredits) { |
491 | - if($totalCredits==0) |
|
491 | + if ($totalCredits == 0) |
|
492 | 492 | return; |
493 | - if($totalCredits<0) |
|
493 | + if ($totalCredits < 0) |
|
494 | 494 | throw new Exception('You cannot use negative total credits'); |
495 | - if($totalCredits>$this->getTotalSmrCredits()) |
|
495 | + if ($totalCredits > $this->getTotalSmrCredits()) |
|
496 | 496 | throw new Exception('You do not have that many credits in total to use'); |
497 | 497 | |
498 | - $rewardCredits=$this->rewardCredits; |
|
499 | - $credits=$this->credits; |
|
500 | - $rewardCredits-=$totalCredits; |
|
501 | - if($rewardCredits<0) { |
|
502 | - $credits+=$rewardCredits; |
|
503 | - $rewardCredits=0; |
|
498 | + $rewardCredits = $this->rewardCredits; |
|
499 | + $credits = $this->credits; |
|
500 | + $rewardCredits -= $totalCredits; |
|
501 | + if ($rewardCredits < 0) { |
|
502 | + $credits += $rewardCredits; |
|
503 | + $rewardCredits = 0; |
|
504 | 504 | } |
505 | - if($this->credits==0 && $this->rewardCredits==0) |
|
506 | - $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).','.$this->db->escapeNumber($rewardCredits).')'); |
|
505 | + if ($this->credits == 0 && $this->rewardCredits == 0) |
|
506 | + $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left, reward_credits) VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($credits) . ',' . $this->db->escapeNumber($rewardCredits) . ')'); |
|
507 | 507 | else |
508 | - $this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).', reward_credits='.$this->db->escapeNumber($rewardCredits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
509 | - $this->credits=$credits; |
|
510 | - $this->rewardCredits=$rewardCredits; |
|
508 | + $this->db->query('UPDATE account_has_credits SET credits_left=' . $this->db->escapeNumber($credits) . ', reward_credits=' . $this->db->escapeNumber($rewardCredits) . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
509 | + $this->credits = $credits; |
|
510 | + $this->rewardCredits = $rewardCredits; |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | public function getSmrCredits() { |
@@ -521,49 +521,49 @@ discard block |
||
521 | 521 | } |
522 | 522 | |
523 | 523 | public function setSmrCredits($credits) { |
524 | - if($this->getSmrCredits()==$credits) |
|
524 | + if ($this->getSmrCredits() == $credits) |
|
525 | 525 | return; |
526 | - if($this->credits==0 && $this->rewardCredits==0) |
|
527 | - $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')'); |
|
526 | + if ($this->credits == 0 && $this->rewardCredits == 0) |
|
527 | + $this->db->query('REPLACE INTO account_has_credits (account_id, credits_left) VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($credits) . ')'); |
|
528 | 528 | else |
529 | - $this->db->query('UPDATE account_has_credits SET credits_left='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
530 | - $this->credits=$credits; |
|
529 | + $this->db->query('UPDATE account_has_credits SET credits_left=' . $this->db->escapeNumber($credits) . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
530 | + $this->credits = $credits; |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | public function increaseSmrCredits($credits) { |
534 | - if($credits==0) |
|
534 | + if ($credits == 0) |
|
535 | 535 | return; |
536 | - if($credits<0) |
|
536 | + if ($credits < 0) |
|
537 | 537 | throw new Exception('You cannot gain negative credits'); |
538 | - $this->setSmrCredits($this->getSmrCredits()+$credits); |
|
538 | + $this->setSmrCredits($this->getSmrCredits() + $credits); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | public function decreaseSmrCredits($credits) { |
542 | - if($credits==0) |
|
542 | + if ($credits == 0) |
|
543 | 543 | return; |
544 | - if($credits<0) |
|
544 | + if ($credits < 0) |
|
545 | 545 | throw new Exception('You cannot use negative credits'); |
546 | - if($credits>$this->getSmrCredits()) |
|
546 | + if ($credits > $this->getSmrCredits()) |
|
547 | 547 | throw new Exception('You cannot use more credits than you have'); |
548 | - $this->setSmrCredits($this->getSmrCredits()-$credits); |
|
548 | + $this->setSmrCredits($this->getSmrCredits() - $credits); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | public function setSmrRewardCredits($credits) { |
552 | - if($this->getSmrRewardCredits()==$credits) |
|
552 | + if ($this->getSmrRewardCredits() == $credits) |
|
553 | 553 | return; |
554 | - if($this->credits==0 && $this->rewardCredits==0) |
|
555 | - $this->db->query('REPLACE INTO account_has_credits (account_id, reward_credits) VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($credits).')'); |
|
554 | + if ($this->credits == 0 && $this->rewardCredits == 0) |
|
555 | + $this->db->query('REPLACE INTO account_has_credits (account_id, reward_credits) VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($credits) . ')'); |
|
556 | 556 | else |
557 | - $this->db->query('UPDATE account_has_credits SET reward_credits='.$this->db->escapeNumber($credits).' WHERE '.$this->SQL.' LIMIT 1'); |
|
558 | - $this->rewardCredits=$credits; |
|
557 | + $this->db->query('UPDATE account_has_credits SET reward_credits=' . $this->db->escapeNumber($credits) . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
558 | + $this->rewardCredits = $credits; |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | public function increaseSmrRewardCredits($credits) { |
562 | - if($credits==0) |
|
562 | + if ($credits == 0) |
|
563 | 563 | return; |
564 | - if($credits<0) |
|
564 | + if ($credits < 0) |
|
565 | 565 | throw new Exception('You cannot gain negative reward credits'); |
566 | - $this->setSmrRewardCredits($this->getSmrRewardCredits()+$credits); |
|
566 | + $this->setSmrRewardCredits($this->getSmrRewardCredits() + $credits); |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | public function sendMessageToBox($boxTypeID, $message) { |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | self::doMessageSendingToBox($this->getAccountID(), $boxTypeID, $message); |
572 | 572 | } |
573 | 573 | |
574 | - public static function doMessageSendingToBox($senderID, $boxTypeID, $message, $gameID=0) { |
|
574 | + public static function doMessageSendingToBox($senderID, $boxTypeID, $message, $gameID = 0) { |
|
575 | 575 | $db = new SmrMySqlDatabase(); |
576 | 576 | // send him the message |
577 | 577 | $db->query('INSERT INTO message_boxes |
@@ -594,13 +594,13 @@ discard block |
||
594 | 594 | } |
595 | 595 | |
596 | 596 | public function getOldAccountID($dbName) { |
597 | - return isset($this->oldAccountIDs[$dbName])?$this->oldAccountIDs[$dbName]:0; |
|
597 | + return isset($this->oldAccountIDs[$dbName]) ? $this->oldAccountIDs[$dbName] : 0; |
|
598 | 598 | } |
599 | 599 | |
600 | - public function hasOldAccountID($dbName=false) { |
|
601 | - if($dbName===false) |
|
602 | - return count($this->getOldAccountIDs())!=0; |
|
603 | - return $this->getOldAccountID($dbName)!=0; |
|
600 | + public function hasOldAccountID($dbName = false) { |
|
601 | + if ($dbName === false) |
|
602 | + return count($this->getOldAccountIDs()) != 0; |
|
603 | + return $this->getOldAccountID($dbName) != 0; |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | public function getLogin() { |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | } |
613 | 613 | |
614 | 614 | public function setEmail($email) { |
615 | - if($this->email==$email) { |
|
615 | + if ($this->email == $email) { |
|
616 | 616 | return; |
617 | 617 | } |
618 | 618 | $this->email = $email; |
@@ -629,14 +629,14 @@ discard block |
||
629 | 629 | |
630 | 630 | // check if the host got a MX or at least an A entry |
631 | 631 | if (!checkdnsrr($host, 'MX') && !checkdnsrr($host, 'A')) { |
632 | - create_error('This is not a valid email address! The domain '.$host.' does not exist.'); |
|
632 | + create_error('This is not a valid email address! The domain ' . $host . ' does not exist.'); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | if (strstr($email, ' ')) { |
636 | 636 | create_error('The email is invalid! It cannot contain any spaces.'); |
637 | 637 | } |
638 | 638 | |
639 | - $this->db->query('SELECT 1 FROM account WHERE email = '.$this->db->escapeString($email).' and account_id != ' . $this->db->escapeNumber($this->getAccountID()) . ' LIMIT 1'); |
|
639 | + $this->db->query('SELECT 1 FROM account WHERE email = ' . $this->db->escapeString($email) . ' and account_id != ' . $this->db->escapeNumber($this->getAccountID()) . ' LIMIT 1'); |
|
640 | 640 | if ($this->db->getNumRows() > 0) { |
641 | 641 | create_error('This email address is already registered.'); |
642 | 642 | } |
@@ -647,12 +647,12 @@ discard block |
||
647 | 647 | |
648 | 648 | // remember when we sent validation code |
649 | 649 | $this->db->query('REPLACE INTO notification (notification_type, account_id, time) |
650 | - VALUES(\'validation_code\', '.$this->db->escapeNumber($this->getAccountID()).', ' . $this->db->escapeNumber(TIME) . ')'); |
|
650 | + VALUES(\'validation_code\', '.$this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber(TIME) . ')'); |
|
651 | 651 | |
652 | 652 | $emailMessage = |
653 | - 'You changed your email address registered with SMR and need to revalidate now!'.EOL.EOL. |
|
654 | - ' Your new validation code is: '.$this->getValidationCode().EOL.EOL. |
|
655 | - 'The Space Merchant Realms server is on the web at '.URL; |
|
653 | + 'You changed your email address registered with SMR and need to revalidate now!' . EOL . EOL . |
|
654 | + ' Your new validation code is: ' . $this->getValidationCode() . EOL . EOL . |
|
655 | + 'The Space Merchant Realms server is on the web at ' . URL; |
|
656 | 656 | |
657 | 657 | $mail = setupMailer(); |
658 | 658 | $mail->Subject = 'Your validation code!'; |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | } |
679 | 679 | |
680 | 680 | public function setFontSize($size) { |
681 | - if($this->fontSize==$size) |
|
681 | + if ($this->fontSize == $size) |
|
682 | 682 | return; |
683 | 683 | $this->fontSize = $size; |
684 | 684 | $this->hasChanged = true; |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | |
693 | 693 | // sets the extra CSS file linked in preferences |
694 | 694 | public function setCssLink($link) { |
695 | - if($this->cssLink==$link) |
|
695 | + if ($this->cssLink == $link) |
|
696 | 696 | return; |
697 | 697 | $this->cssLink = $link; |
698 | 698 | $this->hasChanged = true; |
@@ -704,11 +704,11 @@ discard block |
||
704 | 704 | } |
705 | 705 | |
706 | 706 | public function setTemplate($template) { |
707 | - if($this->template==$template) |
|
707 | + if ($this->template == $template) |
|
708 | 708 | return; |
709 | - if(!in_array($template,array_keys(Globals::getAvailableTemplates()))) |
|
710 | - throw new Exception('Template not allowed: '.$template); |
|
711 | - $this->db->query('UPDATE account SET template = ' . $this->db->escapeString($template) . ' WHERE '.$this->SQL.' LIMIT 1'); |
|
709 | + if (!in_array($template, array_keys(Globals::getAvailableTemplates()))) |
|
710 | + throw new Exception('Template not allowed: ' . $template); |
|
711 | + $this->db->query('UPDATE account SET template = ' . $this->db->escapeString($template) . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
712 | 712 | $this->template = $template; |
713 | 713 | $colourSchemes = Globals::getAvailableColourSchemes($template); |
714 | 714 | $this->setColourScheme($colourSchemes[0]); |
@@ -719,10 +719,10 @@ discard block |
||
719 | 719 | } |
720 | 720 | |
721 | 721 | public function setColourScheme($colourScheme) { |
722 | - if($this->colourScheme==$colourScheme) |
|
722 | + if ($this->colourScheme == $colourScheme) |
|
723 | 723 | return; |
724 | - if(!in_array($colourScheme,array_keys(Globals::getAvailableColourSchemes($this->getTemplate())))) |
|
725 | - throw new Exception('Colour scheme not allowed: '.$colourScheme); |
|
724 | + if (!in_array($colourScheme, array_keys(Globals::getAvailableColourSchemes($this->getTemplate())))) |
|
725 | + throw new Exception('Colour scheme not allowed: ' . $colourScheme); |
|
726 | 726 | $this->colourScheme = $colourScheme; |
727 | 727 | $this->hasChanged = true; |
728 | 728 | $this->update(); |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | return CSS_COLOUR_URLS[$this->getTemplate()][$this->getColourScheme()]; |
739 | 739 | } |
740 | 740 | |
741 | - public function getHofName($linked=false) { |
|
741 | + public function getHofName($linked = false) { |
|
742 | 742 | if ($linked) { |
743 | 743 | return '<a href="' . $this->getPersonalHofHREF() . '">' . $this->hofName . '</a>'; |
744 | 744 | } else { |
@@ -747,7 +747,7 @@ discard block |
||
747 | 747 | } |
748 | 748 | |
749 | 749 | public function setHofName($name) { |
750 | - if($this->hofName==$name) |
|
750 | + if ($this->hofName == $name) |
|
751 | 751 | return; |
752 | 752 | $this->hofName = $name; |
753 | 753 | $this->hasChanged = true; |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | } |
760 | 760 | |
761 | 761 | public function setIrcNick($nick) { |
762 | - if($this->ircNick==$nick) |
|
762 | + if ($this->ircNick == $nick) |
|
763 | 763 | return; |
764 | 764 | $this->ircNick = $nick; |
765 | 765 | $this->hasChanged = true; |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | } |
781 | 781 | |
782 | 782 | public function getReferralLink() { |
783 | - return URL . '/login_create.php?ref='.$this->getAccountID(); |
|
783 | + return URL . '/login_create.php?ref=' . $this->getAccountID(); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | public function getShortDateFormat() { |
@@ -788,7 +788,7 @@ discard block |
||
788 | 788 | } |
789 | 789 | |
790 | 790 | public function setShortDateFormat($format) { |
791 | - if($this->dateShort==$format) |
|
791 | + if ($this->dateShort == $format) |
|
792 | 792 | return; |
793 | 793 | $this->dateShort = $format; |
794 | 794 | $this->hasChanged = true; |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | } |
801 | 801 | |
802 | 802 | public function setShortTimeFormat($format) { |
803 | - if($this->timeShort==$format) |
|
803 | + if ($this->timeShort == $format) |
|
804 | 804 | return; |
805 | 805 | $this->timeShort = $format; |
806 | 806 | $this->hasChanged = true; |
@@ -812,15 +812,15 @@ discard block |
||
812 | 812 | } |
813 | 813 | |
814 | 814 | protected function setValidationCode($code) { |
815 | - if($this->validation_code == $code) |
|
815 | + if ($this->validation_code == $code) |
|
816 | 816 | return; |
817 | - $this->validation_code=$code; |
|
818 | - $this->hasChanged=true; |
|
817 | + $this->validation_code = $code; |
|
818 | + $this->hasChanged = true; |
|
819 | 819 | $this->update(); |
820 | 820 | } |
821 | 821 | |
822 | 822 | public function setValidated($bool) { |
823 | - if($this->validated == $bool) |
|
823 | + if ($this->validated == $bool) |
|
824 | 824 | return; |
825 | 825 | $this->validated = $bool; |
826 | 826 | $this->hasChanged = true; |
@@ -832,7 +832,7 @@ discard block |
||
832 | 832 | } |
833 | 833 | |
834 | 834 | public function isLoggedIn() { |
835 | - $this->db->query('SELECT 1 FROM active_session WHERE account_id = '.$this->db->escapeNumber($this->getAccountID()).' LIMIT 1'); |
|
835 | + $this->db->query('SELECT 1 FROM active_session WHERE account_id = ' . $this->db->escapeNumber($this->getAccountID()) . ' LIMIT 1'); |
|
836 | 836 | return $this->db->nextRecord(); |
837 | 837 | } |
838 | 838 | |
@@ -873,15 +873,15 @@ discard block |
||
873 | 873 | $this->update(); |
874 | 874 | } |
875 | 875 | |
876 | - public function addAuthMethod($loginType,$authKey) { |
|
877 | - $this->db->query('SELECT account_id FROM account_auth WHERE login_type='.$this->db->escapeString($loginType).' AND auth_key = '.$this->db->escapeString($authKey).';'); |
|
878 | - if($this->db->nextRecord()) { |
|
879 | - if($this->db->getInt('account_id')!=$this->getAccountID()) { |
|
876 | + public function addAuthMethod($loginType, $authKey) { |
|
877 | + $this->db->query('SELECT account_id FROM account_auth WHERE login_type=' . $this->db->escapeString($loginType) . ' AND auth_key = ' . $this->db->escapeString($authKey) . ';'); |
|
878 | + if ($this->db->nextRecord()) { |
|
879 | + if ($this->db->getInt('account_id') != $this->getAccountID()) { |
|
880 | 880 | throw new Exception('Another account already uses this form of auth.'); |
881 | 881 | } |
882 | 882 | return true; |
883 | 883 | } |
884 | - $this->db->query('INSERT INTO account_auth values ('.$this->db->escapeNumber($this->getAccountID()).','.$this->db->escapeString($loginType).','.$this->db->escapeString($authKey).');'); |
|
884 | + $this->db->query('INSERT INTO account_auth values (' . $this->db->escapeNumber($this->getAccountID()) . ',' . $this->db->escapeString($loginType) . ',' . $this->db->escapeString($authKey) . ');'); |
|
885 | 885 | return true; |
886 | 886 | } |
887 | 887 | |
@@ -894,10 +894,10 @@ discard block |
||
894 | 894 | } |
895 | 895 | |
896 | 896 | protected function setPasswordReset($passwordReset) { |
897 | - if($this->passwordReset == $passwordReset) |
|
897 | + if ($this->passwordReset == $passwordReset) |
|
898 | 898 | return; |
899 | - $this->passwordReset=$passwordReset; |
|
900 | - $this->hasChanged=true; |
|
899 | + $this->passwordReset = $passwordReset; |
|
900 | + $this->hasChanged = true; |
|
901 | 901 | $this->update(); |
902 | 902 | } |
903 | 903 | |
@@ -906,7 +906,7 @@ discard block |
||
906 | 906 | } |
907 | 907 | |
908 | 908 | public function setDisplayShipImages($yesNo) { |
909 | - if($this->images == $yesNo) |
|
909 | + if ($this->images == $yesNo) |
|
910 | 910 | return; |
911 | 911 | $this->images = $yesNo; |
912 | 912 | $this->hasChanged = true; |
@@ -918,10 +918,10 @@ discard block |
||
918 | 918 | } |
919 | 919 | |
920 | 920 | public function setUseAJAX($bool) { |
921 | - if($this->useAJAX == $bool) |
|
921 | + if ($this->useAJAX == $bool) |
|
922 | 922 | return; |
923 | - $this->useAJAX=$bool; |
|
924 | - $this->hasChanged=true; |
|
923 | + $this->useAJAX = $bool; |
|
924 | + $this->hasChanged = true; |
|
925 | 925 | $this->update(); |
926 | 926 | } |
927 | 927 | |
@@ -930,16 +930,16 @@ discard block |
||
930 | 930 | } |
931 | 931 | |
932 | 932 | public function setDefaultCSSEnabled($bool) { |
933 | - if($this->defaultCSSEnabled == $bool) |
|
933 | + if ($this->defaultCSSEnabled == $bool) |
|
934 | 934 | return; |
935 | - $this->defaultCSSEnabled=$bool; |
|
936 | - $this->hasChanged=true; |
|
935 | + $this->defaultCSSEnabled = $bool; |
|
936 | + $this->hasChanged = true; |
|
937 | 937 | $this->update(); |
938 | 938 | } |
939 | 939 | |
940 | 940 | public function getHotkeys($hotkeyType = false) { |
941 | - if($hotkeyType!==false) { |
|
942 | - if(isset($this->hotkeys[$hotkeyType])) { |
|
941 | + if ($hotkeyType !== false) { |
|
942 | + if (isset($this->hotkeys[$hotkeyType])) { |
|
943 | 943 | return $this->hotkeys[$hotkeyType]; |
944 | 944 | } |
945 | 945 | else { |
@@ -949,42 +949,42 @@ discard block |
||
949 | 949 | return $this->hotkeys; |
950 | 950 | } |
951 | 951 | |
952 | - public function setHotkey($hotkeyType,$binding) { |
|
953 | - if($this->getHotkeys($hotkeyType) == $binding) |
|
952 | + public function setHotkey($hotkeyType, $binding) { |
|
953 | + if ($this->getHotkeys($hotkeyType) == $binding) |
|
954 | 954 | return; |
955 | 955 | $this->hotkeys[$hotkeyType] = $binding; |
956 | - $this->hasChanged=true; |
|
956 | + $this->hasChanged = true; |
|
957 | 957 | $this->update(); |
958 | 958 | } |
959 | 959 | |
960 | 960 | public function isReceivingMessageNotifications($messageTypeID) { |
961 | - return isset($this->messageNotifications[$messageTypeID])?$this->messageNotifications[$messageTypeID]>0:false; |
|
961 | + return isset($this->messageNotifications[$messageTypeID]) ? $this->messageNotifications[$messageTypeID] > 0 : false; |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | public function getMessageNotifications($messageTypeID) { |
965 | - return isset($this->messageNotifications[$messageTypeID])?$this->messageNotifications[$messageTypeID]:0; |
|
965 | + return isset($this->messageNotifications[$messageTypeID]) ? $this->messageNotifications[$messageTypeID] : 0; |
|
966 | 966 | } |
967 | 967 | |
968 | - public function setMessageNotifications($messageTypeID,$num) { |
|
969 | - if($this->getMessageNotifications($messageTypeID) == $num) |
|
968 | + public function setMessageNotifications($messageTypeID, $num) { |
|
969 | + if ($this->getMessageNotifications($messageTypeID) == $num) |
|
970 | 970 | return; |
971 | - $this->messageNotifications[$messageTypeID]=$num; |
|
972 | - $this->hasChanged=true; |
|
971 | + $this->messageNotifications[$messageTypeID] = $num; |
|
972 | + $this->hasChanged = true; |
|
973 | 973 | $this->update(); |
974 | 974 | } |
975 | 975 | |
976 | - public function increaseMessageNotifications($messageTypeID,$num) { |
|
977 | - if($num==0) |
|
976 | + public function increaseMessageNotifications($messageTypeID, $num) { |
|
977 | + if ($num == 0) |
|
978 | 978 | return; |
979 | - if($num<0) |
|
979 | + if ($num < 0) |
|
980 | 980 | throw new Exception('You cannot increase by a negative amount'); |
981 | 981 | $this->setMessageNotifications($messageTypeID, $this->getMessageNotifications($messageTypeID) + $num); |
982 | 982 | } |
983 | 983 | |
984 | - public function decreaseMessageNotifications($messageTypeID,$num) { |
|
985 | - if($num==0) |
|
984 | + public function decreaseMessageNotifications($messageTypeID, $num) { |
|
985 | + if ($num == 0) |
|
986 | 986 | return; |
987 | - if($num<0) |
|
987 | + if ($num < 0) |
|
988 | 988 | throw new Exception('You cannot decrease by a negative amount'); |
989 | 989 | $this->setMessageNotifications($messageTypeID, $this->getMessageNotifications($messageTypeID) - $num); |
990 | 990 | } |
@@ -994,10 +994,10 @@ discard block |
||
994 | 994 | } |
995 | 995 | |
996 | 996 | public function setCenterGalaxyMapOnPlayer($bool) { |
997 | - if($this->centerGalaxyMapOnPlayer == $bool) |
|
997 | + if ($this->centerGalaxyMapOnPlayer == $bool) |
|
998 | 998 | return; |
999 | - $this->centerGalaxyMapOnPlayer=$bool; |
|
1000 | - $this->hasChanged=true; |
|
999 | + $this->centerGalaxyMapOnPlayer = $bool; |
|
1000 | + $this->hasChanged = true; |
|
1001 | 1001 | $this->update(); |
1002 | 1002 | } |
1003 | 1003 | |
@@ -1006,26 +1006,26 @@ discard block |
||
1006 | 1006 | } |
1007 | 1007 | |
1008 | 1008 | public function isMailBanned() { |
1009 | - return $this->mailBanned>TIME; |
|
1009 | + return $this->mailBanned > TIME; |
|
1010 | 1010 | } |
1011 | 1011 | |
1012 | 1012 | public function setMailBanned($time) { |
1013 | - if($this->mailBanned == $time) |
|
1013 | + if ($this->mailBanned == $time) |
|
1014 | 1014 | return; |
1015 | - $this->mailBanned=$time; |
|
1016 | - $this->hasChanged=true; |
|
1015 | + $this->mailBanned = $time; |
|
1016 | + $this->hasChanged = true; |
|
1017 | 1017 | } |
1018 | 1018 | |
1019 | 1019 | public function increaseMailBanned($increaseTime) { |
1020 | - $time = max(TIME,$this->getMailBanned()); |
|
1021 | - $this->setMailBanned($time+$increaseTime); |
|
1020 | + $time = max(TIME, $this->getMailBanned()); |
|
1021 | + $this->setMailBanned($time + $increaseTime); |
|
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | public function getPermissions() { |
1025 | - if(!isset($this->permissions)) { |
|
1025 | + if (!isset($this->permissions)) { |
|
1026 | 1026 | $this->permissions = array(); |
1027 | 1027 | $this->db->query('SELECT permission_id FROM account_has_permission WHERE ' . $this->SQL); |
1028 | - while($this->db->nextRecord()) { |
|
1028 | + while ($this->db->nextRecord()) { |
|
1029 | 1029 | $this->permissions[$this->db->getInt('permission_id')] = true; |
1030 | 1030 | } |
1031 | 1031 | } |
@@ -1034,28 +1034,28 @@ discard block |
||
1034 | 1034 | |
1035 | 1035 | public function hasPermission($permissionID = false) { |
1036 | 1036 | $permissions = $this->getPermissions(); |
1037 | - if($permissionID === false) { |
|
1037 | + if ($permissionID === false) { |
|
1038 | 1038 | return count($permissions) > 0; |
1039 | 1039 | } |
1040 | 1040 | return isset($permissions[$permissionID]) ? $permissions[$permissionID] : false; |
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | public function getPoints() { |
1044 | - if(!isset($this->points)) { |
|
1045 | - $this->points=0; |
|
1044 | + if (!isset($this->points)) { |
|
1045 | + $this->points = 0; |
|
1046 | 1046 | $this->db->lockTable('account_has_points'); |
1047 | - $this->db->query('SELECT * FROM account_has_points WHERE '.$this->SQL.' LIMIT 1'); |
|
1048 | - if($this->db->nextRecord()) { |
|
1049 | - $this->points=$this->db->getInt('points'); |
|
1047 | + $this->db->query('SELECT * FROM account_has_points WHERE ' . $this->SQL . ' LIMIT 1'); |
|
1048 | + if ($this->db->nextRecord()) { |
|
1049 | + $this->points = $this->db->getInt('points'); |
|
1050 | 1050 | $lastUpdate = $this->db->getInt('last_update'); |
1051 | 1051 | //we are gonna check for reducing points... |
1052 | - if($this->points>0 && $lastUpdate < TIME - (7 * 86400)) { |
|
1053 | - $removePoints=0; |
|
1054 | - while($lastUpdate < TIME - (7 * 86400)) { |
|
1052 | + if ($this->points > 0 && $lastUpdate < TIME - (7 * 86400)) { |
|
1053 | + $removePoints = 0; |
|
1054 | + while ($lastUpdate < TIME - (7 * 86400)) { |
|
1055 | 1055 | $removePoints++; |
1056 | 1056 | $lastUpdate += (7 * 86400); |
1057 | 1057 | } |
1058 | - $this->removePoints($removePoints,$lastUpdate); |
|
1058 | + $this->removePoints($removePoints, $lastUpdate); |
|
1059 | 1059 | } |
1060 | 1060 | } |
1061 | 1061 | $this->db->unlock(); |
@@ -1063,30 +1063,30 @@ discard block |
||
1063 | 1063 | return $this->points; |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - public function setPoints($numPoints,$lastUpdate=false) { |
|
1067 | - $numPoints = max($numPoints,0); |
|
1068 | - if($this->getPoints()==$numPoints) |
|
1066 | + public function setPoints($numPoints, $lastUpdate = false) { |
|
1067 | + $numPoints = max($numPoints, 0); |
|
1068 | + if ($this->getPoints() == $numPoints) |
|
1069 | 1069 | return; |
1070 | - if ($this->points==0) |
|
1071 | - $this->db->query('INSERT INTO account_has_points (account_id, points, last_update) VALUES ('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($numPoints).', '.$this->db->escapeNumber($lastUpdate?$lastUpdate:TIME).')'); |
|
1072 | - else if($numPoints<=0) |
|
1073 | - $this->db->query('DELETE FROM account_has_points WHERE '.$this->SQL.' LIMIT 1'); |
|
1070 | + if ($this->points == 0) |
|
1071 | + $this->db->query('INSERT INTO account_has_points (account_id, points, last_update) VALUES (' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($numPoints) . ', ' . $this->db->escapeNumber($lastUpdate ? $lastUpdate : TIME) . ')'); |
|
1072 | + else if ($numPoints <= 0) |
|
1073 | + $this->db->query('DELETE FROM account_has_points WHERE ' . $this->SQL . ' LIMIT 1'); |
|
1074 | 1074 | else |
1075 | - $this->db->query('UPDATE account_has_points SET points = '.$this->db->escapeNumber($numPoints).($lastUpdate ? ', last_update = '.$this->db->escapeNumber(TIME) : '').' WHERE '.$this->SQL.' LIMIT 1'); |
|
1076 | - $this->points=$numPoints; |
|
1075 | + $this->db->query('UPDATE account_has_points SET points = ' . $this->db->escapeNumber($numPoints) . ($lastUpdate ? ', last_update = ' . $this->db->escapeNumber(TIME) : '') . ' WHERE ' . $this->SQL . ' LIMIT 1'); |
|
1076 | + $this->points = $numPoints; |
|
1077 | 1077 | } |
1078 | 1078 | |
1079 | - public function removePoints($numPoints,$lastUpdate=false) { |
|
1080 | - if($numPoints>0) |
|
1081 | - $this->setPoints($this->getPoints()-$numPoints,$lastUpdate); |
|
1079 | + public function removePoints($numPoints, $lastUpdate = false) { |
|
1080 | + if ($numPoints > 0) |
|
1081 | + $this->setPoints($this->getPoints() - $numPoints, $lastUpdate); |
|
1082 | 1082 | } |
1083 | 1083 | |
1084 | - public function addPoints($numPoints,SmrAccount $admin,$reasonID,$suspicion) { |
|
1084 | + public function addPoints($numPoints, SmrAccount $admin, $reasonID, $suspicion) { |
|
1085 | 1085 | //do we have points |
1086 | - $this->setPoints($this->getPoints() + $numPoints,TIME); |
|
1086 | + $this->setPoints($this->getPoints() + $numPoints, TIME); |
|
1087 | 1087 | $totalPoints = $this->getPoints(); |
1088 | 1088 | if ($totalPoints < 10) |
1089 | - return false;//leave scripts its only a warning |
|
1089 | + return false; //leave scripts its only a warning |
|
1090 | 1090 | elseif ($totalPoints < 20) |
1091 | 1091 | $days = 2; |
1092 | 1092 | elseif ($totalPoints < 30) |
@@ -1094,7 +1094,7 @@ discard block |
||
1094 | 1094 | elseif ($totalPoints < 50) |
1095 | 1095 | $days = 7; |
1096 | 1096 | elseif ($totalPoints < 75) |
1097 | - $days = 15 ; |
|
1097 | + $days = 15; |
|
1098 | 1098 | elseif ($totalPoints < 100) |
1099 | 1099 | $days = 30; |
1100 | 1100 | elseif ($totalPoints < 125) |
@@ -1108,13 +1108,13 @@ discard block |
||
1108 | 1108 | else |
1109 | 1109 | $days = 0; //Forever/indefinite |
1110 | 1110 | |
1111 | - if($days==0) { |
|
1111 | + if ($days == 0) { |
|
1112 | 1112 | $expireTime = 0; |
1113 | 1113 | } |
1114 | 1114 | else { |
1115 | 1115 | $expireTime = TIME + $days * 86400; |
1116 | 1116 | } |
1117 | - $this->banAccount($expireTime,$admin,$reasonID,$suspicion); |
|
1117 | + $this->banAccount($expireTime, $admin, $reasonID, $suspicion); |
|
1118 | 1118 | |
1119 | 1119 | return $days; |
1120 | 1120 | } |
@@ -1141,12 +1141,12 @@ discard block |
||
1141 | 1141 | $this->hasChanged = true; |
1142 | 1142 | } |
1143 | 1143 | |
1144 | - public function banAccount($expireTime,SmrAccount $admin,$reasonID,$suspicion,$removeExceptions = false) { |
|
1144 | + public function banAccount($expireTime, SmrAccount $admin, $reasonID, $suspicion, $removeExceptions = false) { |
|
1145 | 1145 | $this->db->query('REPLACE INTO account_is_closed |
1146 | 1146 | (account_id, reason_id, suspicion, expires) |
1147 | - VALUES('.$this->db->escapeNumber($this->getAccountID()).', '.$this->db->escapeNumber($reasonID).', '.$this->db->escapeString($suspicion).', '.$this->db->escapeNumber($expireTime).')'); |
|
1147 | + VALUES('.$this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber($reasonID) . ', ' . $this->db->escapeString($suspicion) . ', ' . $this->db->escapeNumber($expireTime) . ')'); |
|
1148 | 1148 | $this->db->lockTable('active_session'); |
1149 | - $this->db->query('DELETE FROM active_session WHERE '.$this->SQL.' LIMIT 1'); |
|
1149 | + $this->db->query('DELETE FROM active_session WHERE ' . $this->SQL . ' LIMIT 1'); |
|
1150 | 1150 | $this->db->unlock(); |
1151 | 1151 | |
1152 | 1152 | $this->db->query('INSERT INTO account_has_closing_history |
@@ -1166,38 +1166,38 @@ discard block |
||
1166 | 1166 | $player->update(); |
1167 | 1167 | } |
1168 | 1168 | $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account closed by ' . $admin->getLogin() . '.'); |
1169 | - if($removeExceptions!==false) |
|
1169 | + if ($removeExceptions !== false) |
|
1170 | 1170 | $this->db->query('DELETE FROM account_exceptions WHERE ' . $this->SQL); |
1171 | 1171 | } |
1172 | 1172 | |
1173 | - public function unbanAccount(SmrAccount $admin = null,$currException=false) { |
|
1173 | + public function unbanAccount(SmrAccount $admin = null, $currException = false) { |
|
1174 | 1174 | $adminID = 0; |
1175 | - if($admin!==null) |
|
1175 | + if ($admin !== null) |
|
1176 | 1176 | $adminID = $admin->getAccountID(); |
1177 | 1177 | $this->db->query('DELETE FROM account_is_closed WHERE ' . $this->SQL . ' LIMIT 1'); |
1178 | 1178 | $this->db->query('INSERT INTO account_has_closing_history |
1179 | 1179 | (account_id, time, admin_id, action) |
1180 | 1180 | VALUES(' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeNumber(TIME) . ', ' . $this->db->escapeNumber($adminID) . ', ' . $this->db->escapeString('Opened') . ')'); |
1181 | 1181 | $this->db->query('UPDATE player SET last_turn_update = GREATEST(' . $this->db->escapeNumber(TIME) . ', last_turn_update) WHERE ' . $this->SQL); |
1182 | - if($admin!==null) |
|
1182 | + if ($admin !== null) |
|
1183 | 1183 | $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account reopened by ' . $admin->getLogin() . '.'); |
1184 | 1184 | else |
1185 | 1185 | $this->log(LOG_TYPE_ACCOUNT_CHANGES, 'Account automatically reopened.'); |
1186 | - if($currException!==false) |
|
1186 | + if ($currException !== false) |
|
1187 | 1187 | $this->db->query('REPLACE INTO account_exceptions (account_id, reason) |
1188 | 1188 | VALUES (' . $this->db->escapeNumber($this->getAccountID()) . ', ' . $this->db->escapeString($currException) . ')'); |
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | public function getToggleAJAXHREF() { |
1192 | 1192 | global $var; |
1193 | - return SmrSession::getNewHREF(create_container('skeleton.php','toggle_processing.php',array('toggle'=>'AJAX','referrer'=>$var['body']))); |
|
1193 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'toggle_processing.php', array('toggle'=>'AJAX', 'referrer'=>$var['body']))); |
|
1194 | 1194 | } |
1195 | 1195 | |
1196 | 1196 | public function getUserRankingHREF() { |
1197 | - return SmrSession::getNewHREF(create_container('skeleton.php','rankings_view.php')); |
|
1197 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'rankings_view.php')); |
|
1198 | 1198 | } |
1199 | 1199 | |
1200 | 1200 | public function getPersonalHofHREF() { |
1201 | - return SmrSession::getNewHREF(create_container('skeleton.php','hall_of_fame_player_detail.php',array('account_id' => $this->getAccountID()))); |
|
1201 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'hall_of_fame_player_detail.php', array('account_id' => $this->getAccountID()))); |
|
1202 | 1202 | } |
1203 | 1203 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | } |
18 | 18 | |
19 | 19 | protected static function initialiseDatabase() { |
20 | - if(self::$db==null) { |
|
20 | + if (self::$db == null) { |
|
21 | 21 | self::$db = new SmrMySqlDatabase(); |
22 | 22 | } |
23 | 23 | } |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | } |
28 | 28 | |
29 | 29 | public static function canAccessPage($pageName, AbstractSmrPlayer $player, array $extraInfo) { |
30 | - switch($pageName) { |
|
30 | + switch ($pageName) { |
|
31 | 31 | case 'AllianceMOTD': |
32 | - if($player->getAllianceID() != $extraInfo['AllianceID']) { |
|
32 | + if ($player->getAllianceID() != $extraInfo['AllianceID']) { |
|
33 | 33 | logException(new Exception('Tried to access page without permission.')); |
34 | 34 | create_error('You cannot access this page.'); |
35 | 35 | } |
@@ -38,10 +38,10 @@ discard block |
||
38 | 38 | } |
39 | 39 | |
40 | 40 | public static function &getHiddenPlayers() { |
41 | - if(self::$HIDDEN_PLAYERS==null) { |
|
41 | + if (self::$HIDDEN_PLAYERS == null) { |
|
42 | 42 | self::initialiseDatabase(); |
43 | 43 | self::$db->query('SELECT account_id FROM hidden_players'); |
44 | - self::$HIDDEN_PLAYERS = array(0);//stop errors |
|
44 | + self::$HIDDEN_PLAYERS = array(0); //stop errors |
|
45 | 45 | while (self::$db->nextRecord()) { |
46 | 46 | self::$HIDDEN_PLAYERS[] = self::$db->getField('account_id'); |
47 | 47 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | } |
51 | 51 | |
52 | 52 | public static function &getLevelRequirements() { |
53 | - if(self::$LEVEL_REQUIREMENTS==null) { |
|
53 | + if (self::$LEVEL_REQUIREMENTS == null) { |
|
54 | 54 | self::initialiseDatabase(); |
55 | 55 | self::$LEVEL_REQUIREMENTS = array(); |
56 | 56 | |
@@ -67,13 +67,13 @@ discard block |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | public static function &getRaces() { |
70 | - if(self::$RACES==null) { |
|
70 | + if (self::$RACES == null) { |
|
71 | 71 | self::initialiseDatabase(); |
72 | 72 | self::$RACES = array(); |
73 | 73 | |
74 | 74 | // determine user level |
75 | 75 | self::$db->query('SELECT race_id,race_name,race_description FROM race ORDER BY race_id'); |
76 | - while(self::$db->nextRecord()) { |
|
76 | + while (self::$db->nextRecord()) { |
|
77 | 77 | self::$RACES[self::$db->getInt('race_id')] = array( |
78 | 78 | 'Race ID' => self::$db->getInt('race_id'), |
79 | 79 | 'Race Name' => self::$db->getField('race_name'), |
@@ -110,21 +110,21 @@ discard block |
||
110 | 110 | |
111 | 111 | public static function getColouredRaceName($raceID, $relations, $linked = true) { |
112 | 112 | $raceName = get_colored_text($relations, Globals::getRaceName($raceID)); |
113 | - if($linked === true) { |
|
114 | - $container = create_container('skeleton.php','council_list.php', array('race_id' => $raceID)); |
|
113 | + if ($linked === true) { |
|
114 | + $container = create_container('skeleton.php', 'council_list.php', array('race_id' => $raceID)); |
|
115 | 115 | $raceName = create_link($container, $raceName); |
116 | 116 | } |
117 | 117 | return $raceName; |
118 | 118 | } |
119 | 119 | |
120 | 120 | public static function &getGoods() { |
121 | - if(self::$GOODS==null) { |
|
121 | + if (self::$GOODS == null) { |
|
122 | 122 | self::initialiseDatabase(); |
123 | 123 | self::$GOODS = array(); |
124 | 124 | |
125 | 125 | // determine user level |
126 | 126 | self::$db->query('SELECT * FROM good ORDER BY good_id'); |
127 | - while(self::$db->nextRecord()) { |
|
127 | + while (self::$db->nextRecord()) { |
|
128 | 128 | self::$GOODS[self::$db->getField('good_id')] = array( |
129 | 129 | 'Type' => 'Good', |
130 | 130 | 'ID' => self::$db->getInt('good_id'), |
@@ -143,20 +143,20 @@ discard block |
||
143 | 143 | return Globals::getGoods()[$goodID]; |
144 | 144 | } |
145 | 145 | public static function getGoodName($goodID) { |
146 | - if($goodID==GOOD_NOTHING) { |
|
146 | + if ($goodID == GOOD_NOTHING) { |
|
147 | 147 | return 'Nothing'; |
148 | 148 | } |
149 | 149 | return Globals::getGoods()[$goodID]['Name']; |
150 | 150 | } |
151 | 151 | |
152 | - public static function &getHardwareTypes($hardwareTypeID=false) { |
|
153 | - if(self::$HARDWARE_TYPES==null) { |
|
152 | + public static function &getHardwareTypes($hardwareTypeID = false) { |
|
153 | + if (self::$HARDWARE_TYPES == null) { |
|
154 | 154 | self::initialiseDatabase(); |
155 | 155 | self::$HARDWARE_TYPES = array(); |
156 | 156 | |
157 | 157 | // determine user level |
158 | 158 | self::$db->query('SELECT * FROM hardware_type ORDER BY hardware_type_id'); |
159 | - while(self::$db->nextRecord()) { |
|
159 | + while (self::$db->nextRecord()) { |
|
160 | 160 | self::$HARDWARE_TYPES[self::$db->getField('hardware_type_id')] = array( |
161 | 161 | 'Type' => 'Hardware', |
162 | 162 | 'ID' => self::$db->getInt('hardware_type_id'), |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | ); |
166 | 166 | } |
167 | 167 | } |
168 | - if($hardwareTypeID===false) { |
|
168 | + if ($hardwareTypeID === false) { |
|
169 | 169 | return self::$HARDWARE_TYPES; |
170 | 170 | } |
171 | 171 | return self::$HARDWARE_TYPES[$hardwareTypeID]; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | } |
198 | 198 | |
199 | 199 | public static function getGameType($gameID) { |
200 | - if(self::isValidGame($gameID)) { |
|
200 | + if (self::isValidGame($gameID)) { |
|
201 | 201 | return SmrGame::getGame($gameID)->getGameType(); |
202 | 202 | } |
203 | 203 | return 0; |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | } |
245 | 245 | |
246 | 246 | public static function isFeatureRequestOpen() { |
247 | - if(self::$FEATURE_REQUEST_OPEN == null) { |
|
247 | + if (self::$FEATURE_REQUEST_OPEN == null) { |
|
248 | 248 | self::initialiseDatabase(); |
249 | 249 | self::$db->query('SELECT open FROM open_forms WHERE type=\'FEATURE\''); |
250 | 250 | self::$db->nextRecord(); |
@@ -254,12 +254,12 @@ discard block |
||
254 | 254 | return self::$FEATURE_REQUEST_OPEN; |
255 | 255 | } |
256 | 256 | |
257 | - public static function &getRaceRelations($gameID,$raceID) { |
|
258 | - if(!isset(self::$RACE_RELATIONS[$gameID])) { |
|
257 | + public static function &getRaceRelations($gameID, $raceID) { |
|
258 | + if (!isset(self::$RACE_RELATIONS[$gameID])) { |
|
259 | 259 | self::$RACE_RELATIONS[$gameID] = array(); |
260 | 260 | } |
261 | 261 | |
262 | - if(!isset(self::$RACE_RELATIONS[$gameID][$raceID])) { |
|
262 | + if (!isset(self::$RACE_RELATIONS[$gameID][$raceID])) { |
|
263 | 263 | self::initialiseDatabase(); |
264 | 264 | //get relations |
265 | 265 | $RACES = Globals::getRaces(); |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | foreach ($RACES as $otherRaceID => $raceArray) { |
268 | 268 | self::$RACE_RELATIONS[$gameID][$raceID][$otherRaceID] = 0; |
269 | 269 | } |
270 | - self::$db->query('SELECT race_id_2,relation FROM race_has_relation WHERE race_id_1='.self::$db->escapeNumber($raceID).' AND game_id='.self::$db->escapeNumber($gameID).' LIMIT '.count($RACES)); |
|
270 | + self::$db->query('SELECT race_id_2,relation FROM race_has_relation WHERE race_id_1=' . self::$db->escapeNumber($raceID) . ' AND game_id=' . self::$db->escapeNumber($gameID) . ' LIMIT ' . count($RACES)); |
|
271 | 271 | while (self::$db->nextRecord()) { |
272 | 272 | self::$RACE_RELATIONS[$gameID][$raceID][self::$db->getInt('race_id_2')] = self::$db->getInt('relation'); |
273 | 273 | } |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | } |
277 | 277 | |
278 | 278 | public static function getUserRanking() { |
279 | - if(!isset(self::$USER_RANKINGS)) { |
|
279 | + if (!isset(self::$USER_RANKINGS)) { |
|
280 | 280 | self::initialiseDatabase(); |
281 | 281 | self::$USER_RANKINGS = array(); |
282 | 282 | self::$db->query('SELECT rank, rank_name FROM user_rankings ORDER BY rank'); |
@@ -292,15 +292,15 @@ discard block |
||
292 | 292 | } |
293 | 293 | |
294 | 294 | public static function getCurrentSectorHREF() { |
295 | - return self::$AVAILABLE_LINKS['CurrentSector'] = SmrSession::getNewHREF(create_container('skeleton.php','current_sector.php')); |
|
295 | + return self::$AVAILABLE_LINKS['CurrentSector'] = SmrSession::getNewHREF(create_container('skeleton.php', 'current_sector.php')); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | public static function getLocalMapHREF() { |
299 | - return self::$AVAILABLE_LINKS['LocalMap'] = SmrSession::getNewHREF(create_container('skeleton.php','map_local.php')); |
|
299 | + return self::$AVAILABLE_LINKS['LocalMap'] = SmrSession::getNewHREF(create_container('skeleton.php', 'map_local.php')); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | public static function getCurrentPlayersHREF() { |
303 | - return self::$AVAILABLE_LINKS['CurrentPlayers'] = SmrSession::getNewHREF(create_container('skeleton.php','current_players.php')); |
|
303 | + return self::$AVAILABLE_LINKS['CurrentPlayers'] = SmrSession::getNewHREF(create_container('skeleton.php', 'current_players.php')); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | public static function getTradeHREF() { |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | } |
309 | 309 | |
310 | 310 | public static function getAttackTraderHREF($accountID) { |
311 | - $container = create_container('skeleton.php','trader_attack_processing.php'); |
|
311 | + $container = create_container('skeleton.php', 'trader_attack_processing.php'); |
|
312 | 312 | $container['target'] = $accountID; |
313 | 313 | return self::$AVAILABLE_LINKS['AttackTrader'] = SmrSession::getNewHREF($container); |
314 | 314 | } |
@@ -317,8 +317,8 @@ discard block |
||
317 | 317 | return SmrSession::getNewHREF(create_container('death_processing.php')); |
318 | 318 | } |
319 | 319 | |
320 | - public static function getBetaFunctionsHREF(){ //BETA |
|
321 | - return SmrSession::getNewHREF(create_container('skeleton.php','beta_functions.php')); |
|
320 | + public static function getBetaFunctionsHREF() { //BETA |
|
321 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'beta_functions.php')); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | public static function getBugReportProcessingHREF() { |
@@ -326,13 +326,13 @@ discard block |
||
326 | 326 | } |
327 | 327 | |
328 | 328 | public static function getWeaponReorderHREF($weaponOrderID, $direction) { |
329 | - $container = create_container('skeleton.php','weapon_reorder.php'); |
|
330 | - $container[$direction] = $weaponOrderID; |
|
329 | + $container = create_container('skeleton.php', 'weapon_reorder.php'); |
|
330 | + $container[$direction] = $weaponOrderID; |
|
331 | 331 | return SmrSession::getNewHREF($container); |
332 | 332 | } |
333 | 333 | |
334 | 334 | public static function getSmrFileCreateHREF($adminCreateGameID = false) { |
335 | - $container = create_container('skeleton.php','smr_file_create.php'); |
|
335 | + $container = create_container('skeleton.php', 'smr_file_create.php'); |
|
336 | 336 | $container['AdminCreateGameID'] = $adminCreateGameID; |
337 | 337 | return SmrSession::getNewHREF($container); |
338 | 338 | } |
@@ -351,42 +351,42 @@ discard block |
||
351 | 351 | |
352 | 352 | public static function getSectorScanHREF($toSector) { |
353 | 353 | global $player; |
354 | - $container = create_container('skeleton.php','sector_scan.php'); |
|
354 | + $container = create_container('skeleton.php', 'sector_scan.php'); |
|
355 | 355 | $container['target_sector'] = $toSector; |
356 | 356 | return self::$AVAILABLE_LINKS['Scan' . $player->getSector()->getSectorDirection($toSector)] = SmrSession::getNewHREF($container); |
357 | 357 | } |
358 | 358 | |
359 | 359 | public static function getPlotCourseHREF($fromSector = false, $toSector = false) { |
360 | - if($fromSector === false && $toSector === false) { |
|
361 | - return self::$AVAILABLE_LINKS['PlotCourse'] = SmrSession::getNewHREF(create_container('skeleton.php','course_plot.php')); |
|
360 | + if ($fromSector === false && $toSector === false) { |
|
361 | + return self::$AVAILABLE_LINKS['PlotCourse'] = SmrSession::getNewHREF(create_container('skeleton.php', 'course_plot.php')); |
|
362 | 362 | } |
363 | 363 | else { |
364 | - return SmrSession::getNewHREF(create_container('course_plot_processing.php','',array('from'=>$fromSector,'to'=>$toSector))); |
|
364 | + return SmrSession::getNewHREF(create_container('course_plot_processing.php', '', array('from'=>$fromSector, 'to'=>$toSector))); |
|
365 | 365 | } |
366 | 366 | } |
367 | 367 | |
368 | 368 | public static function getPlanetMainHREF() { |
369 | - return SmrSession::getNewHREF(create_container('skeleton.php','planet_main.php')); |
|
369 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'planet_main.php')); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | public static function getPlanetConstructionHREF() { |
373 | - return SmrSession::getNewHREF(create_container('skeleton.php','planet_construction.php')); |
|
373 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'planet_construction.php')); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | public static function getPlanetDefensesHREF() { |
377 | - return SmrSession::getNewHREF(create_container('skeleton.php','planet_defense.php')); |
|
377 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'planet_defense.php')); |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | public static function getPlanetOwnershipHREF() { |
381 | - return SmrSession::getNewHREF(create_container('skeleton.php','planet_ownership.php')); |
|
381 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'planet_ownership.php')); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | public static function getPlanetStockpileHREF() { |
385 | - return SmrSession::getNewHREF(create_container('skeleton.php','planet_stockpile.php')); |
|
385 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'planet_stockpile.php')); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | public static function getPlanetFinancesHREF() { |
389 | - return SmrSession::getNewHREF(create_container('skeleton.php','planet_financial.php')); |
|
389 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'planet_financial.php')); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | public static function getAllianceHREF($allianceID = null) { |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | |
401 | 401 | public static function getAllianceBankHREF($allianceID = null) { |
402 | 402 | $container = create_container('skeleton.php', 'bank_alliance.php'); |
403 | - if ($allianceID!=null) { |
|
403 | + if ($allianceID != null) { |
|
404 | 404 | $container['alliance_id'] = $allianceID; |
405 | 405 | } |
406 | 406 | return SmrSession::getNewHREF($container); |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | |
409 | 409 | public static function getAllianceRosterHREF($allianceID = null) { |
410 | 410 | $container = create_container('skeleton.php', 'alliance_roster.php'); |
411 | - if ($allianceID!=null) { |
|
411 | + if ($allianceID != null) { |
|
412 | 412 | $container['alliance_id'] = $allianceID; |
413 | 413 | } |
414 | 414 | return SmrSession::getNewHREF($container); |
@@ -473,9 +473,9 @@ discard block |
||
473 | 473 | return SmrSession::getNewHREF(create_container('skeleton.php', 'trader_status.php')); |
474 | 474 | } |
475 | 475 | |
476 | - public static function getCouncilHREF($raceID=false) { |
|
476 | + public static function getCouncilHREF($raceID = false) { |
|
477 | 477 | $container = create_container('skeleton.php', 'council_list.php'); |
478 | - if($raceID!==false) { |
|
478 | + if ($raceID !== false) { |
|
479 | 479 | $container['race_id'] = $raceID; |
480 | 480 | } |
481 | 481 | return SmrSession::getNewHREF($container); |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | |
549 | 549 | public static function getAvailableTemplates() { |
550 | 550 | return array('Default' => array('Default'), |
551 | - 'Freon22' => array('Default','Blue','ClassicGreen','None')); |
|
551 | + 'Freon22' => array('Default', 'Blue', 'ClassicGreen', 'None')); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | public static function getAvailableColourSchemes($templateName) { |
@@ -7,9 +7,9 @@ discard block |
||
7 | 7 | protected $SQL; |
8 | 8 | |
9 | 9 | public static function refreshCache() { |
10 | - foreach(self::$CACHE_SHIPS as &$gameShips) { |
|
11 | - foreach($gameShips as &$ship) { |
|
12 | - $ship = self::getShip($ship->getPlayer(),true); |
|
10 | + foreach (self::$CACHE_SHIPS as &$gameShips) { |
|
11 | + foreach ($gameShips as &$ship) { |
|
12 | + $ship = self::getShip($ship->getPlayer(), true); |
|
13 | 13 | } |
14 | 14 | } |
15 | 15 | } |
@@ -19,15 +19,15 @@ discard block |
||
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function saveShips() { |
22 | - foreach(self::$CACHE_SHIPS as $gameShips) { |
|
23 | - foreach($gameShips as $ship) { |
|
22 | + foreach (self::$CACHE_SHIPS as $gameShips) { |
|
23 | + foreach ($gameShips as $ship) { |
|
24 | 24 | $ship->update(); |
25 | 25 | } |
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
29 | - public static function &getShip(AbstractSmrPlayer $player,$forceUpdate = false) { |
|
30 | - if($forceUpdate || !isset(self::$CACHE_SHIPS[$player->getGameID()][$player->getAccountID()])) { |
|
29 | + public static function &getShip(AbstractSmrPlayer $player, $forceUpdate = false) { |
|
30 | + if ($forceUpdate || !isset(self::$CACHE_SHIPS[$player->getGameID()][$player->getAccountID()])) { |
|
31 | 31 | $s = new SmrShip($player); |
32 | 32 | self::$CACHE_SHIPS[$player->getGameID()][$player->getAccountID()] = $s; |
33 | 33 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | protected function __construct(AbstractSmrPlayer $player) { |
38 | 38 | parent::__construct($player); |
39 | 39 | $this->db = new SmrMySqlDatabase(); |
40 | - $this->SQL = 'account_id='.$this->db->escapeNumber($this->getAccountID()).' AND game_id='.$this->db->escapeNumber($this->getGameID()); |
|
40 | + $this->SQL = 'account_id=' . $this->db->escapeNumber($this->getAccountID()) . ' AND game_id=' . $this->db->escapeNumber($this->getGameID()); |
|
41 | 41 | |
42 | 42 | $this->loadHardware(); |
43 | 43 | $this->loadWeapons(); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | protected function loadWeapons() { |
51 | 51 | // determine weapon |
52 | 52 | $this->db->query('SELECT weapon_type.*, order_id FROM ship_has_weapon JOIN weapon_type USING (weapon_type_id) |
53 | - WHERE ' . $this->SQL .' |
|
53 | + WHERE ' . $this->SQL . ' |
|
54 | 54 | ORDER BY order_id LIMIT ' . $this->db->escapeNumber($this->getHardpoints())); |
55 | 55 | |
56 | 56 | $this->weapons = array(); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | } |
63 | 63 | |
64 | 64 | protected function loadCargo() { |
65 | - if(!isset($this->cargo)) { |
|
65 | + if (!isset($this->cargo)) { |
|
66 | 66 | // initialize cargo array |
67 | 67 | $this->cargo = array(); |
68 | 68 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | } |
102 | 102 | |
103 | 103 | function updateCargo() { |
104 | - if($this->hasChangedCargo === true) { |
|
104 | + if ($this->hasChangedCargo === true) { |
|
105 | 105 | // write cargo info |
106 | 106 | foreach ($this->getCargo() as $id => $amount) { |
107 | 107 | if ($amount > 0) { |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | } |
136 | 136 | |
137 | 137 | function updateWeapon() { |
138 | - if($this->hasChangedWeapons === true) { |
|
138 | + if ($this->hasChangedWeapons === true) { |
|
139 | 139 | // write weapon info |
140 | 140 | $this->db->query('DELETE FROM ship_has_weapon WHERE ' . $this->SQL); |
141 | 141 | foreach ($this->weapons as $orderID => $weapon) { |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | public function isCloaked() { |
184 | - if(!$this->hasCloak()) |
|
184 | + if (!$this->hasCloak()) |
|
185 | 185 | return false; |
186 | - if(!isset($this->isCloaked)) { |
|
186 | + if (!isset($this->isCloaked)) { |
|
187 | 187 | $this->db->query('SELECT 1 FROM ship_is_cloaked WHERE ' . $this->SQL . ' LIMIT 1'); |
188 | - $this->isCloaked = $this->db->getNumRows()>0; |
|
188 | + $this->isCloaked = $this->db->getNumRows() > 0; |
|
189 | 189 | } |
190 | 190 | return $this->isCloaked; |
191 | 191 | } |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | |
203 | 203 | function cloakOverload() { |
204 | 204 | // 1 in 25 chance of cloak being destroyed if active |
205 | - if($this->isCloaked() && mt_rand(0,99) < 5) { |
|
205 | + if ($this->isCloaked() && mt_rand(0, 99) < 5) { |
|
206 | 206 | $this->db->query('DELETE FROM ship_has_hardware |
207 | 207 | WHERE ' . $this->SQL . ' |
208 | 208 | AND hardware_type_id = 8 |
209 | 209 | LIMIT 1'); |
210 | 210 | $this->decloak(); |
211 | - $this->setHardware(HARDWARE_CLOAK,0); |
|
211 | + $this->setHardware(HARDWARE_CLOAK, 0); |
|
212 | 212 | return true; |
213 | 213 | } |
214 | 214 | |
@@ -224,14 +224,14 @@ discard block |
||
224 | 224 | } |
225 | 225 | |
226 | 226 | public function getIllusionShip() { |
227 | - if(!isset($this->illusionShip)) { |
|
228 | - $this->illusionShip=false; |
|
227 | + if (!isset($this->illusionShip)) { |
|
228 | + $this->illusionShip = false; |
|
229 | 229 | $this->db->query('SELECT ship_has_illusion.*,ship_type.ship_name |
230 | 230 | FROM ship_has_illusion |
231 | 231 | JOIN ship_type USING(ship_type_id) |
232 | 232 | WHERE ' . $this->SQL . ' LIMIT 1'); |
233 | - if($this->db->nextRecord()) { |
|
234 | - $this->illusionShip=array( |
|
233 | + if ($this->db->nextRecord()) { |
|
234 | + $this->illusionShip = array( |
|
235 | 235 | 'ID' => $this->db->getInt('ship_type_id'), |
236 | 236 | 'Attack' => $this->db->getInt('attack'), |
237 | 237 | 'Defense' => $this->db->getInt('defense'), |