/** * 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)); } }
/** * Add javascripts, handle removing of materials and show the list of them. * * @return void */ public function process() { $this->template->loadJs('addMaterial'); $this->template->loadJs('jquery.materialAsset'); $this->getTemplate()->loadJs('jquery.ajax'); $this->getTemplate()->loadJs('removeRow'); $this->getTemplate()->loadJs('jquery.popupEdit'); $materialListing = \Listing\Materials::loadList(); $materialTypeListing = \Listing\MaterialTypes::loadList(); switch ($_GET['action']) { case 'remove': $this->removeMaterial($materialListing->getById($_GET['id'])); break; } $moneyHelper = new \Helper\Money(); $this->getTemplate()->assign('materialListing', $materialListing); $this->getTemplate()->assign('materialTypeListing', $materialTypeListing); $this->getTemplate()->assign('currencyList', json_encode($moneyHelper->getCurrencyList())); }
/** * Add javascripts, handle the removing of blueprints and show the blueprints list. * * @return void */ public function process() { $this->getTemplate()->loadJs('addBlueprint'); $this->getTemplate()->loadJs('jquery.materialSelect'); $this->getTemplate()->loadJs('jquery.techniqueSelect'); $this->getTemplate()->loadJs('jquery.blueprint'); $this->getTemplate()->loadJs('showBlueprint'); $this->getTemplate()->loadJsReadyScript(' $(document).tooltip({ content: function () { $(this).addClass("tooltip"); return $(this).attr("title").replace(/(?:\\r\\n|\\r|\\n)/g, "<br />"); } }); $(".addTalentPoints").addTalentPoints(); '); $blueprintListing = \Listing\Blueprints::loadList(); $itemListing = \Listing\Items::loadList(); $itemTypeListing = \Listing\ItemTypes::loadList(); $materialListing = \Listing\Materials::loadList(); $techniqueListing = \Listing\Techniques::loadList(); $moneyHelper = new \Helper\Money(); if ($_GET['remove']) { $this->removeBlueprint($blueprintListing->getById($_GET['remove'])); } $translator = \SmartWork\Translator::getInstance(); $this->getTemplate()->assign('blueprintListing', $blueprintListing); $this->getTemplate()->assign('itemListing', $itemListing); $this->getTemplate()->assign('itemTypeListing', $itemTypeListing); $this->getTemplate()->assign('materialListing', $materialListing); $this->getTemplate()->assign('materialList', json_encode($materialListing->getAsArray())); $this->getTemplate()->assign('techniqueListing', $techniqueListing); $this->getTemplate()->assign('techniqueList', json_encode($techniqueListing->getAsArray())); $this->getTemplate()->assign('currencyList', $moneyHelper->getCurrencyList()); $talentList = array('bowMaking' => $translator->gt('bowMaking'), 'precisionMechanics' => $translator->gt('precisionMechanics'), 'blacksmith' => $translator->gt('blacksmith'), 'woodworking' => $translator->gt('woodworking'), 'leatherworking' => $translator->gt('leatherworking'), 'tailoring' => $translator->gt('tailoring')); asort($talentList, SORT_NATURAL); $this->getTemplate()->assign('talentList', json_encode($talentList)); $this->assign('columsPerItemType', array('meleeWeapon' => array('blueprint', 'item', 'itemType', 'damageType', 'materials', 'techniques', 'upgradeHitPoints', 'upgradeBreakFactor', 'upgradeInitiative', 'upgradeWeaponModificator'), 'rangedWeapon' => array('blueprint', 'item', 'itemType', 'damageType', 'materials', 'bonusRangedFightValue', 'reducePhysicalStrengthRequirement'))); }
/** * 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'; }
/** * 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 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'; } }