Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( 3938d8...8d8584 )
by Dan
29s queued 20s
created
tools/npc/npc.php 1 patch
Braces   +55 added lines, -67 removed lines patch added patch discarded remove patch
@@ -89,12 +89,10 @@  discard block
 block discarded – undo
89 89
 
90 90
 	try {
91 91
 		changeNPCLogin();
92
-	}
93
-	catch (ForwardException $e) {}
92
+	} catch (ForwardException $e) {}
94 93
 
95 94
 	NPCStuff();
96
-}
97
-catch (Throwable $e) {
95
+} catch (Throwable $e) {
98 96
 	logException($e);
99 97
 	// Try to shut down cleanly
100 98
 	exitNPC();
@@ -157,8 +155,7 @@  discard block
 block discarded – undo
157 155
 			$fedContainer = null;
158 156
 			if ($var['url'] == 'shop_ship_processing.php' && ($fedContainer = plotToFed($player, true)) !== true) { //We just bought a ship, we should head back to our trade gal/uno - we use HQ for now as it's both in our gal and a UNO, plus it's safe which is always a bonus
159 157
 				processContainer($fedContainer);
160
-			}
161
-			else if ($player->getShip()->isUnderAttack() === true
158
+			} else if ($player->getShip()->isUnderAttack() === true
162 159
 				&&($player->hasPlottedCourse() === false || $player->getPlottedCourse()->getEndSector()->offersFederalProtection() === false)
163 160
 				&&($fedContainer == null ? $fedContainer = plotToFed($player, true) : $fedContainer) !== true) { //We're under attack and need to plot course to fed.
164 161
 				// Get the lock, remove under attack and update.
@@ -171,20 +168,16 @@  discard block
 block discarded – undo
171 168
 				debug('Under Attack');
172 169
 				$underAttack = true;
173 170
 				processContainer($fedContainer);
174
-			}
175
-			else if ($player->hasPlottedCourse() === true && $player->getPlottedCourse()->getEndSector()->offersFederalProtection()) { //We have a route to fed to follow, figure it's probably a damned sensible thing to follow.
171
+			} else if ($player->hasPlottedCourse() === true && $player->getPlottedCourse()->getEndSector()->offersFederalProtection()) { //We have a route to fed to follow, figure it's probably a damned sensible thing to follow.
176 172
 				debug('Follow Course: ' . $player->getPlottedCourse()->getNextOnPath());
177 173
 				processContainer(moveToSector($player, $player->getPlottedCourse()->getNextOnPath()));
178
-			}
179
-			else if (($container = canWeUNO($player, true)) !== false) { //We have money and are at a uno, let's uno!
174
+			} else if (($container = canWeUNO($player, true)) !== false) { //We have money and are at a uno, let's uno!
180 175
 				debug('We\'re UNOing');
181 176
 				processContainer($container);
182
-			}
183
-			else if ($player->hasPlottedCourse() === true) { //We have a route to follow, figure it's probably a sensible thing to follow.
177
+			} else if ($player->hasPlottedCourse() === true) { //We have a route to follow, figure it's probably a sensible thing to follow.
184 178
 				debug('Follow Course: ' . $player->getPlottedCourse()->getNextOnPath());
185 179
 				processContainer(moveToSector($player, $player->getPlottedCourse()->getNextOnPath()));
186
-			}
187
-			else if ($player->getTurns() < NPC_LOW_TURNS || ($player->getTurns() < $player->getMaxTurns() / 2 && $player->getNewbieTurns() < NPC_LOW_NEWBIE_TURNS) || $underAttack) { //We're low on turns or have been under attack and need to plot course to fed
180
+			} else if ($player->getTurns() < NPC_LOW_TURNS || ($player->getTurns() < $player->getMaxTurns() / 2 && $player->getNewbieTurns() < NPC_LOW_NEWBIE_TURNS) || $underAttack) { //We're low on turns or have been under attack and need to plot course to fed
188 181
 				if ($player->getTurns() < NPC_LOW_TURNS) {
189 182
 					debug('Low Turns:' . $player->getTurns());
190 183
 				}
@@ -201,16 +194,13 @@  discard block
 block discarded – undo
201 194
 				}
202 195
 				$ship = $player->getShip();
203 196
 				processContainer(plotToFed($player, !$ship->hasMaxShields() || !$ship->hasMaxArmour() || !$ship->hasMaxCargoHolds()));
204
-			}
205
-			else if (($container = checkForShipUpgrade($player)) !== false) { //We have money and are at a uno, let's uno!
197
+			} else if (($container = checkForShipUpgrade($player)) !== false) { //We have money and are at a uno, let's uno!
206 198
 				debug('We\'re reshipping!');
207 199
 				processContainer($container);
208
-			}
209
-			else if (($container = canWeUNO($player, false)) !== false) { //We need to UNO and have enough money to do it properly so let's do it sooner rather than later.
200
+			} else if (($container = canWeUNO($player, false)) !== false) { //We need to UNO and have enough money to do it properly so let's do it sooner rather than later.
210 201
 				debug('We need to UNO, so off we go!');
211 202
 				processContainer($container);
212
-			}
213
-			else if ($TRADE_ROUTE instanceof \Routes\Route) {
203
+			} else if ($TRADE_ROUTE instanceof \Routes\Route) {
214 204
 				debug('Trade Route');
215 205
 				$forwardRoute = $TRADE_ROUTE->getForwardRoute();
216 206
 				$returnRoute = $TRADE_ROUTE->getReturnRoute();
@@ -218,8 +208,7 @@  discard block
 block discarded – undo
218 208
 					if ($forwardRoute->getBuySectorId() == $player->getSectorID()) {
219 209
 						$buyRoute = $forwardRoute;
220 210
 						$sellRoute = $returnRoute;
221
-					}
222
-					else if ($returnRoute->getBuySectorId() == $player->getSectorID()) {
211
+					} else if ($returnRoute->getBuySectorId() == $player->getSectorID()) {
223 212
 						$buyRoute = $returnRoute;
224 213
 						$sellRoute = $forwardRoute;
225 214
 					}
@@ -236,30 +225,25 @@  discard block
 block discarded – undo
236 225
 								//Sell goods
237 226
 								debug('Sell Goods');
238 227
 								processContainer(tradeGoods($goodID, $player, $port));
239
-							}
240
-							else {
228
+							} else {
241 229
 								//Move to next route or fed.
242 230
 								if (($TRADE_ROUTE =& changeRoute($TRADE_ROUTES)) === false) {
243 231
 									debug('Changing Route Failed');
244 232
 									processContainer(plotToFed($player));
245
-								}
246
-								else {
233
+								} else {
247 234
 									debug('Route Changed');
248 235
 									continue;
249 236
 								}
250 237
 							}
