/** * Get a single item. * Used for ajax requests. * * @param \Model\Item $item * * @return void */ protected function getItem($item) { $this->doRender = false; if (empty($item)) { $this->echoAjaxResponse(array('ok' => false, 'error' => 'noItemFound')); } else { $moneyHelper = new \Helper\Money(); $itemArray = $item->getAsArray(); $itemArray['price'] = $moneyHelper->exchange($itemArray['price'], 'K', 'S'); $itemArray['currency'] = 'S'; $itemArray['weaponModificator'] = $itemArray['weaponModificatorFormatted']; $this->echoAjaxResponse(array('ok' => true, 'data' => $itemArray)); } }
/** * Calculate the end price for the blueprint. * * @return string */ public function getEndPrice() { $price = $this->getItem()->getPrice(); $materialPrice = 0; $priceFactor = 0; $priceFactorBelowOne = 0; $moneyHelper = new \Helper\Money(); switch ($this->getItemType()->getType()) { case 'meleeWeapon': foreach ($this->materialList as $item) { /* @var $material \Model\Material */ $material = $item['material']; /* @var $materialAsset \Model\MaterialAsset */ $materialAsset = $item['materialAsset']; if ($materialAsset->getPriceFactor()) { if ($materialAsset->getPriceFactor() >= 1) { $priceFactor += $materialAsset->getPriceFactor(); } else { if (!$priceFactorBelowOne) { $priceFactorBelowOne = $materialAsset->getPriceFactor(); } else { $priceFactorBelowOne *= $materialAsset->getPriceFactor(); } } } elseif ($materialAsset->getPriceWeight()) { $materialPrice += $this->item->getWeight() * ($item['percentage'] / 100) * $materialAsset->getPriceWeightRaw(); } } /* @var $technique \Model\Technique */ foreach ($this->techniqueList as $technique) { if ($technique->getUnsellable()) { $translator = \SmartWork\Translator::getInstance(); return $translator->gt('unsellable'); } if ($technique->getPriceFactor() >= 1) { $priceFactor += $technique->getPriceFactor(); } else { if (!$priceFactorBelowOne) { $priceFactorBelowOne = $technique->getPriceFactor(); } else { $priceFactorBelowOne *= $technique->getPriceFactor(); } } } $priceFactor += $this->getUpgradeHitPoints() * 3; $priceFactor += $this->getUpgradeBreakFactor() * -2; $priceFactor += $this->getUpgradeInitiative() * 5; if ($this->getUpgradeWeaponModificator()) { $upgradeWeaponModificator = $this->getUpgradeWeaponModificator(); $priceFactor += ($upgradeWeaponModificator[0]['attack'] + $upgradeWeaponModificator[0]['parade']) * 5; } break; case 'rangedWeapon': foreach ($this->materialList as $item) { /* @var $material \Model\Material */ $material = $item['material']; /* @var $materialAsset \Model\MaterialAsset */ $materialAsset = $item['materialAsset']; if ($materialAsset->getPriceFactor()) { if ($materialAsset->getPriceFactor() >= 1) { $priceFactor += $materialAsset->getPriceFactor(); } else { if (!$priceFactorBelowOne) { $priceFactorBelowOne = $materialAsset->getPriceFactor(); } else { $priceFactorBelowOne *= $materialAsset->getPriceFactor(); } } } elseif ($materialAsset->getPriceWeight()) { $materialPrice += $this->item->getWeight() * ($item['percentage'] / 100) * $materialAsset->getPriceWeightRaw(); } } $priceFactor += $this->getBonusRangedFightValue() * 5; $priceFactor += $this->getReducePhysicalStrengthRequirement() * 3; break; case 'shield': break; case 'armor': break; case 'projectile': break; } if ($priceFactor > 0) { $price *= $priceFactor; } if ($priceFactorBelowOne > 0) { $price *= $priceFactorBelowOne; } $price += $materialPrice; return number_format($moneyHelper->exchange($price, 'K', 'S'), 0, ',', '.') . ' S'; }
/** * Get the weight price as a formatted string. * * @return string */ public function getPriceWeight() { $moneyHelper = new \Helper\Money(); return number_format($moneyHelper->exchange($this->priceWeight, 'K', 'S'), 0, ',', '.') . ' ST'; }
/** * Get the price formatted as Silbertaler. * * @return string */ public function getPriceFormatted() { $moneyHelper = new \Helper\Money(); $price = $moneyHelper->exchange($this->getPrice(), 'K', 'S'); if ($price > 0 && $price < 1) { return number_format($price, 1, ',', '.') . ' S'; } else { return number_format($price, 0, ',', '.') . ' S'; } }