From 31667e3ba333aefd905b704a4d68619f4d9c74ca Mon Sep 17 00:00:00 2001 From: openlegends Date: Mon, 18 Mar 2024 04:10:03 +0200 Subject: [PATCH] update api --- src/Test/Card/Ability/Damage.php | 51 +++++---------------------- src/Test/Card/Ability/Drain.php | 12 +++++-- src/Test/Card/Ability/Guard.php | 11 ------ src/Test/Card/Ability/Lethal.php | 11 ------ src/Test/Card/Ability/Multiple.php | 19 +++++----- src/Test/Card/Goblin.php | 56 ++++++++++++++---------------- src/Test/Card/Mouse.php | 32 ++++++++--------- 7 files changed, 71 insertions(+), 121 deletions(-) delete mode 100644 src/Test/Card/Ability/Guard.php delete mode 100644 src/Test/Card/Ability/Lethal.php diff --git a/src/Test/Card/Ability/Damage.php b/src/Test/Card/Ability/Damage.php index 79b83b3..2200f91 100644 --- a/src/Test/Card/Ability/Damage.php +++ b/src/Test/Card/Ability/Damage.php @@ -2,53 +2,18 @@ declare(strict_types=1); -namespace OpenLegends\Asset\Test\Card\Ability; +namespace OpenLegends\Asset\Test\Action\Card; -class Damage extends \OpenLegends\Engine\Abstract\Card\Ability +class Damage extends \OpenLegends\Engine\Abstract\Action\Card { - public function apply( - \OpenLegends\Engine\Abstract\Card | \OpenLegends\Engine\Abstract\Player $target - ): void + public function __construct() { - // Give damage - $target->setHealth( - $target->getHealth() - $source->getPower() + $this->setName( + _('Damage') ); - // Target is card - if ($target instanceof \OpenLegends\Engine\Abstract\Card) - { - // Take back damage - $source->setHealth( - $source->getHealth() - $target->getPower() - ); - - // Check for source lethal ability - if ($source->getHealth() > 0) - { - // Check for lethal ability - foreach ($target->getAbilities() as $ability) - { - if ($target->getAbility() instanceof \OpenLegends\Asset\Test\Card\Ability\Lethal) - { - $source->setHealth(0); - break; - } - } - } - - // Check for target lethal ability - if ($target->getHealth() > 0) - { - foreach ($source->getAbilities() as $ability) - { - if ($ability instanceof \OpenLegends\Asset\Test\Card\Ability\Lethal) - { - $target->setHealth(0); - break; - } - } - } - } + $this->setDescription( + _('This card make damage equal it power to another card or player') + ); } } \ No newline at end of file diff --git a/src/Test/Card/Ability/Drain.php b/src/Test/Card/Ability/Drain.php index 02295ac..e74c8bf 100644 --- a/src/Test/Card/Ability/Drain.php +++ b/src/Test/Card/Ability/Drain.php @@ -6,6 +6,14 @@ namespace OpenLegends\Asset\Test\Card\Ability; class Drain extends \OpenLegends\Engine\Abstract\Card\Ability { - public function apply(): void - {} + public function __construct() + { + $this->setName( + _('Drain') + ); + + $this->setDescription( + _('Drain player HP on damage') + ); + } } \ No newline at end of file diff --git a/src/Test/Card/Ability/Guard.php b/src/Test/Card/Ability/Guard.php deleted file mode 100644 index 84dcd55..0000000 --- a/src/Test/Card/Ability/Guard.php +++ /dev/null @@ -1,11 +0,0 @@ -setName( + _('Multiple') + ); + + $this->setDescription( + _('This card has multiple abilities') + ); + } + public function add( \OpenLegends\Engine\Abstract\Card\Ability $ability ): void { $this->_abilities[] = $ability; } - - public function apply(): void - { - foreach ($this->_abilities as $ability) - { - $ability->apply(); - } - } } \ No newline at end of file diff --git a/src/Test/Card/Goblin.php b/src/Test/Card/Goblin.php index 94dd008..4d657cb 100644 --- a/src/Test/Card/Goblin.php +++ b/src/Test/Card/Goblin.php @@ -8,36 +8,6 @@ class Goblin extends \OpenLegends\Engine\Abstract\Card { public function __construct() { - $ability = new \OpenLegends\Asset\Test\Card\Ability\Multiple(); - - $ability->add( - new \OpenLegends\Asset\Test\Card\Ability\Lethal() - ); - - $ability->add( - new \OpenLegends\Asset\Test\Card\Ability\Guard() - ); - - $ability->add( - new \OpenLegends\Asset\Test\Card\Ability\Damage() - ); - - $this->setAbility( - $ability - ); - - $this->setAttribute( - new \OpenLegends\Asset\Test\Card\Attribute\Neutral() - ); - - $this->setType( - new \OpenLegends\Asset\Test\Card\Type\Goblin() - ); - - $this->setRarity( - new \OpenLegends\Asset\Test\Card\Rarity\Common() - ); - $this->setTitle( _('Goblin') ); @@ -65,5 +35,31 @@ class Goblin extends \OpenLegends\Engine\Abstract\Card $this->setExtract( 3 ); + + $this->setAttribute( + new \OpenLegends\Asset\Test\Card\Attribute\Neutral() + ); + + $this->setType( + new \OpenLegends\Asset\Test\Card\Type\Goblin() + ); + + $this->setRarity( + new \OpenLegends\Asset\Test\Card\Rarity\Common() + ); + + $ability = new \OpenLegends\Asset\Test\Card\Ability\Multiple(); + + $ability->add( + new \OpenLegends\Asset\Test\Card\Ability\Damage() + ); + + $ability->add( + new \OpenLegends\Asset\Test\Card\Ability\Drain() + ); + + $this->setAbility( + $ability + ); } } \ No newline at end of file diff --git a/src/Test/Card/Mouse.php b/src/Test/Card/Mouse.php index 3770b7c..c696190 100644 --- a/src/Test/Card/Mouse.php +++ b/src/Test/Card/Mouse.php @@ -8,22 +8,6 @@ class Mouse extends \OpenLegends\Engine\Abstract\Card { public function __construct() { - $this->setAttribute( - new \OpenLegends\Asset\Test\Card\Attribute\Neutral() - ); - - $this->setType( - new \OpenLegends\Asset\Test\Card\Type\Animal() - ); - - $this->setRarity( - new \OpenLegends\Asset\Test\Card\Rarity\Common() - ); - - $this->setAbility( - new \OpenLegends\Asset\Test\Card\Ability\Damage() - ); - $this->setTitle( _('Mouse') ); @@ -51,5 +35,21 @@ class Mouse extends \OpenLegends\Engine\Abstract\Card $this->setExtract( 1 ); + + $this->setAttribute( + new \OpenLegends\Asset\Test\Card\Attribute\Neutral() + ); + + $this->setType( + new \OpenLegends\Asset\Test\Card\Type\Animal() + ); + + $this->setRarity( + new \OpenLegends\Asset\Test\Card\Rarity\Common() + ); + + $this->setAbility( + new \OpenLegends\Asset\Test\Card\Ability\Damage() + ); } } \ No newline at end of file