251
-						}
252
-						else if ($ship->hasCargo($buyRoute->getGoodID()) === true) { //We've bought goods, plot to sell
238
+						} else if ($ship->hasCargo($buyRoute->getGoodID()) === true) { //We've bought goods, plot to sell
253 239
 							debug('Plot To Sell: ' . $buyRoute->getSellSectorId());
254 240
 							processContainer(plotToSector($player, $buyRoute->getSellSectorId()));
255
-						}
256
-						else {
241
+						} else {
257 242
 							//Dump goods
258 243
 							debug('Dump Goods');
259 244
 							processContainer(dumpCargo($player));
260 245
 						}
261
-					}
262
-					else { //Buy goods
246
+					} else { //Buy goods
263 247
 						$goodID = $buyRoute->getGoodID();
264 248
 
265 249
 						$port = $player->getSector()->getPort();
@@ -268,26 +252,22 @@  discard block
 block discarded – undo
268 252
 						if ($tradeable === true && $port->getGoodAmount($goodID) >= $ship->getEmptyHolds()) { //Buy goods
269 253
 							debug('Buy Goods');
270 254
 							processContainer(tradeGoods($goodID, $player, $port));
271
-						}
272
-						else {
255
+						} else {
273 256
 							//Move to next route or fed.
274 257
 							if (($TRADE_ROUTE =& changeRoute($TRADE_ROUTES)) === false) {
275 258
 								debug('Changing Route Failed');
276 259
 								processContainer(plotToFed($player));
277
-							}
278
-							else {
260
+							} else {
279 261
 								debug('Route Changed');
280 262
 								continue;
281 263
 							}
282 264
 						}
283 265
 					}
