We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -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 integer |
| 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; |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | public function isInPath($sectorID) { |
| 111 | - return in_array($sectorID,$this->getPath()); |
|
| 111 | + return in_array($sectorID, $this->getPath()); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | protected $HOF; |
| 51 | 51 | protected static $HOFVis; |
| 52 | 52 | |
| 53 | - protected $hasChanged=false; |
|
| 54 | - protected $hasHOFChanged=false; |
|
| 55 | - protected static $hasHOFVisChanged=array(); |
|
| 53 | + protected $hasChanged = false; |
|
| 54 | + protected $hasHOFChanged = false; |
|
| 55 | + protected static $hasHOFVisChanged = array(); |
|
| 56 | 56 | protected $hasBountyChanged = array(); |
| 57 | 57 | |
| 58 | 58 | protected function __construct() { |
@@ -75,13 +75,13 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | public function hasNewbieTurns() { |
| 78 | - return $this->getNewbieTurns()>0; |
|
| 78 | + return $this->getNewbieTurns() > 0; |
|
| 79 | 79 | } |
| 80 | 80 | public function setNewbieTurns($newbieTurns) { |
| 81 | - if($this->newbieTurns == $newbieTurns) |
|
| 81 | + if ($this->newbieTurns == $newbieTurns) |
|
| 82 | 82 | return; |
| 83 | - $this->newbieTurns=$newbieTurns; |
|
| 84 | - $this->hasChanged=true; |
|
| 83 | + $this->newbieTurns = $newbieTurns; |
|
| 84 | + $this->hasChanged = true; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | public function getShipTypeID() { |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | public function setShipTypeID($shipID) { |
| 92 | - if($this->shipID == $shipID) |
|
| 92 | + if ($this->shipID == $shipID) |
|
| 93 | 93 | return; |
| 94 | - $this->shipID=$shipID; |
|
| 95 | - $this->hasChanged=true; |
|
| 94 | + $this->shipID = $shipID; |
|
| 95 | + $this->hasChanged = true; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | public function &getSectorPlanet() { |
| 112 | - return SmrPlanet::getPlanet($this->getGameID(),$this->getSectorID()); |
|
| 112 | + return SmrPlanet::getPlanet($this->getGameID(), $this->getSectorID()); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | public function &getSectorPort() { |
| 116 | - return SmrPort::getPort($this->getGameID(),$this->getSectorID()); |
|
| 116 | + return SmrPort::getPort($this->getGameID(), $this->getSectorID()); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | public function getSectorID() { |
@@ -121,15 +121,15 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | public function &getSector() { |
| 124 | - return SmrSector::getSector($this->getGameID(),$this->getSectorID()); |
|
| 124 | + return SmrSector::getSector($this->getGameID(), $this->getSectorID()); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | public function setSectorID($sectorID) { |
| 128 | 128 | $this->lastSectorID = $this->getSectorID(); |
| 129 | - $this->actionTaken('LeaveSector',array('Sector'=>$this->getSector())); |
|
| 129 | + $this->actionTaken('LeaveSector', array('Sector'=>$this->getSector())); |
|
| 130 | 130 | $this->sectorID = $sectorID; |
| 131 | - $this->actionTaken('EnterSector',array('Sector'=>$this->getSector())); |
|
| 132 | - $this->hasChanged=true; |
|
| 131 | + $this->actionTaken('EnterSector', array('Sector'=>$this->getSector())); |
|
| 132 | + $this->hasChanged = true; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | public function getLastSectorID() { |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | public function isDraftLeader() { |
| 167 | - if(!isset($this->draftLeader)) { |
|
| 167 | + if (!isset($this->draftLeader)) { |
|
| 168 | 168 | $this->draftLeader = false; |
| 169 | 169 | $this->db->query('SELECT 1 FROM draft_leaders WHERE ' . $this->SQL . ' LIMIT 1'); |
| 170 | 170 | if ($this->db->nextRecord()) { |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | public function getGPWriter() { |
| 178 | - if(!isset($this->gpWriter)) { |
|
| 178 | + if (!isset($this->gpWriter)) { |
|
| 179 | 179 | $this->gpWriter = false; |
| 180 | 180 | $this->db->query('SELECT position FROM galactic_post_writer WHERE ' . $this->SQL); |
| 181 | 181 | if ($this->db->nextRecord()) { |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | public function hasFederalProtection() { |
| 203 | - $sector = SmrSector::getSector($this->getGameID(),$this->getSectorID()); |
|
| 203 | + $sector = SmrSector::getSector($this->getGameID(), $this->getSectorID()); |
|
| 204 | 204 | if (!$sector->offersFederalProtection()) { |
| 205 | 205 | return false; |
| 206 | 206 | } |
@@ -210,8 +210,8 @@ discard block |
||
| 210 | 210 | return false; |
| 211 | 211 | |
| 212 | 212 | if ($ship->getAttackRating() <= $this->getSafeAttackRating()) { |
| 213 | - foreach($sector->getFedRaceIDs() as $fedRaceID) { |
|
| 214 | - if($this->canBeProtectedByRace($fedRaceID)) { |
|
| 213 | + foreach ($sector->getFedRaceIDs() as $fedRaceID) { |
|
| 214 | + if ($this->canBeProtectedByRace($fedRaceID)) { |
|
| 215 | 215 | return true; |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -221,15 +221,15 @@ discard block |
||
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | public function canBeProtectedByRace($raceID) { |
| 224 | - if(!isset($this->canFed)) { |
|
| 224 | + if (!isset($this->canFed)) { |
|
| 225 | 225 | $this->canFed = array(); |
| 226 | 226 | $RACES = Globals::getRaces(); |
| 227 | - foreach($RACES as $raceID2 => $raceName) { |
|
| 227 | + foreach ($RACES as $raceID2 => $raceName) { |
|
| 228 | 228 | $this->canFed[$raceID2] = $this->getRelation($raceID2) >= ALIGN_FED_PROTECTION; |
| 229 | 229 | } |
| 230 | 230 | $this->db->query('SELECT race_id, allowed FROM player_can_fed |
| 231 | 231 | WHERE ' . $this->SQL . ' AND expiry > ' . $this->db->escapeNumber(TIME)); |
| 232 | - while($this->db->nextRecord()) { |
|
| 232 | + while ($this->db->nextRecord()) { |
|
| 233 | 233 | $this->canFed[$this->db->getInt('race_id')] = $this->db->getBoolean('allowed'); |
| 234 | 234 | } |
| 235 | 235 | } |
@@ -248,10 +248,10 @@ discard block |
||
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | public function setDead($bool) { |
| 251 | - if($this->dead == $bool) |
|
| 251 | + if ($this->dead == $bool) |
|
| 252 | 252 | return; |
| 253 | - $this->dead=$bool; |
|
| 254 | - $this->hasChanged=true; |
|
| 253 | + $this->dead = $bool; |
|
| 254 | + $this->hasChanged = true; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | public function getKills() { |
@@ -259,16 +259,16 @@ discard block |
||
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | public function increaseKills($kills) { |
| 262 | - if($kills < 0) |
|
| 262 | + if ($kills < 0) |
|
| 263 | 263 | throw new Exception('Trying to increase negative kills.'); |
| 264 | - $this->setKills($this->kills+$kills); |
|
| 264 | + $this->setKills($this->kills + $kills); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | public function setKills($kills) { |
| 268 | - if($this->kills == $kills) |
|
| 268 | + if ($this->kills == $kills) |
|
| 269 | 269 | return; |
| 270 | - $this->kills=$kills; |
|
| 271 | - $this->hasChanged=true; |
|
| 270 | + $this->kills = $kills; |
|
| 271 | + $this->hasChanged = true; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | public function getDeaths() { |
@@ -276,16 +276,16 @@ discard block |
||
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | public function increaseDeaths($deaths) { |
| 279 | - if($deaths < 0) |
|
| 279 | + if ($deaths < 0) |
|
| 280 | 280 | throw new Exception('Trying to increase negative deaths.'); |
| 281 | - $this->setDeaths($this->getDeaths()+$deaths); |
|
| 281 | + $this->setDeaths($this->getDeaths() + $deaths); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | public function setDeaths($deaths) { |
| 285 | - if($this->deaths == $deaths) |
|
| 285 | + if ($this->deaths == $deaths) |
|
| 286 | 286 | return; |
| 287 | 287 | $this->deaths = $deaths; |
| 288 | - $this->hasChanged=true; |
|
| 288 | + $this->hasChanged = true; |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | public function getAssists() { |
@@ -305,26 +305,26 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | public function increaseAlignment($align) { |
| 308 | - if($align < 0) |
|
| 308 | + if ($align < 0) |
|
| 309 | 309 | throw new Exception('Trying to increase negative align.'); |
| 310 | - if($align == 0) |
|
| 310 | + if ($align == 0) |
|
| 311 | 311 | return; |
| 312 | 312 | $align += $this->alignment; |
| 313 | 313 | $this->setAlignment($align); |
| 314 | 314 | } |
| 315 | 315 | public function decreaseAlignment($align) { |
| 316 | - if($align < 0) |
|
| 316 | + if ($align < 0) |
|
| 317 | 317 | throw new Exception('Trying to decrease negative align.'); |
| 318 | - if($align == 0) |
|
| 318 | + if ($align == 0) |
|
| 319 | 319 | return; |
| 320 | 320 | $align = $this->alignment - $align; |
| 321 | 321 | $this->setAlignment($align); |
| 322 | 322 | } |
| 323 | 323 | public function setAlignment($align) { |
| 324 | - if($this->alignment == $align) |
|
| 324 | + if ($this->alignment == $align) |
|
| 325 | 325 | return; |
| 326 | 326 | $this->alignment = $align; |
| 327 | - $this->hasChanged=true; |
|
| 327 | + $this->hasChanged = true; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | public function getCredits() { |
@@ -336,9 +336,9 @@ discard block |
||
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | public function getNextLevelPercentAcquired() { |
| 339 | - if($this->getNextLevelExperience() == $this->getThisLevelExperience()) |
|
| 339 | + if ($this->getNextLevelExperience() == $this->getThisLevelExperience()) |
|
| 340 | 340 | return 100; |
| 341 | - return max(0,min(100,round(($this->getExperience() - $this->getThisLevelExperience()) / ($this->getNextLevelExperience() - $this->getThisLevelExperience())*100))); |
|
| 341 | + return max(0, min(100, round(($this->getExperience() - $this->getThisLevelExperience()) / ($this->getNextLevelExperience() - $this->getThisLevelExperience()) * 100))); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | public function getNextLevelPercentRemaining() { |
@@ -347,9 +347,9 @@ discard block |
||
| 347 | 347 | |
| 348 | 348 | public function getNextLevelExperience() { |
| 349 | 349 | $LEVELS_REQUIREMENTS = Globals::getLevelRequirements(); |
| 350 | - if(!isset($LEVELS_REQUIREMENTS[$this->getLevelID()+1])) |
|
| 350 | + if (!isset($LEVELS_REQUIREMENTS[$this->getLevelID() + 1])) |
|
| 351 | 351 | return $this->getThisLevelExperience(); //Return current level experience if on last level. |
| 352 | - return $LEVELS_REQUIREMENTS[$this->getLevelID()+1]['Requirement']; |
|
| 352 | + return $LEVELS_REQUIREMENTS[$this->getLevelID() + 1]['Requirement']; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | public function getThisLevelExperience() { |
@@ -358,14 +358,14 @@ discard block |
||
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | public function setExperience($experience) { |
| 361 | - if($this->experience == $experience) |
|
| 361 | + if ($this->experience == $experience) |
|
| 362 | 362 | return; |
| 363 | - if($experience<MIN_EXPERIENCE) |
|
| 363 | + if ($experience < MIN_EXPERIENCE) |
|
| 364 | 364 | $experience = MIN_EXPERIENCE; |
| 365 | - if($experience>MAX_EXPERIENCE) |
|
| 365 | + if ($experience > MAX_EXPERIENCE) |
|
| 366 | 366 | $experience = MAX_EXPERIENCE; |
| 367 | 367 | $this->experience = $experience; |
| 368 | - $this->hasChanged=true; |
|
| 368 | + $this->hasChanged = true; |
|
| 369 | 369 | |
| 370 | 370 | // Since exp has changed, invalidate the player level so that it can |
| 371 | 371 | // be recomputed next time it is queried (in case it has changed). |
@@ -373,49 +373,49 @@ discard block |
||
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | public function increaseCredits($credits) { |
| 376 | - if($credits < 0) |
|
| 376 | + if ($credits < 0) |
|
| 377 | 377 | throw new Exception('Trying to increase negative credits.'); |
| 378 | - if($credits == 0) |
|
| 378 | + if ($credits == 0) |
|
| 379 | 379 | return; |
| 380 | 380 | $credits += $this->credits; |
| 381 | 381 | $this->setCredits($credits); |
| 382 | 382 | } |
| 383 | 383 | public function decreaseCredits($credits) { |
| 384 | - if($credits < 0) |
|
| 384 | + if ($credits < 0) |
|
| 385 | 385 | throw new Exception('Trying to decrease negative credits.'); |
| 386 | - if($credits == 0) |
|
| 386 | + if ($credits == 0) |
|
| 387 | 387 | return; |
| 388 | 388 | $credits = $this->credits - $credits; |
| 389 | 389 | $this->setCredits($credits); |
| 390 | 390 | } |
| 391 | 391 | public function setCredits($credits) { |
| 392 | - if($this->credits == $credits) |
|
| 392 | + if ($this->credits == $credits) |
|
| 393 | 393 | return; |
| 394 | - if($credits < 0) |
|
| 394 | + if ($credits < 0) |
|
| 395 | 395 | throw new Exception('Trying to set negative credits.'); |
| 396 | - if($credits > MAX_MONEY) |
|
| 396 | + if ($credits > MAX_MONEY) |
|
| 397 | 397 | $credits = MAX_MONEY; |
| 398 | 398 | $this->credits = $credits; |
| 399 | - $this->hasChanged=true; |
|
| 399 | + $this->hasChanged = true; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | public function increaseExperience($experience) { |
| 403 | - if($experience < 0) |
|
| 403 | + if ($experience < 0) |
|
| 404 | 404 | throw new Exception('Trying to increase negative experience.'); |
| 405 | - if($experience == 0) |
|
| 405 | + if ($experience == 0) |
|
| 406 | 406 | return; |
| 407 | 407 | $newExperience = $this->experience + $experience; |
| 408 | 408 | $this->setExperience($newExperience); |
| 409 | - $this->increaseHOF($experience,array('Experience','Total','Gain'), HOF_PUBLIC); |
|
| 409 | + $this->increaseHOF($experience, array('Experience', 'Total', 'Gain'), HOF_PUBLIC); |
|
| 410 | 410 | } |
| 411 | 411 | public function decreaseExperience($experience) { |
| 412 | - if($experience < 0) |
|
| 412 | + if ($experience < 0) |
|
| 413 | 413 | throw new Exception('Trying to decrease negative experience.'); |
| 414 | - if($experience == 0) |
|
| 414 | + if ($experience == 0) |
|
| 415 | 415 | return; |
| 416 | 416 | $newExperience = $this->experience - $experience; |
| 417 | 417 | $this->setExperience($newExperience); |
| 418 | - $this->decreaseHOF($experience,array('Experience','Total','Loss'), HOF_PUBLIC); |
|
| 418 | + $this->decreaseHOF($experience, array('Experience', 'Total', 'Loss'), HOF_PUBLIC); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | public function isLandedOnPlanet() { |
@@ -423,10 +423,10 @@ discard block |
||
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | public function setLandedOnPlanet($bool) { |
| 426 | - if($this->landedOnPlanet == $bool) |
|
| 426 | + if ($this->landedOnPlanet == $bool) |
|
| 427 | 427 | return; |
| 428 | - $this->landedOnPlanet=$bool; |
|
| 429 | - $this->hasChanged=true; |
|
| 428 | + $this->landedOnPlanet = $bool; |
|
| 429 | + $this->hasChanged = true; |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
@@ -472,24 +472,24 @@ discard block |
||
| 472 | 472 | $this->hasChanged = true; |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | - public function getDisplayName($includeAlliance=false) { |
|
| 476 | - $return = get_colored_text($this->getAlignment(),$this->playerName.' ('.$this->getPlayerID().')'); |
|
| 477 | - if($this->isNPC()) { |
|
| 475 | + public function getDisplayName($includeAlliance = false) { |
|
| 476 | + $return = get_colored_text($this->getAlignment(), $this->playerName . ' (' . $this->getPlayerID() . ')'); |
|
| 477 | + if ($this->isNPC()) { |
|
| 478 | 478 | $return .= ' <span class="npcColour">[NPC]</span>'; |
| 479 | 479 | } |
| 480 | - if($includeAlliance) { |
|
| 481 | - $return.= ' (' . $this->getAllianceName() . '</a>' . ')'; |
|
| 480 | + if ($includeAlliance) { |
|
| 481 | + $return .= ' (' . $this->getAllianceName() . '</a>' . ')'; |
|
| 482 | 482 | } |
| 483 | 483 | return $return; |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | public function getBBLink() { |
| 487 | - return '[player='.$this->getPlayerID().']'; |
|
| 487 | + return '[player=' . $this->getPlayerID() . ']'; |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | - public function getLinkedDisplayName($includeAlliance=true) { |
|
| 491 | - $return = '<a href="'.$this->getTraderSearchHREF().'">'.$this->getDisplayName().'</a>'; |
|
| 492 | - if($includeAlliance) { |
|
| 490 | + public function getLinkedDisplayName($includeAlliance = true) { |
|
| 491 | + $return = '<a href="' . $this->getTraderSearchHREF() . '">' . $this->getDisplayName() . '</a>'; |
|
| 492 | + if ($includeAlliance) { |
|
| 493 | 493 | $return .= ' (' . $this->getAllianceName(true) . ')'; |
| 494 | 494 | } |
| 495 | 495 | return $return; |
@@ -505,7 +505,7 @@ discard block |
||
| 505 | 505 | |
| 506 | 506 | public static function getColouredRaceNameOrDefault($otherRaceID, AbstractSmrPlayer $player = null, $linked = false) { |
| 507 | 507 | $relations = 0; |
| 508 | - if($player !== null) { |
|
| 508 | + if ($player !== null) { |
|
| 509 | 509 | $relations = $player->getRelation($otherRaceID); |
| 510 | 510 | } |
| 511 | 511 | return Globals::getColouredRaceName($otherRaceID, $relations, $linked); |
@@ -516,10 +516,10 @@ discard block |
||
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | public function setRaceID($raceID) { |
| 519 | - if($this->raceID == $raceID) |
|
| 519 | + if ($this->raceID == $raceID) |
|
| 520 | 520 | return; |
| 521 | - $this->raceID=$raceID; |
|
| 522 | - $this->hasChanged=true; |
|
| 521 | + $this->raceID = $raceID; |
|
| 522 | + $this->hasChanged = true; |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | public function isAllianceLeader($forceUpdate = false) { |
@@ -535,27 +535,27 @@ discard block |
||
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | public function hasAlliance() { |
| 538 | - return $this->getAllianceID()!=0; |
|
| 538 | + return $this->getAllianceID() != 0; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | public function setAllianceID($ID) { |
| 542 | - if($this->allianceID == $ID) |
|
| 542 | + if ($this->allianceID == $ID) |
|
| 543 | 543 | return; |
| 544 | - $this->allianceID=$ID; |
|
| 544 | + $this->allianceID = $ID; |
|
| 545 | 545 | if ($this->allianceID != 0) { |
| 546 | 546 | $status = $this->hasNewbieStatus() ? 'NEWBIE' : 'VETERAN'; |
| 547 | 547 | $this->db->query('INSERT IGNORE INTO player_joined_alliance (account_id,game_id,alliance_id,status) ' . |
| 548 | - 'VALUES ('.$this->db->escapeNumber($this->getAccountID()).','.$this->db->escapeNumber($this->getGameID()).','.$this->db->escapeNumber($this->getAllianceID()).','.$this->db->escapeString($status).')'); |
|
| 548 | + 'VALUES (' . $this->db->escapeNumber($this->getAccountID()) . ',' . $this->db->escapeNumber($this->getGameID()) . ',' . $this->db->escapeNumber($this->getAllianceID()) . ',' . $this->db->escapeString($status) . ')'); |
|
| 549 | 549 | } |
| 550 | - $this->hasChanged=true; |
|
| 550 | + $this->hasChanged = true; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | public function getAllianceBBLink() { |
| 554 | - return $this->hasAlliance()?'[alliance='.$this->getAllianceID().']':$this->getAllianceName(); |
|
| 554 | + return $this->hasAlliance() ? '[alliance=' . $this->getAllianceID() . ']' : $this->getAllianceName(); |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | - public function getAllianceName($linked=false, $includeAllianceID=false) { |
|
| 558 | - if($this->hasAlliance()) { |
|
| 557 | + public function getAllianceName($linked = false, $includeAllianceID = false) { |
|
| 558 | + if ($this->hasAlliance()) { |
|
| 559 | 559 | return $this->getAlliance()->getAllianceName($linked, $includeAllianceID); |
| 560 | 560 | } |
| 561 | 561 | else { |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | if ($allianceID === false) { |
| 568 | 568 | $allianceID = $this->getAllianceID(); |
| 569 | 569 | } |
| 570 | - if(!isset($this->allianceRoles[$allianceID])) { |
|
| 570 | + if (!isset($this->allianceRoles[$allianceID])) { |
|
| 571 | 571 | $this->allianceRoles[$allianceID] = 0; |
| 572 | 572 | $this->db->query('SELECT role_id |
| 573 | 573 | FROM player_has_alliance_role |
@@ -586,10 +586,10 @@ discard block |
||
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | public function setCombatDronesKamikazeOnMines($bool) { |
| 589 | - if($this->combatDronesKamikazeOnMines == $bool) |
|
| 589 | + if ($this->combatDronesKamikazeOnMines == $bool) |
|
| 590 | 590 | return; |
| 591 | 591 | $this->combatDronesKamikazeOnMines = $bool; |
| 592 | - $this->hasChanged=true; |
|
| 592 | + $this->hasChanged = true; |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | protected abstract function getGadgetsData(); |
@@ -599,19 +599,19 @@ discard block |
||
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | public function getGadget($gadgetID) { |
| 602 | - if(!is_numeric($gadgetID)) { |
|
| 602 | + if (!is_numeric($gadgetID)) { |
|
| 603 | 603 | global $GADGETS; |
| 604 | 604 | $gadgetID = $GADGETS[$gadgetID]['ID']; |
| 605 | 605 | } |
| 606 | 606 | $gadgets = $this->getGadgets(); |
| 607 | - if(isset($gadgets[$gadgetID])) |
|
| 607 | + if (isset($gadgets[$gadgetID])) |
|
| 608 | 608 | return $gadgets[$gadgetID]; |
| 609 | 609 | return false; |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | public function isGadgetEquipped($gadgetID) { |
| 613 | 613 | $gadget = $this->getGadget($gadgetID); |
| 614 | - if($gadget===false) |
|
| 614 | + if ($gadget === false) |
|
| 615 | 615 | return false; |
| 616 | 616 | return $gadget['Equipped'] > 0 && $gadget['Equipped'] < TIME && ($gadget['Expires'] == 0 || $gadget['Expires'] > TIME) && $gadget['Cooldown'] <= TIME; |
| 617 | 617 | } |
@@ -632,10 +632,10 @@ discard block |
||
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | public function getRelations() { |
| 635 | - if(!isset($this->relations)) { |
|
| 635 | + if (!isset($this->relations)) { |
|
| 636 | 636 | //get relations |
| 637 | 637 | $RACES = Globals::getRaces(); |
| 638 | - $raceRelations = Globals::getRaceRelations($this->getGameID(),$this->getRaceID()); |
|
| 638 | + $raceRelations = Globals::getRaceRelations($this->getGameID(), $this->getRaceID()); |
|
| 639 | 639 | $pureRels = $this->getPureRelations(); // make sure they're initialised. |
| 640 | 640 | $this->relations = array(); |
| 641 | 641 | foreach ($RACES as $raceID => $raceName) { |
@@ -680,26 +680,26 @@ discard block |
||
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | public function hasMilitaryPayment() { |
| 683 | - return $this->getMilitaryPayment()>0; |
|
| 683 | + return $this->getMilitaryPayment() > 0; |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | public function setMilitaryPayment($amount) { |
| 687 | - if($this->militaryPayment == $amount) |
|
| 687 | + if ($this->militaryPayment == $amount) |
|
| 688 | 688 | return; |
| 689 | 689 | $this->militaryPayment = $amount; |
| 690 | - $this->hasChanged=true; |
|
| 690 | + $this->hasChanged = true; |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | public function increaseMilitaryPayment($amount) { |
| 694 | - if($amount < 0) |
|
| 694 | + if ($amount < 0) |
|
| 695 | 695 | throw new Exception('Trying to increase negative military payment.'); |
| 696 | - $this->setMilitaryPayment($this->getMilitaryPayment()+$amount); |
|
| 696 | + $this->setMilitaryPayment($this->getMilitaryPayment() + $amount); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | public function decreaseMilitaryPayment($amount) { |
| 700 | - if($amount < 0) |
|
| 700 | + if ($amount < 0) |
|
| 701 | 701 | throw new Exception('Trying to decrease negative military payment.'); |
| 702 | - $this->setMilitaryPayment($this->getMilitaryPayment()-$amount); |
|
| 702 | + $this->setMilitaryPayment($this->getMilitaryPayment() - $amount); |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | abstract protected function getBountiesData(); |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | public function hasBounties() { |
| 713 | - return count($this->getBounties())>0; |
|
| 713 | + return count($this->getBounties()) > 0; |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | public function getBounty($bountyID) { |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | public function hasBounty($bountyID) { |
| 722 | - return $this->getBounty($bountyID)!==false; |
|
| 722 | + return $this->getBounty($bountyID) !== false; |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | public function getBountyAmount($bountyID) { |
@@ -740,15 +740,15 @@ discard block |
||
| 740 | 740 | |
| 741 | 741 | public function getNextBountyID() { |
| 742 | 742 | $keys = array_keys($this->getBounties()); |
| 743 | - if(count($keys)>0) |
|
| 744 | - return max($keys)+1; |
|
| 743 | + if (count($keys) > 0) |
|
| 744 | + return max($keys) + 1; |
|
| 745 | 745 | else |
| 746 | 746 | return 0; |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | public function setBounty(array $bounty) { |
| 750 | 750 | $this->bounties[$bounty['ID']] = $bounty; |
| 751 | - $this->hasBountyChanged[$bounty['ID']]=true; |
|
| 751 | + $this->hasBountyChanged[$bounty['ID']] = true; |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | public function setBountyAmount($bountyID, $amount) { |
@@ -757,22 +757,22 @@ discard block |
||
| 757 | 757 | $this->setBounty($bounty); |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | - public function increaseBountyAmount($bountyID,$amount) { |
|
| 761 | - if($amount < 0) |
|
| 760 | + public function increaseBountyAmount($bountyID, $amount) { |
|
| 761 | + if ($amount < 0) |
|
| 762 | 762 | throw new Exception('Trying to increase negative bounty.'); |
| 763 | - $this->setBountyAmount($this->getBountyAmount($bountyID)+$amount); |
|
| 763 | + $this->setBountyAmount($this->getBountyAmount($bountyID) + $amount); |
|
| 764 | 764 | } |
| 765 | 765 | |
| 766 | - public function decreaseBountyAmount($bountyID,$amount) { |
|
| 767 | - if($amount < 0) |
|
| 766 | + public function decreaseBountyAmount($bountyID, $amount) { |
|
| 767 | + if ($amount < 0) |
|
| 768 | 768 | throw new Exception('Trying to decrease negative bounty.'); |
| 769 | - $this->setBountyAmount($this->getBountyAmount($bountyID)+$amount); |
|
| 769 | + $this->setBountyAmount($this->getBountyAmount($bountyID) + $amount); |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | public function getCurrentBounty($type) { |
| 773 | 773 | $bounties = $this->getBounties(); |
| 774 | - foreach($bounties as $bounty) { |
|
| 775 | - if($bounty['Claimer'] == 0 && $bounty['Type']==$type) |
|
| 774 | + foreach ($bounties as $bounty) { |
|
| 775 | + if ($bounty['Claimer'] == 0 && $bounty['Type'] == $type) |
|
| 776 | 776 | return $bounty; |
| 777 | 777 | } |
| 778 | 778 | return $this->createBounty($type); |
@@ -780,8 +780,8 @@ discard block |
||
| 780 | 780 | |
| 781 | 781 | public function hasCurrentBounty($type) { |
| 782 | 782 | $bounties = $this->getBounties(); |
| 783 | - foreach($bounties as $bounty) { |
|
| 784 | - if($bounty['Claimer'] == 0 && $bounty['Type']==$type) |
|
| 783 | + foreach ($bounties as $bounty) { |
|
| 784 | + if ($bounty['Claimer'] == 0 && $bounty['Type'] == $type) |
|
| 785 | 785 | return true; |
| 786 | 786 | } |
| 787 | 787 | return false; |
@@ -794,22 +794,22 @@ discard block |
||
| 794 | 794 | |
| 795 | 795 | public function setCurrentBountyAmount($type, $amount) { |
| 796 | 796 | $bounty = $this->getCurrentBounty($type); |
| 797 | - if($bounty['Amount'] == $amount) |
|
| 797 | + if ($bounty['Amount'] == $amount) |
|
| 798 | 798 | return; |
| 799 | 799 | $bounty['Amount'] = $amount; |
| 800 | 800 | $this->setBounty($bounty); |
| 801 | 801 | } |
| 802 | 802 | |
| 803 | - public function increaseCurrentBountyAmount($type,$amount) { |
|
| 804 | - if($amount < 0) |
|
| 803 | + public function increaseCurrentBountyAmount($type, $amount) { |
|
| 804 | + if ($amount < 0) |
|
| 805 | 805 | throw new Exception('Trying to increase negative current bounty.'); |
| 806 | - $this->setCurrentBountyAmount($type,$this->getCurrentBountyAmount($type)+$amount); |
|
| 806 | + $this->setCurrentBountyAmount($type, $this->getCurrentBountyAmount($type) + $amount); |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | - public function decreaseCurrentBountyAmount($type,$amount) { |
|
| 810 | - if($amount < 0) |
|
| 809 | + public function decreaseCurrentBountyAmount($type, $amount) { |
|
| 810 | + if ($amount < 0) |
|
| 811 | 811 | throw new Exception('Trying to decrease negative current bounty.'); |
| 812 | - $this->setCurrentBountyAmount($type,$this->getCurrentBountyAmount($type)-$amount); |
|
| 812 | + $this->setCurrentBountyAmount($type, $this->getCurrentBountyAmount($type) - $amount); |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | public function getCurrentBountySmrCredits($type) { |
@@ -819,29 +819,29 @@ discard block |
||
| 819 | 819 | |
| 820 | 820 | public function setCurrentBountySmrCredits($type, $credits) { |
| 821 | 821 | $bounty = $this->getCurrentBounty($type); |
| 822 | - if($bounty['SmrCredits'] == $credits) |
|
| 822 | + if ($bounty['SmrCredits'] == $credits) |
|
| 823 | 823 | return; |
| 824 | 824 | $bounty['SmrCredits'] = $credits; |
| 825 | 825 | $this->setBounty($bounty); |
| 826 | 826 | } |
| 827 | 827 | |
| 828 | - public function increaseCurrentBountySmrCredits($type,$credits) { |
|
| 829 | - if($credits<0) |
|
| 828 | + public function increaseCurrentBountySmrCredits($type, $credits) { |
|
| 829 | + if ($credits < 0) |
|
| 830 | 830 | throw new Exception('Trying to increase negative current bounty.'); |
| 831 | - $this->setCurrentBountySmrCredits($type,$this->getCurrentBountySmrCredits($type)+$credits); |
|
| 831 | + $this->setCurrentBountySmrCredits($type, $this->getCurrentBountySmrCredits($type) + $credits); |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | - public function decreaseCurrentBountySmrCredits($type,$credits) { |
|
| 835 | - if($credits<0) |
|
| 834 | + public function decreaseCurrentBountySmrCredits($type, $credits) { |
|
| 835 | + if ($credits < 0) |
|
| 836 | 836 | throw new Exception('Trying to decrease negative current bounty.'); |
| 837 | - $this->setCurrentBountySmrCredits($type,$this->getCurrentBountySmrCredits($type)-$credits); |
|
| 837 | + $this->setCurrentBountySmrCredits($type, $this->getCurrentBountySmrCredits($type) - $credits); |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | public function setBountiesClaimable(AbstractSmrPlayer $claimer) { |
| 841 | 841 | $bounties = $this->getBounties(); |
| 842 | - if(is_array($bounties)) { |
|
| 843 | - foreach($bounties as $bounty) { |
|
| 844 | - if($bounty['Claimer'] == 0) { |
|
| 842 | + if (is_array($bounties)) { |
|
| 843 | + foreach ($bounties as $bounty) { |
|
| 844 | + if ($bounty['Claimer'] == 0) { |
|
| 845 | 845 | $bounty['Claimer'] = $claimer->getAccountID(); |
| 846 | 846 | $this->setBounty($bounty); |
| 847 | 847 | } |
@@ -854,71 +854,71 @@ discard block |
||
| 854 | 854 | |
| 855 | 855 | public function getHOF(array $typeList = null) { |
| 856 | 856 | $this->getHOFData(); |
| 857 | - if($typeList==null) |
|
| 857 | + if ($typeList == null) |
|
| 858 | 858 | return $this->HOF; |
| 859 | - $hof=$this->HOF; |
|
| 860 | - foreach($typeList as $type) { |
|
| 861 | - if(!isset($hof[$type])) |
|
| 859 | + $hof = $this->HOF; |
|
| 860 | + foreach ($typeList as $type) { |
|
| 861 | + if (!isset($hof[$type])) |
|
| 862 | 862 | return 0; |
| 863 | 863 | $hof = $hof[$type]; |
| 864 | 864 | } |
| 865 | 865 | return $hof; |
| 866 | 866 | } |
| 867 | 867 | |
| 868 | - public function increaseHOF($amount,array $typeList, $visibility) { |
|
| 869 | - if($amount < 0) |
|
| 870 | - throw new Exception('Trying to increase negative HOF: '.implode(':',$typeList)); |
|
| 871 | - if($amount == 0) |
|
| 868 | + public function increaseHOF($amount, array $typeList, $visibility) { |
|
| 869 | + if ($amount < 0) |
|
| 870 | + throw new Exception('Trying to increase negative HOF: ' . implode(':', $typeList)); |
|
| 871 | + if ($amount == 0) |
|
| 872 | 872 | return; |
| 873 | - $this->setHOF($this->getHOF($typeList)+$amount,$typeList, $visibility); |
|
| 873 | + $this->setHOF($this->getHOF($typeList) + $amount, $typeList, $visibility); |
|
| 874 | 874 | } |
| 875 | 875 | |
| 876 | - public function decreaseHOF($amount,array $typeList, $visibility) { |
|
| 877 | - if($amount < 0) |
|
| 878 | - throw new Exception('Trying to decrease negative HOF: '.implode(':',$typeList)); |
|
| 879 | - if($amount == 0) |
|
| 876 | + public function decreaseHOF($amount, array $typeList, $visibility) { |
|
| 877 | + if ($amount < 0) |
|
| 878 | + throw new Exception('Trying to decrease negative HOF: ' . implode(':', $typeList)); |
|
| 879 | + if ($amount == 0) |
|
| 880 | 880 | return; |
| 881 | - $this->setHOF($this->getHOF($typeList)-$amount,$typeList, $visibility); |
|
| 881 | + $this->setHOF($this->getHOF($typeList) - $amount, $typeList, $visibility); |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | - public function setHOF($amount,array $typeList, $visibility) { |
|
| 885 | - if(is_array($this->getHOF($typeList))) |
|
| 886 | - throw new Exception('Trying to overwrite a HOF type: '.implode(':',$typeList)); |
|
| 887 | - if($this->isNPC()) { |
|
| 884 | + public function setHOF($amount, array $typeList, $visibility) { |
|
| 885 | + if (is_array($this->getHOF($typeList))) |
|
| 886 | + throw new Exception('Trying to overwrite a HOF type: ' . implode(':', $typeList)); |
|
| 887 | + if ($this->isNPC()) { |
|
| 888 | 888 | // Don't store HOF for NPCs. |
| 889 | 889 | return; |
| 890 | 890 | } |
| 891 | - if($this->getHOF($typeList)==$amount) |
|
| 891 | + if ($this->getHOF($typeList) == $amount) |
|
| 892 | 892 | return; |
| 893 | - if($amount < 0) |
|
| 894 | - $amount=0; |
|
| 893 | + if ($amount < 0) |
|
| 894 | + $amount = 0; |
|
| 895 | 895 | $this->getHOF(); |
| 896 | 896 | |
| 897 | - $hofType = implode(':',$typeList); |
|
| 898 | - if(!isset(self::$HOFVis[$hofType])) { |
|
| 897 | + $hofType = implode(':', $typeList); |
|
| 898 | + if (!isset(self::$HOFVis[$hofType])) { |
|
| 899 | 899 | self::$hasHOFVisChanged[$hofType] = self::HOF_NEW; |
| 900 | 900 | } |
| 901 | - else if(self::$HOFVis[$hofType] != $visibility) { |
|
| 901 | + else if (self::$HOFVis[$hofType] != $visibility) { |
|
| 902 | 902 | self::$hasHOFVisChanged[$hofType] = self::HOF_CHANGED; |
| 903 | 903 | } |
| 904 | 904 | self::$HOFVis[$hofType] = $visibility; |
| 905 | 905 | |
| 906 | - $hof =& $this->HOF; |
|
| 907 | - $hofChanged =& $this->hasHOFChanged; |
|
| 906 | + $hof = & $this->HOF; |
|
| 907 | + $hofChanged = & $this->hasHOFChanged; |
|
| 908 | 908 | $new = false; |
| 909 | - foreach($typeList as $type) { |
|
| 910 | - if(!isset($hofChanged[$type])) |
|
| 909 | + foreach ($typeList as $type) { |
|
| 910 | + if (!isset($hofChanged[$type])) |
|
| 911 | 911 | $hofChanged[$type] = array(); |
| 912 | - if(!isset($hof[$type])) { |
|
| 912 | + if (!isset($hof[$type])) { |
|
| 913 | 913 | $hof[$type] = array(); |
| 914 | 914 | $new = true; |
| 915 | 915 | } |
| 916 | - $hof =& $hof[$type]; |
|
| 917 | - $hofChanged =& $hofChanged[$type]; |
|
| 916 | + $hof = & $hof[$type]; |
|
| 917 | + $hofChanged = & $hofChanged[$type]; |
|
| 918 | 918 | } |
| 919 | - if($hofChanged==null) { |
|
| 919 | + if ($hofChanged == null) { |
|
| 920 | 920 | $hofChanged = self::HOF_CHANGED; |
| 921 | - if($new) |
|
| 921 | + if ($new) |
|
| 922 | 922 | $hofChanged = self::HOF_NEW; |
| 923 | 923 | } |
| 924 | 924 | $hof = $amount; |
@@ -936,7 +936,7 @@ discard block |
||
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | public function hasTurns() { |
| 939 | - return $this->turns>0; |
|
| 939 | + return $this->turns > 0; |
|
| 940 | 940 | } |
| 941 | 941 | |
| 942 | 942 | public function getMaxTurns() { |
@@ -944,41 +944,41 @@ discard block |
||
| 944 | 944 | // round(DEFAULT_MAX_TURNS * Globals::getGameSpeed($this->getGameID())); |
| 945 | 945 | } |
| 946 | 946 | |
| 947 | - public function setTurns($turns,$newNoob = false,$updateLastActive = false) { |
|
| 948 | - if($this->turns == $turns && ($this->newbieTurns == $newNoob || $newNoob==false) && !$updateLastActive) |
|
| 947 | + public function setTurns($turns, $newNoob = false, $updateLastActive = false) { |
|
| 948 | + if ($this->turns == $turns && ($this->newbieTurns == $newNoob || $newNoob == false) && !$updateLastActive) |
|
| 949 | 949 | return; |
| 950 | 950 | |
| 951 | 951 | // Make sure turns are in range [0, MaxTurns] |
| 952 | 952 | $this->turns = max(0, min($turns, $this->getMaxTurns())); |
| 953 | 953 | |
| 954 | - if($newNoob !== false) |
|
| 954 | + if ($newNoob !== false) |
|
| 955 | 955 | $this->newbieTurns = $newNoob; |
| 956 | 956 | if ($this->newbieTurns < 0) |
| 957 | 957 | $this->newbieTurns = 0; |
| 958 | 958 | |
| 959 | - $this->hasChanged=true; |
|
| 960 | - if($updateLastActive === true) { |
|
| 959 | + $this->hasChanged = true; |
|
| 960 | + if ($updateLastActive === true) { |
|
| 961 | 961 | $this->setLastActive(TIME); |
| 962 | 962 | $this->updateLastCPLAction(); |
| 963 | 963 | } |
| 964 | 964 | } |
| 965 | 965 | |
| 966 | 966 | public function takeTurns($take, $noob = 0, $updateLastActive = true) { |
| 967 | - if($take < 0 || $noob < 0) |
|
| 967 | + if ($take < 0 || $noob < 0) |
|
| 968 | 968 | throw new Exception('Trying to take negative turns.'); |
| 969 | 969 | $take = ceil($take); |
| 970 | 970 | $new_turns = $this->getTurns() - $take; |
| 971 | - $newbiesTaken = min($this->getNewbieTurns(),$noob); |
|
| 971 | + $newbiesTaken = min($this->getNewbieTurns(), $noob); |
|
| 972 | 972 | $new_noob = $this->getNewbieTurns() - $noob; |
| 973 | 973 | |
| 974 | 974 | $this->setTurns($new_turns, $new_noob, $updateLastActive); |
| 975 | - $this->increaseHOF($take,array('Movement','Turns Used','Since Last Death'), HOF_ALLIANCE); |
|
| 976 | - $this->increaseHOF($take,array('Movement','Turns Used','Total'), HOF_ALLIANCE); |
|
| 977 | - $this->increaseHOF($newbiesTaken,array('Movement','Turns Used','Newbie'), HOF_ALLIANCE); |
|
| 975 | + $this->increaseHOF($take, array('Movement', 'Turns Used', 'Since Last Death'), HOF_ALLIANCE); |
|
| 976 | + $this->increaseHOF($take, array('Movement', 'Turns Used', 'Total'), HOF_ALLIANCE); |
|
| 977 | + $this->increaseHOF($newbiesTaken, array('Movement', 'Turns Used', 'Newbie'), HOF_ALLIANCE); |
|
| 978 | 978 | } |
| 979 | 979 | |
| 980 | - public function giveTurns($give, $noob = 0,$updateLastActive = false) { |
|
| 981 | - if($give < 0 || $noob < 0) |
|
| 980 | + public function giveTurns($give, $noob = 0, $updateLastActive = false) { |
|
| 981 | + if ($give < 0 || $noob < 0) |
|
| 982 | 982 | throw new Exception('Trying to give negative turns.'); |
| 983 | 983 | $give = floor($give); |
| 984 | 984 | |
@@ -990,10 +990,10 @@ discard block |
||
| 990 | 990 | } |
| 991 | 991 | |
| 992 | 992 | public function setLastActive($lastActive) { |
| 993 | - if($this->lastActive == $lastActive) |
|
| 993 | + if ($this->lastActive == $lastActive) |
|
| 994 | 994 | return; |
| 995 | - $this->lastActive=$lastActive; |
|
| 996 | - $this->hasChanged=true; |
|
| 995 | + $this->lastActive = $lastActive; |
|
| 996 | + $this->hasChanged = true; |
|
| 997 | 997 | } |
| 998 | 998 | |
| 999 | 999 | public function getLastCPLAction() { |
@@ -1001,10 +1001,10 @@ discard block |
||
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | 1003 | public function setLastCPLAction($time) { |
| 1004 | - if($this->lastCPLAction == $time) |
|
| 1004 | + if ($this->lastCPLAction == $time) |
|
| 1005 | 1005 | return; |
| 1006 | - $this->lastCPLAction=$time; |
|
| 1007 | - $this->hasChanged=true; |
|
| 1006 | + $this->lastCPLAction = $time; |
|
| 1007 | + $this->hasChanged = true; |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | public function updateLastCPLAction() { |
@@ -1013,7 +1013,7 @@ discard block |
||
| 1013 | 1013 | |
| 1014 | 1014 | |
| 1015 | 1015 | function getCompletedMissions() { |
| 1016 | - if(!isset($this->completedMissions)) { |
|
| 1016 | + if (!isset($this->completedMissions)) { |
|
| 1017 | 1017 | //Get Player missions |
| 1018 | 1018 | $this->db->query('SELECT mission_id FROM player_completed_mission WHERE ' . $this->SQL); |
| 1019 | 1019 | $this->completedMissions = array(); |
@@ -1024,7 +1024,7 @@ discard block |
||
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | public function getMissions() { |
| 1027 | - if(!isset($this->missions)) { |
|
| 1027 | + if (!isset($this->missions)) { |
|
| 1028 | 1028 | $this->db->query('SELECT * FROM player_has_mission WHERE ' . $this->SQL); |
| 1029 | 1029 | $this->missions = array(); |
| 1030 | 1030 | while ($this->db->nextRecord()) { |
@@ -1045,7 +1045,7 @@ discard block |
||
| 1045 | 1045 | |
| 1046 | 1046 | public function getActiveMissions() { |
| 1047 | 1047 | $missions = $this->getMissions(); |
| 1048 | - foreach($missions as $missionID => $mission) { |
|
| 1048 | + foreach ($missions as $missionID => $mission) { |
|
| 1049 | 1049 | if ($mission['On Step'] >= count(MISSIONS[$missionID]['Steps'])) { |
| 1050 | 1050 | unset($missions[$missionID]); |
| 1051 | 1051 | } |
@@ -1055,7 +1055,7 @@ discard block |
||
| 1055 | 1055 | |
| 1056 | 1056 | function getMission($missionID) { |
| 1057 | 1057 | $missions = $this->getMissions(); |
| 1058 | - if(isset($missions[$missionID])) |
|
| 1058 | + if (isset($missions[$missionID])) |
|
| 1059 | 1059 | return $missions[$missionID]; |
| 1060 | 1060 | return false; |
| 1061 | 1061 | } |
@@ -1066,7 +1066,7 @@ discard block |
||
| 1066 | 1066 | |
| 1067 | 1067 | function updateMission($missionID) { |
| 1068 | 1068 | $this->getMissions(); |
| 1069 | - if(isset($this->missions[$missionID])) { |
|
| 1069 | + if (isset($this->missions[$missionID])) { |
|
| 1070 | 1070 | $mission = $this->missions[$missionID]; |
| 1071 | 1071 | $this->db->query(' |
| 1072 | 1072 | UPDATE player_has_mission |
@@ -1084,15 +1084,15 @@ discard block |
||
| 1084 | 1084 | } |
| 1085 | 1085 | |
| 1086 | 1086 | private function setupMissionStep($missionID) { |
| 1087 | - $mission =& $this->missions[$missionID]; |
|
| 1087 | + $mission = & $this->missions[$missionID]; |
|
| 1088 | 1088 | $step = MISSIONS[$missionID]['Steps'][$mission['On Step']]; |
| 1089 | - if(isset($step['PickSector'])) { |
|
| 1089 | + if (isset($step['PickSector'])) { |
|
| 1090 | 1090 | $realX = Plotter::getX($step['PickSector']['Type'], $step['PickSector']['X'], $this->getGameID()); |
| 1091 | - if($realX === false) { |
|
| 1091 | + if ($realX === false) { |
|
| 1092 | 1092 | throw new Exception('Invalid PickSector definition in mission: ' . $missionID); |
| 1093 | 1093 | } |
| 1094 | 1094 | $path = Plotter::findDistanceToX($realX, $this->getSector(), true, null, $this); |
| 1095 | - if($path === false) { |
|
| 1095 | + if ($path === false) { |
|
| 1096 | 1096 | throw new Exception('Cannot find location: ' . $missionID); |
| 1097 | 1097 | } |
| 1098 | 1098 | $mission['Sector'] = $path->getEndSectorID(); |
@@ -1102,7 +1102,7 @@ discard block |
||
| 1102 | 1102 | function addMission($missionID) { |
| 1103 | 1103 | $this->getMissions(); |
| 1104 | 1104 | |
| 1105 | - if(isset($this->missions[$missionID])) |
|
| 1105 | + if (isset($this->missions[$missionID])) |
|
| 1106 | 1106 | return; |
| 1107 | 1107 | $sector = 0; |
| 1108 | 1108 | |
@@ -1115,13 +1115,13 @@ discard block |
||
| 1115 | 1115 | 'Starting Sector' => $this->getSectorID() |
| 1116 | 1116 | ); |
| 1117 | 1117 | |
| 1118 | - $this->missions[$missionID] =& $mission; |
|
| 1118 | + $this->missions[$missionID] = & $mission; |
|
| 1119 | 1119 | $this->setupMissionStep($missionID); |
| 1120 | 1120 | $this->rebuildMission($missionID); |
| 1121 | 1121 | |
| 1122 | 1122 | $this->db->query(' |
| 1123 | 1123 | REPLACE INTO player_has_mission (game_id,account_id,mission_id,on_step,progress,unread,starting_sector,mission_sector,step_fails) |
| 1124 | - VALUES ('.$this->db->escapeNumber($this->gameID).','.$this->db->escapeNumber($this->accountID).','.$this->db->escapeNumber($missionID).','.$this->db->escapeNumber($mission['On Step']).','.$this->db->escapeNumber($mission['Progress']).','.$this->db->escapeBoolean($mission['Unread']).','.$this->db->escapeNumber($mission['Starting Sector']).','.$this->db->escapeNumber($mission['Sector']).','.$this->db->escapeNumber($mission['Expires']).')' |
|
| 1124 | + VALUES ('.$this->db->escapeNumber($this->gameID) . ',' . $this->db->escapeNumber($this->accountID) . ',' . $this->db->escapeNumber($missionID) . ',' . $this->db->escapeNumber($mission['On Step']) . ',' . $this->db->escapeNumber($mission['Progress']) . ',' . $this->db->escapeBoolean($mission['Unread']) . ',' . $this->db->escapeNumber($mission['Starting Sector']) . ',' . $this->db->escapeNumber($mission['Sector']) . ',' . $this->db->escapeNumber($mission['Expires']) . ')' |
|
| 1125 | 1125 | ); |
| 1126 | 1126 | } |
| 1127 | 1127 | |
@@ -1135,9 +1135,9 @@ discard block |
||
| 1135 | 1135 | } |
| 1136 | 1136 | else { |
| 1137 | 1137 | $currentStep = MISSIONS[$missionID]['Steps'][$mission['On Step']]; |
| 1138 | - $currentStep['Text'] = str_replace(array('<Race>','<Sector>','<Starting Sector>','<trader>'),array($this->getRaceID(),$mission['Sector'],$mission['Starting Sector'],$this->playerName),$currentStep['Text']); |
|
| 1138 | + $currentStep['Text'] = str_replace(array('<Race>', '<Sector>', '<Starting Sector>', '<trader>'), array($this->getRaceID(), $mission['Sector'], $mission['Starting Sector'], $this->playerName), $currentStep['Text']); |
|
| 1139 | 1139 | if (isset($currentStep['Task'])) { |
| 1140 | - $currentStep['Task'] = str_replace(array('<Race>','<Sector>','<Starting Sector>','<trader>'),array($this->getRaceID(),$mission['Sector'],$mission['Starting Sector'],$this->playerName),$currentStep['Task']); |
|
| 1140 | + $currentStep['Task'] = str_replace(array('<Race>', '<Sector>', '<Starting Sector>', '<trader>'), array($this->getRaceID(), $mission['Sector'], $mission['Starting Sector'], $this->playerName), $currentStep['Task']); |
|
| 1141 | 1141 | } |
| 1142 | 1142 | if (isset($currentStep['Level'])) { |
| 1143 | 1143 | $currentStep['Level'] = str_replace('<Player Level>', $this->getLevelID(), $currentStep['Level']); |
@@ -1151,9 +1151,9 @@ discard block |
||
| 1151 | 1151 | |
| 1152 | 1152 | function deleteMission($missionID) { |
| 1153 | 1153 | $this->getMissions(); |
| 1154 | - if(isset($this->missions[$missionID])) { |
|
| 1154 | + if (isset($this->missions[$missionID])) { |
|
| 1155 | 1155 | unset($this->missions[$missionID]); |
| 1156 | - $this->db->query('DELETE FROM player_has_mission WHERE '.$this->SQL.' AND mission_id = '.$this->db->escapeNumber($missionID).' LIMIT 1'); |
|
| 1156 | + $this->db->query('DELETE FROM player_has_mission WHERE ' . $this->SQL . ' AND mission_id = ' . $this->db->escapeNumber($missionID) . ' LIMIT 1'); |
|
| 1157 | 1157 | return true; |
| 1158 | 1158 | } |
| 1159 | 1159 | return false; |
@@ -1162,8 +1162,8 @@ discard block |
||
| 1162 | 1162 | public function markMissionsRead() { |
| 1163 | 1163 | $this->getMissions(); |
| 1164 | 1164 | $unreadMissions = array(); |
| 1165 | - foreach($this->missions as $missionID => &$mission) { |
|
| 1166 | - if($mission['Unread']) { |
|
| 1165 | + foreach ($this->missions as $missionID => &$mission) { |
|
| 1166 | + if ($mission['Unread']) { |
|
| 1167 | 1167 | $unreadMissions[] = $missionID; |
| 1168 | 1168 | $mission['Unread'] = false; |
| 1169 | 1169 | $this->updateMission($missionID); |
@@ -1174,17 +1174,17 @@ discard block |
||
| 1174 | 1174 | |
| 1175 | 1175 | public function claimMissionReward($missionID) { |
| 1176 | 1176 | $this->getMissions(); |
| 1177 | - $mission =& $this->missions[$missionID]; |
|
| 1178 | - if($mission === false) { |
|
| 1177 | + $mission = & $this->missions[$missionID]; |
|
| 1178 | + if ($mission === false) { |
|
| 1179 | 1179 | throw new Exception('Unknown mission: ' . $missionID); |
| 1180 | 1180 | } |
| 1181 | - if($mission['Task'] === false || $mission['Task']['Step'] != 'Claim') { |
|
| 1181 | + if ($mission['Task'] === false || $mission['Task']['Step'] != 'Claim') { |
|
| 1182 | 1182 | throw new Exception('Cannot claim mission: ' . $missionID . ', for step: ' . $mission['On Step']); |
| 1183 | 1183 | } |
| 1184 | 1184 | $mission['On Step']++; |
| 1185 | 1185 | $mission['Unread'] = true; |
| 1186 | - foreach($mission['Task']['Rewards'] as $rewardItem => $amount) { |
|
| 1187 | - switch($rewardItem) { |
|
| 1186 | + foreach ($mission['Task']['Rewards'] as $rewardItem => $amount) { |
|
| 1187 | + switch ($rewardItem) { |
|
| 1188 | 1188 | case 'Credits': |
| 1189 | 1189 | $this->increaseCredits($amount); |
| 1190 | 1190 | break; |
@@ -1206,14 +1206,14 @@ discard block |
||
| 1206 | 1206 | public function getAvailableMissions() { |
| 1207 | 1207 | $availableMissions = array(); |
| 1208 | 1208 | foreach (MISSIONS as $missionID => $mission) { |
| 1209 | - if($this->hasMission($missionID)) { |
|
| 1209 | + if ($this->hasMission($missionID)) { |
|
| 1210 | 1210 | continue; |
| 1211 | 1211 | } |
| 1212 | 1212 | $realX = Plotter::getX($mission['HasX']['Type'], $mission['HasX']['X'], $this->getGameID()); |
| 1213 | - if($realX === false) { |
|
| 1213 | + if ($realX === false) { |
|
| 1214 | 1214 | throw new Exception('Invalid HasX definition in mission: ' . $missionID); |
| 1215 | 1215 | } |
| 1216 | - if($this->getSector()->hasX($realX)) { |
|
| 1216 | + if ($this->getSector()->hasX($realX)) { |
|
| 1217 | 1217 | $availableMissions[$missionID] = $mission; |
| 1218 | 1218 | } |
| 1219 | 1219 | } |
@@ -1225,31 +1225,31 @@ discard block |
||
| 1225 | 1225 | throw new Exception('Unknown action: ' . $actionID); |
| 1226 | 1226 | } |
| 1227 | 1227 | // TODO: Reenable this once tested. if($this->getAccount()->isLoggingEnabled()) |
| 1228 | - switch($actionID) { |
|
| 1228 | + switch ($actionID) { |
|
| 1229 | 1229 | case 'WalkSector': |
| 1230 | 1230 | $this->getAccount()->log(LOG_TYPE_MOVEMENT, 'Walks to sector: ' . $values['Sector']->getSectorID(), $this->getSectorID()); |
| 1231 | 1231 | break; |
| 1232 | 1232 | case 'JoinAlliance': |
| 1233 | - $this->getAccount()->log(LOG_TYPE_ALLIANCE, 'joined alliance: '.$values['Alliance']->getAllianceName(), $this->getSectorID()); |
|
| 1233 | + $this->getAccount()->log(LOG_TYPE_ALLIANCE, 'joined alliance: ' . $values['Alliance']->getAllianceName(), $this->getSectorID()); |
|
| 1234 | 1234 | break; |
| 1235 | 1235 | case 'LeaveAlliance': |
| 1236 | - $this->getAccount()->log(LOG_TYPE_ALLIANCE, 'left alliance: '.$values['Alliance']->getAllianceName(), $this->getSectorID()); |
|
| 1236 | + $this->getAccount()->log(LOG_TYPE_ALLIANCE, 'left alliance: ' . $values['Alliance']->getAllianceName(), $this->getSectorID()); |
|
| 1237 | 1237 | break; |
| 1238 | 1238 | case 'DisbandAlliance': |
| 1239 | - $this->getAccount()->log(LOG_TYPE_ALLIANCE, 'disbanded alliance '.$values['Alliance']->getAllianceName(), $this->getSectorID()); |
|
| 1239 | + $this->getAccount()->log(LOG_TYPE_ALLIANCE, 'disbanded alliance ' . $values['Alliance']->getAllianceName(), $this->getSectorID()); |
|
| 1240 | 1240 | break; |
| 1241 | 1241 | case 'KickPlayer': |
| 1242 | - $this->getAccount()->log(LOG_TYPE_ALLIANCE, 'kicked '.$values['Player']->getAccount()->getLogin().' ('.$values['Player']->getPlayerName().') from alliance '.$values['Alliance']->getAllianceName(), 0); |
|
| 1242 | + $this->getAccount()->log(LOG_TYPE_ALLIANCE, 'kicked ' . $values['Player']->getAccount()->getLogin() . ' (' . $values['Player']->getPlayerName() . ') from alliance ' . $values['Alliance']->getAllianceName(), 0); |
|
| 1243 | 1243 | break; |
| 1244 | 1244 | case 'PlayerKicked': |
| 1245 | - $this->getAccount()->log(LOG_TYPE_ALLIANCE, 'was kicked from alliance '.$values['Alliance']->getAllianceName().' by '.$values['Player']->getAccount()->getLogin().' ('.$values['Player']->getPlayerName().')', 0); |
|
| 1245 | + $this->getAccount()->log(LOG_TYPE_ALLIANCE, 'was kicked from alliance ' . $values['Alliance']->getAllianceName() . ' by ' . $values['Player']->getAccount()->getLogin() . ' (' . $values['Player']->getPlayerName() . ')', 0); |
|
| 1246 | 1246 | break; |
| 1247 | 1247 | |
| 1248 | 1248 | } |
| 1249 | 1249 | $this->getMissions(); |
| 1250 | - foreach($this->missions as $missionID => &$mission) { |
|
| 1251 | - if($mission['Task'] !== false && $mission['Task']['Step'] == $actionID) { |
|
| 1252 | - if(checkMissionRequirements($values, $mission, $this) === true) { |
|
| 1250 | + foreach ($this->missions as $missionID => &$mission) { |
|
| 1251 | + if ($mission['Task'] !== false && $mission['Task']['Step'] == $actionID) { |
|
| 1252 | + if (checkMissionRequirements($values, $mission, $this) === true) { |
|
| 1253 | 1253 | $mission['On Step']++; |
| 1254 | 1254 | $mission['Unread'] = true; |
| 1255 | 1255 | $this->setupMissionStep($missionID); |
@@ -1261,8 +1261,8 @@ discard block |
||
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | 1263 | public function canSeeAny(array $otherPlayerArray) { |
| 1264 | - foreach($otherPlayerArray as $otherPlayer) { |
|
| 1265 | - if($this->canSee($otherPlayer)) { |
|
| 1264 | + foreach ($otherPlayerArray as $otherPlayer) { |
|
| 1265 | + if ($this->canSee($otherPlayer)) { |
|
| 1266 | 1266 | return true; |
| 1267 | 1267 | } |
| 1268 | 1268 | } |
@@ -1270,21 +1270,21 @@ discard block |
||
| 1270 | 1270 | } |
| 1271 | 1271 | |
| 1272 | 1272 | public function canSee(AbstractSmrPlayer $otherPlayer) { |
| 1273 | - if(!$otherPlayer->getShip()->isCloaked()) |
|
| 1273 | + if (!$otherPlayer->getShip()->isCloaked()) |
|
| 1274 | 1274 | return true; |
| 1275 | - if($this->sameAlliance($otherPlayer)) |
|
| 1275 | + if ($this->sameAlliance($otherPlayer)) |
|
| 1276 | 1276 | return true; |
| 1277 | - if($this->getExperience()>=$otherPlayer->getExperience()) |
|
| 1277 | + if ($this->getExperience() >= $otherPlayer->getExperience()) |
|
| 1278 | 1278 | return true; |
| 1279 | 1279 | return false; |
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | 1282 | public function equals(AbstractSmrPlayer $otherPlayer = null) { |
| 1283 | - return $otherPlayer!==null && $this->getAccountID()==$otherPlayer->getAccountID() && $this->getGameID()==$otherPlayer->getGameID(); |
|
| 1283 | + return $otherPlayer !== null && $this->getAccountID() == $otherPlayer->getAccountID() && $this->getGameID() == $otherPlayer->getGameID(); |
|
| 1284 | 1284 | } |
| 1285 | 1285 | |
| 1286 | 1286 | public function sameAlliance(AbstractSmrPlayer $otherPlayer = null) { |
| 1287 | - return $otherPlayer != null && ($this->equals($otherPlayer) || ($this->hasAlliance() && $this->getAllianceID()==$otherPlayer->getAllianceID())); |
|
| 1287 | + return $otherPlayer != null && ($this->equals($otherPlayer) || ($this->hasAlliance() && $this->getAllianceID() == $otherPlayer->getAllianceID())); |
|
| 1288 | 1288 | } |
| 1289 | 1289 | |
| 1290 | 1290 | public function sharedForceAlliance(AbstractSmrPlayer $otherPlayer = null) { |
@@ -1328,10 +1328,10 @@ discard block |
||
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | public function meetsAlignmentRestriction($restriction) { |
| 1331 | - if($restriction<0) |
|
| 1332 | - return $this->getAlignment()<=$restriction; |
|
| 1333 | - if($restriction>0) |
|
| 1334 | - return $this->getAlignment()>=$restriction; |
|
| 1331 | + if ($restriction < 0) |
|
| 1332 | + return $this->getAlignment() <= $restriction; |
|
| 1333 | + if ($restriction > 0) |
|
| 1334 | + return $this->getAlignment() >= $restriction; |
|
| 1335 | 1335 | return true; |
| 1336 | 1336 | } |
| 1337 | 1337 | |
@@ -1351,10 +1351,10 @@ discard block |
||
| 1351 | 1351 | * Will retrieve all visited sectors, use only when you are likely to check a large number of these |
| 1352 | 1352 | */ |
| 1353 | 1353 | public function hasVisitedSector($sectorID) { |
| 1354 | - if(!isset($this->visitedSectors)) { |
|
| 1354 | + if (!isset($this->visitedSectors)) { |
|
| 1355 | 1355 | $this->visitedSectors = array(); |
| 1356 | 1356 | $this->db->query('SELECT sector_id FROM player_visited_sector WHERE ' . $this->SQL); |
| 1357 | - while($this->db->nextRecord()) |
|
| 1357 | + while ($this->db->nextRecord()) |
|
| 1358 | 1358 | $this->visitedSectors[$this->db->getField('sector_id')] = false; |
| 1359 | 1359 | } |
| 1360 | 1360 | return !isset($this->visitedSectors[$sectorID]); |
@@ -1365,7 +1365,7 @@ discard block |
||
| 1365 | 1365 | } |
| 1366 | 1366 | |
| 1367 | 1367 | public function getExamineTraderHREF() { |
| 1368 | - $container = create_container('skeleton.php','trader_examine.php'); |
|
| 1368 | + $container = create_container('skeleton.php', 'trader_examine.php'); |
|
| 1369 | 1369 | $container['target'] = $this->getAccountID(); |
| 1370 | 1370 | return SmrSession::getNewHREF($container); |
| 1371 | 1371 | } |
@@ -1375,13 +1375,13 @@ discard block |
||
| 1375 | 1375 | } |
| 1376 | 1376 | |
| 1377 | 1377 | public function getPlanetKickHREF() { |
| 1378 | - $container = create_container('planet_kick_processing.php','trader_attack_processing.php'); |
|
| 1378 | + $container = create_container('planet_kick_processing.php', 'trader_attack_processing.php'); |
|
| 1379 | 1379 | $container['account_id'] = $this->getAccountID(); |
| 1380 | 1380 | return SmrSession::getNewHREF($container); |
| 1381 | 1381 | } |
| 1382 | 1382 | |
| 1383 | 1383 | public function getTraderSearchHREF() { |
| 1384 | - $container = create_container('skeleton.php','trader_search_result.php'); |
|
| 1384 | + $container = create_container('skeleton.php', 'trader_search_result.php'); |
|
| 1385 | 1385 | $container['player_id'] = $this->getPlayerID(); |
| 1386 | 1386 | return SmrSession::getNewHREF($container); |
| 1387 | 1387 | } |
@@ -1391,7 +1391,7 @@ discard block |
||
| 1391 | 1391 | } |
| 1392 | 1392 | |
| 1393 | 1393 | public function getToggleWeaponHidingHREF() { |
| 1394 | - $container = create_container('skeleton.php','toggle_processing.php'); |
|
| 1394 | + $container = create_container('skeleton.php', 'toggle_processing.php'); |
|
| 1395 | 1395 | $container['toggle'] = 'WeaponHiding'; |
| 1396 | 1396 | return SmrSession::getNewHREF($container); |
| 1397 | 1397 | } |
@@ -78,8 +78,9 @@ discard block |
||
| 78 | 78 | return $this->getNewbieTurns()>0; |
| 79 | 79 | } |
| 80 | 80 | public function setNewbieTurns($newbieTurns) { |
| 81 | - if($this->newbieTurns == $newbieTurns) |
|
| 82 | - return; |
|
| 81 | + if($this->newbieTurns == $newbieTurns) { |
|
| 82 | + return; |
|
| 83 | + } |
|
| 83 | 84 | $this->newbieTurns=$newbieTurns; |
| 84 | 85 | $this->hasChanged=true; |
| 85 | 86 | } |
@@ -89,8 +90,9 @@ discard block |
||
| 89 | 90 | } |
| 90 | 91 | |
| 91 | 92 | public function setShipTypeID($shipID) { |
| 92 | - if($this->shipID == $shipID) |
|
| 93 | - return; |
|
| 93 | + if($this->shipID == $shipID) { |
|
| 94 | + return; |
|
| 95 | + } |
|
| 94 | 96 | $this->shipID=$shipID; |
| 95 | 97 | $this->hasChanged=true; |
| 96 | 98 | } |
@@ -206,8 +208,9 @@ discard block |
||
| 206 | 208 | } |
| 207 | 209 | |
| 208 | 210 | $ship = $this->getShip(); |
| 209 | - if ($ship->hasIllegalGoods()) |
|
| 210 | - return false; |
|
| 211 | + if ($ship->hasIllegalGoods()) { |
|
| 212 | + return false; |
|
| 213 | + } |
|
| 211 | 214 | |
| 212 | 215 | if ($ship->getAttackRating() <= $this->getSafeAttackRating()) { |
| 213 | 216 | foreach($sector->getFedRaceIDs() as $fedRaceID) { |
@@ -248,8 +251,9 @@ discard block |
||
| 248 | 251 | } |
| 249 | 252 | |
| 250 | 253 | public function setDead($bool) { |
| 251 | - if($this->dead == $bool) |
|
| 252 | - return; |
|
| 254 | + if($this->dead == $bool) { |
|
| 255 | + return; |
|
| 256 | + } |
|
| 253 | 257 | $this->dead=$bool; |
| 254 | 258 | $this->hasChanged=true; |
| 255 | 259 | } |
@@ -259,14 +263,16 @@ discard block |
||
| 259 | 263 | } |
| 260 | 264 | |
| 261 | 265 | public function increaseKills($kills) { |
| 262 | - if($kills < 0) |
|
| 263 | - throw new Exception('Trying to increase negative kills.'); |
|
| 266 | + if($kills < 0) { |
|
| 267 | + throw new Exception('Trying to increase negative kills.'); |
|
| 268 | + } |
|
| 264 | 269 | $this->setKills($this->kills+$kills); |
| 265 | 270 | } |
| 266 | 271 | |
| 267 | 272 | public function setKills($kills) { |
| 268 | - if($this->kills == $kills) |
|
| 269 | - return; |
|
| 273 | + if($this->kills == $kills) { |
|
| 274 | + return; |
|
| 275 | + } |
|
| 270 | 276 | $this->kills=$kills; |
| 271 | 277 | $this->hasChanged=true; |
| 272 | 278 | } |
@@ -276,14 +282,16 @@ discard block |
||
| 276 | 282 | } |
| 277 | 283 | |
| 278 | 284 | public function increaseDeaths($deaths) { |
| 279 | - if($deaths < 0) |
|
| 280 | - throw new Exception('Trying to increase negative deaths.'); |
|
| 285 | + if($deaths < 0) { |
|
| 286 | + throw new Exception('Trying to increase negative deaths.'); |
|
| 287 | + } |
|
| 281 | 288 | $this->setDeaths($this->getDeaths()+$deaths); |
| 282 | 289 | } |
| 283 | 290 | |
| 284 | 291 | public function setDeaths($deaths) { |
| 285 | - if($this->deaths == $deaths) |
|
| 286 | - return; |
|
| 292 | + if($this->deaths == $deaths) { |
|
| 293 | + return; |
|
| 294 | + } |
|
| 287 | 295 | $this->deaths = $deaths; |
| 288 | 296 | $this->hasChanged=true; |
| 289 | 297 | } |
@@ -305,24 +313,29 @@ discard block |
||
| 305 | 313 | } |
| 306 | 314 | |
| 307 | 315 | public function increaseAlignment($align) { |
| 308 | - if($align < 0) |
|
| 309 | - throw new Exception('Trying to increase negative align.'); |
|
| 310 | - if($align == 0) |
|
| 311 | - return; |
|
| 316 | + if($align < 0) { |
|
| 317 | + throw new Exception('Trying to increase negative align.'); |
|
| 318 | + } |
|
| 319 | + if($align == 0) { |
|
| 320 | + return; |
|
| 321 | + } |
|
| 312 | 322 | $align += $this->alignment; |
| 313 | 323 | $this->setAlignment($align); |
| 314 | 324 | } |
| 315 | 325 | public function decreaseAlignment($align) { |
| 316 | - if($align < 0) |
|
| 317 | - throw new Exception('Trying to decrease negative align.'); |
|
| 318 | - if($align == 0) |
|
| 319 | - return; |
|
| 326 | + if($align < 0) { |
|
| 327 | + throw new Exception('Trying to decrease negative align.'); |
|
| 328 | + } |
|
| 329 | + if($align == 0) { |
|
| 330 | + return; |
|
| 331 | + } |
|
| 320 | 332 | $align = $this->alignment - $align; |
| 321 | 333 | $this->setAlignment($align); |
| 322 | 334 | } |
| 323 | 335 | public function setAlignment($align) { |
| 324 | - if($this->alignment == $align) |
|
| 325 | - return; |
|
| 336 | + if($this->alignment == $align) { |
|
| 337 | + return; |
|
| 338 | + } |
|
| 326 | 339 | $this->alignment = $align; |
| 327 | 340 | $this->hasChanged=true; |
| 328 | 341 | } |
@@ -336,8 +349,9 @@ discard block |
||
| 336 | 349 | } |
| 337 | 350 | |
| 338 | 351 | public function getNextLevelPercentAcquired() { |
| 339 | - if($this->getNextLevelExperience() == $this->getThisLevelExperience()) |
|
| 340 | - return 100; |
|
| 352 | + if($this->getNextLevelExperience() == $this->getThisLevelExperience()) { |
|
| 353 | + return 100; |
|
| 354 | + } |
|
| 341 | 355 | return max(0,min(100,round(($this->getExperience() - $this->getThisLevelExperience()) / ($this->getNextLevelExperience() - $this->getThisLevelExperience())*100))); |
| 342 | 356 | } |
| 343 | 357 | |
@@ -347,8 +361,10 @@ discard block |
||
| 347 | 361 | |
| 348 | 362 | public function getNextLevelExperience() { |
| 349 | 363 | $LEVELS_REQUIREMENTS = Globals::getLevelRequirements(); |
| 350 | - if(!isset($LEVELS_REQUIREMENTS[$this->getLevelID()+1])) |
|
| 351 | - return $this->getThisLevelExperience(); //Return current level experience if on last level. |
|
| 364 | + if(!isset($LEVELS_REQUIREMENTS[$this->getLevelID()+1])) { |
|
| 365 | + return $this->getThisLevelExperience(); |
|
| 366 | + } |
|
| 367 | + //Return current level experience if on last level. |
|
| 352 | 368 | return $LEVELS_REQUIREMENTS[$this->getLevelID()+1]['Requirement']; |
| 353 | 369 | } |
| 354 | 370 | |
@@ -358,12 +374,15 @@ discard block |
||
| 358 | 374 | } |
| 359 | 375 | |
| 360 | 376 | public function setExperience($experience) { |
| 361 | - if($this->experience == $experience) |
|
| 362 | - return; |
|
| 363 | - if($experience<MIN_EXPERIENCE) |
|
| 364 | - $experience = MIN_EXPERIENCE; |
|
| 365 | - if($experience>MAX_EXPERIENCE) |
|
| 366 | - $experience = MAX_EXPERIENCE; |
|
| 377 | + if($this->experience == $experience) { |
|
| 378 | + return; |
|
| 379 | + } |
|
| 380 | + if($experience<MIN_EXPERIENCE) { |
|
| 381 | + $experience = MIN_EXPERIENCE; |
|
| 382 | + } |
|
| 383 | + if($experience>MAX_EXPERIENCE) { |
|
| 384 | + $experience = MAX_EXPERIENCE; |
|
| 385 | + } |
|
| 367 | 386 | $this->experience = $experience; |
| 368 | 387 | $this->hasChanged=true; |
| 369 | 388 | |
@@ -373,46 +392,57 @@ discard block |
||
| 373 | 392 | } |
| 374 | 393 | |
| 375 | 394 | public function increaseCredits($credits) { |
| 376 | - if($credits < 0) |
|
| 377 | - throw new Exception('Trying to increase negative credits.'); |
|
| 378 | - if($credits == 0) |
|
| 379 | - return; |
|
| 395 | + if($credits < 0) { |
|
| 396 | + throw new Exception('Trying to increase negative credits.'); |
|
| 397 | + } |
|
| 398 | + if($credits == 0) { |
|
| 399 | + return; |
|
| 400 | + } |
|
| 380 | 401 | $credits += $this->credits; |
| 381 | 402 | $this->setCredits($credits); |
| 382 | 403 | } |
| 383 | 404 | public function decreaseCredits($credits) { |
| 384 | - if($credits < 0) |
|
| 385 | - throw new Exception('Trying to decrease negative credits.'); |
|
| 386 | - if($credits == 0) |
|
| 387 | - return; |
|
| 405 | + if($credits < 0) { |
|
| 406 | + throw new Exception('Trying to decrease negative credits.'); |
|
| 407 | + } |
|
| 408 | + if($credits == 0) { |
|
| 409 | + return; |
|
| 410 | + } |
|
| 388 | 411 | $credits = $this->credits - $credits; |
| 389 | 412 | $this->setCredits($credits); |
| 390 | 413 | } |
| 391 | 414 | public function setCredits($credits) { |
| 392 | - if($this->credits == $credits) |
|
| 393 | - return; |
|
| 394 | - if($credits < 0) |
|
| 395 | - throw new Exception('Trying to set negative credits.'); |
|
| 396 | - if($credits > MAX_MONEY) |
|
| 397 | - $credits = MAX_MONEY; |
|
| 415 | + if($this->credits == $credits) { |
|
| 416 | + return; |
|
| 417 | + } |
|
| 418 | + if($credits < 0) { |
|
| 419 | + throw new Exception('Trying to set negative credits.'); |
|
| 420 | + } |
|
| 421 | + if($credits > MAX_MONEY) { |
|
| 422 | + $credits = MAX_MONEY; |
|
| 423 | + } |
|
| 398 | 424 | $this->credits = $credits; |
| 399 | 425 | $this->hasChanged=true; |
| 400 | 426 | } |
| 401 | 427 | |
| 402 | 428 | public function increaseExperience($experience) { |
| 403 | - if($experience < 0) |
|
| 404 | - throw new Exception('Trying to increase negative experience.'); |
|
| 405 | - if($experience == 0) |
|
| 406 | - return; |
|
| 429 | + if($experience < 0) { |
|
| 430 | + throw new Exception('Trying to increase negative experience.'); |
|
| 431 | + } |
|
| 432 | + if($experience == 0) { |
|
| 433 | + return; |
|
| 434 | + } |
|
| 407 | 435 | $newExperience = $this->experience + $experience; |
| 408 | 436 | $this->setExperience($newExperience); |
| 409 | 437 | $this->increaseHOF($experience,array('Experience','Total','Gain'), HOF_PUBLIC); |
| 410 | 438 | } |
| 411 | 439 | public function decreaseExperience($experience) { |
| 412 | - if($experience < 0) |
|
| 413 | - throw new Exception('Trying to decrease negative experience.'); |
|
| 414 | - if($experience == 0) |
|
| 415 | - return; |
|
| 440 | + if($experience < 0) { |
|
| 441 | + throw new Exception('Trying to decrease negative experience.'); |
|
| 442 | + } |
|
| 443 | + if($experience == 0) { |
|
| 444 | + return; |
|
| 445 | + } |
|
| 416 | 446 | $newExperience = $this->experience - $experience; |
| 417 | 447 | $this->setExperience($newExperience); |
| 418 | 448 | $this->decreaseHOF($experience,array('Experience','Total','Loss'), HOF_PUBLIC); |
@@ -423,8 +453,9 @@ discard block |
||
| 423 | 453 | } |
| 424 | 454 | |
| 425 | 455 | public function setLandedOnPlanet($bool) { |
| 426 | - if($this->landedOnPlanet == $bool) |
|
| 427 | - return; |
|
| 456 | + if($this->landedOnPlanet == $bool) { |
|
| 457 | + return; |
|
| 458 | + } |
|
| 428 | 459 | $this->landedOnPlanet=$bool; |
| 429 | 460 | $this->hasChanged=true; |
| 430 | 461 | } |
@@ -438,7 +469,9 @@ discard block |
||
| 438 | 469 | if ($this->level === null) { |
| 439 | 470 | $LEVELS_REQUIREMENTS = Globals::getLevelRequirements(); |
| 440 | 471 | foreach ($LEVELS_REQUIREMENTS as $level_id => $require) { |
| 441 | - if ($this->getExperience() >= $require['Requirement']) continue; |
|
| 472 | + if ($this->getExperience() >= $require['Requirement']) { |
|
| 473 | + continue; |
|
| 474 | + } |
|
| 442 | 475 | $this->level = $level_id - 1; |
| 443 | 476 | return $this->level; |
| 444 | 477 | } |
@@ -516,8 +549,9 @@ discard block |
||
| 516 | 549 | } |
| 517 | 550 | |
| 518 | 551 | public function setRaceID($raceID) { |
| 519 | - if($this->raceID == $raceID) |
|
| 520 | - return; |
|
| 552 | + if($this->raceID == $raceID) { |
|
| 553 | + return; |
|
| 554 | + } |
|
| 521 | 555 | $this->raceID=$raceID; |
| 522 | 556 | $this->hasChanged=true; |
| 523 | 557 | } |
@@ -539,8 +573,9 @@ discard block |
||
| 539 | 573 | } |
| 540 | 574 | |
| 541 | 575 | public function setAllianceID($ID) { |
| 542 | - if($this->allianceID == $ID) |
|
| 543 | - return; |
|
| 576 | + if($this->allianceID == $ID) { |
|
| 577 | + return; |
|
| 578 | + } |
|
| 544 | 579 | $this->allianceID=$ID; |
| 545 | 580 | if ($this->allianceID != 0) { |
| 546 | 581 | $status = $this->hasNewbieStatus() ? 'NEWBIE' : 'VETERAN'; |
@@ -557,8 +592,7 @@ discard block |
||
| 557 | 592 | public function getAllianceName($linked=false, $includeAllianceID=false) { |
| 558 | 593 | if($this->hasAlliance()) { |
| 559 | 594 | return $this->getAlliance()->getAllianceName($linked, $includeAllianceID); |
| 560 | - } |
|
| 561 | - else { |
|
| 595 | + } else { |
|
| 562 | 596 | return 'No Alliance'; |
| 563 | 597 | } |
| 564 | 598 | } |
@@ -586,8 +620,9 @@ discard block |
||
| 586 | 620 | } |
| 587 | 621 | |
| 588 | 622 | public function setCombatDronesKamikazeOnMines($bool) { |
| 589 | - if($this->combatDronesKamikazeOnMines == $bool) |
|
| 590 | - return; |
|
| 623 | + if($this->combatDronesKamikazeOnMines == $bool) { |
|
| 624 | + return; |
|
| 625 | + } |
|
| 591 | 626 | $this->combatDronesKamikazeOnMines = $bool; |
| 592 | 627 | $this->hasChanged=true; |
| 593 | 628 | } |
@@ -604,15 +639,17 @@ discard block |
||
| 604 | 639 | $gadgetID = $GADGETS[$gadgetID]['ID']; |
| 605 | 640 | } |
| 606 | 641 | $gadgets = $this->getGadgets(); |
| 607 | - if(isset($gadgets[$gadgetID])) |
|
| 608 | - return $gadgets[$gadgetID]; |
|
| 642 | + if(isset($gadgets[$gadgetID])) { |
|
| 643 | + return $gadgets[$gadgetID]; |
|
| 644 | + } |
|
| 609 | 645 | return false; |
| 610 | 646 | } |
| 611 | 647 | |
| 612 | 648 | public function isGadgetEquipped($gadgetID) { |
| 613 | 649 | $gadget = $this->getGadget($gadgetID); |
| 614 | - if($gadget===false) |
|
| 615 | - return false; |
|
| 650 | + if($gadget===false) { |
|
| 651 | + return false; |
|
| 652 | + } |
|
| 616 | 653 | return $gadget['Equipped'] > 0 && $gadget['Equipped'] < TIME && ($gadget['Expires'] == 0 || $gadget['Expires'] > TIME) && $gadget['Cooldown'] <= TIME; |
| 617 | 654 | } |
| 618 | 655 | |
@@ -684,21 +721,24 @@ discard block |
||
| 684 | 721 | } |
| 685 | 722 | |
| 686 | 723 | public function setMilitaryPayment($amount) { |
| 687 | - if($this->militaryPayment == $amount) |
|
| 688 | - return; |
|
| 724 | + if($this->militaryPayment == $amount) { |
|
| 725 | + return; |
|
| 726 | + } |
|
| 689 | 727 | $this->militaryPayment = $amount; |
| 690 | 728 | $this->hasChanged=true; |
| 691 | 729 | } |
| 692 | 730 | |
| 693 | 731 | public function increaseMilitaryPayment($amount) { |
| 694 | - if($amount < 0) |
|
| 695 | - throw new Exception('Trying to increase negative military payment.'); |
|
| 732 | + if($amount < 0) { |
|
| 733 | + throw new Exception('Trying to increase negative military payment.'); |
|
| 734 | + } |
|
| 696 | 735 | $this->setMilitaryPayment($this->getMilitaryPayment()+$amount); |
| 697 | 736 | } |
| 698 | 737 | |
| 699 | 738 | public function decreaseMilitaryPayment($amount) { |
| 700 | - if($amount < 0) |
|
| 701 | - throw new Exception('Trying to decrease negative military payment.'); |
|
| 739 | + if($amount < 0) { |
|
| 740 | + throw new Exception('Trying to decrease negative military payment.'); |
|
| 741 | + } |
|
| 702 | 742 | $this->setMilitaryPayment($this->getMilitaryPayment()-$amount); |
| 703 | 743 | } |
| 704 | 744 | |
@@ -740,10 +780,11 @@ discard block |
||
| 740 | 780 | |
| 741 | 781 | public function getNextBountyID() { |
| 742 | 782 | $keys = array_keys($this->getBounties()); |
| 743 | - if(count($keys)>0) |
|
| 744 | - return max($keys)+1; |
|
| 745 | - else |
|
| 746 | - return 0; |
|
| 783 | + if(count($keys)>0) { |
|
| 784 | + return max($keys)+1; |
|
| 785 | + } else { |
|
| 786 | + return 0; |
|
| 787 | + } |
|
| 747 | 788 | } |
| 748 | 789 | |
| 749 | 790 | public function setBounty(array $bounty) { |
@@ -758,22 +799,25 @@ discard block |
||
| 758 | 799 | } |
| 759 | 800 | |
| 760 | 801 | public function increaseBountyAmount($bountyID,$amount) { |
| 761 | - if($amount < 0) |
|
| 762 | - throw new Exception('Trying to increase negative bounty.'); |
|
| 802 | + if($amount < 0) { |
|
| 803 | + throw new Exception('Trying to increase negative bounty.'); |
|
| 804 | + } |
|
| 763 | 805 | $this->setBountyAmount($this->getBountyAmount($bountyID)+$amount); |
| 764 | 806 | } |
| 765 | 807 | |
| 766 | 808 | public function decreaseBountyAmount($bountyID,$amount) { |
| 767 | - if($amount < 0) |
|
| 768 | - throw new Exception('Trying to decrease negative bounty.'); |
|
| 809 | + if($amount < 0) { |
|
| 810 | + throw new Exception('Trying to decrease negative bounty.'); |
|
| 811 | + } |
|
| 769 | 812 | $this->setBountyAmount($this->getBountyAmount($bountyID)+$amount); |
| 770 | 813 | } |
| 771 | 814 | |
| 772 | 815 | public function getCurrentBounty($type) { |
| 773 | 816 | $bounties = $this->getBounties(); |
| 774 | 817 | foreach($bounties as $bounty) { |
| 775 | - if($bounty['Claimer'] == 0 && $bounty['Type']==$type) |
|
| 776 | - return $bounty; |
|
| 818 | + if($bounty['Claimer'] == 0 && $bounty['Type']==$type) { |
|
| 819 | + return $bounty; |
|
| 820 | + } |
|
| 777 | 821 | } |
| 778 | 822 | return $this->createBounty($type); |
| 779 | 823 | } |
@@ -781,8 +825,9 @@ discard block |
||
| 781 | 825 | public function hasCurrentBounty($type) { |
| 782 | 826 | $bounties = $this->getBounties(); |
| 783 | 827 | foreach($bounties as $bounty) { |
| 784 | - if($bounty['Claimer'] == 0 && $bounty['Type']==$type) |
|
| 785 | - return true; |
|
| 828 | + if($bounty['Claimer'] == 0 && $bounty['Type']==$type) { |
|
| 829 | + return true; |
|
| 830 | + } |
|
| 786 | 831 | } |
| 787 | 832 | return false; |
| 788 | 833 | } |
@@ -794,21 +839,24 @@ discard block |
||
| 794 | 839 | |
| 795 | 840 | public function setCurrentBountyAmount($type, $amount) { |
| 796 | 841 | $bounty = $this->getCurrentBounty($type); |
| 797 | - if($bounty['Amount'] == $amount) |
|
| 798 | - return; |
|
| 842 | + if($bounty['Amount'] == $amount) { |
|
| 843 | + return; |
|
| 844 | + } |
|
| 799 | 845 | $bounty['Amount'] = $amount; |
| 800 | 846 | $this->setBounty($bounty); |
| 801 | 847 | } |
| 802 | 848 | |
| 803 | 849 | public function increaseCurrentBountyAmount($type,$amount) { |
| 804 | - if($amount < 0) |
|
| 805 | - throw new Exception('Trying to increase negative current bounty.'); |
|
| 850 | + if($amount < 0) { |
|
| 851 | + throw new Exception('Trying to increase negative current bounty.'); |
|
| 852 | + } |
|
| 806 | 853 | $this->setCurrentBountyAmount($type,$this->getCurrentBountyAmount($type)+$amount); |
| 807 | 854 | } |
| 808 | 855 | |
| 809 | 856 | public function decreaseCurrentBountyAmount($type,$amount) { |
| 810 | - if($amount < 0) |
|
| 811 | - throw new Exception('Trying to decrease negative current bounty.'); |
|
| 857 | + if($amount < 0) { |
|
| 858 | + throw new Exception('Trying to decrease negative current bounty.'); |
|
| 859 | + } |
|
| 812 | 860 | $this->setCurrentBountyAmount($type,$this->getCurrentBountyAmount($type)-$amount); |
| 813 | 861 | } |
| 814 | 862 | |
@@ -819,21 +867,24 @@ discard block |
||
| 819 | 867 | |
| 820 | 868 | public function setCurrentBountySmrCredits($type, $credits) { |
| 821 | 869 | $bounty = $this->getCurrentBounty($type); |
| 822 | - if($bounty['SmrCredits'] == $credits) |
|
| 823 | - return; |
|
| 870 | + if($bounty['SmrCredits'] == $credits) { |
|
| 871 | + return; |
|
| 872 | + } |
|
| 824 | 873 | $bounty['SmrCredits'] = $credits; |
| 825 | 874 | $this->setBounty($bounty); |
| 826 | 875 | } |
| 827 | 876 | |
| 828 | 877 | public function increaseCurrentBountySmrCredits($type,$credits) { |
| 829 | - if($credits<0) |
|
| 830 | - throw new Exception('Trying to increase negative current bounty.'); |
|
| 878 | + if($credits<0) { |
|
| 879 | + throw new Exception('Trying to increase negative current bounty.'); |
|
| 880 | + } |
|
| 831 | 881 | $this->setCurrentBountySmrCredits($type,$this->getCurrentBountySmrCredits($type)+$credits); |
| 832 | 882 | } |
| 833 | 883 | |
| 834 | 884 | public function decreaseCurrentBountySmrCredits($type,$credits) { |
| 835 | - if($credits<0) |
|
| 836 | - throw new Exception('Trying to decrease negative current bounty.'); |
|
| 885 | + if($credits<0) { |
|
| 886 | + throw new Exception('Trying to decrease negative current bounty.'); |
|
| 887 | + } |
|
| 837 | 888 | $this->setCurrentBountySmrCredits($type,$this->getCurrentBountySmrCredits($type)-$credits); |
| 838 | 889 | } |
| 839 | 890 | |
@@ -854,51 +905,59 @@ discard block |
||
| 854 | 905 | |
| 855 | 906 | public function getHOF(array $typeList = null) { |
| 856 | 907 | $this->getHOFData(); |
| 857 | - if($typeList==null) |
|
| 858 | - return $this->HOF; |
|
| 908 | + if($typeList==null) { |
|
| 909 | + return $this->HOF; |
|
| 910 | + } |
|
| 859 | 911 | $hof=$this->HOF; |
| 860 | 912 | foreach($typeList as $type) { |
| 861 | - if(!isset($hof[$type])) |
|
| 862 | - return 0; |
|
| 913 | + if(!isset($hof[$type])) { |
|
| 914 | + return 0; |
|
| 915 | + } |
|
| 863 | 916 | $hof = $hof[$type]; |
| 864 | 917 | } |
| 865 | 918 | return $hof; |
| 866 | 919 | } |
| 867 | 920 | |
| 868 | 921 | public function increaseHOF($amount,array $typeList, $visibility) { |
| 869 | - if($amount < 0) |
|
| 870 | - throw new Exception('Trying to increase negative HOF: '.implode(':',$typeList)); |
|
| 871 | - if($amount == 0) |
|
| 872 | - return; |
|
| 922 | + if($amount < 0) { |
|
| 923 | + throw new Exception('Trying to increase negative HOF: '.implode(':',$typeList)); |
|
| 924 | + } |
|
| 925 | + if($amount == 0) { |
|
| 926 | + return; |
|
| 927 | + } |
|
| 873 | 928 | $this->setHOF($this->getHOF($typeList)+$amount,$typeList, $visibility); |
| 874 | 929 | } |
| 875 | 930 | |
| 876 | 931 | public function decreaseHOF($amount,array $typeList, $visibility) { |
| 877 | - if($amount < 0) |
|
| 878 | - throw new Exception('Trying to decrease negative HOF: '.implode(':',$typeList)); |
|
| 879 | - if($amount == 0) |
|
| 880 | - return; |
|
| 932 | + if($amount < 0) { |
|
| 933 | + throw new Exception('Trying to decrease negative HOF: '.implode(':',$typeList)); |
|
| 934 | + } |
|
| 935 | + if($amount == 0) { |
|
| 936 | + return; |
|
| 937 | + } |
|
| 881 | 938 | $this->setHOF($this->getHOF($typeList)-$amount,$typeList, $visibility); |
| 882 | 939 | } |
| 883 | 940 | |
| 884 | 941 | public function setHOF($amount,array $typeList, $visibility) { |
| 885 | - if(is_array($this->getHOF($typeList))) |
|
| 886 | - throw new Exception('Trying to overwrite a HOF type: '.implode(':',$typeList)); |
|
| 942 | + if(is_array($this->getHOF($typeList))) { |
|
| 943 | + throw new Exception('Trying to overwrite a HOF type: '.implode(':',$typeList)); |
|
| 944 | + } |
|
| 887 | 945 | if($this->isNPC()) { |
| 888 | 946 | // Don't store HOF for NPCs. |
| 889 | 947 | return; |
| 890 | 948 | } |
| 891 | - if($this->getHOF($typeList)==$amount) |
|
| 892 | - return; |
|
| 893 | - if($amount < 0) |
|
| 894 | - $amount=0; |
|
| 949 | + if($this->getHOF($typeList)==$amount) { |
|
| 950 | + return; |
|
| 951 | + } |
|
| 952 | + if($amount < 0) { |
|
| 953 | + $amount=0; |
|
| 954 | + } |
|
| 895 | 955 | $this->getHOF(); |
| 896 | 956 | |
| 897 | 957 | $hofType = implode(':',$typeList); |
| 898 | 958 | if(!isset(self::$HOFVis[$hofType])) { |
| 899 | 959 | self::$hasHOFVisChanged[$hofType] = self::HOF_NEW; |
| 900 | - } |
|
| 901 | - else if(self::$HOFVis[$hofType] != $visibility) { |
|
| 960 | + } else if(self::$HOFVis[$hofType] != $visibility) { |
|
| 902 | 961 | self::$hasHOFVisChanged[$hofType] = self::HOF_CHANGED; |
| 903 | 962 | } |
| 904 | 963 | self::$HOFVis[$hofType] = $visibility; |
@@ -907,8 +966,9 @@ discard block |
||
| 907 | 966 | $hofChanged =& $this->hasHOFChanged; |
| 908 | 967 | $new = false; |
| 909 | 968 | foreach($typeList as $type) { |
| 910 | - if(!isset($hofChanged[$type])) |
|
| 911 | - $hofChanged[$type] = array(); |
|
| 969 | + if(!isset($hofChanged[$type])) { |
|
| 970 | + $hofChanged[$type] = array(); |
|
| 971 | + } |
|
| 912 | 972 | if(!isset($hof[$type])) { |
| 913 | 973 | $hof[$type] = array(); |
| 914 | 974 | $new = true; |
@@ -918,8 +978,9 @@ discard block |
||
| 918 | 978 | } |
| 919 | 979 | if($hofChanged==null) { |
| 920 | 980 | $hofChanged = self::HOF_CHANGED; |
| 921 | - if($new) |
|
| 922 | - $hofChanged = self::HOF_NEW; |
|
| 981 | + if($new) { |
|
| 982 | + $hofChanged = self::HOF_NEW; |
|
| 983 | + } |
|
| 923 | 984 | } |
| 924 | 985 | $hof = $amount; |
| 925 | 986 | } |
@@ -945,16 +1006,19 @@ discard block |
||
| 945 | 1006 | } |
| 946 | 1007 | |
| 947 | 1008 | public function setTurns($turns,$newNoob = false,$updateLastActive = false) { |
| 948 | - if($this->turns == $turns && ($this->newbieTurns == $newNoob || $newNoob==false) && !$updateLastActive) |
|
| 949 | - return; |
|
| 1009 | + if($this->turns == $turns && ($this->newbieTurns == $newNoob || $newNoob==false) && !$updateLastActive) { |
|
| 1010 | + return; |
|
| 1011 | + } |
|
| 950 | 1012 | |
| 951 | 1013 | // Make sure turns are in range [0, MaxTurns] |
| 952 | 1014 | $this->turns = max(0, min($turns, $this->getMaxTurns())); |
| 953 | 1015 | |
| 954 | - if($newNoob !== false) |
|
| 955 | - $this->newbieTurns = $newNoob; |
|
| 956 | - if ($this->newbieTurns < 0) |
|
| 957 | - $this->newbieTurns = 0; |
|
| 1016 | + if($newNoob !== false) { |
|
| 1017 | + $this->newbieTurns = $newNoob; |
|
| 1018 | + } |
|
| 1019 | + if ($this->newbieTurns < 0) { |
|
| 1020 | + $this->newbieTurns = 0; |
|
| 1021 | + } |
|
| 958 | 1022 | |
| 959 | 1023 | $this->hasChanged=true; |
| 960 | 1024 | if($updateLastActive === true) { |
@@ -964,8 +1028,9 @@ discard block |
||
| 964 | 1028 | } |
| 965 | 1029 | |
| 966 | 1030 | public function takeTurns($take, $noob = 0, $updateLastActive = true) { |
| 967 | - if($take < 0 || $noob < 0) |
|
| 968 | - throw new Exception('Trying to take negative turns.'); |
|
| 1031 | + if($take < 0 || $noob < 0) { |
|
| 1032 | + throw new Exception('Trying to take negative turns.'); |
|
| 1033 | + } |
|
| 969 | 1034 | $take = ceil($take); |
| 970 | 1035 | $new_turns = $this->getTurns() - $take; |
| 971 | 1036 | $newbiesTaken = min($this->getNewbieTurns(),$noob); |
@@ -978,8 +1043,9 @@ discard block |
||
| 978 | 1043 | } |
| 979 | 1044 | |
| 980 | 1045 | public function giveTurns($give, $noob = 0,$updateLastActive = false) { |
| 981 | - if($give < 0 || $noob < 0) |
|
| 982 | - throw new Exception('Trying to give negative turns.'); |
|
| 1046 | + if($give < 0 || $noob < 0) { |
|
| 1047 | + throw new Exception('Trying to give negative turns.'); |
|
| 1048 | + } |
|
| 983 | 1049 | $give = floor($give); |
| 984 | 1050 | |
| 985 | 1051 | $this->setTurns($this->getTurns() + $give, $this->getNewbieTurns() + $noob, $updateLastActive); |
@@ -990,8 +1056,9 @@ discard block |
||
| 990 | 1056 | } |
| 991 | 1057 | |
| 992 | 1058 | public function setLastActive($lastActive) { |
| 993 | - if($this->lastActive == $lastActive) |
|
| 994 | - return; |
|
| 1059 | + if($this->lastActive == $lastActive) { |
|
| 1060 | + return; |
|
| 1061 | + } |
|
| 995 | 1062 | $this->lastActive=$lastActive; |
| 996 | 1063 | $this->hasChanged=true; |
| 997 | 1064 | } |
@@ -1001,8 +1068,9 @@ discard block |
||
| 1001 | 1068 | } |
| 1002 | 1069 | |
| 1003 | 1070 | public function setLastCPLAction($time) { |
| 1004 | - if($this->lastCPLAction == $time) |
|
| 1005 | - return; |
|
| 1071 | + if($this->lastCPLAction == $time) { |
|
| 1072 | + return; |
|
| 1073 | + } |
|
| 1006 | 1074 | $this->lastCPLAction=$time; |
| 1007 | 1075 | $this->hasChanged=true; |
| 1008 | 1076 | } |
@@ -1017,8 +1085,9 @@ discard block |
||
| 1017 | 1085 | //Get Player missions |
| 1018 | 1086 | $this->db->query('SELECT mission_id FROM player_completed_mission WHERE ' . $this->SQL); |
| 1019 | 1087 | $this->completedMissions = array(); |
| 1020 | - while ($this->db->nextRecord()) |
|
| 1021 | - $this->completedMissions[$this->db->getField('mission_id')] = $this->db->getField('mission_id'); |
|
| 1088 | + while ($this->db->nextRecord()) { |
|
| 1089 | + $this->completedMissions[$this->db->getField('mission_id')] = $this->db->getField('mission_id'); |
|
| 1090 | + } |
|
| 1022 | 1091 | } |
| 1023 | 1092 | return $this->completedMissions; |
| 1024 | 1093 | } |
@@ -1055,8 +1124,9 @@ discard block |
||
| 1055 | 1124 | |
| 1056 | 1125 | function getMission($missionID) { |
| 1057 | 1126 | $missions = $this->getMissions(); |
| 1058 | - if(isset($missions[$missionID])) |
|
| 1059 | - return $missions[$missionID]; |
|
| 1127 | + if(isset($missions[$missionID])) { |
|
| 1128 | + return $missions[$missionID]; |
|
| 1129 | + } |
|
| 1060 | 1130 | return false; |
| 1061 | 1131 | } |
| 1062 | 1132 | |
@@ -1102,8 +1172,9 @@ discard block |
||
| 1102 | 1172 | function addMission($missionID) { |
| 1103 | 1173 | $this->getMissions(); |
| 1104 | 1174 | |
| 1105 | - if(isset($this->missions[$missionID])) |
|
| 1106 | - return; |
|
| 1175 | + if(isset($this->missions[$missionID])) { |
|
| 1176 | + return; |
|
| 1177 | + } |
|
| 1107 | 1178 | $sector = 0; |
| 1108 | 1179 | |
| 1109 | 1180 | $mission = array( |
@@ -1132,8 +1203,7 @@ discard block |
||
| 1132 | 1203 | if ($mission['On Step'] >= count(MISSIONS[$missionID]['Steps'])) { |
| 1133 | 1204 | // If we have completed this mission just use false to indicate no current task. |
| 1134 | 1205 | $currentStep = false; |
| 1135 | - } |
|
| 1136 | - else { |
|
| 1206 | + } else { |
|
| 1137 | 1207 | $currentStep = MISSIONS[$missionID]['Steps'][$mission['On Step']]; |
| 1138 | 1208 | $currentStep['Text'] = str_replace(array('<Race>','<Sector>','<Starting Sector>','<trader>'),array($this->getRaceID(),$mission['Sector'],$mission['Starting Sector'],$this->playerName),$currentStep['Text']); |
| 1139 | 1209 | if (isset($currentStep['Task'])) { |
@@ -1141,8 +1211,7 @@ discard block |
||
| 1141 | 1211 | } |
| 1142 | 1212 | if (isset($currentStep['Level'])) { |
| 1143 | 1213 | $currentStep['Level'] = str_replace('<Player Level>', $this->getLevelID(), $currentStep['Level']); |
| 1144 | - } |
|
| 1145 | - else { |
|
| 1214 | + } else { |
|
| 1146 | 1215 | $currentStep['Level'] = 0; |
| 1147 | 1216 | } |
| 1148 | 1217 | } |
@@ -1270,12 +1339,15 @@ discard block |
||
| 1270 | 1339 | } |
| 1271 | 1340 | |
| 1272 | 1341 | public function canSee(AbstractSmrPlayer $otherPlayer) { |
| 1273 | - if(!$otherPlayer->getShip()->isCloaked()) |
|
| 1274 | - return true; |
|
| 1275 | - if($this->sameAlliance($otherPlayer)) |
|
| 1276 | - return true; |
|
| 1277 | - if($this->getExperience()>=$otherPlayer->getExperience()) |
|
| 1278 | - return true; |
|
| 1342 | + if(!$otherPlayer->getShip()->isCloaked()) { |
|
| 1343 | + return true; |
|
| 1344 | + } |
|
| 1345 | + if($this->sameAlliance($otherPlayer)) { |
|
| 1346 | + return true; |
|
| 1347 | + } |
|
| 1348 | + if($this->getExperience()>=$otherPlayer->getExperience()) { |
|
| 1349 | + return true; |
|
| 1350 | + } |
|
| 1279 | 1351 | return false; |
| 1280 | 1352 | } |
| 1281 | 1353 | |
@@ -1328,10 +1400,12 @@ discard block |
||
| 1328 | 1400 | } |
| 1329 | 1401 | |
| 1330 | 1402 | public function meetsAlignmentRestriction($restriction) { |
| 1331 | - if($restriction<0) |
|
| 1332 | - return $this->getAlignment()<=$restriction; |
|
| 1333 | - if($restriction>0) |
|
| 1334 | - return $this->getAlignment()>=$restriction; |
|
| 1403 | + if($restriction<0) { |
|
| 1404 | + return $this->getAlignment()<=$restriction; |
|
| 1405 | + } |
|
| 1406 | + if($restriction>0) { |
|
| 1407 | + return $this->getAlignment()>=$restriction; |
|
| 1408 | + } |
|
| 1335 | 1409 | return true; |
| 1336 | 1410 | } |
| 1337 | 1411 | |
@@ -1354,8 +1428,9 @@ discard block |
||
| 1354 | 1428 | if(!isset($this->visitedSectors)) { |
| 1355 | 1429 | $this->visitedSectors = array(); |
| 1356 | 1430 | $this->db->query('SELECT sector_id FROM player_visited_sector WHERE ' . $this->SQL); |
| 1357 | - while($this->db->nextRecord()) |
|
| 1358 | - $this->visitedSectors[$this->db->getField('sector_id')] = false; |
|
| 1431 | + while($this->db->nextRecord()) { |
|
| 1432 | + $this->visitedSectors[$this->db->getField('sector_id')] = false; |
|
| 1433 | + } |
|
| 1359 | 1434 | } |
| 1360 | 1435 | return !isset($this->visitedSectors[$sectorID]); |
| 1361 | 1436 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | protected $typeInfo; |
| 37 | 37 | |
| 38 | 38 | protected $hasChanged = false; |
| 39 | - protected $hasChangedFinancial = false; // for credits, bond, maturity |
|
| 39 | + protected $hasChangedFinancial = false; // for credits, bond, maturity |
|
| 40 | 40 | protected $hasChangedStockpile = false; |
| 41 | 41 | protected $hasChangedWeapons = array(); |
| 42 | 42 | protected $hasChangedBuildings = array(); |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | protected $delayedArmourDelta = 0; |
| 49 | 49 | |
| 50 | 50 | public static function refreshCache() { |
| 51 | - foreach(self::$CACHE_PLANETS as $gameID => &$gamePlanets) { |
|
| 52 | - foreach($gamePlanets as $sectorID => &$planet) { |
|
| 53 | - $planet = self::getPlanet($gameID,$sectorID,true); |
|
| 51 | + foreach (self::$CACHE_PLANETS as $gameID => &$gamePlanets) { |
|
| 52 | + foreach ($gamePlanets as $sectorID => &$planet) { |
|
| 53 | + $planet = self::getPlanet($gameID, $sectorID, true); |
|
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | } |
@@ -60,22 +60,22 @@ discard block |
||
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | public static function savePlanets() { |
| 63 | - foreach(self::$CACHE_PLANETS as $gamePlanets) { |
|
| 64 | - foreach($gamePlanets as $planet) { |
|
| 63 | + foreach (self::$CACHE_PLANETS as $gamePlanets) { |
|
| 64 | + foreach ($gamePlanets as $planet) { |
|
| 65 | 65 | $planet->update(); |
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public static function &getPlanet($gameID, $sectorID, $forceUpdate=false, $db=null) { |
|
| 71 | - if($forceUpdate || !isset(self::$CACHE_PLANETS[$gameID][$sectorID])) { |
|
| 70 | + public static function &getPlanet($gameID, $sectorID, $forceUpdate = false, $db = null) { |
|
| 71 | + if ($forceUpdate || !isset(self::$CACHE_PLANETS[$gameID][$sectorID])) { |
|
| 72 | 72 | self::$CACHE_PLANETS[$gameID][$sectorID] = new SmrPlanet($gameID, $sectorID, $db); |
| 73 | 73 | } |
| 74 | 74 | return self::$CACHE_PLANETS[$gameID][$sectorID]; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public static function &createPlanet($gameID,$sectorID,$type=1) { |
|
| 78 | - if(!self::getPlanet($gameID,$sectorID)->exists()) { |
|
| 77 | + public static function &createPlanet($gameID, $sectorID, $type = 1) { |
|
| 78 | + if (!self::getPlanet($gameID, $sectorID)->exists()) { |
|
| 79 | 79 | $minTime = max(SmrGame::getGame($gameID)->getStartDate(), |
| 80 | 80 | SmrGame::getGame($gameID)->getStartTurnsDate()); |
| 81 | 81 | $inhabitableTime = $minTime + pow(mt_rand(45, 85), 3); |
@@ -85,10 +85,10 @@ discard block |
||
| 85 | 85 | $db->query('INSERT INTO planet (game_id, sector_id, inhabitable_time, planet_type_id) |
| 86 | 86 | VALUES (' . $db->escapeNumber($gameID) . ', ' . $db->escapeNumber($sectorID) . ', ' . $db->escapeNumber($inhabitableTime) . ', ' . $db->escapeNumber($type) . ')'); |
| 87 | 87 | } |
| 88 | - return self::getPlanet($gameID,$sectorID,true); |
|
| 88 | + return self::getPlanet($gameID, $sectorID, true); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - public static function removePlanet($gameID,$sectorID) { |
|
| 91 | + public static function removePlanet($gameID, $sectorID) { |
|
| 92 | 92 | $db = new SmrMySqlDatabase(); |
| 93 | 93 | $SQL = 'game_id = ' . $db->escapeNumber($gameID) . ' AND sector_id = ' . $db->escapeNumber($sectorID); |
| 94 | 94 | $db->query('DELETE FROM planet WHERE ' . $SQL); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | unset(self::$CACHE_PLANETS[$gameID][$sectorID]); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - protected function __construct($gameID, $sectorID, $db=null) { |
|
| 105 | + protected function __construct($gameID, $sectorID, $db = null) { |
|
| 106 | 106 | $this->db = new SmrMySqlDatabase(); |
| 107 | 107 | $this->SQL = 'game_id = ' . $this->db->escapeNumber($gameID) . ' AND sector_id = ' . $this->db->escapeNumber($sectorID); |
| 108 | 108 | |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | if ($planetExists) { |
| 118 | - $this->gameID = (int) $gameID; |
|
| 119 | - $this->sectorID = (int) $sectorID; |
|
| 118 | + $this->gameID = (int)$gameID; |
|
| 119 | + $this->sectorID = (int)$sectorID; |
|
| 120 | 120 | $this->planetName = stripslashes($db->getField('planet_name')); |
| 121 | 121 | $this->ownerID = $db->getInt('owner_id'); |
| 122 | 122 | $this->password = $db->getField('password'); |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | // calc the interest for the time |
| 168 | 168 | $interest = $this->getBonds() * $this->getInterestRate(); |
| 169 | 169 | |
| 170 | - if($partial === true && $this->getMaturity() > TIME) { |
|
| 170 | + if ($partial === true && $this->getMaturity() > TIME) { |
|
| 171 | 171 | // Adjust interest based upon how much of the bond duration has passed. |
| 172 | 172 | $interest -= ($interest / $this->getBondTime()) * ($this->getMaturity() - TIME); |
| 173 | 173 | } |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | public function &getGalaxy() { |
| 212 | - return SmrGalaxy::getGalaxyContaining($this->getGameID(),$this->getSectorID()); |
|
| 212 | + return SmrGalaxy::getGalaxyContaining($this->getGameID(), $this->getSectorID()); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | public function getOwnerID() { |
@@ -217,19 +217,19 @@ discard block |
||
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | public function hasOwner() { |
| 220 | - return $this->ownerID!=0; |
|
| 220 | + return $this->ownerID != 0; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | public function setOwnerID($claimerID) { |
| 224 | - if($this->ownerID==$claimerID) { |
|
| 224 | + if ($this->ownerID == $claimerID) { |
|
| 225 | 225 | return; |
| 226 | 226 | } |
| 227 | - $this->ownerID=$claimerID; |
|
| 227 | + $this->ownerID = $claimerID; |
|
| 228 | 228 | $this->hasChanged = true; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | public function &getOwner() { |
| 232 | - return SmrPlayer::getPlayer($this->getOwnerID(),$this->getGameID()); |
|
| 232 | + return SmrPlayer::getPlayer($this->getOwnerID(), $this->getGameID()); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | public function getPassword() { |
@@ -237,10 +237,10 @@ discard block |
||
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | public function setPassword($password) { |
| 240 | - if($this->password==$password) { |
|
| 240 | + if ($this->password == $password) { |
|
| 241 | 241 | return; |
| 242 | 242 | } |
| 243 | - $this->password=$password; |
|
| 243 | + $this->password = $password; |
|
| 244 | 244 | $this->hasChanged = true; |
| 245 | 245 | } |
| 246 | 246 | |
@@ -253,10 +253,10 @@ discard block |
||
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | public function setCredits($num) { |
| 256 | - if($this->credits==$num) { |
|
| 256 | + if ($this->credits == $num) { |
|
| 257 | 257 | return; |
| 258 | 258 | } |
| 259 | - if($num < 0) { |
|
| 259 | + if ($num < 0) { |
|
| 260 | 260 | throw new Exception('You cannot set negative credits.'); |
| 261 | 261 | } |
| 262 | 262 | $this->credits = $num; |
@@ -264,14 +264,14 @@ discard block |
||
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | public function increaseCredits($num) { |
| 267 | - if($num == 0) { |
|
| 267 | + if ($num == 0) { |
|
| 268 | 268 | return; |
| 269 | 269 | } |
| 270 | 270 | $this->setCredits($this->getCredits() + $num); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | public function decreaseCredits($num) { |
| 274 | - if($num == 0) { |
|
| 274 | + if ($num == 0) { |
|
| 275 | 275 | return; |
| 276 | 276 | } |
| 277 | 277 | $this->setCredits($this->getCredits() - $num); |
@@ -282,10 +282,10 @@ discard block |
||
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | public function setMaturity($num) { |
| 285 | - if($this->maturity==$num) { |
|
| 285 | + if ($this->maturity == $num) { |
|
| 286 | 286 | return; |
| 287 | 287 | } |
| 288 | - if($num < 0) { |
|
| 288 | + if ($num < 0) { |
|
| 289 | 289 | throw new Exception('You cannot set negative maturity.'); |
| 290 | 290 | } |
| 291 | 291 | $this->maturity = $num; |
@@ -297,10 +297,10 @@ discard block |
||
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | public function setBonds($num) { |
| 300 | - if($this->bonds==$num) { |
|
| 300 | + if ($this->bonds == $num) { |
|
| 301 | 301 | return; |
| 302 | 302 | } |
| 303 | - if($num < 0) { |
|
| 303 | + if ($num < 0) { |
|
| 304 | 304 | throw new Exception('You cannot set negative bonds.'); |
| 305 | 305 | } |
| 306 | 306 | $this->bonds = $num; |
@@ -308,14 +308,14 @@ discard block |
||
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | public function increaseBonds($num) { |
| 311 | - if($num == 0) { |
|
| 311 | + if ($num == 0) { |
|
| 312 | 312 | return; |
| 313 | 313 | } |
| 314 | 314 | $this->setBonds($this->getBonds() + $num); |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | public function decreaseBonds($num) { |
| 318 | - if($num == 0) { |
|
| 318 | + if ($num == 0) { |
|
| 319 | 319 | return; |
| 320 | 320 | } |
| 321 | 321 | $this->setBonds($this->getBonds() - $num); |
@@ -344,27 +344,27 @@ discard block |
||
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | public function getShields($delayed = false) { |
| 347 | - return $this->shields + ($delayed?$this->delayedShieldsDelta:0); |
|
| 347 | + return $this->shields + ($delayed ? $this->delayedShieldsDelta : 0); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | public function hasShields($delayed = false) { |
| 351 | - return $this->getShields($delayed)>0; |
|
| 351 | + return $this->getShields($delayed) > 0; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | public function setShields($shields) { |
| 355 | 355 | $shields = max(0, min($shields, $this->getMaxShields())); |
| 356 | - if($this->shields == $shields) { |
|
| 356 | + if ($this->shields == $shields) { |
|
| 357 | 357 | return; |
| 358 | 358 | } |
| 359 | - $this->shields=$shields; |
|
| 359 | + $this->shields = $shields; |
|
| 360 | 360 | $this->hasChanged = true; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | public function decreaseShields($number, $delayed = false) { |
| 364 | - if($number == 0) { |
|
| 364 | + if ($number == 0) { |
|
| 365 | 365 | return; |
| 366 | 366 | } |
| 367 | - if($delayed===false) { |
|
| 367 | + if ($delayed === false) { |
|
| 368 | 368 | $this->setShields($this->getShields() - $number); |
| 369 | 369 | } |
| 370 | 370 | else { |
@@ -373,10 +373,10 @@ discard block |
||
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | public function increaseShields($number, $delayed = false) { |
| 376 | - if($number == 0) { |
|
| 376 | + if ($number == 0) { |
|
| 377 | 377 | return; |
| 378 | 378 | } |
| 379 | - if($delayed===false) { |
|
| 379 | + if ($delayed === false) { |
|
| 380 | 380 | $this->setShields($this->getShields() + $number); |
| 381 | 381 | } |
| 382 | 382 | else { |
@@ -389,16 +389,16 @@ discard block |
||
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | public function getArmour($delayed = false) { |
| 392 | - return $this->armour + ($delayed?$this->delayedArmourDelta:0); |
|
| 392 | + return $this->armour + ($delayed ? $this->delayedArmourDelta : 0); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | public function hasArmour($delayed = false) { |
| 396 | - return $this->getArmour($delayed)>0; |
|
| 396 | + return $this->getArmour($delayed) > 0; |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | public function setArmour($armour) { |
| 400 | 400 | $armour = max(0, min($armour, $this->getMaxArmour())); |
| 401 | - if($this->armour == $armour) { |
|
| 401 | + if ($this->armour == $armour) { |
|
| 402 | 402 | return; |
| 403 | 403 | } |
| 404 | 404 | $this->armour = $armour; |
@@ -406,10 +406,10 @@ discard block |
||
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | public function decreaseArmour($number, $delayed = false) { |
| 409 | - if($number == 0) { |
|
| 409 | + if ($number == 0) { |
|
| 410 | 410 | return; |
| 411 | 411 | } |
| 412 | - if($delayed===false) { |
|
| 412 | + if ($delayed === false) { |
|
| 413 | 413 | $this->setArmour($this->getArmour() - $number); |
| 414 | 414 | } |
| 415 | 415 | else { |
@@ -418,10 +418,10 @@ discard block |
||
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | public function increaseArmour($number, $delayed = false) { |
| 421 | - if($number == 0) { |
|
| 421 | + if ($number == 0) { |
|
| 422 | 422 | return; |
| 423 | 423 | } |
| 424 | - if($delayed===false) { |
|
| 424 | + if ($delayed === false) { |
|
| 425 | 425 | $this->setArmour($this->getArmour() + $number); |
| 426 | 426 | } |
| 427 | 427 | else { |
@@ -434,27 +434,27 @@ discard block |
||
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | public function getCDs($delayed = false) { |
| 437 | - return $this->drones + ($delayed?$this->delayedCDsDelta:0); |
|
| 437 | + return $this->drones + ($delayed ? $this->delayedCDsDelta : 0); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | public function hasCDs($delayed = false) { |
| 441 | - return $this->getCDs($delayed)>0; |
|
| 441 | + return $this->getCDs($delayed) > 0; |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | public function setCDs($combatDrones) { |
| 445 | 445 | $combatDrones = max(0, min($combatDrones, $this->getMaxCDs())); |
| 446 | - if($this->drones == $combatDrones) { |
|
| 446 | + if ($this->drones == $combatDrones) { |
|
| 447 | 447 | return; |
| 448 | 448 | } |
| 449 | - $this->drones=$combatDrones; |
|
| 449 | + $this->drones = $combatDrones; |
|
| 450 | 450 | $this->hasChanged = true; |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | public function decreaseCDs($number, $delayed = false) { |
| 454 | - if($number == 0) { |
|
| 454 | + if ($number == 0) { |
|
| 455 | 455 | return; |
| 456 | 456 | } |
| 457 | - if($delayed===false) { |
|
| 457 | + if ($delayed === false) { |
|
| 458 | 458 | $this->setCDs($this->getCDs() - $number); |
| 459 | 459 | } |
| 460 | 460 | else { |
@@ -463,10 +463,10 @@ discard block |
||
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | public function increaseCDs($number, $delayed = false) { |
| 466 | - if($number == 0) { |
|
| 466 | + if ($number == 0) { |
|
| 467 | 467 | return; |
| 468 | 468 | } |
| 469 | - if($delayed===false) { |
|
| 469 | + if ($delayed === false) { |
|
| 470 | 470 | $this->setCDs($this->getCDs() + $number); |
| 471 | 471 | } |
| 472 | 472 | else { |
@@ -514,13 +514,13 @@ discard block |
||
| 514 | 514 | if ($orderID == 0) { |
| 515 | 515 | throw new Exception('Cannot move this weapon up!'); |
| 516 | 516 | } |
| 517 | - if (isset($this->mountedWeapons[$orderID-1])) { |
|
| 518 | - $previousWeapon = $this->mountedWeapons[$orderID-1]; |
|
| 517 | + if (isset($this->mountedWeapons[$orderID - 1])) { |
|
| 518 | + $previousWeapon = $this->mountedWeapons[$orderID - 1]; |
|
| 519 | 519 | } |
| 520 | 520 | if (isset($this->mountedWeapons[$orderID])) { |
| 521 | - $this->mountedWeapons[$orderID-1] = $this->mountedWeapons[$orderID]; |
|
| 521 | + $this->mountedWeapons[$orderID - 1] = $this->mountedWeapons[$orderID]; |
|
| 522 | 522 | } else { |
| 523 | - unset($this->mountedWeapons[$orderID-1]); |
|
| 523 | + unset($this->mountedWeapons[$orderID - 1]); |
|
| 524 | 524 | } |
| 525 | 525 | if (isset($previousWeapon)) { |
| 526 | 526 | $this->mountedWeapons[$orderID] = $previousWeapon; |
@@ -528,21 +528,21 @@ discard block |
||
| 528 | 528 | unset($this->mountedWeapons[$orderID]); |
| 529 | 529 | } |
| 530 | 530 | $this->hasChangedWeapons[$orderID] = true; |
| 531 | - $this->hasChangedWeapons[$orderID-1] = true; |
|
| 531 | + $this->hasChangedWeapons[$orderID - 1] = true; |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | public function moveMountedWeaponDown($orderID) { |
| 535 | 535 | $this->getMountedWeapons(); // Make sure array is initialized |
| 536 | - if ($orderID == $this->getMaxMountedWeapons()-1) { |
|
| 536 | + if ($orderID == $this->getMaxMountedWeapons() - 1) { |
|
| 537 | 537 | throw new Exception('Cannot move this weapon down!'); |
| 538 | 538 | } |
| 539 | - if (isset($this->mountedWeapons[$orderID+1])) { |
|
| 540 | - $nextWeapon = $this->mountedWeapons[$orderID+1]; |
|
| 539 | + if (isset($this->mountedWeapons[$orderID + 1])) { |
|
| 540 | + $nextWeapon = $this->mountedWeapons[$orderID + 1]; |
|
| 541 | 541 | } |
| 542 | 542 | if (isset($this->mountedWeapons[$orderID])) { |
| 543 | - $this->mountedWeapons[$orderID+1] = $this->mountedWeapons[$orderID]; |
|
| 543 | + $this->mountedWeapons[$orderID + 1] = $this->mountedWeapons[$orderID]; |
|
| 544 | 544 | } else { |
| 545 | - unset($this->mountedWeapons[$orderID+1]); |
|
| 545 | + unset($this->mountedWeapons[$orderID + 1]); |
|
| 546 | 546 | } |
| 547 | 547 | if (isset($nextWeapon)) { |
| 548 | 548 | $this->mountedWeapons[$orderID] = $nextWeapon; |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | unset($this->mountedWeapons[$orderID]); |
| 551 | 551 | } |
| 552 | 552 | $this->hasChangedWeapons[$orderID] = true; |
| 553 | - $this->hasChangedWeapons[$orderID+1] = true; |
|
| 553 | + $this->hasChangedWeapons[$orderID + 1] = true; |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | |
@@ -559,11 +559,11 @@ discard block |
||
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | public function exists() { |
| 562 | - return $this->getGameID()!=null && $this->getSectorID()!==null; |
|
| 562 | + return $this->getGameID() != null && $this->getSectorID() !== null; |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | - public function getStockpile($goodID=false) { |
|
| 566 | - if(!isset($this->stockpile)) { |
|
| 565 | + public function getStockpile($goodID = false) { |
|
| 566 | + if (!isset($this->stockpile)) { |
|
| 567 | 567 | // initialize cargo array |
| 568 | 568 | $this->stockpile = array(); |
| 569 | 569 | // get supplies from db |
@@ -572,15 +572,15 @@ discard block |
||
| 572 | 572 | while ($this->db->nextRecord()) |
| 573 | 573 | $this->stockpile[$this->db->getInt('good_id')] = $this->db->getInt('amount'); |
| 574 | 574 | } |
| 575 | - if($goodID===false) |
|
| 575 | + if ($goodID === false) |
|
| 576 | 576 | return $this->stockpile; |
| 577 | - if(isset($this->stockpile[$goodID])) |
|
| 577 | + if (isset($this->stockpile[$goodID])) |
|
| 578 | 578 | return $this->stockpile[$goodID]; |
| 579 | 579 | return 0; |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | - public function hasStockpile($goodID=false) { |
|
| 583 | - if($goodID===false) { |
|
| 582 | + public function hasStockpile($goodID = false) { |
|
| 583 | + if ($goodID === false) { |
|
| 584 | 584 | $stockpile = $this->getStockpile($goodID); |
| 585 | 585 | return count($stockpile) > 0 && max($stockpile) > 0; |
| 586 | 586 | } |
@@ -589,31 +589,31 @@ discard block |
||
| 589 | 589 | } |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | - public function setStockpile($goodID,$amount) { |
|
| 593 | - if($amount < 0) { |
|
| 592 | + public function setStockpile($goodID, $amount) { |
|
| 593 | + if ($amount < 0) { |
|
| 594 | 594 | throw new Exception('Trying to set negative stockpile.'); |
| 595 | 595 | } |
| 596 | - if($this->getStockpile($goodID) == $amount) { |
|
| 596 | + if ($this->getStockpile($goodID) == $amount) { |
|
| 597 | 597 | return; |
| 598 | 598 | } |
| 599 | 599 | $this->stockpile[$goodID] = $amount; |
| 600 | 600 | $this->hasChangedStockpile = true; |
| 601 | 601 | } |
| 602 | 602 | |
| 603 | - public function decreaseStockpile($goodID,$amount) { |
|
| 604 | - if($amount < 0) |
|
| 603 | + public function decreaseStockpile($goodID, $amount) { |
|
| 604 | + if ($amount < 0) |
|
| 605 | 605 | throw new Exception('Trying to decrease negative stockpile.'); |
| 606 | - $this->setStockpile($goodID,$this->getStockpile($goodID) - $amount); |
|
| 606 | + $this->setStockpile($goodID, $this->getStockpile($goodID) - $amount); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | - public function increaseStockpile($goodID,$amount) { |
|
| 610 | - if($amount < 0) |
|
| 609 | + public function increaseStockpile($goodID, $amount) { |
|
| 610 | + if ($amount < 0) |
|
| 611 | 611 | throw new Exception('Trying to increase negative stockpile.'); |
| 612 | - $this->setStockpile($goodID,$this->getStockpile($goodID) + $amount); |
|
| 612 | + $this->setStockpile($goodID, $this->getStockpile($goodID) + $amount); |
|
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | public function getBuildings() { |
| 616 | - if(!isset($this->buildings)) { |
|
| 616 | + if (!isset($this->buildings)) { |
|
| 617 | 617 | $this->buildings = array(); |
| 618 | 618 | |
| 619 | 619 | // get buildingss from db |
@@ -631,41 +631,41 @@ discard block |
||
| 631 | 631 | |
| 632 | 632 | public function getBuilding($buildingTypeID) { |
| 633 | 633 | $buildings = $this->getBuildings(); |
| 634 | - if(isset($buildings[$buildingTypeID])) { |
|
| 634 | + if (isset($buildings[$buildingTypeID])) { |
|
| 635 | 635 | return $buildings[$buildingTypeID]; |
| 636 | 636 | } |
| 637 | 637 | return 0; |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | public function hasBuilding($buildingTypeID) { |
| 641 | - return $this->getBuilding($buildingTypeID)>0; |
|
| 641 | + return $this->getBuilding($buildingTypeID) > 0; |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | - public function setBuilding($buildingTypeID,$number) { |
|
| 645 | - if($this->getBuilding($buildingTypeID) == $number) |
|
| 644 | + public function setBuilding($buildingTypeID, $number) { |
|
| 645 | + if ($this->getBuilding($buildingTypeID) == $number) |
|
| 646 | 646 | return; |
| 647 | 647 | |
| 648 | 648 | $this->buildings[$buildingTypeID] = $number; |
| 649 | 649 | $this->hasChangedBuildings[$buildingTypeID] = true; |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | - public function increaseBuilding($buildingTypeID,$number) { |
|
| 653 | - $this->setBuilding($buildingTypeID,$this->getBuilding($buildingTypeID)+$number); |
|
| 652 | + public function increaseBuilding($buildingTypeID, $number) { |
|
| 653 | + $this->setBuilding($buildingTypeID, $this->getBuilding($buildingTypeID) + $number); |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | - public function destroyBuilding($buildingTypeID,$number) { |
|
| 657 | - if(!$this->hasBuilding($buildingTypeID)) { |
|
| 656 | + public function destroyBuilding($buildingTypeID, $number) { |
|
| 657 | + if (!$this->hasBuilding($buildingTypeID)) { |
|
| 658 | 658 | throw new Exception('Trying to destroy a nonexistent building'); |
| 659 | 659 | } |
| 660 | - $this->setBuilding($buildingTypeID,$this->getBuilding($buildingTypeID)-$number); |
|
| 660 | + $this->setBuilding($buildingTypeID, $this->getBuilding($buildingTypeID) - $number); |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | function getCurrentlyBuilding() { |
| 664 | - if(!isset($this->currentlyBuilding)) { |
|
| 664 | + if (!isset($this->currentlyBuilding)) { |
|
| 665 | 665 | $this->currentlyBuilding = array(); |
| 666 | 666 | |
| 667 | 667 | $this->db->query('SELECT * FROM planet_is_building WHERE ' . $this->SQL); |
| 668 | - while($this->db->nextRecord()) { |
|
| 668 | + while ($this->db->nextRecord()) { |
|
| 669 | 669 | $this->currentlyBuilding[$this->db->getInt('building_slot_id')] = array( |
| 670 | 670 | 'BuildingSlotID' => $this->db->getInt('building_slot_id'), |
| 671 | 671 | 'ConstructionID' => $this->db->getInt('construction_id'), |
@@ -681,9 +681,9 @@ discard block |
||
| 681 | 681 | unset($this->currentlyBuilding[$id]); |
| 682 | 682 | $expGain = $this->getConstructionExp($building['ConstructionID']); |
| 683 | 683 | $player = SmrPlayer::getPlayer($building['ConstructorID'], $this->getGameID()); |
| 684 | - $player->increaseHOF(1, array('Planet','Buildings','Built'), HOF_ALLIANCE); |
|
| 684 | + $player->increaseHOF(1, array('Planet', 'Buildings', 'Built'), HOF_ALLIANCE); |
|
| 685 | 685 | $player->increaseExperience($expGain); |
| 686 | - $player->increaseHOF($expGain, array('Planet','Buildings','Experience'), HOF_ALLIANCE); |
|
| 686 | + $player->increaseHOF($expGain, array('Planet', 'Buildings', 'Experience'), HOF_ALLIANCE); |
|
| 687 | 687 | $this->hasStoppedBuilding[] = $building['BuildingSlotID']; |
| 688 | 688 | $this->increaseBuilding($building['ConstructionID'], 1); |
| 689 | 689 | |
@@ -700,8 +700,8 @@ discard block |
||
| 700 | 700 | return $this->currentlyBuilding; |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | - public function getMaxBuildings($buildingTypeID=false) { |
|
| 704 | - if($buildingTypeID===false) { |
|
| 703 | + public function getMaxBuildings($buildingTypeID = false) { |
|
| 704 | + if ($buildingTypeID === false) { |
|
| 705 | 705 | $structs = $this->typeInfo::STRUCTURES; |
| 706 | 706 | return array_combine(array_keys($structs), |
| 707 | 707 | array_column($structs, 'max_amount')); |
@@ -718,13 +718,13 @@ discard block |
||
| 718 | 718 | return; |
| 719 | 719 | } |
| 720 | 720 | $this->typeID = $num; |
| 721 | - $this->db->query('UPDATE planet SET planet_type_id = '.$this->db->escapeNumber($num).' WHERE '.$this->SQL); |
|
| 721 | + $this->db->query('UPDATE planet SET planet_type_id = ' . $this->db->escapeNumber($num) . ' WHERE ' . $this->SQL); |
|
| 722 | 722 | $this->typeInfo = SmrPlanetType::getTypeInfo($this->getTypeID()); |
| 723 | 723 | |
| 724 | 724 | //trim buildings first |
| 725 | 725 | foreach ($this->getBuildings() as $id => $amt) { |
| 726 | 726 | if ($this->getMaxBuildings($id) < $amt) { |
| 727 | - $this->destroyBuilding($id,$amt - $this->getMaxBuildings($id)); |
|
| 727 | + $this->destroyBuilding($id, $amt - $this->getMaxBuildings($id)); |
|
| 728 | 728 | } |
| 729 | 729 | } |
| 730 | 730 | |
@@ -755,7 +755,7 @@ discard block |
||
| 755 | 755 | return $this->typeInfo->maxLanded(); |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | - public function getStructureTypes($structureID=false) { |
|
| 758 | + public function getStructureTypes($structureID = false) { |
|
| 759 | 759 | return $this->typeInfo->structureTypes($structureID); |
| 760 | 760 | } |
| 761 | 761 | |
@@ -781,14 +781,14 @@ discard block |
||
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | public function update() { |
| 784 | - if(!$this->exists()) { |
|
| 784 | + if (!$this->exists()) { |
|
| 785 | 785 | return; |
| 786 | 786 | } |
| 787 | 787 | $this->doDelayedUpdates(); |
| 788 | - if($this->hasChanged) { |
|
| 788 | + if ($this->hasChanged) { |
|
| 789 | 789 | $this->db->query('UPDATE planet SET |
| 790 | 790 | owner_id = ' . $this->db->escapeNumber($this->ownerID) . ', |
| 791 | - password = '.$this->db->escapeString($this->password) .', |
|
| 791 | + password = '.$this->db->escapeString($this->password) . ', |
|
| 792 | 792 | planet_name = ' . $this->db->escapeString($this->planetName) . ', |
| 793 | 793 | shields = ' . $this->db->escapeNumber($this->shields) . ', |
| 794 | 794 | armour = ' . $this->db->escapeNumber($this->armour) . ', |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | $this->hasChangedFinancial = false; |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | - if($this->hasChangedStockpile) { |
|
| 812 | + if ($this->hasChangedStockpile) { |
|
| 813 | 813 | // write stockpile info |
| 814 | 814 | foreach ($this->getStockpile() as $id => $amount) { |
| 815 | 815 | if ($amount != 0) { |
@@ -826,21 +826,21 @@ discard block |
||
| 826 | 826 | if ($this->hasChangedWeapons) { |
| 827 | 827 | foreach (array_keys($this->hasChangedWeapons) as $orderID) { |
| 828 | 828 | if (isset($this->mountedWeapons[$orderID])) { |
| 829 | - $this->db->query('REPLACE INTO planet_has_weapon (game_id, sector_id, order_id, weapon_type_id) VALUES ('.$this->db->escapeNumber($this->getGameID()).','.$this->db->escapeNumber($this->getSectorID()).','.$this->db->escapeNumber($orderID).','.$this->db->escapeNumber($this->mountedWeapons[$orderID]->getWeaponTypeID()).')'); |
|
| 829 | + $this->db->query('REPLACE INTO planet_has_weapon (game_id, sector_id, order_id, weapon_type_id) VALUES (' . $this->db->escapeNumber($this->getGameID()) . ',' . $this->db->escapeNumber($this->getSectorID()) . ',' . $this->db->escapeNumber($orderID) . ',' . $this->db->escapeNumber($this->mountedWeapons[$orderID]->getWeaponTypeID()) . ')'); |
|
| 830 | 830 | } else { |
| 831 | - $this->db->query('DELETE FROM planet_has_weapon WHERE '.$this->SQL.' AND order_id='.$this->db->escapeNumber($orderID)); |
|
| 831 | + $this->db->query('DELETE FROM planet_has_weapon WHERE ' . $this->SQL . ' AND order_id=' . $this->db->escapeNumber($orderID)); |
|
| 832 | 832 | } |
| 833 | 833 | } |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | - if(count($this->hasStoppedBuilding)>0) { |
|
| 836 | + if (count($this->hasStoppedBuilding) > 0) { |
|
| 837 | 837 | $this->db->query('DELETE FROM planet_is_building WHERE ' . $this->SQL . ' |
| 838 | 838 | AND building_slot_id IN (' . $this->db->escapeArray($this->hasStoppedBuilding) . ') LIMIT ' . count($this->hasStoppedBuilding)); |
| 839 | 839 | $this->hasStoppedBuilding = array(); |
| 840 | 840 | } |
| 841 | 841 | // write building info |
| 842 | 842 | foreach ($this->hasChangedBuildings as $id => $hasChanged) { |
| 843 | - if($hasChanged===true) { |
|
| 843 | + if ($hasChanged === true) { |
|
| 844 | 844 | if ($this->hasBuilding($id)) { |
| 845 | 845 | $this->db->query('REPLACE INTO planet_has_building (game_id, sector_id, construction_id, amount) ' . |
| 846 | 846 | 'VALUES(' . $this->db->escapeNumber($this->gameID) . ', ' . $this->db->escapeNumber($this->sectorID) . ', ' . $this->db->escapeNumber($id) . ', ' . $this->db->escapeNumber($this->getBuilding($id)) . ')'); |
@@ -855,15 +855,15 @@ discard block |
||
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | function getLevel() { |
| 858 | - return array_sum($this->getBuildings())/3; |
|
| 858 | + return array_sum($this->getBuildings()) / 3; |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | function getMaxLevel() { |
| 862 | - return array_sum($this->getMaxBuildings())/3; |
|
| 862 | + return array_sum($this->getMaxBuildings()) / 3; |
|
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | function accuracy() { |
| 866 | - if($this->hasWeapons()) { |
|
| 866 | + if ($this->hasWeapons()) { |
|
| 867 | 867 | $weapons = $this->getWeapons(); |
| 868 | 868 | return $weapons[0]->getModifiedPlanetAccuracy($this); |
| 869 | 869 | } |
@@ -889,10 +889,10 @@ discard block |
||
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | function canBuild(AbstractSmrPlayer $constructor, $constructionID) { |
| 892 | - if($this->hasCurrentlyBuilding()) { |
|
| 892 | + if ($this->hasCurrentlyBuilding()) { |
|
| 893 | 893 | return 'There is already a building in progress!'; |
| 894 | 894 | } |
| 895 | - if($this->getBuilding($constructionID) >= $this->getMaxBuildings($constructionID)) { |
|
| 895 | + if ($this->getBuilding($constructionID) >= $this->getMaxBuildings($constructionID)) { |
|
| 896 | 896 | return 'This planet has reached the maximum buildings of that type.'; |
| 897 | 897 | } |
| 898 | 898 | $cost = $this->getStructureTypes($constructionID)->creditCost(); |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | private function getCompletionModifier($constructionID) { |
| 919 | 919 | $currentBuildings = $this->getBuilding($constructionID); |
| 920 | 920 | $maxBuildings = $this->getMaxBuildings($constructionID); |
| 921 | - return 0.01 + 2.97 * pow($currentBuildings/$maxBuildings, 2); |
|
| 921 | + return 0.01 + 2.97 * pow($currentBuildings / $maxBuildings, 2); |
|
| 922 | 922 | } |
| 923 | 923 | |
| 924 | 924 | // Amount of exp gained to build the next building of this type |
@@ -935,13 +935,13 @@ discard block |
||
| 935 | 935 | } |
| 936 | 936 | |
| 937 | 937 | function startBuilding(AbstractSmrPlayer $constructor, $constructionID) { |
| 938 | - if(($message = $this->canBuild($constructor, $constructionID)) !== true) { |
|
| 939 | - throw new Exception('Unable to start building: '.$message); |
|
| 938 | + if (($message = $this->canBuild($constructor, $constructionID)) !== true) { |
|
| 939 | + throw new Exception('Unable to start building: ' . $message); |
|
| 940 | 940 | } |
| 941 | 941 | $constructor->decreaseCredits($this->getStructureTypes($constructionID)->creditCost()); |
| 942 | 942 | // take the goods that are needed |
| 943 | 943 | foreach ($this->getStructureTypes($constructionID)->goods() as $goodID => $amount) { |
| 944 | - $this->decreaseStockpile($goodID,$amount); |
|
| 944 | + $this->decreaseStockpile($goodID, $amount); |
|
| 945 | 945 | } |
| 946 | 946 | foreach ($this->getStructureTypes($constructionID)->hardwareCost() as $hardwareID) { |
| 947 | 947 | $constructor->getShip()->setHardware($hardwareID, 0); |
@@ -964,13 +964,13 @@ discard block |
||
| 964 | 964 | function stopBuilding($constructionID) { |
| 965 | 965 | $matchingBuilding = false; |
| 966 | 966 | $latestFinish = 0; |
| 967 | - foreach($this->getCurrentlyBuilding() as $key => $building) { |
|
| 968 | - if($building['ConstructionID'] == $constructionID && $building['Finishes'] > $latestFinish) { |
|
| 967 | + foreach ($this->getCurrentlyBuilding() as $key => $building) { |
|
| 968 | + if ($building['ConstructionID'] == $constructionID && $building['Finishes'] > $latestFinish) { |
|
| 969 | 969 | $latestFinish = $building['Finishes']; |
| 970 | 970 | $matchingBuilding = $building; |
| 971 | 971 | } |
| 972 | 972 | } |
| 973 | - if($matchingBuilding) { |
|
| 973 | + if ($matchingBuilding) { |
|
| 974 | 974 | $this->hasStoppedBuilding[] = $matchingBuilding['BuildingSlotID']; |
| 975 | 975 | unset($this->currentlyBuilding[$matchingBuilding['BuildingSlotID']]); |
| 976 | 976 | return true; |
@@ -983,7 +983,7 @@ discard block |
||
| 983 | 983 | } |
| 984 | 984 | |
| 985 | 985 | public function setName($name) { |
| 986 | - if($this->planetName == $name) { |
|
| 986 | + if ($this->planetName == $name) { |
|
| 987 | 987 | return; |
| 988 | 988 | } |
| 989 | 989 | $this->planetName = $name; |
@@ -991,15 +991,15 @@ discard block |
||
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | public function getDisplayName() { |
| 994 | - return '<span style="color:yellow;font-variant:small-caps">' . $this->getName() . '(#'.$this->getSectorID().')</span>';; |
|
| 994 | + return '<span style="color:yellow;font-variant:small-caps">' . $this->getName() . '(#' . $this->getSectorID() . ')</span>'; ; |
|
| 995 | 995 | } |
| 996 | 996 | |
| 997 | 997 | public function isInhabitable() { |
| 998 | - return $this->inhabitableTime<= TIME; |
|
| 998 | + return $this->inhabitableTime <= TIME; |
|
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | public function isClaimed() { |
| 1002 | - return $this->ownerID>0; |
|
| 1002 | + return $this->ownerID > 0; |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | public function removeClaimed() { |
@@ -1041,9 +1041,9 @@ discard block |
||
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | 1043 | public function attackedBy(AbstractSmrPlayer $trigger, array $attackers) { |
| 1044 | - $trigger->increaseHOF(1,array('Combat','Planet','Number Of Triggers'), HOF_PUBLIC); |
|
| 1044 | + $trigger->increaseHOF(1, array('Combat', 'Planet', 'Number Of Triggers'), HOF_PUBLIC); |
|
| 1045 | 1045 | foreach ($attackers as $attacker) { |
| 1046 | - $attacker->increaseHOF(1,array('Combat','Planet','Number Of Attacks'), HOF_PUBLIC); |
|
| 1046 | + $attacker->increaseHOF(1, array('Combat', 'Planet', 'Number Of Attacks'), HOF_PUBLIC); |
|
| 1047 | 1047 | $this->db->query('REPLACE INTO player_attacks_planet (game_id, account_id, sector_id, time, level) VALUES ' . |
| 1048 | 1048 | '(' . $this->db->escapeNumber($this->getGameID()) . ', ' . $this->db->escapeNumber($attacker->getAccountID()) . ', ' . $this->db->escapeNumber($this->getSectorID()) . ', ' . $this->db->escapeNumber(TIME) . ', ' . $this->db->escapeNumber($this->getLevel()) . ')'); |
| 1049 | 1049 | } |
@@ -1052,9 +1052,9 @@ discard block |
||
| 1052 | 1052 | // Note: Attack uniqueness determined by planet owner. |
| 1053 | 1053 | $owner = $this->getOwner(); |
| 1054 | 1054 | $this->db->query('SELECT 1 FROM news WHERE type = \'BREAKING\' AND game_id = ' . $this->db->escapeNumber($trigger->getGameID()) . ' AND dead_id=' . $this->db->escapeNumber($owner->getAccountID()) . ' AND time > ' . $this->db->escapeNumber(TIME - self::TIME_ATTACK_NEWS_COOLDOWN) . ' LIMIT 1'); |
| 1055 | - if ($this->db->getNumRows()==0) { |
|
| 1055 | + if ($this->db->getNumRows() == 0) { |
|
| 1056 | 1056 | if (count($attackers) >= 5) { |
| 1057 | - $text = count($attackers) . ' members of '.$trigger->getAllianceBBLink().' have been spotted attacking ' . |
|
| 1057 | + $text = count($attackers) . ' members of ' . $trigger->getAllianceBBLink() . ' have been spotted attacking ' . |
|
| 1058 | 1058 | $this->getDisplayName() . ' in sector ' . Globals::getSectorBBLink($this->getSectorID()) . '. The planet is owned by ' . $owner->getBBLink(); |
| 1059 | 1059 | if ($owner->hasAlliance()) { |
| 1060 | 1060 | $text .= ', a member of ' . $owner->getAllianceBBLink(); |
@@ -1068,7 +1068,7 @@ discard block |
||
| 1068 | 1068 | |
| 1069 | 1069 | |
| 1070 | 1070 | public function &getPlayers() { |
| 1071 | - return SmrPlayer::getPlanetPlayers($this->getGameID(),$this->getSectorID()); |
|
| 1071 | + return SmrPlayer::getPlanetPlayers($this->getGameID(), $this->getSectorID()); |
|
| 1072 | 1072 | } |
| 1073 | 1073 | |
| 1074 | 1074 | public function countPlayers() { |
@@ -1080,7 +1080,7 @@ discard block |
||
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | public function &getOtherTraders(AbstractSmrPlayer $player) { |
| 1083 | - $players = SmrPlayer::getPlanetPlayers($this->getGameID(),$this->getSectorID()); //Do not use & because we unset something and only want that in what we return |
|
| 1083 | + $players = SmrPlayer::getPlanetPlayers($this->getGameID(), $this->getSectorID()); //Do not use & because we unset something and only want that in what we return |
|
| 1084 | 1084 | unset($players[$player->getAccountID()]); |
| 1085 | 1085 | return $players; |
| 1086 | 1086 | } |
@@ -1090,22 +1090,22 @@ discard block |
||
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | 1092 | public function hasEnemyTraders(AbstractSmrPlayer $player) { |
| 1093 | - if(!$this->hasOtherTraders($player)) |
|
| 1093 | + if (!$this->hasOtherTraders($player)) |
|
| 1094 | 1094 | return false; |
| 1095 | 1095 | $otherPlayers = $this->getOtherTraders($player); |
| 1096 | - foreach($otherPlayers as $otherPlayer) { |
|
| 1097 | - if(!$player->traderNAPAlliance($otherPlayer)) |
|
| 1096 | + foreach ($otherPlayers as $otherPlayer) { |
|
| 1097 | + if (!$player->traderNAPAlliance($otherPlayer)) |
|
| 1098 | 1098 | return true; |
| 1099 | 1099 | } |
| 1100 | 1100 | return false; |
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | public function hasFriendlyTraders(AbstractSmrPlayer $player) { |
| 1104 | - if(!$this->hasOtherTraders($player)) |
|
| 1104 | + if (!$this->hasOtherTraders($player)) |
|
| 1105 | 1105 | return false; |
| 1106 | 1106 | $otherPlayers = $this->getOtherTraders($player); |
| 1107 | - foreach($otherPlayers as $otherPlayer) { |
|
| 1108 | - if($player->traderNAPAlliance($otherPlayer)) |
|
| 1107 | + foreach ($otherPlayers as $otherPlayer) { |
|
| 1108 | + if ($player->traderNAPAlliance($otherPlayer)) |
|
| 1109 | 1109 | return true; |
| 1110 | 1110 | } |
| 1111 | 1111 | return false; |
@@ -1113,14 +1113,14 @@ discard block |
||
| 1113 | 1113 | |
| 1114 | 1114 | public function &getWeapons() { |
| 1115 | 1115 | $weapons = $this->getMountedWeapons(); |
| 1116 | - for($i=0; $i<$this->getBuilding(PLANET_TURRET); ++$i) { |
|
| 1116 | + for ($i = 0; $i < $this->getBuilding(PLANET_TURRET); ++$i) { |
|
| 1117 | 1117 | $weapons[] = SmrWeapon::getWeapon(WEAPON_PLANET_TURRET); |
| 1118 | 1118 | } |
| 1119 | 1119 | return $weapons; |
| 1120 | 1120 | } |
| 1121 | 1121 | |
| 1122 | 1122 | public function hasWeapons() { |
| 1123 | - return count($this->getWeapons())>0; |
|
| 1123 | + return count($this->getWeapons()) > 0; |
|
| 1124 | 1124 | } |
| 1125 | 1125 | |
| 1126 | 1126 | public function &shootPlayer(AbstractSmrPlayer $targetPlayer) { |
@@ -1129,25 +1129,25 @@ discard block |
||
| 1129 | 1129 | |
| 1130 | 1130 | public function &shootPlayers(array $targetPlayers) { |
| 1131 | 1131 | $results = array('Planet' => $this, 'TotalDamage' => 0, 'TotalDamagePerTargetPlayer' => array()); |
| 1132 | - foreach($targetPlayers as $targetPlayer) { |
|
| 1132 | + foreach ($targetPlayers as $targetPlayer) { |
|
| 1133 | 1133 | $results['TotalDamagePerTargetPlayer'][$targetPlayer->getAccountID()] = 0; |
| 1134 | 1134 | } |
| 1135 | - if($this->isDestroyed()) { |
|
| 1135 | + if ($this->isDestroyed()) { |
|
| 1136 | 1136 | $results['DeadBeforeShot'] = true; |
| 1137 | 1137 | return $results; |
| 1138 | 1138 | } |
| 1139 | 1139 | $results['DeadBeforeShot'] = false; |
| 1140 | 1140 | $weapons = $this->getWeapons(); |
| 1141 | - foreach($weapons as $orderID => $weapon) { |
|
| 1142 | - $results['Weapons'][$orderID] =& $weapon->shootPlayerAsPlanet($this, $targetPlayers[array_rand($targetPlayers)]); |
|
| 1143 | - if($results['Weapons'][$orderID]['Hit']) { |
|
| 1141 | + foreach ($weapons as $orderID => $weapon) { |
|
| 1142 | + $results['Weapons'][$orderID] = & $weapon->shootPlayerAsPlanet($this, $targetPlayers[array_rand($targetPlayers)]); |
|
| 1143 | + if ($results['Weapons'][$orderID]['Hit']) { |
|
| 1144 | 1144 | $results['TotalDamage'] += $results['Weapons'][$orderID]['ActualDamage']['TotalDamage']; |
| 1145 | 1145 | $results['TotalDamagePerTargetPlayer'][$results['Weapons'][$orderID]['TargetPlayer']->getAccountID()] += $results['Weapons'][$orderID]['ActualDamage']['TotalDamage']; |
| 1146 | 1146 | } |
| 1147 | 1147 | } |
| 1148 | - if($this->hasCDs()) { |
|
| 1149 | - $thisCDs = new SmrCombatDrones($this->getGameID(),$this->getCDs(),true); |
|
| 1150 | - $results['Drones'] =& $thisCDs->shootPlayerAsPlanet($this, $targetPlayers[array_rand($targetPlayers)]); |
|
| 1148 | + if ($this->hasCDs()) { |
|
| 1149 | + $thisCDs = new SmrCombatDrones($this->getGameID(), $this->getCDs(), true); |
|
| 1150 | + $results['Drones'] = & $thisCDs->shootPlayerAsPlanet($this, $targetPlayers[array_rand($targetPlayers)]); |
|
| 1151 | 1151 | $results['TotalDamage'] += $results['Drones']['ActualDamage']['TotalDamage']; |
| 1152 | 1152 | $results['TotalDamagePerTargetPlayer'][$results['Drones']['TargetPlayer']->getAccountID()] += $results['Drones']['ActualDamage']['TotalDamage']; |
| 1153 | 1153 | } |
@@ -1159,7 +1159,7 @@ discard block |
||
| 1159 | 1159 | // For every 70 damage there is a 15% chance of destroying a structure. |
| 1160 | 1160 | // Which structure is destroyed depends on the ratio of buildings and |
| 1161 | 1161 | // the time it takes to build them. |
| 1162 | - for ($i = 0; $damage > self::DAMAGE_NEEDED_FOR_DOWNGRADE_CHANCE; $damage-=self::DAMAGE_NEEDED_FOR_DOWNGRADE_CHANCE) { |
|
| 1162 | + for ($i = 0; $damage > self::DAMAGE_NEEDED_FOR_DOWNGRADE_CHANCE; $damage -= self::DAMAGE_NEEDED_FOR_DOWNGRADE_CHANCE) { |
|
| 1163 | 1163 | // Stop if the planet has no more buildlings |
| 1164 | 1164 | if ($this->getLevel() == 0) { |
| 1165 | 1165 | break; |
@@ -1173,7 +1173,7 @@ discard block |
||
| 1173 | 1173 | $destroyID = getWeightedRandom($chanceFactors); |
| 1174 | 1174 | $this->destroyBuilding($destroyID, 1); |
| 1175 | 1175 | $this->checkForExcessDefense(); |
| 1176 | - $results .= 'This team destroys <span class="red">1</span> '.$this->getStructureTypes($destroyID)->name().'.<br />'; |
|
| 1176 | + $results .= 'This team destroys <span class="red">1</span> ' . $this->getStructureTypes($destroyID)->name() . '.<br />'; |
|
| 1177 | 1177 | } |
| 1178 | 1178 | } |
| 1179 | 1179 | return $results; |
@@ -1184,20 +1184,20 @@ discard block |
||
| 1184 | 1184 | $shieldDamage = 0; |
| 1185 | 1185 | $cdDamage = 0; |
| 1186 | 1186 | $armourDamage = 0; |
| 1187 | - if(!$alreadyDead) { |
|
| 1188 | - if($damage['Shield'] || !$this->hasShields(true)) { |
|
| 1189 | - $shieldDamage = $this->doShieldDamage(min($damage['MaxDamage'],$damage['Shield']),$delayed); |
|
| 1187 | + if (!$alreadyDead) { |
|
| 1188 | + if ($damage['Shield'] || !$this->hasShields(true)) { |
|
| 1189 | + $shieldDamage = $this->doShieldDamage(min($damage['MaxDamage'], $damage['Shield']), $delayed); |
|
| 1190 | 1190 | $damage['Shield'] -= $shieldDamage; |
| 1191 | 1191 | $damage['MaxDamage'] -= $shieldDamage; |
| 1192 | 1192 | |
| 1193 | - if(!$this->hasShields(true) && ($shieldDamage == 0 || $damage['Rollover'])) { |
|
| 1193 | + if (!$this->hasShields(true) && ($shieldDamage == 0 || $damage['Rollover'])) { |
|
| 1194 | 1194 | if ($this->hasCDs(true)) { |
| 1195 | - $cdDamage = $this->doCDDamage(min($damage['MaxDamage'],$damage['Armour']),$delayed); |
|
| 1195 | + $cdDamage = $this->doCDDamage(min($damage['MaxDamage'], $damage['Armour']), $delayed); |
|
| 1196 | 1196 | $damage['Armour'] -= $cdDamage; |
| 1197 | 1197 | $damage['MaxDamage'] -= $cdDamage; |
| 1198 | 1198 | } |
| 1199 | 1199 | if ($this->hasArmour(true) && ($cdDamage == 0 || $damage['Rollover'])) { |
| 1200 | - $armourDamage = $this->doArmourDamage(min($damage['MaxDamage'],$damage['Armour']),$delayed); |
|
| 1200 | + $armourDamage = $this->doArmourDamage(min($damage['MaxDamage'], $damage['Armour']), $delayed); |
|
| 1201 | 1201 | $damage['Armour'] -= $armourDamage; |
| 1202 | 1202 | $damage['MaxDamage'] -= $armourDamage; |
| 1203 | 1203 | } |
@@ -1205,7 +1205,7 @@ discard block |
||
| 1205 | 1205 | |
| 1206 | 1206 | } |
| 1207 | 1207 | else { // hit drones behind shields - we should only use this reduced damage branch if we cannot hit shields. |
| 1208 | - $cdDamage = $this->doCDDamage(floor(min($damage['MaxDamage'],$damage['Armour'])*DRONES_BEHIND_SHIELDS_DAMAGE_PERCENT),$delayed); |
|
| 1208 | + $cdDamage = $this->doCDDamage(floor(min($damage['MaxDamage'], $damage['Armour']) * DRONES_BEHIND_SHIELDS_DAMAGE_PERCENT), $delayed); |
|
| 1209 | 1209 | } |
| 1210 | 1210 | } |
| 1211 | 1211 | |
@@ -1217,27 +1217,27 @@ discard block |
||
| 1217 | 1217 | 'HasShields' => $this->hasShields(true), |
| 1218 | 1218 | 'HasArmour' => $this->hasArmour(true), |
| 1219 | 1219 | 'CDs' => $cdDamage, |
| 1220 | - 'NumCDs' => $cdDamage/CD_ARMOUR, |
|
| 1220 | + 'NumCDs' => $cdDamage / CD_ARMOUR, |
|
| 1221 | 1221 | 'HasCDs' => $this->hasCDs(true), |
| 1222 | - 'TotalDamage' => $shieldDamage+$cdDamage+$armourDamage |
|
| 1222 | + 'TotalDamage' => $shieldDamage + $cdDamage + $armourDamage |
|
| 1223 | 1223 | ); |
| 1224 | 1224 | return $return; |
| 1225 | 1225 | } |
| 1226 | 1226 | |
| 1227 | 1227 | protected function doShieldDamage($damage, $delayed) { |
| 1228 | - $actualDamage = min($this->getShields(true),$damage); |
|
| 1228 | + $actualDamage = min($this->getShields(true), $damage); |
|
| 1229 | 1229 | $this->decreaseShields($actualDamage, $delayed); |
| 1230 | 1230 | return $actualDamage; |
| 1231 | 1231 | } |
| 1232 | 1232 | |
| 1233 | 1233 | protected function doCDDamage($damage, $delayed) { |
| 1234 | - $actualDamage = min($this->getCDs(true),floor($damage/CD_ARMOUR)); |
|
| 1234 | + $actualDamage = min($this->getCDs(true), floor($damage / CD_ARMOUR)); |
|
| 1235 | 1235 | $this->decreaseCDs($actualDamage, $delayed); |
| 1236 | - return $actualDamage*CD_ARMOUR; |
|
| 1236 | + return $actualDamage * CD_ARMOUR; |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | 1239 | protected function doArmourDamage($damage, $delayed) { |
| 1240 | - $actualDamage = min($this->getArmour(true),$damage);; |
|
| 1240 | + $actualDamage = min($this->getArmour(true), $damage); ; |
|
| 1241 | 1241 | $this->decreaseArmour($actualDamage, $delayed); |
| 1242 | 1242 | return $actualDamage; |
| 1243 | 1243 | } |
@@ -1246,9 +1246,9 @@ discard block |
||
| 1246 | 1246 | //get all players involved for HoF |
| 1247 | 1247 | $this->db->query('SELECT account_id,level FROM player_attacks_planet WHERE ' . $this->SQL . ' AND time > ' . $this->db->escapeNumber(TIME - self::TIME_TO_CREDIT_BUST)); |
| 1248 | 1248 | while ($this->db->nextRecord()) { |
| 1249 | - $currPlayer = SmrPlayer::getPlayer($this->db->getInt('account_id'),$this->getGameID()); |
|
| 1250 | - $currPlayer->increaseHOF($this->db->getInt('level'),array('Combat','Planet','Levels'), HOF_PUBLIC); |
|
| 1251 | - $currPlayer->increaseHOF(1,array('Combat','Planet','Completed'), HOF_PUBLIC); |
|
| 1249 | + $currPlayer = SmrPlayer::getPlayer($this->db->getInt('account_id'), $this->getGameID()); |
|
| 1250 | + $currPlayer->increaseHOF($this->db->getInt('level'), array('Combat', 'Planet', 'Levels'), HOF_PUBLIC); |
|
| 1251 | + $currPlayer->increaseHOF(1, array('Combat', 'Planet', 'Completed'), HOF_PUBLIC); |
|
| 1252 | 1252 | } |
| 1253 | 1253 | $this->db->query('DELETE FROM player_attacks_planet WHERE ' . $this->SQL); |
| 1254 | 1254 | } |
@@ -20,19 +20,19 @@ discard block |
||
| 20 | 20 | protected $ownerID; |
| 21 | 21 | protected $sectorID; |
| 22 | 22 | protected $gameID; |
| 23 | - protected $combatDrones=0; |
|
| 24 | - protected $scoutDrones=0; |
|
| 25 | - protected $mines=0; |
|
| 26 | - protected $expire=0; |
|
| 23 | + protected $combatDrones = 0; |
|
| 24 | + protected $scoutDrones = 0; |
|
| 25 | + protected $mines = 0; |
|
| 26 | + protected $expire = 0; |
|
| 27 | 27 | |
| 28 | 28 | protected $isNew; |
| 29 | 29 | protected $hasChanged = false; |
| 30 | 30 | |
| 31 | 31 | public static function refreshCache() { |
| 32 | - foreach(self::$CACHE_FORCES as $gameID => &$gameForces) { |
|
| 33 | - foreach($gameForces as $sectorID => &$gameSectorForces) { |
|
| 34 | - foreach($gameSectorForces as $ownerID => &$forces) { |
|
| 35 | - $forces = self::getForce($gameID,$sectorID,$ownerID,true); |
|
| 32 | + foreach (self::$CACHE_FORCES as $gameID => &$gameForces) { |
|
| 33 | + foreach ($gameForces as $sectorID => &$gameSectorForces) { |
|
| 34 | + foreach ($gameSectorForces as $ownerID => &$forces) { |
|
| 35 | + $forces = self::getForce($gameID, $sectorID, $ownerID, true); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -44,22 +44,22 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | public static function saveForces() { |
| 47 | - foreach(self::$CACHE_FORCES as $gameForces) { |
|
| 48 | - foreach($gameForces as $gameSectorForces) { |
|
| 49 | - foreach($gameSectorForces as $forces) { |
|
| 47 | + foreach (self::$CACHE_FORCES as $gameForces) { |
|
| 48 | + foreach ($gameForces as $gameSectorForces) { |
|
| 49 | + foreach ($gameSectorForces as $forces) { |
|
| 50 | 50 | $forces->update(); |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - public static function &getSectorForces($gameID,$sectorID,$forceUpdate = false) { |
|
| 57 | - if($forceUpdate || !isset(self::$CACHE_SECTOR_FORCES[$gameID][$sectorID])) { |
|
| 58 | - self::tidyUpForces(SmrGalaxy::getGalaxyContaining($gameID,$sectorID)); |
|
| 56 | + public static function &getSectorForces($gameID, $sectorID, $forceUpdate = false) { |
|
| 57 | + if ($forceUpdate || !isset(self::$CACHE_SECTOR_FORCES[$gameID][$sectorID])) { |
|
| 58 | + self::tidyUpForces(SmrGalaxy::getGalaxyContaining($gameID, $sectorID)); |
|
| 59 | 59 | $db = new SmrMySqlDatabase(); |
| 60 | 60 | $db->query('SELECT * FROM sector_has_forces WHERE sector_id = ' . $db->escapeNumber($sectorID) . ' AND game_id=' . $db->escapeNumber($gameID) . ' ORDER BY expire_time ASC'); |
| 61 | 61 | $forces = array(); |
| 62 | - while($db->nextRecord()) { |
|
| 62 | + while ($db->nextRecord()) { |
|
| 63 | 63 | $ownerID = $db->getInt('owner_id'); |
| 64 | 64 | $forces[$ownerID] = self::getForce($gameID, $sectorID, $ownerID, $forceUpdate, $db); |
| 65 | 65 | } |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | return self::$CACHE_SECTOR_FORCES[$gameID][$sectorID]; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public static function &getForce($gameID, $sectorID, $ownerID, $forceUpdate=false, $db=null) { |
|
| 72 | - if($forceUpdate || !isset(self::$CACHE_FORCES[$gameID][$sectorID][$ownerID])) { |
|
| 73 | - self::tidyUpForces(SmrGalaxy::getGalaxyContaining($gameID,$sectorID)); |
|
| 71 | + public static function &getForce($gameID, $sectorID, $ownerID, $forceUpdate = false, $db = null) { |
|
| 72 | + if ($forceUpdate || !isset(self::$CACHE_FORCES[$gameID][$sectorID][$ownerID])) { |
|
| 73 | + self::tidyUpForces(SmrGalaxy::getGalaxyContaining($gameID, $sectorID)); |
|
| 74 | 74 | $p = new SmrForce($gameID, $sectorID, $ownerID, $db); |
| 75 | 75 | self::$CACHE_FORCES[$gameID][$sectorID][$ownerID] = $p; |
| 76 | 76 | } |
@@ -78,24 +78,24 @@ discard block |
||
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | public static function tidyUpForces(SmrGalaxy $galaxyToTidy) { |
| 81 | - if(!isset(self::$TIDIED_UP[$galaxyToTidy->getGameID()][$galaxyToTidy->getGalaxyID()])) { |
|
| 81 | + if (!isset(self::$TIDIED_UP[$galaxyToTidy->getGameID()][$galaxyToTidy->getGalaxyID()])) { |
|
| 82 | 82 | self::$TIDIED_UP[$galaxyToTidy->getGameID()][$galaxyToTidy->getGalaxyID()] = true; |
| 83 | 83 | $db = new SmrMySqlDatabase(); |
| 84 | 84 | $db->query('UPDATE sector_has_forces |
| 85 | 85 | SET refresher=0, |
| 86 | 86 | expire_time = (refresh_at + if(combat_drones+mines=0, |
| 87 | - LEAST('.$db->escapeNumber(self::LOWEST_MAX_EXPIRE_SCOUTS_ONLY).', scout_drones*'.$db->escapeNumber(self::TIME_PER_SCOUT_ONLY).'), |
|
| 88 | - LEAST('.$db->escapeNumber($galaxyToTidy->getMaxForceTime()).', (combat_drones*'.$db->escapeNumber(self::TIME_PERCENT_PER_COMBAT).'+scout_drones*'.$db->escapeNumber(self::TIME_PERCENT_PER_SCOUT).'+mines*'.$db->escapeNumber(self::TIME_PERCENT_PER_MINE).')*'.$db->escapeNumber($galaxyToTidy->getMaxForceTime()).') |
|
| 87 | + LEAST('.$db->escapeNumber(self::LOWEST_MAX_EXPIRE_SCOUTS_ONLY) . ', scout_drones*' . $db->escapeNumber(self::TIME_PER_SCOUT_ONLY) . '), |
|
| 88 | + LEAST('.$db->escapeNumber($galaxyToTidy->getMaxForceTime()) . ', (combat_drones*' . $db->escapeNumber(self::TIME_PERCENT_PER_COMBAT) . '+scout_drones*' . $db->escapeNumber(self::TIME_PERCENT_PER_SCOUT) . '+mines*' . $db->escapeNumber(self::TIME_PERCENT_PER_MINE) . ')*' . $db->escapeNumber($galaxyToTidy->getMaxForceTime()) . ') |
|
| 89 | 89 | )) |
| 90 | - WHERE game_id = '.$db->escapeNumber($galaxyToTidy->getGameID()).' AND sector_id >= '.$db->escapeNumber($galaxyToTidy->getStartSector()).' AND sector_id <= '.$db->escapeNumber($galaxyToTidy->getEndSector()).' AND refresher != 0 AND refresh_at <= '.$db->escapeNumber(TIME)); |
|
| 90 | + WHERE game_id = '.$db->escapeNumber($galaxyToTidy->getGameID()) . ' AND sector_id >= ' . $db->escapeNumber($galaxyToTidy->getStartSector()) . ' AND sector_id <= ' . $db->escapeNumber($galaxyToTidy->getEndSector()) . ' AND refresher != 0 AND refresh_at <= ' . $db->escapeNumber(TIME)); |
|
| 91 | 91 | $db->query('DELETE FROM sector_has_forces WHERE expire_time < ' . $db->escapeNumber(TIME)); |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - protected function __construct($gameID, $sectorID, $ownerID, $db=null) { |
|
| 95 | + protected function __construct($gameID, $sectorID, $ownerID, $db = null) { |
|
| 96 | 96 | $this->db = new SmrMySqlDatabase(); |
| 97 | - $this->SQL = 'game_id = '.$this->db->escapeNumber($gameID).' |
|
| 98 | - AND sector_id = '.$this->db->escapeNumber($sectorID).' |
|
| 97 | + $this->SQL = 'game_id = ' . $this->db->escapeNumber($gameID) . ' |
|
| 98 | + AND sector_id = '.$this->db->escapeNumber($sectorID) . ' |
|
| 99 | 99 | AND owner_id = '.$this->db->escapeNumber($ownerID); |
| 100 | 100 | |
| 101 | 101 | if (isset($db)) { |
@@ -118,31 +118,31 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | public function exists() { |
| 121 | - return ($this->hasCDs()||$this->hasSDs()||$this->hasMines())&&!$this->hasExpired(); |
|
| 121 | + return ($this->hasCDs() || $this->hasSDs() || $this->hasMines()) && !$this->hasExpired(); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | public function canAcceptCDs() { |
| 125 | - return $this->getCDs()<50; |
|
| 125 | + return $this->getCDs() < 50; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | public function canAcceptSDs() { |
| 129 | - return $this->getSDs()<5; |
|
| 129 | + return $this->getSDs() < 5; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | public function canAcceptMines() { |
| 133 | - return $this->getMines()<50; |
|
| 133 | + return $this->getMines() < 50; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | public function hasCDs() { |
| 137 | - return $this->getCDs()>0; |
|
| 137 | + return $this->getCDs() > 0; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | public function hasSDs() { |
| 141 | - return $this->getSDs()>0; |
|
| 141 | + return $this->getSDs() > 0; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | public function hasMines() { |
| 145 | - return $this->getMines()>0; |
|
| 145 | + return $this->getMines() > 0; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | public function getCDs() { |
@@ -158,52 +158,52 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | public function addMines($amount) { |
| 161 | - if($amount<0) { |
|
| 161 | + if ($amount < 0) { |
|
| 162 | 162 | throw new Exception('Cannot add negative mines.'); |
| 163 | 163 | } |
| 164 | 164 | $this->setMines($this->getMines() + $amount); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | public function addCDs($amount) { |
| 168 | - if($amount<0) { |
|
| 168 | + if ($amount < 0) { |
|
| 169 | 169 | throw new Exception('Cannot add negative CDs.'); |
| 170 | 170 | } |
| 171 | 171 | $this->setCDs($this->getCDs() + $amount); |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | public function addSDs($amount) { |
| 175 | - if($amount<0) { |
|
| 175 | + if ($amount < 0) { |
|
| 176 | 176 | throw new Exception('Cannot add negative SDs.'); |
| 177 | 177 | } |
| 178 | 178 | $this->setSDs($this->getSDs() + $amount); |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | public function takeMines($amount) { |
| 182 | - if($amount<0) { |
|
| 182 | + if ($amount < 0) { |
|
| 183 | 183 | throw new Exception('Cannot take negative mines.'); |
| 184 | 184 | } |
| 185 | 185 | $this->setMines($this->getMines() - $amount); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | public function takeCDs($amount) { |
| 189 | - if($amount<0) { |
|
| 189 | + if ($amount < 0) { |
|
| 190 | 190 | throw new Exception('Cannot take negative CDs.'); |
| 191 | 191 | } |
| 192 | 192 | $this->setCDs($this->getCDs() - $amount); |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | public function takeSDs($amount) { |
| 196 | - if($amount<0) { |
|
| 196 | + if ($amount < 0) { |
|
| 197 | 197 | throw new Exception('Cannot take negative SDs.'); |
| 198 | 198 | } |
| 199 | 199 | $this->setSDs($this->getSDs() - $amount); |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | public function setMines($amount) { |
| 203 | - if($amount<0) { |
|
| 203 | + if ($amount < 0) { |
|
| 204 | 204 | throw new Exception('Cannot set negative mines.'); |
| 205 | 205 | } |
| 206 | - if($amount==$this->getMines()) { |
|
| 206 | + if ($amount == $this->getMines()) { |
|
| 207 | 207 | return; |
| 208 | 208 | } |
| 209 | 209 | $this->hasChanged = true; |
@@ -211,10 +211,10 @@ discard block |
||
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | public function setCDs($amount) { |
| 214 | - if($amount<0) { |
|
| 214 | + if ($amount < 0) { |
|
| 215 | 215 | throw new Exception('Cannot set negative CDs.'); |
| 216 | 216 | } |
| 217 | - if($amount==$this->getCDs()) { |
|
| 217 | + if ($amount == $this->getCDs()) { |
|
| 218 | 218 | return; |
| 219 | 219 | } |
| 220 | 220 | $this->hasChanged = true; |
@@ -222,10 +222,10 @@ discard block |
||
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | public function setSDs($amount) { |
| 225 | - if($amount<0) { |
|
| 225 | + if ($amount < 0) { |
|
| 226 | 226 | throw new Exception('Cannot set negative SDs.'); |
| 227 | 227 | } |
| 228 | - if($amount==$this->getSDs()) { |
|
| 228 | + if ($amount == $this->getSDs()) { |
|
| 229 | 229 | return; |
| 230 | 230 | } |
| 231 | 231 | $this->hasChanged = true; |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | public function hasExpired() { |
| 236 | - return $this->expire<TIME; |
|
| 236 | + return $this->expire < TIME; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | public function getExpire() { |
@@ -241,38 +241,38 @@ discard block |
||
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | public function setExpire($time) { |
| 244 | - if($time<0) { |
|
| 244 | + if ($time < 0) { |
|
| 245 | 245 | throw new Exception('Cannot set negative expiry.'); |
| 246 | 246 | } |
| 247 | - if($time==$this->getExpire()) { |
|
| 247 | + if ($time == $this->getExpire()) { |
|
| 248 | 248 | return; |
| 249 | 249 | } |
| 250 | - if($time > TIME + $this->getMaxExpireTime()) { |
|
| 250 | + if ($time > TIME + $this->getMaxExpireTime()) { |
|
| 251 | 251 | $time = TIME + $this->getMaxExpireTime(); |
| 252 | 252 | } |
| 253 | 253 | $this->hasChanged = true; |
| 254 | 254 | $this->expire = $time; |
| 255 | - if(!$this->isNew) |
|
| 255 | + if (!$this->isNew) |
|
| 256 | 256 | $this->update(); |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | public function updateExpire() { |
| 260 | 260 | // Changed (26/10/05) - scout drones count * 2 |
| 261 | - if($this->getCDs() == 0 && $this->getMines() == 0 && $this->getSDs() > 0) { |
|
| 262 | - $time = self::TIME_PER_SCOUT_ONLY*$this->getSDs(); |
|
| 261 | + if ($this->getCDs() == 0 && $this->getMines() == 0 && $this->getSDs() > 0) { |
|
| 262 | + $time = self::TIME_PER_SCOUT_ONLY * $this->getSDs(); |
|
| 263 | 263 | } |
| 264 | 264 | else { |
| 265 | - $time = ($this->getCDs()*self::TIME_PERCENT_PER_COMBAT + $this->getSDs()*self::TIME_PERCENT_PER_SCOUT + $this->getMines()*self::TIME_PERCENT_PER_MINE) * $this->getMaxGalaxyExpireTime(); |
|
| 265 | + $time = ($this->getCDs() * self::TIME_PERCENT_PER_COMBAT + $this->getSDs() * self::TIME_PERCENT_PER_SCOUT + $this->getMines() * self::TIME_PERCENT_PER_MINE) * $this->getMaxGalaxyExpireTime(); |
|
| 266 | 266 | } |
| 267 | 267 | $this->setExpire(TIME + $time); |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | public function getMaxExpireTime() { |
| 271 | - if($this->hasCDs()||$this->hasMines()) { |
|
| 271 | + if ($this->hasCDs() || $this->hasMines()) { |
|
| 272 | 272 | return $this->getMaxGalaxyExpireTime(); |
| 273 | 273 | } |
| 274 | - if(!$this->hasCDs() && !$this->hasMines() && $this->hasSDs()) { |
|
| 275 | - return max(self::LOWEST_MAX_EXPIRE_SCOUTS_ONLY,$this->getMaxGalaxyExpireTime()); |
|
| 274 | + if (!$this->hasCDs() && !$this->hasMines() && $this->hasSDs()) { |
|
| 275 | + return max(self::LOWEST_MAX_EXPIRE_SCOUTS_ONLY, $this->getMaxGalaxyExpireTime()); |
|
| 276 | 276 | } |
| 277 | 277 | return 0; |
| 278 | 278 | } |
@@ -283,26 +283,26 @@ discard block |
||
| 283 | 283 | |
| 284 | 284 | public function getBumpTurnCost(AbstractSmrShip $ship) { |
| 285 | 285 | $mines = $this->getMines(); |
| 286 | - if($mines <= 1) { |
|
| 286 | + if ($mines <= 1) { |
|
| 287 | 287 | return 0; |
| 288 | 288 | } |
| 289 | - if($mines < 10) { |
|
| 289 | + if ($mines < 10) { |
|
| 290 | 290 | $turns = 1; |
| 291 | 291 | } |
| 292 | - else if($mines < 25) { |
|
| 292 | + else if ($mines < 25) { |
|
| 293 | 293 | $turns = 2; |
| 294 | 294 | } |
| 295 | 295 | else { |
| 296 | 296 | $turns = 3; |
| 297 | 297 | } |
| 298 | - if($ship->isFederal() || $ship->hasDCS()) { |
|
| 298 | + if ($ship->isFederal() || $ship->hasDCS()) { |
|
| 299 | 299 | $turns -= 1; |
| 300 | 300 | } |
| 301 | 301 | return $turns; |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | public function getAttackTurnCost(AbstractSmrShip $ship) { |
| 305 | - if($ship->isFederal() || $ship->hasDCS()) { |
|
| 305 | + if ($ship->isFederal() || $ship->hasDCS()) { |
|
| 306 | 306 | return 2; |
| 307 | 307 | } |
| 308 | 308 | return 3; |
@@ -317,45 +317,45 @@ discard block |
||
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | public function &getSector() { |
| 320 | - return SmrSector::getSector($this->getGameID(),$this->getSectorID()); |
|
| 320 | + return SmrSector::getSector($this->getGameID(), $this->getSectorID()); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | public function getSectorID() { |
| 324 | 324 | return $this->sectorID; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - public function ping($pingMessage, AbstractSmrPlayer $playerPinging, $skipCheck=false) { |
|
| 328 | - if(!$this->hasSDs() && !$skipCheck) { |
|
| 327 | + public function ping($pingMessage, AbstractSmrPlayer $playerPinging, $skipCheck = false) { |
|
| 328 | + if (!$this->hasSDs() && !$skipCheck) { |
|
| 329 | 329 | return; |
| 330 | 330 | } |
| 331 | 331 | $owner = $this->getOwner(); |
| 332 | - if(!$playerPinging->sameAlliance($owner)) { |
|
| 333 | - $playerPinging->sendMessage($owner->getAccountID(), MSG_SCOUT, $pingMessage,false); |
|
| 332 | + if (!$playerPinging->sameAlliance($owner)) { |
|
| 333 | + $playerPinging->sendMessage($owner->getAccountID(), MSG_SCOUT, $pingMessage, false); |
|
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | function &getGalaxy() { |
| 338 | - return SmrGalaxy::getGalaxyContaining($this->getGameID(),$this->getSectorID()); |
|
| 338 | + return SmrGalaxy::getGalaxyContaining($this->getGameID(), $this->getSectorID()); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | function &getOwner() { |
| 342 | - return SmrPlayer::getPlayer($this->getOwnerID(),$this->getGameID()); |
|
| 342 | + return SmrPlayer::getPlayer($this->getOwnerID(), $this->getGameID()); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | public function update() { |
| 346 | - if(!$this->isNew) { |
|
| 346 | + if (!$this->isNew) { |
|
| 347 | 347 | if (!$this->exists()) { |
| 348 | 348 | $this->db->query('DELETE FROM sector_has_forces WHERE ' . $this->SQL); |
| 349 | - $this->isNew=true; |
|
| 349 | + $this->isNew = true; |
|
| 350 | 350 | } |
| 351 | 351 | else if ($this->hasChanged) { |
| 352 | - $this->db->query('UPDATE sector_has_forces SET combat_drones = '.$this->db->escapeNumber($this->combatDrones).', scout_drones = ' . $this->db->escapeNumber($this->scoutDrones) . ', mines = ' . $this->db->escapeNumber($this->mines) . ', expire_time = ' . $this->db->escapeNumber($this->expire) . ' WHERE ' . $this->SQL); |
|
| 352 | + $this->db->query('UPDATE sector_has_forces SET combat_drones = ' . $this->db->escapeNumber($this->combatDrones) . ', scout_drones = ' . $this->db->escapeNumber($this->scoutDrones) . ', mines = ' . $this->db->escapeNumber($this->mines) . ', expire_time = ' . $this->db->escapeNumber($this->expire) . ' WHERE ' . $this->SQL); |
|
| 353 | 353 | } |
| 354 | 354 | } |
| 355 | - else if($this->exists()) { |
|
| 355 | + else if ($this->exists()) { |
|
| 356 | 356 | $this->db->query('INSERT INTO sector_has_forces (game_id, sector_id, owner_id, combat_drones, scout_drones, mines, expire_time) |
| 357 | - VALUES('.$this->db->escapeNumber($this->gameID).', '.$this->db->escapeNumber($this->sectorID).', '.$this->db->escapeNumber($this->ownerID).', '.$this->db->escapeNumber($this->combatDrones).', '.$this->db->escapeNumber($this->scoutDrones).', '.$this->db->escapeNumber($this->mines).', '.$this->db->escapeNumber($this->expire).')'); |
|
| 358 | - $this->isNew=false; |
|
| 357 | + VALUES('.$this->db->escapeNumber($this->gameID) . ', ' . $this->db->escapeNumber($this->sectorID) . ', ' . $this->db->escapeNumber($this->ownerID) . ', ' . $this->db->escapeNumber($this->combatDrones) . ', ' . $this->db->escapeNumber($this->scoutDrones) . ', ' . $this->db->escapeNumber($this->mines) . ', ' . $this->db->escapeNumber($this->expire) . ')'); |
|
| 358 | + $this->isNew = false; |
|
| 359 | 359 | } |
| 360 | 360 | // This instance is now in sync with the database |
| 361 | 361 | $this->hasChanged = false; |
@@ -370,20 +370,20 @@ discard block |
||
| 370 | 370 | |
| 371 | 371 | public function getExamineDropForcesHREF() { |
| 372 | 372 | $container = create_container('skeleton.php', 'forces_drop.php'); |
| 373 | - $container['owner_id'] = $this->getOwnerID(); |
|
| 373 | + $container['owner_id'] = $this->getOwnerID(); |
|
| 374 | 374 | return SmrSession::getNewHREF($container); |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | public function getAttackForcesHREF() { |
| 378 | 378 | $container = create_container('forces_attack_processing.php'); |
| 379 | 379 | $container['action'] = 'attack'; |
| 380 | - $container['owner_id'] = $this->getOwnerID(); |
|
| 380 | + $container['owner_id'] = $this->getOwnerID(); |
|
| 381 | 381 | return SmrSession::getNewHREF($container); |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | public function getRefreshHREF() { |
| 385 | 385 | $container = create_container('forces_refresh_processing.php'); |
| 386 | - $container['owner_id'] = $this->getOwnerID(); |
|
| 386 | + $container['owner_id'] = $this->getOwnerID(); |
|
| 387 | 387 | return SmrSession::getNewHREF($container); |
| 388 | 388 | } |
| 389 | 389 | |
@@ -393,74 +393,74 @@ discard block |
||
| 393 | 393 | |
| 394 | 394 | public function getDropSDHREF() { |
| 395 | 395 | $container = $this->getDropContainer(); |
| 396 | - $container['drop_scout_drones'] = 1; |
|
| 396 | + $container['drop_scout_drones'] = 1; |
|
| 397 | 397 | return SmrSession::getNewHREF($container); |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | public function getTakeSDHREF() { |
| 401 | 401 | $container = $this->getDropContainer(); |
| 402 | - $container['take_scout_drones'] = 1; |
|
| 402 | + $container['take_scout_drones'] = 1; |
|
| 403 | 403 | return SmrSession::getNewHREF($container); |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | public function getDropCDHREF() { |
| 407 | 407 | $container = $this->getDropContainer(); |
| 408 | - $container['drop_combat_drones'] = 1; |
|
| 408 | + $container['drop_combat_drones'] = 1; |
|
| 409 | 409 | return SmrSession::getNewHREF($container); |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | public function getTakeCDHREF() { |
| 413 | 413 | $container = $this->getDropContainer(); |
| 414 | - $container['take_combat_drones'] = 1; |
|
| 414 | + $container['take_combat_drones'] = 1; |
|
| 415 | 415 | return SmrSession::getNewHREF($container); |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | public function getDropMineHREF() { |
| 419 | 419 | $container = $this->getDropContainer(); |
| 420 | - $container['drop_mines'] = 1; |
|
| 420 | + $container['drop_mines'] = 1; |
|
| 421 | 421 | return SmrSession::getNewHREF($container); |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | public function getTakeMineHREF() { |
| 425 | 425 | $container = $this->getDropContainer(); |
| 426 | - $container['take_mines'] = 1; |
|
| 426 | + $container['take_mines'] = 1; |
|
| 427 | 427 | return SmrSession::getNewHREF($container); |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | public static function getRefreshAllHREF() { |
| 431 | 431 | $container = array(); |
| 432 | - $container['url'] = 'forces_mass_refresh.php'; |
|
| 432 | + $container['url'] = 'forces_mass_refresh.php'; |
|
| 433 | 433 | return SmrSession::getNewHREF($container); |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | - public function &shootPlayer(AbstractSmrPlayer $targetPlayer,$minesAreAttacker) { |
|
| 437 | - return $this->shootPlayers(array($targetPlayer),$minesAreAttacker); |
|
| 436 | + public function &shootPlayer(AbstractSmrPlayer $targetPlayer, $minesAreAttacker) { |
|
| 437 | + return $this->shootPlayers(array($targetPlayer), $minesAreAttacker); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | - public function &shootPlayers(array $targetPlayers,$minesAreAttacker) { |
|
| 440 | + public function &shootPlayers(array $targetPlayers, $minesAreAttacker) { |
|
| 441 | 441 | $results = array('TotalDamage' => 0); |
| 442 | - if(!$this->exists()) { |
|
| 442 | + if (!$this->exists()) { |
|
| 443 | 443 | $results['DeadBeforeShot'] = true; |
| 444 | 444 | return $results; |
| 445 | 445 | } |
| 446 | 446 | $results['DeadBeforeShot'] = false; |
| 447 | 447 | |
| 448 | - if($this->hasMines()) { |
|
| 449 | - $thisMines = new SmrMines($this->getGameID(),$this->getMines()); |
|
| 450 | - $results['Results']['Mines'] =& $thisMines->shootPlayerAsForce($this, $targetPlayers[array_rand($targetPlayers)],$minesAreAttacker); |
|
| 448 | + if ($this->hasMines()) { |
|
| 449 | + $thisMines = new SmrMines($this->getGameID(), $this->getMines()); |
|
| 450 | + $results['Results']['Mines'] = & $thisMines->shootPlayerAsForce($this, $targetPlayers[array_rand($targetPlayers)], $minesAreAttacker); |
|
| 451 | 451 | $results['TotalDamage'] += $results['Results']['Mines']['ActualDamage']['TotalDamage']; |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | - if($this->hasCDs()) { |
|
| 455 | - $thisCDs = new SmrCombatDrones($this->getGameID(),$this->getCDs()); |
|
| 456 | - $results['Results']['Drones'] =& $thisCDs->shootPlayerAsForce($this, $targetPlayers[array_rand($targetPlayers)]); |
|
| 454 | + if ($this->hasCDs()) { |
|
| 455 | + $thisCDs = new SmrCombatDrones($this->getGameID(), $this->getCDs()); |
|
| 456 | + $results['Results']['Drones'] = & $thisCDs->shootPlayerAsForce($this, $targetPlayers[array_rand($targetPlayers)]); |
|
| 457 | 457 | $results['TotalDamage'] += $results['Results']['Drones']['ActualDamage']['TotalDamage']; |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - if(!$minesAreAttacker) { |
|
| 461 | - if($this->hasSDs()) { |
|
| 462 | - $thisSDs = new SmrScoutDrones($this->getGameID(),$this->getSDs()); |
|
| 463 | - $results['Results']['Scouts'] =& $thisSDs->shootPlayerAsForce($this, $targetPlayers[array_rand($targetPlayers)]); |
|
| 460 | + if (!$minesAreAttacker) { |
|
| 461 | + if ($this->hasSDs()) { |
|
| 462 | + $thisSDs = new SmrScoutDrones($this->getGameID(), $this->getSDs()); |
|
| 463 | + $results['Results']['Scouts'] = & $thisSDs->shootPlayerAsForce($this, $targetPlayers[array_rand($targetPlayers)]); |
|
| 464 | 464 | $results['TotalDamage'] += $results['Results']['Scouts']['ActualDamage']['TotalDamage']; |
| 465 | 465 | } |
| 466 | 466 | } |
@@ -474,16 +474,16 @@ discard block |
||
| 474 | 474 | $minesDamage = 0; |
| 475 | 475 | $cdDamage = 0; |
| 476 | 476 | $sdDamage = 0; |
| 477 | - if(!$alreadyDead) { |
|
| 478 | - $minesDamage = $this->doMinesDamage(min($damage['MaxDamage'],$damage['Armour'])); |
|
| 477 | + if (!$alreadyDead) { |
|
| 478 | + $minesDamage = $this->doMinesDamage(min($damage['MaxDamage'], $damage['Armour'])); |
|
| 479 | 479 | $damage['Armour'] -= $minesDamage; |
| 480 | 480 | $damage['MaxDamage'] -= $minesDamage; |
| 481 | - if(!$this->hasMines() && ($minesDamage == 0 || $damage['Rollover'])) { |
|
| 482 | - $cdDamage = $this->doCDDamage(min($damage['MaxDamage'],$damage['Armour'])); |
|
| 481 | + if (!$this->hasMines() && ($minesDamage == 0 || $damage['Rollover'])) { |
|
| 482 | + $cdDamage = $this->doCDDamage(min($damage['MaxDamage'], $damage['Armour'])); |
|
| 483 | 483 | $damage['Armour'] -= $cdDamage; |
| 484 | 484 | $damage['MaxDamage'] -= $cdDamage; |
| 485 | - if(!$this->hasCDs() && ($cdDamage == 0 || $damage['Rollover'])) { |
|
| 486 | - $sdDamage = $this->doSDDamage(min($damage['MaxDamage'],$damage['Armour'])); |
|
| 485 | + if (!$this->hasCDs() && ($cdDamage == 0 || $damage['Rollover'])) { |
|
| 486 | + $sdDamage = $this->doSDDamage(min($damage['MaxDamage'], $damage['Armour'])); |
|
| 487 | 487 | } |
| 488 | 488 | } |
| 489 | 489 | } |
@@ -491,35 +491,35 @@ discard block |
||
| 491 | 491 | 'KillingShot' => !$alreadyDead && !$this->exists(), |
| 492 | 492 | 'TargetAlreadyDead' => $alreadyDead, |
| 493 | 493 | 'Mines' => $minesDamage, |
| 494 | - 'NumMines' => $minesDamage/MINE_ARMOUR, |
|
| 494 | + 'NumMines' => $minesDamage / MINE_ARMOUR, |
|
| 495 | 495 | 'HasMines' => $this->hasMines(), |
| 496 | 496 | 'CDs' => $cdDamage, |
| 497 | - 'NumCDs' => $cdDamage/CD_ARMOUR, |
|
| 497 | + 'NumCDs' => $cdDamage / CD_ARMOUR, |
|
| 498 | 498 | 'HasCDs' => $this->hasCDs(), |
| 499 | 499 | 'SDs' => $sdDamage, |
| 500 | - 'NumSDs' => $sdDamage/SD_ARMOUR, |
|
| 500 | + 'NumSDs' => $sdDamage / SD_ARMOUR, |
|
| 501 | 501 | 'HasSDs' => $this->hasSDs(), |
| 502 | - 'TotalDamage' => $minesDamage+$cdDamage+$sdDamage |
|
| 502 | + 'TotalDamage' => $minesDamage + $cdDamage + $sdDamage |
|
| 503 | 503 | ); |
| 504 | 504 | return $return; |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | protected function doMinesDamage($damage) { |
| 508 | - $actualDamage = min($this->getMines(),floor($damage/MINE_ARMOUR)); |
|
| 508 | + $actualDamage = min($this->getMines(), floor($damage / MINE_ARMOUR)); |
|
| 509 | 509 | $this->takeMines($actualDamage); |
| 510 | - return $actualDamage*MINE_ARMOUR; |
|
| 510 | + return $actualDamage * MINE_ARMOUR; |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | protected function doCDDamage($damage) { |
| 514 | - $actualDamage = min($this->getCDs(),floor($damage/CD_ARMOUR)); |
|
| 514 | + $actualDamage = min($this->getCDs(), floor($damage / CD_ARMOUR)); |
|
| 515 | 515 | $this->takeCDs($actualDamage); |
| 516 | - return $actualDamage*CD_ARMOUR; |
|
| 516 | + return $actualDamage * CD_ARMOUR; |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | protected function doSDDamage($damage) { |
| 520 | - $actualDamage = min($this->getSDs(),floor($damage/SD_ARMOUR)); |
|
| 520 | + $actualDamage = min($this->getSDs(), floor($damage / SD_ARMOUR)); |
|
| 521 | 521 | $this->takeSDs($actualDamage); |
| 522 | - return $actualDamage*SD_ARMOUR; |
|
| 522 | + return $actualDamage * SD_ARMOUR; |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | public function &killForcesByPlayer(AbstractSmrPlayer $killer) { |
@@ -4,18 +4,18 @@ |
||
| 4 | 4 | throw new Exception('Gal_on not found!'); |
| 5 | 5 | } |
| 6 | 6 | |
| 7 | -$galaxy = SmrGalaxy::getGalaxy($var['game_id'],$var['gal_on']); |
|
| 7 | +$galaxy = SmrGalaxy::getGalaxy($var['game_id'], $var['gal_on']); |
|
| 8 | 8 | $template->assign('Galaxy', $galaxy); |
| 9 | 9 | |
| 10 | 10 | //get totals |
| 11 | 11 | $total = array(); |
| 12 | 12 | $totalPorts = array(); |
| 13 | 13 | $total['Ports'] = 0; |
| 14 | -for ($i=1; $i<=SmrPort::MAX_LEVEL; $i++) { |
|
| 14 | +for ($i = 1; $i <= SmrPort::MAX_LEVEL; $i++) { |
|
| 15 | 15 | $totalPorts[$i] = 0; |
| 16 | 16 | } |
| 17 | 17 | foreach ($galaxy->getSectors() as $galSector) { |
| 18 | - if($galSector->hasPort()) { |
|
| 18 | + if ($galSector->hasPort()) { |
|
| 19 | 19 | $totalPorts[$galSector->getPort()->getLevel()]++; |
| 20 | 20 | $total['Ports']++; |
| 21 | 21 | } |