Refactored to 2 namespaces: Wootook & Legacies

Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
Gregory PLANCHAT 2011-10-04 19:57:00 +02:00
commit ec7e40e1aa
1004 changed files with 4808 additions and 2971 deletions

View file

@ -0,0 +1,158 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire
{
const TYPE_BUILDING = 'build';
const TYPE_BUILDING_MOON = 'build_moon';
const TYPE_BUILDING_PLANET = 'build_planet';
const TYPE_RESEARCH = 'tech';
const TYPE_SHIP = 'fleet';
const TYPE_DEFENSE = 'defense';
const TYPE_SPECIAL = 'special';
const TYPE_OFFICER = 'officier';
const TYPE_PRODUCTION = 'prod';
const TYPE_FLEET_MISSION = 'mission';
const RESOURCE_METAL = 'metal';
const RESOURCE_CRISTAL = 'cristal';
const RESOURCE_DEUTERIUM = 'deuterium';
const RESOURCE_ENERGY = 'energy';
const RESOURCE_MULTIPLIER = 'factor';
const RESOURCE_FORMULA = 'formule';
const RESOURCE_CLASS = 'class';
const BASE_BUILDING_TIME = 'base_time';
const SHIPS_CONSUMPTION_PRIMARY = 'consumption';
const SHIPS_CELERITY_PRIMARY = 'speed';
const SHIPS_CONSUMPTION_SECONDARY = 'consumption2';
const SHIPS_CELERITY_SECONDARY = 'speed2';
const SHIPS_CAPACITY = 'capacity';
const ID_BUILDING_METAL_MINE = 1;
const ID_BUILDING_CRISTAL_MINE = 2;
const ID_BUILDING_DEUTERIUM_SYNTHETISER = 3;
const ID_BUILDING_SOLAR_PLANT = 4;
const ID_BUILDING_FUSION_REACTOR = 12;
const ID_BUILDING_ROBOTIC_FACTORY = 14;
const ID_BUILDING_NANITE_FACTORY = 15;
const ID_BUILDING_SHIPYARD = 21;
const ID_BUILDING_METAL_STORAGE = 22;
const ID_BUILDING_CRISTAL_STORAGE = 23;
const ID_BUILDING_DEUTERIUM_TANK = 24;
const ID_BUILDING_RESEARCH_LAB = 31;
const ID_BUILDING_TERRAFORMER = 33;
const ID_BUILDING_ALLIANCE_DEPOT = 34;
const ID_BUILDING_LUNAR_BASE = 41;
const ID_BUILDING_SENSOR_PHALANX = 42;
const ID_BUILDING_JUMP_GATE = 43;
const ID_BUILDING_MISSILE_SILO = 44;
const ID_RESEARCH_ESPIONAGE_TECHNOLOGY = 106;
const ID_RESEARCH_COMPUTER_TECHNOLOGY = 108;
const ID_RESEARCH_WEAPON_TECHNOLOGY = 109;
const ID_RESEARCH_SHIELDING_TECHNOLOGY = 110;
const ID_RESEARCH_ARMOUR_TECHNOLOGY = 111;
const ID_RESEARCH_ENERGY_TECHNOLOGY = 113;
const ID_RESEARCH_HYPERSPACE_TECHNOLOGY = 114;
const ID_RESEARCH_COMBUSTION_DRIVE = 115;
const ID_RESEARCH_IMPULSE_DRIVE = 117;
const ID_RESEARCH_HYPERSPACE_DRIVE = 118;
const ID_RESEARCH_LASER_TECHNOLOGY = 120;
const ID_RESEARCH_ION_TECHNOLOGY = 121;
const ID_RESEARCH_PLASMA_TECHNOLOGY = 122;
const ID_RESEARCH_INTERGALACTIC_RESEARCH_NETWORK = 123;
const ID_RESEARCH_EXPEDITION_TECHNOLOGY = 124;
const ID_RESEARCH_ASTROPHYSICS = 124;
const ID_RESEARCH_GRAVITON_TECHNOLOGY = 199;
const ID_SHIP_LIGHT_TRANSPORT = 202;
const ID_SHIP_LARGE_TRANSPORT = 203;
const ID_SHIP_LIGHT_FIGHTER = 204;
const ID_SHIP_HEAVY_FIGHTER = 205;
const ID_SHIP_CRUISER = 206;
const ID_SHIP_BATTLESHIP = 207;
const ID_SHIP_COLONY_SHIP = 208;
const ID_SHIP_RECYCLER = 209;
const ID_SHIP_SPY_DRONE = 210;
const ID_SHIP_BOMBER = 211;
const ID_SHIP_SOLAR_SATELLITE = 212;
const ID_SHIP_DESTRUCTOR = 213;
const ID_SHIP_DEATH_STAR = 214;
const ID_SHIP_BATTLECRUISER = 215;
const ID_SHIP_SUPERNOVA = 216;
const ID_DEFENSE_ROCKET_LAUNCHER = 401;
const ID_DEFENSE_LIGHT_LASER = 402;
const ID_DEFENSE_HEAVY_LASER = 403;
const ID_DEFENSE_ION_CANNON = 404;
const ID_DEFENSE_GAUSS_CANNON = 405;
const ID_DEFENSE_PLASMA_TURRET = 406;
const ID_DEFENSE_SMALL_SHIELD_DOME = 407;
const ID_DEFENSE_LARGE_SHIELD_DOME = 408;
const ID_SPECIAL_ANTIBALLISTIC_MISSILE = 502;
const ID_SPECIAL_INTERPLANETARY_MISSILE = 503;
const ID_COMBAT_SHIELDS = 'shield';
const ID_COMBAT_FIREPOWER = 'attack';
const ID_COMBAT_RAPID_FIRE = 'sd';
const ID_MISSION_ATTACK = 1;
const ID_MISSION_GROUP_ATTACK = 2;
const ID_MISSION_TRANSPORT = 3;
const ID_MISSION_STATION = 4;
const ID_MISSION_STATION_ALLY = 5;
const ID_MISSION_SPY = 6;
const ID_MISSION_SETTLE_COLONY = 7;
const ID_MISSION_RECYCLE = 8;
const ID_MISSION_DESTROY = 9;
const ID_MISSION_MISSILES = 10;
const ID_MISSION_EXPEDITION = 15;
public static function getFieldName($id)
{
$fieldsAlias = Wootook_Empire_Model_Game_FieldsAlias::getSingleton();
if (!isset($fieldsAlias[$id])) {
return null;
}
return $fieldsAlias[$id];
}
}