284
-				}
285
-				else {
266
+				} else {
286 267
 					debug('Plot To Buy: ' . $forwardRoute->getBuySectorId());
287 268
 					processContainer(plotToSector($player, $forwardRoute->getBuySectorId()));
288 269
 				}
289
-			}
290
-			else { //Something weird is going on.. Let's fed and wait.
270
+			} else { //Something weird is going on.. Let's fed and wait.
291 271
 				debug('No actual action? Wtf?');
292 272
 				processContainer(plotToFed($player));
293 273
 			}
@@ -299,8 +279,7 @@  discard block
 block discarded – undo
299 279
 				processContainer(moveToSector($player,$moveTo));
300 280
 			}
301 281
 			*/
302
-		}
303
-		catch (ForwardException $e) {
282
+		} catch (ForwardException $e) {
304 283
 			global $lock;
305 284
 			if ($lock) { //only save if we have the lock.
306 285
 				SmrSector::saveSectors();
@@ -308,8 +287,9 @@  discard block
 block discarded – undo
308 287
 				SmrPlayer::savePlayers();
309 288
 				SmrForce::saveForces();
310 289
 				SmrPort::savePorts();
311
-				if (class_exists('WeightedRandom', false))
312
-					WeightedRandom::saveWeightedRandoms();
290
+				if (class_exists('WeightedRandom', false)) {
291
+									WeightedRandom::saveWeightedRandoms();
292
+				}
313 293
 				release_lock();
314 294
 			}
315 295
 			//Clean up the caches as the data may get changed by other players
@@ -448,11 +428,13 @@  discard block
 block discarded – undo
448 428
 }
449 429
 
