Location: PHPKode > projects > PhpBlock > A9.8/modules/dungeon/unit/dungeonrealobject.class.php
<?php
include_once $PATH_TO_CODE."/script/realobject.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/dungeonfunction.php";

abstract class DungeonRealObject extends RealObject {
	public static $REAL_OBJECT_INFO_TYPE1_LEVEL=100000;

	public static $REAL_OBJECT_INFO_TYPE2_XP_POINT=100000;

	public function __construct($parObjectInfo) {
		parent::__construct($parObjectInfo);
	}
	public function getLevel() {
		return $this->getObjectInfo(DungeonRealObject::$REAL_OBJECT_INFO_TYPE1_LEVEL, DungeonRealObject::$REAL_OBJECT_INFO_TYPE2_CURRENT_POINT);
	}
	public function getXP() {
		return $this->getObjectInfo(DungeonRealObject::$REAL_OBJECT_INFO_TYPE1_LEVEL, DungeonRealObject::$REAL_OBJECT_INFO_TYPE2_XP_POINT);
	}

	public function setLevel($parNewLevel) {
		$this->setObjectInfos(
		DungeonRealObject::$REAL_OBJECT_INFO_TYPE1_LEVEL,
		DungeonRealObject::$REAL_OBJECT_INFO_TYPE2_CURRENT_POINT,
		$parNewLevel);
	}
	public function getNextLevelCost($locCurrentLevel) {
		if($locCurrentLevel >= 10) {
			$locCurrentLevel = $locCurrentLevel*1.2;
		}
		return max(2, $locCurrentLevel+1);
	}
	public function addXP($parXP) {
		$locNewXp = $parXP+$this->getXP();
		$locLevel = $this->getLevel();
		//e.g : to pass level 3 from level 2, the cost is 3 XP
		while($locNewXp - $this->getNextLevelCost($locLevel) >= 0) {
			$locNewXp -= $this->getNextLevelCost($locLevel);
			$locLevel++;

			$locMuxLife = 1.15;
			$locMuxFight = 1.15;
			$locMuxAction = 1.1;
			$locMuxLevelStepToIncreaseAccurency = 3;

			if($locLevel > 9) {
				$locMuxLife = 1.05;
				$locMuxFight = 1.05;
				$locMuxAction = 1.05;
				$locMuxLevelStepToIncreaseAccurency = 5;
			}

			$this->setObjectInfos(
			RealObject::$REAL_OBJECT_INFO_TYPE1_ACTION_POINT,
			RealObject::$REAL_OBJECT_INFO_TYPE2_MAX_POINT,
			$this->getMaxActionPoint()*$locMuxAction);

			$this->setObjectInfos(
			RealObject::$REAL_OBJECT_INFO_TYPE1_FIGHT_ACTION_POINT,
			RealObject::$REAL_OBJECT_INFO_TYPE2_MAX_POINT,
			$this->getMaxFightActionPoint()*$locMuxFight);

			$this->addObjectInfos(
			RealObject::$REAL_OBJECT_INFO_TYPE1_LIFE_POINT,
			RealObject::$REAL_OBJECT_INFO_TYPE2_MAX_POINT,
			max(1, $this->getMaxLife()*(1-$locMuxLife)));

			$this->setLife($this->getLife()*$locMuxLife);

			if(0 == $locLevel%$locMuxLevelStepToIncreaseAccurency) {
				for($i=0; $i < $this->getWeaponsCount(); $i++) {
					$this->addObjectInfos(
					RealObject::$REAL_OBJECT_INFO_TYPE1_AIM_ACCURENCY,
					$i, 1);
				}
			}
		}
		$this->setLevel($locLevel);
		$this->setObjectInfos(
		DungeonRealObject::$REAL_OBJECT_INFO_TYPE1_LEVEL,
		DungeonRealObject::$REAL_OBJECT_INFO_TYPE2_XP_POINT,
		$locNewXp);
	}
	public function increasePopulationDueToHumanKillAction() {
		global $gloObjectManager;
		$resPop=executer("SELECT zone.zoneId
		FROM block JOIN zone USING (blockId)
		WHERE zone.population > 0 AND zone.population < ".DungeonConstante::$MAX_POPULATION_PER_ZONE." 
		AND block.playerId=$this->playerId
		ORDER BY RAND()");
		$locPopulationToAdd = DungeonConstante::$POPULATION_LOSS_FOR_UNIT_CREATION*0.5;
		while(($row=mysql_fetch_array($resPop)) && $locPopulationToAdd > 0) {
			$locZone = $gloObjectManager->getZone($row[0]);
			$locPopulation = $locZone->getPopulation();
			$locPopulationToAddToThisZone = min($locPopulationToAdd, DungeonConstante::$MAX_POPULATION_PER_ZONE - $locPopulation);
			$locZone->setPopulation($locPopulation+$locPopulationToAddToThisZone);
			$locPopulationToAdd -= $locPopulationToAddToThisZone;
		}
		$this->kill(false, false, true);
	}

	public function kill($parKiller, $parSendAMessageToOwner=true, $parDeleteObject=false) {
		global $gloObjectManager;
		if(0 != $this->getHeroMode()) {
			//Create a new unit on any block
			$locPlayer = $gloObjectManager->getPlayer($this->playerId);
			$locAllBlocksId = Block::getAllBlocksId($this->playerId);
			if(count($locAllBlocksId) > 0) {
				//FIXME DO THAT AT THE LOGIN !!!!!
				$locXP = 50;
				$locBlockId = $locAllBlocksId[rand(0, count($locAllBlocksId)-1)];
				$locZone = $gloObjectManager->getZone($locBlockId);
				switch($this->realObjectType) {
					case DungeonConstante::$REAL_OBJECT_TYPE_SOLDIER:
					case DungeonConstante::$REAL_OBJECT_TYPE_GRUNT:
					case DungeonConstante::$REAL_OBJECT_TYPE_SKELETON:
						$locObject = createStandard($locZone, $locPlayer, $this->getHeroMode(), $locXP);
						break;
					case DungeonConstante::$REAL_OBJECT_TYPE_DEADWORM:
					case DungeonConstante::$REAL_OBJECT_TYPE_MINER_GRUNT:
					case DungeonConstante::$REAL_OBJECT_TYPE_MINER:
						$locObject = createDigger($locZone, $locPlayer, $this->getHeroMode(), $locXP);
						break;
					case DungeonConstante::$REAL_OBJECT_TYPE_KNIGHT:
					case DungeonConstante::$REAL_OBJECT_TYPE_WAR_GRUNT:
					case DungeonConstante::$REAL_OBJECT_TYPE_SPECTRE:
						$locObject = createWarrior($locZone, $locPlayer, $this->getHeroMode(), $locXP);
						break;
				}
				$locObject->setActionPoint(0);
				$locObject->setFightPoint(0);
				$locObject->setHeroMode(1);
			}
		}
		if($parKiller) {
			if($parKiller->getLevel() < $this->getLevel() + 10) {
				//TODO : use power of the unit ! not the upkeep
				//e.g : a unit level 1 kills an unit level 3 then it earns min(3, 6)=3Xp
				$locXpToWin =
				ceil(2*
				(max(1, $this->getLevel())/max(1, $parKiller->getLevel()))
				);
				$locXpToWin = max(1, $locXpToWin);
				$parKiller->addXP($locXpToWin);
			}
			$locPlayerOfKiller = $gloObjectManager->getPlayer($parKiller->playerId);
			$locPlayerOfKiller->addCash(pow($this->getLevel(), 0.75)*DungeonConstante::$CASH_EARN_BY_LEVEL);
		}
		parent::kill($parKiller, $parSendAMessageToOwner, $parDeleteObject);
	}
	public static function insertWeapon($parObjectId, $locWeaponNumber, $parAimPercentStartFire,
	$parAimAccurency, $parShootingRange, $parWeaponType,
	$parWeaponDamage) {
		RealObject::insertWeapon($parObjectId, $locWeaponNumber, $parAimPercentStartFire,
		$parAimAccurency, $parShootingRange, $parWeaponType,
		$parWeaponDamage);
	}
	public static function createObject($parObjectType,
	$parPlayer, $parZone, $parObjectCategory, $parIsLobotomize=false, $parDisplayPriority=1,
	$parVisibleState=0, $parCanTakeControl=1) {
		return RealObject::createObject($parObjectType,
		$parPlayer, $parZone, $parObjectCategory, $parIsLobotomize, $parDisplayPriority, $parVisibleState, $parCanTakeControl);
	}

	public function isAvailableToFindTrap() {
		return true;
	}

	public static function insertInfo($parObjectId, $parMaxPoint,
	$parLifePoint, $parShield,
	$parMaxActionPoint,
	$parMaxFightPoint,
	$parSearchActionPoint,
	$parMoveCost, $parDigCost, $parFightCost, $parUpkeepCost, $parLobotomizeCounter=0) {
		RealObject::insertInfo($parObjectId, $parMaxPoint,
		$parLifePoint, $parShield,
		$parMaxActionPoint,
		$parMaxFightPoint,
		$parMoveCost, $parDigCost, $parFightCost, $parLobotomizeCounter);
		executer("INSERT INTO objectInfo(objectId, type1, type2, value) VALUES
		($parObjectId,
                        ".RealObject::$REAL_OBJECT_INFO_TYPE1_ACTION_COST.",
                        ".RealObject::$REAL_OBJECT_INFO_TYPE2_ACTION_SEARCH_TRAP_COST.",
		$parSearchActionPoint),
		($parObjectId,
                        ".DungeonRealObject::$REAL_OBJECT_INFO_TYPE1_LEVEL.",
                        ".DungeonRealObject::$REAL_OBJECT_INFO_TYPE2_XP_POINT.",
		0),
		($parObjectId,
                        ".DungeonRealObject::$REAL_OBJECT_INFO_TYPE1_LEVEL.",
                        ".RealObject::$REAL_OBJECT_INFO_TYPE2_CURRENT_POINT.",
		1),
		($parObjectId,
                        ".RealObject::$REAL_OBJECT_INFO_TYPE1_COST.",
                        ".RealObject::$REAL_OBJECT_INFO_TYPE2_CURRENT_UPKEEP_COST.",
		$parUpkeepCost)
                        ");
	}

	protected function getExtraImageParameters() {
		$locArray = parent::getExtraImageParameters();
		array_push($locArray, "l".$this->getLevel());
		return $locArray;
	}
	public function toStringPublicInfo() {
		$locStr = parent::toStringPublicInfo();
		$locStr .= "\nlevel: ".$this->getLevel();
		return $locStr;
	}
	public function toStringMessage() {
		$locStr = parent::toStringMessage();
		$locStr .= " level: ".$this->getLevel();
		return $locStr;
	}

}
?>
Return current item: PhpBlock