예제 #1
0
 /**
  * Sanity checks a skill level (verify it's an integer between 0 and 5)
  * 
  * @param int $skillLevel the value to be checked
  * 
  * @return bool true on success
  * @throws \iveeCore\Exceptions\InvalidParameterValueException if $skillLevel is not a valid skill level
  */
 public static function sanityCheckSkillLevel($skillLevel)
 {
     if ($skillLevel < 0 or $skillLevel > 5 or !is_int($skillLevel)) {
         $exceptionClass = Config::getIveeClassName('InvalidParameterValueException');
         throw new $exceptionClass("Skill level needs to be an integer between 0 and 5");
     }
     return true;
 }
예제 #2
0
 /**
  * Gets all necessary data from SQL.
  *
  * @return array
  * @throws iveCore\Exceptions\TypeIdNotFoundException when a typeId is not found
  */
 protected function queryAttributes()
 {
     $sdeClass = Config::getIveeClassName('SDE');
     $row = $sdeClass::instance()->query("SELECT\n            it.groupID,\n            ig.categoryID,\n            it.typeName,\n            it.volume,\n            it.portionSize,\n            it.basePrice,\n            it.marketGroupID,\n            iap.typeID as blueprintTypeID\n            FROM invTypes AS it\n            JOIN industryActivityProducts as iap ON iap.productTypeID = it.typeID\n            JOIN invGroups AS ig ON it.groupID = ig.groupID\n            WHERE it.published = 1\n            AND iap.activityID = 1\n            AND it.typeID = " . $this->id . ";")->fetch_assoc();
     if (empty($row)) {
         self::throwException('TypeIdNotFoundException', "typeId " . $this->id . " not found");
     }
     return $row;
 }
예제 #3
0
 /**
  * Gets the Reaction object(s) this product can be produced from
  * 
  * @return array with Reaction objects(s)
  */
 public function getReactions()
 {
     $typeClass = Config::getIveeClassName('Type');
     $ret = array();
     foreach ($this->productOfReactionIDs as $reactionID) {
         $ret[$reactionID] = $typeClass::getById($reactionID);
     }
     return $ret;
 }
예제 #4
0
 /**
  * Gets item from Memcached.
  *
  * @param string $key under which the item is stored
  *
  * @return mixed
  * @throws \iveeCrest\Exceptions\KeyNotFoundInCacheException if key is not found
  */
 public function getItem($key)
 {
     $item = $this->memcached->get(md5($this->uniqId . '_' . $key));
     if ($this->memcached->getResultCode() == \Memcached::RES_NOTFOUND) {
         $exceptionClass = Config::getIveeClassName('KeyNotFoundInCacheException');
         throw new $exceptionClass("Key not found in memcached.");
     }
     //count memcached hit
     $this->hits++;
     return $item;
 }
예제 #5
0
 /**
  * Gets all necessary data from SQL.
  *
  * @return array
  * @throws \iveeCore\Exceptions\TypeIdNotFoundException if the typeId is not found
  */
 protected function queryAttributes()
 {
     //lookup SDE class
     $sdeClass = Config::getIveeClassName('SDE');
     $sde = $sdeClass::instance();
     $row = $sde->query("SELECT\n            it.groupID,\n            ig.categoryID,\n            it.typeName,\n            it.volume,\n            it.portionSize,\n            it.basePrice,\n            it.marketGroupID,\n            0 as productTypeID,\n            0 as maxProductionLimit\n            FROM invTypes AS it\n            JOIN invGroups AS ig ON it.groupID = ig.groupID\n            WHERE it.published = 1\n            AND it.typeID = " . $this->id . ";")->fetch_assoc();
     if (empty($row)) {
         self::throwException('TypeIdNotFoundException', "Relic ID=" . $this->id . " not found");
     }
     return $row;
 }
