Add attack/defense/damage modifiers and invuln.

Adds attack, defense and damage modifiers for both "goodguy" (self) and
"badguy" (target) as well as a handler for goodguy/badguy invulnurability.

Modified the battle calculation to not recalculate if noone does damage as
long as at least 1 buff is active. This prevets infinite loops.
This commit is contained in:
Basilius Sauter
2016-06-04 23:12:27 +02:00
parent 4badaea249
commit 7b609e3b5c
5 changed files with 828 additions and 68 deletions
+329 -8
View File
@@ -121,9 +121,9 @@ class BattleTest extends ModelTestCase
}
/**
* Tests a fight which the player has to loose (lvl 1 vs lvl 100)
* Tests a fight which the player has to lose (lvl 1 vs lvl 100)
*/
public function testPlayerLooseBattle()
public function testPlayerLoseBattle()
{
$em = $this->getEntityManager();
@@ -171,7 +171,7 @@ class BattleTest extends ModelTestCase
/**
* @expectedException LotGD\Core\Exceptions\BattleNotOverException
*/
public function testBattleNotOverExceptionFromLooser()
public function testBattleNotOverExceptionFromLoser()
{
$em = $this->getEntityManager();
@@ -196,25 +196,54 @@ class BattleTest extends ModelTestCase
$battle = new Battle($this->getMockGame($character), $character, $monster);
// Fighting for 99 rounds should be enough for determining a looser - and to
// Fighting for 99 rounds should be enough for determining a loser - and to
// throw the exception.
for ($n = 0; $n < 99; $n++) {
$battle->fightNRounds(1);
}
}
private function provideBuffBattleParticipants(Buff $buff): Battle
private function provideBuffBattleParticipants(Buff $buff, int $participantsType): Battle
{
$em = $this->getEntityManager();
$em->clear();
$character = $em->getRepository(Character::class)->find(4);
$monster = $em->getRepository(Monster::class)->find(3);
switch ($participantsType) {
default:
case 0:
// Fair Battle
$character = $em->getRepository(Character::class)->find(1);
$monster = $em->getRepository(Monster::class)->find(1);
break;
case 1:
// very long battle
$character = $em->getRepository(Character::class)->find(4);
$monster = $em->getRepository(Monster::class)->find(3);
break;
case 2:
// player should win battle
$character = $em->getRepository(Character::class)->find(13);
$monster = $em->getRepository(Monster::class)->find(11);
break;
case 3:
// player should lose battle
$character = $em->getRepository(Character::class)->find(11);
$monster = $em->getRepository(Monster::class)->find(13);
break;
}
$character->addBuff($buff);
return new Battle($this->getMockGame($character), $character, $monster);
}
/**
* Asserts that a certain BuffMessageEvent with a specific text is contained in the lst of events
* @param Collection $events The list of events
* @param string $battleEventText The text to test for
* @param int $timesAtLeast Mininum number of times the message is expected to be in the event list
* @param int? $timesAtMax Maximum number of times the message is expected to be in the event list, or $timesAtLeast if null.
*/
protected function assertBuffEventMessageExists(
Collection $events,
string $battleEventText,
@@ -238,6 +267,10 @@ class BattleTest extends ModelTestCase
$this->assertLessThanOrEqual($timesAtMax, $eventCounter);
}
/**
* Tests normal buff messages - message upon start of the buff, message every
* round (except when it's started), and the message displayed if the buff expires.
*/
public function testBattleBuffMessages()
{
$battle = $this->provideBuffBattleParticipants(new Buff([
@@ -247,8 +280,9 @@ class BattleTest extends ModelTestCase
"roundMessage" => "The buff is still activate",
"endMessage" => "The buff is ending.",
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]));
]), 1);
// We fight for 5 rounds - this ensures that the buff is started and expired.
$battle->fightNRounds(5);
$this->assertBuffEventMessageExists($battle->getEvents(), "And this buff starts!", 1);
@@ -278,4 +312,291 @@ class BattleTest extends ModelTestCase
}
}
public function testBattleBuffPlayerGoodguyModifier()
{
// Get a battle ready
$battle = $this->provideBuffBattleParticipants(new Buff([
"slot" => "test",
"rounds" => 99,
"goodguyAttackModifier" => 0.0,
"goodguyDefenseModifier" => 0.0,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]), 2);
$rounds = $battle->fightNRounds(99);
$this->assertTrue($battle->isOver());
$this->assertSame($battle->getPlayer(), $battle->getLoser());
// Get a battle that the player should lose and apply a buff that the player forces to win
$battle = $this->provideBuffBattleParticipants(new Buff([
"slot" => "test",
"rounds" => 99,
"goodguyAttackModifier" => 2,
"goodguyDefenseModifier" => 2,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]), 3);
$battle->fightNRounds(99);
$this->assertTrue($battle->isOver());
$this->assertSame($battle->getPlayer(), $battle->getWinner());
}
public function testBattleBuffPlayerBadguyModifier()
{
// Get a battle that the player should win and apply a buff that the player forces to lose.
$battle = $this->provideBuffBattleParticipants(new Buff([
"slot" => "test",
"rounds" => 99,
"badguyAttackModifier" => 10,
"badguyDefenseModifier" => 10,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]), 2);
$rounds = $battle->fightNRounds(99);
$this->assertTrue($battle->isOver());
$this->assertSame($battle->getPlayer(), $battle->getLoser());
// Get a battle that the player should lose and apply a buff that the player forces to win
$battle = $this->provideBuffBattleParticipants(new Buff([
"slot" => "test",
"rounds" => 99,
"badguyAttackModifier" => 0,
"badguyDefenseModifier" => 0,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]), 3);
$battle->fightNRounds(99);
$this->assertTrue($battle->isOver());
$this->assertSame($battle->getPlayer(), $battle->getWinner());
}
public function testBattleBuffPlayerDamageModifier()
{
// Get a battle that the player should win and apply a buff that the player forces to lose
$battle = $this->provideBuffBattleParticipants(new Buff([
"slot" => "test",
"rounds" => 99,
"goodguyDamageModifier" => 0.0,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]), 0);
$rounds = $battle->fightNRounds(10);
$this->assertSame($battle->getMonster()->getMaxHealth(), $battle->getMonster()->getHealth());
// Get a battle that the player should lose and apply a buff that the player forces to win
$battle = $this->provideBuffBattleParticipants(new Buff([
"slot" => "test",
"rounds" => 99,
"badguyDamageModifier" => 0.0,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]), 0);
$battle->fightNRounds(10);
$this->assertSame($battle->getPlayer()->getMaxHealth(), $battle->getPlayer()->getHealth());
}
public function testBattleBuffPlayerInvulnurability()
{
// Get a battle that the player should win and apply a buff that the player forces to lose
$battle = $this->provideBuffBattleParticipants(new Buff([
"slot" => "test",
"rounds" => 99,
"badguyInvulnurable" => true,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]), 0);
$rounds = $battle->fightNRounds(99);
$this->assertSame($battle->getMonster()->getMaxHealth(), $battle->getMonster()->getHealth());
$this->assertTrue($battle->isOver());
$this->assertSame($battle->getMonster(), $battle->getWinner());
// Get a battle that the player should lose and apply a buff that the player forces to win
$battle = $this->provideBuffBattleParticipants(new Buff([
"slot" => "test",
"rounds" => 99,
"goodguyInvulnurable" => true,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]), 0);
$rounds = $battle->fightNRounds(99);
$this->assertSame($battle->getPlayer()->getMaxHealth(), $battle->getPlayer()->getHealth());
$this->assertTrue($battle->isOver());
$this->assertSame($battle->getPlayer(), $battle->getWinner());
}
public function testBufflistGoodguyAttackModifier()
{
$em = $this->getEntityManager();
$player = $em->getRepository(Character::class)->find(1);
$game = $this->getMockGame($player);
$player->addBuff(new Buff([
"slot" => "test1",
"rounds" => 1,
"goodguyAttackModifier" => 1.23,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]));
$player->addBuff(new Buff([
"slot" => "test2",
"rounds" => 1,
"goodguyAttackModifier" => 0.126,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]));
$player->addBuff(new Buff([
"slot" => "test3",
"rounds" => 1,
"goodguyAttackModifier" => 13.4,
]));
$modifier = $player->getBuffs()->getGoodguyAttackModifier();
$this->assertEquals(0.15498, $modifier, '', 0.001);
}
public function testBufflistGoodguyDefenseModifier()
{
$em = $this->getEntityManager();
$player = $em->getRepository(Character::class)->find(1);
$game = $this->getMockGame($player);
$player->addBuff(new Buff([
"slot" => "test1",
"rounds" => 1,
"goodguyDefenseModifier" => 1.293,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]));
$player->addBuff(new Buff([
"slot" => "test2",
"rounds" => 1,
"goodguyDefenseModifier" => 5.6,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]));
$player->addBuff(new Buff([
"slot" => "test3",
"rounds" => 1,
"goodguyDefenseModifier" => 0,
]));
$modifier = $player->getBuffs()->getGoodguyDefenseModifier();
$this->assertEquals(7.2408, $modifier, '', 0.001);
}
public function testBufflistGoodguyDamageModifier()
{
$em = $this->getEntityManager();
$player = $em->getRepository(Character::class)->find(1);
$game = $this->getMockGame($player);
$player->addBuff(new Buff([
"slot" => "test1",
"rounds" => 1,
"goodguyDamageModifier" => 10,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]));
$player->addBuff(new Buff([
"slot" => "test2",
"rounds" => 1,
"goodguyDamageModifier" => 0.25,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]));
$player->addBuff(new Buff([
"slot" => "test3",
"rounds" => 1,
"goodguyDamageModifier" => 3.5,
]));
$modifier = $player->getBuffs()->getGoodguyDamageModifier();
$this->assertEquals(2.5, $modifier, '', 0.001);
}
public function testBufflistBadguyAttackModifier()
{
$em = $this->getEntityManager();
$player = $em->getRepository(Character::class)->find(1);
$game = $this->getMockGame($player);
$player->addBuff(new Buff([
"slot" => "test1",
"rounds" => 1,
"badguyAttackModifier" => 1.23,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]));
$player->addBuff(new Buff([
"slot" => "test2",
"rounds" => 1,
"badguyAttackModifier" => 0.126,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]));
$player->addBuff(new Buff([
"slot" => "test3",
"rounds" => 1,
"badguyAttackModifier" => 13.4,
]));
$modifier = $player->getBuffs()->getBadguyAttackModifier();
$this->assertEquals(0.15498, $modifier, '', 0.001);
}
public function testBufflistBadguyDefenseModifier()
{
$em = $this->getEntityManager();
$player = $em->getRepository(Character::class)->find(1);
$game = $this->getMockGame($player);
$player->addBuff(new Buff([
"slot" => "test1",
"rounds" => 1,
"badguyDefenseModifier" => 1.293,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]));
$player->addBuff(new Buff([
"slot" => "test2",
"rounds" => 1,
"badguyDefenseModifier" => 5.6,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]));
$player->addBuff(new Buff([
"slot" => "test3",
"rounds" => 1,
"badguyDefenseModifier" => 0,
]));
$modifier = $player->getBuffs()->getBadguyDefenseModifier();
$this->assertEquals(7.2408, $modifier, '', 0.001);
}
public function testBufflistBadguyDamageModifier()
{
$em = $this->getEntityManager();
$player = $em->getRepository(Character::class)->find(1);
$game = $this->getMockGame($player);
$player->addBuff(new Buff([
"slot" => "test1",
"rounds" => 1,
"badguyDamageModifier" => 10,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]));
$player->addBuff(new Buff([
"slot" => "test2",
"rounds" => 1,
"badguyDamageModifier" => 0.25,
"activateAt" => Buff::ACTIVATE_ROUNDSTART,
]));
$player->addBuff(new Buff([
"slot" => "test3",
"rounds" => 1,
"badguyDamageModifier" => 3.5,
]));
$modifier = $player->getBuffs()->getBadguyDamageModifier();
$this->assertEquals(2.5, $modifier, '', 0.001);
}
}