Updated config management

Updated install

Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
Gregory PLANCHAT 2011-12-14 23:45:09 +01:00
commit fcd1f5b740
58 changed files with 1579 additions and 1695 deletions

View file

@ -46,6 +46,10 @@ abstract class Wootook_Empire_Model_BuilderAbstract
public function enqueue($params, $index = null)
{
if ($this->_currentUser->getVacation()) {
return $this;
}
$item = $this->_initItem($params);
if ($item === null) {
return $this;

View file

@ -260,6 +260,14 @@ class Wootook_Empire_Model_Planet
return $this;
}
if ($this->getUser()->isVacation()) {
$resourceConfig = Wootook::getGameConfig('resource/base-income');
foreach ($resources->getAllDatas() as $resource => $resourceData) {
$this->setData($resourceData['production_field'], $resourceConfig[$resource]);
}
return $this;
}
/*
* Compute resources consumers and resources producers
*/
@ -952,22 +960,14 @@ class Wootook_Empire_Model_Planet
$key = array_rand($positions, 1);
$finalPosition = $positions[$key];
$config = Wootook_Core_Model_Config::getSingleton();
$planet = new self();
$planet
->setData('id_owner', $user->getId())
->setData('name', Wootook::getRequest()->getParam('planet'))
->setData('galaxy', $systemInfo->getData('galaxy'))
->setData('system', $systemInfo->getData('system'))
->setData('planet', $finalPosition)
->setData('planet_type', 1)
->setData('field_max', $config->getData('initial_fields'))
->setData('field_current', 0)
->setData('metal', 500) // TODO: use config
->setData('cristal', 500) // TODO: use config
;
$planet->save();
$user->createNewPlanet(
$systemInfo->getData('galaxy'),
$systemInfo->getData('system'),
$finalPosition,
Wootook_Empire_Model_Planet::TYPE_PLANET,
Wootook::getRequest()->getParam('planet'),
Wootook::getGameConfig('resource/initial/fields')
);
$user
->setData('id_planet', $planet->getId())
@ -976,13 +976,6 @@ class Wootook_Empire_Model_Planet
->setData('system', $planet->getSystem())
->setData('planet', $planet->getPosition())
;
Wootook::dispatchEvent('planet.init', array(
'planet' => $planet,
'user' => $user
));
$planet->save();
}
}

View file

@ -68,14 +68,13 @@ class Wootook_Empire_Model_Planet_Builder
public function getBuildingTime($buildingId, $level)
{
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
$gameConfig = Wootook_Core_Model_Config::getSingleton();
Math::setPrecision(50);
$firstLevelTime = $prices[$buildingId][Legacies_Empire::BASE_BUILDING_TIME];
$partialLevelTime = Math::mul($firstLevelTime, Math::pow($prices[$buildingId][Legacies_Empire::RESOURCE_MULTIPLIER], $level));
$levelTime = Math::sub($partialLevelTime, $firstLevelTime);
$speedFactor = $gameConfig->getData('game_speed');
$speedFactor = Wootook::getGameConfig('game/speed/general');
$baseTime = $levelTime / $speedFactor * 3600;
Math::setPrecision();

View file

@ -174,6 +174,7 @@ class Wootook_Empire_Model_User
$user->setData('banaday', 0)
->setData('bana', 0)
->setData('urlaubs_modus', 0)
->setData('urlaubs_until', null)
->save()
;
} else {
@ -186,18 +187,25 @@ class Wootook_Empire_Model_User
Wootook::getResponse()->setCookie(self::$_cookieName, array('id' => $login['id'], 'key' => $login['login_rememberme']), self::COOKIE_LIFETIME);
}
self::$_singleton = self::factory($login['id']);
self::$_singleton->_updateActivity();
$session->setData('user_id', intval($login['id']));
return self::$_singleton;
return self::setLoggedIn(self::factory($login['id']));
}
$session->addError('Your username or credential is invalid, please check your input.');
return null;
}
public static function setLoggedIn(self $user)
{
$session = Wootook::getSession(self::SESSION_KEY);
self::$_singleton = $user;
self::$_singleton->_updateActivity();
$session->setData('user_id', intval(self::$_singleton->getId()));
return self::$_singleton;
}
public static function register($username, $email, $password)
{
try {
@ -225,7 +233,7 @@ class Wootook_Empire_Model_User
} catch (Wootook_Core_Exception_DataAccessException $e) {
$session = Wootook_Core_Model_Session::factory(Wootook_Empire_Model_User::SESSION_KEY);
trigger_error($e->getMessage(), E_USER_ERROR);
Wootook_Core_ErrorProfiler::getSingleton()->exceptionManager($e);
$session->addError($e->getMessage());
return null;
}
@ -233,6 +241,44 @@ class Wootook_Empire_Model_User
return $user;
}
public function createNewPlanet($galaxy, $system, $position, $type, $name, $size = null)
{
if ($size === null) {
$baseSize = Wootook::getGameConfig('resource/initial/fields');
$factor = $position * 10 / (1 + log($position * 10));
$fuzz = 2 * $factor * pow(sin($factor), 2) / 2 + $factor / 4;
$size = mt_rand(floor($factor / 10), ceil($factor * 5 / 4)) + mt_rand(0, $fuzz);
}
$planet = new self();
$planet
->setData('id_owner', $user->getId())
->setData('name', $name)
->setData('galaxy', $galaxy)
->setData('system', $system)
->setData('planet', $position)
->setData('planet_type', $type)
->setData('field_max', $size)
->setData('diameter', pow($size, 2) + mt_rand(0, $size * $position))
->setData('field_current', 0)
;
$resourceConfig = Wootook::getGameConfig('resource/initial');
$resourceList = Wootook_Empire_Model_Game_Resources::getSingleton();
foreach ($resourceList as $resource => $resourceData) {
$planet->setData($resourceData['production_field'], $resourceConfig[$resource]);
}
Wootook::dispatchEvent('planet.init', array(
'planet' => $planet,
'user' => $user
));
$planet->save();
}
/**
*
* Enter description here ...
@ -561,4 +607,34 @@ class Wootook_Empire_Model_User
$navigation->addLink('tools/back', 'Go back to the game', 'Go back to the game', 'overview.php', array(), array('admin'));
}
}
public function getVacation()
{
return $this->getData('urlaubs_modus') ? true : false;
}
public function getVacationEndDate()
{
return $this->getData('urlaubs_until');
}
public function setVacation($active = true)
{
$this->setData('urlaubs_modus', $active);
foreach ($this->getPlanetCollection() as $planet) {
$planet->updateResources();
$planet->updateResourceProduction();
$planet->save();
}
if ($active) {
$this->setData('urlaubs_until', time() + Wootook::getConfig('engine/options/vacation-min-time'));
} else {
$this->setData('urlaubs_until', null);
}
$this->save();
return $this;
}
}