Новый класс UserStats для параметров персонажа. Перенос некоторых проверок в геттеры. Удаление неиспользуемых сеттеров.
This commit is contained in:
parent
eacde76543
commit
0a07d53be7
@ -14,45 +14,23 @@ class User
|
|||||||
protected $realname;
|
protected $realname;
|
||||||
protected $borndate;
|
protected $borndate;
|
||||||
protected $info;
|
protected $info;
|
||||||
protected $level = 0;
|
protected $level;
|
||||||
protected $align = 0;
|
protected $align;
|
||||||
protected $clan;
|
protected $clan;
|
||||||
protected $money = 0;
|
protected $money;
|
||||||
protected $strength = 0;
|
protected $ip = 0;
|
||||||
protected $dexterity = 0;
|
|
||||||
protected $intuition = 0;
|
|
||||||
protected $endurance = 0;
|
|
||||||
protected $intelligence = 0;
|
|
||||||
protected $wisdom = 0;
|
|
||||||
protected $health;
|
|
||||||
protected $mana;
|
|
||||||
protected $ip;
|
|
||||||
protected $session_id;
|
|
||||||
protected $admin = 0;
|
protected $admin = 0;
|
||||||
protected $enter_game;
|
protected $enter_game;
|
||||||
protected $room;
|
protected $room;
|
||||||
protected $block;
|
protected $block;
|
||||||
protected $shadow;
|
protected $shadow;
|
||||||
// Удар кулаком всегда 1-2.
|
|
||||||
protected $minDamage = 1;
|
|
||||||
protected $maxDamage = 2;
|
|
||||||
//Броня без предметов не существует.
|
|
||||||
protected $headArmor = 0;
|
|
||||||
protected $chestArmor = 0;
|
|
||||||
protected $legArmor = 0;
|
|
||||||
protected $free_stat_points = 0;
|
|
||||||
private const STAT_MAXIMUM_AMOUNT = 40;
|
|
||||||
private const ERROR_STAT_IS_MAXIMUM = 'Ошибка: Параметр достиг своего лимита!';
|
|
||||||
private const ERROR_STAT_UNKNOWN = 'Ошибка: Неизвестный параметр!';
|
|
||||||
// Пока несуществующие, для совместимости.
|
// Пока несуществующие, для совместимости.
|
||||||
protected $married = 'Someone или нет.';
|
|
||||||
protected $experience = 200;
|
protected $experience = 200;
|
||||||
protected $battle = 0;
|
protected $battle = 0;
|
||||||
protected $in_tower = 0; // Скорее башню похороним чем запустим...
|
protected $in_tower = 0; // Скорее башню похороним чем запустим...
|
||||||
protected $zayavka = 0;
|
protected $zayavka = 0;
|
||||||
// Динамически рассчитываемые
|
|
||||||
protected $maxHealth = 5;
|
|
||||||
protected $maxMana = 5;
|
|
||||||
protected static $db;
|
protected static $db;
|
||||||
|
|
||||||
public const INFO_CHAR_LIMIT = 1500;
|
public const INFO_CHAR_LIMIT = 1500;
|
||||||
@ -66,51 +44,8 @@ class User
|
|||||||
$this->$key = $user_query[$key];
|
$this->$key = $user_query[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->maxHealth = round(($this->endurance * 3) + ($this->endurance / 2) * ($this->level - 1) + ($this->endurance / 5) * (($this->level - 1) * ($this->level - 2) / 2));
|
|
||||||
$this->maxMana = round(($this->wisdom * 3) + ($this->wisdom / 2) * ($this->level - 1) + ($this->wisdom / 5) * (($this->level - 1) * ($this->level - 2) / 2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Отдаёт информацию о базовом(!) стате.
|
|
||||||
* @param $stat_name - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'.
|
|
||||||
* @param int $isMainWindow - переключатель "главного окна". Если включить, дополнительно будет показывать ссылку на повышение стата на 1, при условии наличия свободных очков статов.
|
|
||||||
* @return string
|
|
||||||
* @throws GameException
|
|
||||||
*/
|
|
||||||
public function getStat($stat_name, $isMainWindow = 0):string
|
|
||||||
{
|
|
||||||
$allowed = ['strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'];
|
|
||||||
if (in_array($stat_name, $allowed)) {
|
|
||||||
if ($this->free_stat_points && $isMainWindow && $this->$stat_name < self::STAT_MAXIMUM_AMOUNT) {
|
|
||||||
return sprintf('%s <a href="/main.php?edit=%s&ups=%s">[+]</a>', $this->$stat_name, mt_rand(), $stat_name);
|
|
||||||
} else {
|
|
||||||
return $this->$stat_name;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new GameException(self::ERROR_STAT_UNKNOWN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Повышает один из выбранных статов на 1, но не выше self::STAT_MAXIMUM_AMOUNT при условии наличия свободных очков статов.
|
|
||||||
* @param string $stat_name - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'.
|
|
||||||
* @throws GameException
|
|
||||||
*/
|
|
||||||
public function addOnePointToStat(string $stat_name)
|
|
||||||
{
|
|
||||||
$allowed = ['strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'];
|
|
||||||
if (in_array($stat_name, $allowed)) {
|
|
||||||
if ($this->free_stat_points > 0 && $this->$stat_name <= self::STAT_MAXIMUM_AMOUNT) {
|
|
||||||
$query = "UPDATE users SET {$stat_name} = {$stat_name} + 1, free_stat_points = free_stat_points - 1 WHERE id = ?";
|
|
||||||
self::$db->execute($query,$this->id);
|
|
||||||
} else {
|
|
||||||
throw new GameException(self::ERROR_STAT_IS_MAXIMUM);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new GameException(self::ERROR_STAT_UNKNOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function showStarSign(): ?string
|
protected function showStarSign(): ?string
|
||||||
{
|
{
|
||||||
@ -156,22 +91,13 @@ class User
|
|||||||
return $sign ?? null;
|
return $sign ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHealth(): string
|
|
||||||
|
public static function setUserEffect(int $userId, int $type, string $name, int $time): bool
|
||||||
{
|
{
|
||||||
return $this->health . '/' . $this->maxHealth;
|
return self::$db->execute('INSERT INTO users_effects (owner_id, type, name, remaining_time) VALUES (?,?,?,?)', [$userId, $type, $name, $time]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMana(): string
|
public static function removeUserEffect(int $userId, int $type): bool
|
||||||
{
|
|
||||||
return $this->mana . '/' . $this->maxMana;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function setUserEffect(int $userId, int $type, string $name, int $time):bool
|
|
||||||
{
|
|
||||||
return self::$db->execute('INSERT INTO users_effects (owner_id, type, name, remaining_time) VALUES (?,?,?,?)',[$userId, $type, $name, $time]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function removeUserEffect(int $userId, int $type):bool
|
|
||||||
{
|
{
|
||||||
if (self::$db->fetch('SELECT 1 FROM users_effects WHERE owner_id = ? AND type = ?', [$userId, $type])) {
|
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]);
|
self::$db->execute('DELETE FROM users_effects WHERE owner_id = ? AND type = ?', [$userId, $type]);
|
||||||
@ -187,14 +113,6 @@ class User
|
|||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $id
|
|
||||||
*/
|
|
||||||
public function setId(int $id): void
|
|
||||||
{
|
|
||||||
$this->id = $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -227,6 +145,11 @@ class User
|
|||||||
$this->pass = $pass;
|
$this->pass = $pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function savePass()
|
||||||
|
{
|
||||||
|
self::$db->execute('UPDATE users SET pass = ? WHERE id = ?', [$this->pass, $this->id]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -355,101 +278,6 @@ class User
|
|||||||
$this->money = $money;
|
$this->money = $money;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getStrength(): int
|
|
||||||
{
|
|
||||||
return $this->strength;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $strength
|
|
||||||
*/
|
|
||||||
public function setStrength(int $strength): void
|
|
||||||
{
|
|
||||||
$this->strength = $strength;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getDexterity(): int
|
|
||||||
{
|
|
||||||
return $this->dexterity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $dexterity
|
|
||||||
*/
|
|
||||||
public function setDexterity(int $dexterity): void
|
|
||||||
{
|
|
||||||
$this->dexterity = $dexterity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getIntuition(): int
|
|
||||||
{
|
|
||||||
return $this->intuition;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $intuition
|
|
||||||
*/
|
|
||||||
public function setIntuition(int $intuition): void
|
|
||||||
{
|
|
||||||
$this->intuition = $intuition;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getEndurance(): int
|
|
||||||
{
|
|
||||||
return $this->endurance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $endurance
|
|
||||||
*/
|
|
||||||
public function setEndurance(int $endurance): void
|
|
||||||
{
|
|
||||||
$this->endurance = $endurance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getIntelligence(): int
|
|
||||||
{
|
|
||||||
return $this->intelligence;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $intelligence
|
|
||||||
*/
|
|
||||||
public function setIntelligence(int $intelligence): void
|
|
||||||
{
|
|
||||||
$this->intelligence = $intelligence;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getWisdom(): int
|
|
||||||
{
|
|
||||||
return $this->wisdom;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $wisdom
|
|
||||||
*/
|
|
||||||
public function setWisdom(int $wisdom): void
|
|
||||||
{
|
|
||||||
$this->wisdom = $wisdom;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@ -467,21 +295,6 @@ class User
|
|||||||
$this->ip = $ip;
|
$this->ip = $ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getSessionId()
|
|
||||||
{
|
|
||||||
return $this->session_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $session_id
|
|
||||||
*/
|
|
||||||
public function setSessionId($session_id): void
|
|
||||||
{
|
|
||||||
$this->session_id = $session_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
@ -491,14 +304,6 @@ class User
|
|||||||
return $this->admin;
|
return $this->admin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $admin
|
|
||||||
*/
|
|
||||||
public function setAdmin(int $admin): void
|
|
||||||
{
|
|
||||||
$this->admin = $admin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
@ -560,103 +365,18 @@ class User
|
|||||||
*/
|
*/
|
||||||
public function setShadow($shadow): void
|
public function setShadow($shadow): void
|
||||||
{
|
{
|
||||||
$this->shadow = $shadow;
|
$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';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function saveShadow()
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getMinDamage(): int
|
|
||||||
{
|
{
|
||||||
return $this->minDamage;
|
self::$db->execute('UPDATE users SET shadow = ? WHERE id = ?', [$this->getShadow(), $this->getId()]);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getMaxDamage(): int
|
|
||||||
{
|
|
||||||
return $this->maxDamage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getHeadArmor(): int
|
|
||||||
{
|
|
||||||
return $this->headArmor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $headArmor
|
|
||||||
*/
|
|
||||||
public function setHeadArmor(int $headArmor): void
|
|
||||||
{
|
|
||||||
$this->headArmor = $headArmor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getChestArmor(): int
|
|
||||||
{
|
|
||||||
return $this->chestArmor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $chestArmor
|
|
||||||
*/
|
|
||||||
public function setChestArmor(int $chestArmor): void
|
|
||||||
{
|
|
||||||
$this->chestArmor = $chestArmor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getLegArmor(): int
|
|
||||||
{
|
|
||||||
return $this->legArmor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $legArmor
|
|
||||||
*/
|
|
||||||
public function setLegArmor(int $legArmor): void
|
|
||||||
{
|
|
||||||
$this->legArmor = $legArmor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getFreeStatPoints(): int
|
|
||||||
{
|
|
||||||
return $this->free_stat_points;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $free_stat_points
|
|
||||||
*/
|
|
||||||
public function setFreeStatPoints(int $free_stat_points): void
|
|
||||||
{
|
|
||||||
$this->free_stat_points = $free_stat_points;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getMarried(): string
|
|
||||||
{
|
|
||||||
return $this->married;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $married
|
|
||||||
*/
|
|
||||||
public function setMarried(string $married): void
|
|
||||||
{
|
|
||||||
$this->married = $married;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -723,20 +443,9 @@ class User
|
|||||||
$this->zayavka = $zayavka;
|
$this->zayavka = $zayavka;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function saveAnketa()
|
||||||
* @return float|int
|
|
||||||
*/
|
|
||||||
public function getMaxHealth()
|
|
||||||
{
|
{
|
||||||
return $this->maxHealth;
|
self::$db->execute('UPDATE users SET realname = ?, info = ? WHERE id = ?', [$this->realname, $this->info, $this->id]);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return float|int
|
|
||||||
*/
|
|
||||||
public function getMaxMana()
|
|
||||||
{
|
|
||||||
return $this->maxMana;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -3,7 +3,7 @@ namespace Battles;
|
|||||||
use Battles\Models\EffectsModel;
|
use Battles\Models\EffectsModel;
|
||||||
use Exceptions\GameException;
|
use Exceptions\GameException;
|
||||||
|
|
||||||
class UserInfo extends User
|
class UserInfo extends UserStats
|
||||||
{
|
{
|
||||||
use Rooms;
|
use Rooms;
|
||||||
//Статусы того, кто смотрит на информацию.
|
//Статусы того, кто смотрит на информацию.
|
||||||
|
221
classes/Battles/UserStats.php
Normal file
221
classes/Battles/UserStats.php
Normal file
@ -0,0 +1,221 @@
|
|||||||
|
<?php
|
||||||
|
# Date: 03.02.2021 (11:05)
|
||||||
|
|
||||||
|
namespace Battles;
|
||||||
|
|
||||||
|
use Exceptions\GameException;
|
||||||
|
|
||||||
|
class UserStats extends User
|
||||||
|
{
|
||||||
|
protected $strength;
|
||||||
|
protected $dexterity;
|
||||||
|
protected $intuition;
|
||||||
|
protected $endurance;
|
||||||
|
protected $intelligence;
|
||||||
|
protected $wisdom;
|
||||||
|
protected $health;
|
||||||
|
protected $mana;
|
||||||
|
protected $free_stat_points;
|
||||||
|
private const STAT_MAXIMUM_AMOUNT = 40;
|
||||||
|
private const ERROR_STAT_IS_MAXIMUM = 'Ошибка: Параметр достиг своего лимита!';
|
||||||
|
private const ERROR_STAT_UNKNOWN = 'Ошибка: Неизвестный параметр!';
|
||||||
|
|
||||||
|
//// Неизменяемые для игрока(!) переменные.
|
||||||
|
// Удар кулаком всегда 1-2.
|
||||||
|
protected $minDamage = 1;
|
||||||
|
protected $maxDamage = 2;
|
||||||
|
// Природная броня всегда 0.
|
||||||
|
// Зачем их три, если во всех формулах она одна?
|
||||||
|
protected $headArmor = 0;
|
||||||
|
protected $chestArmor = 0;
|
||||||
|
protected $legArmor = 0;
|
||||||
|
// Динамически рассчитываемые
|
||||||
|
protected $maxHealth;
|
||||||
|
protected $maxMana;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UserStats constructor.
|
||||||
|
*
|
||||||
|
* @param $user
|
||||||
|
*/
|
||||||
|
public function __construct($user)
|
||||||
|
{
|
||||||
|
parent::__construct($user);
|
||||||
|
$this->maxHealth = round(($this->endurance * 3) + ($this->endurance / 2) * ($this->level - 1) + ($this->endurance / 5) * (($this->level - 1) * ($this->level - 2) / 2));
|
||||||
|
$this->maxMana = round(($this->wisdom * 3) + ($this->wisdom / 2) * ($this->level - 1) + ($this->wisdom / 5) * (($this->level - 1) * ($this->level - 2) / 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Отдаёт информацию о базовом(!) стате.
|
||||||
|
*
|
||||||
|
* @param $stat_name - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition',
|
||||||
|
* 'endurance', 'intelligence', 'wisdom'.
|
||||||
|
* @param int $isMainWindow - переключатель "главного окна". Если включить, дополнительно будет показывать ссылку
|
||||||
|
* на повышение стата на 1, при условии наличия свободных очков статов.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getStat($stat_name, $isMainWindow = 0): string
|
||||||
|
{
|
||||||
|
if (!in_array($stat_name, ['strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'])) {
|
||||||
|
return self::ERROR_STAT_UNKNOWN;
|
||||||
|
}
|
||||||
|
if ($this->free_stat_points && $isMainWindow && $this->$stat_name < self::STAT_MAXIMUM_AMOUNT) {
|
||||||
|
$this->$stat_name .= " <a href='/main.php?edit=" . mt_rand() . "&ups=$stat_name'>[+]</a>";
|
||||||
|
}
|
||||||
|
return $this->$stat_name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Повышает один из выбранных статов на 1, но не выше self::STAT_MAXIMUM_AMOUNT при условии наличия свободных очков
|
||||||
|
* статов.
|
||||||
|
*
|
||||||
|
* @param string $stat_name - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition',
|
||||||
|
* 'endurance', 'intelligence', 'wisdom'.
|
||||||
|
*
|
||||||
|
* @throws GameException
|
||||||
|
*/
|
||||||
|
public function addOnePointToStat(string $stat_name)
|
||||||
|
{
|
||||||
|
if (!in_array($stat_name, ['strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'])) {
|
||||||
|
throw new GameException(self::ERROR_STAT_UNKNOWN);
|
||||||
|
}
|
||||||
|
if ($this->free_stat_points <= 0 || $this->$stat_name >= self::STAT_MAXIMUM_AMOUNT) {
|
||||||
|
throw new GameException(self::ERROR_STAT_IS_MAXIMUM);
|
||||||
|
} else {
|
||||||
|
$query = "UPDATE users SET {$stat_name} = {$stat_name} + 1, free_stat_points = free_stat_points - 1 WHERE id = ?";
|
||||||
|
self::$db->execute($query, $this->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getStrength()
|
||||||
|
{
|
||||||
|
return $this->strength;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getDexterity()
|
||||||
|
{
|
||||||
|
return $this->dexterity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getIntuition()
|
||||||
|
{
|
||||||
|
return $this->intuition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getEndurance()
|
||||||
|
{
|
||||||
|
return $this->endurance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getIntelligence()
|
||||||
|
{
|
||||||
|
return $this->intelligence;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getWisdom()
|
||||||
|
{
|
||||||
|
return $this->wisdom;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getHealth()
|
||||||
|
{
|
||||||
|
return $this->health;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getMana()
|
||||||
|
{
|
||||||
|
return $this->mana;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getFreeStatPoints()
|
||||||
|
{
|
||||||
|
return $this->free_stat_points;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
public function getMaxHealth(): float
|
||||||
|
{
|
||||||
|
return $this->maxHealth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
public function getMaxMana(): float
|
||||||
|
{
|
||||||
|
return $this->maxMana;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getMinDamage(): int
|
||||||
|
{
|
||||||
|
return $this->minDamage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getMaxDamage(): int
|
||||||
|
{
|
||||||
|
return $this->maxDamage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getHeadArmor(): int
|
||||||
|
{
|
||||||
|
return $this->headArmor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getChestArmor(): int
|
||||||
|
{
|
||||||
|
return $this->chestArmor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getLegArmor(): int
|
||||||
|
{
|
||||||
|
return $this->legArmor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
19
inf.php
19
inf.php
@ -1,21 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
include_once 'config.php';
|
include_once 'config.php';
|
||||||
$login = urldecode($_SERVER['QUERY_STRING']) ?? '';
|
$userInfo = new \Battles\UserInfo(urldecode($_SERVER['QUERY_STRING']));
|
||||||
$userInfo = new \Battles\UserInfo($login);
|
$presentsModel = new \Battles\Models\PresentsModel($userInfo->getId());
|
||||||
$presentsModel = new \Battles\Models\PresentsModel($userInfo->id);
|
|
||||||
$presentsList = $presentsModel->getAllPresents();
|
$presentsList = $presentsModel->getAllPresents();
|
||||||
$userInfo->watcher_id = $_SESSION['uid'] ?? null;
|
$userInfo->watcher_id = $_SESSION['uid'] ?? null;
|
||||||
\Battles\Template::header('Информация о ' . $userInfo->login);
|
\Battles\Template::header('Информация о ' . $userInfo->getLogin());
|
||||||
if (!$userInfo->id) {
|
if (!$userInfo->getId()) {
|
||||||
echo sprintf('Ошибка: персонаж <em>%s</em> не найден...<p><a style="color: #99f;" href="javascript:window.history.go(-1);">←назад</a></p>', $login);
|
echo sprintf('Ошибка: персонаж <em>%s</em> не найден...<p><a style="color: #99f;" href="javascript:window.history.go(-1);">←назад</a></p>', urldecode($_SERVER['QUERY_STRING']));
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
try {
|
$userInfo->showUserInfo();
|
||||||
$userInfo->showUserInfo();
|
|
||||||
|
|
||||||
} catch (Exception $e_showUserInfo) {
|
|
||||||
echo "<div class='debug'>Ошибка генератора showUserInfo() в User.php: {$e_showUserInfo}</div>";
|
|
||||||
}
|
|
||||||
|
|
||||||
include_once 'views/presents-list.php';
|
include_once 'views/presents-list.php';
|
91
main.php
91
main.php
@ -6,6 +6,7 @@ use Battles\InventoryItem;
|
|||||||
use Battles\Template;
|
use Battles\Template;
|
||||||
use Battles\Travel;
|
use Battles\Travel;
|
||||||
use Battles\UserInfo;
|
use Battles\UserInfo;
|
||||||
|
use Battles\UserStats;
|
||||||
|
|
||||||
ob_start("ob_gzhandler");
|
ob_start("ob_gzhandler");
|
||||||
session_start();
|
session_start();
|
||||||
@ -35,6 +36,7 @@ $setShadow = $_POST['setshadow'] ?? null;
|
|||||||
$edit = $_GET['edit'] ?? null;
|
$edit = $_GET['edit'] ?? null;
|
||||||
// Подготавливаем отображение инфы и предметов.
|
// Подготавливаем отображение инфы и предметов.
|
||||||
$userInfo = new UserInfo($user->getId());
|
$userInfo = new UserInfo($user->getId());
|
||||||
|
$userStats = new UserStats($user->getId());
|
||||||
$getItemsBonuses = new DressedItems($_SESSION['uid']);
|
$getItemsBonuses = new DressedItems($_SESSION['uid']);
|
||||||
$data = \Battles\Database\DBPDO::INIT()->ofetchAll('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot = 0 AND on_sale = 0', $user->getId());
|
$data = \Battles\Database\DBPDO::INIT()->ofetchAll('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot = 0 AND on_sale = 0', $user->getId());
|
||||||
$iteminfo = [];
|
$iteminfo = [];
|
||||||
@ -173,7 +175,7 @@ if ($goto) {
|
|||||||
$eff = db::c()->query('SELECT 1 FROM `users_effects` WHERE `owner_id` = ?i AND (`type` = 14 OR `type` = 13)', $user->getId());
|
$eff = db::c()->query('SELECT 1 FROM `users_effects` WHERE `owner_id` = ?i AND (`type` = 14 OR `type` = 13)', $user->getId());
|
||||||
//(масса: <?= $getItemsBonuses->getItemsWeight() . '/' . $user->strength * 4
|
//(масса: <?= $getItemsBonuses->getItemsWeight() . '/' . $user->strength * 4
|
||||||
|
|
||||||
if ($d['sum_weight'] > $user->getStrength() * 4 && $goto) {
|
if ($d['sum_weight'] > $userStats->getStrength() * 4 && $goto) {
|
||||||
err('У вас переполнен рюкзак, вы не можете передвигаться...');
|
err('У вас переполнен рюкзак, вы не можете передвигаться...');
|
||||||
$imove = false;
|
$imove = false;
|
||||||
}
|
}
|
||||||
@ -199,60 +201,11 @@ if (isset($_GET['use'])) {
|
|||||||
usemagic($_GET['use'], $_POST['target']);
|
usemagic($_GET['use'], $_POST['target']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setShadow($image)
|
if ($obraz) {
|
||||||
{
|
$user->setShadow($obraz);
|
||||||
global $user;
|
$user->saveShadow();
|
||||||
$shadows = [
|
|
||||||
'm01', 'm02', 'm03', 'm04', 'm05', 'm06', 'm07', 'm08', 'm09', 'm10',
|
|
||||||
'f01', 'f02', 'f03', 'f04', 'f05', 'f06', 'f07', 'f08', 'f09', 'f10',
|
|
||||||
'person',
|
|
||||||
];
|
|
||||||
if (in_array($image, $shadows)) {
|
|
||||||
$i = $image . '.png';
|
|
||||||
db::c()->query('UPDATE `users` SET `shadow` = "?s" WHERE `id` = ?i', $i, $user->getId());
|
|
||||||
} else {
|
|
||||||
err('Ошибка!');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($obraz && ($user->getShadow() == 'g0.gif' || $user->getShadow() == 'man0.gif')) {
|
|
||||||
setShadow($obraz);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($del == 1 && $effectId > 0) {
|
|
||||||
$pl = db::c()->query('SELECT type FROM users_effects WHERE owner_id = ?i AND effect_id = ?i', $user->getId(), $effectId)->fetch_assoc();
|
|
||||||
if (isset($pl['type'])) {
|
|
||||||
echo del_efs($effectId, $pl['type']);
|
|
||||||
} else {
|
|
||||||
echo "<span class='error'>Эффект не найден!</span>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($brons && $ids) {
|
|
||||||
try {
|
|
||||||
$cur = db::c()->query('SELECT free_bron, bron1, bron2, bron3, bron4 FROM inventory WHERE owner = ?i AND id = ?i', $user->getId(), $ids)->fetch_assoc();
|
|
||||||
} catch (\Krugozor\Database\Mysql\Exception $e) {
|
|
||||||
echo "<div style='background-color: #ffaaaa;'>Ошибка: " . $e->getMessage() . "<br> В файле: " . $e->getFile() . " (" . $e->getLine() . ")</div>";
|
|
||||||
}
|
|
||||||
if ($cur['free_bron'] > 0 && $cur[$brons] > 0) {
|
|
||||||
db::c()->query('UPDATE inventory SET free_bron = free_bron - 1, ?f = ?f +1 WHERE owner_id = ?i AND item_id = ?i', $brons, $brons, $user->getId(), $ids);
|
|
||||||
echo "<span class='success'>Параметр брони увеличен!</span>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($stats && $ids) {
|
|
||||||
$cur = db::c()->query('SELECT free_stat, gsila, glovk, ginta, gintel FROM inventory WHERE owner_id = ?i AND item_id = ?i', $user->getId(), $ids);
|
|
||||||
if ($cur['free_stat'] > 0 && $cur[$stats] > 0) {
|
|
||||||
db::c()->query('UPDATE inventory SET free_stat = free_stat - 1, ?f = ?f +1 WHERE owner_id = ?i AND item_id = ?i', $stats, $stats, $user->getId(), $ids);
|
|
||||||
echo "<span class='success'>Параметр увеличен!</span>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($mfs && $ids) {
|
|
||||||
$cur = db::c()->query('SELECT free_mf, mfkrit, mfuvorot, mfakrit, mfauvorot FROM inventory WHERE owner_id = ?i AND item_id = ?i', $user->getId(), $ids);
|
|
||||||
if (isset($cur['id']) && $cur['free_mf'] > 0 && $cur[$mfs] > 0) {
|
|
||||||
db::c()->query('UPDATE inventory SET free_mf = free_mf - 1, ?f = ?f +1 WHERE owner_id = ?i AND item_id = ?i', $mfs, $mfs, $user->getId(), $ids);
|
|
||||||
echo "<span class='success'>Параметр увеличен!</span>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($setShadow) {
|
if ($setShadow) {
|
||||||
Template::header('Образ персонажа');
|
Template::header('Образ персонажа');
|
||||||
?>
|
?>
|
||||||
@ -388,39 +341,39 @@ Template::header('Игра');
|
|||||||
<!--Параметры-->
|
<!--Параметры-->
|
||||||
<div>
|
<div>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
Сила: <?= ($user->getFreeStatPoints() ? $user->getStat('strength', 1) . '(' . strval($user->getStrength() + $getItemsBonuses->getStrengthBonus()) . ')' : $user->getStrength() + $getItemsBonuses->getStrengthBonus()) ?>
|
Сила: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('strength', 1) . '(' . strval($userStats->getStrength() + $getItemsBonuses->getStrengthBonus()) . ')' : $userStats->getStrength() + $getItemsBonuses->getStrengthBonus()) ?>
|
||||||
<br>
|
<br>
|
||||||
Ловкость: <?= ($user->getFreeStatPoints() ? $user->getStat('dexterity', 1) . '(' . strval($user->getDexterity() + $getItemsBonuses->getDexterityBonus()) . ')' : $user->getDexterity() + $getItemsBonuses->getDexterityBonus()) ?>
|
Ловкость: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('dexterity', 1) . '(' . strval($userStats->getDexterity() + $getItemsBonuses->getDexterityBonus()) . ')' : $userStats->getDexterity() + $getItemsBonuses->getDexterityBonus()) ?>
|
||||||
<br>
|
<br>
|
||||||
Интуиция: <?= ($user->getFreeStatPoints() ? $user->getStat('intuition', 1) . '(' . strval($user->getIntuition() + $getItemsBonuses->getIntuitionBonus()) . ')' : $user->getIntuition() + $getItemsBonuses->getIntuitionBonus()) ?>
|
Интуиция: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('intuition', 1) . '(' . strval($userStats->getIntuition() + $getItemsBonuses->getIntuitionBonus()) . ')' : $userStats->getIntuition() + $getItemsBonuses->getIntuitionBonus()) ?>
|
||||||
<br>
|
<br>
|
||||||
Выносливость: <?= ($user->getFreeStatPoints() ? $user->getStat('endurance', 1) . '(' . strval($user->getEndurance() + $getItemsBonuses->getEnduranceBonus()) . ')' : $user->getEndurance() + $getItemsBonuses->getEnduranceBonus()) ?>
|
Выносливость: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('endurance', 1) . '(' . strval($userStats->getEndurance() + $getItemsBonuses->getEnduranceBonus()) . ')' : $userStats->getEndurance() + $getItemsBonuses->getEnduranceBonus()) ?>
|
||||||
<br>
|
<br>
|
||||||
Интеллект: <?= ($user->getFreeStatPoints() ? $user->getStat('intelligence', 1) . '(' . strval($user->getIntelligence() + $getItemsBonuses->getIntelliganceBonus()) . ')' : $user->getIntelligence() + $getItemsBonuses->getIntelliganceBonus()) ?>
|
Интеллект: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('intelligence', 1) . '(' . strval($userStats->getIntelligence() + $getItemsBonuses->getIntelliganceBonus()) . ')' : $userStats->getIntelligence() + $getItemsBonuses->getIntelliganceBonus()) ?>
|
||||||
<br>
|
<br>
|
||||||
Мудрость: <?= ($user->getFreeStatPoints() ? $user->getStat('wisdom', 1) . '(' . strval($user->getWisdom() + $getItemsBonuses->getWisdomBonus()) . ')' : $user->getWisdom() + $getItemsBonuses->getWisdomBonus()) ?>
|
Мудрость: <?= ($userStats->getFreeStatPoints() ? $userStats->getStat('wisdom', 1) . '(' . strval($userStats->getWisdom() + $getItemsBonuses->getWisdomBonus()) . ')' : $userStats->getWisdom() + $getItemsBonuses->getWisdomBonus()) ?>
|
||||||
<br>
|
<br>
|
||||||
<?php if ($user->getFreeStatPoints()): ?>
|
<?php if ($userStats->getFreeStatPoints()): ?>
|
||||||
<small style="color: darkgreen;">Возможных
|
<small style="color: darkgreen;">Возможных
|
||||||
увеличений: <?= $user->getFreeStatPoints() ?></small><br>
|
увеличений: <?= $userStats->getFreeStatPoints() ?></small><br>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<br>
|
<br>
|
||||||
Здоровье: <?= $user->getHealth() ?><br>
|
Здоровье: <?= $userStats->getHealth() ?><br>
|
||||||
Пыль: <?= $user->getMana() ?><br>
|
Пыль: <?= $userStats->getMana() ?><br>
|
||||||
Уворот: <?= $getItemsBonuses->getEvasionBonus() ?><br>
|
Уворот: <?= $getItemsBonuses->getEvasionBonus() ?><br>
|
||||||
Точность: <?= $getItemsBonuses->getAccuracyBonus() ?><br>
|
Точность: <?= $getItemsBonuses->getAccuracyBonus() ?><br>
|
||||||
Шанс крита: <?= $getItemsBonuses->getCriticalsBonus() ?><br>
|
Шанс крита: <?= $getItemsBonuses->getCriticalsBonus() ?><br>
|
||||||
Урон: <?= $user->getMinDamage() + $getItemsBonuses->getMinPhysDamage() ?>
|
Урон: <?= $userStats->getMinDamage() + $getItemsBonuses->getMinPhysDamage() ?>
|
||||||
- <?= $user->getMaxDamage() + $getItemsBonuses->getMaxPhysDamage() ?> <br>
|
- <?= $userStats->getMaxDamage() + $getItemsBonuses->getMaxPhysDamage() ?> <br>
|
||||||
<br>
|
<br>
|
||||||
Защита от огня: ?? <br>
|
Защита от огня: ?? <br>
|
||||||
Защита от воды: ?? <br>
|
Защита от воды: ?? <br>
|
||||||
Защита от вохдуха: ?? <br>
|
Защита от вохдуха: ?? <br>
|
||||||
Защита от земли: ?? <br>
|
Защита от земли: ?? <br>
|
||||||
Защита от яда: ?? <br>
|
Защита от яда: ?? <br>
|
||||||
Броня головы: <?= $user->getHeadArmor() ?> <br>
|
Броня головы: <?= $userStats->getHeadArmor() ?> <br>
|
||||||
Броня корпуса: <?= $user->getChestArmor() ?> <br>
|
Броня корпуса: <?= $userStats->getChestArmor() ?> <br>
|
||||||
Броня ног: <?= $user->getLegArmor() ?> <br>
|
Броня ног: <?= $userStats->getLegArmor() ?> <br>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
@ -445,7 +398,7 @@ Template::header('Игра');
|
|||||||
<div> <!--рюкзак-->
|
<div> <!--рюкзак-->
|
||||||
<table BORDER=0 WIDTH=100% CELLSPACING="1" CELLPADDING="2" BGCOLOR="#A5A5A5">
|
<table BORDER=0 WIDTH=100% CELLSPACING="1" CELLPADDING="2" BGCOLOR="#A5A5A5">
|
||||||
<caption>Рюкзак
|
<caption>Рюкзак
|
||||||
(масса: <?= '?? /' . $user->getStrength() * 4 ?>)
|
(масса: <?= '?? /' . $userStats->getStrength() * 4 ?>)
|
||||||
</caption>
|
</caption>
|
||||||
<?php
|
<?php
|
||||||
foreach ($iteminfo as $ii) {
|
foreach ($iteminfo as $ii) {
|
||||||
|
@ -8,7 +8,6 @@ require_once 'functions.php';
|
|||||||
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING);
|
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING);
|
||||||
$oldpsw = filter_input(INPUT_POST, 'oldpsw', FILTER_SANITIZE_SPECIAL_CHARS);
|
$oldpsw = filter_input(INPUT_POST, 'oldpsw', FILTER_SANITIZE_SPECIAL_CHARS);
|
||||||
$newpsw = filter_input(INPUT_POST, 'newpsw', FILTER_SANITIZE_SPECIAL_CHARS);
|
$newpsw = filter_input(INPUT_POST, 'newpsw', FILTER_SANITIZE_SPECIAL_CHARS);
|
||||||
$color = filter_input(INPUT_POST, 'color', FILTER_VALIDATE_INT);
|
|
||||||
$hobbie = filter_input(INPUT_POST, 'hobbie', FILTER_SANITIZE_STRING);
|
$hobbie = filter_input(INPUT_POST, 'hobbie', FILTER_SANITIZE_STRING);
|
||||||
$hobbie = str_replace("\\n", "<br />", $hobbie);
|
$hobbie = str_replace("\\n", "<br />", $hobbie);
|
||||||
$hobbie = str_replace("\\r", "", $hobbie);
|
$hobbie = str_replace("\\r", "", $hobbie);
|
||||||
@ -18,14 +17,19 @@ if ($name || $hobbie) {
|
|||||||
if (strlen($hobbie) > User::INFO_CHAR_LIMIT) {
|
if (strlen($hobbie) > User::INFO_CHAR_LIMIT) {
|
||||||
err('Максимальная длинна поля Хобби: ' . User::INFO_CHAR_LIMIT . ' символов!');
|
err('Максимальная длинна поля Хобби: ' . User::INFO_CHAR_LIMIT . ' символов!');
|
||||||
} else {
|
} else {
|
||||||
$values = ['realname' => $name, 'color' => $color, 'info' => $hobbie];
|
if ($name) {
|
||||||
db::c()->query('UPDATE users SET ?As WHERE id = ?i', $values, $user->getId());
|
$user->setRealname($name);
|
||||||
|
}
|
||||||
|
if ($hobbie) {
|
||||||
|
$user->setInfo($hobbie);
|
||||||
|
}
|
||||||
|
$user->saveAnketa();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($oldpsw && $newpsw) {
|
if ($oldpsw && $newpsw) {
|
||||||
if (password_verify($oldpsw, $user->getPass())) {
|
if (password_verify($oldpsw, $user->getPass())) {
|
||||||
db::c()->query('UPDATE `users` SET `pass` = "?s" WHERE `id` = ?i', password_hash($newpsw, PASSWORD_DEFAULT), $user->getId());
|
$user->setPass(password_hash($newpsw, PASSWORD_DEFAULT));
|
||||||
|
$user->savePass();
|
||||||
} else {
|
} else {
|
||||||
err('Неверный текущий пароль!');
|
err('Неверный текущий пароль!');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user