Updated BattleClass to use BattleEvents
Implemented BattleEvents from @austenmc's old branch. Added an empty Buff-Model as well, as well as a BuffList. @ToDo: Add events, and add buff calculations to the battle class. This PR will, however, only introduce the basic battle class, buffs will come in another patch.
This commit is contained in:
@@ -5,6 +5,8 @@ namespace LotGD\Core\Tests\Models;
|
||||
|
||||
use LotGD\Core\{
|
||||
Battle,
|
||||
DiceBag,
|
||||
Game,
|
||||
Models\Character,
|
||||
Models\Monster
|
||||
};
|
||||
@@ -19,6 +21,19 @@ class BattleTest extends ModelTestCase
|
||||
/** @var string default data set */
|
||||
protected $dataset = "battle";
|
||||
|
||||
public function getMockGame(Character $character): Game
|
||||
{
|
||||
$game = $this->getMockBuilder(Game::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$game->method('getEntityManager')->willReturn($this->getEntityManager());
|
||||
$game->method('getDiceBag')->willReturn(new DiceBag());
|
||||
$game->method('getCharacter')->willReturn($character);
|
||||
|
||||
return $game;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests basic monster functionality
|
||||
*/
|
||||
@@ -26,12 +41,13 @@ class BattleTest extends ModelTestCase
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$character = $em->getRepository(Character::class)->find(1);
|
||||
$monster = $em->getRepository(Monster::class)->find(1);
|
||||
|
||||
$this->assertSame(5, $monster->getLevel());
|
||||
$this->assertSame(52, $monster->getMaxHealth());
|
||||
$this->assertSame(9, $monster->getAttack());
|
||||
$this->assertSame(7, $monster->getDefense());
|
||||
$this->assertSame(9, $monster->getAttack($this->getMockGame($character)));
|
||||
$this->assertSame(7, $monster->getDefense($this->getMockGame($character)));
|
||||
$this->assertSame($monster->getMaxHealth(), $monster->getHealth());
|
||||
}
|
||||
|
||||
@@ -45,7 +61,7 @@ class BattleTest extends ModelTestCase
|
||||
$character = $em->getRepository(Character::class)->find(1);
|
||||
$monster = $em->getRepository(Monster::class)->find(1);
|
||||
|
||||
$battle = new Battle($character, $monster);
|
||||
$battle = new Battle($this->getMockGame($character), $character, $monster);
|
||||
|
||||
for ($n = 0; $n < 99; $n++) {
|
||||
$oldPlayerHealth = $character->getHealth();
|
||||
@@ -75,7 +91,7 @@ class BattleTest extends ModelTestCase
|
||||
$highLevelPlayer = $em->getRepository(Character::class)->find(2);
|
||||
$lowLevelMonster = $em->getRepository(Monster::class)->find(3);
|
||||
|
||||
$battle = new Battle($highLevelPlayer, $lowLevelMonster);
|
||||
$battle = new Battle($this->getMockGame($highLevelPlayer), $highLevelPlayer, $lowLevelMonster);
|
||||
|
||||
for ($n = 0; $n < 99; $n++) {
|
||||
$oldPlayerHealth = $highLevelPlayer->getHealth();
|
||||
@@ -108,7 +124,7 @@ class BattleTest extends ModelTestCase
|
||||
$lowLevelPlayer = $em->getRepository(Character::class)->find(3);
|
||||
$highLevelMonster = $em->getRepository(Monster::class)->find(2);
|
||||
|
||||
$battle = new Battle($lowLevelPlayer, $highLevelMonster);
|
||||
$battle = new Battle($this->getMockGame($lowLevelPlayer), $lowLevelPlayer, $highLevelMonster);
|
||||
|
||||
for ($n = 0; $n < 99; $n++) {
|
||||
$oldPlayerHealth = $lowLevelPlayer->getHealth();
|
||||
@@ -141,7 +157,7 @@ class BattleTest extends ModelTestCase
|
||||
$character = $em->getRepository(Character::class)->find(1);
|
||||
$monster = $em->getRepository(Monster::class)->find(1);
|
||||
|
||||
$battle = new Battle($character, $monster);
|
||||
$battle = new Battle($this->getMockGame($character), $character, $monster);
|
||||
|
||||
$battle->getWinner();
|
||||
}
|
||||
@@ -156,9 +172,9 @@ class BattleTest extends ModelTestCase
|
||||
$character = $em->getRepository(Character::class)->find(1);
|
||||
$monster = $em->getRepository(Monster::class)->find(1);
|
||||
|
||||
$battle = new Battle($character, $monster);
|
||||
$battle = new Battle($this->getMockGame($character), $character, $monster);
|
||||
|
||||
$battle->getLooser();
|
||||
$battle->getLoser();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,7 +188,7 @@ class BattleTest extends ModelTestCase
|
||||
$character = $em->getRepository(Character::class)->find(1);
|
||||
$monster = $em->getRepository(Monster::class)->find(1);
|
||||
|
||||
$battle = new Battle($character, $monster);
|
||||
$battle = new Battle($this->getMockGame($character), $character, $monster);
|
||||
|
||||
// Fighting for 99 rounds should be enough for determining a looser - and to
|
||||
// throw the exception.
|
||||
|
||||
Reference in New Issue
Block a user