2020-07-03 13:23:08 +00:00
|
|
|
|
<?php
|
2021-01-27 15:56:04 +00:00
|
|
|
|
|
2020-10-28 20:21:08 +00:00
|
|
|
|
namespace Battles;
|
2021-01-27 15:56:04 +00:00
|
|
|
|
|
2021-01-28 21:05:34 +00:00
|
|
|
|
use Battles\Database\DBPDO;
|
2020-07-03 13:23:08 +00:00
|
|
|
|
|
|
|
|
|
class User
|
|
|
|
|
{
|
2021-08-25 01:44:36 +00:00
|
|
|
|
protected int $id = 0;
|
|
|
|
|
protected string $login = '';
|
|
|
|
|
protected ?string $pass = null;
|
|
|
|
|
protected ?string $email = null;
|
|
|
|
|
protected ?string $realname = null;
|
|
|
|
|
protected ?string $borndate = null;
|
|
|
|
|
protected ?string $info = null;
|
|
|
|
|
protected int $level = 0;
|
|
|
|
|
protected ?int $align = null;
|
|
|
|
|
protected ?string $clan = null;
|
|
|
|
|
protected ?int $money = null;
|
|
|
|
|
protected ?string $ip = null;
|
|
|
|
|
|
|
|
|
|
protected ?int $admin = null;
|
|
|
|
|
protected int $room = 0;
|
|
|
|
|
protected int $block = 0;
|
|
|
|
|
protected string $shadow = '';
|
2021-03-10 21:38:14 +00:00
|
|
|
|
|
2020-07-03 13:49:39 +00:00
|
|
|
|
// Пока несуществующие, для совместимости.
|
2021-08-25 01:44:36 +00:00
|
|
|
|
protected int $experience = 0;
|
|
|
|
|
protected int $battle = 0;
|
|
|
|
|
protected int $in_tower = 0; // Скорее башню похороним чем запустим...
|
|
|
|
|
protected int $zayavka = 0;
|
|
|
|
|
protected static DBPDO $db;
|
2020-07-04 10:49:43 +00:00
|
|
|
|
|
2021-03-10 21:03:59 +00:00
|
|
|
|
public const INFO_CHAR_LIMIT = 1500;
|
2021-08-25 01:44:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* @var User Переменная инициализируемая при запуске, хранящая объект текущего пользователя.
|
|
|
|
|
*/
|
|
|
|
|
public static User $current;
|
2021-03-10 21:03:59 +00:00
|
|
|
|
|
2021-08-25 01:44:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* @param int|string $user
|
|
|
|
|
*/
|
2021-03-10 21:03:59 +00:00
|
|
|
|
public function __construct($user)
|
2020-07-03 13:23:08 +00:00
|
|
|
|
{
|
2021-01-28 21:05:34 +00:00
|
|
|
|
self::$db = DBPDO::INIT();
|
2021-08-25 01:44:36 +00:00
|
|
|
|
$query = 'select * from users where login = ?';
|
|
|
|
|
if (is_numeric($user)) {
|
|
|
|
|
$query = 'select * from users where id = ?';
|
|
|
|
|
$user = (int)$user;
|
|
|
|
|
}
|
|
|
|
|
$user_query = self::$db->fetch($query, $user);
|
2020-07-03 13:23:08 +00:00
|
|
|
|
foreach ($this as $key => $value) {
|
|
|
|
|
if (isset($user_query[$key])) {
|
|
|
|
|
$this->$key = $user_query[$key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-03 16:37:24 +00:00
|
|
|
|
|
2021-05-12 18:51:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* @param int $userId
|
|
|
|
|
* @param int $type
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @param int $time
|
|
|
|
|
* @param string|null $json_modifiers_list (str, dex, int, end, intel, wis).
|
|
|
|
|
*/
|
2021-08-25 01:44:36 +00:00
|
|
|
|
public static function addUserEffect(int $userId, int $type, string $name, int $time, string $json_modifiers_list = null)
|
2020-08-29 18:14:33 +00:00
|
|
|
|
{
|
2021-05-12 18:51:37 +00:00
|
|
|
|
$mods = json_decode($json_modifiers_list);
|
2021-08-25 01:44:36 +00:00
|
|
|
|
self::$db->execute('INSERT INTO users_effects (owner_id, type, name, remaining_time, mod_strength, mod_dexterity, mod_intuition, mod_endurance, mod_intelligence, mod_wisdom) VALUES (?,?,?,?,?,?,?,?,?,?)', [$userId, $type, $name, $time, $mods->str ?? null, $mods->dex ?? null, $mods->int ?? null, $mods->end ?? null, $mods->intel ?? null, $mods->wis ?? null]);
|
2020-07-10 08:08:00 +00:00
|
|
|
|
}
|
2021-01-28 21:05:34 +00:00
|
|
|
|
|
2021-03-10 21:38:14 +00:00
|
|
|
|
public static function removeUserEffect(int $userId, int $type): bool
|
2021-01-28 21:05:34 +00:00
|
|
|
|
{
|
|
|
|
|
if (self::$db->fetch('SELECT 1 FROM users_effects WHERE owner_id = ? AND type = ?', [$userId, $type])) {
|
|
|
|
|
self::$db->execute('DELETE FROM users_effects WHERE owner_id = ? AND type = ?', [$userId, $type]);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-02-01 16:42:52 +00:00
|
|
|
|
|
|
|
|
|
public function getId(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getLogin(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->login;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 01:44:36 +00:00
|
|
|
|
public function getPass(): string
|
2021-02-01 16:42:52 +00:00
|
|
|
|
{
|
|
|
|
|
return $this->pass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param mixed $pass
|
|
|
|
|
*/
|
|
|
|
|
public function setPass($pass): void
|
|
|
|
|
{
|
|
|
|
|
$this->pass = $pass;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-10 21:38:14 +00:00
|
|
|
|
public function savePass()
|
|
|
|
|
{
|
|
|
|
|
self::$db->execute('UPDATE users SET pass = ? WHERE id = ?', [$this->pass, $this->id]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 01:44:36 +00:00
|
|
|
|
public function getRealname(): string
|
2021-02-01 16:42:52 +00:00
|
|
|
|
{
|
|
|
|
|
return $this->realname;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param mixed $realname
|
|
|
|
|
*/
|
|
|
|
|
public function setRealname($realname): void
|
|
|
|
|
{
|
|
|
|
|
$this->realname = $realname;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 01:44:36 +00:00
|
|
|
|
public function getInfo(): string
|
2021-02-01 16:42:52 +00:00
|
|
|
|
{
|
|
|
|
|
return $this->info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param mixed $info
|
|
|
|
|
*/
|
2021-08-25 01:44:36 +00:00
|
|
|
|
public function setInfo($info)
|
2021-02-01 16:42:52 +00:00
|
|
|
|
{
|
|
|
|
|
$this->info = $info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getLevel(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->level;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAlign(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->align;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 01:44:36 +00:00
|
|
|
|
public function getClan(): ?string
|
2021-02-01 16:42:52 +00:00
|
|
|
|
{
|
|
|
|
|
return $this->clan;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-08-25 01:44:36 +00:00
|
|
|
|
* @param string|null $short_name Короткое название клана. Передать null для очистки.
|
2021-02-01 16:42:52 +00:00
|
|
|
|
*/
|
2021-08-25 01:44:36 +00:00
|
|
|
|
public function setClan(?string $short_name)
|
2021-02-01 16:42:52 +00:00
|
|
|
|
{
|
2021-08-25 01:44:36 +00:00
|
|
|
|
if (is_null($short_name)) {
|
|
|
|
|
$this->clan = null;
|
|
|
|
|
self::$db->execute('update users set clan = null where id = ?', $this->id);
|
|
|
|
|
} else {
|
|
|
|
|
$this->clan = $short_name;
|
|
|
|
|
self::$db->execute('update users set clan = ? where id = ?', [$short_name, $this->id]);
|
|
|
|
|
}
|
2021-02-01 16:42:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getMoney(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->money;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 01:44:36 +00:00
|
|
|
|
public function setMoney(int $money)
|
2021-02-01 16:42:52 +00:00
|
|
|
|
{
|
2021-08-22 20:43:42 +00:00
|
|
|
|
$this->money = $money < 0 ? 0 : $money;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function saveMoney()
|
|
|
|
|
{
|
|
|
|
|
self::$db->execute('update users set money = ? where id = ?', [$this->money, $this->id]);
|
2021-02-01 16:42:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAdmin(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->admin;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 01:44:36 +00:00
|
|
|
|
public function getRoom(): int
|
2021-02-01 16:42:52 +00:00
|
|
|
|
{
|
|
|
|
|
return $this->room;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param mixed $room
|
|
|
|
|
*/
|
2021-08-25 01:44:36 +00:00
|
|
|
|
public function setRoom($room)
|
2021-02-01 16:42:52 +00:00
|
|
|
|
{
|
|
|
|
|
$this->room = $room;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 01:44:36 +00:00
|
|
|
|
public function getBlock(): int
|
2021-02-01 16:42:52 +00:00
|
|
|
|
{
|
|
|
|
|
return $this->block;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 01:44:36 +00:00
|
|
|
|
public function getShadow(): string
|
2021-02-01 16:42:52 +00:00
|
|
|
|
{
|
|
|
|
|
return $this->shadow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param mixed $shadow
|
|
|
|
|
*/
|
|
|
|
|
public function setShadow($shadow): void
|
|
|
|
|
{
|
2021-03-10 21:38:14 +00:00
|
|
|
|
$shadows = [
|
|
|
|
|
'm01', 'm02', 'm03', 'm04', 'm05', 'm06', 'm07', 'm08', 'm09', 'm10',
|
|
|
|
|
'f01', 'f02', 'f03', 'f04', 'f05', 'f06', 'f07', 'f08', 'f09', 'f10',
|
|
|
|
|
];
|
|
|
|
|
if (in_array($shadow, $shadows) && $this->getShadow() == '0.png') {
|
|
|
|
|
$this->shadow = $shadow . '.png';
|
|
|
|
|
}
|
2021-02-01 16:42:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-10 21:38:14 +00:00
|
|
|
|
public function saveShadow()
|
2021-02-01 16:42:52 +00:00
|
|
|
|
{
|
2021-08-22 20:43:42 +00:00
|
|
|
|
self::$db->execute('UPDATE users SET shadow = ? WHERE id = ?', [$this->shadow, $this->id]);
|
2021-02-01 16:42:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getExperience(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->experience;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getBattle(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->battle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getInTower(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->in_tower;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getZayavka(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->zayavka;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-10 21:38:14 +00:00
|
|
|
|
public function saveAnketa()
|
2021-02-01 16:42:52 +00:00
|
|
|
|
{
|
2021-03-10 21:38:14 +00:00
|
|
|
|
self::$db->execute('UPDATE users SET realname = ?, info = ? WHERE id = ?', [$this->realname, $this->info, $this->id]);
|
2021-02-01 16:42:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-10 22:55:08 +00:00
|
|
|
|
public function setOnline()
|
|
|
|
|
{
|
|
|
|
|
self::$db->execute('update online set real_time = ? where user_id = ?', [time(), $this->getId()]);
|
|
|
|
|
}
|
2021-05-12 20:34:54 +00:00
|
|
|
|
|
|
|
|
|
public function setInjury(int $type): bool
|
|
|
|
|
{
|
2021-08-25 01:44:36 +00:00
|
|
|
|
if (!in_array($type, [11, 12, 13, 14])) {
|
2021-05-12 20:34:54 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$names1 = ['разбитый нос', 'сотрясение первой степени', 'потрепанные уши', 'прикушенный язык', 'перелом переносицы', 'растяжение ноги', 'растяжение руки', 'подбитый глаз', 'синяк под глазом', 'кровоточащее рассечение', 'отбитая «пятая точка»', 'заклинившая челюсть', 'выбитый зуб «мудрости»', 'косоглазие'];
|
|
|
|
|
$names2 = ['отбитые почки', 'вывих «вырезано цензурой»', 'сотрясение второй степени', 'оторванное ухо', 'вывих руки', 'оторванные уши', 'поврежденный позвоночник', 'поврежденный копчик', 'разрыв сухожилия', 'перелом ребра', 'перелом двух ребер', 'вывих ноги', 'сломанная челюсть'];
|
|
|
|
|
$names3 = ['пробитый череп', 'разрыв селезенки', 'смещение позвонков', 'открытый перелом руки', 'открытый перелом «вырезано цензурой»', 'излом носоглотки', 'непонятные, но множественные травмы', 'сильное внутреннее кровотечение', 'раздробленная коленная чашечка', 'перелом шеи', 'смещение позвонков', 'открытый перелом ключицы', 'перелом позвоночника', 'вывих позвоночника', 'сотрясение третьей степени'];
|
2021-08-25 01:44:36 +00:00
|
|
|
|
$param_names = ['str', 'dex', 'int', 'end', 'intel', 'wis',];
|
2021-05-12 20:34:54 +00:00
|
|
|
|
shuffle($param_names);
|
|
|
|
|
switch ($type) {
|
|
|
|
|
case 11:
|
|
|
|
|
shuffle($names1);
|
|
|
|
|
$name = UserEffects::$effectName[$type] . ': ' . $names1(0);
|
2021-08-25 01:44:36 +00:00
|
|
|
|
self::addUserEffect($this->id, $type, $name, strtotime('30min'), json_encode([$param_names(0) => -1]));
|
2021-05-12 20:34:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case 12:
|
|
|
|
|
shuffle($names2);
|
|
|
|
|
$name = UserEffects::$effectName[$type] . ': ' . $names2(0);
|
2021-08-25 01:44:36 +00:00
|
|
|
|
self::addUserEffect($this->id, $type, $name, strtotime('3hours'), json_encode([$param_names(0) => mt_rand(-3, -1), $param_names(1) => mt_rand(-3, -1)]));
|
2021-05-12 20:34:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case 13:
|
|
|
|
|
shuffle($names3);
|
|
|
|
|
$name = UserEffects::$effectName[$type] . ': ' . $names3(0);
|
2021-08-25 01:44:36 +00:00
|
|
|
|
self::addUserEffect($this->id, $type, $name, strtotime('12hours'), json_encode([$param_names(0) => mt_rand(-5, -1), $param_names(1) => mt_rand(-5, -1), $param_names(2) => mt_rand(-5, -1)]));
|
2021-05-12 20:34:54 +00:00
|
|
|
|
break;
|
|
|
|
|
default: //type 14
|
2021-08-25 01:44:36 +00:00
|
|
|
|
self::addUserEffect($this->id, $type, UserEffects::$effectName[$type], strtotime('1day'), json_encode([$param_names(0) => -10]));
|
2021-05-12 20:34:54 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-07-03 13:23:08 +00:00
|
|
|
|
}
|