Location: PHPKode > projects > PhpBlock > A9.8/modules/dungeon/action/spell/recruitspell.class.php
<?php
include_once $PATH_TO_CODE."/modules/dungeon/action/spell/dungeonabstractspell.class.php";
include_once $PATH_TO_CODE."/modules/dungeon/algorithm/monsterchoiceaction.class.php";

class RecruitSpellAction extends DungeonAbstractSpellAction {
	function __construct() {
		parent::__construct(DungeonConstante::$ACTION_RECRUIT_SPELL, DungeonConstante::$ACTION_BUY_RECRUIT_SPELL_COST, true);
	}
	protected function doAction($parZoneActionArray, $locZone, $locBlock) {
		global $gloObjectManager;
		$locMoveAlgo = $gloObjectManager->getPathFinder(100, 20, 4.0);
		$locMoveAlgo->globalReturnLastChoiceOnFailure = true;

		$locMonsterChoiceAction = new MonsterChoiceAction($locMoveAlgo);
		$locManageAction = ManageAction::getInstance();
		$locPlayer = $locManageAction->getPlayer();
		if($locPlayer->playerId == $locBlock->playerId) {
			if($locBlock->isInLostOfControl()) {
				$locManageAction->addPlayerInfo("You can't recruit from blocks in lost of control");
			} if($locBlock->getPopulation() < DungeonConstante::$POPULATION_LOSS_FOR_UNIT_CREATION) {
				$locManageAction->addPlayerInfo("You haven't enough population to recruit on this block");
			} else {
				$locManageAction->addPlayerInfo("You recruit units from population");
				for($i=0; $i < 3; $i++) {
					if(!$this->recruitAUnit($locPlayer, $locBlock, $locMonsterChoiceAction)) {
						break;
					}
				}
			}
		} else {
			$locManageAction->addPlayerInfo("You can't recruit from blocks that you don't own");
		}
		return true;
	}
	private function recruitAUnit($locPlayer, $locBlock, $locMonsterChoiceAction) {
		global $gloObjectManager;
		$locManageAction = ManageAction::getInstance();

		$locPopulationToRemove = DungeonConstante::$POPULATION_LOSS_FOR_UNIT_CREATION;
		//FIXME faire un recrutement dans un rayon de 1 block ?
		$res=executer("SELECT zoneId FROM zone WHERE population > 0 AND blockId=$locBlock->blockId ORDER BY population DESC");
		while($locPopulationToRemove > 0 && $row=mysql_fetch_array($res)) {
			$locZone = $gloObjectManager->getZone($row[0]);
			if(!$locZone->isOccuped()) {
				$locObject = createRandomUnit($locZone, $locPlayer, DungeonConstante::calculateXpUnitAboutPopulation($locBlock->getAveragePopulation()));
				$locMonsterChoiceAction->choiceAction($locObject);
				$locPopulationToRemoveToThisZone = min($locPopulationToRemove, $locZone->getPopulation());
				$locZone->setPopulation($locZone->getPopulation()-$locPopulationToRemoveToThisZone);
				$locPopulationToRemove -= $locPopulationToRemoveToThisZone;
				$locManageAction->addPlayerInfo("create unit with level ".$locObject->getLevel());
				return true;
			}
		}
		return false;
	}
}
?>
Return current item: PhpBlock