/** * @param \Likedimion\Tools\Helper\PlayerDataHelper $playerData * @throws \Likedimion\Exception\RegistrationException * @return Player */ public function createPlayer(PlayerDataHelper $playerData) { try { $findPlayer = $this->playerService->getRepository()->findPlayerByName($playerData->name); throw new RegistrationException("player_name_exists"); } catch (EntityNotFoundException $e) { $player = new Player(); $player->setName($playerData->name); $player->setSex($playerData->sex); $player->setClass($playerData->class); $player->setRace($playerData->race); $stats = $player->getStats(); $cfg = Game::getInstance()->getConfig(); $stats->setStrenge($cfg["new_player"][$player->getClass()]["str"]); $stats->setDexterity($cfg["new_player"][$player->getClass()]["dex"]); $stats->setIntelligence($cfg["new_player"][$player->getClass()]["int"]); $stats->setSpirituality($cfg["new_player"][$player->getClass()]["spr"]); $stats->setEndurance($cfg["new_player"][$player->getClass()]["end"]); $player->setStats($stats); $this->playerCalculatingService->calculate($player); $this->playerService->getRepository()->save($player); $account = $this->authService->getAccount(Game::getInstance()->getAuthToken()->getValue()); $player->setAccount($account); $this->accountService->getRepository()->save($account); $this->playerService->getRepository()->save($player); return $player; } }
public function testCreatePlayer() { try { $token = $this->authService->login($this->email, $this->password); $this->game->setAuthToken($token); $player = $this->playerRegistrationService->createPlayer($this->playerData); $this->assertInstanceOf($this->entityClass, $player); $this->playerService->getRepository()->remove($player); } catch (RegistrationException $e) { $this->fail($e->getMessage()); } }
public function onAction(PlayerEvent $player) { $player->getPlayer()->setLastActionTime(time()); $this->playerService->getRepository()->save($player->getPlayer()); }