예제 #6
0
 /**
  * Subtracts materials from the total material array.
  *
  * @param int $typeId of the material
  * @param int $quantity of the material
  *
  * @return void
  * @throws \iveeCore\Exceptions\InvalidParameterValueException
  */
 public function subtractMaterial($typeId, $quantity)
 {
     $exceptionClass = Config::getIveeClassName('InvalidParameterValueException');
     if (!isset($this->materials[$typeId])) {
         throw new $exceptionClass('Trying to subtract materials of typeId ' . (int) $typeId . " from MaterialMap, which doesn't occur");
     } elseif ($quantity > $this->materials[$typeId]) {
         throw new $exceptionClass('Trying to subtract more materials of typeId ' . (int) $typeId . " from MaterialMap than is available");
     }
     $this->materials[$typeId] -= $quantity;
     if ($this->materials[$typeId] == 0) {
         unset($this->materials[$typeId]);
     }
 }
예제 #7
0
 /**
  * Constructor. Use \iveeCore\Speciality::getById() to instantiate Speciality objects instead.
  *
  * @param int $id of requested Speciality
  *
  * @return \iveeCore\Speciality
  * @throws \iveeCore\Exceptions\SpecialityIdNotFoundException if the specialityID is not found
  */
 protected function __construct($id)
 {
     $this->id = (int) $id;
     $sdeClass = Config::getIveeClassName('SDE');
     $sde = $sdeClass::instance();
     $row = $sde->query("SELECT specialityName\n            FROM iveeSpecialities\n            WHERE specialityID = " . $this->id . ';')->fetch_assoc();
     if (empty($row)) {
         static::throwException('SpecialityIdNotFoundException', "Speciality ID=" . $this->id . " not found");
     }
     //set data to attributes
     $this->name = $row['specialityName'];
     $res = $sde->query("SELECT groupID\n            FROM iveeSpecialityGroups\n            WHERE specialityID = " . $this->id . ';');
     while ($row = $res->fetch_assoc()) {
         $this->specialityGroupIDs[(int) $row['groupID']] = 1;
     }
 }
예제 #8
0
 /**
  * Returns a clone of the MaterialMap for this process, WITHOUT sub-processes. Will return an empty new MaterialMap
  * object if this process has no material requirements.
  *
  * @return \iveeCore\MaterialMap
  */
 public function getMaterialMap()
 {
     if (isset($this->materials)) {
         return clone $this->materials;
         //we return a clone so the original doesn't get altered
     } else {
         $materialClass = Config::getIveeClassName('MaterialMap');
         return new $materialClass();
     }
 }
예제 #9
0
 /**
  * Gets the best station for reprocessing in the system, based on the yield, which is dependent on the base
  * reprocessing efficiency and the standings from it's corporation to the character. If multiple stations have the
  * same yield, the first of those is returned.
  *
  * @return \iveeCore\Station
  * @throws \iveeCore\Exceptions\NoRelevantDataException when there is no station with Reprocessing Plant (16)
  * service in system
  */
 public function getBestReprocessingStation()
 {
     $bestStation = null;
     $bestYield = 0.0;
     foreach ($this->getSolarSystem()->getStationsWithService(16) as $station) {
         $yield = $station->getReprocessingEfficiency() * $this->getCharacterModifier()->getReprocessingTaxFactor($station->getCorporationId());
         if ($yield > $bestYield) {
             $bestYield = $yield;
             $bestStation = $station;
         }
     }
     if (is_null($bestStation)) {
         $exceptionClass = Config::getIveeClassName('NoRelevantDataException');
         throw new $exceptionClass('No Station with Reprocessing Plant service in System');
     }
     return $bestStation;
 }
