Location: PHPKode > projects > PhpBlock > A9.8/modules/dungeon/tick/ownertick.class.php
<?php
include_once $PATH_TO_CODE."/script/tick/allincludefortick.php";

class OwnerTick extends Tick {
	public function getName() {
		return "Take land";
	}
	public function run() {
		global $gloObjectManager;

		$res = executer("
                        SELECT DISTINCT block.blockId
                        FROM block
                        WHERE block.isInLostOfControl=1
						AND block.allianceId > 0");
		while($row = mysql_fetch_array($res))
		{
			$locBlockId = $row[0];
			$this->testBlock($locBlockId);
		}

		//Select all block where units on it are not in same alliance
		$res = executer("
                        SELECT DISTINCT b.blockId, b.allianceId
                        FROM object o, block b
                        WHERE b.allianceId <> o.allianceId AND o.blockId = b.blockId
						AND o.canTakeControl=1
						AND b.isInLostOfControl=0
						AND b.allianceId > 0");
		while($row  = mysql_fetch_array($res)) {
			$locBlockId = $row[0];
			$locBlockAllianceId =  $row[1];
			$this->testBlock($locBlockId);
		}

		//Auto conquer gold
/*no more gold in this version
		$res = executer("
                        SELECT DISTINCT b.blockId, b.allianceId
                        FROM object o, block b, zone z
                        WHERE b.allianceId <> o.allianceId 
						AND o.blockId = b.blockId
						AND z.blockId = b.blockId
						AND o.allianceId > 1
						AND o.canTakeControl=1
						AND b.isInLostOfControl=0
						AND b.allianceId=0
						AND z.zoneType=".DungeonConstante::$ZONE_TYPE_GOLD);
		while($row  = mysql_fetch_array($res)) {
			$locBlockId = $row[0];
			$locBlockAllianceId =  $row[1];
				
			$locBlock = $gloObjectManager->getBlock($locBlockId);
			$locResOtherObject = $locBlock->getOtherAllianceObjectNear($locBlockAllianceId, 0, 0, 0);
			if($locObjectRow = mysql_fetch_array($locResOtherObject)) {
				$locObject = $gloObjectManager->getRealObject($locObjectRow[0]);
				$locObjectAllianceId = $locObject->allianceId;
				$locObjectPlayerId = $locObject->playerId;
				//echo "$locBlockId $locObjectPlayerId $locObjectAllianceId<br>";
					
				if(0 == $locBlockAllianceId && $locObjectPlayerId > 1) {//No owner for the block, ignore monster player
					if($locBlock->containsGoldAndIsOwnableForAllianceId($locObjectAllianceId)) {
						$locBlock->setPlayerId($locObjectPlayerId);
					}
				}
			}
		}
*/
	}
	public function testBlock($locBlockId) {
		global $gloObjectManager;
		$locBlock = $gloObjectManager->getBlock($locBlockId);
		if($locBlock->testIsInLostOfControl()) {
			//Player loses his block
			if(!$locBlock->isInLostOfControl()) {
				$locBlock->setLostOfControl(DungeonConstante::$DEFAULT_TIME_TO_LOST_CONTROL);
			}
		} else {
			//Player has full possession of his block if it has at least one unit on it
			if($locBlock->isInLostOfControl()) {
				if(mysql_fetch_array($locBlock->getAllianceObjectNear($locBlock->allianceId))) {
					$locBlock->removeLostOfControl();
				}
			}
		}
		if($locBlock->isInLostOfControl()) {
			if($locBlock->getLostOfControlTime() <= 1) {
				$locOwner = $gloObjectManager->getPlayer($locBlock->playerId);
				if($locOwner) {
					$locOwnerName = $locOwner->playerName;
				} else {
					$locOwnerName = "unknown";
				}
				//TODO : send message to other unit of player ?
				$locPlayersIdList = $locBlock->getPlayersIdAround(3, 3, 2);
				foreach($locPlayersIdList as $locPlayerId) {
					if($locPlayerId == $locBlock->playerId) {
						PlayerMessage::getInstance()->addPlayerInfo($locPlayerId, "you lost your control on one of your block", PlayerMessage::$VERY_BAD, $locBlock->blockId);
					} else {
						
						PlayerMessage::getInstance()->addPlayerInfo($locPlayerId, "$locOwnerName losts his control on a block", PlayerMessage::$GOOD, $locBlock->blockId);
					}
				}
				//For each population case, you earn pillage
				$res = executer("SELECT * FROM zone WHERE blockId=$locBlock->blockId AND population > 0");
				while(mysql_fetch_array($res)) {
					$locOwner->addCash2(DungeonConstante::$PILLAGE_EVIL_POINTS_EARNED);
				}
				$locBlock->lostOfControl();
			} else  {
				$locBlock->removeLostOfControlTime(1);
			}
		} 
	}
}
?>
Return current item: PhpBlock