Location: PHPKode > projects > PhpBlock > A9.8/modules/dungeon/action/abstractrecruitaction.class.php
<?php
include_once $PATH_TO_CODE."/modules/dungeon/action/abstractaction.class.php";

abstract class DungeonAbstractRecruitAction extends DungeonAbstractAction {
	function __construct($parActionType, $parCost,
	$parIsBarrackNecessary=true, $parTargetMustNotOccuped=true) {
		parent::__construct($parActionType);
		$this->isBarrackNecessary = $parIsBarrackNecessary;
		$this->cost = $parCost;
		$this->targetMustNotOccuped = $parTargetMustNotOccuped;
	}

	public function isBarrackNear($parZone) {
		if (count($parZone->getAllZoneIdOfZoneType(DungeonConstante::$ZONE_TYPE_BARRACK, 1, 1, 1)) > 0) {
			return true;
		} else {
			ManageAction::getInstance()->addPlayerInfo("No near barrack");
			return false;
		}
	}

	public function action($parZoneActionArray) {
		$locManageAction = ManageAction::getInstance();
		$locPlayer = $locManageAction->getPlayer();
		if($this->getZoneAndBlock($parZoneActionArray, $locZone, $locBlock)) {
			if($this->isOkToRecruit($locBlock, $locZone, $locPlayer)) {
				if($this->costIsCash2) {
					$locPlayer->addCash2(-$this->cost);
				} else {
					$locPlayer->addCash(-$this->cost);
				}
				$locObjectId = $this->create($locZone, $locPlayer);
				if($locObjectId) {
					global $gloObjectManager;
					$locObject = $gloObjectManager->getRealObject($locObjectId);
					$locObject->setActionPoint(0);
					$locObject->setFightPoint(0);
				}
			}
		}
	}
	
	public function getCost() {
		return $this->cost;
	}

	public function isBlockMustBeOwnByPlayer() {
		return true;
	}
	
	public function isOkToRecruit($locBlock, $locZone, $locPlayer) {
		$locManageAction = ManageAction::getInstance();
		$locPlayer = $locManageAction->getPlayer();
		if($locBlock->playerId==$locPlayer->playerId || !$this->isBlockMustBeOwnByPlayer()) {
			if($this->targetMustNotOccuped && $locZone->isOccuped()) {
				$locManageAction->addPlayerInfo("zone is occupied");
				return false;
			}
			if($this->isBarrackNecessary) {
				if(!$this->isBarrackNear($locZone)) {
					return false;
				}
			}
			return $this->verifyPlayerEnoughCash($this->cost);
		} else {
			$locManageAction->addPlayerInfo(" Target is not yours");
		}
		return false;
	}
	public abstract function create($locZone, $locPlayer);
}
?>
Return current item: PhpBlock