예제 #10
0
 /**
  * Returns a MaterialMap object representing the reprocessing materials of the item
  *
  * @param int $batchSize number of items being reprocessed, needs to be multiple of portionSize
  * @param float $equipmentYield the reprocessing yield of the station or array
  * @param float $taxFactor the tax imposed by station as factor (<1.0)
  * @param float $implantBonusFactor the reprocessing bonus given by an implant as factor (>1.0)
  *
  * @return \iveeCore\MaterialMap
  * @throws \iveeCore\Exceptions\NotReprocessableException if item is not reprocessable
  * @throws \iveeCore\Exceptions\InvalidParameterValueException if batchSize is not multiple of portionSize or if 
  * $equipmentYield or $implantBonusPercent is not sane
  */
 public function getReprocessingMaterialMap($batchSize, $equipmentYield = 0.5, $taxFactor = 0.95, $implantBonusFactor = 1.0)
 {
     if (!$this->isReprocessable()) {
         self::throwException('NotReprocessableException', $this->name . ' is not reprocessable');
     }
     $exceptionClass = Config::getIveeClassName('InvalidParameterValueException');
     $defaultsClass = Config::getIveeClassName('Defaults');
     $defaults = $defaultsClass::instance();
     if ($batchSize % $this->portionSize != 0) {
         throw new $exceptionClass('Reprocessing batch size needs to be multiple of ' . $this->portionSize);
     }
     if ($equipmentYield > 1) {
         throw new $exceptionClass('Equipment reprocessing yield can never be > 1.0');
     }
     if ($implantBonusFactor > 1.04) {
         throw new $exceptionClass('No implants has reprocessing bonus > 4%');
     }
     if ($taxFactor > 1) {
         throw new $exceptionClass('Reprocessing tax cannot be lower than 0%');
     }
     //if (compressed) ore or ice
     if ($this->getCategoryID() == 25) {
         //Reprocessing, Reprocessing Efficiency and specific Processing skills
         $yield = $equipmentYield * (1 + 0.03 * $defaults->getSkillLevel(3385)) * (1 + 0.02 * $defaults->getSkillLevel(3389)) * (1 + 0.02 * $defaults->getSkillLevel($this->getReprocessingSkillID())) * $implantBonusFactor;
     } else {
         $yield = $equipmentYield * (1 + 0.02 * $defaults->getSkillLevel(12196));
     }
     //Scrapmetal Processing skills
     $materialsClass = Config::getIveeClassName('MaterialMap');
     $rmat = new $materialsClass();
     $numPortions = $batchSize / $this->portionSize;
     foreach ($this->getMaterials() as $typeID => $quantity) {
         $rmat->addMaterial($typeID, round($quantity * $yield * $numPortions * $taxFactor));
     }
     return $rmat;
 }
 /**
  * Gets item from Memcached.
  *
  * @param string $key under which the item is stored
  *
  * @return mixed
  * @throws \iveeCrest\Exceptions\KeyNotFoundInCacheException if key is not found
  */
 public function getItem($key)
 {
     //$ckey = md5($this->uniqId . '_' . $key);
     $ckey = $key;
     if (empty($this->cache2[$ckey])) {
         $exceptionClass = Config::getIveeClassName('KeyNotFoundInCacheException');
         throw new $exceptionClass("Key not found in cache.");
     }
     $citem = $this->cache2[$ckey];
     $item = $citem['value'];
     $ttl = $item->getCacheTTL();
     $expire = $citem['expire'];
     if (strpos($key, "oauth/token") !== false) {
         echo time2s() . "getItem() token cache_TTL {$ttl}\n";
     }
     if (strpos($key, "orders/sell") !== false) {
         //echo time2s()."getItem() order cache_TTL $ttl\n";
     }
     // TODO: do we need to throw an exception on TTL expiration?
     //$this->cache2[$ckey]['value']->getCacheTTL();
     if (time() >= $expire) {
         $exceptionClass = Config::getIveeClassName('KeyNotFoundInCacheException');
         throw new $exceptionClass("Key not found in cache.");
         echo time2s . ">>> cache item expired {$key}\n";
     }
     //count cache hit
     $this->hits++;
     return $item;
 }
 /**
  * Prints data about this process
  * 
  * @return void
  */
 public function printData()
 {
     $typeClass = Config::getIveeClassName('Type');
     $utilClass = Config::getIveeClassName('Util');
     echo "Average total success times:" . PHP_EOL;
     print_r($this->getTotalSuccessTimes());
     echo "Average total success materials:" . PHP_EOL;
     foreach ($this->getTotalSuccessMaterialMap()->getMaterials() as $typeID => $amount) {
         echo $amount . 'x ' . $typeClass::getById($typeID)->getName() . PHP_EOL;
     }
     echo "Total average success material cost: " . $utilClass::quantitiesToReadable($this->getTotalSuccessMaterialBuyCost()) . "ISK" . PHP_EOL;
     echo "Total average success slot cost: " . $utilClass::quantitiesToReadable($this->getTotalSuccessProcessCost()) . "ISK" . PHP_EOL;
     echo "Total average success cost: " . $utilClass::quantitiesToReadable($this->getTotalSuccessCost()) . "ISK" . PHP_EOL;
     echo "Total profit: " . $utilClass::quantitiesToReadable($this->getTotalProfit()) . "ISK" . PHP_EOL;
 }
