public function build($village, $x, $y, $useDuration = true) { $db = Neuron_Core_Database::__getInstance(); if ($useDuration) { $constructionTime = $this->getConstructionTime($village); } else { $constructionTime = 0; } $size = $this->getSize(); $bcost = $this->getBuildingCost($village); $resources = array(); $runes = array(); if (isset($bcost['runeId']) && isset($bcost['runeAmount'])) { $runes[$bcost['runeId']] = $bcost['runeAmount']; } unset($bcost['runeId']); unset($bcost['runeAmount']); foreach ($bcost as $k => $v) { $resources[$k] = $v; } $t = json_encode(array(array('resources' => $resources, 'runes' => $runes))); $data = array('xas' => $x, 'yas' => $y, 'sizeX' => $size[0], 'sizeY' => $size[1], 'buildingType' => $this->getBuildingId(), 'village' => $village->getId(), 'startDate' => time(), 'readyDate' => time() + $constructionTime, 'usedResources' => $t); $id = $db->insert('map_buildings', $data); $village->buildings->reloadBuildings(); $village->resources->reloadRunes(); reloadEverything(); Neuron_GameServer::addMapUpdate($x, $y, 'BUILD'); $obj = self::getBuilding($this->getBuildingId(), $village->getRace(), $x, $y); $obj->setVillage($village); $obj->setData($id, $data); // Triggers! $obj->onBuild(); return $obj; }