View file

@ -0,0 +1,76 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Block_Planet_ResearchLab
extends Wootook_Empire_Block_Planet_BuilderAbstract
{
protected $_planet = null;
public function setPlanet(Wootook_Empire_Model_Planet $planet)
{
$this->_planet = $planet;
return $this;
}
public function getPlanet()
{
if ($this->_planet === null) {
$this->_planet = Wootook_Empire_Model_User::getSingleton()
->getCurrentPlanet()
;
}
return $this->_planet;
}
public function _initChildBlocks()
{
$types = Wootook_Empire_Model_Game_Types::getSingleton();
/** @var Wootook_Core_Block_Concat $parentBlock */
$parentBlock = $this->getLayout()->getBlock('item-list.items');
foreach ($types->getData(Legacies_Empire::TYPE_RESEARCH) as $itemId) {
if (!$this->getPlanet()->getResearchLab()->checkAvailability($itemId)) {
continue;
}
$block = $this->getItemBlock($itemId);
$parentBlock->setPartial($block->getName(), $block);
}
return $this;
}
}

View file

@ -0,0 +1,89 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Block_Planet_ResearchLab_Item
extends Wootook_Empire_Block_Planet_Builder_ItemAbstract
{
public function getLevel()
{
return $this->getUser()->getElement($this->getItemId());
}
public function getResourcesNeeded($level)
{
return $this->getPlanet()->getResearchLab()->getResourcesNeeded($this->getItemId(), $level);
}
public function getQueuedLevel()
{
return $this->getPlanet()->getResearchLab()->getResearchLevelQueued($this->getItemId());
}
public function getBuildingTime($level)
{
return $this->getPlanet()->getResearchLab()->getResearchTime($this->getItemId(), $level);
}
public function getResourcesConfigForLevel($level)
{
$resources = $this->getResourcesNeeded($level);
$resourceConfig = array();
foreach ($resources as $resourceId => $resourceValue) {
$resourceConfig[$resourceId] = new Wootook_Object(array(
'resource_id' => $resourceId,
'value' => $resourceValue
));
$amount = $this->getPlanet()->getResourceAmount($resourceId);
if (Math::comp($amount, $resourceValue) < 0) {
$resourceConfig[$resourceId]->setData('requirement', Math::sub($amount, $resourceValue));
} else {
$resourceConfig[$resourceId]->setData('overflow', Math::sub($amount, $resourceValue));
}
}
return $resourceConfig;
}
public function getResourcesConfigForNextLevel()
{
return $this->getResourcesConfigForLevel($this->getNextLevel());
}
public function getBuildingTimeForNextLevel()
{
return $this->getBuildingTime($this->getNextLevel());
}
}

View file

@ -0,0 +1,48 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Block_Planet_ResearchLab_Queue
extends Wootook_Empire_Block_Planet_Builder_QueueAbstract
{
public function getQueue()
{
return $this->getPlanet()->getResearchLab()->getBuilder();
}
public function isEmpty()
{
return $this->getQueue()->count() == 0;
}
}

View file

