Conform to PSR2

This commit is contained in:
Austen McDonald
2016-08-08 23:03:15 -07:00
parent f6a6ceec9e
commit d5747fdf95
48 changed files with 161 additions and 176 deletions
+17 -23
View File
@@ -47,7 +47,7 @@ class Battle
/**
* Battle Configuration
* @var type
* @var type
*/
protected $configuration = [
"riposteEnabled" => true,
@@ -74,7 +74,6 @@ class Battle
*/
public function getActions()
{
}
/**
@@ -82,7 +81,6 @@ class Battle
*/
public function selectAction()
{
}
/**
@@ -271,7 +269,7 @@ class Battle
$events = new ArrayCollection(array_merge($offenseTurnEvents->toArray(), $defenseTurnEvents->toArray()));
$eventsToAdd = new ArrayCollection();
foreach($events as $event) {
foreach ($events as $event) {
$event->apply();
$eventsToAdd->add($event);
@@ -299,7 +297,7 @@ class Battle
$this->events = new ArrayCollection(
array_merge(
$this->events->toArray(),
$this->events->toArray(),
$playerBuffStartEvents->toArray(),
$monsterBuffStartEvents->toArray(),
$eventsToAdd->toArray(),
@@ -324,13 +322,13 @@ class Battle
$attackersBuffs = $attacker->getBuffs();
$defendersBuffs = $defender->getBuffs();
// Adjustement makes fights versus monsters with lower level easier,
// Adjustement makes fights versus monsters with lower level easier,
// and more difficult if the monster has a higher level by adjusting
// the monster's defense value.
// For example, if a level 10 player attacks a level 9 monster, the
// For example, if a level 10 player attacks a level 9 monster, the
// defenseAdjustement value for the monster is 0.81, reducing the monster's
// defense by 20% and making it more likely for the player to land a hit.
// On the other hand, the player's defense is increased by ~ 10%, making it
// On the other hand, the player's defense is increased by ~ 10%, making it
// less likely for the enemy to hit the player.
$adjustement = 1.0;
$defenseAdjustement = 1.0;
@@ -339,8 +337,7 @@ class Battle
$adjustement = $attacker->getLevel() / $defender->getLevel();
$defenseAdjustement = 1. / ($adjustement * $adjustement);
}
}
elseif ($defender === $this->player && $this->isLevelAdjustementEnabled()) {
} elseif ($defender === $this->player && $this->isLevelAdjustementEnabled()) {
if ($attacker->getLevel() > 1 && $defender->getLevel() > 1) {
$adjustement = $defender->getLevel() / $attacker->getLevel();
$defenseAdjustement = $adjustement;
@@ -354,8 +351,8 @@ class Battle
* $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)
* $defendersBuffs->getGoodguyDefenseModifier()
$defendersDefense = $defender->getDefense($this->game)
* $defendersBuffs->getGoodguyDefenseModifier()
* $attackersBuffs->getBadguyDefenseModifier()
* $defenseAdjustement;
@@ -376,7 +373,7 @@ class Battle
$defendersDefRoll = $this->game->getDiceBag()->normal(0, $defendersDefense);
$damage = $attackersAtkRoll - $defendersDefRoll;
// If the attacker's attack after modification is bigger than before,
// 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()) {
$events->add(new CriticalHitEvent($attacker, $attackersAttack));
@@ -387,7 +384,7 @@ class Battle
$damage = 0;
}
// Here, we take invulnurable buffs into account. There are 4 possible values coming from the
// Here, we take invulnurable buffs into account. There are 4 possible values coming from the
// 2 buff lists, so we must take care a bit.
$attackerIsInvulnurable = $attackersBuffs->goodguyIsInvulnurable() || $defendersBuffs->badguyIsInvulnurable();
$defenderIsInvulnurable = $defendersBuffs->goodguyIsInvulnurable() || $attackersBuffs->badguyIsInvulnurable();
@@ -395,28 +392,25 @@ class Battle
if ($attackerIsInvulnurable && $defenderIsInvulnurable) {
// Both are invulnurable, damage is 0.
$damage = 0;
}
elseif ($attackerIsInvulnurable) {
} elseif ($attackerIsInvulnurable) {
// Attaker is invulnurable, damage is always > 0 (there is no riposte)
$damage = abs($damage);
}
elseif ($defenderIsInvulnurable) {
} elseif ($defenderIsInvulnurable) {
// Defender is invulnurable, damage is always < 0 (defender always ripostes)
$damage = - abs($damage);
}
if ($damage < 0) {
// If the damage is less then 0, it's a RIPOSTE. They are only half
// If the damage is less then 0, it's a RIPOSTE. They are only half
// as damaging than normal attacks.
$damage /= 2;
// Apply damage modification. It's a RIPOSTE, so the defenders makes the
// damage. Therefore, we take defender's goodguyDamageModifier into account,
// Apply damage modification. It's a RIPOSTE, so the defenders makes the
// damage. Therefore, we take defender's goodguyDamageModifier into account,
// and the attacker's badguyDamageModifier.
$damage *= $defendersBuffs->getGoodguyDamageModifier()
* $attackersBuffs->getBadguyDamageModifier();
}
else {
} else {
// Apply damage modification. It's a normal attack - meaning the attacker does
// the damage. Therefore, we take the attacker's goodguyDamageModifier and
// the defender's badguyDamageModifier into account.
+4 -7
View File
@@ -44,16 +44,14 @@ class BootConfiguration
// only lotgd-modules are installed in the vendor directory
if ($package->getType() === "lotgd-module") {
$confFile = $installationManager->getInstallPath($package) . DIRECTORY_SEPARATOR . "lotgd.yml";
}
else {
} else {
$confFile = $cwd . DIRECTORY_SEPARATOR . "lotgd.yml";
}
$this->rootNamespace = $this->findRootNamespace($package);
if (file_exists($confFile)) {
$this->rawConfig = Yaml::parse(file_get_contents($confFile));
}
else {
} else {
$name = $package->getName();
$type = $package->getType();
throw new \Exception("Package {$name} of type {$type} does not have a lotgd.yml in it's root ($confFile).");
@@ -98,11 +96,10 @@ class BootConfiguration
{
$parent = $this->rawConfig;
foreach ($arguments as $argument){
foreach ($arguments as $argument) {
if (isset($parent[$argument])) {
$parent = $parent[$argument];
}
else {
} else {
return null;
}
}
+1 -2
View File
@@ -27,8 +27,7 @@ class BootConfigurationManager
$packages = $composerManager->getPackages();
$this->configurations = [];
foreach($packages as $package)
{
foreach ($packages as $package) {
if ($package->getType() === "lotgd-crate" || $package->getType() === "lotgd-module") {
$this->configurations[] = new BootConfiguration($composerManager, $package, $cwd);
}
+1 -2
View File
@@ -112,8 +112,7 @@ class Bootstrap
if (empty($configFilePath)) {
$configFilePath = implode(DIRECTORY_SEPARATOR, [$this->rootDir, "config", "lotgd.yml"]);
}
else {
} else {
$configFilePath = $this->rootDir . DIRECTORY_SEPARATOR . $configFilePath;
}
+20 -37
View File
@@ -74,7 +74,7 @@ class BuffList
public function loadBuffs()
{
if ($this->loaded === false) {
foreach($this->buffs as $buff) {
foreach ($this->buffs as $buff) {
$this->buffsBySlot[$buff->getSlot()] = $buff;
}
}
@@ -89,8 +89,7 @@ class BuffList
{
if ($this->usedBuffs->contains($buff)) {
$used = true;
}
else {
} else {
$used = false;
}
@@ -118,8 +117,7 @@ class BuffList
if ($buff->hasBeenStarted() === false && $used === false) {
$return = $buff->getStartMessage();
$buff->setHasBeenStarted();
}
elseif($used === false) {
} elseif ($used === false) {
$return = $buff->getRoundMessage();
}
@@ -196,7 +194,7 @@ class BuffList
/* @var $endEvents Collection */
$endEvents = new ArrayCollection();
foreach($this->usedBuffs as $buff) {
foreach ($this->usedBuffs as $buff) {
/* @var $roundsLeft int */
$roundsLeft = $buff->getRounds() - 1;
$buff->setRounds($roundsLeft);
@@ -304,8 +302,7 @@ class BuffList
// Only look at buffs that are activated in battle.
if ($buff->getsActivatedAt(Buff::ACTIVATE_NONE)) {
continue;
}
else {
} else {
yield $buff;
}
}
@@ -451,15 +448,12 @@ class BuffList
if ($attacksBoth === true) {
if ($game->getDiceBag()->chance(0.5)) {
$who = 1;
}
else {
} else {
$who = -1;
}
}
elseif ($buff->getMinionMaxGoodguyDamage() !== 0 || $buff->getMinionMinGoodguyDamage() !== 0) {
} elseif ($buff->getMinionMaxGoodguyDamage() !== 0 || $buff->getMinionMinGoodguyDamage() !== 0) {
$who = 1;
}
else {
} else {
$who = -1;
}
@@ -467,8 +461,7 @@ class BuffList
// Minion does damage to the goodguy
$damage = $game->getDiceBag()->normal($buff->getMinionMinGoodguyDamage(), $buff->getMinionMaxGoodguyDamage());
$target = $goodguy;
}
else {
} else {
// Minion does damage to the badguy
$damage = $game->getDiceBag()->normal($buff->getMinionMinBadguyDamage(), $buff->getMinionMaxBadguyDamage());
$target = $badguy;
@@ -476,11 +469,9 @@ class BuffList
if ($damage < 0) {
$message = $buff->getEffectFailsMessage();
}
elseif ($damage > 0) {
} elseif ($damage > 0) {
$message = $buff->getEffectSucceedsMessage();
}
else {
} else {
$message = $buff->getNoEffectMessage();
}
@@ -516,7 +507,7 @@ class BuffList
): Collection {
$events = [];
foreach($this->activeBuffs[$activation] as $buff) {
foreach ($this->activeBuffs[$activation] as $buff) {
if ($buff->getGoodguyDamageReflection() !== 0.) {
if ($damage > 0) {
// Damage is > 0, so badguy takes damage. We cannot reflect anything, since this buff
@@ -530,8 +521,7 @@ class BuffList
$reflectedDamage = (int)round($buff->getGoodguyDamageReflection() * $damage * -1, 0);
if ($reflectedDamage === 0) {
$message = $buff->getNoEffectMessage();
}
else {
} else {
$message = $buff->getEffectSucceedsMessage();
}
}
@@ -549,8 +539,7 @@ class BuffList
$reflectedDamage = (int)round($buff->getGoodguyDamageReflection() * $damage, 0);
if ($reflectedDamage === 0) {
$message = $buff->getNoEffectMessage();
}
else {
} else {
$message = $buff->getEffectSucceedsMessage();
}
} elseif ($damage == 0) {
@@ -574,18 +563,15 @@ class BuffList
// Damage is > 0, badguy takes damage. Goodguy lifetap works only upon damage to the goodguy.
$healAmount = 0;
$message = $buff->getEffectFailsMessage();
}
elseif ($damage < 0) {
} elseif ($damage < 0) {
// Damage is < 0, goodguy takes damage. We act upon this.
$healAmount = (int)round($damage * -$buff->getBadguyLifetap(), 0);
if ($healAmount === 0) {
$message = $buff->getNoEffectMessage();
}
else {
} else {
$message = $buff->getEffectSucceedsMessage();
}
}
else {
} else {
$healAmount = 0;
$message = $buff->getNoEffectMessage();
}
@@ -603,17 +589,14 @@ class BuffList
$healAmount = (int)round($damage * $buff->getBadguyLifetap(), 0);
if ($healAmount === 0) {
$message = $buff->getNoEffectMessage();
}
else {
} else {
$message = $buff->getEffectSucceedsMessage();
}
}
elseif ($damage < 0) {
} elseif ($damage < 0) {
// Damage is < 0, goodguy takes damage. Badguy lifetap works only upon damage to the goodguy.
$healAmount = 0;
$message = $buff->getEffectFailsMessage();
}
else {
} else {
$healAmount = 0;
$message = $buff->getNoEffectMessage();
}
+4 -6
View File
@@ -32,11 +32,9 @@ class ComposerManager
// Search "true" working directory
if (file_exists(getcwd() . "/composer.json")) {
$cwd = getcwd() . "/";
}
elseif (file_exists(getcwd() . "/../composer.json")) {
} elseif (file_exists(getcwd() . "/../composer.json")) {
$cwd = getcwd() . "/../";
}
else {
} else {
$cwd = getcwd();
throw new InvalidConfigurationException("composer.json has neither been found in {$cwd} nor in it's parent directory.");
}
@@ -59,7 +57,7 @@ class ComposerManager
$packages = $this->getComposer()->getRepositoryManager()->getLocalRepository()->getPackages();
foreach ($packages as $p) {
if ($p->getName() === $library) {
return $p;
return $p;
}
}
throw new LibraryDoesNotExistException();
@@ -157,7 +155,7 @@ class ComposerManager
implode(DIRECTORY_SEPARATOR, [$cwd, "vendor", "autoload.php"]),
implode(DIRECTORY_SEPARATOR, [__DIR__, "..", "vendor", "autoload.php"]),
implode(DIRECTORY_SEPARATOR, [__DIR__, "..", "autoload.php"]),
];
];
foreach ($order as $path) {
if (file_exists($path)) {
+2 -1
View File
@@ -17,7 +17,8 @@ use LotGD\Core\Console\Command\{
/**
* Main execution class for the daenerys tool.
*/
class Main {
class Main
{
private $application;
private $bootstrap;
private $game;
+2 -4
View File
@@ -80,11 +80,9 @@ class DiceBag
if ($min === $max) {
return (int)round($min/1000, 0);
}
elseif ($min < $max) {
} elseif ($min < $max) {
return (int)round(mt_rand($min, $max)/1000, 0);
}
else {
} else {
return (int)round(mt_rand($max, $min)/1000, 0);
}
}
+2 -1
View File
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a scene action is not found.
*/
class ActionNotFoundException extends CoreException {
class ActionNotFoundException extends CoreException
{
}
+2 -1
View File
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a specific, required argument is missing
*/
class AttributeMissingException extends CoreException {
class AttributeMissingException extends CoreException
{
}
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a character is not found.
*/
class CharacterNotFoundException extends CoreException {
class CharacterNotFoundException extends CoreException
{
}
+2 -1
View File
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a specific, required argument is missing
*/
class ClassNotFoundException extends CoreException {
class ClassNotFoundException extends CoreException
{
}
+2 -1
View File
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Base exceptions for all core errors.
*/
class CoreException extends \Exception {
class CoreException extends \Exception
{
}
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a configuration value is missing or invalid.
*/
class InvalidConfigurationException extends CoreException {
class InvalidConfigurationException extends CoreException
{
}
+2 -1
View File
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a specific, required argument is missing
*/
class IsNullException extends CoreException {
class IsNullException extends CoreException
{
}
+2 -1
View File
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a specific, required argument is missing
*/
class KeyNotFoundException extends CoreException {
class KeyNotFoundException extends CoreException
{
}
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a Composer library does not exists.
*/
class LibraryDoesNotExistException extends CoreException {
class LibraryDoesNotExistException extends CoreException
{
}
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a module already exists.
*/
class ModuleAlreadyExistsException extends CoreException {
class ModuleAlreadyExistsException extends CoreException
{
}
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a module does not exists.
*/
class ModuleDoesNotExistException extends CoreException {
class ModuleDoesNotExistException extends CoreException
{
}
+2 -1
View File
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a specific, required argument is missing
*/
class NoParentSetException extends CoreException {
class NoParentSetException extends CoreException
{
}
+2 -1
View File
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a specific, required argument is missing
*/
class NotImplementedException extends CoreException {
class NotImplementedException extends CoreException
{
}
+2 -1
View File
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a specific, required argument is missing
*/
class ParentAlreadySetException extends CoreException {
class ParentAlreadySetException extends CoreException
{
}
+2 -1
View File
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a scene is not found.
*/
class SceneNotFoundException extends CoreException {
class SceneNotFoundException extends CoreException
{
}
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if an event subscription does not exist.
*/
class SubscriptionNotFoundException extends CoreException {
class SubscriptionNotFoundException extends CoreException
{
}
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Gets thrown if a array containts an unexpected array key
*/
class UnexpectedArrayKeyException extends CoreException {
class UnexpectedArrayKeyException extends CoreException
{
}
+2 -1
View File
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a specific, required argument is missing
*/
class WrongParentException extends CoreException {
class WrongParentException extends CoreException
{
}
+2 -1
View File
@@ -6,6 +6,7 @@ namespace LotGD\Core\Exceptions;
/**
* Exception if a variable has the wrong type.
*/
class WrongTypeException extends CoreException {
class WrongTypeException extends CoreException
{
}
+3 -1
View File
@@ -255,7 +255,9 @@ class Game
$v->setOwner($this->getCharacter());
$v->changeFromScene($s);
$ag = new ActionGroup('lotgd/core/default', '', 0);
$as = array_map(function ($c) { return new Action($c->getId()); }, $s->getChildren()->toArray());
$as = array_map(function ($c) {
return new Action($c->getId());
}, $s->getChildren()->toArray());
$ag->setActions($as);
$v->setActions([$ag]);
+1 -1
View File
@@ -120,4 +120,4 @@ abstract class BasicEnemy implements FighterInterface
return false;
}
}
}
}
+2 -1
View File
@@ -16,7 +16,8 @@ class BuffMessageEvent extends BattleEvent
* Create a new BuffMessageEvent.
* @param string $message The message from the buff.
*/
public function __construct(string $message) {
public function __construct(string $message)
{
$this->message = $message;
}
+3 -6
View File
@@ -68,22 +68,19 @@ class DamageEvent extends BattleEvent
if ($this->damage === 0) {
if ($this->attacker === $game->getCharacter()) {
return "You try to hit {$defendersName} but MISS!";
}
else {
} else {
return "{$attackersName} tries to hit you but they MISS!";
}
} elseif ($this->damage > 0) {
if ($this->attacker === $game->getCharacter()) {
return "You hit {$defendersName} for {$this->damage} points of damage!";
}
else {
} else {
return "{$attackersName} hits you for {$this->damage} points of damage!";
}
} else {
if ($this->attacker === $game->getCharacter()) {
return "You try to hit {$defendersName} but are RIPOSTED for {$this->damage} points of damage";
}
else {
} else {
return "{$attackersName} tries to hit you but you RIPOSTE for {$this->damage} points of damage";
}
}
-1
View File
@@ -26,7 +26,6 @@ class DeathEvent extends BattleEvent
*/
public function apply()
{
}
/**
@@ -52,8 +52,7 @@ class RegenerationBuffEvent extends BattleEvent
$target->getDisplayName(),
$this->noEffectMessage
);
}
else {
} else {
return str_replace(
[
"{target}",
@@ -82,17 +81,14 @@ class RegenerationBuffEvent extends BattleEvent
// Healing
if ($healthLacking === 0) {
$this->regeneration = 0;
}
elseif ($healthLacking < $this->regeneration) {
} elseif ($healthLacking < $this->regeneration) {
$this->regeneration = $healthLacking;
}
}
else {
} else {
// Damaging
if ($healthLeft === 0) {
$this->regeneration = 0;
}
elseif ($healthLeft < -1*$this->regeneration) {
} elseif ($healthLeft < -1*$this->regeneration) {
$this->regeneration = - $healthLeft;
}
}
+13 -12
View File
@@ -25,7 +25,7 @@ class Buff
/** @Id @Column(type="integer") @GeneratedValue */
private $id;
/**
/**
* @ManyToOne(targetEntity="Character", inversedBy="buffs")
* @JoinColumn(nullable=True)
*/
@@ -100,7 +100,7 @@ class Buff
private $expiresAfterBattle = false;
/**
* The number of rounds this buff lasts.
*
*
* Gets reduces very round by 1. If the value is < 0, the buff is permament until a new day arises.
* @var int
* @Column(type="integer")
@@ -229,7 +229,7 @@ class Buff
/**
* Allowed buff values and their type
* @var array
* @var array
*/
private $buffArrayTemplate = [
"slot" => "string",
@@ -268,7 +268,7 @@ class Buff
/**
* Requried buff values.
* @var type
* @var type
*/
private $required = [
"slot",
@@ -280,14 +280,15 @@ class Buff
* @param array $buffArray
* @throws ArgumentException
*/
public function __construct(array $buffArray) {
foreach($buffArray as $attribute => $value) {
public function __construct(array $buffArray)
{
foreach ($buffArray as $attribute => $value) {
// Throw exception if an attribute does not exist (to prevent spelling errors)
if (!isset($this->buffArrayTemplate[$attribute])) {
throw new ArgumentException("{$attribute} is not a valid key for a buff.");
}
switch($this->buffArrayTemplate[$attribute]) {
switch ($this->buffArrayTemplate[$attribute]) {
case "string":
if (is_string($value) === false) {
throw new ArgumentException("{$attribute} needs to be a string.");
@@ -321,7 +322,7 @@ class Buff
$this->{$attribute} = $value;
}
foreach($this->required as $required) {
foreach ($this->required as $required) {
if (is_null($this->$required)) {
throw new ArgumentException("{$required} needs to be inside of the buffArray!");
}
@@ -333,10 +334,11 @@ class Buff
* @param \LotGD\Core\Models\Buff $buff
* @return \LotGD\Core\Models\Buff
*/
public static function constructFromTemplate(Buff $buff): Buff {
public static function constructFromTemplate(Buff $buff): Buff
{
$buffArray = [];
foreach($this->buffArrayTemplate as $attribute => $type) {
foreach ($this->buffArrayTemplate as $attribute => $type) {
$buffArray[$attribute] = $buff->$attribute;
}
@@ -460,8 +462,7 @@ class Buff
{
if ($flag === self::ACTIVATE_NONE) {
return $this->activateAt == self::ACTIVATE_NONE ? true : false;
}
else {
} else {
return ($this->activateAt & $flag) == true;
}
}
+1 -1
View File
@@ -279,7 +279,7 @@ class Character implements CharacterInterface, CreateableInterface
{
try {
$this->getBuffs()->add($buff);
} catch(BuffSlotOccupiedException $e) {
} catch (BuffSlotOccupiedException $e) {
$this->getBuffs()->renew($buff);
}
}
+1 -1
View File
@@ -15,4 +15,4 @@ use Doctrine\ORM\Mapping\Table;
class GameConfigurationElement
{
use Properties;
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ use LotGD\Core\Tools\Model\AutoScaleFighter;
/**
* The Monster entity
*
*
* @Entity
* @Table(name="masters")
*/
+5 -7
View File
@@ -69,7 +69,7 @@ class Message
/**
* Constructs the message.
*
*
* This method has been made protected to prevent from accessing it directly. Use
* the static methods self::send() and self::sendSystemMessage() instead.
* @param \LotGD\Core\Models\Character $from
@@ -118,15 +118,14 @@ class Message
{
if (is_null($this->author)) {
return SystemCharacter::getInstance();
}
else {
} else {
return $this->author;
}
}
/**
* Returns the apparant character of the message.
*
*
* If a character sends a system message, this method will return the SystemCharacter message
* instead of the true author.
* @return \LotGD\Core\Models\CharacterInterface
@@ -135,8 +134,7 @@ class Message
{
if ($this->isSystemMessage()) {
return SystemCharacter::getInstance();
}
else {
} else {
return $this->getAuthor();
}
}
@@ -161,7 +159,7 @@ class Message
/**
* Sets the thread this message belongs to, once.
*
*
* A message that belongs to a thread needs to stay there - there is no need for messages to
* switch the thread and end up in a complete different discussion.
* @param \LotGD\Core\Models\MessageThread $thread
+4 -5
View File
@@ -14,7 +14,7 @@ use LotGD\Core\Tools\Model\Saveable;
/**
* A Thread of messages
*
*
* @Entity(repositoryClass="LotGD\Core\Models\Repositories\MessageThreadRepository")
* @Table(name="message_threads")
*/
@@ -71,7 +71,7 @@ class MessageThread implements SaveableInterface
}
/**
*
*
* @param \LotGD\Core\Models\Message $message
* @throws CoreException
*/
@@ -79,8 +79,7 @@ class MessageThread implements SaveableInterface
{
if ($this->isReadonly() && $message->getApparantAuthor() instanceof SystemCharacter === false) {
throw new CoreException("Cannot write a normal message to a readonly thread");
}
else {
} else {
$this->messages->add($message);
}
}
@@ -108,7 +107,7 @@ class MessageThread implements SaveableInterface
* @param EntityManagerInterface $em
*/
public function save(EntityManagerInterface $em)
{
{
foreach ($this->participants as $participant) {
$participantsMessageThreads = $participant->getMessageThreads();
if ($participantsMessageThreads->contains($this) === false) {
+1 -1
View File
@@ -41,4 +41,4 @@ class MissingCharacter implements CharacterInterface
{
return $this->displayname;
}
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ use LotGD\Core\Tools\Model\AutoScaleFighter;
/**
* The Monster entity
*
*
* @Entity
* @Table(name="monsters")
*/
@@ -25,14 +25,14 @@ class MessageThreadRepository extends EntityRepository
{
// ToDo: Replace array with CharacterCollection
usort(
$listOfCharacters,
function($a, $b) {
$listOfCharacters,
function ($a, $b) {
return $a->getId() <=> $b->getId();
}
);
$threadParticipants = "";
foreach($listOfCharacters as $character) {
foreach ($listOfCharacters as $character) {
$threadParticipants .= $character->getId() . ".";
}
+6 -8
View File
@@ -39,8 +39,7 @@ class ModuleManager
// Minimal scrub to the subscriptions list.
foreach ($extra['lotgd-subscriptions'] as $s) {
if (!is_string($s))
{
if (!is_string($s)) {
$this->g->getLogger()->error("Module {$name} has invalid event subscription: {$s}.");
continue;
}
@@ -76,8 +75,7 @@ class ModuleManager
$name = $package->getName();
if (!isset($package->getExtra()['lotgd-namespace']) ||
!is_string($package->getExtra()['lotgd-namespace']))
{
!is_string($package->getExtra()['lotgd-namespace'])) {
throw new KeyNotFoundException("Module {$name} is missing a valid 'lotgd-namespace' entry in its extra field.");
}
@@ -145,7 +143,8 @@ class ModuleManager
* Returns the list of currently registered modules.
* @return array<Module> Array of modules.
*/
public function getModules(): array {
public function getModules(): array
{
return $this->g->getEntityManager()->getRepository(ModuleModel::class)->findAll();
}
@@ -180,7 +179,7 @@ class ModuleManager
$class = $p->getExtra()['lotgd-namespace'] . 'Module';
$expectedSubscriptions = ModuleManager::getPackageSubscriptions($p);
$currentSubscriptionsForThisPackage = array_filter($currentSubscriptions, function($s) use ($name) {
$currentSubscriptionsForThisPackage = array_filter($currentSubscriptions, function ($s) use ($name) {
return $s->getLibrary() === $name;
});
@@ -193,8 +192,7 @@ class ModuleManager
// Count the subscriptions for this
if ($c->getPattern() === $e &&
$c->getClass() === $class &&
$c->getLibrary() === $p->getName())
{
$c->getLibrary() === $p->getName()) {
$found = true;
break;
}
+2 -1
View File
@@ -14,7 +14,8 @@ use LotGD\Core\{
* Automatically calculated values based on the fighter's level
*/
trait AutoScaleFighter
{
{
/**
* Returns the maximum health based on the fighter's level
* @return int
+4 -2
View File
@@ -13,12 +13,14 @@ use LotGD\Core\Exceptions\{
/**
* Provides methods for deleting entities.
*/
trait Deletor {
trait Deletor
{
/**
* Deletes the entity
* @param EntityManagerInterface $em
*/
public function delete(EntityManagerInterface $em) {
public function delete(EntityManagerInterface $em)
{
$em->remove($this);
$em->flush();
}
+2 -1
View File
@@ -16,7 +16,8 @@ use LotGD\Core\Models\CharacterViewpoint;
*/
trait MockCharacter
{
public function __call($name, $arguments) {
public function __call($name, $arguments)
{
throw new IsNullException();
}
+3 -2
View File
@@ -49,7 +49,8 @@ trait Properties
* Sets the stored property
* @param mixed $value
*/
public function setValue($value) {
public function setValue($value)
{
$this->propertyValue = serialize($value);
}
}
}
+12 -11
View File
@@ -33,7 +33,7 @@ class OneToManyCollection implements Collection
*/
public function __construct(EntityManagerInterface $entityManager, string $typeClass)
{
if(class_exists($typeClass) === false) {
if (class_exists($typeClass) === false) {
throw new ClassNotFoundException(sprintf("The class %s has not been found.", $typeClass));
}
@@ -69,8 +69,7 @@ class OneToManyCollection implements Collection
if ($this->collection === null) {
return $this->numberOfRows;
}
else {
} else {
return count($this->collection);
}
}
@@ -121,8 +120,7 @@ class OneToManyCollection implements Collection
{
try {
$this->checkElementType($element);
}
catch (WrongTypeException $e) {
} catch (WrongTypeException $e) {
return false;
}
@@ -178,8 +176,7 @@ class OneToManyCollection implements Collection
{
if (isset($this->collection[$key])) {
return $this->collection[$key];
}
else {
} else {
throw new KeyNotFoundException(sprintf("The key %s has not been found within the collection", $key));
}
}
@@ -329,28 +326,32 @@ class OneToManyCollection implements Collection
/**
* @inheritDoc
*/
public function offsetGet($key) {
public function offsetGet($key)
{
return $this->get($key);
}
/**
* @inheritDoc
*/
public function offsetSet($key, $element) {
public function offsetSet($key, $element)
{
$this->set($key, $element);
}
/**
* @inheritDoc
*/
public function offsetUnset($key) {
public function offsetUnset($key)
{
$this->remove($key);
}
/**
* @inheritDoc
*/
public function offsetExists($key) {
public function offsetExists($key)
{
return isset($this->collection[$key]);
}
}