battles/classes/User.php

181 lines
6.0 KiB
PHP
Raw Normal View History

<?php
class User
{
public $id;
public $login;
public $email;
public $realname;
public $borndate;
public $info;
public $level;
public $align;
public $clan;
public $money;
public $strength;
public $dexterity;
public $intuition;
public $endurance;
public $intelligence;
public $wisdom;
public $ip;
public $session_id;
public $admin;
public $enter_game;
public $room;
public $block;
// Пока несуществующие, для совместимости.
public $married;
public $exp;
public $stats;
public $shadow;
2020-07-04 23:25:14 +00:00
const EMPTY_SLOT = <<<EMPTY_SLOT
<img src="/i/sh/noitem.png" class="item-wrap-normal" title="Пустой слот" alt="Пустой слот>
EMPTY_SLOT;
2020-07-04 10:49:43 +00:00
use Rooms;
2020-07-03 13:33:34 +00:00
public function __construct($user)
{
$user_query = db::c()->query('SELECT * FROM users WHERE id = "?s" OR login = "?s"', $user, $user)->fetch_assoc();
foreach ($this as $key => $value) {
if (isset($user_query[$key])) {
$this->$key = $user_query[$key];
}
}
}
protected function showItem($item = 0)
{
$itemSlot = $item['dressed_slot'] ?? 0;
$itemName = $item['name'] ?? '';
$itemImage = $item['image'] ?? '';
if ($itemSlot) {
echo <<<SLOT
<img src="/i/sh/{$itemImage}" class="item-wrap-normal tip" alt="Слот [{$itemSlot}]">
<span class="tiptext"><strong>{$itemName}</strong></span>
SLOT;
} else {
echo <<<EMPTY_SLOT
2020-07-04 23:29:32 +00:00
<img src="/i/sh/noitem.png" class="item-wrap-normal" title="Пустой слот [{$item}]" alt="Пустой слот [{$item}]">
EMPTY_SLOT;
}
}
public function showUserInfo()
{
$dressed_items = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $this->id);
while ($row = $dressed_items->fetch_assoc()) {
$dressed_item[$row['dressed_slot']] = $row;
}
echo '<div class="user-info-container">';
echo '<div class="slot-1">';
if (isset($dressed_item[1])) {
$this->showItem($dressed_item[1]);
} else {
$this->showItem(1);
}
echo '</div><!-- slot-1 -->';
echo '<div class="slot-2">';
if (isset($dressed_item[2])) {
$this->showItem($dressed_item[2]);
} else {
$this->showItem(2);
}
echo '</div><!-- slot-2 -->';
echo '<div class="slot-3">';
if (isset($dressed_item[3])) {
$this->showItem($dressed_item[3]);
} else {
$this->showItem(3);
}
echo '</div><!-- slot-3 -->';
echo '<div class="slot-4">';
if (isset($dressed_item[4])) {
$this->showItem($dressed_item[4]);
} else {
$this->showItem(4);
}
echo '</div><!-- slot-4 -->';
echo '<div class="slot-5">';
if (isset($dressed_item[5])) {
$this->showItem($dressed_item[5]);
} else {
$this->showItem(5);
}
echo '</div><!-- slot-5 -->';
echo '<div class="slot-6">';
if (isset($dressed_item[6])) {
$this->showItem($dressed_item[6]);
} else {
$this->showItem(6);
}
echo '</div><!-- slot-6 -->';
echo '<div class="slot-7">';
if (isset($dressed_item[7])) {
$this->showItem($dressed_item[7]);
} else {
$this->showItem(7);
}
echo '</div><!-- slot-7 -->';
echo '<div class="slot-8">';
if (isset($dressed_item[8])) {
$this->showItem($dressed_item[8]);
} else {
$this->showItem(8);
}
echo '</div><!-- slot-8 -->';
echo '<div class="slot-lower">';
if (isset($dressed_item[9])) {
$this->showItem($dressed_item[9]);
} else {
$this->showItem(9);
}
if (isset($dressed_item[10])) {
$this->showItem($dressed_item[10]);
} else {
$this->showItem(10);
}
if (isset($dressed_item[11])) {
$this->showItem($dressed_item[11]);
} else {
$this->showItem(11);
}
echo '</div><!-- slot-lower -->';
echo '<div class="slot-image">';
echo sprintf('<img src="/i/shadow/%s" width="200" height="430" alt="%s">', $this->shadow, $this->login);
echo '</div><!-- slot-image -->';
echo '<div class="user-signs">';
echo sprintf('<img src="i/zodiac/%s.png" alt="Родовой знак">', star_sign($this->borndate));
echo '</div><!-- user-signs -->';
echo '<div class="user-info">';
2020-07-05 15:45:59 +00:00
echo '<div class="stats-container">';
echo '<div class="column">';
echo 'Уровень<br>Сила<br>Ловкость<br>Интуиция<br>Выносливость<br>Интеллект<br>Мудрость<br>Находится в:';
echo '</div><!-- column -->';
2020-07-05 15:45:59 +00:00
echo '<div class="column">';
echo $this->level . '<br>' . $this->strength . '<br>' . $this->dexterity . '<br>' . $this->intuition . '<br>' . $this->endurance . '<br>' . $this->intelligence . '<br>' . $this->wisdom . '<br>' . $this->getRoomName($this->room);
echo '</div><!-- column -->';
echo '</div><!-- stats-container -->';
if ($this->married) {
echo sprintf('<a href = "inf.php?%s" target = _blank ><img alt = "В браке с %s" src = "i/married.gif" title = "В браке с %s"></a >', $this->married, $this->married, $this->married);
}
echo '</div><!-- user-info -->';
echo '</div><!-- user-info-container -->';
echo '<hr><!-- Нижняя часть -->';
echo '<div class="user-info-container-lower">';
echo '<h2>Об игроке</h2>';
if ($this->realname) {
echo sprintf('Имя: %s<br>', $this->realname);
}
if ($this->info) {
echo nl2br($this->info);
}
echo '</div><!-- user-info-container-lower -->';
2020-07-04 10:49:43 +00:00
}
}