@ -0,0 +1,97 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Block_Planet_ResearchLab_Queue_Item
extends Wootook_Empire_Block_Planet_Builder_Queue_ItemAbstract
{
protected $_itemIdField = 'research_id';
public function getLevel()
{
return $this->getUser()->getElement($this->getItemId());
}
public function getResourcesNeeded($level)
{
return $this->getPlanet()->getResearchLab()->getResourcesNeeded($this->getItemId(), $this->getQueuedLevel() + 1);
}
public function getItemQueuedLevel()
{
return $this->getItem()->getData('level');
}
public function getQueuedLevel()
{
return $this->getPlanet()->getResearchLab()->getResearchLevelQueued($this->getItemId());
}
public function getBuildingTime($level)
{
return $this->getPlanet()->getResearchLab()->getBuildingTime($this->getItemId(), $level);
}
public function getResourcesConfigForLevel($level)
{
$resources = $this->getResourcesNeeded($level);
$resourceConfig = array();
foreach ($resources as $resourceId => $resourceValue) {
$resourceConfig[$resourceId] = new Wootook_Object(array(
'resource_id' => $resourceId,
'value' => $resourceValue
));
$amount = $this->getPlanet()->getResourceAmount($resourceId);
if (Math::comp($amount, $resourceValue) < 0) {
$resourceConfig[$resourceId]->setData('requirement', Math::sub($amount, $resourceValue));
} else {
$resourceConfig[$resourceId]->setData('overflow', Math::sub($amount, $resourceValue));
}
}
return $resourceConfig;
}
public function getResourcesConfigForNextLevel()
{
return $this->getResourcesConfigForLevel($this->getNextLevel());
}
public function getBuildingTimeForNextLevel()
{
return $this->getBuildingTime($this->getNextLevel());
}
}

View file

@ -0,0 +1,115 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Block_Planet_Shipyard
extends Wootook_Empire_Block_Planet_BuilderAbstract
{
protected $_planet = null;
protected $_type = Legacies_Empire::TYPE_SHIP;
protected $_allowedTypes = array(
Legacies_Empire::TYPE_SHIP,
Legacies_Empire::TYPE_DEFENSE
);
public function setPlanet(Wootook_Empire_Model_Planet $planet)
{
$this->_planet = $planet;
return $this;
}
public function getPlanet()
{
if ($this->_planet === null) {
$this->_planet = Wootook_Empire_Model_User::getSingleton()
->getCurrentPlanet()
;
}
return $this->_planet;
}
public function setAllowedTypes($types)
{
if (is_array($types)) {
$this->_allowedTypes = $types;
}
return $this;
}
public function addAllowedType($type)
{
if (!in_array($type, $this->_allowedTypes)) {
$this->_allowedTypes[] = $type;
}
return $this;
}
public function getAllowedTypes()
{
return $this->_allowedTypes;
}
public function setType($type)
{
if (in_array($type, $this->_allowedTypes)) {
$this->_type = $type;
}
return $this;
}
public function getType()
{
return $this->_type;
}
public function _initChildBlocks()
{
$types = Wootook_Empire_Model_Game_Types::getSingleton();
/** @var Wootook_Core_Block_Concat $parentBlock */
$parentBlock = $this->getLayout()->getBlock('item-list.items');
foreach ($types->getData($this->getType()) as $itemId) {
if (!$this->getPlanet()->getShipyard()->checkAvailability($itemId)) {
continue;
}
$block = $this->getItemBlock($itemId);
$parentBlock->setPartial($block->getName(), $block);
}
return $this;
}
}

View file

@ -0,0 +1,80 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Block_Planet_Shipyard_Item
extends Wootook_Empire_Block_Planet_Builder_ItemAbstract
{
public function getQty()
{
return $this->getPlanet()->getElement($this->getItemId());
}
public function getResourcesNeeded($qty)
{
return $this->getPlanet()->getShipyard()->getResourcesNeeded($this->getItemId(), $qty);
}
public function getBuildingTime($qty)
{
return $this->getPlanet()->getShipyard()->getBuildingTime($this->getItemId(), $qty);
}
public function getMaximumBuildableElementsCount()
{
return $this->getPlanet()->getShipyard()->getMaximumBuildableElementsCount($this->getItemId());
}
public function getResourcesConfigForQty($qty)
{
$resources = $this->getResourcesNeeded($qty);
$resourceConfig = array();
foreach ($resources as $resourceId => $resourceValue) {
$resourceConfig[$resourceId] = new Wootook_Object(array(
'resource_id' => $resourceId,
'value' => $resourceValue
));
$amount = $this->getPlanet()->getResourceAmount($resourceId);
if (Math::comp($amount, $resourceValue) < 0) {
$resourceConfig[$resourceId]->setData('requirement', Math::sub($amount, $resourceValue));
} else {
$resourceConfig[$resourceId]->setData('overflow', Math::sub($amount, $resourceValue));
}
}
return $resourceConfig;
}
}

