<?php
/**
* アクション基底クラス
*
*/
abstract class Action
{
/** @var BattleAble 行動実行者 */
protected BattleAble $performer;
/** @var BattleAble 対象 */
protected BattleAble $target;
/**
* constructor
*
* @param BattleAble $performer 行動実行者
* @param BattleAble $target 対象
*/
public function __construct(BattleAble $performer, BattleAble $target)
{
$this->performer = $performer;
$this->target = $target;
}
/**
* 実行
*
* @return $this
*/
final public function execute(): self
{
$this->initAction();
$this->action();
return $this;
}
/**
* 繰り返し処理を中断すべきか
*
* @return bool
*/
abstract public function shouldBreak(): bool;
/**
* アクション
*
* @return void
*/
abstract protected function action(): void;
/**
* 行動初期化
*
* @return void
*/
private function initAction(): void
{
$this->performer->setDefence(false);
$this->performer->setCriticalHit(false);
$this->target->setBlockSuccess(false);
}
}