private function automove($alvo)
 {
     if ($this->autolevantar()) {
         return false;
     }
     if ($this->autoequipar()) {
         return false;
     }
     $caminho = Mapa::encontrarCaminho($this->getPos(), $alvo->getPos());
     $proximo = Mapa::getPosString($caminho[0]);
     //echo "Proximo passo: <b>$proximo->x.$proximo->y</b></br />";
     //var_dump($proximo);
     //echo "<br />";
     $sentido = Mapa::getSentido($this->getPos(), $proximo);
     $podeAtacar = false;
     $limit = 0;
     //$esquerda = (5 - $this->sentido) - $sentido;
     //$esquerda = $this->sentido - $sentido;
     //$esquerda = $sentido + $this->sentido;
     //if ($direita > 5) $direita -= 5;
     //if ($esquerda > 5) $esquerda -= 5;
     //if ($direita < 0) $direita = 5 + $direita;
     //if ($esquerda < 0) $esquerda = 5 + $esquerda;
     if ($sentido > $this->sentido) {
         $direita = $sentido - $this->sentido;
         $esquerda = 6 - $direita;
     } else {
         $esquerda = $this->sentido - $sentido;
         $direita = 6 - $esquerda;
     }
     while ($sentido != $this->sentido && $this->getDeslocamentoRestante() > 0) {
         if ($direita <= $esquerda) {
             $this->mover(MV_DIREITA);
         } else {
             $this->mover(MV_ESQUERDA);
         }
         if ($limit >= 100) {
             break;
         }
         $limit++;
         //echo "Sentido: ".$this->sentido.", ir para <b>$sentido</b>, D=$direita, E=$esquerda<br />";
     }
     //echo "Sentido Atual: $this->sentido<br />";
     $alcanceMaximo = $this->alcanceMaximo();
     foreach (Mapa::emAlcance($this->x, $this->y, $alcanceMaximo) as $area) {
         if (!is_null($area->getPersonagem())) {
             //echo $area->getPersonagem()->getNome()." no alcance.<br />";
             if ($area->getPersonagem()->getIdGrupo() != $this->getIdGrupo()) {
                 $podeAtacar = true;
                 break;
             }
         }
     }
     if (!$podeAtacar && $sentido == $this->sentido && $this->getDeslocamentoRestante() > 0) {
         if ($this->mover(MV_FRENTE)) {
             //echo "Foi para <b>$this->x.$this->y</b><br />";
             return $this->automove($alvo);
         } else {
             return $podeAtacar;
         }
     } else {
         return $podeAtacar;
     }
 }
Beispiel #2
0
 public static function ataqueDistancia($orig, $dest)
 {
     if (!$orig instanceof Personagem) {
         throw new Exception("Origem precisa sem um personagem.");
     }
     if (!$dest instanceof Personagem) {
         throw new Exception("Destino precisa sem um personagem.");
     }
     $sentido = static::getSentido2DAtaque($orig, $dest);
     //echo "Sentido: $sentido<br />";
     if ($sentido == SENTIDO_COSTAS) {
         return null;
     }
     $retorno = new stdClass();
     $retorno->visibilidade = 0;
     //$retorno->luz = 0;
     $linha = static::linha($orig->getPos(), $dest->getPos());
     $retorno->distancia = count($linha) - 1;
     $sentido = Mapa::getSentido($orig->getPos(), $dest->getPos());
     $inverso = Mapa::inverterSentido2D($sentido);
     //if ($orig->getid() == 1) {
     //    echo $dest->getNome()." - $sentido - $inverso<br />";
     //}
     foreach ($linha as $pos) {
         $area = static::getArea($pos->x, $pos->y);
         $retorno->visibilidade += $area->getVisibilidade();
     }
     //exit();
     if (!is_null($area)) {
         $retorno->visibilidade += $area->getLuz();
     }
     return $retorno;
 }