450 430
 function canWeUNO(AbstractSmrPlayer $player, $oppurtunisticOnly) {
451
-	if ($player->getCredits() < MINUMUM_RESERVE_CREDITS)
452
-		return false;
431
+	if ($player->getCredits() < MINUMUM_RESERVE_CREDITS) {
432
+			return false;
433
+	}
453 434
 	$ship = $player->getShip();
454
-	if ($ship->hasMaxShields() && $ship->hasMaxArmour() && $ship->hasMaxCargoHolds())
455
-		return false;
435
+	if ($ship->hasMaxShields() && $ship->hasMaxArmour() && $ship->hasMaxCargoHolds()) {
436
+			return false;
437
+	}
456 438
 	$sector = $player->getSector();
457 439
 
458 440
 	// We buy armour in preference to shields as it's cheaper.
@@ -466,8 +448,7 @@  discard block
 block discarded – undo
466 448
 			$hardwareSold = $location->getHardwareSold();
467 449
 			if ($player->getNewbieTurns() > MIN_NEWBIE_TURNS_TO_BUY_CARGO && !$ship->hasMaxCargoHolds() && isset($hardwareSold[HARDWARE_CARGO]) && ($amount = floor(($player->getCredits() - MINUMUM_RESERVE_CREDITS) / Globals::getHardwareCost(HARDWARE_CARGO))) > 0) { // Buy cargo holds first if we have plenty of newbie turns left.
468 450
 				$hardwareID = HARDWARE_CARGO;
469
-			}
470
-			else {
451
+			} else {
471 452
 				foreach ($hardwareArray as $hardwareArrayID) {
472 453
 					if (!$ship->hasMaxHardware($hardwareArrayID) && isset($hardwareSold[$hardwareArrayID]) && ($amount = floor(($player->getCredits() - MINUMUM_RESERVE_CREDITS) / Globals::getHardwareCost($hardwareArrayID))) > 0) {
473 454
 						$hardwareID = $hardwareArrayID;
@@ -481,11 +462,14 @@  discard block
 block discarded – undo
481 462
 		}
482 463
 	}
483 464
 
484
-	if ($oppurtunisticOnly === true)
485
-		return false;
465
+	if ($oppurtunisticOnly === true) {
466
+			return false;
467
+	}
486 468
 
487
-	if ($player->getCredits() - $ship->getCostToUNO() < MINUMUM_RESERVE_CREDITS)
488
-		return false; //Only do non-oppurtunistic UNO if we have the money to do it properly!
469
+	if ($player->getCredits() - $ship->getCostToUNO() < MINUMUM_RESERVE_CREDITS) {
470
+			return false;
471
+	}
472
+	//Only do non-oppurtunistic UNO if we have the money to do it properly!
489 473
 
490 474
 	foreach ($hardwareArray as $hardwareArrayID) {
491 475
 		if (!$ship->hasMaxHardware($hardwareArrayID)) {
@@ -574,8 +558,10 @@  discard block
 block discarded – undo
574 558
 
575 559
 function checkForShipUpgrade(AbstractSmrPlayer $player) {
576 560
 	foreach (SHIP_UPGRADE_PATH[$player->getRaceID()] as $upgradeShipID) {
577
-		if ($player->getShipTypeID() == $upgradeShipID) //We can't upgrade, only downgrade.
561
+		if ($player->getShipTypeID() == $upgradeShipID) {
562
+			//We can't upgrade, only downgrade.
578 563
 			return false;
564
+		}
579 565
 		$cost = $player->getShip()->getCostToUpgrade($upgradeShipID);
580 566
 		if ($cost <= 0 || $player->getCredits() - $cost > MINUMUM_RESERVE_CREDITS) {
581 567
 			return doShipUpgrade($player, $upgradeShipID);
@@ -597,8 +583,9 @@  discard block
 block discarded – undo
597 583
 
598 584
 function &changeRoute(array &$tradeRoutes) {
599 585
 	$false = false;
600
-	if (count($tradeRoutes) == 0)
601
-		return $false;
586
+	if (count($tradeRoutes) == 0) {
587
+			return $false;
588
+	}
602 589
 	$routeKey = array_rand($tradeRoutes);
603 590
 	$tradeRoute =& $tradeRoutes[$routeKey];
604 591
 	unset($tradeRoutes[$routeKey]);
@@ -612,10 +599,11 @@  discard block
 block discarded – undo
612 599
 
613 600
 	$tradeGoods = array(GOOD_NOTHING => false);
614 601
 	foreach (Globals::getGoods() as $goodID => $good) {
615
-		if ($player->meetsAlignmentRestriction($good['AlignRestriction']))
616
-			$tradeGoods[$goodID] = true;
617
-		else
618
-			$tradeGoods[$goodID] = false;
602
+		if ($player->meetsAlignmentRestriction($good['AlignRestriction'])) {
603
+					$tradeGoods[$goodID] = true;
604
+		} else {
605
+					$tradeGoods[$goodID] = false;
606
+		}
619 607
 	}
620 608
 
621 609
 	// Only allow NPCs to trade at ports of their race and neutral ports
@@ -642,8 +630,7 @@  discard block
 block discarded – undo
642 630
 		$routes = unserialize(gzuncompress($db->getField('routes')));
643 631
 		debug('Using Cached Routes: #' . count($routes));
644 632
 		return $routes;
645
-	}
646
-	else {
633
+	} else {
647 634
 		debug('Generating Routes');
648 635
 		$allSectors = array();
649 636
 		foreach (SmrGalaxy::getGameGalaxies($player->getGameID()) as $galaxy) {
@@ -652,10 +639,11 @@  discard block
 block discarded – undo
652 639
 
653 640
 		$distances = Plotter::calculatePortToPortDistances($allSectors, $maxDistance, $startSectorID, $endSectorID);
654 641
 
655
-		if ($maxNumberOfPorts == 1)
656
-			$allRoutes = \Routes\RouteGenerator::generateOneWayRoutes($allSectors, $distances, $tradeGoods, $tradeRaces, $routesForPort);
657
-		else
658
-			$allRoutes = \Routes\RouteGenerator::generateMultiPortRoutes($maxNumberOfPorts, $allSectors, $tradeGoods, $tradeRaces, $distances, $routesForPort, $numberOfRoutes);
642
+		if ($maxNumberOfPorts == 1) {
643
+					$allRoutes = \Routes\RouteGenerator::generateOneWayRoutes($allSectors, $distances, $tradeGoods, $tradeRaces, $routesForPort);
644
+		} else {
645
+					$allRoutes = \Routes\RouteGenerator::generateMultiPortRoutes($maxNumberOfPorts, $allSectors, $tradeGoods, $tradeRaces, $distances, $routesForPort, $numberOfRoutes);
646
+		}
659 647
 
660 648
 		unset($distances);
661 649
 
Please login to merge, or discard this patch.