Browse Source

update api

main
openlegends 9 months ago
parent
commit
31667e3ba3
  1. 51
      src/Test/Card/Ability/Damage.php
  2. 12
      src/Test/Card/Ability/Drain.php
  3. 11
      src/Test/Card/Ability/Guard.php
  4. 11
      src/Test/Card/Ability/Lethal.php
  5. 19
      src/Test/Card/Ability/Multiple.php
  6. 56
      src/Test/Card/Goblin.php
  7. 32
      src/Test/Card/Mouse.php

51
src/Test/Card/Ability/Damage.php

@ -2,53 +2,18 @@ @@ -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')
);
}
}

12
src/Test/Card/Ability/Drain.php

@ -6,6 +6,14 @@ namespace OpenLegends\Asset\Test\Card\Ability; @@ -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')
);
}
}

11
src/Test/Card/Ability/Guard.php

@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
namespace OpenLegends\Asset\Test\Card\Ability;
class Guard extends \OpenLegends\Engine\Abstract\Card\Ability
{
public function apply(): void
{}
}

11
src/Test/Card/Ability/Lethal.php

@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
namespace OpenLegends\Asset\Test\Card\Ability;
class Lethal extends \OpenLegends\Engine\Abstract\Card\Ability
{
public function apply(): void
{}
}

19
src/Test/Card/Ability/Multiple.php

@ -8,18 +8,21 @@ class Multiple extends \OpenLegends\Engine\Abstract\Card\Ability @@ -8,18 +8,21 @@ class Multiple extends \OpenLegends\Engine\Abstract\Card\Ability
{
private array $_abilities = [];
public function __construct()
{
$this->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();
}
}
}

56
src/Test/Card/Goblin.php

@ -8,36 +8,6 @@ class Goblin extends \OpenLegends\Engine\Abstract\Card @@ -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 @@ -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
);
}
}

32
src/Test/Card/Mouse.php

@ -8,22 +8,6 @@ class Mouse extends \OpenLegends\Engine\Abstract\Card @@ -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 @@ -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()
);
}
}
Loading…
Cancel
Save