Location: PHPKode > projects > PhpBlock > A9.8/modules/dungeon/objectmanager.class.php
<?php
include_once $PATH_TO_CODE."/script/abstractobjectmanager.class.php";
include_once $PATH_TO_CODE."/script/realobject.class.php";
include_once $PATH_TO_CODE."/script/weapon.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/dungeonzone.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/dungeonblock.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/dungeonplayer.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/unit/ork/grunt.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/unit/ork/minerork.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/unit/ork/warork.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/unit/human/soldier.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/unit/human/miner.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/unit/human/knight.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/unit/undead/skeleton.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/unit/undead/deadworm.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/unit/undead/spectre.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/unit/monster/monsternest.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/unit/trap.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/unit/rallypoint.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/weapontrap.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/algorithm/dungeon-a-star.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/listener/unithasmovelistener.class.php";

include_once $PATH_TO_CODE."/modules/basicfog/listener/foglistener.class.php";

class ObjectManager extends AbstractObjectManager
{
	function getInstance()
	{
		if(!AbstractObjectManager::$instance) {
			AbstractObjectManager::$instance = new ObjectManager();
		}
		return AbstractObjectManager::$instance;
	}

	protected function __construct()
	{
		parent::__construct();
		if(DungeonConstante::$FOW_IS_ACTIVATED) {
			$this->registerEventListener(new FogListener());
		}
		if(DungeonConstante::$AUTO_CONQUER_ON_MOVE_IS_ACTIVATED) {
			$this->registerEventListener(new UnitHasMoveListener());
		}
	}

	public function createNewPlayer($parPlayerName, $parEntityNameLogin, $parPlayerLogin, $parPlayerPassword, $parColor) {
		return Player::create($parPlayerName, $parEntityNameLogin, $parPlayerLogin, $parPlayerPassword, $parColor);
	}

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

	public function createBlock($parBlockId) {
		return new DungeonBlock($parBlockId);
	}
	public function createZoneWithRow($row) {
		$locZone = new DungeonZone();
		DungeonZone::staticGetZoneWithRow($locZone, $row);
		return $locZone;
	}
	public function getZoneResOfBlock($parBlockId) {
		return DungeonZone::staticGetResForBlockId($parBlockId);
	}
	public function createZone($parZoneId) {
		return new DungeonZone($parZoneId);
	}
	public function createPlayer($parPlayerId) {
		return new DungeonPlayer($parPlayerId);
	}
	public function createWeapon($parObject, $parWeaponNum, $parWeaponType, $parTargetId, $parAimPercentFire, $parAccurency, $parShootingRange, $parDamage) {
		switch($parWeaponType) {
			case Weapon::$WEAPON_TYPE_TRAP:
				return new WeaponTrap($parObject, $parWeaponNum, $parTargetId, $parAimPercentFire, $parAccurency, $parShootingRange, $parDamage);
				break;
			default:
				return new Weapon($parObject, $parWeaponNum, $parTargetId, $parAimPercentFire, $parAccurency, $parShootingRange, $parDamage);
		}
	}
	public function createRealObject($parObjectId, $parObjectInfo) {
		//$locObjectInfo = RealObject::getStaticObjectSQLRaw($parObjectId);
		if($parObjectInfo) {
			//TODO cache system
			switch($parObjectInfo["objectType"]) {
				case DungeonConstante::$REAL_OBJECT_TYPE_SKELETON:
					return new Skeleton($parObjectInfo);
				case DungeonConstante::$REAL_OBJECT_TYPE_SPECTRE:
					return new Spectre($parObjectInfo);
				case DungeonConstante::$REAL_OBJECT_TYPE_DEADWORM:
					return new DeadWorm($parObjectInfo);
				case DungeonConstante::$REAL_OBJECT_TYPE_GRUNT:
					return new Grunt($parObjectInfo);
				case DungeonConstante::$REAL_OBJECT_TYPE_WAR_GRUNT:
					return new WarOrk($parObjectInfo);
				case DungeonConstante::$REAL_OBJECT_TYPE_MINER_GRUNT:
					return new MinerOrk($parObjectInfo);
				case DungeonConstante::$REAL_OBJECT_TYPE_SOLDIER:
					return new Soldier($parObjectInfo);
				case DungeonConstante::$REAL_OBJECT_TYPE_KNIGHT:
					return new Knight($parObjectInfo);
				case DungeonConstante::$REAL_OBJECT_TYPE_MINER:
					return new Miner($parObjectInfo);
				case DungeonConstante::$REAL_OBJECT_TYPE_TRAP:
					return new Trap($parObjectInfo);
				case DungeonConstante::$REAL_OBJECT_TYPE_RALLY_POINT:
					return new RallyPoint($parObjectInfo);
				case DungeonConstante::$REAL_OBJECT_TYPE_MONSTER_NEST:
					return new MonsterNest($parObjectInfo);
				default:
					return new RealObject($parObjectInfo);
			}
		} else {
			return False;
		}
	}

	public function getImageURL($parSize, $parArrayOfImage, $parAllianceColor="000000", $parPlayerColor="000000", $parAlpha=127) {
		$res = "modules/dungeon/imageobject.php?size=$parSize&p=";
		for($i = 0; $i < count($parArrayOfImage)-1; $i++) {
			$res = "$res".$parArrayOfImage[$i].Constante::$SEP_URL_4;
		}
		$res = "$res".$parArrayOfImage[count($parArrayOfImage)-1];
		$res = "$res".Constante::$SEP_URL_5."$parAlpha";
		$res = "$res".Constante::$SEP_URL_5."$parAllianceColor";
		$res = "$res".Constante::$SEP_URL_5."$parPlayerColor";
		return $res;
	}