View file

@ -0,0 +1,49 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Block_Planet_Shipyard_Queue
extends Wootook_Empire_Block_Planet_Builder_QueueAbstract
{
public function getQueue()
{
return $this->getPlanet()->getShipyard()->getBuilder();
}
public function isEmpty()
{
return $this->getQueue()->count() == 0;
}
}

View file

@ -0,0 +1,37 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
interface Legacies_Empire_Exception {}

View file

@ -0,0 +1,46 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Model_Planet_Building_CristalMine
implements Wootook_Empire_Model_Planet_ResourceProductionInterface, Wootook_Empire_Model_Planet_BuildingInterface
{
public function getProductionRatios($level, $produtionRatio, $planet, $user)
{
return array(
Legacies_Empire::RESOURCE_CRISTAL => 10 + 20 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio),
Legacies_Empire::RESOURCE_ENERGY => -10 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio)
);
}
}

View file

@ -0,0 +1,46 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Model_Planet_Building_DeuteriumSynthetiser
implements Wootook_Empire_Model_Planet_ResourceProductionInterface, Wootook_Empire_Model_Planet_BuildingInterface
{
public function getProductionRatios($level, $produtionRatio, $planet, $user)
{
return array(
Legacies_Empire::RESOURCE_DEUTERIUM => 10 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio),
Legacies_Empire::RESOURCE_ENERGY => -30 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio)
);
}
}

View file

@ -0,0 +1,46 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Model_Planet_Building_FusionReactor
implements Wootook_Empire_Model_Planet_ResourceProductionInterface, Wootook_Empire_Model_Planet_BuildingInterface
{
public function getProductionRatios($level, $produtionRatio, $planet, $user)
{
return array(
Legacies_Empire::RESOURCE_DEUTERIUM => -10 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio),
Legacies_Empire::RESOURCE_ENERGY => 50 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio)
);
}
}

View file

@ -0,0 +1,47 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Model_Planet_Building_MetalMine
implements Wootook_Empire_Model_Planet_ResourceProductionInterface, Wootook_Empire_Model_Planet_BuildingInterface
{
public function getProductionRatios($level, $produtionRatio, $planet, $user)
{
return array(
Legacies_Empire::RESOURCE_METAL => 20 + 30 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio),
Legacies_Empire::RESOURCE_ENERGY => -10 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio)
);
}
}

View file

@ -0,0 +1,52 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Model_Planet_Building_NaniteFactory
implements Wootook_Empire_Model_Planet_BuildingInterface
{
public static function buildingTimeListener($event)
{
$planet = $event->getData('planet');
if (!$planet->getId() || ($level = $planet->getElement(Legacies_Empire::ID_BUILDING_NANITE_FACTORY)) <= 0) {
return;
}
$time = $event->getData('time');
$speedFactor = pow(2, $level);
$event->setData('time', $time / $speedFactor);
}
}

View file

@ -0,0 +1,269 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
* 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 Wootook_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 = Wootook::now();
}
if ($destroy === false) {
$level = $this->_currentUser->getElement($researchId) + 1;
} else {
$level = max($this->_currentUser->getElement($researchId) - 1, 0);
}
// Dispatch event
Wootook::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
Wootook::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 = Wootook::now();
}
// Dispatch event
Wootook::dispatchEvent($this->_eventPrefix . 'update-queue.before', array(
'time' => &$time,
'laboratory' => $this,
'planet' => $this->_currentPlanet,
'user' => $this->_currentUser
));
$this->_builder->updateQueue($time);
// Dispatch event
Wootook::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($researchId)
{
try {
// Dispatch event
Wootook::dispatchEvent($this->_eventPrefix . 'check-availability', array(
'research_id' => $researchId,
'laboratory' => $this,
'planet' => $this->_currentPlanet,
'user' => $this->_currentUser
));
} catch (Legacies_Core_Event_Break $e) {
return false;
}
return $this->_builder->checkAvailability($researchId);
}
public function getResourcesNeeded($researchId, $level)
{
return $this->_builder->getResourcesNeeded($researchId, $level);
}
public function getResearchTime($researchId, $level)
{
$this->_builder->getBuildingTime($researchId, $level);
}
public function getResearchLevelQueued($researchId)
{
$level = $this->_currentUser->getElement($researchId);
foreach ($this->_builder as $item) {
if ($item->getData('research_id') != $researchId) {
continue;
}
$level = $item->getData('level');
}
return $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();
}
}
}
}

View file

