<?php $amount = $_REQUEST['amount']; if (!is_numeric($amount)) { create_error('Numbers only please'); } // only whole numbers allowed $amount = floor($amount); $hardware_id = $var['hardware_id']; $hardware_name = Globals::getHardwareName($hardware_id); $cost = Globals::getHardwareCost($hardware_id); // no negative amounts are allowed if ($amount <= 0) { create_error('You must actually enter an amount greater than zero!'); } // do we have enough cash? if ($player->getCredits() < $cost * $amount) { create_error('You don\'t have enough credits to buy ' . $amount . ' items!'); } // chec for max. we can hold! if ($amount > $ship->getMaxHardware($hardware_id) - $ship->getHardware($hardware_id)) { create_error('You can\'t buy more ' . $hardware_name . ' than you can transport!'); } // take the money from the user $player->decreaseCredits($cost * $amount); $player->update(); // now adjust add to ship $ship->increaseHardware($hardware_id, $amount); $ship->updateHardware(); $ship->removeUnderAttack(); //HoF
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)); } } }