$speed = $ship->getSpeed(); // assign the new ship $ship->decloak(); $ship->disableIllusion(); $ship->setShipTypeID($ship_id); //now adapt turns $player->setTurns($player->getTurns() * ($speed / $ship->getSpeed())); doUNO($player, $ship); } elseif ($var['func'] == 'Weapon') { $weapon_id = $_REQUEST['weapon_id']; $amount = $_REQUEST['amount']; for ($i = 1; $i <= $amount; $i++) { $ship->addWeapon($weapon_id); } } elseif ($var['func'] == 'Uno') { doUNO($player, $ship); } elseif ($var['func'] == 'Warp') { $sector_to = trim($_REQUEST['sector_to']); if (!is_numeric($sector_to)) { create_error('Sector ID has to be a number.'); } if (!SmrGalaxy::getGalaxyContaining($player->getGameID(), $sector_to)) { create_error('Sector ID is not in any galaxy.'); } $player->setSectorID($sector_to); $player->setLandedOnPlanet(false); } elseif ($var['func'] == 'Turns') { $player->setTurns((int) $_REQUEST['turns']); } elseif ($var['func'] == 'Exp') { $exp = min(500000, (int) $_REQUEST['exp']); $player->setExperience($exp);
function canWeUNO(AbstractSmrPlayer &$player, $oppurtunisticOnly) { if ($player->getCredits() < MINUMUM_RESERVE_CREDITS) { return false; } $ship =& $player->getShip(); if ($ship->hasMaxShields() && $ship->hasMaxArmour() && $ship->hasMaxCargoHolds()) { return false; } $sector =& $player->getSector(); // We buy armour in preference to shields as it's cheaper. // We buy cargo holds last if we have no newbie turns because we'd rather not die $hardwareArray = array(HARDWARE_ARMOUR, HARDWARE_SHIELDS, HARDWARE_CARGO); $amount = 0; $locations =& $sector->getLocations(); foreach ($locations as &$location) { if ($location->isHardwareSold()) { $hardwareSold =& $location->getHardwareSold(); 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. $hardwareID = HARDWARE_CARGO; } else { foreach ($hardwareArray as $hardwareArrayID) { if (!$ship->hasMaxHardware($hardwareArrayID) && isset($hardwareSold[$hardwareArrayID]) && ($amount = floor(($player->getCredits() - MINUMUM_RESERVE_CREDITS) / Globals::getHardwareCost($hardwareArrayID))) > 0) { $hardwareID = $hardwareArrayID; break; } } } if (isset($hardwareID)) { return doUNO($hardwareID, min($ship->getMaxHardware($hardwareID) - $ship->getHardware($hardwareID), $amount)); } } } if ($oppurtunisticOnly === true) { return false; } if ($player->getCredits() - $ship->getCostToUNO() < MINUMUM_RESERVE_CREDITS) { return false; } //Only do non-oppurtunistic UNO if we have the money to do it properly! foreach ($hardwareArray as $hardwareArrayID) { if (!$ship->hasMaxHardware($hardwareArrayID)) { $hardwareNeededID = $hardwareArrayID; return plotToNearest($player, Globals::getHardwareTypes($hardwareArrayID)); } } }