예제 #13
0
 /**
  * Returns SkillMap of minimum skill requirements for activity.
  *
  * @param int $activityId of the desired activity. See ProcessData constants.
  *
  * @return \iveeCore\SkillMap
  */
 protected function getSkillMapForActivity($activityId)
 {
     if (isset($this->activitySkills[(int) $activityId])) {
         return clone $this->activitySkills[(int) $activityId];
     } else {
         $skillMapClass = Config::getIveeClassName('SkillMap');
         return new $skillMapClass();
     }
 }
예제 #14
0
 /**
  * Prints data about this process
  * 
  * @return void
  */
 public function printData()
 {
     $typeClass = Config::getIveeClassName('Type');
     $utilClass = Config::getIveeClassName('Util');
     echo "Total slot time: " . $utilClass::secondsToReadable($this->getTotalTime()) . PHP_EOL;
     //iterate over materials
     foreach ($this->getTotalMaterialMap()->getMaterials() as $typeID => $amount) {
         echo $amount . 'x ' . $typeClass::getById($typeID)->getName() . PHP_EOL;
     }
     echo "Material cost: " . $utilClass::quantitiesToReadable($this->getTotalMaterialBuyCost()) . "ISK" . PHP_EOL;
     echo "Slot cost: " . $utilClass::quantitiesToReadable($this->getTotalProcessCost()) . "ISK" . PHP_EOL;
     echo "Total cost: " . $utilClass::quantitiesToReadable($this->getTotalCost()) . "ISK" . PHP_EOL;
     echo "Total profit: " . $utilClass::quantitiesToReadable($this->getTotalProfit()) . "ISK" . PHP_EOL;
 }
예제 #15
0
 /**
  * Constructor. Use \iveeCore\Team::getById() to instantiate Team objects instead.
  *
  * @param int $id of the Team
  *
  * @return \iveeCore\Team
  * @throws \iveeCore\Exceptions\TeamIdNotFoundException if teamID is not found
  */
 protected function __construct($id)
 {
     $this->id = (int) $id;
     $sdeClass = Config::getIveeClassName('SDE');
     $sde = $sdeClass::instance();
     $row = $sde->query("SELECT solarSystemID, UNIX_TIMESTAMP(expiryTime) as expiryTime, UNIX_TIMESTAMP(creationTime) as\n            creationTime, activityID, teamName, costModifier, specID, w0BonusID, w0BonusValue, w0SpecID, w1BonusID,\n            w1BonusValue, w1SpecID, w2BonusID, w2BonusValue, w2SpecID, w3BonusID, w3BonusValue, w3SpecID\n            FROM iveeTeams WHERE teamID = " . $this->id . ";")->fetch_assoc();
     if (empty($row)) {
         static::throwException('TeamIdNotFoundException', "teamID " . $this->id . " not found");
     }
     //set data to attributes
     $this->solarSystemID = (int) $row['solarSystemID'];
     $this->expiryTime = (int) $row['expiryTime'];
     $this->creationTime = (int) $row['creationTime'];
     $this->activityID = (int) $row['activityID'];
     $this->name = $row['teamName'];
     $this->costModifier = 1.0 + $row['costModifier'] / 100;
     //convert percent to factor
     $this->specialityID = (int) $row['specID'];
     $this->bonusIDs = array((int) $row['w0BonusID'], (int) $row['w1BonusID'], (int) $row['w2BonusID'], (int) $row['w3BonusID']);
     $this->bonusValues = array((double) $row['w0BonusValue'], (double) $row['w1BonusValue'], (double) $row['w2BonusValue'], (double) $row['w3BonusValue']);
     $specialityClass = Config::getIveeClassName('Speciality');
     $this->workerSpecialities = array($specialityClass::getById((int) $row['w0SpecID']), $specialityClass::getById((int) $row['w1SpecID']), $specialityClass::getById((int) $row['w2SpecID']), $specialityClass::getById((int) $row['w3SpecID']));
 }