@ -0,0 +1,252 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Model_Planet_Building_ResearchLab_Builder
extends Wootook_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
*/
protected function _initItem(Array $params)
{
if (!isset($params['technology_id']) || !isset($params['level'])) {
return null;
}
$technologyId = $params['technology_id'];
$level = $params['level'];
if (!isset($params['created_at'])) {
$createdAt = time();
} else {
$createdAt = $params['created_at'];
}
if (!isset($params['updated_at'])) {
$updatedAt = $createdAt;
} else {
$updatedAt = $params['updated_at'];
}
return new Legacies_Empire_Model_Planet_Building_ResearchLab_Item(array(
'technology_id' => $technologyId,
'level' => $level,
'created_at' => $createdAt,
'updated_at' => $updatedAt
));
}
/**
* 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 = Wootook_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 = 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');
// 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 = Wootook_Empire_Model_Game_Prices::getSingleton();
$resources = Wootook_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 = Wootook_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 = Wootook_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;
}
};

View file

@ -0,0 +1,39 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Model_Planet_Building_ResearchLab_Item
extends Wootook_Empire_Model_Builder_Item
{
}

View file

@ -0,0 +1,52 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Model_Planet_Building_RoboticFactory
implements Wootook_Empire_Model_Planet_BuildingInterface
{
public static function buildingTimeListener($event)
{
$planet = $event->getData('planet');
if (!$planet->getId() || ($level = $planet->getElement(Legacies_Empire::ID_BUILDING_ROBOTIC_FACTORY)) <= 0) {
return;
}
$time = $event->getData('time');
$speedFactor = 1 + $level;
$event->setData('time', $time / $speedFactor);
}
}

View file

@ -0,0 +1,285 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
* Shipyard building, manages ship and defenses building queue on each planet
*
* @access public
* @category Empire
* @category Planet
* @package Legacies
* @subpackage Legacies_Empire
*/
class Legacies_Empire_Model_Planet_Building_Shipyard
implements Wootook_Empire_Model_Planet_BuildingInterface
{
private $_eventPrefix = 'planet.shipyard.';
/**
* 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;
/**
* Resource list
*
* @var array
*/
protected $_resourcesTypes = array(
Legacies_Empire::RESOURCE_METAL,
Legacies_Empire::RESOURCE_CRISTAL,
Legacies_Empire::RESOURCE_DEUTERIUM,
Legacies_Empire::RESOURCE_ENERGY
);
/**
* Multiton instances
* @var array
*/
protected static $_instances = array();
/**
* Multiton factory. Retruns the planet's shipyard 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_Shipyard
*/
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_Shipyard::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_Shipyard_Builder($currentPlanet, $currentUser);
}
/**
* Returns the timestamp at the instance creation.
*
* @deprecated
* @return int
*/
protected function _now()
{
return Wootook::now();
}
/**
* @deprecated
* @return Legacies_Empire_Model_Planet_Building_Shipyard
*/
public function save()
{
$this->_currentPlanet->save();
return $this;
}
/**
* Append items to build to the construction list
*
* @param int $shipId
* @param int|string $qty
* @return Legacies_Empire_Model_Planet_Building_Shipyard
*/
public function appendQueue($shipId, $qty, $time = null)
{
if ($time === null) {
$time = Wootook::now();
}
// Dispatch event
Wootook::dispatchEvent($this->_eventPrefix . 'append-queue.before', array(
'ship_id' => $shipId,
'qty' => &$qty,
'time' => &$time,
'shipyard' => $this,
'planet' => $this->_currentPlanet,
'user' => $this->_currentUser
));
$this->_builder->appendQueue($shipId, $qty, $time);
// Dispatch event
Wootook::dispatchEvent($this->_eventPrefix . 'append-queue.before', array(
'ship_id' => $shipId,
'qty' => $qty,
'time' => $time,
'shipyard' => $this,
'planet' => $this->_currentPlanet,
'user' => $this->_currentUser
));
return $this;
}
/**
* Update the contruction queue.
*
* @return Legacies_Empire_Model_Planet_Building_Shipyard
*/
public function updateQueue($time = null)
{
if ($time === null) {
$time = Wootook::now();
}
// Dispatch event
Wootook::dispatchEvent($this->_eventPrefix . 'update-queue.before', array(
'time' => &$time,
'shipyard' => $this,
'planet' => $this->_currentPlanet,
'user' => $this->_currentUser
));
$this->_builder->updateQueue($time);
// Dispatch event
Wootook::dispatchEvent($this->_eventPrefix . 'update-queue.after', array(
'time' => $time,
'shipyard' => $this,
'planet' => $this->_currentPlanet,
'user' => $this->_currentUser
));
return $this;
}
/**
* Return the construction queue
* @see Legacies_Empire_Model_Planet_Building_Shipyard_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 $shipId
* @return bool
*/
public function checkAvailability($shipId)
{
try {
// Dispatch event
Wootook::dispatchEvent($this->_eventPrefix . 'check-availability', array(
'ship_id' => $shipId,
'shipyard' => $this,
'planet' => $this->_currentPlanet,
'user' => $this->_currentUser
));
} catch (Legacies_Core_Event_Break $e) {
return false;
}
return $this->_builder->checkAvailability($shipId);
}
/**
* Returns the maximum quantity of elements that are possible to build on
* the current planet.
*
* @param int $shipId
* @return int|string
*/
public function getMaximumBuildableElementsCount($shipId)
{
return $this->_builder->getMaximumBuildableElementsCount($shipId);
}
public function getResourcesNeeded($shipId, $qty)
{
return $this->_builder->getResourcesNeeded($shipId, $qty);
}
public function getBuildingTime($shipId, $qty)
{
return $this->_builder->getBuildingTime($shipId, $qty);
}
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 = self::factory($planet, $planet->getUser());
if ($shipyard !== null) {
$shipyard->updateQueue();
}
}
}
}

