/** * Get the estimated finishing time in days or hours. * * @param boolean $format * * @return string|integer */ public function getEstimatedFinishingTime($format = true) { $talentPoints = $this->getTotalTalentPoints(); $time = 0; foreach ($this->blueprint->getMaterialList() as $material) { switch ($material['talent']) { case 'blacksmith': $charHandicap = $this->character->getBlacksmith() - $this->getHandicap(); break; case 'bowMaking': $charHandicap = $this->character->getBowMaking() - $this->getHandicap(); break; case 'precisionMechanics': $charHandicap = $this->character->getPrecisionMechanics() - $this->getHandicap(); break; case 'woodworking': $charHandicap = $this->character->getWoodworking() - $this->getHandicap(); break; case 'leatherworking': $charHandicap = $this->character->getLeatherworking() - $this->getHandicap(); break; case 'tailoring': $charHandicap = $this->character->getTailoring() - $this->getHandicap(); break; } if ($charHandicap <= 0) { $charHandicap = 1; } $time += $talentPoints / $charHandicap * ($this->blueprint->getTimeUnits() * $this->timeUnitSeconds); } switch ($this->blueprint->getItemType()->getType()) { case 'meleeWeapon': $charHandicap = $this->character->getBlacksmith() - $this->getHandicap(); break; case 'rangedWeapon': $charHandicap = $this->character->getBowMaking() - $this->getHandicap(); break; case 'shield': break; case 'armor': break; case 'projectile': break; } if ($format) { return $this->formatProductionTime($time); } return $time; }
/** * Import a character from the Helden Software xml export. * * @return \Model\Character */ public function import() { $simplexml = simplexml_load_string($this->xml); /* @var $characterXml \SimpleXMLElement */ $characterXml = $simplexml->held; $characterAttributes = $characterXml->attributes(); $character = array('user' => \SmartWork\User::getUserById($_SESSION['userId']), 'key' => $characterAttributes['key'], 'lastUpdate' => \DateTime::createFromFormat('U', intval(floatval($characterAttributes['stand']) / 1000)), 'name' => $characterAttributes['name'], 'bowMaking' => 0, 'precisionMechanics' => 0, 'blacksmith' => 0, 'woodworking' => 0, 'leatherworking' => 0, 'tailoring' => 0); /* @var $talents \SimpleXMLElement */ $talents = $characterXml->talentliste; /* @var $talent \SimpleXMLElement */ foreach ($talents->talent as $talent) { $talentAttributes = $talent->attributes(); if (array_key_exists(strval($talentAttributes['name']), $this->talentMapping)) { $character[$this->talentMapping[strval($talentAttributes['name'])]] = intval($talentAttributes['value']); } } return \Model\Character::create($character); }
/** * Load all characters for the logged in user. * * @return \self */ public static function loadList() { $sql = ' SELECT `characterId` FROM characters WHERE userid = ' . \sqlval($_SESSION['userId']) . ' AND !deleted '; $characterIds = query($sql, true); $obj = new self(); if (empty($characterIds)) { return $obj; } $list = array(); foreach ($characterIds as $character) { $list[$character['characterId']] = \Model\Character::loadById($character['characterId']); } $obj->setList($list); return $obj; }
/** * Remove a character. * * @param \Model\Character $character * * @return void */ protected function removeCharacter($character) { $character->remove(); redirect('index.php?page=Characters'); }