예제 #16
0
 /**
  * Gets the id for a given name
  * 
  * @param string $name for which the ID should be returned
  *
  * @return int
  * @throws \iveeCore\Exceptions\KeyNotFoundInCacheException if the names to ID array isn't found in pool or cache
  * @throws \iveeCore\Exceptions\TypeNameNotFoundException if the given name is not found in the mapping array
  */
 public function getIdByName($name)
 {
     if (empty($this->nameToId)) {
         if ($this->cache instanceof ICache) {
             //try getting mapping array from cache, will throw an exception if not found
             $this->nameToId = $this->cache->getItem($this->classNick . 'Names');
         } else {
             $KeyNotFoundInCacheExceptionClass = Config::getIveeClassName('KeyNotFoundInCacheException');
             throw new $KeyNotFoundInCacheExceptionClass('Names not found in pool');
         }
     }
     if (isset($this->nameToId[$name])) {
         return $this->nameToId[$name];
     }
     $typeNameNotFoundExceptionClass = Config::getIveeClassName('TypeNameNotFoundException');
     throw new $typeNameNotFoundExceptionClass('Type name not found');
 }
예제 #17
0
 /**
  * Prints data about this process.
  *
  * @param \iveeCore\IndustryModifier $buyContext for buying context
  * @param \iveeCore\IndustryModifier $sellContext for selling context, optional. If not given, $buyContext will be
  * used.
  *
  * @return void
  */
 public function printData(IndustryModifier $buyContext, IndustryModifier $sellContext = null)
 {
     $utilClass = Config::getIveeClassName('Util');
     echo "Total slot time: " . $utilClass::secondsToReadable($this->getTotalTime()) . PHP_EOL;
     //iterate over materials
     foreach ($this->getTotalMaterialMap()->getMaterials() as $typeId => $amount) {
         echo $amount . 'x ' . Type::getById($typeId)->getName() . PHP_EOL;
     }
     echo "Material cost: " . $utilClass::quantitiesToReadable($this->getTotalMaterialBuyCost($buyContext)) . "ISK" . PHP_EOL;
     echo "Slot cost: " . $utilClass::quantitiesToReadable($this->getTotalProcessCost()) . "ISK" . PHP_EOL;
     echo "Total cost: " . $utilClass::quantitiesToReadable($this->getTotalCost($buyContext)) . "ISK" . PHP_EOL;
     echo "Total profit: " . $utilClass::quantitiesToReadable($this->getTotalProfit($buyContext, $sellContext)) . "ISK" . PHP_EOL;
 }
예제 #18
0
 /**
  * Returns the compatible decryptor IDs for a given groupID
  * 
  * @param int $groupID specifies the decryptor group to return
  * 
  * @return array with the decryptor IDs
  * @throws \iveeCore\Exceptions\InvalidDecryptorGroupException if decryptor group is not found
  */
 public static function getIDsFromGroup($groupID)
 {
     //lazy load data from DB
     if (empty(static::$decryptorGroups)) {
         //lookup SDE class
         $sdeClass = Config::getIveeClassName('SDE');
         $res = $sdeClass::instance()->query("SELECT it.groupID, it.typeID FROM invGroups as ig\n                JOIN invTypes as it ON ig.groupID = it.groupID\n                WHERE categoryID = 35\n                AND it.published = 1");
         while ($row = $res->fetch_assoc()) {
             static::$decryptorGroups[(int) $row['groupID']][] = $row['typeID'];
         }
     }
     if (!isset(static::$decryptorGroups[$groupID])) {
         self::throwException('InvalidDecryptorGroupException', "Decryptor group " . (int) $groupID . " not found");
     }
     return static::$decryptorGroups[$groupID];
 }
예제 #19
0
 /**
  * Gets item from Redis.
  *
  * @param string $key under which the item is stored
  *
  * @return \iveeCore\ICacheable
  * @throws \iveeCore\Exceptions\KeyNotFoundInCacheException if key is not found
  */
 public function getItem($key)
 {
     $item = $this->redis->get($key);
     if (!$item) {
         $exceptionClass = Config::getIveeClassName('KeyNotFoundInCacheException');
         throw new $exceptionClass("Key not found in Redis.");
     }
     //count hit
     $this->hits++;
     return unserialize(gzdecode($item));
 }