View file

@ -0,0 +1,337 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Model_Planet_Building_Shipyard_Builder
extends Wootook_Empire_Model_BuilderAbstract
{
/**
* @var int
*/
protected $_maxLength = 0;
public function init()
{
$this->_unserializeQueue($this->_currentPlanet->getData('b_hangar_id'));
}
/**
* @param int $buildingId
* @param int $qty
* @param int $time
*/
protected function _initItem(Array $params)
{
if (!isset($params['ship_id']) || !isset($params['qty'])) {
return null;
}
$shipId = $params['ship_id'];
$qty = $params['qty'];
if (!isset($params['created_at'])) {
$createdAt = time();
} else {
$createdAt = $params['created_at'];
}
if (!isset($params['updated_at'])) {
$updatedAt = $createdAt;
} else {
$updatedAt = $params['updated_at'];
}
return new Legacies_Empire_Model_Planet_Building_Shipyard_Item(array(
'ship_id' => $shipId,
'qty' => $qty,
'created_at' => $createdAt,
'updated_at' => $updatedAt
));
}
/**
* Check if a ship or defense type is actually buildable on the current
* planet, depending on the technology and buildings requirements.
*
* @param int $shipId
* @return bool
*/
public function checkAvailability($shipId)
{
$types = Wootook_Empire_Model_Game_Types::getSingleton();
if (!$types->is($shipId, Legacies_Empire::TYPE_SHIP) && !$types->is($shipId, Legacies_Empire::TYPE_DEFENSE)) {
return false;
}
parent::checkAvailability($shipId);
return true;
}
/**
* Returns the maximum quantity of elements that are possible to build on
* the current planet.
*
* @param int $shipId
* @return int|string
*/
public function getMaximumBuildableElementsCount($shipId)
{
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
$fields = Wootook_Empire_Model_Game_FieldsAlias::getSingleton();
$resources = Wootook_Empire_Model_Game_Resources::getSingleton();
$qty = 0;
foreach ($resources as $resourceId => $_) {
if (isset($prices[$shipId]) && isset($prices[$shipId][$resourceId]) && Math::comp($prices[$shipId][$resourceId], 0) > 0) {
$maxQty = Math::floor(Math::div($this->_currentPlanet->getData($resourceId), $prices[$shipId][$resourceId]));
if ($maxQty == 0) {
return 0;
}
if ($qty == 0 || Math::comp($maxQty, $qty) < 0) {
$qty = $maxQty;
}
}
}
if ($qty == 0) {
return 0;
}
$limitedElementsQty = array(
Legacies_Empire::ID_DEFENSE_SMALL_SHIELD_DOME => array(
'current' => $this->_currentPlanet[$fields[Legacies_Empire::ID_DEFENSE_SMALL_SHIELD_DOME]],
'requested' => $this->_currentPlanet[$fields[Legacies_Empire::ID_DEFENSE_SMALL_SHIELD_DOME]],
'limit' => 1
),
Legacies_Empire::ID_DEFENSE_LARGE_SHIELD_DOME => array(
'current' => $this->_currentPlanet[$fields[Legacies_Empire::ID_DEFENSE_LARGE_SHIELD_DOME]],
'requested' => $this->_currentPlanet[$fields[Legacies_Empire::ID_DEFENSE_LARGE_SHIELD_DOME]],
'limit' => 1
),
Legacies_Empire::ID_SPECIAL_ANTIBALLISTIC_MISSILE => array(
'current' => $this->_currentPlanet[$fields[Legacies_Empire::ID_SPECIAL_ANTIBALLISTIC_MISSILE]],
'requested' => $this->_currentPlanet[$fields[Legacies_Empire::ID_SPECIAL_ANTIBALLISTIC_MISSILE]],
'limit' => $this->_currentPlanet[$fields[Legacies_Empire::ID_BUILDING_MISSILE_SILO]] * 10
),
Legacies_Empire::ID_SPECIAL_INTERPLANETARY_MISSILE => array(
'current' => $this->_currentPlanet[$fields[Legacies_Empire::ID_SPECIAL_INTERPLANETARY_MISSILE]],
'requested' => $this->_currentPlanet[$fields[Legacies_Empire::ID_SPECIAL_INTERPLANETARY_MISSILE]],
'limit' => $this->_currentPlanet[$fields[Legacies_Empire::ID_BUILDING_MISSILE_SILO]] * 5
)
);
if (in_array($shipId, array_keys($limitedElementsQty))) {
foreach ($this->getQueue() as $element) {
if ($element['ship_id'] != $shipId) {
continue;
}
$limitedElementsQty[$shipId]['requested'] = Math::add($limitedElementsQty[$shipId]['requested'], $element['qty']);
if (Math::comp($limitedElementsQty[$shipId]['requested'], $limitedElementsQty[$shipId]['limit']) >= 0) {
return 0;
}
}
if (Math::comp($limitedElementsQty[$shipId]['current'], $limitedElementsQty[$shipId]['limit']) >= 0) {
return 0;
}
if (Math::comp($qty, $limitedElementsQty[$shipId]['limit']) >= 0) {
return $limitedElementsQty[$shipId]['limit'];
}
}
return $qty;
}
/**
* Returns the time needed to build $qty of $shipId
*
* @param int $shipId
* @param int $qty
*/
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');
$baseTime = Math::div($buildingTime, $speedFactor);
Math::setPrecision();
$event = Wootook::dispatchEvent('planet.shipyard.building-time', array(
'time' => $baseTime,
'base_time' => $baseTime,
'planet' => $this->_currentPlanet,
'user' => $this->_currentUser,
'ship_id' => $shipId,
'qty' => $qty
));
return $event->getData('time');
}
/**
* (non-PHPdoc)
* @see Legacies_Empire_Model_BuilderAbstract::getResourcesNeeded()
*/
public function getResourcesNeeded($shipId, $qty)
{
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
$resources = Wootook_Empire_Model_Game_Resources::getSingleton();
if (!isset($prices[$shipId])) {
return array();
}
$resourcesNeeded = array();
foreach ($resources as $resourceId => $resourceConfig) {
if (!isset($prices[$shipId][$resourceId])) {
continue;
}
if (Math::isPositive($prices[$shipId][$resourceId])) {
$resourcesNeeded[$resourceId] = Math::mul($prices[$shipId][$resourceId], $qty);
}
}
return $resourcesNeeded;
}
/**
* Returns the quantity set in parameter or the maximum buildable elements
* if the quantity requested exeeds this number.
*
* @param int $shipId
* @param int|string $qty
* @return int|stirng
*/
protected function _checkMaximumQuantity($shipId, $qty)
{
return Math::min($qty, $this->getMaximumBuildableElementsCount($shipId));
}
/**
* Update the contruction queue.
*
* @return Legacies_Empire_Model_Planet_Building_Shipyard
*/
public function updateQueue($time)
{
$fields = Wootook_Empire_Model_Game_FieldsAlias::getSingleton();
$elapsedTime = $time - $this->_currentPlanet->getData('b_hangar');
foreach ($this->getQueue() as $element) {
$shipId = $element->getData('ship_id');
$qty = $element->getData('qty');
$buildTime = $this->getBuildingTime($shipId, $qty);
if ($elapsedTime >= $buildTime) {
$this->_currentPlanet[$fields[$shipId]] = Math::add($this->_currentPlanet[$fields[$shipId]], $qty);
$elapsedTime -= $buildTime;
$this->dequeue($element);
continue;
}
$timeRatio = $elapsedTime / $buildTime;
$itemsBuilt = Math::mul($timeRatio, $qty);
$element->setData('updated_at', $time);
$element->setData('qty', Math::sub($qty, $itemsBuilt));
$this->_currentPlanet->setData($fields[$shipId], Math::add($this->_currentPlanet->getData($fields[$shipId]), $itemsBuilt));
break;
}
$this->_currentPlanet->setData('b_hangar_id', $this->serialize());
$this->_currentPlanet->setData('b_hangar', $time);
return $this;
}
/**
* Append items to build to the construction list
*
* @param int $shipId
* @param int|string $qty
* @return Legacies_Empire_Model_Planet_Building_Shipyard
*/
public function appendQueue($shipId, $qty, $time)
{
if ($this->_maxLength > 0 && $this->count() >= $this->_maxLength) {
return $this;
}
if (!Math::isPositive($qty)) {
return $this;
}
$types = Wootook_Empire_Model_Game_Types::getSingleton();
if (!$types->is($shipId, Legacies_Empire::TYPE_SHIP) && !$types->is($shipId, Legacies_Empire::TYPE_DEFENSE)) {
return $this;
}
if (!$this->checkAvailability($shipId)) {
return $this;
}
if (MAX_FLEET_OR_DEFS_PER_ROW > 0) {
$qty = Math::min($this->_checkMaximumQuantity($shipId, $qty), MAX_FLEET_OR_DEFS_PER_ROW);
} else {
$qty = $this->_checkMaximumQuantity($shipId, $qty);
}
if (!Math::isPositive($qty)) {
return $this;
}
$resourcesNeeded = $this->getResourcesNeeded($shipId, $qty);
$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;
}
}

