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

@ -108,13 +108,12 @@ class Legacies_Empire_Model_Planet_Building_ResearchLab_Builder
{
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
$types = Wootook_Empire_Model_Game_Types::getSingleton();
$gameConfig = Wootook_Core_Model_Config::getSingleton();
Math::setPrecision(50);
// FIXME: Resource dependency
$totalCost = Math::mul(Math::add($prices[$technologyId][Legacies_Empire::RESOURCE_METAL], $prices[$technologyId][Legacies_Empire::RESOURCE_CRISTAL]), $level);
$speedFactor = $gameConfig->getData('game_speed');
$speedFactor = Wootook::getGameConfig('game/speed/general');
// FIXME: Building & Technology dependency
$extraLaboratoriesLevels = 0;

View file

@ -185,12 +185,11 @@ class Legacies_Empire_Model_Planet_Building_Shipyard_Builder
public function getBuildingTime($shipId, $qty)
{
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
$gameConfig = Wootook_Core_Model_Config::getSingleton();
Math::setPrecision(50);
$buildingTime = Math::mul($prices[$shipId][Legacies_Empire::BASE_BUILDING_TIME], $qty);
$speedFactor = $gameConfig->getData('game_speed');
$speedFactor = Wootook::getGameConfig('game/speed/general');
$baseTime = Math::div($buildingTime, $speedFactor);
Math::setPrecision();

View file

@ -130,71 +130,206 @@ SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('config')} (
`config_name` VARCHAR(64) NOT NULL,
`config_value` TEXT NOT NULL,
UNIQUE KEY (`config_name`)
CREATE TABLE IF NOT EXISTS {$this->getTableName('core_website')} (
`website_id` TINYINT UNSIGNED NOT NULL,
`code` VARCHAR(64) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`sort_order` TINYINT UNSIGNED NOT NULL,
`default_group_id` TINYINT UNSIGNED NOT NULL,
`is_default` BOOL NOT NULL,
`is_staging` BOOL NOT NULL,
`is_active` BOOL NOT NULL,
PRIMARY KEY (`webste_id`),
UNIQUE (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
INSERT IGNORE INTO {$this->getTableName('config')} (`config_name`, `config_value`) VALUES
-- ('game/1/resource/income/base/metal', '20'),
-- ('game/1/resource/income/base/cristal', '10'),
-- ('game/1/resource/income/base/deuterium', '0'),
-- ('game/1/resource/income/base/energy', '0'),
-- ('game/1/resource/multiplier', '1000'),
CREATE TABLE IF NOT EXISTS {$this->getTableName('core_game_group')} (
`group_id` TINYINT UNSIGNED NOT NULL,
`website_id` TINYINT UNSIGNED NOT NULL,
`code` VARCHAR(64) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`sort_order` TINYINT UNSIGNED NOT NULL,
`is_default` BOOL NOT NULL,
PRIMARY KEY (`group_id`),
INDEX (`webste_id`),
UNIQUE (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
-- ('game/1/speed/general', '2500'),
-- ('game/1/speed/fleet', '2500'),
$this->query($sql);
('game_speed', '2500'),
('fleet_speed', '2500'),
('resource_multiplier', '1000'),
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('core_game')} (
`game_id` SMALLINT UNSIGNED NOT NULL,
`group_id` TINYINT UNSIGNED NOT NULL,
`website_id` TINYINT UNSIGNED NOT NULL,
`code` VARCHAR(64) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`sort_order` TINYINT UNSIGNED NOT NULL,
`is_default` BOOL NOT NULL,
`is_staging` BOOL NOT NULL,
`is_active` BOOL NOT NULL,
PRIMARY KEY (`group_id`),
INDEX (`webste_id`),
UNIQUE (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
('metal_basic_income', '20'),
('cristal_basic_income', '10'),
('deuterium_basic_income', '0'),
('energy_basic_income', '0'),
$this->query($sql);
('Fleet_Cdr', '30'),
('Defs_Cdr', '30'),
('initial_fields', '5000'),
('COOKIE_NAME', 'wootook'),
('game_name', 'Wootook'),
('game_disable', '1'),
('close_reason', 'Le jeu est clos pour le moment!'),
('BuildLabWhileRun', '0'),
('urlaubs_modus_erz', '1'),
('noobprotection', '1'),
('noobprotectiontime', '5000'),
('noobprotectionmulti', '5'),
('forum_url', 'http://board.xnova-ng.org/'),
('OverviewNewsFrame', '1'),
('OverviewNewsTEXT', 'Bienvenue sur le nouveau serveur Wootook'),
('OverviewExternChat', '0'),
('OverviewExternChatCmd', ''),
('OverviewBanner', '0'),
('OverviewClickBanner', ''),
('ExtCopyFrame', '0'),
('ExtCopyOwner', ''),
('ExtCopyFunct', ''),
('ForumBannerFrame', '0'),
('stat_settings', '1000'),
('link_enable', '0'),
('link_name', ''),
('link_url', ''),
('enable_announces', '1'),
('enable_marchand', '1'),
('enable_notes', '1'),
('bot_name', 'XNoviana Reali'),
('bot_adress', 'contact@wootook.org'),
('banner_source_post', '../images/bann.png'),
('ban_duration', '30'),
('enable_bot', '0'),
('enable_bbcode', '1');
$sql = <<<SQL_EOF
INSERT INTO {$this->getTableName('core_website')} (`website_id`, `code`, `name`, `sort_order`, `default_group_id`, `is_default`, `is_staging`, `is_active`)
VALUES
(0, "admin", "Administration", 0, 0, 0, 0, 1),
(1, "default", "Default Website", 1, 1, 1, 0, 1);
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
INSERT INTO {$this->getTableName('core_game_group')} (`group_id`, `website_id`, `code`, `name`, `sort_order`, `is_default`)
VALUES
(0, 0, "admin", "Administration", 0, 0),
(1, 1, "default", "Default Group", 1, 1);
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
INSERT INTO {$this->getTableName('core_game')} (`game_id`, `group_id`, `website_id`, `code`, `name`, `sort_order`, `is_default`, `is_staging`, `is_active`)
VALUES
(0, 0, 0, "admin", "Administration", 0, 0, 0, 1),
(1, 1, 1, "default", "Default Game", 1, 1, 0, 1);
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('core_config')} (
`website_id` TINYINT UNSIGNED NOT NULL,
`game_id` TINYINT UNSIGNED NOT NULL,
`config_path` VARCHAR(64) NOT NULL,
`config_value` VARCHAR(255) NOT NULL,
PRIMARY KEY (`website_id`, `game_id`, `config_path`),
INDEX (`website_id`),
INDEX (`game_id`),
INDEX (`config_path`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
INSERT IGNORE INTO {$this->getTableName('core_config')} (`webste_id`, `game_id`, `config_path`, `config_value`) VALUES
(1, 1, 'resource/base-income/metal', '20'),
(1, 1, 'resource/base-income/cristal', '10'),
(1, 1, 'resource/base-income/deuterium', '0'),
(1, 1, 'resource/base-income/energy', '0'),
(1, 1, 'resource/initial/fields', '163'),
(1, 1, 'resource/initial/metal', '500'),
(1, 1, 'resource/initial/cristal', '500'),
(1, 1, 'resource/initial/deuterium', '0'),
(1, 1, 'resource/initial/energy', '0'),
(1, 1, 'game/general/name', 'Wootook'),
(1, 1, 'game/general/boards-url', 'http://wootook.org/board/'),
(1, 1, 'game/general/extra-url-title', 'Wootook!'),
(1, 1, 'game/general/extra-url', 'http://wootook.org/'),
(1, 1, 'game/general/active', '1'),
(1, 1, 'game/general/closing-message', 'Le jeu est clos pour le moment.'),
(1, 1, 'game/general/locale', 'fr_FR'),
(1, 1, 'game/resource/multiplier', '1000'),
(1, 1, 'game/speed/general', '2500'),
(1, 1, 'game/speed/fleet', '2500'),
(1, 1, 'game/debris/metal-percent', '30'),
(1, 1, 'game/debris/cristal-percent', '30'),
(1, 1, 'game/debris/deuterium-percent', '0'),
(1, 1, 'game/debris/energy-percent', '0'),
(1, 1, 'game/debris/fleet', '1'),
(1, 1, 'game/debris/defense', '0'),
(1, 1, 'game/noob-protection/active', '0'),
(1, 1, 'game/noob-protection/points-cap', '5000'),
(1, 1, 'game/noob-protection/multiplier', '5'),
(0, 0, 'web/cookie/name', '__wtk'),
(0, 0, 'web/cookie/time', '2592000'),
(0, 0, 'web/cookie/domain', ''),
(0, 0, 'web/cookie/path', ''),
(0, 0, 'engine/options/bbcode', '1'),
(0, 0, 'engine/options/ga', '1'),
(0, 0, 'engine/options/announces', '0'),
(0, 0, 'engine/options/retailer', '0'),
(0, 0, 'engine/options/notes', '0'),
(0, 0, 'engine/options/chat', '0'),
(0, 0, 'engine/options/banner', '0'),
(0, 0, 'engine/options/vacation-min-time', '172800'),
(0, 0, 'game/news/active', '0'),
(0, 0, 'game/news/content', 'Bienvenue sur le nouveau serveur de jeu Wootook!'),
(0, 0, 'engine/ban/duration', '86400'),
(0, 0, 'engine/bot/active', '0'),
(0, 0, 'engine/bot/name', 'Woot'),
(0, 0, 'engine/bot/email', 'contact@wootook.org'),
--------------------------------------------------------------------------------
-- (0, 0, 'game_speed', '2500'),
-- (0, 0, 'fleet_speed', '2500'),
-- (0, 0, 'resource_multiplier', '1000'),
-- (0, 0, 'metal_basic_income', '20'),
-- (0, 0, 'cristal_basic_income', '10'),
-- (0, 0, 'deuterium_basic_income', '0'),
-- (0, 0, 'energy_basic_income', '0'),
-- (0, 0, 'Fleet_Cdr', '30'),
-- (0, 0, 'Defs_Cdr', '30'),
-- (0, 0, 'initial_fields', '5000'),
-- (0, 0, 'COOKIE_NAME', 'wootook'),
-- (0, 0, 'game_name', 'Wootook'),
-- (0, 0, 'game_disable', '1'),
-- (0, 0, 'close_reason', 'Le jeu est clos pour le moment.'),
(0, 0, 'BuildLabWhileRun', '0'),
-- (0, 0, 'urlaubs_modus_erz', '1'),
-- (0, 0, 'noobprotection', '1'),
-- (0, 0, 'noobprotectiontime', '5000'),
-- (0, 0, 'noobprotectionmulti', '5'),
-- (0, 0, 'forum_url', 'http://wootook.org/board/'),
-- (0, 0, 'OverviewNewsFrame', '1'),
-- (0, 0, 'OverviewNewsTEXT', 'Bienvenue sur le nouveau serveur Wootook'),
-- (0, 0, 'OverviewExternChat', '0'),
-- (0, 0, 'OverviewExternChatCmd', ''),
-- (0, 0, 'OverviewBanner', '0'),
-- (0, 0, 'OverviewClickBanner', ''),
(0, 0, 'ExtCopyFrame', '0'),
(0, 0, 'ExtCopyOwner', ''),
(0, 0, 'ExtCopyFunct', ''),
-- (0, 0, 'ForumBannerFrame', '0'),
-- (0, 0, 'stat_settings', '1000'),
-- (0, 0, 'link_enable', '0'),
-- (0, 0, 'link_name', ''),
-- (0, 0, 'link_url', ''),
-- (0, 0, 'enable_announces', '1'),
-- (0, 0, 'enable_marchand', '1'),
-- (0, 0, 'enable_notes', '1'),
-- (0, 0, 'bot_name', 'Isaac'),
-- (0, 0, 'bot_adress', 'contact@wootook.org'),
-- (0, 0, 'banner_source_post', '../images/bann.png'),
-- (0, 0, 'ban_duration', '30'),
-- (0, 0, 'enable_bot', '0'),
-- (0, 0, 'enable_bbcode', '1');
SQL_EOF;
$this->query($sql);
@ -259,7 +394,7 @@ $this->query($sql);
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('galaxy')} (
`galaxy` TINYINT UNSIGNED NOT NULL,
`galaxy` SMALLINT UNSIGNED NOT NULL,
`system` SMALLINT UNSIGNED NOT NULL,
`planet` TINYINT UNSIGNED NOT NULL,
`id_planet` BIGINT UNSIGNED NOT NULL,
@ -617,3 +752,320 @@ SQL_EOF;
$this->query($sql);
/*
* Galaxy positions generation
*/
$galaxyCount = Wootook::getConfig('default/engine/universe/galaxies');
$systemCount = Wootook::getConfig('default/engine/universe/systems');
$sql = <<<SQL_EOF
INSERT INTO {$this->getTableName('galaxy')}
(`galaxy`, `system`, `planet`, `id_planet`, `metal`, `crystal`, `id_luna`, `luna`)
SELECT
_increment.galaxy AS `galaxy`,
_increment.system AS `system`,
0 AS `planet`,
0 AS `id_planet`,
0 AS `metal`,
0 AS `crystal`,
0 AS `id_luna`,
0 AS `luna`
FROM (
SELECT
(1 + _galaxy_10e0.galaxy + _galaxy_10e1.galaxy + _galaxy_10e2.galaxy + _galaxy_10e3.galaxy + _galaxy_10e4.galaxy) AS galaxy,
(1 + _system_10e0.system + _system_10e1.system + _system_10e2.system + _system_10e3.system + _system_10e4.system) AS system
FROM (
SELECT 0 AS system
UNION ALL
SELECT 1 AS system
UNION ALL
SELECT 2 AS system
UNION ALL
SELECT 3 AS system
UNION ALL
SELECT 4 AS system
UNION ALL
SELECT 5 AS system
UNION ALL
SELECT 6 AS system
UNION ALL
SELECT 7 AS system
UNION ALL
SELECT 8 AS system
UNION ALL
SELECT 9 AS system
) AS _system_10e0
SQL_EOF;
if ($systemCount > 10) {
$sql .= <<<SQL_EOF
CROSS JOIN (
SELECT 0 AS system
UNION ALL
SELECT 10 AS system
UNION ALL
SELECT 20 AS system
UNION ALL
SELECT 30 AS system
UNION ALL
SELECT 40 AS system
UNION ALL
SELECT 50 AS system
UNION ALL
SELECT 60 AS system
UNION ALL
SELECT 70 AS system
UNION ALL
SELECT 80 AS system
UNION ALL
SELECT 90 AS system
) AS _system_10e1
SQL_EOF;
} else {
$sql .= <<<SQL_EOF
CROSS JOIN (SELECT 0 AS system) AS _system_10e1
SQL_EOF;
}
if ($systemCount > 100) {
$sql .= <<<SQL_EOF
CROSS JOIN (
SELECT 0 AS system
UNION ALL
SELECT 100 AS system
UNION ALL
SELECT 200 AS system
UNION ALL
SELECT 300 AS system
UNION ALL
SELECT 400 AS system
UNION ALL
SELECT 500 AS system
UNION ALL
SELECT 600 AS system
UNION ALL
SELECT 700 AS system
UNION ALL
SELECT 800 AS system
UNION ALL
SELECT 900 AS system
) AS _system_10e2
SQL_EOF;
} else {
$sql .= <<<SQL_EOF
CROSS JOIN (SELECT 0 AS system) AS _system_10e2
SQL_EOF;
}
if ($systemCount > 1000) {
$sql .= <<<SQL_EOF
CROSS JOIN (
SELECT 0 AS system
UNION ALL
SELECT 1000 AS system
UNION ALL
SELECT 2000 AS system
UNION ALL
SELECT 3000 AS system
UNION ALL
SELECT 4000 AS system
UNION ALL
SELECT 5000 AS system
UNION ALL
SELECT 6000 AS system
UNION ALL
SELECT 7000 AS system
UNION ALL
SELECT 8000 AS system
UNION ALL
SELECT 9000 AS system
) AS _system_10e3
SQL_EOF;
} else {
$sql .= <<<SQL_EOF
CROSS JOIN (SELECT 0 AS system) AS _system_10e3
SQL_EOF;
}
if ($systemCount > 10000) {
$sql .= <<<SQL_EOF
CROSS JOIN (
SELECT 0 AS system
UNION ALL
SELECT 10000 AS system
UNION ALL
SELECT 20000 AS system
UNION ALL
SELECT 30000 AS system
UNION ALL
SELECT 40000 AS system
UNION ALL
SELECT 50000 AS system
UNION ALL
SELECT 60000 AS system
UNION ALL
SELECT 70000 AS system
UNION ALL
SELECT 80000 AS system
UNION ALL
SELECT 90000 AS system
) AS _system_10e4
SQL_EOF;
} else {
$sql .= <<<SQL_EOF
CROSS JOIN (SELECT 0 AS system) AS _system_10e4
SQL_EOF;
}
$sql .= <<<SQL_EOF
CROSS JOIN (
SELECT 0 AS galaxy
UNION ALL
SELECT 1 AS galaxy
UNION ALL
SELECT 2 AS galaxy
UNION ALL
SELECT 3 AS galaxy
UNION ALL
SELECT 4 AS galaxy
UNION ALL
SELECT 5 AS galaxy
UNION ALL
SELECT 6 AS galaxy
UNION ALL
SELECT 7 AS galaxy
UNION ALL
SELECT 8 AS galaxy
UNION ALL
SELECT 9 AS galaxy
) AS _galaxy_10e0
SQL_EOF;
if ($systemCount > 10) {
$sql .= <<<SQL_EOF
CROSS JOIN (
SELECT 0 AS galaxy
UNION ALL
SELECT 10 AS galaxy
UNION ALL
SELECT 20 AS galaxy
UNION ALL
SELECT 30 AS galaxy
UNION ALL
SELECT 40 AS galaxy
UNION ALL
SELECT 50 AS galaxy
UNION ALL
SELECT 60 AS galaxy
UNION ALL
SELECT 70 AS galaxy
UNION ALL
SELECT 80 AS galaxy
UNION ALL
SELECT 90 AS galaxy
) AS _galaxy_10e1
SQL_EOF;
} else {
$sql .= <<<SQL_EOF
CROSS JOIN (SELECT 0 AS galaxy) AS _galaxy_10e1
SQL_EOF;
}
if ($systemCount > 100) {
$sql .= <<<SQL_EOF
CROSS JOIN (
SELECT 0 AS galaxy
UNION ALL
SELECT 100 AS galaxy
UNION ALL
SELECT 200 AS galaxy
UNION ALL
SELECT 300 AS galaxy
UNION ALL
SELECT 400 AS galaxy
UNION ALL
SELECT 500 AS galaxy
UNION ALL
SELECT 600 AS galaxy
UNION ALL
SELECT 700 AS galaxy
UNION ALL
SELECT 800 AS galaxy
UNION ALL
SELECT 900 AS galaxy
) AS _galaxy_10e2
SQL_EOF;
} else {
$sql .= <<<SQL_EOF
CROSS JOIN (SELECT 0 AS galaxy) AS _galaxy_10e2
SQL_EOF;
}
if ($systemCount > 1000) {
$sql .= <<<SQL_EOF
CROSS JOIN (
SELECT 0 AS galaxy
UNION ALL
SELECT 1000 AS galaxy
UNION ALL
SELECT 2000 AS galaxy
UNION ALL
SELECT 3000 AS galaxy
UNION ALL
SELECT 4000 AS galaxy
UNION ALL
SELECT 5000 AS galaxy
UNION ALL
SELECT 6000 AS galaxy
UNION ALL
SELECT 7000 AS galaxy
UNION ALL
SELECT 8000 AS galaxy
UNION ALL
SELECT 9000 AS galaxy
) AS _galaxy_10e3
SQL_EOF;
} else {
$sql .= <<<SQL_EOF
CROSS JOIN (SELECT 0 AS galaxy) AS _galaxy_10e3
SQL_EOF;
}
if ($systemCount > 10000) {
$sql .= <<<SQL_EOF
CROSS JOIN (
SELECT 0 AS galaxy
UNION ALL
SELECT 10000 AS galaxy
UNION ALL
SELECT 20000 AS galaxy
UNION ALL
SELECT 30000 AS galaxy
UNION ALL
SELECT 40000 AS galaxy
UNION ALL
SELECT 50000 AS galaxy
UNION ALL
SELECT 60000 AS galaxy
UNION ALL
SELECT 70000 AS galaxy
UNION ALL
SELECT 80000 AS galaxy
UNION ALL
SELECT 90000 AS galaxy
) AS _galaxy_10e4
SQL_EOF;
} else {
$sql .= <<<SQL_EOF
CROSS JOIN (SELECT 0 AS galaxy) AS _galaxy_10e4
SQL_EOF;
}
$sql .= <<<SQL_EOF
) _increment
WHERE _increment.galaxy<={$galaxyCount}
AND _increment.system<={$systemCount}
SQL_EOF;
$this->query($sql);

View file

@ -81,10 +81,31 @@ class Wootook
/**
*
* Enter description here ...
* @var array
* @var Wootook_Core_Config_Adapter_Abstract
*/
protected static $_config = null;
/**
*
* Enter description here ...
* @var Wootook_Core_Config_Adapter_Abstract
*/
protected static $_globalConfig = null;
/**
*
* Enter description here ...
* @var array
*/
protected static $_websiteConfigs = array();
/**
*
* Enter description here ...
* @var array
*/
protected static $_gameConfigs = array();
/**
* Registers an event listener to be called later in the application.
*
@ -179,7 +200,7 @@ class Wootook
public static function getLocale()
{
$availableLocales = self::getConfig('global/locales');
$availableLocales = self::$_config->getConfig('global/locales');
return self::getPreferredLocale($availableLocales);
}
@ -287,68 +308,172 @@ class Wootook
self::$_response = $response;
}
public static function loadConfig()
public static function loadConfig($filename = null)
{
self::$_config = include ROOT_PATH . DIRECTORY_SEPARATOR . 'config.php';
if (!is_array(self::$_config)) {
self::$_config = array();
if ($filename === null) {
$filename = ROOT_PATH . DIRECTORY_SEPARATOR . 'config.php';
}
self::$_config = new Wootook_Core_Config_Adapter_Array($filename);
self::$_globalConfig = clone self::$_config['default'];
self::$_globalConfig->merge(self::$_config['global']);
self::_appendDatabaseConfig(self::$_globalConfig);
self::$_websiteConfigs = array();
self::$_gameConfigs = array();
return self::$_config;
}
protected static function _appendDatabaseConfig(Wootook_Core_Config_Node $config, $type = 'global', $id = 0)
{
$collection = new Wootook_Core_Collection('core_config', 'Wootook_Core_Model_Config');
switch ($type) {
case 'website':
$collection->where('website_id = :website_id');
$collection->load(array('website_id' => $id));
break;
case 'game':
$collection->where('game_id = :game_id');
$collection->load(array('game_id' => $id));
break;
default:
$collection->where('website_id = 0');
$collection->where('game_id = 0');
$collection->load(array());
break;
}
foreach ($collection as $row) {
$config->setConfig($row->getData('config_path'), $row->getData('config_value'));
}
return $config;
}
protected static function _initWebsiteConfig($websiteId)
{
if (self::$_config === null) {
self::loadConfig();
}
$websiteId = 1;
if (!isset(self::$_websiteConfigs[$websiteId])) {
self::$_websiteConfigs[$websiteId] = clone self::$_globalConfig;
$websiteConfig = self::$_config->getConfig("website/{$websiteId}");
if ($websiteConfig !== null) {
self::$_websiteConfigs[$websiteId]->merge($websiteConfig);
}
self::_appendDatabaseConfig(self::$_websiteConfigs[$websiteId], 'website', $websiteId);
}
return self::$_websiteConfigs[$websiteId];
}
protected static function _initGameConfig($gameId)
{
if (self::$_config === null) {
self::loadConfig();
}
$websiteId = 1;
$gameId = 1;
if (!isset(self::$_gameConfigs[$gameId])) {
self::_initWebsiteConfig($websiteId);
self::$_gameConfigs[$gameId] = clone self::$_websiteConfigs[$websiteId];
$gameConfig = self::$_config->getConfig("game/{$gameId}");
if ($gameConfig !== null) {
self::$_gameConfigs[$gameId]->merge($gameConfig);
}
self::_appendDatabaseConfig(self::$_gameConfigs[$gameId], 'game', $gameId);
}
return self::$_gameConfigs[$gameId];
}
public static function getConfig($path = null)
{
if (self::$_config === null) {
self::loadConfig();
}
if ($path === null || !is_string($path)) {
return self::$_config;
if ($path !== null) {
return self::$_globalConfig->getConfig($path);
}
$config = self::$_config;
foreach (explode('/', $path) as $chunk) {
if (!isset($config[$chunk])) {
return null;
}
$config = $config[$chunk];
}
return $config;
return self::$_globalConfig;
}
public static function setConfig($path, $value)
public static function getWebsiteConfig($path = null, $websiteId = null)
{
if (self::$_config === null) {
self::loadConfig();
}
if ($path === null || !is_string($path)) {
return self::$_config = $value;
$websiteId = 1;
self::_initWebsiteConfig($websiteId);
if ($path !== null) {
return self::$_websiteConfigs[$websiteId]->getConfig($path);
}
$config = &self::$_config;
foreach (explode('/', $path) as $chunk) {
if (!isset($config[$chunk])) {
$config[$chunk] = array();
return self::$_websiteConfigs[$websiteId];
}
public static function getGameConfig($path = null, $gameId = null)
{
if (self::$_config === null) {
self::loadConfig();
}
$gameId = 1;
self::_initGameConfig($gameId);
if ($path !== null) {
return self::$_gameConfigs[$gameId]->getConfig($path);
}
return self::$_gameConfigs[$gameId];
}
public static function setConfig($path, $value, $websiteId = null, $gameId = null)
{
if (self::$_config === null) {
self::loadConfig();
}
$updater = new Wootook_Core_Model_Config();
$updater->setPath($path)->setValue($value);
if ($websiteId !== null) {
$updater->setWebsiteId($websiteId);
if ($gameId !== null) {
$updater->setGameId($gameId);
self::$_gameConfigs[$gameId]->setConfig($path, $value);
} else {
self::$_websiteConfigs[$websiteId]->setConfig($path, $value);
}
$config = &$config[$chunk];
} else {
self::$_globalConfig->setConfig($path, $value);
}
$config = $value;
$updater->save();
return true;
}
public static function writeConfig(Array $config)
{
file_put_contents(ROOT_PATH . DIRECTORY_SEPARATOR . 'config.php',
'<' . '?p' . 'hp ' . var_export($config, true) . ';');
self::$_config = $config;
}
public static function getBaseUrl()
{
return self::getConfig('global/web/base_url');
return self::$_config->getConfig('global/web/base_url');
}
public static function getSkinUrl($package, $theme, $uri, Array $params = array())

View file

@ -14,10 +14,14 @@ class Wootook_Core_Block_Messages
{
$messages = array();
var_dump($this->_storages);
foreach ($this->_storages as $namespace) {
$session = Wootook::getSession($namespace);
var_dump($session);
foreach ($session->getMessages() as $messageLevel => $messageList) {
var_dump(array($messageLevel => $messageList));
foreach ($session->getData('messages') as $messageLevel => $messageList) {
if (!isset($messages[$messageLevel])) {
$messages[$messageLevel] = $messageList;
} else {

View file

@ -1,7 +1,7 @@
<?php
class Wootook_Core_Collection
extends Wootook_Core_Model
extends Wootook_Core_Database_Resource
implements Iterator, Countable
{
protected $_tableName = null;
@ -254,7 +254,7 @@ SQL_EOF;
{
$sql = $this->_prepareSql();
$database = Wootook_Database::getSingleton();
$database = $this->getReadConnection();
$statement = $database->prepare($sql);
$args = func_get_args();

View file

@ -0,0 +1,6 @@
<?php
abstract class Wootook_Core_Config_Adapter_Abstract
extends Wootook_Core_Config_Node
{
}

View file

@ -0,0 +1,33 @@
<?php
class Wootook_Core_Config_Adapter_Array
extends Wootook_Core_Config_Adapter_Abstract
{
public function __construct($filename = null)
{
if ($filename !== null) {
$this->load($filename);
}
}
public function load($filename)
{
$data = include $filename;
if (!is_array($data)) {
throw new Wootook_Core_Exception_DataAccessException(
Wootook::__('Configuration file could not be loaded.'));
}
$this->_init($data);
return $this;
}
public function save($filename)
{
file_put_contents($filename, '<' . '?p' . 'hp return ' . var_export($this->toArray(), true) . ';');
return $this;
}
}

View file

@ -0,0 +1,204 @@
<?php
class Wootook_Core_Config_Node
implements ArrayAccess
{
protected $_children = array();
protected $_parent = null;
protected static $_attributeNameCache = array();
public function __construct(Array $data = array(), $parent = null)
{
$this->_init($data, $parent);
}
public function setData(Array $data = array())
{
$this->_init($data);
return $this;
}
protected function _init(Array $data, $parent = null)
{
if ($parent !== null) {
$this->_parent = $parent;
}
$this->_children = array();
foreach ($data as $key => $value) {
if (is_array($value)) {
$this->offsetSet($key, new self($value, $this));
} else {
$this->offsetSet($key, $value);
}
}
return $this;
}
public function setConfig($path, $value)
{
$explodedPath = explode('/', $path);
$length = count($explodedPath);
$currentNode = $this;
for ($i = 0; $i < $length; $i++) {
if (!$currentNode->offsetExists($explodedPath[$i])) {
$newNode = new Wootook_Core_Config_Node(array(), $currentNode);
$currentNode->offsetSet($explodedPath[$i], $newNode);
}
$currentNode = $currentNode->offsetGet($explodedPath[$i]);
if ($i >= ($length - 1)) {
if (is_array($value)) {
$currentNode->offsetSet($explodedPath[$i], new self($value, $this));
} else {
$currentNode->offsetSet($explodedPath[$i], $value);
}
break;
} else if (!$currentNode instanceof Wootook_Core_Config_Node) {
throw new Wootook_Core_Exception_RuntimeException();
}
}
return $this;
}
public function getConfig($path)
{
$explodedPath = explode('/', $path);
$length = count($explodedPath);
$currentNode = $this;
for ($i = 0; $i < $length; $i++) {
if (!$currentNode instanceof Wootook_Core_Config_Node) {
throw new Wootook_Core_Exception_RuntimeException();
}
if (!$currentNode->offsetExists($explodedPath[$i])) {
return null;
}
$currentNode = $currentNode->offsetGet($explodedPath[$i]);
}
return $currentNode;
}
public function toArray()
{
$result = array();
foreach ($this->_children as $key => $child) {
if ($child instanceof self) {
$result[$key] = $child->toArray();
} else if ($child instanceof Wootook_Core_Config_Leaf) {
$result[$key] = $child->getValue();
} else {
$result[$key] = $child;
}
}
return $result;
}
public function reset()
{
$this->_children = array();
$this->_parent = null;
return $this;
}
public function merge(self $node)
{
foreach ($node->_children as $offset => $value) {
if ($value instanceof self) {
if (!$this->offsetExists($offset)) {
$this->offsetSet($offset, new self(array(), $this));
}
$this->offsetGet($offset)->merge($value);
} else {
$this->offsetSet($offset, $value);
}
}
return $this;
}
private function _resolveAttributeName($key)
{
if (!isset(self::$_attributeNameCache[$key])) {
self::$_attributeNameCache[$key] = str_replace(' ', '-', strtolower(preg_replace('#[A-Z]#', ' \\1', $key)));
}
return self::$_attributeNameCache[$key];
}
public function __get($offset)
{
return $this->offsetGet($this->_resolveAttributeName($offset));
}
public function __set($offset, $value)
{
return $this->offsetSet($this->_resolveAttributeName($offset), $value);
}
public function __isset($offset)
{
return $this->offsetExists($this->_resolveAttributeName($offset));
}
public function __unset($offset)
{
return $this->offsetUnset($this->_resolveAttributeName($offset));
}
public function __clone()
{
$clone = new self();
foreach ($this->_children as $childName => $childNode) {
if ($childNode instanceof self) {
$childNode = clone $childNode;
$childNode->_parent = $clone;
}
$clone->offsetSet($childName, $childNode);
}
return $clone;
}
public function offsetGet($offset)
{
if ($this->offsetExists($offset)) {
return $this->_children[$offset];
}
return null;
}
public function offsetSet($offset, $value)
{
$this->_children[$offset] = $value;
return $value;
}
public function offsetExists($offset)
{
if (isset($this->_children[$offset])) {
return true;
}
return false;
}
public function offsetUnset($offset)
{
if ($this->offsetExists($offset)) {
unset($this->_children[$offset]);
}
}
}

View file

@ -0,0 +1,67 @@
<?php
abstract class Wootook_Core_Database_Resource
extends Wootook_Core_Model
{
protected $_readConnection = null;
protected $_writeConnection = null;
protected $_tableName = null;
public function setTableName($tableName)
{
$this->_tableName = $tableName;
return $this;
}
public function getTableName()
{
return $this->_tableName;
}
public function getReadConnection()
{
if ($this->_readConnection === null) {
$this->_readConnection = Wootook_Database::getConnection('core_read');
}
return $this->_readConnection;
}
public function setReadConnection($connection)
{
if ($connection instanceof Wootook_Database) {
$this->_readConnection = $connection;
} else if (is_string($connection)) {
$this->_readConnection = Wootook_Database::getConnection($connection);
} else {
throw new Wootook_Core_Exception_RuntimeException(
'First parameter should be either a database connection object or a string identifier.');
}
return $this;
}
public function getWriteConnection()
{
if ($this->_writeConnection === null) {
$this->_writeConnection = Wootook_Database::getConnection('core_write');
}
return $this->_writeConnection;
}
public function setWriteConnection($connection)
{
if ($connection instanceof Wootook_Database) {
$this->_readConnection = $connection;
} else if (is_string($connection)) {
$this->_readConnection = Wootook_Database::getConnection($connection);
} else {
throw new Wootook_Core_Exception_RuntimeException(
'First parameter should be either a database connection object or a string identifier.');
}
return $this;
}
}

View file

@ -1,11 +1,10 @@
<?php
abstract class Wootook_Core_Entity
extends Wootook_Core_Model
extends Wootook_Core_Database_Resource
implements Wootook_Core_EntityInterface
{
protected $_idFieldName = null;
protected $_tableName = null;
public function setIdFieldName($fieldName)
{
@ -19,18 +18,6 @@ abstract class Wootook_Core_Entity
return $this->_idFieldName;
}
public function setTableName($tableName)
{
$this->_tableName = $tableName;
return $this;
}
public function getTableName()
{
return $this->_tableName;
}
public function setId($id)
{
$this->setData($this->getIdFieldName(), $id);
@ -48,10 +35,10 @@ abstract class Wootook_Core_Entity
$id = func_get_arg(0);
$idFieldName = self::getIdFieldName();
$database = Wootook_Database::getSingleton();
$database = $this->getReadConnection();
$sql =<<<SQL_EOF
SELECT * FROM {$database->getTable(self::getTableName())}
SELECT * FROM {$database->getTable($this->getTableName())}
WHERE {$idFieldName}=:id
LIMIT 1
SQL_EOF;
@ -89,9 +76,9 @@ SQL_EOF;
$idFieldName = self::getIdFieldName();
$values[$idFieldName] = $this->getId();
$database = Wootook_Database::getSingleton();
$database = $this->getWriteConnection();
$sql =<<<SQL_EOF
UPDATE {$database->getTable(self::getTableName())}
UPDATE {$database->getTable($this->getTableName())}
SET {$fieldsImploded}
WHERE {$idFieldName}=:{$idFieldName}
SQL_EOF;
@ -113,9 +100,9 @@ SQL_EOF;
}
$tokensImploded = implode(', ', $tokens);
$database = Wootook_Database::getSingleton();
$database = $this->getWriteConnection();
$sql =<<<SQL_EOF
INSERT INTO {$database->getTable(self::getTableName())} ($fieldsImploded)
INSERT INTO {$database->getTable($this->getTableName())} ($fieldsImploded)
VALUES ({$tokensImploded})
SQL_EOF;
$statement = $database->prepare($sql);
@ -140,9 +127,9 @@ SQL_EOF;
$fieldsImploded = implod(', ', $fields);
$idFieldName = self::getIdFieldName();
$database = Wootook_Database::getSingleton();
$database = $this->getWriteConnection();
$sql =<<<SQL_EOF
DELETE {$database->getTable(self::getTableName())}
DELETE {$database->getTable($this->getTableName())}
WHERE {$idFieldName}=:{$idFieldName}
SQL_EOF;

View file

@ -7,10 +7,9 @@
* @uses Wootook_Empire_Model_User
*/
abstract class Wootook_Core_Entity_SubTable
extends Wootook_Core_Model
extends Wootook_Core_Database_Resource
{
private $_isLoaded = false;
protected $_tableName = null;
protected $_idFieldNames = array();
protected $_eventPrefix = 'entity.sub-table';
@ -118,16 +117,4 @@ SQL_EOF;
return $this;
}
public function setTableName($tableName)
{
$this->_tableName = $tableName;
return $this;
}
public function getTableName()
{
return $this->_tableName;
}
}

View file

@ -16,6 +16,10 @@ class Wootook_Core_ErrorProfiler
private $_mute = false;
/**
*
* @return Wootook_Core_ErrorProfiler
*/
public static function getSingleton()
{
if (self::$_singleton === null) {

View file

@ -8,81 +8,56 @@
* @uses Legacies_Empire
*/
class Wootook_Core_Model_Config
extends Wootook_Core_Model
implements Wootook_Core_Singleton
extends Wootook_Core_Entity_SubTable
{
private static $_singleton = null;
protected $_eventPrefix = 'core.config';
protected $_eventObject = 'config';
public static function getSingleton()
{
if (self::$_singleton === null) {
self::$_singleton = new self();
}
return self::$_singleton;
}
protected function _init()
{
$this->load();
$this->_tableName = 'core_config';
$this->_idFieldNames = array('config_path', 'website_id', 'game_id');
}
protected function _load()
public function setWebsiteId($websiteId)
{
$database = Wootook_Database::getSingleton();
$sql =<<<SQL_EOF
SELECT config_name AS attribute, config_value AS value
FROM {$database->getTable('config')} AS config
SQL_EOF;
$attributeName = null;
$attributeValue = null;
$statement = $database->prepare($sql);
$statement->execute();
$statement->bindColumn('attribute', $attributeName, PDO::PARAM_STR);
$statement->bindColumn('value', $attributeValue, PDO::PARAM_STR);
while ($statement->fetch(PDO::FETCH_BOUND)) {
$this->setData($attributeName, $attributeValue);
}
return $this;
return $this->setData('website_id', $websiteId);
}
protected function _save()
public function getWebsiteId()
{
$database = Wootook_Database::getSingleton();
$fields = array();
$sql =<<<SQL_EOF
UPDATE {{table}}
SET config_value=:value
WHERE config_name=:name
SQL_EOF;
$statement = $database->prepare($sql);
foreach ($this->getAllDatas() as $attributeName => $attributeValue) {
$statement->execute(array(
'name' => $attributeName,
'value' => $attributeValue
));
}
return $this;
return $this->getData('website_id');
}
protected function _delete()
public function setGameId($gameId)
{
// NOP
return $this;
return $this->setData('game_id', $gameId);
}
public function isEnabled()
public function getGameId()
{
return (bool) $this->getData('game_disable');
return $this->getData('game_id');
}
public function setPath($path)
{
return $this->setData('config_path', $path);
}
public function getPath()
{
return $this->getData('config_path');
}
public function setValue($value)
{
return $this->setData('config_value', $value);
}
public function getValue()
{
return $this->getData('config_value');
}
}

View file

@ -58,7 +58,8 @@ class Wootook_Core_Model_Session
{
$messages = $this->_data['messages'];
if ($clear == true) {
$this->_data['messages'] = array();
var_dump($this->_data['messages']);
//$this->_data['messages'] = array();
}
return $messages;
}

View file

@ -33,8 +33,10 @@ class Wootook_Database
return self::$_connectionAliases[$connectionName];
}
if ($alias = Wootook::getConfig("global/database/{$connectionName}/use")) {
if ($alias = Wootook::getConfig("database/{$connectionName}/use")) {
self::$_connectionAliases[$connectionName] = self::getConnection($alias);
return self::$_connectionAliases[$connectionName];
}
self::$_connections[$connectionName] = self::_initConnection($connectionName);
@ -45,23 +47,23 @@ class Wootook_Database
private static function _initConnection($connectionName)
{
$hostname = Wootook::getConfig("global/database/{$connectionName}/params/hostname");
$username = Wootook::getConfig("global/database/{$connectionName}/params/username");
$password = Wootook::getConfig("global/database/{$connectionName}/params/password");
$database = Wootook::getConfig("global/database/{$connectionName}/params/database");
$hostname = Wootook::getConfig("database/{$connectionName}/params/hostname");
$username = Wootook::getConfig("database/{$connectionName}/params/username");
$password = Wootook::getConfig("database/{$connectionName}/params/password");
$database = Wootook::getConfig("database/{$connectionName}/params/database");
if (empty($hostname) || empty($username) || empty($database)) {
return null;
}
$dsn = "mysql:dbname={$database};host={$hostname}";
if (($port = Wootook::getConfig("global/database/{$connectionName}/params/port")) && is_numeric($port)) {
if (($port = Wootook::getConfig("database/{$connectionName}/params/port")) && is_numeric($port)) {
$dsn .= ";port={$port}";
}
$event = Wootook::dispatchEvent('database.prepare-options', array(
'name' => $connectionName,
'options' => array_merge(self::$options, Wootook::getConfig("global/database/{$connectionName}/options"))
'options' => array_merge(self::$options, Wootook::getConfig("database/{$connectionName}/options")->toArray())
));
$options = $event->getData('options');
@ -71,7 +73,7 @@ class Wootook_Database
$connection->_username = $username;
$connection->_password = $password;
if (($prefix = Wootook::getConfig("global/database/{$connectionName}/table_prefix")) !== null) {
if (($prefix = Wootook::getConfig("database/{$connectionName}/table_prefix")) !== null) {
$connection->setTablePrefix($prefix);
}

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;
}
}