battles/classes/User.php

219 lines
6.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
const EMPTY_SLOT = <<<EMPTY_SLOT
<img src="/i/sh/noitem.png" class="item-wrap-normal" title="Пустой слот" alt="Пустой слот>
EMPTY_SLOT;
use Rooms;
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
<img src="/i/sh/noitem.png" class="item-wrap-normal" title="Пустой слот [{$item}]" alt="Пустой слот [{$item}]">
EMPTY_SLOT;
}
}
public function showUserInfo()
{
$dressed_item = [];
$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 <<<USERINFO
<table width=100%>
<tr>
<td style="width: 250px; vertical-align: top;">
<div style="text-align: center">
USERINFO;
if ($this->align) {
echo sprintf('<img src="/i/align_%s.png" alt="Склонность">', $this->align);
}
if ($this->block) {
echo sprintf('<span class="private"><s>%s</s></span>', $this->login);
} else {
echo sprintf('<strong>%s</strong>', $this->login);
}
if ($this->clan) {
echo sprintf('<img src="/i/clan/%s.png" alt="%s">', $this->clan, $this->clan);
}
echo <<<USERINFO
</div>
<div style="width: 100%; height: 16px; background: #ffaaff; overflow: hidden; border-radius: 3px; font-size: 14px; text-align: center;">
добавить здоровье
</div>
<table style="width: 100%; text-align: center;">
<tr>
<td width=62 valign=top>
<table width=100%>
<tr>
<td>
USERINFO;
if (isset($dressed_item[1])) {
$this->showItem($dressed_item[1]);
} else {
$this->showItem(1);
}
echo '</td></tr><tr><td>';
if (isset($dressed_item[2])) {
$this->showItem($dressed_item[2]);
} else {
$this->showItem(2);
}
echo '</td></tr><tr><td>';
if (isset($dressed_item[3])) {
$this->showItem($dressed_item[3]);
} else {
$this->showItem(3);
}
echo '</td></tr><tr><td>';
if (isset($dressed_item[4])) {
$this->showItem($dressed_item[4]);
} else {
$this->showItem(4);
}
echo '</td></tr>';
echo <<<USERINFO
</table>
</td>
<td valign=top>
<img src="/i/shadow/{$this->shadow}" onerror=" this.src = '/i/shadow/0.gif';">
</td>
<td width="62" valign=top>
<table width=100%>
<tr>
<td>
USERINFO;
if (isset($dressed_item[5])) {
$this->showItem($dressed_item[5]);
} else {
$this->showItem(5);
}
echo '</td></tr><tr><td>';
if (isset($dressed_item[6])) {
$this->showItem($dressed_item[6]);
} else {
$this->showItem(6);
}
echo '</td></tr><tr><td>';
if (isset($dressed_item[7])) {
$this->showItem($dressed_item[7]);
} else {
$this->showItem(7);
}
echo '</td></tr><tr><td>';
if (isset($dressed_item[8])) {
$this->showItem($dressed_item[8]);
} else {
$this->showItem(8);
}
echo '</td></tr>
</table>
</td>
</tr>
</table>
<div style="text-align: center">';
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 <<<USERINFO
</div>
</td>
<td width="100%">
Имя {$this->login} <br>
Сила {$this->strength} <br>
Ловкость {$this->dexterity} <br>
Интуиция {$this->intuition} <br>
Выносливость {$this->endurance} <br>
Интеллект {$this->intelligence} <br>
Мудрость {$this->wisdom} <br>
Находится в {$this->getRoomName($this->room)}<br>
</td>
<td style="vertical-align: top; width: 100px; text-align: center;">
<img src="i/zodiac/<?= star_sign($this->borndate); ?>.png" alt="Родовой знак">
</td>
</tr>
</table>
USERINFO;
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);
}
// if (isset($dressed_item[1])) {
// $this->showItem($dressed_item[1]);
// }
// if (isset($dressed_item[2])) {
// $this->showItem($dressed_item[2]);
// }
// if (isset($dressed_item[4])) {
// $this->showItem($dressed_item[4]);
// }
}
}