From d88a7966c74ad9d1c25ff78d41871bb9ea6dd7dd Mon Sep 17 00:00:00 2001 From: openlegends Date: Mon, 18 Mar 2024 03:48:22 +0200 Subject: [PATCH] implement attack action --- src/Test/Card/Action/Attack.php | 92 +++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/Test/Card/Action/Attack.php diff --git a/src/Test/Card/Action/Attack.php b/src/Test/Card/Action/Attack.php new file mode 100644 index 0000000..6e28324 --- /dev/null +++ b/src/Test/Card/Action/Attack.php @@ -0,0 +1,92 @@ +_card = $card; + } + + public function card( + \OpenLegends\Engine\Abstract\Card &$card, + ?int $power = null + ): void + { + $damage = $power ? $power : $this->_card->getPower(); + + if ($damage) + { + if ($card->getCover()) + { + $card->setCover( + false + ); + } + + else + { + $health = $card->getHealth() - $damage; + + if ($health < 0 && $this->_card->getBreakthrough()) + { + $this->_breakthrough = abs( + $health + ); + } + + if ($this->_card->getLethal()) + { + $card->setHealth( + 0 + ); + } + + else + { + $card->setHealth( + $health + ); + } + } + } + } + + public function player( + \OpenLegends\Engine\Abstract\Player &$player, + ?int $power = null + ): void + { + $damage = $power ? $power : $this->_card->getPower(); + + if ($damage) + { + if ($player->getCover()) + { + $player->setCover( + false + ); + } + + else + { + $player->setHealth( + $player->getHealth() - $damage + ); + } + } + } + + public function getBreakthrough(): int + { + return $this->_breakthrough; + } +} \ No newline at end of file