예제 #20
0
 /**
  * Convenience method for throwing iveeCore Exceptions
  *
  * @param string $exceptionName nickname of the exception as configured in Config
  * @param string $message to be passed to the exception
  * @param int $code the exception code
  * @param Exception $previous the previous exception used for chaining
  *
  * @return void
  * @throws \iveeCore\Exceptions\TypeIdNotFoundException if typeID is not found
  */
 protected static function throwException($exceptionName, $message = "", $code = 0, $previous = null)
 {
     $exceptionClass = Config::getIveeClassName($exceptionName);
     throw new $exceptionClass($message, $code, $previous);
 }
예제 #21
0
 /**
  * Returns an InventionProcessData object describing the invention process.
  *
  * @param \iveeCore\IndustryModifier $iMod the object with all the necessary industry modifying entities
  * @param int $inventedBpId the ID if the blueprint to be invented. If left null, it is set to the first
  * inventable blueprint ID
  * @param int $decryptorId the decryptor the be used, if any
  * @param int $manuRecursionDepth defines if and how deep used materials should be manufactured recursively
  *
  * @return \iveeCore\InventionProcessData
  * @throws \iveeCore\Exceptions\NotInventableException if the specified blueprint can't be invented from this
  * @throws \iveeCore\Exceptions\WrongTypeException if decryptorId isn't a decryptor
  */
 public function invent(IndustryModifier $iMod, $inventedBpId = null, $decryptorId = null, $manuRecursionDepth = 1)
 {
     $inventionDataClass = Config::getIveeClassName('InventionProcessData');
     $inventableBpIds = $this->getInventableBlueprintIds();
     //if no inventedBpId given, set to first inventable BP ID
     if (is_null($inventedBpId)) {
         $inventedBpId = $inventableBpIds[0];
     } elseif (!isset($this->inventsBlueprintIds[$inventedBpId])) {
         self::throwException('NotInventableException', "Specified blueprint can't be invented from this inventor blueprint.");
     }
     //get invented BP
     $inventedBp = Type::getById($inventedBpId);
     //get modifiers and test if inventing is possible with the given assemblyLines
     $modifier = $iMod->getModifier(ProcessData::ACTIVITY_INVENTING, $inventedBp->getProduct());
     //calculate base cost, its the average of all possible invented BP's product base cost
     $baseCost = 0;
     $numInventableBps = 0;
     foreach ($inventableBpIds as $inventableBpId) {
         $inventableBp = Type::getById($inventableBpId);
         if ($inventableBp instanceof InventableBlueprint) {
             $baseCost += $inventableBp->getProductBaseCost($iMod->getMaxPriceDataAge());
             $numInventableBps++;
         }
     }
     $baseCost = $baseCost / $numInventableBps;
     //with decryptor
     if ($decryptorId > 0) {
         $decryptor = $this->getAndCheckDecryptor($decryptorId);
         $idata = new $inventionDataClass($inventedBpId, $this->getBaseTimeForActivity(ProcessData::ACTIVITY_INVENTING) * $modifier['t'], $baseCost * 0.02 * $modifier['c'], $this->calcInventionProbability($iMod->getCharacterModifier()) * $decryptor->getProbabilityModifier(), $this->inventionOutputRuns + $decryptor->getRunModifier(), -2 - $decryptor->getMEModifier(), -4 - $decryptor->getTEModifier(), $modifier['solarSystemId'], $modifier['assemblyLineTypeId']);
         $idata->addMaterial($decryptorId, 1);
     } else {
         //without decryptor
         $idata = new $inventionDataClass($inventedBpId, $this->getBaseTimeForActivity(ProcessData::ACTIVITY_INVENTING) * $modifier['t'], $baseCost * 0.02 * $modifier['c'], $this->calcInventionProbability($iMod->getCharacterModifier()), $this->inventionOutputRuns, -2, -4, $modifier['solarSystemId'], $modifier['assemblyLineTypeId']);
     }
     $idata->addSkillMap($this->getSkillMapForActivity(ProcessData::ACTIVITY_INVENTING));
     $this->addActivityMaterials($iMod, $idata, ProcessData::ACTIVITY_INVENTING, $modifier['m'], 1, $manuRecursionDepth, 0);
     return $idata;
 }
 /**
  * Prints data about this process.
  *
  * @param \iveeCore\IndustryModifier $buyContext for buying context
  * @param \iveeCore\IndustryModifier $sellContext for selling context, optional. If not given, $buyContext ist used.
  *
  * @return void
  */
 public function printData(IndustryModifier $buyContext, IndustryModifier $sellContext = null)
 {
     $utilClass = Config::getIveeClassName('Util');
     echo "Total Slot Time: " . $utilClass::secondsToReadable($this->getTotalTime()) . PHP_EOL;
     echo "Total Materials for " . $this->producesQuantity . "x " . Type::getById($this->producesTypeId)->getName() . ":" . PHP_EOL;
     //iterate over materials
     foreach ($this->getTotalMaterialMap()->getMaterials() as $typeId => $amount) {
         echo $amount . 'x ' . Type::getById($typeId)->getName() . PHP_EOL;
     }
     echo "Total Material Cost: " . $utilClass::quantitiesToReadable($this->getTotalMaterialBuyCost($buyContext)) . "ISK" . PHP_EOL;
     echo "Total Slot Cost: " . $utilClass::quantitiesToReadable($this->getTotalProcessCost()) . "ISK" . PHP_EOL;
     echo "Total Cost: " . $utilClass::quantitiesToReadable($this->getTotalCost($buyContext)) . "ISK" . PHP_EOL;
     try {
         echo "Total Profit: " . $utilClass::quantitiesToReadable($this->getTotalProfit($buyContext, $sellContext)) . "ISK" . PHP_EOL;
     } catch (Exceptions\NoPriceDataAvailableException $e) {
         echo "No profit calculation possible due to missing price data for product" . PHP_EOL;
     }
 }
