Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>

This commit is contained in:
Gregory PLANCHAT 2011-06-28 13:02:55 +02:00
commit 3fd8832b45
138 changed files with 2597 additions and 1253 deletions

View file

@ -89,7 +89,7 @@ abstract class Legacies_Empire_Model_BuilderAbstract
{
$this->clearQueue();
$unserialized = unserialize($serialized);
$unserialized = @unserialize($serialized);
if ($unserialized === false) {
$this->_queue = array();
return $this;

View file

@ -49,6 +49,9 @@ class Legacies_Empire_Model_Game_Types
public function is($element, $type)
{
if (!is_array($this->getData($type))) {
return false;
}
return in_array($element, $this->getData($type));
}
}

View file

@ -90,6 +90,28 @@ class Legacies_Empire_Model_Planet
return $this;
}
public function updateBuildingFields()
{
$types = Legacies_Empire_Model_Game_Types::getSingleton();
if ($this->isPlanet()) {
$filter = Legacies_Empire::TYPE_BUILDING_PLANET;
} else if ($this->isMoon()) {
$filter = Legacies_Empire::TYPE_BUILDING_MOON;
} else {
return $this;
}
$usedFields = 0;
foreach ($types[$filter] as $buildingId) {
$usedFields += $this->getElement($buildingId);
}
$this->setData('field_current', $usedFields);
return $this;
}
public function updateResourceProduction($time = null)
{
$types = Legacies_Empire_Model_Game_Types::getSingleton();
@ -121,7 +143,7 @@ class Legacies_Empire_Model_Planet
$level = $this->getData(Legacies_Empire::getFieldName($productionUnit));
$ratio = $this->getData($ratioField);
$element = self::getProducitonElementInstance($productionUnit);
$element = self::getProductionElementInstance($productionUnit);
$productionRatios[$productionUnit] = $element->getProductionRatios($level, $ratio, $this, $this->getUser());
foreach ($productionRatios[$productionUnit] as $resourceId => $resourceProduction) {
@ -216,7 +238,7 @@ class Legacies_Empire_Model_Planet
return $this;
}
public static function getProducitonElementInstance($buildingId)
public static function getProductionElementInstance($buildingId)
{
$production = Legacies_Empire_Model_Game_Production::getSingleton();
@ -232,6 +254,49 @@ class Legacies_Empire_Model_Planet
return self::$_productionInstances[$buildingId];
}
public function getFleetCollection($time = null)
{
$firstCollection = new Legacies_Core_Collection(array('fleet' => 'fleets'));
$firstCollection
->column('*')
->where('fleet.fleet_start_galaxy = :galaxy')
->where('fleet.fleet_start_system = :system')
->where('fleet.fleet_start_planet = :position')
->where('fleet.fleet_start_type = :planet_type')
;
$backCollection = new Legacies_Core_Collection(array('fleet' => 'fleets'));
$backCollection
->column('*')
->where('fleet.fleet_end_galaxy = :galaxy')
->where('fleet.fleet_end_system = :system')
->where('fleet.fleet_end_planet = :position')
->where('fleet.fleet_end_type = :planet_type')
;
$options = array(
'galaxy' => $this->getSystem(),
'system' => $this->getSystem(),
'position' => $this->getPosition(),
'planet_type' => $this->getType()
);
if ($time !== null) {
$options['now'] = $time;
$firstCollection->where('fleet_start_time <= :now');
$backCollection->where('fleet_end_time <= :now');
}
$collection = new Legacies_Core_Collection();
$collection
->setEntityClassName('Legacies_Empire_Model_Fleet')
->union($firstCollection)
->union($backCollection)
->load($options)
;
return $collection;
}
public function getUser()
{
if ($this->_user === null) {
@ -434,7 +499,7 @@ class Legacies_Empire_Model_Planet
'user' => $this->_currentUser
));
$this->_builder->updateQueue();
$this->_builder->updateQueue($time);
// Dispatch event
Legacies::dispatchEvent($this->_eventPrefix . 'update-queue.after', array(
@ -443,6 +508,13 @@ class Legacies_Empire_Model_Planet
'planet' => $this->_currentPlanet,
'user' => $this->_currentUser
));
return $this;
}
public function getBuildingQueue()
{
return $this->_builder;
}
/**
@ -471,6 +543,28 @@ class Legacies_Empire_Model_Planet
return true;
}
/**
* Get the resources needed to build a specific building
*
* @param int $buildingId
* @return bool
*/
public function getResourcesNeeded($buildingId, $level)
{
return $this->_builder->getResourcesNeeded($buildingId, $level);
}
/**
* Get the time needed to build a specific building
*
* @param int $buildingId
* @return bool
*/
public function getBuildingTime($buildingId, $level)
{
return $this->_builder->getBuildingTime($buildingId, $level);
}
public static function registrationListener($eventData)
{
if (isset($eventData['user'])) {

View file

@ -78,13 +78,10 @@ class Legacies_Empire_Model_Planet_Builder
*
* @return Legacies_Empire_Model_Planet_Building_Shipyard
*/
public function updateQueue($time = null)
public function updateQueue($time)
{
$fields = Legacies_Empire_Model_Game_FieldsAlias::getSingleton();
if ($time === null) {
$time = Legacies::now();
}
$elapsedTime = $time - $this->_currentPlanet->getData('b_building');
foreach ($this->getQueue() as $element) {
@ -97,6 +94,7 @@ class Legacies_Empire_Model_Planet_Builder
$this->_currentPlanet->setElement($buildingId, $level);
$this->_currentPlanet->updateResourceProduction($time - $elapsedTime);
$this->_currentPlanet->updateStorages($time - $elapsedTime);
$this->_currentPlanet->updateBuildingFields();
$this->dequeue($element);
Legacies::dispatchEvent('planet.building.level-update', array(

View file

@ -207,13 +207,13 @@ class Legacies_Empire_Model_Planet_Building_Shipyard
/**
* Return the construction queue
* @see Legacies_Empire_Model_Planet_Building_Shipyard_Item
* @see Legacies_Empire_Model_Planet_Building_Shipyard_Builder
*
* @return array
*/
public function getQueue()
public function getBuilder()
{
return $this->_queue;
return $this->_builder;
}
/**

View file

@ -0,0 +1,27 @@
<?php
class Legacies_Empire_Model_Planet_Ship_LightTransport
implements Legacies_Empire_Model_Planet_ShipInterface
{
const REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_IMPULSE_DRIVE = 4;
public function getBaseSpeed(Legacies_Empire_Model_User $user)
{
$prices = Legacies_Empire_Model_Game_Prices::getSingleton();
if ($user->getElement(Legacies_Empire::ID_RESEARCH_IMPULSE_DRIVE) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_IMPULSE_DRIVE) {
return $prices[Legacies_Empire::ID_SHIP_LIGHT_TRANSPORT][Legacies_Empire::SHIPS_CELERITY_PRIMARY];
} else {
return $prices[Legacies_Empire::ID_SHIP_LIGHT_TRANSPORT][Legacies_Empire::SHIPS_CELERITY_SECONDARY];
}
}
public function getSpeedMultiplier(Legacies_Empire_Model_User $user)
{
if ($user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_DRIVE) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_IMPULSE_DRIVE) {
return pow(1.1, $user->getElement(Legacies_Empire::ID_RESEARCH_COMBUSTION_DRIVE));
} else {
return pow(1.2, $user->getElement(Legacies_Empire::ID_RESEARCH_IMPULSE_DRIVE));
}
}
}

View file

@ -9,4 +9,14 @@ class Legacies_Empire_Model_Planet_Ship_SolarSatellite
Legacies_Empire::RESOURCE_ENERGY => ((floatval($planet->getData('temp_max')) / 4) + 20) * (0.1 * $produtionRatio) * floatval($quantity)
);
}
public function getMaximumSpeed(Legacies_Empire_Model_User $user)
{
return 0;
}
public function getActualMaximumSpeed(Legacies_Empire_Model_User $user)
{
return 0;
}
}

View file

@ -3,10 +3,36 @@
class Legacies_Empire_Model_Planet_Ship_Supernova
implements Legacies_Empire_Model_Planet_ResourceProductionInterface, Legacies_Empire_Model_Planet_ShipInterface
{
const REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_DRIVE = 20;
const REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_TECHNOLOGY = 15;
public function getProductionRatios($quantity, $produtionRatio, $planet, $user)
{
return array(
Legacies_Empire::RESOURCE_ENERGY => ((floatval($planet->getData('temp_max')) / 4) + 20) * (0.1 * $produtionRatio) * floatval($quantity) * -1250
);
}
public function getBaseSpeed(Legacies_Empire_Model_User $user)
{
$prices = Legacies_Empire_Model_Game_Prices::getSingleton();
if ($user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_DRIVE) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_DRIVE &&
$user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_TECHNOLOGY) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_TECHNOLOGY) {
return $prices[Legacies_Empire::ID_SHIP_SUPERNOVA][Legacies_Empire::SHIPS_CELERITY_PRIMARY];
} else {
return $prices[Legacies_Empire::ID_SHIP_SUPERNOVA][Legacies_Empire::SHIPS_CELERITY_SECONDARY];
}
}
public function getSpeedMultiplier(Legacies_Empire_Model_User $user)
{
if ($user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_DRIVE) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_DRIVE &&
$user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_TECHNOLOGY) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_TECHNOLOGY) {
return pow(1.2, $user->getElement(Legacies_Empire::ID_RESEARCH_IMPULSE_DRIVE));
} else {
return pow(1.3, $user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_DRIVE)) *
pow(1.1, $user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_TECHNOLOGY));
}
}
}

View file

@ -2,4 +2,6 @@
interface Legacies_Empire_Model_Planet_ShipInterface
{
public function getBaseSpeed(Legacies_Empire_Model_User $user);
public function getSpeedMultiplier(Legacies_Empire_Model_User $user);
}

View file

@ -22,6 +22,13 @@ class Legacies_Empire_Model_User
const PLANET_SORT_POSITION = 1;
const PLANET_SORT_NAME = 2;
protected static $_cookieName = self::COOKIE_NAME;
public static function setCookieName($name)
{
self::$_cookieName = $name;
}
public static function factory($id)
{
if ($id === null) {
@ -44,7 +51,7 @@ class Legacies_Empire_Model_User
$session = Legacies::getSession(self::SESSION_KEY);
if ($session->hasData('user_id')) {
$id = intval($session->getData('user_id'));
} else if (Legacies::$request !== null && ($cookie = Legacies::$request->getCookie(self::COOKIE_NAME)) !== null) {
} else if (Legacies::$request !== null && ($cookie = Legacies::$request->getCookie(self::$_cookieName)) !== null) {
$cookieData = unserialize(stripslashes($cookie));
if (is_array($cookieData)) {
$collection = new Legacies_Core_Collection(array('user' => 'users'));
@ -92,8 +99,8 @@ class Legacies_Empire_Model_User
protected function _updateActivity()
{
$this
->setData('request_uri', $_SERVER['REQUEST_URI'])
->setData('remote_addr', $_SERVER['REMOTE_ADDR'])
->setData('current_page', $_SERVER['REQUEST_URI'])
->setData('user_lastip', $_SERVER['REMOTE_ADDR'])
->setData('user_agent', $_SERVER['HTTP_USER_AGENT'])
->setData('onlinetime', time())
->save()
@ -104,7 +111,7 @@ class Legacies_Empire_Model_User
public function logout()
{
if (Legacies::$response !== null) {
Legacies::$response->unsetCookie(self::COOKIE_NAME);
Legacies::$response->unsetCookie(self::$_cookieName);
}
Legacies_Core_Model_Session::destroy();
}
@ -150,7 +157,7 @@ class Legacies_Empire_Model_User
}
if (isset($_POST["rememberme"]) && Legacies::$request !== null) {
Legacies::$response->setCookie(self::COOKIE_NAME, array('id' => $login['id'], 'key' => $login['login_rememberme']), self::COOKIE_LIFETIME);
Legacies::$response->setCookie(self::$_cookieName, array('id' => $login['id'], 'key' => $login['login_rememberme']), self::COOKIE_LIFETIME);
}
self::$_singleton = self::factory($login['id']);
@ -190,6 +197,25 @@ class Legacies_Empire_Model_User
return $user;
}
public function updateCurrentPlanet($planetId)
{
$planetColelction = $this->_preparePlanetCollection()->where('id=:id');
$planetCollection->load(array(
'id' => $planetId,
'user' => $this->getId()
));
if ($planetCollection->count() !== 1) {
return false;
}
$planet = $planetCollection->current();
$this->setData('current_planet', $planet->getId());
return true;
}
public function getCurrentPlanet()
{
$planetId = $this->getData('current_planet');
@ -200,7 +226,7 @@ class Legacies_Empire_Model_User
return Legacies_Empire_Model_Planet::factory($planetId);
}
public function getPlanetCollection()
protected function _preparePlanetCollection()
{
$planetCollection = new Legacies_Core_Collection(array('planet' => 'planets'), 'Legacies_Empire_Model_Planet');
$planetCollection->where('id_owner=:user');
@ -226,6 +252,12 @@ class Legacies_Empire_Model_User
$planetCollection->order('planet.id', $order);
break;
}
return $planetCollection;
}
public function getPlanetCollection()
{
$planetCollection = $this->_preparePlanetCollection();
$planetCollection->load(array(
'user' => $this->getId()