Куча мелочей, в том числе по #42.

This commit is contained in:
lopar
2021-08-25 04:44:36 +03:00
parent cbbbb8a3c6
commit 1f38e6bd61
21 changed files with 223 additions and 378 deletions
+18 -19
View File
@@ -11,24 +11,24 @@ class Clan
private $clan;
public static Clan $current;
public function __construct(User $user, DBPDO $db)
public function __construct()
{
$this->db = $db;
$this->user = $user;
$this->db = DBPDO::$db;
$this->user = User::$current;
$this->clan = $this->db->ofetch('select * from clans where owner_id = ?', $this->user->getId());
}
public function addMember(string $login): string
{
$target = new User($login);
$error = null;
$check = $this->db->ofetch('select id, level, clan from users where login = ?', $login);
if (!$this->getProverka($check->id)) {
if (!$this->getProverka($target->getId())) {
$error .= '<br>Нет проверки!';
}
if ($check->clan) {
if ($target->getClan()) {
$error .= '<br>Персонаж уже состоит в клане!';
}
if ($check->level < 1) {
if ($target->getLevel() < 1) {
$error .= '<br>Персонаж 0 уровня не может быть принят!';
}
if ($this->user->getMoney() < GameConfigs::CLAN['add_member_cost']) {
@@ -39,21 +39,21 @@ class Clan
}
$this->user->setMoney($this->user->getMoney() - GameConfigs::CLAN['add_member_cost']);
$this->user->saveMoney();
$this->db->execute('update users set clan = ? where id = ?', [$this->user->getClan(), $check->id]);
$target->setClan($this->user->getClan());
return "Персонаж «{$login}» успешно принят в клан.";
}
public function removeMember(string $login): string
{
$target = new User($login);
$error = null;
$check = $this->db->ofetch('select id, clan from users where login = ?', $login);
if ($this->user->getMoney() < GameConfigs::CLAN['remove_member_cost']) {
$error .= '<br>Недостаточно денег!';
}
if ($check->id === $this->user->getId()) {
if ($target->getId() === $this->user->getId()) {
$error .= '<br>Себя выгонять нельзя!';
}
if ($check->clan !== $this->user->getClan()) {
if ($target->getClan() !== $this->user->getClan()) {
$error .= '<br>Персонаж не состоит в этом клане!';
}
if ($error) {
@@ -61,28 +61,28 @@ class Clan
}
$this->user->setMoney($this->user->getMoney() - GameConfigs::CLAN['remove_member_cost']);
$this->user->saveMoney();
$this->db->execute('update users set clan = null where id = ?', $check->id);
$target->setClan(null);
return "Персонаж «{$login}» покинул клан.";
}
public function changeOwner(string $login): string
{
$target = new User($login);
$error = null;
$check = $this->db->ofetch('select id, clan from users where login = ?', $login);
if ($check->id === $this->user->getId()) {
if ($target->getId() === $this->user->getId()) {
$error .= '<br>Самоудовлетворяетесь? ;)';
}
if ($check->clan !== $this->user->getClan()) {
if ($target->getClan() !== $this->user->getClan()) {
$error .= '<br>Персонаж не состоит в этом клане!';
}
if ($error) {
return $error;
}
$this->db->execute('update clans set owner_id = ? where owner_id = ?', [$check->id, $this->user->getId()]);
$this->db->execute('update clans set owner_id = ? where owner_id = ?', [$target->getId(), $this->user->getId()]);
return 'Вы передали управление кланом персонажу «' . $login . '».';
}
public function setClanInfo(string $text)
public function setClanInfo(string $text): string
{
$check = $this->db->ofetch('select id from users where clan = (select short_name from clans where owner_id = ?)', $this->user->getId());
if ($check->id !== $this->user->getId()) {
@@ -94,8 +94,7 @@ class Clan
public function getMemberlist(): array
{
$query = 'select id, (select 1 from clans where short_name = clan and owner_id = id) as clan_owner, room from users where clan = ? order by clan_owner desc, room, login';
return $this->db->ofetchAll($query, $this->user->getClan());
return $this->db->ofetchAll('select id, (select 1 from clans where short_name = clan and owner_id = id) as clan_owner, room from users where clan = ? order by clan_owner desc, room, login', $this->user->getClan());
}
private function getProverka($user_id)