Removed game dependency from FighterInterface->getAttack and getDefense

This commit is contained in:
Vassyli
2018-01-09 09:25:37 +01:00
parent 45a785a8f5
commit 55b821c8e8
7 changed files with 31 additions and 20 deletions
+8 -4
View File
@@ -43,7 +43,7 @@ class Battle
/**
* Battle Configuration
* @var type
* @var array
*/
protected $configuration = [
"riposteEnabled" => true,
@@ -212,6 +212,7 @@ class Battle
/**
* Returns the winner of this fight
* @return FighterInterface
* @throws BattleNotOverException if battle is not over.
*/
public function getWinner(): FighterInterface
{
@@ -225,6 +226,7 @@ class Battle
/**
* Returns the loser of this fight
* @return FighterInterface
* @throws BattleNotOverException if battle is not over.
*/
public function getLoser(): FighterInterface
{
@@ -241,6 +243,8 @@ class Battle
* @param int $n
* @param bool $firstDamageRound Which damage rounds are calculated. Cannot be 0.
* @return int Number of fights fought.
* @throws ArgumentException if firstDamageRound is 0.
* @throws BattleIsOverException
*/
public function fightNRounds(int $n = 1, int $firstDamageRound = self::DAMAGEROUND_BOTH): int
{
@@ -361,12 +365,12 @@ class Battle
// Apply buff scaling for the attacker's attack - this needs to take into
// account the attacker's goodguyAttackModifier and the defenders badguyAttackModifier
$attackersAttack = $attacker->getAttack($this->game)
$attackersAttack = $attacker->getAttack()
* $attackersBuffs->getGoodguyAttackModifier()
* $defendersBuffs->getBadguyAttackModifier();
// It's the opposite for the defender's defense - it needs to take into account the
// defender's goodguyDefenseModifier as well as the attacker's badguyDefenseModifier.
$defendersDefense = $defender->getDefense($this->game)
$defendersDefense = $defender->getDefense()
* $defendersBuffs->getGoodguyDefenseModifier()
* $attackersBuffs->getBadguyDefenseModifier()
* $defenseAdjustement;
@@ -390,7 +394,7 @@ class Battle
// If the attacker's attack after modification is bigger than before,
// we call it a critical hit and apply the CriticalHitEvent.
if ($attackersAttack > $attacker->getAttack($this->game) && $this->isCriticalHitEnabled()) {
if ($attackersAttack > $attacker->getAttack() && $this->isCriticalHitEnabled()) {
$events->add(new CriticalHitEvent($attacker, $attackersAttack));
}
+1 -1
View File
@@ -32,7 +32,7 @@ class CriticalHitEvent extends BattleEvent
*/
public function decorate(Game $game): string
{
$pureAttackersAttack = $this->attacker->getAttack($game, true);
$pureAttackersAttack = $this->attacker->getAttack(true);
if ($this->criticalAttackValue > $pureAttackersAttack * 4) {
return "You execute a MEGA power move!!!";
+11 -6
View File
@@ -15,7 +15,7 @@ use LotGD\Core\{
};
use LotGD\Core\Tools\Exceptions\BuffSlotOccupiedException;
use LotGD\Core\Tools\Model\{
Creator, GameAware, PropertyManager, SoftDeletable
Creator, ExtendableModel, GameAware, PropertyManager, SoftDeletable
};
/**
@@ -24,12 +24,13 @@ use LotGD\Core\Tools\Model\{
* @Entity(repositoryClass="LotGD\Core\Models\Repositories\CharacterRepository")
* @Table(name="characters")
*/
class Character implements CharacterInterface, CreateableInterface, GameAwareInterface
class Character implements CharacterInterface, CreateableInterface, GameAwareInterface, ExtendableModelInterface
{
use Creator;
use SoftDeletable;
use PropertyManager;
use GameAware;
use ExtendableModel;
/** @Id @Column(type="integer") @GeneratedValue */
private $id;
@@ -221,18 +222,22 @@ class Character implements CharacterInterface, CreateableInterface, GameAwareInt
/**
* Returns the character's virtual attribute "attack"
* @param bool $ignoreBuffs
* @return int
*/
public function getAttack(Game $game, bool $ignoreBuffs = false): int
public function getAttack(bool $ignoreBuffs = false): int
{
return $this->level * 2;
return $this->level;
}
/**
* Returns the character's virtual attribute "defense"
* @param bool $ignoreBuffs
* @return int
*/
public function getDefense(Game $game, bool $ignoreBuffs = false): int
public function getDefense(bool $ignoreBuffs = false): int
{
return $this->level * 2;
return $this->level;
}
/**
+2 -2
View File
@@ -18,8 +18,8 @@ interface FighterInterface
public function getMaxHealth(): int;
public function getHealth(): int;
public function isAlive(): bool;
public function getAttack(Game $game, bool $ignoreBuffs = false): int;
public function getDefense(Game $game, bool $ignoreBuffs = false): int;
public function getAttack(bool $ignoreBuffs = false): int;
public function getDefense(bool $ignoreBuffs = false): int;
public function damage(int $damage);
public function heal(int $heal);
public function setHealth(int $amount);
+5 -3
View File
@@ -28,19 +28,21 @@ trait AutoScaleFighter
/**
* Returns the attack value based on the fighter's level
* @param bool $ignoreBuffs
* @return int
*/
public function getAttack(Game $game, bool $ignoreBuffs = false): int
public function getAttack(bool $ignoreBuffs = false): int
{
$level = $this->getLevel();
return (int)$level * 2 - 1;
}
/**
* Returns the defense value based on the fighter's level
* @param bool $ignoreBuffs
* @return int
*/
public function getDefense(Game $game, bool $ignoreBuffs = false): int
public function getDefense(bool $ignoreBuffs = false): int
{
$level = $this->getlevel();
return (int)floor($level*1.45);
+2 -2
View File
@@ -71,12 +71,12 @@ trait MockCharacter
throw new IsNullException();
}
public function getAttack(Game $game, bool $ignoreBuffs = false): int
public function getAttack(bool $ignoreBuffs = false): int
{
throw new IsNullException();
}
public function getDefense(Game $game, bool $ignoreBuffs = false): int
public function getDefense(bool $ignoreBuffs = false): int
{
throw new IsNullException();
}
+2 -2
View File
@@ -56,8 +56,8 @@ class BattleTest extends CoreModelTestCase
$this->assertSame(5, $monster->getLevel());
$this->assertSame(52, $monster->getMaxHealth());
$this->assertSame(9, $monster->getAttack($this->getMockGame($character)));
$this->assertSame(7, $monster->getDefense($this->getMockGame($character)));
$this->assertSame(9, $monster->getAttack());
$this->assertSame(7, $monster->getDefense());
$this->assertSame($monster->getMaxHealth(), $monster->getHealth());
}