Location: PHPKode > projects > PhpBlock > A9.8/script/abstractobjectmanager.class.php
<?php
include_once $PATH_TO_CODE."/script/zone.class.php";
include_once $PATH_TO_CODE."/script/block.class.php";
include_once $PATH_TO_CODE."/script/realobject.class.php";
include_once $PATH_TO_CODE."/script/algorithm/a-star.class.php";
include_once $PATH_TO_CODE."/script/listener/imagemanagerlistener.class.php";

abstract class AbstractObjectManager
{
	protected static $instance=false;
	public $loadBlockInsteadOneZone=true;

	public abstract function getInstance();

	protected function __construct()
	{
		$this->zoneList = array();
		$this->blockList = array();
		$this->playerList = array();
		$this->objectList = array();
		
		$this->listeners = array();
		$this->registerEventListener(new ImageManagerListener());
	}

	public function reset() {
		unset($this->zoneList);
		unset($this->blockList);
		unset($this->playerList);
		unset($this->objectList);
		
		$this->zoneList = array();
		$this->blockList = array();
		$this->playerList = array();
		$this->objectList = array();
	}

	public function __destruct()
	{
		Log::debug("ObjectManager __destruct");
	}

	public function getBlock($parBlockId)
	{
		if(isset($this->blockList["$parBlockId"]))
		{
			Log::debug("ObjectManager getBlock $parBlockId block exists");
			return $this->blockList["$parBlockId"];
		} else {
			Log::debug("ObjectManager getBlock $parBlockId new Block");
			$locBlock = $this->createBlock($parBlockId);
			$this->blockList["$parBlockId"] = &$locBlock;
			return $locBlock;
		}
	}

	public function getZone($parZoneId)
	{
		$locZone = $this->zoneList["$parZoneId"];
		if(!isset($locZone)) {
			Log::debug("ObjectManager getZone $parZoneId not present");
			//echo "ObjectManager getZone $parZoneId not present<br>";
			if($this->loadBlockInsteadOneZone) {
				$locBlockId = Block::staticGetBlockIdWithZoneId($parZoneId);
				$this->createZoneOfBlock($locBlockId);
				$locZone = $this->zoneList["$parZoneId"];
			} else {
				$locZone = $this->createZone($parZoneId);
				$this->zoneList["$parZoneId"] = $locZone;
			}
		}
		return $locZone;
	}

	public function createZoneOfBlock($parBlockId) {
		Log::debug("ObjectManager createZoneOfBlock $parBlockId");
		$res = $this->getZoneResOfBlock($parBlockId);
		while($row = mysql_fetch_array($res)) {
			$locZone = $this->createZoneWithRow($row);
			$locZoneId = $locZone->zoneId;
			$this->zoneList["$locZoneId"] = $locZone;
		}
	}
	
	public function getRealObject($parObjectId)
	{
		$locObject = $this->objectList["$parObjectId"];
		if(!isset($locObject)) {
			$locObjectInfo = RealObject::getStaticObjectSQLRaw($parObjectId);
			if($locObjectInfo) {
				$locObject = $this->createRealObject($parObjectId, $locObjectInfo);
				$this->objectList["$parObjectId"] = $locObject;
			} else {
				$locObject = False;
			}
		}
		return $locObject;
	}
	public function getRealObjects($parObjectIds) {
		$locObjectIdToGet = array();
		$locObjectList = array();
		foreach($parObjectIds as $locObjectId) {
			$locObject = $this->objectList["$parObjectId"];
			if(!isset($locObject)) {
				array_push($locObjectIdToGet, $locObjectId);
			} else {
				array_push($locObjectList, $locObject);		
			}
		}
		$locObjectInfos = RealObject::getStaticObjectsSQLRes($locObjectIdToGet);
		while($locObjectInfo = mysql_fetch_array($locObjectInfos)) {
			$locObject = $this->createRealObject($locObjectInfo[0], $locObjectInfo);
			
			$this->objectList["$locObject->realObjectId"] = $locObject;
			
			array_push($locObjectList, $locObject);
		}
		return $locObjectList;
	}

	public function getPlayer($parPlayerId)
	{
		if(isset($this->playerList["$parPlayerId"]))
		{
			Log::debug("ObjectManager getPlayer $parPlayerId player exists");
			return $this->playerList["$parPlayerId"];
		} else {
			Log::debug("ObjectManager getPlayer $parPlayerId new Player");

			$locPlayer = $this->createPlayer($parPlayerId);
			$this->playerList["$parPlayerId"] = $locPlayer;
			return $locPlayer;
		}
	}
	public function getWeapon(&$parObject, $parWeaponNum, $parWeaponType, $parTargetId, $parAimPercentFire, $parAccurency, $parShootingRange, $parDamage) {
		return $this->createWeapon($parObject, $parWeaponNum, $parWeaponType, $parTargetId, $parAimPercentFire, $parAccurency, $parShootingRange, $parDamage);
	}

	public function getPathFinder() {
		return new AStar(25);
	}

	public function registerEventListener($parEventListener) {
		array_push($this->listeners, $parEventListener);
	}

	public function notifyEvent($parEvent) {
		foreach($this->listeners as $locListener) {
			if($locListener->supports($parEvent->getEventType())) {
				$locListener->fire($parEvent);
			}
		}
	}

	public abstract function createZoneWithRow($row);
	public abstract function getZoneResOfBlock($parBlockId);
	public abstract function createBlock($parBlockId);
	public abstract function createZone($parZoneId);
	public abstract function createPlayer($parPlayerId);
	public abstract function createNewPlayer($parPlayerName, $parEntityNameLogin, $parPlayerLogin, $parPlayerPassword, $parColor);
	public abstract function createWeapon($parObject, $parWeaponNum, $parWeaponType, $parTargetId, $parAimPercentFire, $parAccurency, $parShootingRange, $parDamage);
	public abstract function createRealObject($parObjectId, $parObjectInfo);
}
?>
Return current item: PhpBlock