Refactored to 2 namespaces: Wootook & Legacies
Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
parent
cfeb6aca6d
commit
ec7e40e1aa
1004 changed files with 4808 additions and 2971 deletions
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Model_Builder_Break
|
||||
extends Exception
|
||||
{
|
||||
|
||||
}
|
||||
19
application/code/core/Wootook/Empire/Model/Builder/Item.php
Normal file
19
application/code/core/Wootook/Empire/Model/Builder/Item.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Model_Builder_Item
|
||||
extends Wootook_Object
|
||||
{
|
||||
protected $_index = null;
|
||||
|
||||
public function getIndex()
|
||||
{
|
||||
return $this->_index;
|
||||
}
|
||||
|
||||
public function setIndex($index)
|
||||
{
|
||||
$this->_index = $index;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
247
application/code/core/Wootook/Empire/Model/BuilderAbstract.php
Normal file
247
application/code/core/Wootook/Empire/Model/BuilderAbstract.php
Normal file
|
|
@ -0,0 +1,247 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Empire_Model_BuilderAbstract
|
||||
implements Countable, Serializable, Iterator
|
||||
{
|
||||
/**
|
||||
* Planet instance
|
||||
* @var Wootook_Empire_Model_Planet
|
||||
*/
|
||||
protected $_currentPlanet = null;
|
||||
|
||||
/**
|
||||
* User instance
|
||||
* @var Wootook_Empire_Model_User
|
||||
*/
|
||||
protected $_currentUser = null;
|
||||
|
||||
/**
|
||||
* construction queue
|
||||
* @var array
|
||||
*/
|
||||
protected $_queue = null;
|
||||
|
||||
/**
|
||||
* construction queue
|
||||
* @var array
|
||||
*/
|
||||
protected $_itemClass = 'Wootook_Empire_Model_Builder_Item';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Wootook_Empire_Model_Planet $currentPlanet
|
||||
* @param Wootook_Empire_Model_User $currentUser
|
||||
*/
|
||||
public function __construct(Wootook_Empire_Model_Planet $currentPlanet, Wootook_Empire_Model_User $currentUser)
|
||||
{
|
||||
$this->_currentPlanet = $currentPlanet;
|
||||
$this->_currentUser = $currentUser;
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
abstract public function init();
|
||||
|
||||
abstract protected function _initItem(Array $params);
|
||||
|
||||
public function enqueue($params, $index = null)
|
||||
{
|
||||
$item = $this->_initItem($params);
|
||||
if ($item === null) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($index === null) {
|
||||
$index = $this->_generateIndex();
|
||||
}
|
||||
$item->setIndex($index);
|
||||
$this->_queue[$index] = $item;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function dequeue($item)
|
||||
{
|
||||
unset($this->_queue[$item->getIndex()]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _generateIndex()
|
||||
{
|
||||
return uniqid();
|
||||
}
|
||||
|
||||
public function getItem($itemIndex)
|
||||
{
|
||||
if (isset($this->_queue[$itemIndex])) {
|
||||
return $this->_queue[$itemIndex];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function _serializeQueue()
|
||||
{
|
||||
$serialize = array();
|
||||
foreach ($this->_queue as $itemIndex => $itemInstance) {
|
||||
$serialize[$itemIndex] = $itemInstance->getAllDatas();
|
||||
}
|
||||
return serialize($serialize);
|
||||
}
|
||||
|
||||
protected function _unserializeQueue($serialized)
|
||||
{
|
||||
$this->clearQueue();
|
||||
|
||||
$unserialized = @unserialize($serialized);
|
||||
if ($unserialized === false) {
|
||||
$this->_queue = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
foreach ($unserialized as $itemIndex => $itemData) {
|
||||
$this->enqueue($itemData, $itemIndex);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->_serializeQueue();
|
||||
}
|
||||
|
||||
public function getQueue()
|
||||
{
|
||||
return $this->_queue;
|
||||
}
|
||||
|
||||
public function clearQueue()
|
||||
{
|
||||
$this->_queue = array();
|
||||
}
|
||||
|
||||
abstract public function updateQueue($time);
|
||||
abstract public function appendQueue($typeId, $qty, $time);
|
||||
|
||||
/**
|
||||
* Check if an item type is actually buildable on the current
|
||||
* planet, depending on the technology and buildings requirements.
|
||||
*
|
||||
* @param int $typeId
|
||||
* @return bool
|
||||
*/
|
||||
public function checkAvailability($typeId)
|
||||
{
|
||||
$types = Wootook_Empire_Model_Game_Types::getSingleton();
|
||||
$requirements = Wootook_Empire_Model_Game_Requirements::getSingleton();
|
||||
|
||||
if (!isset($requirements[$typeId]) || empty($requirements[$typeId])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($requirements[$typeId] as $requirement => $level) {
|
||||
if ($types->is($requirement, Legacies_Empire::TYPE_BUILDING) && $this->_currentPlanet->hasElement($requirement, $level)) {
|
||||
continue;
|
||||
} else if ($types->is($requirement, Legacies_Empire::TYPE_RESEARCH) && $this->_currentUser->hasElement($requirement, $level)) {
|
||||
continue;
|
||||
} else if ($types->is($requirement, Legacies_Empire::TYPE_DEFENSE) && $this->_currentPlanet->hasElement($requirement, $level)) {
|
||||
continue;
|
||||
} else if ($types->is($requirement, Legacies_Empire::TYPE_SHIP) && $this->_currentPlanet->hasElement($requirement, $level)) {
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
abstract public function getResourcesNeeded($typeId, $level);
|
||||
abstract public function getBuildingTime($typeId, $level);
|
||||
|
||||
public function serialize()
|
||||
{
|
||||
return $this->_serializeQueue();
|
||||
}
|
||||
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
$this->_unserializeQueue($serialized);
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return count($this->_queue);
|
||||
}
|
||||
|
||||
public function current()
|
||||
{
|
||||
return current($this->_queue);
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
return next($this->_queue);
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return key($this->_queue);
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return current($this->_queue) !== false;
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
reset($this->_queue);
|
||||
}
|
||||
|
||||
public function getCurrentPlanet()
|
||||
{
|
||||
return $this->_currentPlanet;
|
||||
}
|
||||
|
||||
public function getCurrentUser()
|
||||
{
|
||||
return $this->_currentUser;
|
||||
}
|
||||
|
||||
public function setCurrentPlanet(Wootook_Empire_Model_Planet $planet)
|
||||
{
|
||||
$this->_currentPlanet = $planet;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setCurrentUser(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
$this->_currentUser = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _calculateResourceRemainingAmounts($resourceNeeded)
|
||||
{
|
||||
$resourceAmounts = array();
|
||||
foreach ($resourceNeeded as $resourceId => $resourceAmount) {
|
||||
$resourceAmounts[$resourceId] = Math::sub($this->_currentPlanet[$resourceId], $resourceAmount);
|
||||
if (Math::isNegative($resourceAmounts[$resourceId])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $resourceAmounts;
|
||||
}
|
||||
|
||||
protected function _calculateResourceReclaimedAmounts($resourceNeeded)
|
||||
{
|
||||
$resourceAmounts = array();
|
||||
foreach ($resourceNeeded as $resourceId => $resourceAmount) {
|
||||
$resourceAmounts[$resourceId] = Math::add($this->_currentPlanet[$resourceId], $resourceAmount);
|
||||
}
|
||||
return $resourceAmounts;
|
||||
}
|
||||
}
|
||||
155
application/code/core/Wootook/Empire/Model/Fleet.php
Normal file
155
application/code/core/Wootook/Empire/Model/Fleet.php
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Fleet
|
||||
extends Wootook_Core_Entity
|
||||
{
|
||||
protected static $_instances = array();
|
||||
|
||||
protected $_eventPrefix = 'fleet';
|
||||
protected $_eventObject = 'fleet';
|
||||
|
||||
public static function factory($id)
|
||||
{
|
||||
if ($id === null) {
|
||||
return new self();
|
||||
}
|
||||
|
||||
$id = intval($id);
|
||||
if (!isset(self::$_instances[$id])) {
|
||||
$instance = new self();
|
||||
$params = func_get_args();
|
||||
call_user_func_array(array($instance, 'load'), $params);
|
||||
self::$_instances[$id] = $instance;
|
||||
}
|
||||
return self::$_instances[$id];
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->setIdFieldName('fleet_id');
|
||||
$this->setTableName('fleets');
|
||||
}
|
||||
|
||||
public static function planetListener($eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public function isOwnedBy(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
if ($this->getData('fleet_owner') == $user->getId()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getOwner()
|
||||
{
|
||||
if ($id = $this->getData('fleet_owner')) {
|
||||
return Wootook_Empire_Model_User::factory($id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function isMission($missionType)
|
||||
{
|
||||
if ($this->getData('fleet_mission') == $missionType) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getRowClass(Wootook_Empire_Model_User $user = null)
|
||||
{
|
||||
if ($this->isMission(Legacies_Empire::ID_MISSION_ATTACK) || $this->isMission(Legacies_Empire::ID_MISSION_GROUP_ATTACK)) {
|
||||
if ($user !== null && $this->isOwnedBy($user)) {
|
||||
return 'attack';
|
||||
} else {
|
||||
return 'ownattack';
|
||||
}
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_TRANSPORT)) {
|
||||
return 'transport';
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_STATION) || $this->isMission(Legacies_Empire::ID_MISSION_STATION_ALLY)) {
|
||||
return 'station';
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_SETTLE_COLONY)) {
|
||||
return 'settle';
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_RECYCLE)) {
|
||||
return 'recycle';
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_DESTROY)) {
|
||||
return 'destroy';
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_MISSILES)) {
|
||||
return 'missiles';
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_EXPEDITION)) {
|
||||
return 'expedition';
|
||||
}
|
||||
}
|
||||
|
||||
public function getMissionLabel()
|
||||
{
|
||||
if ($this->isMission(Legacies_Empire::ID_MISSION_ATTACK) || $this->isMission(Legacies_Empire::ID_MISSION_GROUP_ATTACK)) {
|
||||
return Wootook::__('Attack');
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_TRANSPORT)) {
|
||||
return Wootook::__('Transport');
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_STATION) || $this->isMission(Legacies_Empire::ID_MISSION_STATION_ALLY)) {
|
||||
return Wootook::__('Station');
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_SETTLE_COLONY)) {
|
||||
return Wootook::__('Settle');
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_RECYCLE)) {
|
||||
return Wootook::__('Recycle');
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_DESTROY)) {
|
||||
return Wootook::__('Destroy');
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_MISSILES)) {
|
||||
return Wootook::__('Missiles Launch');
|
||||
} else if ($this->isMission(Legacies_Empire::ID_MISSION_EXPEDITION)) {
|
||||
return Wootook::__('Expedition');
|
||||
}
|
||||
return Legacies::__('Unknown');
|
||||
}
|
||||
|
||||
public function getStartTime()
|
||||
{
|
||||
return $this->getData('fleet_start_time');
|
||||
}
|
||||
|
||||
public function getActionTime()
|
||||
{
|
||||
return $this->getData('fleet_end_stay');
|
||||
}
|
||||
|
||||
public function getArrivalTime()
|
||||
{
|
||||
if ($this->isMission(Legacies_Empire::ID_MISSION_STATION) || $this->isMission(Legacies_Empire::ID_MISSION_STATION_ALLY)) {
|
||||
return $this->getActionTime();
|
||||
}
|
||||
return $this->getData('fleet_end_time');
|
||||
}
|
||||
|
||||
public function getOriginPlanet()
|
||||
{
|
||||
$coords = array(
|
||||
'galaxy' => $this->getData('fleet_start_galaxy'),
|
||||
'system' => $this->getData('fleet_start_system'),
|
||||
'position' => $this->getData('fleet_start_planet')
|
||||
);
|
||||
$type = $this->getData('fleet_start_type');
|
||||
|
||||
return Wootook_Empire_Model_Planet::factoryFromCoords($coords, $type);
|
||||
}
|
||||
|
||||
public function getDestinationPlanet()
|
||||
{
|
||||
$coords = array(
|
||||
'galaxy' => $this->getData('fleet_end_galaxy'),
|
||||
'system' => $this->getData('fleet_end_system'),
|
||||
'position' => $this->getData('fleet_end_planet')
|
||||
);
|
||||
$type = $this->getData('fleet_end_type');
|
||||
|
||||
return Wootook_Empire_Model_Planet::factoryFromCoords($coords, $type);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Model_Galaxy_Position
|
||||
extends Wootook_Core_Entity_SubTable
|
||||
{
|
||||
protected function _init()
|
||||
{
|
||||
$this->_tableName = 'galaxy';
|
||||
$this->_idFieldNames = array('id_planet');
|
||||
}
|
||||
|
||||
static function initPlanetListerner($eventData)
|
||||
{
|
||||
if (!isset($eventData['planet'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$planet = $eventData['planet'];
|
||||
if (!$planet->isPlanet()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$galaxy = new self();
|
||||
$galaxy
|
||||
->setData('galaxy', $planet->getGalaxy())
|
||||
->setData('system', $planet->getSystem())
|
||||
->setData('planet', $planet->getPosition())
|
||||
->setData('id_planet', $planet->getId())
|
||||
->save()
|
||||
;
|
||||
}
|
||||
}
|
||||
47
application/code/core/Wootook/Empire/Model/Game/Combat.php
Normal file
47
application/code/core/Wootook/Empire/Model/Game/Combat.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Game_Combat
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('combat');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Game_FieldsAlias
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('fields-alias');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
47
application/code/core/Wootook/Empire/Model/Game/Prices.php
Normal file
47
application/code/core/Wootook/Empire/Model/Game/Prices.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Game_Prices
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('prices');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Game_Production
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('production');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Game_Requirements
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('requirements');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Game_Resources
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('resources');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
55
application/code/core/Wootook/Empire/Model/Game/Types.php
Normal file
55
application/code/core/Wootook/Empire/Model/Game/Types.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_Game_Types
|
||||
extends Wootook_Core_Model_Config_Abstract
|
||||
implements Wootook_Core_Singleton
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_initData('types');
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function is($element, $type)
|
||||
{
|
||||
if (!is_array($this->getData($type))) {
|
||||
return false;
|
||||
}
|
||||
return in_array($element, $this->getData($type));
|
||||
}
|
||||
}
|
||||
1037
application/code/core/Wootook/Empire/Model/Planet.php
Normal file
1037
application/code/core/Wootook/Empire/Model/Planet.php
Normal file
File diff suppressed because it is too large
Load diff
272
application/code/core/Wootook/Empire/Model/Planet/Builder.php
Normal file
272
application/code/core/Wootook/Empire/Model/Planet/Builder.php
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Model_Planet_Builder
|
||||
extends Wootook_Empire_Model_BuilderAbstract
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->_unserializeQueue($this->_currentPlanet->getData('b_building_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
*/
|
||||
protected function _initItem(Array $params)
|
||||
{
|
||||
if (!isset($params['building_id']) || !isset($params['level'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$buildingId = $params['building_id'];
|
||||
$level = $params['level'];
|
||||
|
||||
if (!isset($params['created_at'])) {
|
||||
$createdAt = time();
|
||||
} else {
|
||||
$createdAt = $params['created_at'];
|
||||
}
|
||||
|
||||
if (!isset($params['started_at'])) {
|
||||
$startedAt = null;
|
||||
} else {
|
||||
$startedAt = $params['started_at'];
|
||||
}
|
||||
|
||||
if (!isset($params['updated_at'])) {
|
||||
$updatedAt = $createdAt;
|
||||
} else {
|
||||
$updatedAt = $params['updated_at'];
|
||||
}
|
||||
|
||||
return new Wootook_Empire_Model_Planet_Builder_Item(array(
|
||||
'building_id' => $buildingId,
|
||||
'level' => $level,
|
||||
'created_at' => $createdAt,
|
||||
'started_at' => $startedAt,
|
||||
'updated_at' => $updatedAt
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a building is actually buildable on the current planet,
|
||||
* depending on the technology and buildings requirements.
|
||||
*
|
||||
* @param int $buildingId
|
||||
* @return bool
|
||||
*/
|
||||
public function checkAvailability($buildingId)
|
||||
{
|
||||
$types = Wootook_Empire_Model_Game_Types::getSingleton();
|
||||
|
||||
if ($types->is($buildingId, Legacies_Empire::TYPE_BUILDING)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getBuildingTime($buildingId, $level)
|
||||
{
|
||||
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
|
||||
$gameConfig = Wootook_Core_Model_Config::getSingleton();
|
||||
|
||||
Math::setPrecision(50);
|
||||
$firstLevelTime = $prices[$buildingId][Legacies_Empire::BASE_BUILDING_TIME];
|
||||
$partialLevelTime = Math::mul($firstLevelTime, Math::pow($prices[$buildingId][Legacies_Empire::RESOURCE_MULTIPLIER], $level));
|
||||
$levelTime = Math::sub($partialLevelTime, $firstLevelTime);
|
||||
|
||||
$speedFactor = $gameConfig->getData('game_speed');
|
||||
$baseTime = $levelTime / $speedFactor * 3600;
|
||||
|
||||
Math::setPrecision();
|
||||
|
||||
$event = Wootook::dispatchEvent('planet.building.building-time', array(
|
||||
'time' => $baseTime,
|
||||
'base_time' => $baseTime,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser,
|
||||
'building_id' => $buildingId,
|
||||
'level' => $level
|
||||
));
|
||||
|
||||
return $event->getData('time');
|
||||
}
|
||||
|
||||
public function getResourcesNeeded($buildingId, $level)
|
||||
{
|
||||
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
|
||||
$resources = Wootook_Empire_Model_Game_Resources::getSingleton();
|
||||
|
||||
if (!isset($prices[$buildingId])) {
|
||||
return array();
|
||||
}
|
||||
$resourcesNeeded = array();
|
||||
foreach ($resources as $resourceId => $resourceConfig) {
|
||||
if (!isset($prices[$buildingId][$resourceId])) {
|
||||
continue;
|
||||
}
|
||||
if (Math::isPositive($prices[$buildingId][$resourceId])) {
|
||||
$firstLevelCost = $prices[$buildingId][$resourceId];
|
||||
$resourcesNeeded[$resourceId] = Math::mul($firstLevelCost, Math::pow($prices[$buildingId][Legacies_Empire::RESOURCE_MULTIPLIER], $level));
|
||||
}
|
||||
}
|
||||
|
||||
return $resourcesNeeded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the contruction queue.
|
||||
*
|
||||
* @return Wootook_Empire_Model_Planet_Building_Shipyard
|
||||
*/
|
||||
public function updateQueue($time)
|
||||
{
|
||||
$fields = Wootook_Empire_Model_Game_FieldsAlias::getSingleton();
|
||||
|
||||
$startingTime = $this->_currentPlanet->getData('b_building');
|
||||
|
||||
foreach ($this->getQueue() as $element) {
|
||||
$elementTime = $element->getData('started_at');
|
||||
|
||||
if ($elementTime === null) {
|
||||
$element->setData('started_at', $startingTime);
|
||||
$elementTime = $startingTime;
|
||||
}
|
||||
|
||||
$level = $element->getData('level');
|
||||
$buildingId = $element->getData('building_id');
|
||||
$buildTime = $this->getBuildingTime($buildingId, $level);
|
||||
$elapsedTime = $time - $elementTime;
|
||||
|
||||
if ($elapsedTime >= $buildTime) {
|
||||
$this->_currentPlanet->updateResources($time - $elapsedTime);
|
||||
$this->_currentPlanet->setElement($buildingId, $level);
|
||||
$this->_currentPlanet->updateResourceProduction($time - $elapsedTime);
|
||||
$this->_currentPlanet->updateStorages($time - $elapsedTime);
|
||||
$this->_currentPlanet->updateBuildingFields();
|
||||
|
||||
$this->dequeue($element);
|
||||
|
||||
Wootook::dispatchEvent('planet.building.level-update', array(
|
||||
'time' => $time - $elapsedTime,
|
||||
'planet' => $this->_currentPlanet,
|
||||
'user' => $this->_currentUser,
|
||||
'building_id' => $buildingId,
|
||||
'level' => $level
|
||||
));
|
||||
|
||||
$startingTime = $elementTime + $buildTime;
|
||||
continue;
|
||||
}
|
||||
|
||||
$element->setData('updated_at', $time);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_currentPlanet->setData('b_building_id', $this->serialize());
|
||||
$this->_currentPlanet->setData('b_building', $startingTime);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append items to build to the construction list
|
||||
*
|
||||
* @param int $buildingId
|
||||
* @param int|string $level
|
||||
* @return Wootook_Empire_Model_Planet_Building_Shipyard
|
||||
*/
|
||||
public function appendQueue($buildingId, $level, $time)
|
||||
{
|
||||
$types = Wootook_Empire_Model_Game_Types::getSingleton();
|
||||
$resources = Wootook_Empire_Model_Game_Resources::getSingleton();
|
||||
|
||||
if (!Math::isPositive($level)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!$types->is($buildingId, Legacies_Empire::TYPE_BUILDING)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!$this->checkAvailability($buildingId)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$resourcesNeeded = $this->getResourcesNeeded($buildingId, $level);
|
||||
$remainingAmounts = $this->_calculateResourceRemainingAmounts($resourcesNeeded);
|
||||
if ($remainingAmounts === false) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($this->count() == 0) {
|
||||
$this->_currentPlanet->setData('b_building', $time);
|
||||
}
|
||||
|
||||
$this->enqueue(array(
|
||||
'building_id' => $buildingId,
|
||||
'level' => $level,
|
||||
'created_at' => $time
|
||||
));
|
||||
$this->_currentPlanet->setData('b_building_id', $this->serialize());
|
||||
|
||||
foreach ($remainingAmounts as $resourceId => $resourceAmount) {
|
||||
$this->_currentPlanet[$resourceId] = $resourceAmount;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dequeues the first item to build to the construction list and removes all
|
||||
* its successors of the same type.
|
||||
*
|
||||
* @return Wootook_Empire_Model_Planet_Builder
|
||||
*/
|
||||
public function dequeueFirstItem()
|
||||
{
|
||||
$this->rewind();
|
||||
$item = $this->current();
|
||||
|
||||
return $this->dequeueItem($item->getIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* Dequeues an item to build to the construction list and removes all its
|
||||
* successors of the same type.
|
||||
*
|
||||
* @param string $itemId
|
||||
* @return Wootook_Empire_Model_Planet_Builder
|
||||
*/
|
||||
public function dequeueItem($itemId)
|
||||
{
|
||||
$item = $this->getItem($itemId);
|
||||
if (!$item) {
|
||||
return $this;
|
||||
}
|
||||
$buildingId = $item->getData('building_id');
|
||||
|
||||
$keys = array_keys($this->_queue);
|
||||
$size = count($keys);
|
||||
$start = array_search($item->getIndex(), $keys);
|
||||
for ($i = $start; $i < $size; $i++) {
|
||||
$index = $keys[$i];
|
||||
if ($this->_queue[$index]->getData('building_id') != $buildingId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$resourcesNeeded = $this->getResourcesNeeded($buildingId, $this->_queue[$index]->getData('level'));
|
||||
$reclaimedAmounts = $this->_calculateResourceReclaimedAmounts($resourcesNeeded);
|
||||
|
||||
$this->dequeue($this->_queue[$index]);
|
||||
|
||||
foreach ($reclaimedAmounts as $resourceId => $resourceAmount) {
|
||||
$this->_currentPlanet[$resourceId] = $resourceAmount;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_currentPlanet->setData('b_building_id', $this->serialize());
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Model_Planet_Builder_Item
|
||||
extends Wootook_Empire_Model_Builder_Item
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
interface Wootook_Empire_Model_Planet_BuildingInterface
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Model_Planet_Exception implements Wootook_Empire_Exception {}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Model_Planet_PluginLoader
|
||||
extends Wootook_Core_Plugin_LoaderAbstract
|
||||
{
|
||||
protected $_currentUser = null;
|
||||
protected $_currentPlanet = null;
|
||||
|
||||
public function __construct($currentPlanet, $currentUser)
|
||||
{
|
||||
$this->_currentUser = $currentUser;
|
||||
$this->_currentPlanet = $currentPlanet;
|
||||
}
|
||||
|
||||
protected function _load($className, $useSingleton)
|
||||
{
|
||||
$reflection = new ClassReflection($className);
|
||||
if ($useSingleton && $reflection->implementsInterface('Wootook_Core_Singleton')) {
|
||||
$method = $reflection->getMethod('getSingleton');
|
||||
$method->invoke();
|
||||
}
|
||||
|
||||
try {
|
||||
return $reflection->invoke($this->_currentPlanet, $this->_currentUser);
|
||||
} catch (ReflectionException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
interface Wootook_Empire_Model_Planet_ResourceProductionInterface
|
||||
{
|
||||
public function getProductionRatios($level, $produtionRatio, $planet, $user);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Empire_Model_Planet_ShipAbstract
|
||||
implements Wootook_Empire_Model_Planet_ShipInterface
|
||||
{
|
||||
public function getBaseSpeed(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
$prices = Wootook_Empire_Model_Game_Prices::getSingleton();
|
||||
|
||||
return $prices[Legacies_Empire::ID_SHIP_SUPERNOVA][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));
|
||||
}
|
||||
|
||||
public function getActualSpeed(Wootook_Empire_Model_User $user)
|
||||
{
|
||||
return $this->getBaseSpeed($user) * $this->getSpeedMultiplier($user);
|
||||
}
|
||||
|
||||
public function getActualConsumption(Wootook_Empire_Model_User $user, $speed)
|
||||
{
|
||||
return $this->getBaseConsumption($user) * ($speed / 100) * $this->getSpeedMultiplier($user);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
interface Wootook_Empire_Model_Planet_ShipInterface
|
||||
{
|
||||
public function getBaseSpeed(Wootook_Empire_Model_User $user);
|
||||
public function getSpeedMultiplier(Wootook_Empire_Model_User $user);
|
||||
public function getActualSpeed(Wootook_Empire_Model_User $user);
|
||||
|
||||
public function getBaseConsumption(Wootook_Empire_Model_User $user);
|
||||
public function getActualConsumption(Wootook_Empire_Model_User $user, $speed);
|
||||
}
|
||||
538
application/code/core/Wootook/Empire/Model/User.php
Normal file
538
application/code/core/Wootook/Empire/Model/User.php
Normal file
|
|
@ -0,0 +1,538 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
*
|
||||
* @uses Wootook_Object
|
||||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Empire_Model_User
|
||||
extends Wootook_Core_Entity
|
||||
{
|
||||
protected static $_instances = array();
|
||||
|
||||
protected static $_singleton = null;
|
||||
|
||||
protected $_eventPrefix = 'user';
|
||||
protected $_eventObject = 'user';
|
||||
|
||||
public static $hashCallback = 'md5';
|
||||
|
||||
protected $_homePlanet = null;
|
||||
protected $_currentPlanet = null;
|
||||
|
||||
const SESSION_KEY = 'user';
|
||||
const COOKIE_NAME = 'Wootook';
|
||||
const COOKIE_LIFETIME = 2592000;
|
||||
|
||||
const PLANET_SORT_DATE = 0;
|
||||
const PLANET_SORT_POSITION = 1;
|
||||
const PLANET_SORT_NAME = 2;
|
||||
|
||||
protected static $_cookieName = self::COOKIE_NAME;
|
||||
|
||||
public static function setCookieName($name)
|
||||
{
|
||||
self::$_cookieName = $name;
|
||||
}
|
||||
|
||||
public static function factory($id)
|
||||
{
|
||||
if ($id === null) {
|
||||
return new self();
|
||||
}
|
||||
|
||||
$id = intval($id);
|
||||
if (!isset(self::$_instances[$id])) {
|
||||
$instance = new self();
|
||||
$params = func_get_args();
|
||||
call_user_func_array(array($instance, 'load'), $params);
|
||||
self::$_instances[$id] = $instance;
|
||||
}
|
||||
return self::$_instances[$id];
|
||||
}
|
||||
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->getData('username');
|
||||
}
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
$session = Wootook::getSession(self::SESSION_KEY);
|
||||
if ($session->hasData('user_id')) {
|
||||
$id = intval($session->getData('user_id'));
|
||||
} else if (Wootook::getRequest() !== null && ($cookie = Wootook::getRequest()->getCookie(self::$_cookieName)) !== null) {
|
||||
$cookieData = unserialize(stripslashes($cookie));
|
||||
if (is_array($cookieData)) {
|
||||
$collection = new Wootook_Core_Collection(array('user' => 'users'));
|
||||
$cookieData = array(
|
||||
'id' => (isset($cookieData['id']) ? intval($cookieData['id']) : 0),
|
||||
'key' => (isset($cookieData['key']) ? $collection->quote($cookieData['key']) : null)
|
||||
);
|
||||
|
||||
$collection
|
||||
->column('id')
|
||||
->where('user.id=:id')
|
||||
->where(':key=CONCAT((@salt:=MID(:key, 0, 4)), SHA1(CONCAT(user.username, user.password, @salt)))')
|
||||
->load($cookieData)
|
||||
;
|
||||
|
||||
if ($collection->count() > 0) {
|
||||
$session->setData(self::SESSION_KEY, $cookieData['id']);
|
||||
} else {
|
||||
$session->addError('Your session has expired, please login.');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$session->addError('Your session has expired, please login.');
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
self::$_singleton = self::factory($id);
|
||||
} catch (Wootook_Core_Exception_DataAccessException $e) {
|
||||
$session->addError('Session error.');
|
||||
return null;
|
||||
}
|
||||
self::$_singleton->_updateActivity();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
public static function hash($password, $salt = null)
|
||||
{
|
||||
if ($salt === null) {
|
||||
return call_user_func(self::$hashCallback, ($password));
|
||||
}
|
||||
|
||||
return call_user_func(self::$hashCallback, ($password . $salt));
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->setIdFieldName('id');
|
||||
$this->setTableName('users');
|
||||
}
|
||||
|
||||
protected function _updateActivity()
|
||||
{
|
||||
$this
|
||||
->setData('current_page', $_SERVER['REQUEST_URI'])
|
||||
->setData('user_lastip', $_SERVER['REMOTE_ADDR'])
|
||||
->setData('user_agent', $_SERVER['HTTP_USER_AGENT'])
|
||||
->setData('onlinetime', time())
|
||||
->save()
|
||||
;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
Wootook::getResponse()->unsetCookie(self::$_cookieName);
|
||||
Wootook_Core_Model_Session::destroy();
|
||||
}
|
||||
|
||||
public static function login($username, $password, $remember = false)
|
||||
{
|
||||
$session = Wootook::getSession(self::SESSION_KEY);
|
||||
|
||||
try {
|
||||
$collection = new Wootook_Core_Collection(array('user' => 'users'));
|
||||
|
||||
$passwordHash = md5($password);
|
||||
$collection
|
||||
->column('user.id')
|
||||
->column('user.username')
|
||||
->column('user.password')
|
||||
->column('user.banaday')
|
||||
->column('CONCAT((@salt:=MID(MD5(RAND()), 0, 4)), SHA1(CONCAT(user.username, user.password, @salt))) AS login_rememberme')
|
||||
->column('(CASE WHEN user.password="' . $passwordHash . '" THEN 1 ELSE 0 END) AS login_success')
|
||||
->where('user.username=:username')
|
||||
->load(array(
|
||||
'username' => $username
|
||||
))
|
||||
;
|
||||
} catch (Wootook_Core_Exception_DataAccessException $e) {
|
||||
Wootook_Core_ErrorProfiler::getSingleton()->exceptionManager($e);
|
||||
$session->addError('No such user.');
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($collection->count() <= 0) {
|
||||
$session->addError('No such user.');
|
||||
return null;
|
||||
}
|
||||
$login = $collection->current();
|
||||
|
||||
if (intval($login['login_success']) == 1) {
|
||||
if ($login['banaday'] != 0) {
|
||||
if($login['banaday'] <= time()) {
|
||||
$user->setData('banaday', 0)
|
||||
->setData('bana', 0)
|
||||
->setData('urlaubs_modus', 0)
|
||||
->save()
|
||||
;
|
||||
} else {
|
||||
$session->addError('You were banned, please contact admin for more information.');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST["rememberme"]) && Wootook::getRequest() !== null) {
|
||||
Wootook::$response->setCookie(self::$_cookieName, array('id' => $login['id'], 'key' => $login['login_rememberme']), self::COOKIE_LIFETIME);
|
||||
}
|
||||
|
||||
self::$_singleton = self::factory($login['id']);
|
||||
self::$_singleton->_updateActivity();
|
||||
|
||||
$session->setData('user_id', intval($login['id']));
|
||||
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
$session->addError('Your username or credential is invalid, please check your input.');
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function register($username, $email, $password)
|
||||
{
|
||||
try {
|
||||
$request = Wootook::getRequest();
|
||||
$user = new self(array(
|
||||
'username' => $username,
|
||||
'password' => md5($password),
|
||||
'email' => $email,
|
||||
'email_2' => $email,
|
||||
|
||||
'register_time' => Wootook::now(),
|
||||
'onlinetime' => Wootook::now(),
|
||||
'ip_at_reg' => $request->getServer('REMOTE_ADDR'),
|
||||
'user_lastip' => $request->getServer('REMOTE_ADDR'),
|
||||
'user_agent' => $request->getServer('HTTP_USER_AGENT')
|
||||
));
|
||||
|
||||
$user->save();
|
||||
|
||||
Wootook::dispatchEvent('user.init', array(
|
||||
'user' => $user
|
||||
));
|
||||
|
||||
$user->save();
|
||||
} catch (Wootook_Core_Exception_DataAccessException $e) {
|
||||
echo $e->getTraceAsString();
|
||||
$session->addError($e->getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param int|Wootook_Empire_Model_Planet $planet
|
||||
*/
|
||||
public function updateCurrentPlanet($planet)
|
||||
{
|
||||
if (!$planet instanceof Wootook_Empire_Model_Planet) {
|
||||
$planetCollection = $this->_preparePlanetCollection()->where('id=:id');
|
||||
|
||||
$planetCollection->load(array(
|
||||
'id' => $planet,
|
||||
'user' => $this->getId()
|
||||
));
|
||||
|
||||
if ($planetCollection->count() !== 1) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$planet = $planetCollection->current();
|
||||
}
|
||||
|
||||
if ($planet->getUserId() != $this->getId() || $planet->isDestroyed()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->setData('current_planet', $planet->getId())->save();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param Wootook_Empire_Model_Planet $planet
|
||||
*/
|
||||
public function setHomePlanet(Wootook_Empire_Model_Planet $planet)
|
||||
{
|
||||
if ($planet->getUserId() != $this->getId() || $planet->isDestroyed()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->setData('id_planet', $planet->getId());
|
||||
$this->_homePlanet = $planet;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @param Wootook_Empire_Model_Planet $planet
|
||||
*/
|
||||
public function setCurrentPlanet(Wootook_Empire_Model_Planet $planet)
|
||||
{
|
||||
if ($planet->getUserId() != $this->getId() || $planet->isDestroyed()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->setData('current_planet', $planet->getId());
|
||||
$this->_currentPlanet = $planet;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @return Wootook_Empire_Model_Planet
|
||||
*/
|
||||
public function getHomePlanet()
|
||||
{
|
||||
if ($this->_homePlanet === null) {
|
||||
$planetId = $this->getData('id_planet');
|
||||
if (!$planetId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$planet = Wootook_Empire_Model_Planet::factory($planetId);
|
||||
|
||||
if ($planet->getUserId() != $this->getId() || $planet->isDestroyed()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->_homePlanet = $planet;
|
||||
}
|
||||
|
||||
return $planet;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter description here ...
|
||||
* @return Wootook_Empire_Model_Planet
|
||||
*/
|
||||
public function getCurrentPlanet()
|
||||
{
|
||||
if ($this->_currentPlanet === null) {
|
||||
$planetId = $this->getData('current_planet');
|
||||
|
||||
if (!$planetId) {
|
||||
$this->_currentPlanet = $this->getHomePlanet();
|
||||
$this->setData('current_planet', $this->_currentPlanet->getId())->save();
|
||||
|
||||
return $this->_currentPlanet;
|
||||
}
|
||||
|
||||
$planet = Wootook_Empire_Model_Planet::factory($planetId);
|
||||
|
||||
if ($planet->getUserId() != $this->getId() || $planet->isDestroyed()) {
|
||||
$this->_currentPlanet = $this->getHomePlanet();
|
||||
$this->setData('current_planet', $this->_currentPlanet->getId())->save();
|
||||
|
||||
return $this->_currentPlanet;
|
||||
}
|
||||
|
||||
$this->_currentPlanet = $planet;
|
||||
}
|
||||
|
||||
return $this->_currentPlanet;
|
||||
}
|
||||
|
||||
protected function _preparePlanetCollection()
|
||||
{
|
||||
$planetCollection = new Wootook_Core_Collection(array('planet' => 'planets'), 'Wootook_Empire_Model_Planet');
|
||||
$planetCollection->where('id_owner=:user');
|
||||
|
||||
$order = ($this->getData('planet_sort_order') == 1) ? 'DESC' : 'ASC';
|
||||
|
||||
switch ($this->getData('planet_sort')) {
|
||||
case self::PLANET_SORT_POSITION:
|
||||
$planetCollection
|
||||
->order('planet.galaxy', $order)
|
||||
->order('planet.system', $order)
|
||||
->order('planet.planet', $order)
|
||||
->order('planet.planet_type', $order)
|
||||
;
|
||||
break;
|
||||
|
||||
case self::PLANET_SORT_NAME:
|
||||
$planetCollection->order('planet.name', $order);
|
||||
break;
|
||||
|
||||
case self::PLANET_SORT_DATE:
|
||||
default:
|
||||
$planetCollection->order('planet.id', $order);
|
||||
break;
|
||||
}
|
||||
return $planetCollection;
|
||||
}
|
||||
|
||||
public function getPlanetCollection()
|
||||
{
|
||||
$planetCollection = $this->_preparePlanetCollection();
|
||||
|
||||
$planetCollection->load(array(
|
||||
'user' => $this->getId()
|
||||
));
|
||||
|
||||
return $planetCollection;
|
||||
}
|
||||
|
||||
protected function _prepareFleetCollection()
|
||||
{
|
||||
$collection = new Wootook_Core_Collection(array('fleet' => 'fleets'));
|
||||
$collection
|
||||
->setEntityClassName('Wootook_Empire_Model_Fleet')
|
||||
->where('fleet_owner <= :user_id')
|
||||
;
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function getFleets()
|
||||
{
|
||||
return $this->_prepareFleetCollection()->load(array('user_id' => $this->getId()));
|
||||
}
|
||||
|
||||
public function getFleetCount()
|
||||
{
|
||||
return $this->_prepareFleetCollection()->getSize(array('user_id' => $this->getId()));
|
||||
}
|
||||
|
||||
public function getVisibleFleets()
|
||||
{
|
||||
|
||||
$user = Wootook_Empire_Model_User::getSingleton();
|
||||
$firstCollection = new Wootook_Core_Collection(array('fleet' => 'fleets'));
|
||||
$firstCollection
|
||||
// ->column('*')
|
||||
->column('fleet.fleet_start_galaxy', 'galaxy')
|
||||
->column('fleet.fleet_start_system', 'system')
|
||||
->column('fleet.fleet_start_planet', 'planet')
|
||||
->column('fleet.fleet_start_type', 'planet_type')
|
||||
->where('fleet_end_time <= :now')
|
||||
;
|
||||
$backCollection = new Wootook_Core_Collection(array('fleet' => 'fleets'));
|
||||
$backCollection
|
||||
// ->column('*')
|
||||
->column('fleet.fleet_end_galaxy', 'galaxy')
|
||||
->column('fleet.fleet_end_system', 'system')
|
||||
->column('fleet.fleet_end_planet', 'planet')
|
||||
->column('fleet.fleet_end_type', 'planet_type')
|
||||
->where('fleet_end_time <= :now')
|
||||
;
|
||||
$collection = new Wootook_Core_Collection();
|
||||
$collection
|
||||
->setEntityClassName('Wootook_Empire_Model_Fleet')
|
||||
->union($firstCollection)
|
||||
->union($backCollection)
|
||||
->load(array('now' => time()));
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function getElement($elementId)
|
||||
{
|
||||
$fields = Wootook_Empire_Model_Game_FieldsAlias::getSingleton();
|
||||
|
||||
return $this->getData($fields[$elementId]);
|
||||
}
|
||||
|
||||
public function setElement($elementId, $level)
|
||||
{
|
||||
$fields = Wootook_Empire_Model_Game_FieldsAlias::getSingleton();
|
||||
|
||||
return $this->setData($fields[$elementId], $level);
|
||||
}
|
||||
|
||||
public function hasElement($elementId, $levelRequired = 0)
|
||||
{
|
||||
$fields = Wootook_Empire_Model_Game_FieldsAlias::getSingleton();
|
||||
|
||||
return $this->hasData($fields[$elementId]) && Math::comp($this->getElement($elementId), $levelRequired) > 0;
|
||||
}
|
||||
|
||||
public function getSkinPath($default = null)
|
||||
{
|
||||
if ($path = $this->getData('dpath')) {
|
||||
return $path;
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function setSkinPath($path)
|
||||
{
|
||||
$this->setData('dpath', $path);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function checkPassword($password)
|
||||
{
|
||||
if (self::hash($password) == $this->getData('password')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFleetCollection($time = null)
|
||||
{
|
||||
$firstCollection = new Wootook_Core_Collection(array('fleet' => 'fleets'));
|
||||
$firstCollection
|
||||
->column('*')
|
||||
->where('fleet.fleet_owner = :user')
|
||||
;
|
||||
$backCollection = new Wootook_Core_Collection(array('fleet' => 'fleets'));
|
||||
$backCollection
|
||||
->column('*')
|
||||
->where('fleet.fleet_target_owner = :user')
|
||||
;
|
||||
|
||||
$options = array(
|
||||
'user' => $this->getId()
|
||||
);
|
||||
|
||||
if ($time !== null) {
|
||||
$options['now'] = $time;
|
||||
$firstCollection->where('fleet_start_time <= :now');
|
||||
$backCollection->where('fleet_end_time <= :now');
|
||||
}
|
||||
|
||||
$collection = new Wootook_Core_Collection();
|
||||
$collection
|
||||
->setEntityClassName('Wootook_Empire_Model_Fleet')
|
||||
->union($firstCollection)
|
||||
->union($backCollection)
|
||||
->load($options)
|
||||
;
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function getNewMessagesCount()
|
||||
{
|
||||
$messageCollection = new Wootook_Core_Collection('messages');
|
||||
$messageCollection->where('message_owner=:user');
|
||||
$messageCollection->where('message_read_at<=0');
|
||||
|
||||
$newMessages = null;
|
||||
if (($count = $messageCollection->getSize(array('user' => $this->getId()))) > 0) {
|
||||
return $count;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
14
application/code/core/Wootook/Empire/Model/User/Message.php
Normal file
14
application/code/core/Wootook/Empire/Model/User/Message.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Empire_Model_User_Message
|
||||
extends Wootook_Core_Entity_SubTable
|
||||
{
|
||||
protected $_eventObject = 'message';
|
||||
protected $_eventPrefix = 'user.message';
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_tableName = 'messages';
|
||||
$this->_idFieldNames = array('message_id', 'message_owner');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue