Battle
in package
Class for managing and running battles between 2 participants.
Original damage calculation is from LotGD 0.9.7+jt by Eric Stevens and JTraub, released originally under GPL 2.0.
Table of Contents
- DAMAGEROUND_BOTH = 0b11
- DAMAGEROUND_MONSTER = 0b10
- DAMAGEROUND_PLAYER = 0b1
- RESULT_MONSTERDEATH = 2
- RESULT_PLAYERDEATH = 1
- RESULT_UNDECIDED = 0
- $configuration : array<string|int, mixed>
- $events : ArrayCollection
- $game : Game
- $monster : FighterInterface|null
- $player : FighterInterface
- $result : int
- $round : int
- __construct() : mixed
- Takes a game object and two participants (Player and Monster) to fight a battle.
- disableCriticalHit() : void
- Disable critical hits.
- disableLevelAdjustement() : void
- Disables level adjustement.
- disableRiposte() : void
- Disables ripostes.
- enableCriticalHit() : void
- enables critical hits.
- enableLevelAdjustement() : void
- Enables level adjustement.
- enableRiposte() : void
- Enables ripostes.
- fightNRounds() : int
- Fights the number of rounds given by the parameter $n and returns the number of actual rounds fought.
- getEvents() : Collection
- Returns a list of all battle events.
- getLoser() : FighterInterface
- Returns the loser of this fight.
- getMonster() : FighterInterface
- Returns the montser instance.
- getPlayer() : FighterInterface
- Returns the player instance.
- getWinner() : FighterInterface
- Returns the winner of this fight.
- isCriticalHitEnabled() : bool
- Returns true if critical hit events are enabled.
- isLevelAdjustementEnabled() : bool
- Returns true if level adjustements are enabled.
- isOver() : bool
- Returns true if the battle is over.
- isRiposteEnabled() : bool
- Returns true if ripostes are enabled.
- serialize() : string
- Returns a string which contains the important fields that must be serialized.
- unserialize() : self
- fightOneRound() : void
- Fights exactly 1 round.
- turn() : ArrayCollection
- Runs one turn.
Constants
DAMAGEROUND_BOTH
public
mixed
DAMAGEROUND_BOTH
= 0b11
DAMAGEROUND_MONSTER
public
mixed
DAMAGEROUND_MONSTER
= 0b10
DAMAGEROUND_PLAYER
public
mixed
DAMAGEROUND_PLAYER
= 0b1
RESULT_MONSTERDEATH
public
mixed
RESULT_MONSTERDEATH
= 2
RESULT_PLAYERDEATH
public
mixed
RESULT_PLAYERDEATH
= 1
RESULT_UNDECIDED
public
mixed
RESULT_UNDECIDED
= 0
Properties
$configuration
protected
array<string|int, mixed>
$configuration
= ["riposteEnabled" => true, "levelAdjustementEnabled" => true, "criticalHitEnabled" => true]
$events
protected
ArrayCollection
$events
$game
protected
Game
$game
$monster
protected
FighterInterface|null
$monster
$player
protected
FighterInterface
$player
$result
protected
int
$result
= 0
$round
protected
int
$round
= 0
Methods
__construct()
Takes a game object and two participants (Player and Monster) to fight a battle.
public
__construct(Game $game, FighterInterface $player, FighterInterface|null $monster) : mixed
Parameters
- $game : Game
- $player : FighterInterface
- $monster : FighterInterface|null
Return values
mixed —disableCriticalHit()
Disable critical hits.
public
disableCriticalHit() : void
Return values
void —disableLevelAdjustement()
Disables level adjustement.
public
disableLevelAdjustement() : void
Return values
void —disableRiposte()
Disables ripostes.
public
disableRiposte() : void
Return values
void —enableCriticalHit()
enables critical hits.
public
enableCriticalHit() : void
Return values
void —enableLevelAdjustement()
Enables level adjustement.
public
enableLevelAdjustement() : void
Return values
void —enableRiposte()
Enables ripostes.
public
enableRiposte() : void
Return values
void —fightNRounds()
Fights the number of rounds given by the parameter $n and returns the number of actual rounds fought.
public
fightNRounds([int $n = 1 ][, int $firstDamageRound = self::DAMAGEROUND_BOTH ]) : int
Parameters
- $n : int = 1
- $firstDamageRound : int = self::DAMAGEROUND_BOTH
-
Which damage rounds are calculated. Cannot be 0.
Tags
Return values
int —Number of fights fought.
getEvents()
Returns a list of all battle events.
public
getEvents() : Collection
Return values
Collection —getLoser()
Returns the loser of this fight.
public
getLoser() : FighterInterface
Tags
Return values
FighterInterface —getMonster()
Returns the montser instance.
public
getMonster() : FighterInterface
Return values
FighterInterface —getPlayer()
Returns the player instance.
public
getPlayer() : FighterInterface
Return values
FighterInterface —getWinner()
Returns the winner of this fight.
public
getWinner() : FighterInterface
Tags
Return values
FighterInterface —isCriticalHitEnabled()
Returns true if critical hit events are enabled.
public
isCriticalHitEnabled() : bool
Return values
bool —isLevelAdjustementEnabled()
Returns true if level adjustements are enabled.
public
isLevelAdjustementEnabled() : bool
Return values
bool —isOver()
Returns true if the battle is over.
public
isOver() : bool
Return values
bool —isRiposteEnabled()
Returns true if ripostes are enabled.
public
isRiposteEnabled() : bool
Return values
bool —serialize()
Returns a string which contains the important fields that must be serialized.
public
serialize() : string
Return values
string —unserialize()
public
static unserialize(Game $game, FighterInterface $player, string $serialized) : self
Parameters
- $game : Game
- $player : FighterInterface
- $serialized : string
Return values
self —fightOneRound()
Fights exactly 1 round.
protected
fightOneRound(int $firstDamageRound) : void
Parameters
- $firstDamageRound : int
Return values
void —turn()
Runs one turn.
protected
turn(FighterInterface $attacker, FighterInterface $defender) : ArrayCollection
Parameters
- $attacker : FighterInterface
- $defender : FighterInterface