Merge remote-tracking branch 'origin/master' into dev-shop
This commit is contained in:
@@ -52,7 +52,7 @@ class Bank
|
||||
*/
|
||||
private function bankCommission(int $amount): int
|
||||
{
|
||||
$bankCommission = round($amount * Config::$bank_commission);
|
||||
$bankCommission = round($amount * GameConfigs::BANK_COMISSION);
|
||||
if ($bankCommission < 1) {
|
||||
return 1;
|
||||
} else {
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
|
||||
|
||||
namespace Battles\Database;
|
||||
const DATABASE_HOST = '192.168.20.5';
|
||||
const DATABASE_NAME = 'battles';
|
||||
const DATABASE_USER = 'battles';
|
||||
const DATABASE_PASS = 'bottle-neck-horse';
|
||||
const DATABASE_PORT = '32101';
|
||||
use Battles\GameConfigs;
|
||||
use PDO, PDOException;
|
||||
class DBPDO
|
||||
{
|
||||
@@ -37,9 +33,9 @@ class DBPDO
|
||||
{
|
||||
if (!$this->pdo) {
|
||||
|
||||
$dsn = 'mysql:dbname=' . DATABASE_NAME . ';host=' . DATABASE_HOST . ';port=' . DATABASE_PORT . ';charset=utf8;';
|
||||
$user = DATABASE_USER;
|
||||
$password = DATABASE_PASS;
|
||||
$dsn = 'mysql:dbname=' . GameConfigs::DATABASE_NAME . ';host=' . GameConfigs::DATABASE_HOST . ';port=' . GameConfigs::DATABASE_PORT . ';charset=utf8;';
|
||||
$user = GameConfigs::DATABASE_USER;
|
||||
$password = GameConfigs::DATABASE_PASS;
|
||||
|
||||
try {
|
||||
$this->pdo = new PDO($dsn, $user, $password, array(PDO::ATTR_PERSISTENT => true));
|
||||
@@ -144,5 +140,4 @@ class DBPDO
|
||||
{
|
||||
return $this->pdo->lastInsertId();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
namespace Battles;
|
||||
|
||||
use Battles\Database\DBPDO;
|
||||
use stdClass;
|
||||
|
||||
class DressedItems
|
||||
{
|
||||
@@ -27,94 +28,20 @@ class DressedItems
|
||||
|
||||
public static function getDressedItemBySlot($itemSlot, $ownerId)
|
||||
{
|
||||
return self::$db->fetch('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot = ?', [$ownerId, $itemSlot]);
|
||||
return self::$db->fetch('SELECT *, COUNT(1) AS count FROM inventory WHERE owner_id = ? AND dressed_slot = ?', [$ownerId, $itemSlot]);
|
||||
}
|
||||
|
||||
public function getItemsInSlots()
|
||||
public function getItemsInSlots(): stdClass
|
||||
{
|
||||
$items = self::$db->ofetchALL('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot > 0', $this->USERID);
|
||||
$i = 0;
|
||||
while ($i < count($items)) {
|
||||
$this->dressedItem[$items[$i]->dressed_slot] = $items;
|
||||
$i++;
|
||||
$this->dressedItem = new stdClass();
|
||||
foreach ($items as $item) {
|
||||
$i = $item->dressed_slot;
|
||||
$this->dressedItem->$i = $item;
|
||||
}
|
||||
return $this->dressedItem;
|
||||
}
|
||||
|
||||
private function getBonuses(): array
|
||||
{
|
||||
$query = <<<SQL
|
||||
SELECT SUM(add_strength) as sum_strength,
|
||||
SUM(add_dexterity) as sum_dexterity,
|
||||
SUM(add_intuition) as sum_intuition,
|
||||
SUM(add_endurance) as sum_endurance,
|
||||
SUM(add_intelligence) as sum_intelligence,
|
||||
SUM(add_wisdom) as sum_wisdom,
|
||||
SUM(add_accuracy) as sum_accuracy,
|
||||
SUM(add_evasion) as sum_evasion,
|
||||
SUM(add_criticals) as sum_criticals,
|
||||
SUM(add_min_physical_damage) as sum_min_phys_damage,
|
||||
SUM(add_max_physical_damage) as sum_max_phys_damage
|
||||
FROM inventory WHERE owner_id = ? AND dressed_slot > 0
|
||||
SQL;
|
||||
return self::$db->fetch($query, $this->USERID);
|
||||
}
|
||||
|
||||
public function getStrengthBonus(): ?int
|
||||
{
|
||||
return self::getBonuses()['sum_strength'];
|
||||
}
|
||||
|
||||
public function getDexterityBonus(): ?int
|
||||
{
|
||||
return self::getBonuses()['sum_dexterity'];
|
||||
}
|
||||
|
||||
public function getIntuitionBonus(): ?int
|
||||
{
|
||||
return self::getBonuses()['sum_intuition'];
|
||||
}
|
||||
|
||||
public function getEnduranceBonus(): ?int
|
||||
{
|
||||
return self::getBonuses()['sum_endurance'];
|
||||
}
|
||||
|
||||
public function getIntelliganceBonus(): ?int
|
||||
{
|
||||
return self::getBonuses()['sum_intelligence'];
|
||||
}
|
||||
|
||||
public function getWisdomBonus(): ?int
|
||||
{
|
||||
return self::getBonuses()['sum_wisdom'];
|
||||
}
|
||||
|
||||
public function getAccuracyBonus(): ?int
|
||||
{
|
||||
return self::getBonuses()['sum_accuracy'] ?? 0;
|
||||
}
|
||||
|
||||
public function getEvasionBonus(): ?int
|
||||
{
|
||||
return self::getBonuses()['sum_evasion'] ?? 0;
|
||||
}
|
||||
|
||||
public function getCriticalsBonus(): ?int
|
||||
{
|
||||
return self::getBonuses()['sum_criticals'] ?? 0;
|
||||
}
|
||||
|
||||
public function getMinPhysDamage(): ?int
|
||||
{
|
||||
return self::getBonuses()['sum_min_phys_damage'];
|
||||
}
|
||||
|
||||
public function getMaxPhysDamage(): ?int
|
||||
{
|
||||
return self::getBonuses()['sum_max_phys_damage'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Снимает с предмета статус одетого на персонажа в определённом слоте персонажа.
|
||||
* @param $slot_id - номер слота.
|
||||
@@ -123,8 +50,12 @@ SQL;
|
||||
{
|
||||
self::getItemsInSlots();
|
||||
// Проверяем, что используется один из 12 слотов и наличие предмета в слоте.
|
||||
if (in_array($slot_id, Item::ITEM_TYPES_ALLOWED_IN_SLOTS) && $this->dressedItem[$slot_id]) {
|
||||
if (in_array($slot_id, Item::ITEM_TYPES_ALLOWED_IN_SLOTS) && $this->dressedItem->$slot_id) {
|
||||
self::$db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ? AND owner_id = ?', [$slot_id, $this->USERID]);
|
||||
}
|
||||
}
|
||||
public static function undressAllItems($user_id)
|
||||
{
|
||||
return self::$db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot BETWEEN 1 AND 12 AND owner_id = ?', $user_id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
# Date: 15.02.2021 (02:33)
|
||||
|
||||
namespace Battles;
|
||||
|
||||
|
||||
class GameConfigs
|
||||
{
|
||||
const DATABASE_HOST = '192.168.20.5';
|
||||
const DATABASE_NAME = 'battles';
|
||||
const DATABASE_USER = 'battles';
|
||||
const DATABASE_PASS = 'bottle-neck-horse';
|
||||
const DATABASE_PORT = '32101';
|
||||
const DATABASE_CHARSET = 'utf8';
|
||||
|
||||
const CLAN_REGISTER_COST = 10000;
|
||||
const CLAN_REGISTER_LOCK = true; // Запрет на регистрацию кланов.
|
||||
const BANK_COMISSION = 0.05; // 5%
|
||||
|
||||
const DB_SQLITE = '/volume2/web/battles/databases/logs.sqlite';
|
||||
}
|
||||
@@ -19,7 +19,7 @@ class GameLogs
|
||||
*/
|
||||
public static function addBankLog(int $senderId, int $receiverId, int $amount, string $type, string $text)
|
||||
{
|
||||
$db = new SQLite3(Config::$db_sqlite);
|
||||
$db = new SQLite3(GameConfigs::DB_SQLITE);
|
||||
$row = $db->prepare("INSERT INTO bank_logs (sender_id, receiver_id, amount, type, text) VALUES (?, ?, ?, ?, ?)");
|
||||
$row->bindParam(1, $senderId, SQLITE3_INTEGER);
|
||||
$row->bindParam(2, $receiverId, SQLITE3_INTEGER);
|
||||
@@ -45,7 +45,7 @@ class GameLogs
|
||||
if (empty($type)) {
|
||||
$type = "system";
|
||||
}
|
||||
$db = new SQLite3(Config::$db_sqlite);
|
||||
$db = new SQLite3(GameConfigs::DB_SQLITE);
|
||||
$row = $db->prepare("INSERT INTO users_logs (user_id, author_id, type, text) VALUES (?,?,?,?)");
|
||||
$row->bindParam(1, $userId, SQLITE3_INTEGER);
|
||||
$row->bindParam(2, $authorId, SQLITE3_INTEGER);
|
||||
@@ -57,7 +57,7 @@ class GameLogs
|
||||
|
||||
public static function getUserLogs($userId = null, $type = null): SQLite3Result
|
||||
{
|
||||
$db = new SQLite3(Config::$db_sqlite);
|
||||
$db = new SQLite3(GameConfigs::DB_SQLITE);
|
||||
|
||||
if ($userId && $type) {
|
||||
$query = "SELECT * FROM users_logs WHERE user_id = ? AND type = ?";
|
||||
|
||||
@@ -1,15 +1,27 @@
|
||||
<?php
|
||||
namespace Battles;
|
||||
|
||||
use Battles\Database\DBPDO;
|
||||
|
||||
class InventoryItem extends Item
|
||||
{
|
||||
private $present;
|
||||
private $owner_id;
|
||||
private $db;
|
||||
private const TOO_MANY_ITEMS_IN_SLOTS = 'Критическая ошибка: Переполнение слота!';
|
||||
private const UNKNOWN_ITEM_TYPE = 'Неизвестный тип предмета!';
|
||||
private const REQUIREMENTS_NOT_MET = 'Персонаж не соответствует требованиям!';
|
||||
|
||||
/**
|
||||
* InventoryItem constructor.
|
||||
*
|
||||
* @param $row
|
||||
*/
|
||||
public function __construct($row)
|
||||
{
|
||||
parent::__construct($row);
|
||||
if (isset($row['present'])) {
|
||||
$this->present = $row['present'];
|
||||
}
|
||||
$this->owner_id = $row->owner_id;
|
||||
$this->db = DBPDO::INIT();
|
||||
}
|
||||
|
||||
public function printInfo()
|
||||
@@ -22,14 +34,110 @@ class InventoryItem extends Item
|
||||
|
||||
public function printImage()
|
||||
{
|
||||
if (in_array($this->item_type, range(1,12))) {
|
||||
echo "<a href=/main.php?edit=1&dress={$this->item_id} title='Надеть'>";
|
||||
parent::printImage();
|
||||
echo "</a>";
|
||||
if (in_array($this->item_type, range(1, 12))) {
|
||||
echo <<<HTML
|
||||
<a href=/main.php?edit=1&dress={$this->item_id} title='Надеть'>
|
||||
<img src="/i/sh/{$this->image}" class="item-wrap-normal" alt="">
|
||||
</a>
|
||||
HTML;
|
||||
} else {
|
||||
parent::printImage();
|
||||
echo <<<IMG
|
||||
<img src="/i/sh/{$this->image}" class="item-wrap-normal" alt="">
|
||||
IMG;
|
||||
}
|
||||
}
|
||||
|
||||
public function printControls() {}
|
||||
public function printControls()
|
||||
{
|
||||
/* Тут будут кнопки под картинкой. */
|
||||
}
|
||||
|
||||
private function dressStatsChecks(): ?string
|
||||
{
|
||||
$checkStats = new UserStats($this->owner_id);
|
||||
return
|
||||
$this->need_strength > $checkStats->getFullStats()->strength
|
||||
|| $this->need_dexterity > $checkStats->getFullStats()->dexterity
|
||||
|| $this->need_intuition > $checkStats->getFullStats()->intuition
|
||||
|| $this->need_endurance > $checkStats->getFullStats()->endurance
|
||||
|| $this->need_intelligence > $checkStats->getFullStats()->intelligence
|
||||
|| $this->need_wisdom > $checkStats->getFullStats()->wisdom
|
||||
? true : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Одевание предмета из инвентаря в слот.
|
||||
* @return bool|string
|
||||
*/
|
||||
public function dressItem()
|
||||
{
|
||||
$db = new DBPDO();
|
||||
$itemInSlot = [];
|
||||
if ($this->dressStatsChecks()) {
|
||||
return self::REQUIREMENTS_NOT_MET;
|
||||
}
|
||||
// считаем сколько ОДЕТЫХ предметов в слоте в который мы хотим одеть предмет. 1=просто вещь 1-3=шашни с кольцами
|
||||
// Count добавленный в первый запрос возвращает одну строку в любом случае.
|
||||
// fetch возвращает одну строку в любом случае.
|
||||
$weared = $db->ofetchAll('SELECT dressed_slot FROM inventory WHERE dressed_slot != 0 AND item_type = ? AND owner_id = ?', [$this->item_type, $this->owner_id]);
|
||||
$wearedCount = $db->ofetch('select count(dressed_slot) as c from inventory where dressed_slot !=0 and item_type = ? and owner_id = ?', [$this->item_type, $this->owner_id]);
|
||||
// Если в слоте есть предмет(ы), забиваем их массив одетых в слот предметов.
|
||||
if ($wearedCount) {
|
||||
foreach ($weared as $item) {
|
||||
$itemInSlot[] = $item->dressed_slot;
|
||||
}
|
||||
}
|
||||
if (in_array($this->item_type, [
|
||||
self::ITEM_TYPE_HELMET, self::ITEM_TYPE_ARMOR, self::ITEM_TYPE_LEGS, self::ITEM_TYPE_BOOTS,
|
||||
self::ITEM_TYPE_GLOVES, self::ITEM_TYPE_WEAPON, self::ITEM_TYPE_SHIELD, self::ITEM_TYPE_BELT,
|
||||
self::ITEM_TYPE_AMULET,
|
||||
])) {
|
||||
//работаем с нормальными слотами
|
||||
if ($wearedCount->c == 1) {
|
||||
//если слот занят, снимаем старый предмет и одеваем новый предмет
|
||||
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ? AND owner_id = ?', [$itemInSlot[0], $this->owner_id]);
|
||||
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = item_type WHERE item_id = ? AND owner_id = ?', [$this->item_id, $this->owner_id]);
|
||||
} elseif (!$wearedCount->c) {
|
||||
//если слот пуст, одеваем новый предмет
|
||||
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = item_type WHERE item_id = ? AND owner_id = ?', [$this->item_id, $this->owner_id]);
|
||||
} else {
|
||||
/* проверка на переполнение слотов */
|
||||
$error = self::TOO_MANY_ITEMS_IN_SLOTS;
|
||||
DressedItems::undressAllItems($this->owner_id);
|
||||
}
|
||||
} elseif ($this->item_type == self::ITEM_TYPE_RING) {
|
||||
// работаем с кольцами
|
||||
if ($wearedCount->c < 3) {
|
||||
// Сравниваем массив колец и массив слотов для колец.
|
||||
$emptyRingSlots = array_diff([9, 10, 11], $itemInSlot);
|
||||
// Сортируем массив свободных слотов по возрастанию.
|
||||
sort($emptyRingSlots);
|
||||
// Одеваем предмет в первый свободный слот.
|
||||
DBPDO::INIT()->execute('update inventory set dressed_slot = ? where item_id = ?', [$emptyRingSlots[0], $this->item_id]);
|
||||
} elseif ($wearedCount->c == 3) {
|
||||
// Cнимаем предмет из последнего слота 11 и одеваем новый предмет
|
||||
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = 11');
|
||||
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = 11 WHERE item_id = ?', $this->item_id);
|
||||
} else {
|
||||
/* проверка на переполнение слотов */
|
||||
$error = self::TOO_MANY_ITEMS_IN_SLOTS;
|
||||
DressedItems::undressAllItems($this->owner_id);
|
||||
}
|
||||
} else {
|
||||
$error = self::UNKNOWN_ITEM_TYPE;
|
||||
}
|
||||
|
||||
return isset($error) ? $error : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $itemId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function destroyItem($itemId): bool
|
||||
{
|
||||
$db = new DBPDO();
|
||||
return $db->execute('delete from inventory where dressed_slot = 0 and owner_id = ? and item_id = ?', [$_SESSION['uid'], $itemId]);
|
||||
}
|
||||
}
|
||||
+12
-11
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
namespace Battles;
|
||||
abstract class Item
|
||||
class Item
|
||||
{
|
||||
protected $item_id;
|
||||
protected $name;
|
||||
@@ -49,9 +49,17 @@ abstract class Item
|
||||
*/
|
||||
public function __construct($row)
|
||||
{
|
||||
foreach ($this as $key => $value) {
|
||||
if (isset($row[$key])) {
|
||||
$this->$key = $row[$key];
|
||||
if (is_array($row)) {
|
||||
foreach ($this as $key => $value) {
|
||||
if (isset($row[$key])) {
|
||||
$this->$key = $row[$key];
|
||||
}
|
||||
}
|
||||
} elseif (is_object($row)) {
|
||||
foreach ($this as $name => $value) {
|
||||
if (isset($row->$name)) {
|
||||
$this->$name = $row->$name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,14 +102,7 @@ abstract class Item
|
||||
}
|
||||
}
|
||||
|
||||
abstract public function printInfo();
|
||||
|
||||
public function printImage()
|
||||
{
|
||||
echo <<<IMG
|
||||
<img src="/i/sh/{$this->image}" class="item-wrap-normal" alt="">
|
||||
IMG;
|
||||
}
|
||||
|
||||
protected function wrap(int $number):string
|
||||
{
|
||||
|
||||
@@ -52,7 +52,7 @@ class CureInjury extends Magic
|
||||
} else {
|
||||
$this->target = new User($this->target);
|
||||
}
|
||||
$this->login = $this->target->login;
|
||||
$this->login = $this->target->getLogin();
|
||||
return ($this->isVisible($caster, $this->target) && $this->isNotDead($caster) && $this->enoughMana($caster) && $this->isNotInBattle($caster));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
# Date: 26.10.2020 (16:08)
|
||||
namespace Battles;
|
||||
|
||||
use Battles\Database\DBPDO;
|
||||
|
||||
class Travel
|
||||
@@ -57,17 +58,16 @@ class Travel
|
||||
|
||||
/**
|
||||
* Перемещение по комнатам.
|
||||
* @param int $roomId ID куда идём.
|
||||
* @param int $roomIdCurrent ID откуда идём.
|
||||
* @param DBPDO|null $db
|
||||
* @param int $roomId ID куда идём.
|
||||
* @param int $roomIdCurrent ID откуда идём.
|
||||
*/
|
||||
public static function toRoom(int $roomId, int $roomIdCurrent): void
|
||||
{
|
||||
$db = DBPDO::INIT();
|
||||
$itemsWeight = $db->fetch('SELECT SUM(weight) AS all_weight FROM inventory WHERE owner_id = ? AND on_sale = 0', $_SESSION['uid']);
|
||||
$itemsWeight = $db->fetch('SELECT SUM(weight) - (select strength * 5 from users where id = ?) AS weight_overflow FROM inventory WHERE owner_id = ? AND on_sale = 0', [$_SESSION['uid'], $_SESSION['uid']]);
|
||||
$eff = $db->fetch('SELECT type FROM users_effects WHERE owner_id = ? AND (`type` = 10 OR `type` = 13 OR `type` = 14)', $_SESSION['uid']);
|
||||
$errors = [];
|
||||
if ($itemsWeight['all_weight'] > get_meshok()) {
|
||||
if ($itemsWeight['weight_overflow'] > 0) {
|
||||
$errors[0] = 'У вас переполнен рюкзак, вы не можете передвигаться...';
|
||||
}
|
||||
if ($eff['type'] == 10) {
|
||||
|
||||
+73
-316
@@ -3,7 +3,6 @@
|
||||
namespace Battles;
|
||||
|
||||
use Battles\Database\DBPDO;
|
||||
use Exceptions\GameException;
|
||||
|
||||
class User
|
||||
{
|
||||
@@ -14,48 +13,28 @@ class User
|
||||
protected $realname;
|
||||
protected $borndate;
|
||||
protected $info;
|
||||
protected $level = 0;
|
||||
protected $align = 0;
|
||||
protected $level;
|
||||
protected $align;
|
||||
protected $clan;
|
||||
protected $money = 0;
|
||||
protected $strength = 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 $money;
|
||||
protected $ip = 0;
|
||||
|
||||
protected $admin = 0;
|
||||
protected $enter_game;
|
||||
protected $room;
|
||||
protected $block;
|
||||
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 $battle = 0;
|
||||
protected $in_tower = 0; // Скорее башню похороним чем запустим...
|
||||
protected $zayavka = 0;
|
||||
// Динамически рассчитываемые
|
||||
protected $maxHealth = 5;
|
||||
protected $maxMana = 5;
|
||||
protected static $db;
|
||||
|
||||
public function __construct(int $user)
|
||||
public const INFO_CHAR_LIMIT = 1500;
|
||||
|
||||
public function __construct($user)
|
||||
{
|
||||
self::$db = DBPDO::INIT();
|
||||
$user_query = self::$db->fetch('SELECT * FROM users WHERE id = ? OR login = ?', [$user, $user]);
|
||||
@@ -64,51 +43,8 @@ class User
|
||||
$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
|
||||
{
|
||||
@@ -154,22 +90,22 @@ class User
|
||||
return $sign ?? null;
|
||||
}
|
||||
|
||||
public function getHealth(): string
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @param int $type
|
||||
* @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
|
||||
{
|
||||
return $this->health . '/' . $this->maxHealth;
|
||||
$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]);
|
||||
}
|
||||
|
||||
public function getMana(): string
|
||||
{
|
||||
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
|
||||
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])) {
|
||||
self::$db->execute('DELETE FROM users_effects WHERE owner_id = ? AND type = ?', [$userId, $type]);
|
||||
@@ -185,14 +121,6 @@ class User
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*/
|
||||
public function setId(int $id): void
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -225,6 +153,11 @@ class User
|
||||
$this->pass = $pass;
|
||||
}
|
||||
|
||||
public function savePass()
|
||||
{
|
||||
self::$db->execute('UPDATE users SET pass = ? WHERE id = ?', [$this->pass, $this->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -353,101 +286,6 @@ class User
|
||||
$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
|
||||
@@ -465,21 +303,6 @@ class User
|
||||
$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
|
||||
@@ -489,14 +312,6 @@ class User
|
||||
return $this->admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $admin
|
||||
*/
|
||||
public function setAdmin(int $admin): void
|
||||
{
|
||||
$this->admin = $admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -558,103 +373,18 @@ class User
|
||||
*/
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMinDamage(): int
|
||||
public function saveShadow()
|
||||
{
|
||||
return $this->minDamage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
self::$db->execute('UPDATE users SET shadow = ? WHERE id = ?', [$this->getShadow(), $this->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -721,20 +451,47 @@ class User
|
||||
$this->zayavka = $zayavka;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float|int
|
||||
*/
|
||||
public function getMaxHealth()
|
||||
public function saveAnketa()
|
||||
{
|
||||
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()
|
||||
public function setOnline()
|
||||
{
|
||||
return $this->maxMana;
|
||||
self::$db->execute('update online set real_time = ? where user_id = ?', [time(), $this->getId()]);
|
||||
}
|
||||
|
||||
public function setInjury(int $type): bool
|
||||
{
|
||||
if (!in_array($type,[11,12,13,14])) {
|
||||
return false;
|
||||
}
|
||||
$names1 = ['разбитый нос', 'сотрясение первой степени', 'потрепанные уши', 'прикушенный язык', 'перелом переносицы', 'растяжение ноги', 'растяжение руки', 'подбитый глаз', 'синяк под глазом', 'кровоточащее рассечение', 'отбитая «пятая точка»', 'заклинившая челюсть', 'выбитый зуб «мудрости»', 'косоглазие'];
|
||||
$names2 = ['отбитые почки', 'вывих «вырезано цензурой»', 'сотрясение второй степени', 'оторванное ухо', 'вывих руки', 'оторванные уши', 'поврежденный позвоночник', 'поврежденный копчик', 'разрыв сухожилия', 'перелом ребра', 'перелом двух ребер', 'вывих ноги', 'сломанная челюсть'];
|
||||
$names3 = ['пробитый череп', 'разрыв селезенки', 'смещение позвонков', 'открытый перелом руки', 'открытый перелом «вырезано цензурой»', 'излом носоглотки', 'непонятные, но множественные травмы', 'сильное внутреннее кровотечение', 'раздробленная коленная чашечка', 'перелом шеи', 'смещение позвонков', 'открытый перелом ключицы', 'перелом позвоночника', 'вывих позвоночника', 'сотрясение третьей степени'];
|
||||
$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]));
|
||||
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)]));
|
||||
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)]));
|
||||
break;
|
||||
default: //type 14
|
||||
self::setUserEffect($this->id, $type, UserEffects::$effectName[$type], strtotime('1day'), json_encode([$param_names(0) => -10]));
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,10 @@ trait UserEffects
|
||||
4 => 'Заклятие хаоса',
|
||||
5 => 'Заклятие обезличивания',
|
||||
10 => 'паралич',
|
||||
11 => 'легкая травма',
|
||||
12 => 'средняя травма',
|
||||
13 => 'тяжёлая травма',
|
||||
14 => 'неизлечимая травма',
|
||||
11 => 'Легкая травма',
|
||||
12 => 'Средняя травма',
|
||||
13 => 'Тяжёлая травма',
|
||||
14 => 'Неизлечимая травма',
|
||||
20 => 'Проверка Паладинов',
|
||||
21 => 'Сила нейтралитета',
|
||||
22 => 'Защита от кулачного нападения',
|
||||
@@ -49,4 +49,40 @@ trait UserEffects
|
||||
1022 => 'невидимость',
|
||||
9994 => 'Антидот/Путы (Эликсир?)',
|
||||
];
|
||||
|
||||
public static $effectImage = [
|
||||
1 => 'travma.gif',
|
||||
2 => 'magic/sleep.gif',
|
||||
3 => 'magic/sleepf.gif',
|
||||
4 => 'magic/haos.gif',
|
||||
5 => 'magic/obezl.gif',
|
||||
6 => 'expx15.gif',
|
||||
7 => 'euphoria.png',
|
||||
8 => 'sleep_obj.gif',
|
||||
10 => 'magic/chains.gif',
|
||||
11 => 'travma.gif',
|
||||
12 => 'travma.gif',
|
||||
13 => 'travma.gif',
|
||||
14 => 'travma.gif',
|
||||
20 => 'check.gif',
|
||||
21 => 'magic/al_neut_power.gif',
|
||||
22 => 'magic/fist_def.gif',
|
||||
201 => 'magic/defence.gif',
|
||||
202 => 'magic/devastate.gif',
|
||||
203 => 'magic/spell_luck.gif',
|
||||
215 => 'magic/wis_air_def1.gif',
|
||||
216 => 'magic/wis_air_def2.gif',
|
||||
217 => 'magic/wis_air_def3.gif',
|
||||
218 => 'magic/wis_earth_def1.gif',
|
||||
219 => 'magic/wis_earth_def2.gif',
|
||||
220 => 'magic/wis_earth_def3.gif',
|
||||
221 => 'magic/wis_fire_def1.gif',
|
||||
222 => 'magic/wis_fire_def2.gif',
|
||||
223 => 'magic/wis_fire_def3.gif',
|
||||
224 => 'magic/wis_water_def1.gif',
|
||||
225 => 'magic/wis_water_def2.gif',
|
||||
226 => 'magic/wis_water_def3.gif',
|
||||
227 => 'magic/attack_defence.gif',
|
||||
1022 => 'sh/hidden.gif',
|
||||
];
|
||||
}
|
||||
+103
-68
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
namespace Battles;
|
||||
use Battles\Database\DBPDO;
|
||||
use Battles\Models\EffectsModel;
|
||||
use Exceptions\GameException;
|
||||
|
||||
class UserInfo extends User
|
||||
class UserInfo extends UserStats
|
||||
{
|
||||
use Rooms;
|
||||
//Статусы того, кто смотрит на информацию.
|
||||
@@ -25,13 +25,13 @@ class UserInfo extends User
|
||||
$dressedItems = $di->getItemsInSlots();
|
||||
for ($i = 1; $i <= 12; $i++) {
|
||||
echo sprintf('<div class="slot-%s">', $i);
|
||||
if (!empty($dressedItems[$i])) {
|
||||
if (!empty($dressedItems->$i)) {
|
||||
if (!$isBattle && $isMain) {
|
||||
$itemString = '<a href="?edit=%s&drop=%s"><img src="/i/sh/%s" class="item-wrap-normal" alt="%s" title="%s"></a>';
|
||||
echo sprintf($itemString, mt_rand(), $i, $dressedItems[$i]['image'], $dressedItems[$i]['name'], $dressedItems[$i]['name']);
|
||||
echo sprintf('<a href="?edit=%s&drop=%s"><img src="/i/sh/%s" class="item-wrap-normal" alt="%s" title="%s"></a>',
|
||||
mt_rand(), $i, $dressedItems->$i->image, $dressedItems->$i->name, $dressedItems->$i->name);
|
||||
} else {
|
||||
$itemString = '<img src="/i/sh/%s" class="item-wrap-normal tip" alt="%s"><span class="tiptext"><strong>%s</strong></span>';
|
||||
echo sprintf($itemString, $dressedItems[$i]['image'], $dressedItems[$i]['name'], $dressedItems[$i]['name']);
|
||||
echo sprintf('<img src="/i/sh/%s" class="item-wrap-normal tip" alt="%s"><span class="tiptext"><strong>%s</strong></span>',
|
||||
$dressedItems->$i->image, $dressedItems->$i->name, $dressedItems->$i->name);
|
||||
}
|
||||
} else {
|
||||
echo sprintf('<img src="/i/sh/noitem.png" class="item-wrap-normal" title="Пустой слот [%s]" alt="Пустой слот [%s]">', $i, $i);
|
||||
@@ -40,8 +40,8 @@ class UserInfo extends User
|
||||
}
|
||||
echo '<div class="slot-image">';
|
||||
if ($isBattle) {
|
||||
$sh = '<img src="/i/shadow/%s" alt="%s" class="tip"><span class="tiptext"><b>%s</b>Уровень: %s<br>Сила: %s<br>Ловкость: %s<br>Интуиция: %s<br>Выносливость: %s<br>Интеллект: %s<br>Мудрость: %s</span>';
|
||||
echo sprintf($sh, $this->shadow, $this->login, $this->login, $this->level, $this->strength, $this->dexterity, $this->intuition, $this->endurance, $this->intelligence, $this->wisdom);
|
||||
echo sprintf('<img src="/i/shadow/%s" alt="%s" class="tip"><span class="tiptext"><b>%s</b>Уровень: %s<br>Сила: %s<br>Ловкость: %s<br>Интуиция: %s<br>Выносливость: %s<br>Интеллект: %s<br>Мудрость: %s</span>',
|
||||
$this->shadow, $this->login, $this->login, $this->level, $this->strength, $this->dexterity, $this->intuition, $this->endurance, $this->intelligence, $this->wisdom);
|
||||
unset($sh);
|
||||
} else {
|
||||
echo '<img src="/i/shadow/' . $this->shadow . '" alt="' . $this->login . '">';
|
||||
@@ -54,12 +54,12 @@ class UserInfo extends User
|
||||
$captions = 'Уровень:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Местонахождение:';
|
||||
$variables =
|
||||
$this->level . '<br>' .
|
||||
parent::getStat('strength') . '<br>' .
|
||||
parent::getStat('dexterity') . '<br>' .
|
||||
parent::getStat('intuition') . '<br>' .
|
||||
parent::getStat('endurance') . '<br>' .
|
||||
parent::getStat('intelligence') . '<br>' .
|
||||
parent::getStat('wisdom') . '<br>' .
|
||||
parent::getFullStats()->strength . '<br>' .
|
||||
parent::getFullStats()->dexterity . '<br>' .
|
||||
parent::getFullStats()->intuition . '<br>' .
|
||||
parent::getFullStats()->endurance . '<br>' .
|
||||
parent::getFullStats()->intelligence . '<br>' .
|
||||
parent::getFullStats()->wisdom . '<br>' .
|
||||
Rooms::$roomNames[$this->room];
|
||||
if ($isMainWindow) {
|
||||
$this->Bank = new Bank($this->id);
|
||||
@@ -78,31 +78,68 @@ class UserInfo extends User
|
||||
$this->money . '<br>' .
|
||||
$this->Bank->getMoney();
|
||||
}
|
||||
$nameString = '';
|
||||
if ($this->align) {
|
||||
$nameString = sprintf('<img src="/i/align_%s.png" alt="Склонность">', $this->align);
|
||||
$nameString = null;
|
||||
$nameString .= $this->align ? "<img src='/i/align_$this->align.png' alt='Склонность'>" : "";
|
||||
$nameString .= $this->block ? "<span class='private' style='text-decoration: line-through;'>$this->login</span>" : "<b>$this->login</b>";
|
||||
$nameString .= $this->clan ? "<img src='/i/clan/$this->clan.png' alt='Клан'>" : "";
|
||||
|
||||
echo <<<HTML
|
||||
<div class="user-info">
|
||||
<div class="info"><b>$nameString</b></div><!-- info -->
|
||||
<div class="stats-container">
|
||||
<div class="column">$captions</div><!-- column -->
|
||||
<div class="column">$variables</div><!-- column -->
|
||||
</div><!-- stats-container -->
|
||||
</div><!-- user-info -->
|
||||
HTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* О персонаже для модераторов.
|
||||
* @return string|null
|
||||
*/
|
||||
private function showPrivateData(): ?string
|
||||
{
|
||||
if (!$this->watcherIsAdmin || !$this->watcherIsModerator) {
|
||||
return null;
|
||||
}
|
||||
if ($this->block) {
|
||||
$nameString .= '<span class="private"><s>' . $this->login . '</s></span>';
|
||||
} else {
|
||||
$nameString .= ' <b>' . $this->login . '</b> ';
|
||||
$birthday = date('d.m.Y', strtotime($this->borndate));
|
||||
$userLogs = GameLogs::getUserLogs($this->id);
|
||||
$log = null;
|
||||
while ($userLogRow = $userLogs->fetchArray(SQLITE3_ASSOC)) {
|
||||
$log .= sprintf('<code>%s</code><br>', date('d.m.Y H:i ', strtotime($userLogRow['date'])) . $userLogRow['text']);
|
||||
}
|
||||
if ($this->clan) {
|
||||
$nameString .= sprintf('<img src="/i/clan/%s.png" alt="Клан">', $this->clan);
|
||||
}
|
||||
echo '<div class="user-info">';
|
||||
echo '<div class="info">';
|
||||
echo '<b>' . $nameString . '</b>';
|
||||
echo '</div><!-- info -->';
|
||||
echo '<div class="stats-container">';
|
||||
echo '<div class="column">';
|
||||
echo $captions;
|
||||
echo '</div><!-- column -->';
|
||||
echo '<div class="column">';
|
||||
echo $variables;
|
||||
echo '</div><!-- column -->';
|
||||
echo '</div><!-- stats-container -->';
|
||||
echo '</div><!-- user-info -->';
|
||||
$adminData = $this->watcherIsAdmin ? $this->showAdminOnlyData() : null;
|
||||
return <<<INFO
|
||||
<div class="secret-info">
|
||||
E-Mail: $this->email<br>
|
||||
ДР Игрока: $birthday<br>
|
||||
IP Регистрации: $this->ip<br>
|
||||
$adminData<br>
|
||||
<div class="secret-info-user-log"><b>Личное дело</b><br>
|
||||
$log
|
||||
</div><!-- secret-info-user-log -->
|
||||
</div><!-- secret-info -->
|
||||
INFO;
|
||||
}
|
||||
|
||||
/**
|
||||
* О персонаже для администраторов.
|
||||
* @return string|null
|
||||
*/
|
||||
private function showAdminOnlyData(): ?string
|
||||
{
|
||||
$this->Bank = new Bank($this->id);
|
||||
$bankMoney = $this->Bank->getMoney();
|
||||
return <<<INFO
|
||||
ИД Игрока: $this->id<br>
|
||||
ИД Комнаты: $this->room<br>
|
||||
Деньги: $this->money<br>
|
||||
Деньги в банке: $bankMoney<br>
|
||||
Опыт: $this->experience<br>
|
||||
Нераспределённые очки: $this->free_stat_points<br>
|
||||
INFO;
|
||||
|
||||
}
|
||||
|
||||
private function Info()
|
||||
@@ -110,10 +147,7 @@ class UserInfo extends User
|
||||
echo '<div class="user-info-container">';
|
||||
$this->UserInfoDoll();
|
||||
$this->UserInfoStats();
|
||||
echo '<div class="slot-lower">';
|
||||
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 class="slot-lower"> <!-- statuses! -->';
|
||||
echo '</div><!-- slot-lower -->';
|
||||
echo '<div class="user-signs">';
|
||||
echo sprintf('<img src="i/zodiac/%s.png" alt="Родовой знак">', $this->showStarSign());
|
||||
@@ -122,31 +156,10 @@ class UserInfo extends User
|
||||
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 $this->realname ? "Имя: $this->realname" : "";
|
||||
echo $this->info ? "<br>" . nl2br($this->info) : "";
|
||||
echo '</div><!-- user-info-container-lower -->';
|
||||
|
||||
if ($this->watcherIsAdmin || $this->watcherIsModerator) {
|
||||
echo '<div class="secret-info">';
|
||||
$infoString = 'E-Mail: %s<br> ДР Игрока: %s<br> IP Регистрации: %s';
|
||||
echo sprintf($infoString, $this->email, date('d.m.Y', strtotime($this->borndate)), $this->ip);
|
||||
if ($this->watcherIsAdmin) {
|
||||
$this->Bank = new Bank($this->id);
|
||||
$infoString = '<br><span>ИД Игрока: %s<br> ИД Комнаты: %s<br> Деньги: %s<br> Деньги в банке: %s<br> Опыт: %s<br> Нераспределённые очки: %s<br> Текущая сессия: %s</span>';
|
||||
echo sprintf($infoString, $this->id, $this->room, $this->money, $this->Bank->getMoney(), $this->experience, $this->free_stat_points, $this->session_id);
|
||||
}
|
||||
$this->UserLogs = GameLogs::getUserLogs($this->id);
|
||||
echo '<div class="secret-info-user-log"><b>Личное дело</b><br>';
|
||||
while ($userLogRow = $this->UserLogs->fetchArray(SQLITE3_ASSOC)) {
|
||||
echo sprintf('<code>%s</code><br>', date("d.m.Y H:i ", strtotime($userLogRow['date'])) . $userLogRow['text']);
|
||||
}
|
||||
echo '</div><!-- secret-info-user-log -->';
|
||||
echo '</div><!-- secret-info -->';
|
||||
}
|
||||
echo $this->showPrivateData();
|
||||
}
|
||||
|
||||
public function showUserInfo()
|
||||
@@ -155,14 +168,14 @@ class UserInfo extends User
|
||||
$effects = new EffectsModel($this->id);
|
||||
|
||||
if ($this->block && (!$this->watcherIsAdmin || !$this->watcherIsModerator)) {
|
||||
throw new GameException('<span class="error">Персонаж ' . $this->login . ' заблокирован!</span>');
|
||||
echo "<span class='error'>Персонаж $this->login заблокирован!</span>";
|
||||
} elseif ($effects->getHideUserInfoStatus() && (!$this->watcherIsAdmin || !$this->watcherIsModerator)) {
|
||||
if ($effects->getHideUserInfoStatus() == -1) {
|
||||
$date = 'навсегда';
|
||||
} else {
|
||||
$date = 'до' . date('d.m.Y', strtotime($effects->getHideUserInfoStatus()));
|
||||
}
|
||||
throw new GameException('<span class="error">Персонаж ' . $this->login . ' обезличен ' . $date . '.</span>');
|
||||
echo "<span class='error'>Персонаж $this->login обезличен $date.</span>";
|
||||
} else {
|
||||
$this->Info();
|
||||
}
|
||||
@@ -194,4 +207,26 @@ class UserInfo extends User
|
||||
echo '</div><!-- user-info-container -->';
|
||||
}
|
||||
|
||||
public function showUserEffects(): string
|
||||
{
|
||||
$effs = DBPDO::INIT()->ofetchAll('SELECT * FROM users_effects WHERE owner_id = ?', $this->id);
|
||||
$img = UserEffects::$effectImage;
|
||||
$r = '';
|
||||
foreach ($effs as $effect) {
|
||||
$timeleft = timeOut($effect->remaining_time - time());
|
||||
$r .= "
|
||||
<div>
|
||||
<img class='image' src='/i/{$img[$effect->type]}' alt='{$effect->name}'>
|
||||
<span class='title'>{$effect->name}</span>
|
||||
<div class='timeleft'>$timeleft</div>
|
||||
</div>
|
||||
";
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
public function showStarSign(): ?string
|
||||
{
|
||||
return parent::showStarSign();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?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 getHeadArmor(): int
|
||||
{
|
||||
return $this->headArmor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getChestArmor(): int
|
||||
{
|
||||
return $this->chestArmor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLegArmor(): int
|
||||
{
|
||||
return $this->legArmor;
|
||||
}
|
||||
|
||||
public function getFullStats()
|
||||
{
|
||||
$query = "
|
||||
select
|
||||
sum(greatest(strength + (ifnull((select sum(add_strength) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)) + (ifnull((select sum(mod_strength) from users_effects where owner_id = $this->id), 0)), 0)) as strength,
|
||||
sum(greatest(dexterity + (ifnull((select sum(add_dexterity) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)) + (ifnull((select sum(mod_dexterity) from users_effects where owner_id = $this->id), 0)), 0)) as dexterity,
|
||||
sum(greatest(intuition + (ifnull((select sum(add_intuition) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)) + (ifnull((select sum(mod_intuition) from users_effects where owner_id = $this->id), 0)), 0)) as intuition,
|
||||
sum(greatest(endurance + (ifnull((select sum(add_endurance) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)) + (ifnull((select sum(mod_endurance) from users_effects where owner_id = $this->id), 0)), 0)) as endurance,
|
||||
sum(greatest(intelligence + (ifnull((select sum(add_intelligence) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)) + (ifnull((select sum(mod_intelligence) from users_effects where owner_id = $this->id), 0)), 0)) as intelligence,
|
||||
sum(greatest(wisdom + (ifnull((select sum(add_wisdom) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)) + (ifnull((select sum(mod_wisdom) from users_effects where owner_id = $this->id), 0)), 0)) as wisdom,
|
||||
ifnull((select sum(add_accuracy) from inventory where dressed_slot != 0 and owner_id = $this->id), 0) as accuracy,
|
||||
ifnull((select sum(add_evasion) from inventory where dressed_slot != 0 and owner_id = $this->id), 0) as evasion,
|
||||
ifnull((select sum(add_criticals) from inventory where dressed_slot != 0 and owner_id = $this->id), 0) as criticals,
|
||||
sum(greatest($this->minDamage + (ifnull((select sum(add_min_physical_damage) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)), 0)) as min_physical_damage,
|
||||
sum(greatest($this->maxDamage + (ifnull((select sum(add_max_physical_damage) from inventory where dressed_slot != 0 and owner_id = $this->id), 0)), 0)) as max_physical_damage
|
||||
from users where id = $this->id";
|
||||
return self::$db->ofetch($query);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
if (in_array($user->getRoom(), Config::$caverooms)) {
|
||||
$cavedata = Config::$cavedata ?? [];
|
||||
if (in_array($user->getRoom(), CAVE_ROOMS)) {
|
||||
$cavedata = CAVE_DATA ?? [];
|
||||
$floor = mysql_fetch_row(mysql_query("SELECT `floor` FROM `caveparties` WHERE `user` = '$user[id]' LIMIT 1"));
|
||||
if (!isset($cavedata[$user->getRoom()]['x' . $floor])) {
|
||||
$floor = 1;
|
||||
@@ -11,7 +11,7 @@ $lomka1 = $lomka;
|
||||
|
||||
foreach ($lomka1 as $k => $v) {
|
||||
if ($v < _BOTSEPARATOR_) {
|
||||
if (in_array($user->getRoom(), Config::$caverooms)) {
|
||||
if (in_array($user->getRoom(), CAVE_ROOMS)) {
|
||||
mysql_query("UPDATE `caveparties` SET `floor` = $floor, `x` = '" . $cavedata[$user->getRoom()]['x' . $floor] . "', `y` = '" . $cavedata[$user->getRoom()]['y' . $floor] . "', `dir` = '" . $cavedata[$user->getRoom()]['dir' . $floor] . "', `loses` = (`loses`+1) WHERE `user` = '$v' LIMIT 1");
|
||||
}
|
||||
if ($user['laba'] > 0) {
|
||||
|
||||
@@ -21,7 +21,7 @@ function cavesys($text)
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($user->getRoom(), Config::$caverooms)) {
|
||||
if (in_array($user->getRoom(), CAVE_ROOMS)) {
|
||||
include("CaveItems.php");
|
||||
mysql_query('LOCK TABLES `cavebots` WRITE, `caveitems` WRITE, `shop` WRITE, `caveparties` WRITE');
|
||||
$location = mysql_fetch_array(mysql_query("SELECT `x`, `y`, `dir`, `floor` FROM `caveparties` WHERE `user` = '$user[id]' LIMIT 1"));
|
||||
|
||||
+11
-3
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Battles\GameConfigs;
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: lopiu
|
||||
@@ -20,11 +23,16 @@ class db
|
||||
{
|
||||
if (!self::$_instance)
|
||||
{
|
||||
self::$_instance = Krugozor\Database\Mysql\Mysql::create("192.168.20.5", "battles", "bottle-neck-horse", 32101)
|
||||
self::$_instance = Krugozor\Database\Mysql\Mysql::create(
|
||||
GameConfigs::DATABASE_HOST,
|
||||
GameConfigs::DATABASE_USER,
|
||||
GameConfigs::DATABASE_PASS,
|
||||
GameConfigs::DATABASE_PORT
|
||||
)
|
||||
// Выбор базы данных
|
||||
->setDatabaseName("battles")
|
||||
->setDatabaseName(GameConfigs::DATABASE_NAME)
|
||||
// Выбор кодировки
|
||||
->setCharset("utf8");
|
||||
->setCharset(GameConfigs::DATABASE_CHARSET);
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
@@ -1700,7 +1700,7 @@ class fbattle
|
||||
}
|
||||
|
||||
|
||||
if (in_array($user->getRoom(), Config::$caverooms)) {
|
||||
if (in_array($user->getRoom(), CAVE_ROOMS)) {
|
||||
$location = mysql_fetch_array(mysql_query("SELECT `x`, `y`, `dir` FROM `caveparties` WHERE `user` = '" . $this->user['id'] . "' LIMIT 1"));
|
||||
|
||||
if ($location['dir'] == 0) {
|
||||
@@ -1805,7 +1805,7 @@ class fbattle
|
||||
|
||||
function addAction($time, $vars, $vls, $uid)
|
||||
{
|
||||
$ins = mysql_query('INSERT INTO `actions` (`uid`, `time`, `city`, `room`, `vars`, `ip`, `vals`) VALUES ("' . $uid . '", "' . $time . '", "capitalcity", "0", "' . mysql_real_escape_string($vars) . '", "' . mysql_real_escape_string($_SERVER['HTTP_X_REAL_IP']) . '", "' . mysql_real_escape_string($vls) . '")');
|
||||
$ins = mysql_query('INSERT INTO `actions` (`uid`, `time`, `city`, `room`, `vars`, `ip`, `vals`) VALUES ("' . $uid . '", "' . $time . '", "capitalcity", "0", "' . mysql_real_escape_string($vars) . '", "' . $_SERVER['REMOTE_ADDR'] . '", "' . mysql_real_escape_string($vls) . '")');
|
||||
if ($ins) {
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -76,7 +76,7 @@ class Quests
|
||||
if (db::c()->getAffectedRows()) {
|
||||
$tms = (time() + 60 * 60 * $pl['time']);
|
||||
db::c()->query('INSERT INTO `actions` (`uid`, `time`, `city`, `room`, `vars`, `ip`, `vals`, `val`) VALUES (?i,?i,"?s",?i,"?s","?s","?s","?s")',
|
||||
$uid, time(), 'capitalcity', 0, 'start_quest' . $id, $_SERVER['HTTP_X_REAL_IP'], 'go', $tms);
|
||||
$uid, time(), 'capitalcity', 0, 'start_quest' . $id, $_SERVER['REMOTE_ADDR'], 'go', $tms);
|
||||
return 'Вы успешно получили задание "' . $pl['name'] . '"';
|
||||
} else {
|
||||
return 'Не удалось получить данное задание ...';
|
||||
|
||||
Reference in New Issue
Block a user