// log action $account->log(5, 'Moves to sector: ' . $var['target_sector'], $player->sector_id); // send scout msg if (count($scout_owners)) { send_scout_messages($scout_owners, false); } // Move the user around (Must be done while holding both sector locks) $player->sector_id = $var['target_sector']; $player->take_turns($turns); $player->sector_change(); $player->detected = 'false'; $player->update(); // We need to release the lock on our old sector release_lock(); // We need a lock on the new sector so that more than one person isn't hitting the same mines acquire_lock($var['target_sector']); // check if this came from a plotted course from db $db->query("SELECT course, distance FROM player_plotted_course WHERE account_id = {$player->account_id} AND game_id = {$player->game_id} LIMIT 1"); if ($db->next_record()) { // get the array back $path_list = unserialize($db->f('course')); $distance = $db->f('distance'); if ($path_list[0] == $var['target_sector']) { array_shift($path_list); $distance -= $turns; // write back to db if (!empty($path_list)) { $db->query("UPDATE player_plotted_course SET distance = {$distance}, course = '" . addslashes(serialize($path_list)) . "' WHERE account_id = {$player->account_id} AND game_id = {$player->game_id} LIMIT 1"); } else { $db->query("DELETE FROM player_plotted_course WHERE account_id = {$player->account_id} AND game_id = {$player->game_id}"); }
$player->setSectorID($misjumpSector); unset($distances); } else { // we hit it. exactly $player->setSectorID($targetSector->getSectorID()); } $player->takeTurns($turnsToJump, $turnsToJump); // log action $account->log(LOG_TYPE_MOVEMENT, 'Jumps to sector: ' . $target . ' but hits: ' . $player->getSectorID(), $sector->getSectorID()); //$player->sector_change(); //$player->detected = 'false'; $player->update(); // We need to release the lock on our old sector release_lock(); // We need a lock on the new sector so that more than one person isn't hitting the same mines acquire_lock($player->getSectorID()); // delete plotted course $player->deletePlottedCourse(); // get new sector object $sector =& $player->getSector(); // make current sector visible to him $sector->markVisited($player); // send scout msg $sector->enteringSector($player, MOVEMENT_JUMP); $sectorForces =& $sector->getForces(); $mineOwnerID = false; foreach ($sectorForces as &$forces) { if (!$mineOwnerID && $forces->hasMines() && !$player->forceNAPAlliance($forces->getOwner())) { $mineOwnerID = $forces->getOwnerID(); break; }
function NPCStuff() { global $actions, $var, $previousContainer, $underAttack, $NPC_LOGIN, $db; $underAttack = false; $actions = -1; // for($i=0;$i<40;$i++) while (true) { $actions++; try { $TRADE_ROUTE =& $GLOBALS['TRADE_ROUTE']; debug('Action #' . $actions); SmrSession::$game_id = NPC_GAME_ID; debug('Getting player for account id: ' . SmrSession::$account_id); //We have to reload player on each loop $player =& SmrPlayer::getPlayer(SmrSession::$account_id, SmrSession::$game_id, true); $player->updateTurns(); if ($actions == 0) { if ($player->getAllianceName() != $NPC_LOGIN['AllianceName']) { // dirty hack so we can revisit the init block here on next iteration $actions--; if ($player->hasAlliance()) { processContainer(leaveAlliance()); } // figure out if the selected alliance already exist $db->query('SELECT alliance_id FROM alliance WHERE alliance_name=' . $db->escapeString($NPC_LOGIN['AllianceName']) . ' AND game_id=' . $db->escapeNumber(SmrSession::$game_id)); if ($db->nextRecord()) { processContainer(joinAlliance($db->getField('alliance_id'), '*--NPCS--*')); } else { processContainer(createAlliance($NPC_LOGIN['AllianceName'], '*--NPCS--*')); } } if ($player->getTurns() <= mt_rand($player->getMaxTurns() / 2, $player->getMaxTurns()) && ($player->hasNewbieTurns() || $player->hasFederalProtection())) { debug('We don\'t have enough turns to bother starting trading, and we are protected: ' . $player->getTurns()); changeNPCLogin(); } } if (!isset($TRADE_ROUTE)) { //We only want to change trade route if there isn't already one set. $TRADE_ROUTES =& findRoutes($player); $TRADE_ROUTE =& changeRoute($TRADE_ROUTES); } if ($player->isDead()) { debug('Some evil person killed us, let\'s move on now.'); $previousContainer = null; //We died, we don't care what we were doing beforehand. $TRADE_ROUTE =& changeRoute($TRADE_ROUTES); //Change route processContainer(create_container('death_processing.php')); } if ($player->getNewbieTurns() <= NEWBIE_TURNS_WARNING_LIMIT && $player->getNewbieWarning()) { processContainer(create_container('newbie_warning_processing.php')); } $fedContainer = null; 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 processContainer($fedContainer); } else { if ($player->getShip()->isUnderAttack() === true && ($player->hasPlottedCourse() === false || $player->getPlottedCourse()->getEndSector()->offersFederalProtection() === false) && ($fedContainer == null ? $fedContainer = plotToFed($player, true) : $fedContainer) !== true) { //We're under attack and need to plot course to fed. // Get the lock, remove under attack and update. acquire_lock($player->getSectorID()); $ship =& $player->getShip(true); $ship->removeUnderAttack(); $ship->updateHardware(); release_lock(); debug('Under Attack'); $underAttack = true; processContainer($fedContainer); } 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. debug('Follow Course: ' . $player->getPlottedCourse()->getNextOnPath()); processContainer(moveToSector($player, $player->getPlottedCourse()->getNextOnPath())); } else { if (($container = canWeUNO($player, true)) !== false) { //We have money and are at a uno, let's uno! debug('We\'re UNOing'); processContainer($container); } else { if ($player->hasPlottedCourse() === true) { //We have a route to follow, figure it's probably a sensible thing to follow. debug('Follow Course: ' . $player->getPlottedCourse()->getNextOnPath()); processContainer(moveToSector($player, $player->getPlottedCourse()->getNextOnPath())); } 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 if ($player->getTurns() < NPC_LOW_TURNS) { debug('Low Turns:' . $player->getTurns()); } if ($underAttack) { debug('Fedding after attack.'); } if ($player->hasNewbieTurns()) { //We have newbie turns, we can just wait here. debug('We have newbie turns, let\'s just switch to another NPC.'); changeNPCLogin(); } if ($player->hasFederalProtection()) { debug('We are in fed, time to switch to another NPC.'); changeNPCLogin(); } $ship =& $player->getShip(); processContainer(plotToFed($player, !$ship->hasMaxShields() || !$ship->hasMaxArmour() || !$ship->hasMaxCargoHolds())); } else { if (($container = checkForShipUpgrade($player)) !== false) { //We have money and are at a uno, let's uno! debug('We\'re reshipping!'); processContainer($container); } 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. debug('We need to UNO, so off we go!'); processContainer($container); } else { if ($TRADE_ROUTE instanceof Route) { debug('Trade Route'); $forwardRoute =& $TRADE_ROUTE->getForwardRoute(); $returnRoute =& $TRADE_ROUTE->getReturnRoute(); if ($forwardRoute->getBuySectorId() == $player->getSectorID() || $returnRoute->getBuySectorId() == $player->getSectorID()) { if ($forwardRoute->getBuySectorId() == $player->getSectorID()) { $buyRoute =& $forwardRoute; $sellRoute =& $returnRoute; } else { if ($returnRoute->getBuySectorId() == $player->getSectorID()) { $buyRoute =& $returnRoute; $sellRoute =& $forwardRoute; } } $ship =& $player->getShip(); if ($ship->getUsedHolds() > 0) { if ($ship->hasCargo($sellRoute->getGoodID())) { //Sell goods $goodID = $sellRoute->getGoodID(); $port =& $player->getSector()->getPort(); $tradeable = checkPortTradeable($port, $player); if ($tradeable === true && $port->getGoodAmount($goodID) >= $ship->getCargo($sellRoute->getGoodID())) { //TODO: Sell what we can rather than forcing sell all at once? //Sell goods debug('Sell Goods'); processContainer(tradeGoods($goodID, $player, $port)); } else { //Move to next route or fed. if (($TRADE_ROUTE =& changeRoute($TRADE_ROUTES)) === false) { // var_dump($TRADE_ROUTES); debug('Changing Route Failed'); processContainer(plotToFed($player)); } else { debug('Route Changed'); continue; } } } else { if ($ship->hasCargo($buyRoute->getGoodID()) === true) { //We've bought goods, plot to sell debug('Plot To Sell: ' . $buyRoute->getSellSectorId()); processContainer(plotToSector($player, $buyRoute->getSellSectorId())); } else { //Dump goods debug('Dump Goods'); processContainer(dumpCargo($player)); } } } else { //Buy goods $goodID = $buyRoute->getGoodID(); $port =& $player->getSector()->getPort(); $tradeable = checkPortTradeable($port, $player); if ($tradeable === true && $port->getGoodAmount($goodID) >= $ship->getEmptyHolds()) { //Buy goods debug('Buy Goods'); processContainer(tradeGoods($goodID, $player, $port)); } else { //Move to next route or fed. if (($TRADE_ROUTE =& changeRoute($TRADE_ROUTES)) === false) { // var_dump($TRADE_ROUTES); debug('Changing Route Failed'); processContainer(plotToFed($player)); } else { debug('Route Changed'); continue; } } } } else { debug('Plot To Buy: ' . $forwardRoute->getBuySectorId()); processContainer(plotToSector($player, $forwardRoute->getBuySectorId())); } } else { //Something weird is going on.. Let's fed and wait. debug('No actual action? Wtf?'); processContainer(plotToFed($player)); } } } } } } } } } /* else { //Otherwise let's run around at random. $links = $player->getSector()->getLinks(); $moveTo = $links[array_rand($links)]; debug('Random Wanderings: '.$moveTo); processContainer(moveToSector($player,$moveTo)); } */ } catch (Exception $e) { if ($e->getMessage() != 'Forward') { throw $e; } global $lock; if ($lock) { //only save if we have the lock. SmrSector::saveSectors(); SmrShip::saveShips(); SmrPlayer::savePlayers(); SmrForce::saveForces(); SmrPort::savePorts(); if (class_exists('WeightedRandom', false)) { WeightedRandom::saveWeightedRandoms(); } release_lock(); } //Clean up the caches as the data may get changed by other players clearCaches(); //Clear up some global vars global $locksFailed; $locksFailed = array(); $_REQUEST = array(); //Have a sleep between actions sleepNPC(); } } debug('Actions Finished.'); exitNPC(); }
function do_voodoo() { ob_clean(); global $lock, $var; foreach ($GLOBALS as $key => $value) { ${$key} =& $GLOBALS[$key]; } // initialize objects we usually need, like player, ship if (SmrSession::$game_id > 0) { $db = new SmrMySqlDatabase(); // We need to acquire locks BEFORE getting the player information // Otherwise we could be working on stale information $db->query('SELECT sector_id FROM player WHERE account_id=' . SmrSession::$old_account_id . ' AND game_id=' . SmrSession::$game_id . ' LIMIT 1'); $db->next_record(); $sector_id = $db->f('sector_id'); if (!$lock && $var['body'] != 'error.php' && !isset($var['ForwardError'])) { if (!acquire_lock($sector_id)) { create_error("Failed to acquire sector lock"); } } // Now that they've acquire a lock we can move on $player = new SMR_PLAYER(SmrSession::$old_account_id, SmrSession::$game_id); if ($player->dead == 'TRUE' && $var['body'] != 'death.php' && !isset($var['override_death'])) { $container = array(); $container["url"] = "skeleton.php"; $container["body"] = "death.php"; forward($container); } $ship = new SMR_SHIP(SmrSession::$old_account_id, SmrSession::$game_id); // update turns on that player $player->update_turns($ship->speed); if ($player->newbie_turns <= 20 && $player->newbie_warning == "TRUE" && $var["body"] != "newbie_warning.php") { forward(create_container("skeleton.php", "newbie_warning.php")); } } require get_file_loc($var["url"]); SmrSession::update(); if ($lock) { release_lock($lock); } exit; }
} // log action $account->log(5, "Jumps to sector: {$to} but hits: {$player->sector_id}", $sector->sector_id); // send scout msg $sector->leaving_sector(); //set the last sector $player->last_sector_id = $sector->sector_id; // Move the user around (Must be done while holding both sector locks) $player->take_turns(15); $player->sector_change(); $player->detected = 'false'; $player->update(); // We need to release the lock on our old sector release_lock(); // We need a lock on the new sector so that more than one person isn't hitting the same mines acquire_lock($player->sector_id); // delete plotted course $db->query("DELETE FROM player_plotted_course " . "WHERE account_id = {$player->account_id} AND " . "game_id = {$player->game_id}"); // get new sector object $sector = new SMR_SECTOR($player->sector_id, $player->game_id, $player->account_id); // make current sector visible to him $sector->mark_visited(); // send scout msg $sector->entering_sector(); $db->query("SELECT * FROM sector_has_forces, player " . "WHERE sector_has_forces.game_id = player.game_id AND " . "sector_has_forces.owner_id = player.account_id AND " . "sector_has_forces.game_id = {$player->game_id} AND " . "sector_has_forces.sector_id = {$player->sector_id} AND " . "mines > 0 AND " . "owner_id != {$player->account_id} AND " . "(alliance_id != {$player->alliance_id} OR alliance_id = 0)"); while ($db->next_record()) { // we may skip forces if this is a protected gal. if ($sector->is_protected_gal()) { $forces_account = new SMR_ACCOUNT(); $forces_account->get_by_id($db->f("owner_id")); // if one is vet and the other is newbie we skip it