View file

@ -0,0 +1,40 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Model_Planet_Building_Shipyard_Item
extends Wootook_Empire_Model_Builder_Item
{
}

View file

@ -0,0 +1,40 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
class Legacies_Empire_Model_Planet_Building_SolarPlant
implements Wootook_Empire_Model_Planet_ResourceProductionInterface, Wootook_Empire_Model_Planet_BuildingInterface
{
public function getProductionRatios($level, $produtionRatio, $planet, $user)
{
return array(
Legacies_Empire::RESOURCE_ENERGY => 20 * floatval($level) * pow(1.1, floatval($level)) * (0.1 * $produtionRatio)
);
}
}

View file

@ -0,0 +1,53 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Model_Planet_Ship_LargeTransport
extends Wootook_Empire_Model_Planet_ShipAbstract
{
const REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_IMPULSE_DRIVE = 4;
public function getBaseSpeed(Wootook_Empire_Model_User $user)
{
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
return $prices[Legacies_Empire::ID_SHIP_LARGE_TRANSPORT][Legacies_Empire::SHIPS_CELERITY_PRIMARY];
}
public function getSpeedMultiplier(Wootook_Empire_Model_User $user)
{
return pow(1.1, $user->getElement(Legacies_Empire::ID_RESEARCH_COMBUSTION_DRIVE));
}
}