예제 #23
0
 /**
  * Returns an IndustryModifier object for this station.
  *
  * @return \iveeCore\IndustryModifier
  */
 public function getIndustryModifier()
 {
     $industryModifierClass = Config::getIveeClassName('IndustryModifier');
     return $industryModifierClass::getByStationId($this->id);
 }
예제 #24
0
 /**
  * Calculates the reverse engineering chance considering skills
  *
  * @return float
  */
 public function calcReverseEngineeringProbability()
 {
     $defaultsClass = Config::getIveeClassName('Defaults');
     $defaults = $defaultsClass::instance();
     return $this->getReverseEngineeringProbability() * (1 + 0.01 * $defaults->getSkillLevel($this->encryptionSkillID) + 0.1 * ($defaults->getSkillLevel($this->datacoreSkillIDs[0]) + $defaults->getSkillLevel($this->datacoreSkillIDs[1])));
 }
예제 #25
0
 /**
  * Parses cargo or ship scan results to MaterialParseResult.
  *
  * @param string $scanResult to be parsed
  *
  * @return \iveeCore\MaterialParseResult
  */
 public static function parseScanResult($scanResult)
 {
     $materialParseResultClass = Config::getIveeClassName('MaterialParseResult');
     $pr = new $materialParseResultClass();
     //iterate over lines
     foreach (explode("\n", str_replace("\r\n", "\n", trim($scanResult))) as $line) {
         $line = trim($line);
         if (strlen($line) < 1) {
             continue;
         }
         //split line if item is preceded with a quantifier in the form "123 An Item"
         $lineFrag = preg_split('/^([0-9]+ )/', $line, null, PREG_SPLIT_DELIM_CAPTURE);
         try {
             if (count($lineFrag) == 1) {
                 $pr->addMaterial(Type::getIdByName($lineFrag[0]), 1);
             } elseif (count($lineFrag) == 3) {
                 $pr->addMaterial(Type::getIdByName($lineFrag[2]), (int) $lineFrag[1]);
             } else {
                 $pr->addUnparseable($line);
             }
         } catch (Exceptions\TypeNameNotFoundException $e) {
             $pr->addUnparseable(implode('', $lineFrag));
         }
     }
     return $pr;
 }
예제 #26
0
 /**
  * Throws NotOnMarketException
  * 
  * @return void
  * @throws \iveeCore\Exceptions\NotOnMarketException
  */
 protected function throwNotOnMarketException()
 {
     $exceptionClass = Config::getIveeClassName('NotOnMarketException');
     throw new $exceptionClass($this->name . ' cannot be bought or sold on the market');
 }
