Куча мелочей, в том числе по #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
+61 -229
View File
@@ -6,38 +6,49 @@ use Battles\Database\DBPDO;
class User
{
protected $id = 0;
protected $login = '<em>Некто</em>';
protected $pass;
protected $email = '<em>неизвестно</em>';
protected $realname;
protected $borndate;
protected $info;
protected $level;
protected $align;
protected $clan;
protected $money;
protected $ip = 0;
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 $admin = 0;
protected $enter_game;
protected $room;
protected $block;
protected $shadow;
protected ?int $admin = null;
protected int $room = 0;
protected int $block = 0;
protected string $shadow = '';
// Пока несуществующие, для совместимости.
protected $experience = 200;
protected $battle = 0;
protected $in_tower = 0; // Скорее башню похороним чем запустим...
protected $zayavka = 0;
protected static $db;
protected int $experience = 0;
protected int $battle = 0;
protected int $in_tower = 0; // Скорее башню похороним чем запустим...
protected int $zayavka = 0;
protected static DBPDO $db;
public const INFO_CHAR_LIMIT = 1500;
/**
* @var User Переменная инициализируемая при запуске, хранящая объект текущего пользователя.
*/
public static User $current;
/**
* @param int|string $user
*/
public function __construct($user)
{
self::$db = DBPDO::INIT();
$user_query = self::$db->fetch('SELECT * FROM users WHERE id = ? OR login = ?', [$user, $user]);
$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);
foreach ($this as $key => $value) {
if (isset($user_query[$key])) {
$this->$key = $user_query[$key];
@@ -51,12 +62,11 @@ class User
* @param string $name
* @param int $time
* @param string|null $json_modifiers_list (str, dex, int, end, intel, wis).
* @return bool
*/
public static function setUserEffect(int $userId, int $type, string $name, int $time, string $json_modifiers_list = null): bool
public static function addUserEffect(int $userId, int $type, string $name, int $time, string $json_modifiers_list = null)
{
$mods = json_decode($json_modifiers_list);
return 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]);
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]);
}
public static function removeUserEffect(int $userId, int $type): bool
@@ -67,34 +77,17 @@ class User
return false;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @return string
*/
public function getLogin(): string
{
return $this->login;
}
/**
* @param string $login
*/
public function setLogin(string $login): void
{
$this->login = $login;
}
/**
* @return mixed
*/
public function getPass()
public function getPass(): string
{
return $this->pass;
}
@@ -112,26 +105,7 @@ class User
self::$db->execute('UPDATE users SET pass = ? WHERE id = ?', [$this->pass, $this->id]);
}
/**
* @return string
*/
public function getEmail(): string
{
return $this->email;
}
/**
* @param string $email
*/
public function setEmail(string $email): void
{
$this->email = $email;
}
/**
* @return mixed
*/
public function getRealname()
public function getRealname(): string
{
return $this->realname;
}
@@ -144,26 +118,7 @@ class User
$this->realname = $realname;
}
/**
* @return mixed
*/
public function getBorndate()
{
return $this->borndate;
}
/**
* @param mixed $borndate
*/
public function setBorndate($borndate): void
{
$this->borndate = $borndate;
}
/**
* @return mixed
*/
public function getInfo()
public function getInfo(): string
{
return $this->info;
}
@@ -171,71 +126,46 @@ class User
/**
* @param mixed $info
*/
public function setInfo($info): void
public function setInfo($info)
{
$this->info = $info;
}
/**
* @return int
*/
public function getLevel(): int
{
return $this->level;
}
/**
* @param int $level
*/
public function setLevel(int $level): void
{
$this->level = $level;
}
/**
* @return int
*/
public function getAlign(): int
{
return $this->align;
}
/**
* @param int $align
*/
public function setAlign(int $align): void
{
$this->align = $align;
}
/**
* @return string
*/
public function getClan(): string
public function getClan(): ?string
{
return $this->clan;
}
/**
* @param int $clan
* @param string|null $short_name Короткое название клана. Передать null для очистки.
*/
public function setClan(string $clan): void
public function setClan(?string $short_name)
{
$this->clan = $clan;
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]);
}
}
/**
* @return int
*/
public function getMoney(): int
{
return $this->money;
}
/**
* @param int $money
*/
public function setMoney(int $money): void
public function setMoney(int $money)
{
$this->money = $money < 0 ? 0 : $money;
}
@@ -245,52 +175,12 @@ class User
self::$db->execute('update users set money = ? where id = ?', [$this->money, $this->id]);
}
/**
* @return mixed
*/
public function getIp()
{
return $this->ip;
}
/**
* @param mixed $ip
*/
public function setIp($ip): void
{
$this->ip = $ip;
}
/**
* @return int
*/
public function getAdmin(): int
{
return $this->admin;
}
/**
* @return mixed
*/
public function getEnterGame()
{
return $this->enter_game;
}
/**
* @param mixed $enter_game
*/
public function setEnterGame($enter_game): void
{
$this->enter_game = $enter_game;
}
/**
* @return mixed
*/
public function getRoom()
public function getRoom(): int
{
return $this->room;
}
@@ -298,31 +188,17 @@ class User
/**
* @param mixed $room
*/
public function setRoom($room): void
public function setRoom($room)
{
$this->room = $room;
}
/**
* @return mixed
*/
public function getBlock()
public function getBlock(): int
{
return $this->block;
}
/**
* @param mixed $block
*/
public function setBlock($block): void
{
$this->block = $block;
}
/**
* @return mixed
*/
public function getShadow()
public function getShadow(): string
{
return $this->shadow;
}
@@ -346,70 +222,26 @@ class User
self::$db->execute('UPDATE users SET shadow = ? WHERE id = ?', [$this->shadow, $this->id]);
}
/**
* @return int
*/
public function getExperience(): int
{
return $this->experience;
}
/**
* @param int $experience
*/
public function setExperience(int $experience): void
{
$this->experience = $experience;
}
/**
* @return int
*/
public function getBattle(): int
{
return $this->battle;
}
/**
* @param int $battle
*/
public function setBattle(int $battle): void
{
$this->battle = $battle;
}
/**
* @return int
*/
public function getInTower(): int
{
return $this->in_tower;
}
/**
* @param int $in_tower
*/
public function setInTower(int $in_tower): void
{
$this->in_tower = $in_tower;
}
/**
* @return int
*/
public function getZayavka(): int
{
return $this->zayavka;
}
/**
* @param int $zayavka
*/
public function setZayavka(int $zayavka): void
{
$this->zayavka = $zayavka;
}
public function saveAnketa()
{
self::$db->execute('UPDATE users SET realname = ?, info = ? WHERE id = ?', [$this->realname, $this->info, $this->id]);
@@ -422,32 +254,32 @@ class User
public function setInjury(int $type): bool
{
if (!in_array($type,[11,12,13,14])) {
if (!in_array($type, [11, 12, 13, 14])) {
return false;
}
$names1 = ['разбитый нос', 'сотрясение первой степени', 'потрепанные уши', 'прикушенный язык', 'перелом переносицы', 'растяжение ноги', 'растяжение руки', 'подбитый глаз', 'синяк под глазом', 'кровоточащее рассечение', 'отбитая «пятая точка»', 'заклинившая челюсть', 'выбитый зуб «мудрости»', 'косоглазие'];
$names2 = ['отбитые почки', 'вывих «вырезано цензурой»', 'сотрясение второй степени', 'оторванное ухо', 'вывих руки', 'оторванные уши', 'поврежденный позвоночник', 'поврежденный копчик', 'разрыв сухожилия', 'перелом ребра', 'перелом двух ребер', 'вывих ноги', 'сломанная челюсть'];
$names3 = ['пробитый череп', 'разрыв селезенки', 'смещение позвонков', 'открытый перелом руки', 'открытый перелом «вырезано цензурой»', 'излом носоглотки', 'непонятные, но множественные травмы', 'сильное внутреннее кровотечение', 'раздробленная коленная чашечка', 'перелом шеи', 'смещение позвонков', 'открытый перелом ключицы', 'перелом позвоночника', 'вывих позвоночника', 'сотрясение третьей степени'];
$param_names = ['str','dex','int','end','intel','wis',];
$param_names = ['str', 'dex', 'int', 'end', 'intel', 'wis',];
shuffle($param_names);
switch ($type) {
case 11:
shuffle($names1);
$name = UserEffects::$effectName[$type] . ': ' . $names1(0);
self::setUserEffect($this->id, $type, $name, strtotime('30min'), json_encode([$param_names(0) => -1]));
self::addUserEffect($this->id, $type, $name, strtotime('30min'), json_encode([$param_names(0) => -1]));
break;
case 12:
shuffle($names2);
$name = UserEffects::$effectName[$type] . ': ' . $names2(0);
self::setUserEffect($this->id, $type, $name, strtotime('3hours'), json_encode([$param_names(0) => mt_rand(-3,-1), $param_names(1) => mt_rand(-3,-1)]));
self::addUserEffect($this->id, $type, $name, strtotime('3hours'), json_encode([$param_names(0) => mt_rand(-3, -1), $param_names(1) => mt_rand(-3, -1)]));
break;
case 13:
shuffle($names3);
$name = UserEffects::$effectName[$type] . ': ' . $names3(0);
self::setUserEffect($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)]));
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)]));
break;
default: //type 14
self::setUserEffect($this->id, $type, UserEffects::$effectName[$type], strtotime('1day'), json_encode([$param_names(0) => -10]));
self::addUserEffect($this->id, $type, UserEffects::$effectName[$type], strtotime('1day'), json_encode([$param_names(0) => -10]));
break;
}