<?php
include_once $PATH_TO_CODE."/modules/dungeon/action/abstractaction.class.php";
abstract class DungeonAbstractChangeZoneTypeAction extends DungeonAbstractAction {
function __construct($parActionType, $parNewZoneType, $parCost=0, $parChangeZoneNearBlock=false,
$parTestEnnemiesForBuilding=true) {
parent::__construct($parActionType);
$this->newZoneType = $parNewZoneType;
$this->cost = $parCost;
$this->changeZoneNearBlock = $parChangeZoneNearBlock;
$this->testEnnemiesForBuilding = $parTestEnnemiesForBuilding;
}
public function action($parZoneActionArray) {
$locManageAction = ManageAction::getInstance();
$locPlayer = $locManageAction->getPlayer();
if($this->getZoneAndBlock($parZoneActionArray, $locZone, $locBlock)) {
$this->block = $locBlock;
$this->zone = $locZone;
if($this->isOkToChange($locBlock, $locZone)) {
$this->setNewZoneType($locZone);
}
}
}
//problem of ennemy and build near block ...
public function isOkToChange($locBlock, $locZone) {
$locManageAction = ManageAction::getInstance();
$locPlayer = $locManageAction->getPlayer();
if($locBlock->playerId==$locPlayer->playerId) {
if($this->testEnnemiesForBuilding) {
if($locBlock->testIsInLostOfControlForAllianceId($locPlayer->allianceId)) {
$locManageAction->addPlayerInfo("You are losing this block, you can't change anything on it");
return false;
} else if($locBlock->isOtherAllianceObjectNear($locPlayer->allianceId, 1, 1, 1)) {
$locManageAction->addPlayerInfo("Enemies are present in a range of 1 blocks, you can't change anything on this zone");
return false;
}
}
return $this->verifyPlayerEnoughCash($this->getCost());
} else if($locBlock->playerId == 0) {
if($this->testEnnemiesForBuilding) {
if($locBlock->isOtherAllianceObjectNear($locPlayer->allianceId, 2, 2, 2)) {
$locManageAction->addPlayerInfo("Enemies are present in a range of 2 blocks, you can't change anything on this zone");
return false;
} else if($locBlock->isOtherAllianceBlockNear($locPlayer->allianceId, 1, 1, 1)) {
$locManageAction->addPlayerInfo("At least one enemy is adjacent of this block, you can't change anything on it");
return false;
}
}
return $this->verifyPlayerEnoughCash($this->getCost());
} else {
$locManageAction->addPlayerInfo("You are not authorized to build here");
}
return false;
}
public function getCost(){
return $this->cost;
}
public function setNewZoneType($parZone) {
$locManageAction = ManageAction::getInstance();
$locPlayer = $locManageAction->getPlayer();
$locPlayer->addCash(-$this->getCost());
$locPlayer->addShame($this->shameCost);
$parZone->setZoneType($this->newZoneType);
$locManageAction->addPlayerInfo("New zone type: ".DungeonZone::staticGetZoneTypeToString($this->newZoneType).", cost: $this->cost");
}
}
?>