Added Research lab queue manager.
Updated page display for shipyard, defenses and buildings. Moved legacy template files. Added install/migration.mysql to report changes to the database on testing environments. Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
parent
f2d4b0f7e2
commit
ddfb36efa5
341 changed files with 4238 additions and 3259 deletions
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
class Legacies_Empire_Block_Planet_Buildings_Item
|
||||
extends Legacies_Core_Block_Template
|
||||
{
|
||||
protected $_planet = null;
|
||||
protected $_itemId = null;
|
||||
|
||||
public function setPlanet(Legacies_Empire_Model_Planet $planet)
|
||||
{
|
||||
$this->_planet = $planet;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPlanet()
|
||||
{
|
||||
return $this->_planet;
|
||||
}
|
||||
|
||||
public function setItemId($itemId)
|
||||
{
|
||||
$this->_itemId = $itemId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getItemId()
|
||||
{
|
||||
return $this->_itemId;
|
||||
}
|
||||
|
||||
public function getItemInfoUrl()
|
||||
{
|
||||
return $this->getUrl('infos.php', array('gid' => $this->getItemId()));
|
||||
}
|
||||
|
||||
public function getItemImageUrl()
|
||||
{
|
||||
return $this->getSkinUrl('graphics/gebaeude/' . $this->getItemId() . '.gif');
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
static $lang = null;
|
||||
if ($lang === null) {
|
||||
// FIXME: implement a cleaner way to get names
|
||||
$lang = includeLang('tech');
|
||||
}
|
||||
|
||||
if (isset($lang['tech']) && isset($lang['tech'][$this->getItemId()])) {
|
||||
return $this->__($lang['tech'][$this->getItemId()]);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
static $lang = null;
|
||||
if ($lang === null) {
|
||||
// FIXME: implement a cleaner way to get names
|
||||
$lang = includeLang('tech');
|
||||
}
|
||||
|
||||
if (isset($lang['res']) && isset($lang['res']['descriptions']) && isset($lang['res']['descriptions'][$this->getItemId()])) {
|
||||
return $this->__($lang['res']['descriptions'][$this->getItemId()]);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getResourceName($resourceId)
|
||||
{
|
||||
static $lang = null;
|
||||
if ($lang === null) {
|
||||
// FIXME: implement a cleaner way to get names
|
||||
$lang = includeLang('imperium');
|
||||
}
|
||||
if ($resourceId == 'cristal') {
|
||||
$resourceId = 'crystal';
|
||||
}
|
||||
|
||||
if (isset($lang[$resourceId])) {
|
||||
return $this->__($lang[$resourceId]);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getLevel()
|
||||
{
|
||||
return $this->_planet->getElement($this->getItemId());
|
||||
}
|
||||
|
||||
public function getResourcesNeeded()
|
||||
{
|
||||
return $this->_planet->getResourcesNeeded($this->getItemId(), 1);
|
||||
}
|
||||
|
||||
public function getItemTime()
|
||||
{
|
||||
return $this->_planet->getBuildingTime($this->getItemId(), 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
class Legacies_Empire_Block_Planet_Shipyard_Item
|
||||
extends Legacies_Core_Block_Template
|
||||
{
|
||||
protected $_planet = null;
|
||||
protected $_shipyard = null;
|
||||
protected $_itemId = null;
|
||||
|
||||
public function setPlanet(Legacies_Empire_Model_Planet $planet)
|
||||
{
|
||||
$this->_planet = $planet;
|
||||
$this->_shipyard = $this->_planet->getShipyard();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPlanet()
|
||||
{
|
||||
return $this->_planet;
|
||||
}
|
||||
|
||||
public function setItemId($shipId)
|
||||
{
|
||||
$this->_itemId = $shipId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getItemId()
|
||||
{
|
||||
return $this->_itemId;
|
||||
}
|
||||
|
||||
public function getItemInfoUrl()
|
||||
{
|
||||
return $this->getUrl('infos.php', array('gid' => $this->getItemId()));
|
||||
}
|
||||
|
||||
public function getItemImageUrl()
|
||||
{
|
||||
return $this->getSkinUrl('graphics/gebaeude/' . $this->getItemId() . '.gif');
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
static $lang = null;
|
||||
if ($lang === null) {
|
||||
// FIXME: implement a cleaner way to get names
|
||||
$lang = includeLang('tech');
|
||||
}
|
||||
|
||||
if (isset($lang['tech']) && isset($lang['tech'][$this->getItemId()])) {
|
||||
return $this->__($lang['tech'][$this->getItemId()]);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
static $lang = null;
|
||||
if ($lang === null) {
|
||||
// FIXME: implement a cleaner way to get names
|
||||
$lang = includeLang('tech');
|
||||
}
|
||||
|
||||
if (isset($lang['res']) && isset($lang['res']['descriptions']) && isset($lang['res']['descriptions'][$this->getItemId()])) {
|
||||
return $this->__($lang['res']['descriptions'][$this->getItemId()]);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getResourceName($resourceId)
|
||||
{
|
||||
static $lang = null;
|
||||
if ($lang === null) {
|
||||
// FIXME: implement a cleaner way to get names
|
||||
$lang = includeLang('imperium');
|
||||
}
|
||||
if ($resourceId == 'cristal') {
|
||||
$resourceId = 'crystal';
|
||||
}
|
||||
|
||||
if (isset($lang[$resourceId])) {
|
||||
return $this->__($lang[$resourceId]);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getQty()
|
||||
{
|
||||
return $this->_planet->getElement($this->getItemId());
|
||||
}
|
||||
|
||||
public function getResourcesNeeded()
|
||||
{
|
||||
return $this->_shipyard->getResourcesNeeded($this->getItemId(), 1);
|
||||
}
|
||||
|
||||
public function getBuildingTime()
|
||||
{
|
||||
return $this->_shipyard->getBuildingTime($this->getItemId(), 1);
|
||||
}
|
||||
|
||||
public function getMaximumBuildableElementsCount()
|
||||
{
|
||||
return $this->_shipyard->getMaximumBuildableElementsCount($this->getItemId());
|
||||
}
|
||||
}
|
||||
|
|
@ -218,4 +218,16 @@ abstract class Legacies_Empire_Model_BuilderAbstract
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _calculateResourceRemainingAmounts($resourceNeeded)
|
||||
{
|
||||
$resourceAmounts = array();
|
||||
foreach ($resourcesNeeded as $resourceId => $resourceAmount) {
|
||||
$resourceAmounts[$resourceId] = Math::sub($this->_currentPlanet[$resourceId], $resourceAmount);
|
||||
if (Math::isNegative($resourceAmounts[$resourceId])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $resourceAmounts;
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ class Legacies_Empire_Model_Planet
|
|||
protected $_shipyard = null;
|
||||
|
||||
/**
|
||||
* @var Legacies_Empire_Model_Planet_Building_Laboratory
|
||||
* @var Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
*/
|
||||
protected $_laboratory = null;
|
||||
|
||||
|
|
@ -393,15 +393,15 @@ class Legacies_Empire_Model_Planet
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getLaboratory()
|
||||
public function getResearchLab()
|
||||
{
|
||||
if ($this->_laboratory === null) {
|
||||
$this->_laboratory = new Legacies_Empire_Model_Planet_Building_Laboratory($this, $this->getUser());
|
||||
$this->_laboratory = new Legacies_Empire_Model_Planet_Building_ResearchLab($this, $this->getUser());
|
||||
}
|
||||
return $this->_laboratory;
|
||||
}
|
||||
|
||||
public function setLaboratory(Legacies_Empire_Model_Planet_Building_Laboratory $laboratory)
|
||||
public function setResearchLab(Legacies_Empire_Model_Planet_Building_ResearchLab $laboratory)
|
||||
{
|
||||
$this->_laboratory = $laboratory;
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,11 @@ class Legacies_Empire_Model_Planet_Builder
|
|||
return $this->checkAvailability($buildingId);
|
||||
}
|
||||
|
||||
public function getBuildingTime($buildingId, $level)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getResourcesNeeded($buildingId, $level)
|
||||
{
|
||||
$prices = Legacies_Empire_Model_Game_Prices::getSingleton();
|
||||
|
|
@ -68,11 +73,6 @@ class Legacies_Empire_Model_Planet_Builder
|
|||
return $resourcesNeeded;
|
||||
}
|
||||
|
||||
public function getBuildingTime($buildingId, $level)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the contruction queue.
|
||||
*
|
||||
|
|
@ -143,27 +143,18 @@ class Legacies_Empire_Model_Planet_Builder
|
|||
}
|
||||
|
||||
$resourcesNeeded = $this->getResourcesNeeded($buildingId, $level);
|
||||
|
||||
$amounts = array();
|
||||
foreach ($resourcesNeeded as $resourceId => $resourceCost) {
|
||||
$amount[$resourceId] = Math::sub($this->_currentPlanet[$resourceId], $resourceCost);
|
||||
|
||||
if (Math::isNegative($amount[$resourceId])) {
|
||||
return $this;
|
||||
}
|
||||
$remainingAmounts = $this->_calculateResourceRemainingAmounts($resourcesNeeded);
|
||||
if ($remainingAmounts === false) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->enqueue($buildingId, $level, $time);
|
||||
|
||||
foreach ($resourcesNeeded as $resourceId => $resourceCost) {
|
||||
if (!isset($resources[$resourceId]) || !Math::isPositive($resourceCost)) {
|
||||
continue;
|
||||
}
|
||||
$this->_currentPlanet->setData($resourceId, $resourceId[$resourceId]);
|
||||
}
|
||||
|
||||
$this->_currentPlanet->setData('b_building_id', $this->serialize());
|
||||
|
||||
foreach ($remainingAmounts as $resourceId => $resourceAmount) {
|
||||
$this->_currentPlanet[$resourceId] = $resourceAmount;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,256 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of XNova:Legacies
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.txt
|
||||
* @see http://www.xnova-ng.org/
|
||||
*
|
||||
* Copyright (c) 2009-Present, XNova Support Team <http://www.xnova-ng.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --> NOTICE <--
|
||||
* This file is part of the core development branch, changing its contents will
|
||||
* make you unable to use the automatic updates manager. Please refer to the
|
||||
* documentation for further information about customizing XNova.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Research lab building, manages researches queue on each planet
|
||||
*
|
||||
* @access public
|
||||
* @category Empire
|
||||
* @category Planet
|
||||
* @package Legacies
|
||||
* @subpackage Legacies_Empire
|
||||
*/
|
||||
class Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
implements Legacies_Empire_Model_Planet_BuildingInterface
|
||||
{
|
||||
private $_eventPrefix = 'planet.laboratory.';
|
||||
|
||||
/**
|
||||
* Planet instance
|
||||
* @var Legacies_Empire_Model_Planet
|
||||
*/
|
||||
protected $_currentPlanet = null;
|
||||
|
||||
/**
|
||||
* User instance
|
||||
* @var Legacies_Empire_Model_User
|
||||
*/
|
||||
protected $_currentUser = null;
|
||||
|
||||
/**
|
||||
* construction queue
|
||||
* @var array
|
||||
*/
|
||||
protected $_builder = null;
|
||||
|
||||
/**
|
||||
* Multiton instances
|
||||
* @var array
|
||||
*/
|
||||
protected static $_instances = array();
|
||||
|
||||
/**
|
||||
* Multiton factory. Retruns the planet's research lab instance or created it if
|
||||
* it doesn't yet exist.
|
||||
*
|
||||
* @param Legacies_Empire_Model_Planet $currentPlanet
|
||||
* @param Legacies_Empire_Model_User $currentUser
|
||||
* @return Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
*/
|
||||
public static function factory($currentPlanet, $currentUser)
|
||||
{
|
||||
if ($currentPlanet->getId()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset(self::$_instances[$currentPlanet->getId()])) {
|
||||
self::$_instances[$currentPlanet->getId()] = new self($currentPlanet, $currentUser);
|
||||
}
|
||||
return self::$_instances[$currentPlanet->getId()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor. Used for specific usage, use the factory for standard usage.
|
||||
*
|
||||
* @see Legacies_Empire_Model_Planet_Building_ResearchLab::factory()
|
||||
*
|
||||
* @param Legacies_Empire_Model_Planet $currentPlanet
|
||||
* @param Legacies_Empire_Model_User $currentUser
|
||||
*/
|
||||
public function __construct($currentPlanet, $currentUser)
|
||||
{
|
||||
$this->_currentPlanet = $currentPlanet;
|
||||
$this->_currentUser = $currentUser;
|
||||
|
||||
$this->_builder = new Legacies_Empire_Model_Planet_Building_ResearchLab_Builder($currentPlanet, $currentUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$this->_currentPlanet->save();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append items to build to the construction list
|
||||
*
|
||||
* @param int $researchId
|
||||
* @param int|string $level
|
||||
* @return Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
*/
|
||||
public function appendQueue($researchId, $destroy = false, $time = null)
|
||||
{
|
||||
if ($time === null) {
|
||||
$time = Legacies::now();
|
||||
}
|
||||
|
||||
if ($destroy === false) {
|
||||
$level = $this->_currentUser->getElement($researchId) + 1;
|
||||
} else {
|
||||
$level = max($this->_currentUser->getElement($researchId) - 1, 0);
|
||||
}
|
||||
|
||||
// Dispatch event
|
||||
Legacies::dispatchEvent($this->_eventPrefix . 'append-queue.before', array(
|
||||
'research_id' => $researchId,
|
||||
'level' => &$level,
|
||||
'time' => &$time,
|
||||
'laboratory' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
|
||||
$this->_builder->appendQueue($researchId, $level, $time);
|
||||
|
||||
// Dispatch event
|
||||
Legacies::dispatchEvent($this->_eventPrefix . 'append-queue.after', array(
|
||||
'research_id' => $researchId,
|
||||
'level' => $level,
|
||||
'time' => $time,
|
||||
'laboratory' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the contruction queue.
|
||||
*
|
||||
* @return Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
*/
|
||||
public function updateQueue($time = null)
|
||||
{
|
||||
if ($time === null) {
|
||||
$time = Legacies::now();
|
||||
}
|
||||
|
||||
// Dispatch event
|
||||
Legacies::dispatchEvent($this->_eventPrefix . 'update-queue.before', array(
|
||||
'time' => &$time,
|
||||
'laboratory' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
|
||||
$this->_builder->updateQueue($time);
|
||||
|
||||
// Dispatch event
|
||||
Legacies::dispatchEvent($this->_eventPrefix . 'update-queue.after', array(
|
||||
'time' => $time,
|
||||
'laboratory' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the construction queue
|
||||
* @see Legacies_Empire_Model_Planet_Building_ResearchLab_Builder
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBuilder()
|
||||
{
|
||||
return $this->_builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a ship or defense type is actually buildable on the current
|
||||
* planet, depending on the technology and buildings requirements.
|
||||
*
|
||||
* @param int $resourceId
|
||||
* @return bool
|
||||
*/
|
||||
public function checkAvailability($resourceId)
|
||||
{
|
||||
try {
|
||||
// Dispatch event
|
||||
Legacies::dispatchEvent($this->_eventPrefix . 'check-availability', array(
|
||||
'research_id' => $resourceId,
|
||||
'laboratory' => $this,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser
|
||||
));
|
||||
} catch (Legacies_Core_Event_Break $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_builder->checkAvailability($resourceId);
|
||||
}
|
||||
|
||||
public function getResourcesNeeded($resourceId, $level)
|
||||
{
|
||||
return $this->_builder->getResourcesNeeded($resourceId, $level);
|
||||
}
|
||||
|
||||
public function getBuildingTime($resourceId, $level)
|
||||
{
|
||||
$this->_builder->getBuildingTime($resourceId, $level);
|
||||
}
|
||||
|
||||
public static function planetUpdateListener($eventData)
|
||||
{
|
||||
if (isset($eventData['planet'])) {
|
||||
$planet = $eventData['planet'];
|
||||
|
||||
if ($planet === null || !$planet instanceof Legacies_Empire_Model_Planet || !$planet->getId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$time = null;
|
||||
if (isset($eventData['time'])) {
|
||||
$time = $eventData['time'];
|
||||
}
|
||||
|
||||
$shipyard = $planet->getResearchLab();
|
||||
if ($shipyard !== null) {
|
||||
$shipyard->updateQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,206 @@
|
|||
<?php
|
||||
|
||||
class Legacies_Empire_Model_Planet_Building_ResearchLab_Builder
|
||||
extends Legacies_Empire_Model_BuilderAbstract
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $_maxLength = 0;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->_unserializeQueue($this->_currentUser->getData('b_laboratory_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $buildingId
|
||||
* @param int $level
|
||||
* @param int $time
|
||||
*/
|
||||
public function _initItem()
|
||||
{
|
||||
$technologyId = func_get_arg(0);
|
||||
$level = func_get_arg(1);
|
||||
$time = func_get_arg(2);
|
||||
|
||||
return new Legacies_Empire_Model_Planet_Building_ResearchLab_Item(array(
|
||||
'technology_id' => $technologyId,
|
||||
'level' => $level,
|
||||
'created_at' => $time,
|
||||
'updated_at' => $time
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a technology type is actually buildable on the current
|
||||
* planet, depending on the technology and buildings requirements.
|
||||
*
|
||||
* @param int $technologyId
|
||||
* @return bool
|
||||
*/
|
||||
public function checkAvailability($technologyId)
|
||||
{
|
||||
$types = Legacies_Empire_Model_Game_Types::getSingleton();
|
||||
|
||||
if (!$types->is($technologyId, Legacies_Empire::TYPE_RESEARCH)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
parent::checkAvailability($technologyId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time needed to build $level of $technologyId
|
||||
*
|
||||
* @param int $technologyId
|
||||
* @param int $level
|
||||
*/
|
||||
public function getBuildingTime($technologyId, $level)
|
||||
{
|
||||
$prices = Legacies_Empire_Model_Game_Prices::getSingleton();
|
||||
$types = Legacies_Empire_Model_Game_Types::getSingleton();
|
||||
$gameConfig = Legacies_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');
|
||||
|
||||
// FIXME: Building & Technology dependency
|
||||
$extraLaboratoriesLevels = 0;
|
||||
$researchNetworkLevel = $this->_currentUser->getElement(Legacies_Empire::ID_RESEARCH_INTERGALACTIC_RESEARCH_NETWORK);
|
||||
if ($researchNetworkLevel > 0) {
|
||||
$laboratoriesLevels = array();
|
||||
foreach ($this->_currentUser->getPlanetCollection() as $planet) {
|
||||
if ($this->_currentPlanet->getId() == $planet->getId()) {
|
||||
continue;
|
||||
}
|
||||
$level = $planet->getElement(Legacies_Empire::ID_BUILDING_RESEARCH_LAB);
|
||||
if ($level > 0) {
|
||||
$laboratoriesLevels[] = (int) $level;
|
||||
}
|
||||
}
|
||||
sort($laboratoriesLevels, SORT_NUMERIC);
|
||||
$extraLaboratoriesLevels = array_sum(array_slice(array_reverse($laboratoriesLevels), 0, $researchNetworkLevel));
|
||||
}
|
||||
|
||||
$laboratorySpeedup = Math::div($totalCost, ($this->_currentPlanet->getElement(Legacies_Empire::ID_BUILDING_RESEARCH_LAB) + 1 + $extraLaboratoriesLevels));
|
||||
|
||||
Math::setPrecision();
|
||||
|
||||
$baseTime = ($totalCost / $speedFactor) * $laboratorySpeedup;
|
||||
|
||||
return (int) Math::floor($baseTime * 3600);
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see Legacies_Empire_Model_BuilderAbstract::getResourcesNeeded()
|
||||
*/
|
||||
public function getResourcesNeeded($technologyId, $level)
|
||||
{
|
||||
$prices = Legacies_Empire_Model_Game_Prices::getSingleton();
|
||||
$resources = Legacies_Empire_Model_Game_Resources::getSingleton();
|
||||
|
||||
if (!isset($prices[$technologyId])) {
|
||||
return array();
|
||||
}
|
||||
$resourcesNeeded = array();
|
||||
foreach ($resources as $resourceId => $resourceConfig) {
|
||||
if (!isset($prices[$technologyId][$resourceId])) {
|
||||
continue;
|
||||
}
|
||||
if (Math::isPositive($prices[$technologyId][$resourceId])) {
|
||||
$firstLevelCost = $prices[$technologyId][$resourceId];
|
||||
$partialLevelCost = Math::mul($firstLevelCost, Math::pow($prices[$technologyId][Legacies_Empire::RESOURCE_MULTIPLIER], $level));
|
||||
$resourcesNeeded[$resourceId] = Math::sub($partialLevelCost, $firstLevelCost);
|
||||
}
|
||||
}
|
||||
|
||||
return $resourcesNeeded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the contruction queue.
|
||||
*
|
||||
* @return Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
*/
|
||||
public function updateQueue($time)
|
||||
{
|
||||
$fields = Legacies_Empire_Model_Game_FieldsAlias::getSingleton();
|
||||
|
||||
$elapsedTime = $time - $this->_currentUser->getData('b_laboratory');
|
||||
|
||||
foreach ($this->getQueue() as $element) {
|
||||
$technologyId = $element->getData('research_id');
|
||||
$level = $element->getData('level');
|
||||
$buildTime = $this->getBuildingTime($technologyId, $level);
|
||||
|
||||
if ($elapsedTime >= $buildTime) {
|
||||
$this->_currentUser[$fields[$technologyId]] = Math::add($this->_currentUser[$fields[$technologyId]], $level);
|
||||
$elapsedTime -= $buildTime;
|
||||
$this->dequeue($element);
|
||||
continue;
|
||||
}
|
||||
|
||||
$timeRatio = $elapsedTime / $buildTime;
|
||||
$itemsBuilt = Math::mul($timeRatio, $level);
|
||||
|
||||
$element->setData('updated_at', $time);
|
||||
$element->setData('level', Math::sub($level, $itemsBuilt));
|
||||
$this->_currentUser->setData($fields[$technologyId], Math::add($this->_currentUser->getData($fields[$technologyId]), $itemsBuilt));
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_currentUser->setData('b_laboratory_id', $this->serialize());
|
||||
$this->_currentUser->setData('b_laboratory', $time);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append items to build to the construction list
|
||||
*
|
||||
* @param int $technologyId
|
||||
* @param int|string $level
|
||||
* @return Legacies_Empire_Model_Planet_Building_ResearchLab
|
||||
*/
|
||||
public function appendQueue($technologyId, $level, $time)
|
||||
{
|
||||
if ($this->_maxLength > 0 && $this->count() >= $this->_maxLength) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!Math::isPositive($level)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$types = Legacies_Empire_Model_Game_Types::getSingleton();
|
||||
if (!$types->is($technologyId, Legacies_Empire::TYPE_RESEARCH)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!$this->checkAvailability($technologyId)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$resourcesNeeded = $this->getResourcesNeeded($technologyId, $level);
|
||||
$remainingAmounts = $this->_calculateResourceRemainingAmounts($resourcesNeeded);
|
||||
if ($remainingAmounts === false) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->enqueue($technologyId, $level, $time);
|
||||
$this->_currentUser->setData('b_laboratory_id', $this->serialize());
|
||||
|
||||
foreach ($remainingAmounts as $resourceId => $resourceAmount) {
|
||||
$this->_currentPlanet[$resourceId] = $resourceAmount;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
class Legacies_Empire_Model_Planet_Building_ResearchLab_Item
|
||||
extends Legacies_Empire_Model_Builder_Item
|
||||
{
|
||||
}
|
||||
|
|
@ -3,6 +3,11 @@
|
|||
class Legacies_Empire_Model_Planet_Building_Shipyard_Builder
|
||||
extends Legacies_Empire_Model_BuilderAbstract
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $_maxLength = 0;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->_unserializeQueue($this->_currentPlanet->getData('b_hangar_id'));
|
||||
|
|
@ -250,13 +255,15 @@ class Legacies_Empire_Model_Planet_Building_Shipyard_Builder
|
|||
*/
|
||||
public function appendQueue($shipId, $qty, $time)
|
||||
{
|
||||
$types = Legacies_Empire_Model_Game_Types::getSingleton();
|
||||
$resources = Legacies_Empire_Model_Game_Resources::getSingleton();
|
||||
if ($this->_maxLength > 0 && $this->count() >= $this->_maxLength) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!Math::isPositive($qty)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$types = Legacies_Empire_Model_Game_Types::getSingleton();
|
||||
if (!$types->is($shipId, Legacies_Empire::TYPE_SHIP) && !$types->is($shipId, Legacies_Empire::TYPE_DEFENSE)) {
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -276,19 +283,18 @@ class Legacies_Empire_Model_Planet_Building_Shipyard_Builder
|
|||
}
|
||||
|
||||
$resourcesNeeded = $this->getResourcesNeeded($shipId, $qty);
|
||||
$buildTime = $this->getBuildingTime($shipId, $qty);
|
||||
|
||||
$this->enqueue($shipId, $qty, $time);
|
||||
|
||||
foreach ($resources as $resourceId => $resourceConfig) {
|
||||
if (!isset($resourcesNeeded[$resourceId])) {
|
||||
continue;
|
||||
}
|
||||
$this->_currentPlanet[$resourceId] = Math::sub($this->_currentPlanet[$resourceId], $resourcesNeeded[$resourceId]);
|
||||
$remainingAmounts = $this->_calculateResourceRemainingAmounts($resourcesNeeded);
|
||||
if ($remainingAmounts === false) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->enqueue($shipId, $qty, $time);
|
||||
$this->_currentPlanet->setData('b_hangar_id', $this->serialize());
|
||||
|
||||
foreach ($remainingAmounts as $resourceId => $resourceAmount) {
|
||||
$this->_currentPlanet[$resourceId] = $resourceAmount;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Reference in a new issue