115 lines
3.6 KiB
PHP
115 lines
3.6 KiB
PHP
|
<?php
|
|||
|
|
|||
|
namespace Battle\Priem;
|
|||
|
|
|||
|
abstract class AbstractPriem implements PriemInterface
|
|||
|
{
|
|||
|
protected int $caster;
|
|||
|
protected string $name;
|
|||
|
protected string $icon;
|
|||
|
|
|||
|
protected int $power;
|
|||
|
|
|||
|
/**
|
|||
|
* На кого применяем приём. Например:
|
|||
|
* self, static_friend, static_enemy, random_friend, random_enemy, random_friend_group, random_enemy_group,
|
|||
|
* all_friend, all_enemy, all,...
|
|||
|
* @var int
|
|||
|
*/
|
|||
|
protected int $targetType;
|
|||
|
|
|||
|
/**
|
|||
|
* Массив id союзников
|
|||
|
* @var array
|
|||
|
*/
|
|||
|
protected array $friendTeam;
|
|||
|
|
|||
|
/** Массив id противников
|
|||
|
* @var array
|
|||
|
*/
|
|||
|
protected array $enemyTeam;
|
|||
|
|
|||
|
public function __construct(
|
|||
|
int $caster,
|
|||
|
array $friendTeam,
|
|||
|
array $enemyTeam,
|
|||
|
int $targetType,
|
|||
|
string $name,
|
|||
|
string $icon = '',
|
|||
|
) {
|
|||
|
$this->caster = $caster;
|
|||
|
$this->friendTeam = $friendTeam;
|
|||
|
$this->enemyTeam = $enemyTeam;
|
|||
|
$this->targetType = $targetType;
|
|||
|
$this->icon = $icon;
|
|||
|
$this->name = $name;
|
|||
|
}
|
|||
|
|
|||
|
protected function getTarget(): array
|
|||
|
{
|
|||
|
$targets = [];
|
|||
|
$allExceptCaster = array_merge($this->friendTeam, $this->enemyTeam);
|
|||
|
switch ($this->targetType) {
|
|||
|
case self::TAGRET_SELF:
|
|||
|
$targets[] = $this->caster;
|
|||
|
break;
|
|||
|
case self::TARGET_RANDOM_ENEMY:
|
|||
|
shuffle($this->enemyTeam);
|
|||
|
$targets[] = end($this->enemyTeam);
|
|||
|
break;
|
|||
|
case self::TARGET_RANDOM_FRIEND:
|
|||
|
shuffle($this->friendTeam);
|
|||
|
$targets[] = end($this->friendTeam);
|
|||
|
break;
|
|||
|
case self::TARGET_RANDOM:
|
|||
|
shuffle($allExceptCaster);
|
|||
|
$targets[] = end($allExceptCaster);
|
|||
|
break;
|
|||
|
case self::TARGET_RANDOM_ENEMIES:
|
|||
|
for ($i = 1; $i <= count($this->enemyTeam); $i++) {
|
|||
|
if ($i > 1 && mt_rand(1,2) === 1) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
shuffle($this->enemyTeam);
|
|||
|
$targets[] = array_shift($this->enemyTeam);
|
|||
|
}
|
|||
|
break;
|
|||
|
case self::TARGET_RANDOM_FRIENDS:
|
|||
|
for ($i = 1; $i <= count($this->friendTeam); $i++) {
|
|||
|
if ($i > 1 && mt_rand(1,2) === 1) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
shuffle($this->friendTeam);
|
|||
|
$targets[] = array_shift($this->friendTeam);
|
|||
|
}
|
|||
|
break;
|
|||
|
case self::TARGET_RANDOMS:
|
|||
|
for ($i = 1; $i <= count($allExceptCaster); $i++) {
|
|||
|
if ($i > 1 && mt_rand(1,2) === 1) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
shuffle($allExceptCaster);
|
|||
|
$targets[] = array_shift($allExceptCaster);
|
|||
|
}
|
|||
|
break;
|
|||
|
case self::TARGET_ALL_ENEMIES:
|
|||
|
$targets = $this->enemyTeam;
|
|||
|
break;
|
|||
|
case self::TARGET_ALL_FRIENDS:
|
|||
|
$targets = $this->friendTeam;
|
|||
|
break;
|
|||
|
case self::TARGET_ALL:
|
|||
|
$targets = $allExceptCaster;
|
|||
|
$targets[] = $this->caster;
|
|||
|
break;
|
|||
|
}
|
|||
|
return $targets;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Возвращает иконку приёма. В текущей реализации у каждого приёма должна быть иконка.
|
|||
|
* @return string
|
|||
|
*/
|
|||
|
abstract public function getIcon(): string;
|
|||
|
}
|