예제 #27
0
 /**
  * Returns an IndustryModifier object for all NPC stations in this system.
  *
  * @return \iveeCore\IndustryModifier
  */
 public function getIndustryModifierForAllNpcStations()
 {
     $industryModifierClass = Config::getIveeClassName('IndustryModifier');
     return $industryModifierClass::getBySystemIdForAllNpcStations($this->id);
 }
예제 #28
0
 /**
  * Gets the key for a given name.
  *
  * @param string $classTypeNamesKey specific to the class of objects we want to look in
  * @param string $name for which the key should be returned
  *
  * @return string
  * @throws \iveeCore\Exceptions\KeyNotFoundInCacheException if the names to key array isn't found in pool or cache
  * @throws \iveeCore\Exceptions\TypeNameNotFoundException if the given name is not found in the mapping array
  * @throws \iveeCore\Exceptions\WrongTypeException if object returned from cache is not CacheableArray
  */
 public function getKeyByName($classTypeNamesKey, $name)
 {
     if (empty($this->nameToKey[$classTypeNamesKey])) {
         if ($this->cache instanceof ICache) {
             //try getting mapping array from cache, will throw an exception if not found
             $cacheableArray = $this->cache->getItem($classTypeNamesKey);
             if (!$cacheableArray instanceof CacheableArray) {
                 $WrongTypeExceptionClass = Config::getIveeClassName('WrongTypeException');
                 throw new $WrongTypeExceptionClass('Object given is not CacheableArray');
             }
             $this->nameToKey[$classTypeNamesKey] = $cacheableArray->data;
         } else {
             $KeyNotFoundInCacheExceptionClass = Config::getIveeClassName('KeyNotFoundInCacheException');
             throw new $KeyNotFoundInCacheExceptionClass('Names not found in pool');
         }
     }
     if (isset($this->nameToKey[$classTypeNamesKey][$name])) {
         return $this->nameToKey[$classTypeNamesKey][$name];
     }
     $typeNameNotFoundExceptionClass = Config::getIveeClassName('TypeNameNotFoundException');
     throw new $typeNameNotFoundExceptionClass('Type name not found');
 }
 /**
  * Returns the inventor blueprint
  * 
  * @return InventorBlueprint
  */
 public function getInventorBlueprint()
 {
     $typeClass = Config::getIveeClassName('Type');
     return $typeClass::getById($this->getInventorBlueprintId());
 }
예제 #30
0
 /**
  * Runs the reaction for producing a given number of units of this type. If multiple reactions are possible (like
  * alchemy), the most cost effective option is used.
  *
  * @param \iveeCore\IndustryModifier $iMod as industry context
  * @param int|float $units defines the number of desired output material units
  * @param int $recursionDepth defines the maximum number of reaction recursions
  * @param \iveeCore\IndustryModifier $buyContext for pricing context for chosing the cheapest reaction. If not
  * given, it defaults to default Jita 4-4 CNAP.
  *
  * @return \iveeCore\ReactionProcessData
  */
 public function doBestReaction(IndustryModifier $iMod, $units, $recursionDepth = 0, IndustryModifier $buyContext = null)
 {
     $reactions = $this->getReactions();
     //if there's only one reaction option, do straight forward reaction
     if (count($reactions) == 1) {
         return array_pop($reactions)->reactExact($iMod, $units, $recursionDepth);
     }
     //if no pricing context waas given, get the default one
     if (is_null($buyContext)) {
         $iModClass = Config::getIveeClassName('IndustryModifier');
         $buyContext = $iModClass::getByStationId(60003760);
         //hardcoded Jita 4-4 CNAP
     }
     $bestRpd = null;
     $bestCost = null;
     //run all reaction options and pick the cheapest one
     foreach ($reactions as $reaction) {
         $rpd = $reaction->reactExact($iMod, $units, $recursionDepth);
         $cost = $rpd->getTotalMaterialBuyCost($buyContext);
         if (is_null($bestCost) or $cost < $bestCost) {
             $bestCost = $cost;
             $bestRpd = $rpd;
         }
     }
     return $bestRpd;
 }