	public function getImageDefaultPaths($parImageParameters) {
		$locImageDefaultPaths = array();
		//echo $parImageParameters."<br/>";
		$locArrayOfImageType = explode(Constante::$SEP_URL_5, $parImageParameters);
		//echo count($locArrayOfImageType)."<br/>";
		if(count($locArrayOfImageType) > 1) {
			$locAllianceColor = array_pop($locArrayOfImageType);
		} else {
			$locAllianceColor = "000000";
		}
		if(count($locArrayOfImageType) > 1) {
			$locPlayerColor = array_pop($locArrayOfImageType);
		} else {
			$locPlayerColor = "000000";
		}
		if(count($locArrayOfImageType) > 1) {
			$locAlpha = array_pop($locArrayOfImageType);
		} else {
			$locAlpha = 127;
		}
		//echo "alpha: $locAlpha<br/>";

		$locArrayOfImageType = explode(Constante::$SEP_URL_4, $locArrayOfImageType[0]);
		foreach($locArrayOfImageType as $locImageType) {
			//echo $locImageType."<br/>";
			array_push($locImageDefaultPaths, ObjectManager::getInstance()->getImageDefaultPath($locImageType));
		}
		array_push($locImageDefaultPaths, $locPlayerColor);
		array_push($locImageDefaultPaths, $locAllianceColor);
		array_push($locImageDefaultPaths, $locAlpha);
		//echo $locAllianceColor."<br/>";
		//echo $locPlayerColor."<br/>";
		//echo $locAlpha." --- <br/>";

		return $locImageDefaultPaths;
	}

	public function getImageDefaultPath($parImageType)
	{
		global $PATH_TO_IMAGE;
		if($parImageType[0] == 'l') {
			//counter
			$locCounter = min(10, substr($parImageType, 1));
			$locImagePath = $PATH_TO_IMAGE."/object/level/level$locCounter.png";
		} else if($parImageType[0] == 'c') {
			//counter
			$locCounter = substr($parImageType, 1);
			$locImagePath = $PATH_TO_IMAGE."/object/counter/$locCounter.png";
		} else if($parImageType[0] == 'b') {
			//is in a battle
			$locImagePath = $PATH_TO_IMAGE."/object/battle.png";
		} else if($parImageType[0] == 'm') {
			//is in a battle
			$locImagePath = $PATH_TO_IMAGE."/object/moveflag.png";
		} else {
			//TODO : create an array
			switch($parImageType)
			{
				case DungeonConstante::$REAL_OBJECT_INFO_VALUE_MONSTER_NEST_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/monsternest.png";
					break;
				case RealObject::$REAL_OBJECT_INFO_VALUE_BACKGROUND_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/background.png";
					break;
				case DungeonConstante::$REAL_OBJECT_INFO_VALUE_SOLDIER_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/soldier.png";
					break;
				case DungeonConstante::$REAL_OBJECT_INFO_VALUE_KNIGHT_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/knight.png";
					break;
				case DungeonConstante::$REAL_OBJECT_INFO_VALUE_MINER_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/miner.png";
					break;
				case DungeonConstante::$REAL_OBJECT_INFO_VALUE_SKELETON_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/skeleton.png";
					break;
				case DungeonConstante::$REAL_OBJECT_INFO_VALUE_SPECTRE_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/spectre.png";
					break;
				case DungeonConstante::$REAL_OBJECT_INFO_VALUE_DEADWORM_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/deadworm.png";
					break;
				case DungeonConstante::$REAL_OBJECT_INFO_VALUE_GRUNT_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/grunt.png";
					break;
				case DungeonConstante::$REAL_OBJECT_INFO_VALUE_WAR_ORK_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/warork.png";
					break;
				case DungeonConstante::$REAL_OBJECT_INFO_VALUE_MINER_GRUNT_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/minerork.png";
					break;
				case DungeonConstante::$REAL_OBJECT_INFO_VALUE_TRAP_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/trap.png";
					break;
				case RealObject::$REAL_OBJECT_INFO_VALUE_TEMPORARY_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/nuclearboum.png";
					break;
				case RealObject::$REAL_OBJECT_INFO_VALUE_EXPLOSION_TYPE_1_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/nuclearboum.png";
					break;
				case RealObject::$REAL_OBJECT_INFO_VALUE_HURT_TYPE_1_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/blood-small.png";
					break;
				case RealObject::$REAL_OBJECT_INFO_VALUE_HURT_TYPE_2_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/blood-medium.png";
					break;
				case RealObject::$REAL_OBJECT_INFO_VALUE_HURT_TYPE_3_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/blood-large.png";
					break;
				case RealObject::$REAL_OBJECT_INFO_VALUE_HURT_TYPE_4_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/blood-full.png";
					break;
				case RealObject::$REAL_OBJECT_INFO_VALUE_HURT_TYPE_HIT_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/blood-hit.png";
					break;
				case RealObject::$REAL_OBJECT_INFO_VALUE_RIP_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/rip.png";
					break;
				case DungeonConstante::$REAL_OBJECT_INFO_VALUE_RALLY_POINT_IMAGE:
					$locImagePath = $PATH_TO_IMAGE."/object/rallypoint/rallypoint.png";
					break;
				default:
					$locImagePath = $PATH_TO_IMAGE."/object/defaultobject.png";
			}
		}
		return $locImagePath;
	}
	public function getPathFinder($parMaxStep=250, $parMaxRange=25, $parGlobalAvoidUnitCostMux=1.0) {
		//TODO uniform with script
		$locAStar = new DungeonAStar($parMaxStep, $parMaxRange);
		$locAStar->globalAvoidUnitCostMux = $parGlobalAvoidUnitCostMux;
		return $locAStar;
	}
}
$gloObjectManager = ObjectManager::getInstance();
?>
Return current item: PhpBlock