View file

@ -0,0 +1,61 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Model_Planet_Ship_LightTransport
extends Wootook_Empire_Model_Planet_ShipAbstract
{
const REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_IMPULSE_DRIVE = 4;
public function getBaseSpeed(Wootook_Empire_Model_User $user)
{
$prices = Wootook_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(Wootook_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

@ -0,0 +1,66 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Model_Planet_Ship_SolarSatellite
extends Wootook_Empire_Model_Planet_ShipAbstract
implements Wootook_Empire_Model_Planet_ResourceProductionInterface
{
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)
);
}
public function getBaseSpeed(Wootook_Empire_Model_User $user)
{
return 0;
}
public function getSpeedMultiplier(Wootook_Empire_Model_User $user)
{
return 0;
}
public function getActualSpeed(Wootook_Empire_Model_User $user)
{
return 0;
}
public function getBaseConsumption(Wootook_Empire_Model_User $user)
{
return 0;
}
}

View file

@ -0,0 +1,77 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Empire_Model_Planet_Ship_Supernova
extends Wootook_Empire_Model_Planet_ShipAbstract
implements Wootook_Empire_Model_Planet_ResourceProductionInterface
{
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(Wootook_Empire_Model_User $user)
{
$prices = Wootook_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(Wootook_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));
}
}
public function getBaseConsumption(Wootook_Empire_Model_User $user)
{
return 0;
}
}

View file

@ -0,0 +1,37 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
interface Legacies_Exception {}

View file

@ -0,0 +1,37 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
interface Legacies_Officers_Exception {}

View file

@ -0,0 +1,70 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Officers_Model_Observer
{
public static function planetUpdateListener($eventData)
{
if (isset($eventData['planet'])) {
$planet = $eventData['planet'];
$user = $planet->getUser();
$level = floor(sqrt($user->getData('xpminier') / 500));
if ($user->getData('lvl_minier') < $level) {
$difference = $level - $user->getData('lvl_minier');
if ($difference == 1) {
Wootook::getSession(Legacies_Empire_Model_User::SESSION_KEY)
->addInfo('You gained 1 miner level.');
} else {
Wootook::getSession(Legacies_Empire_Model_User::SESSION_KEY)
->addInfo('You gained %1$d miner level.', (int) $difference);
}
}
$level = floor(sqrt($user->getData('xpraid')));
if ($user->getData('lvl_raid') < $level) {
$difference = $level - $user->getData('lvl_raid');
if ($difference == 1) {
Wootook::getSession(Legacies_Empire_Model_User::SESSION_KEY)
->addInfo('You gained 1 raider level.');
} else {
Wootook::getSession(Legacies_Empire_Model_User::SESSION_KEY)
->addInfo('You gained %1$d raider level.', (int) $difference);
}
}
}
}
}

View file

@ -0,0 +1,40 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://www.wootook.com/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero 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 Wootook.
*
*/
/**
*
* Enter description here ...
* @author Greg
*
*/
class Legacies_Officers
{
}