This commit is contained in:
Igor Barkov (iwork) 2020-07-22 17:04:15 +03:00
parent f0bf7069de
commit 35031f1296
5 changed files with 135 additions and 135 deletions

View File

@ -31,6 +31,11 @@ class DressedItems
}
}
private function getDressedItemById($item_id)
{
return db::c()->query('SELECT * FROM inventory WHERE item_id = ?i AND dressed_slot > 0', $item_id)->fetch_assoc();
}
private function getBonusesFromDressedItems()
{
try {
@ -45,8 +50,7 @@ SELECT SUM(add_strength) as sum_strength,
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,
SUM(weight) as sum_weight
SUM(add_max_physical_damage) as sum_max_phys_damage
FROM inventory WHERE owner_id = ?i AND dressed_slot > 0
SQL;
$this->DBSUM = db::c()->query($query, $this->USERID)->fetch_assoc();
@ -61,8 +65,7 @@ SQL;
self::getDressedItems();
}
while ($row = $this->DB->fetch_assoc()) {
$dressed_item[$row['dressed_slot']] = $row;
$this->dressedItem[$row['dressed_slot']] = $row;
$this->dressedItem[$row['item_type']] = $row;
}
return $this->dressedItem;
}
@ -111,10 +114,6 @@ SQL;
{
return self::getBonuses()['sum_criticals'];
}
public function getItemsWeight()
{
return self::getBonuses()['sum_weight'];
}
/**
* Снимает с предмета статус одетого на персонажа в определённом слоте персонажа.
@ -126,8 +125,16 @@ SQL;
{
self::getItemsInSlots();
// Проверяем, что используется один из 12 слотов и наличие предмета в слоте.
if (in_array($slot_id, range(1,12)) && $this->dressedItem[$slot_id]) {
if (in_array($slot_id, Item::ITEM_TYPES_ALLOWED_IN_SLOTS) && $this->dressedItem[$slot_id]) {
db::c()->query('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ?i AND owner_id = ?i', $slot_id, $this->USERID);
}
}
public function slotStatus($slot_id)
{
self::getItemsInSlots();
if ($this->dressedItem[$slot_id]) {
}
}
}

View File

@ -22,7 +22,7 @@ class InventoryItem extends Item
public function printImage()
{
if (!in_array($this->item_type, [12, 50, 200])) {
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>";

View File

@ -2,30 +2,44 @@
abstract class Item
{
public $item_id;
public $name;
public $item_type;
public $durability;
public $price;
public $need_strength;
public $need_dexterity;
public $need_intuition;
public $need_endurance;
public $need_intelligence;
public $need_wisdom;
public $add_strength;
public $add_dexterity;
public $add_intuition;
public $add_endurance;
public $add_intelligence;
public $add_wisdom;
public $add_accuracy;
public $add_evasion;
public $add_criticals;
public $add_min_physical_damage;
public $add_max_physical_damage;
public $weight;
public $image;
protected $item_id;
protected $name;
protected $item_type;
protected $durability;
protected $price;
protected $need_strength;
protected $need_dexterity;
protected $need_intuition;
protected $need_endurance;
protected $need_intelligence;
protected $need_wisdom;
protected $add_strength;
protected $add_dexterity;
protected $add_intuition;
protected $add_endurance;
protected $add_intelligence;
protected $add_wisdom;
protected $add_accuracy;
protected $add_evasion;
protected $add_criticals;
protected $add_min_physical_damage;
protected $add_max_physical_damage;
protected $weight;
protected $image;
public const ITEM_TYPES_ALLOWED_IN_SLOTS = [1,2,3,4,5,6,7,8,9,10,11,12];
public const ITEM_TYPE_HELMET = 1;
public const ITEM_TYPE_ARMOR = 2;
const ITEM_TYPE_LEGS = 3;
const ITEM_TYPE_BOOTS = 4;
const ITEM_TYPE_GLOVES = 5;
const ITEM_TYPE_WEAPON = 6;
const ITEM_TYPE_SHIELD = 7;
const ITEM_TYPE_BELT = 8;
public const ITEM_TYPE_RING = 9;
const ITEM_TYPE_AMULET = 10;
const ITEM_TYPE_CONSUMABLE = 20;
const ITEM_TYPE_OTHER = 50;
const ITEM_TYPE_TRASH = 100;
/**
* Item constructor.
@ -41,28 +55,28 @@ abstract class Item
}
switch ($this->item_type) {
case 1:
case self::ITEM_TYPE_HELMET:
$this->typename = 'Шлем';
break;
case 2:
case self::ITEM_TYPE_ARMOR:
$this->typename = 'Броня';
break;
case 3:
case self::ITEM_TYPE_LEGS:
$this->typename = 'Поножи';
break;
case 4:
case self::ITEM_TYPE_BOOTS:
$this->typename = 'Сапоги';
break;
case 5:
case self::ITEM_TYPE_GLOVES:
$this->typename = 'Перчатки';
break;
case 6:
case self::ITEM_TYPE_WEAPON:
$this->typename = 'Оружие';
break;
case 7:
case self::ITEM_TYPE_SHIELD:
$this->typename = 'Щит';
break;
case 8:
case self::ITEM_TYPE_BELT:
$this->typename = 'Пояс';
break;
case 9:
@ -83,7 +97,7 @@ abstract class Item
public function printImage()
{
echo <<<IMG
<img src="/i/sh/{$this->image}" class="item-wrap-normal">
<img src="/i/sh/{$this->image}" class="item-wrap-normal" alt="">
IMG;
}

View File

@ -32,13 +32,13 @@ class User
public $headArmor = 0;
public $chestArmor = 0;
public $legArmor = 0;
public $free_stat_points = 0;
public const STAT_MAXIMUM_AMOUNT = 40;
private const ERROR_STAT_IS_MAXIMUM = 'Ошибка: Параметр достиг своего лимита!';
private const ERROR_STAT_UNKNOWN = 'Ошибка: Неизвестный параметр!';
// Пока несуществующие, для совместимости.
public $married = 'Someone или нет.';
public $experience = 200;
public $stat_points = 1;
// Динамически рассчитываемые
public $health;
//Статусы того, кто смотрит на информацию.
@ -109,7 +109,7 @@ class User
if ($isMainWindow) {
$this->Bank = new Bank($this->id);
$captions = 'Уровень:<br>Здоровье:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Опыт:<br>Очки характеристик:<br>Деньги:<br>Деньги в банке:';
$variables = $this->level . '<br>' . $this->health . '<br>' . $this->getStrength(1) . '<br>' . $this->getDexterity(1) . '<br>' . $this->getIntuition(1) . '<br>' . $this->getEndurance(1) . '<br>' . $this->getIntelligence(1) . '<br>' . $this->getWisdom(1) . '<br>' . $this->experience . '<br>' . $this->stat_points . '<br>' . $this->money . '<br>' . $this->Bank->money;
$variables = $this->level . '<br>' . $this->health . '<br>' . $this->getStrength(1) . '<br>' . $this->getDexterity(1) . '<br>' . $this->getIntuition(1) . '<br>' . $this->getEndurance(1) . '<br>' . $this->getIntelligence(1) . '<br>' . $this->getWisdom(1) . '<br>' . $this->experience . '<br>' . $this->free_stat_points . '<br>' . $this->money . '<br>' . $this->Bank->money;
}
if ($this->align) {
@ -141,7 +141,7 @@ class User
public function getStrength($isMainWindow = 0)
{
if ($this->stat_points && $isMainWindow && $this->strength < self::STAT_MAXIMUM_AMOUNT) {
if ($this->free_stat_points && $isMainWindow && $this->strength < self::STAT_MAXIMUM_AMOUNT) {
//main.php?edit=1&ups=sila
return sprintf('%s <a href="#">[+]</a>', $this->strength);
}
@ -150,7 +150,7 @@ class User
public function getDexterity($isMainWindow = 0)
{
if ($this->stat_points && $isMainWindow && $this->dexterity < self::STAT_MAXIMUM_AMOUNT) {
if ($this->free_stat_points && $isMainWindow && $this->dexterity < self::STAT_MAXIMUM_AMOUNT) {
//main.php?edit=1&ups=lovk
return sprintf('%s <a href="#">[+]</a>', $this->dexterity);
}
@ -159,7 +159,7 @@ class User
public function getIntuition($isMainWindow = 0)
{
if ($this->stat_points && $isMainWindow && $this->intuition < self::STAT_MAXIMUM_AMOUNT) {
if ($this->free_stat_points && $isMainWindow && $this->intuition < self::STAT_MAXIMUM_AMOUNT) {
//main.php?edit=1&ups=inta...
return sprintf('%s <a href="#">[+]</a>', $this->intuition);
}
@ -168,7 +168,7 @@ class User
public function getEndurance($isMainWindow = 0)
{
if ($this->stat_points && $isMainWindow && $this->endurance < self::STAT_MAXIMUM_AMOUNT) {
if ($this->free_stat_points && $isMainWindow && $this->endurance < self::STAT_MAXIMUM_AMOUNT) {
return sprintf('%s <a href="#">[+]</a>', $this->endurance);
}
return $this->endurance;
@ -176,7 +176,7 @@ class User
public function getIntelligence($isMainWindow = 0)
{
if ($this->stat_points && $isMainWindow && $this->intelligence < self::STAT_MAXIMUM_AMOUNT) {
if ($this->free_stat_points && $isMainWindow && $this->intelligence < self::STAT_MAXIMUM_AMOUNT) {
return sprintf('%s <a href="#">[+]</a>', $this->intelligence);
}
return $this->intelligence;
@ -184,7 +184,7 @@ class User
public function getWisdom($isMainWindow = 0)
{
if ($this->stat_points && $isMainWindow && $this->wisdom < self::STAT_MAXIMUM_AMOUNT) {
if ($this->free_stat_points && $isMainWindow && $this->wisdom < self::STAT_MAXIMUM_AMOUNT) {
return sprintf('%s <a href="#">[+]</a>', $this->wisdom);
}
return $this->wisdom;
@ -192,7 +192,7 @@ class User
public function setStrength()
{
if ($this->strength <= self::STAT_MAXIMUM_AMOUNT && $this->stat_points > 0) {
if ($this->strength <= self::STAT_MAXIMUM_AMOUNT && $this->free_stat_points > 0) {
db::c()->query('UPDATE users SET strength = strength + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i', $this->id);
} else {
throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
@ -201,7 +201,7 @@ class User
public function setDexterity()
{
if ($this->dexterity <= self::STAT_MAXIMUM_AMOUNT && $this->stat_points > 0) {
if ($this->dexterity <= self::STAT_MAXIMUM_AMOUNT && $this->free_stat_points > 0) {
db::c()->query('UPDATE users SET dexterity = dexterity + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i', $this->id);
} else {
throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
@ -210,7 +210,7 @@ class User
public function setIntuition()
{
if ($this->intuition <= self::STAT_MAXIMUM_AMOUNT && $this->stat_points > 0) {
if ($this->intuition <= self::STAT_MAXIMUM_AMOUNT && $this->free_stat_points > 0) {
db::c()->query('UPDATE users SET intuition = intuition + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i', $this->id);
} else {
throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
@ -219,7 +219,7 @@ class User
public function setEndurance()
{
if ($this->endurance <= self::STAT_MAXIMUM_AMOUNT && $this->stat_points > 0) {
if ($this->endurance <= self::STAT_MAXIMUM_AMOUNT && $this->free_stat_points > 0) {
db::c()->query('UPDATE users SET endurance = endurance + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i', $this->id);
} else {
throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
@ -228,7 +228,7 @@ class User
public function setIntelligence()
{
if ($this->intelligence <= self::STAT_MAXIMUM_AMOUNT && $this->stat_points > 0) {
if ($this->intelligence <= self::STAT_MAXIMUM_AMOUNT && $this->free_stat_points > 0) {
db::c()->query('UPDATE users SET intelligence = intelligence + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i', $this->id);
} else {
throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
@ -237,7 +237,7 @@ class User
public function setWisdom()
{
if ($this->wisdom <= self::STAT_MAXIMUM_AMOUNT && $this->stat_points > 0) {
if ($this->wisdom <= self::STAT_MAXIMUM_AMOUNT && $this->free_stat_points > 0) {
db::c()->query('UPDATE users SET wisdom = wisdom + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i', $this->id);
} else {
throw new Exception(self::ERROR_STAT_IS_MAXIMUM);
@ -248,7 +248,7 @@ class User
{
$allowed = ['strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'];
if (in_array($stat_name, $allowed)) {
if ($this->stat_points > 0 && $this->$stat_name <= self::STAT_MAXIMUM_AMOUNT) {
if ($this->free_stat_points > 0 && $this->$stat_name <= self::STAT_MAXIMUM_AMOUNT) {
$query = 'UPDATE users SET ?f = ?f + 1, free_stat_points = free_stat_points - 1 WHERE id = ?i';
db::c()->query($query, $stat_name, $stat_name, $this->id);
} else {
@ -292,7 +292,7 @@ class User
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->money, $this->experience, $this->stat_points, $this->session_id);
echo sprintf($infoString, $this->id, $this->room, $this->money, $this->Bank->money, $this->experience, $this->free_stat_points, $this->session_id);
}
$this->UserLogs = new UserLogModel($this->id);
echo '<div class="secret-info-user-log"><b>Личное дело</b><br>';

131
main.php
View File

@ -294,55 +294,46 @@ function del_efs($uid, $id, $type)
// одеть предмет
function dressitem($id)
{
/*
* FFFFUUUUUUU!!!!!!!!!!!!
* 1. получаем id одеваемого предмета
* 2. смотрим в кокой слот он хочет
* 3. проверяем пустой ли слот
* 4. если слот не пустой, освобождаем слот
* 5. привязываем предмет к слоту
*
* если предмет кольцо
* 1. смотрим три слота колец
* 2. если слот не пустой смотрим слебующий слот
* 3. если слот пустой одеваем предмет в слот
* 4. если все три слота не пустые освобождаем последний слот
* 5. привязываем предмет к слоту
*/
global $user;
$item = db::c()->query('SELECT * FROM `inventory` WHERE `duration` < `maxdur` AND `id` = ?i AND `owner` = ?i AND `dressed` = 0', $id, $user['id'])->fetch_assoc();
switch ($item['type']) {
case 1:
$slot1 = 'sergi';
break;
case 2:
$slot1 = 'kulon';
break;
case 3:
$slot1 = 'weap';
break;
case 4:
$slot1 = 'bron';
break;
case 5:
$slot1 = 'r1';
break;
case 6:
$slot1 = 'r2';
break;
case 7:
$slot1 = 'r3';
break;
case 8:
$slot1 = 'helm';
break;
case 9:
$slot1 = 'perchi';
break;
case 10:
$slot1 = 'shit';
break;
case 11:
$slot1 = 'boots';
break;
case 12:
$slot1 = 'm1';
break;
case 22:
$slot1 = 'rybax';
break;
case 23:
$slot1 = 'plaw';
break;
default:
$slot1 = '';
break;
//$items = new DressedItems($_SESSION['uid']);
//$items->undressItem($_GET['drop']);
$selectedItem = db::c()->query('SELECT * FROM `inventory` WHERE item_id = ?i AND owner_id = ?i AND `dressed_slot` = 0', $id, $_SESSION['uid'])->fetch_object();
$itemInSlot = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot = ?i', $_SESSION['uid'], $selectedItem['item_type']);
if ($itemInSlot->getNumRows()) {
// снимаем предмет и одеваем поверх
} else {
// просто одеваем предмет в слот
}
if (in_array($selectedItem->item_type, [9,10,11])) {
$wearedRings = db::c()->query('SELECT * FROM `inventory` WHERE owner_id = ?i AND dressed_slot IN (9,10,11)', $_SESSION['uid'])->fetch_object();
for ($i = 1; $i <= 3; $i++) {
if (!$wearedRings->dressed_slot) {
db::c()->query('UPDATE inventory SET dressed_slot = ');
}
}
}
if ($selectedItem) {
db::c()->query('UPDATE inventory SET dressed_slot = item_type WHERE id = ?i', $selectedItem['item_id']);
}
if ($item['type'] == 5) {
if (!$user['r1']) {
@ -427,18 +418,6 @@ if (isset($_GET['use'])) {
usemagic($_GET['use'], $_POST['target']);
}
function updstats()
{
global $user;
$u1 = db::c()->query('SELECT
`sila`, `lovk`, `inta`, `intel`, `noj`, `mec`, `topor`, `dubina`,
`mfire`, `mwater`, `mair`, `mearth`, `mlight`, `mgray`, `mdark`, `hp`, `maxhp`
FROM `users` WHERE `id` = ?i', $user['id'])->fetch_assoc();
foreach ($u1 as $k => $v) {
$user[$k] = $v;
}
}
unset($_SESSION['stackall']);
if (isset($_GET["stack"])) {
@ -578,20 +557,20 @@ if (isset($_GET['edit'])) {
$items->undressItem($_GET['drop']);
}
if (input::get('dress')) {
$q = db::c()->query('SELECT `id`, `koll` FROM `inventory` WHERE `id` = ?i AND `owner` = ?i', input::get('dress'), $_SESSION['uid']);
if ($q->getNumRows()) {
$q = $q->fetch_assoc();
if ($q['koll'] > 1) {
$id = unstack($q['id'], 1);
dressitem($id);
} else {
dressitem(input::get('dress'));
}
updstats();
} else {
err('Ошибка: предмет не найден!');
}
if (isset($_GET['dress'])) {
// $q = db::c()->query('SELECT `id`, `koll` FROM `inventory` WHERE `id` = ?i AND `owner` = ?i', input::get('dress'), $_SESSION['uid']);
// if ($q->getNumRows()) {
// $q = $q->fetch_assoc();
// if ($q['koll'] > 1) {
// $id = unstack($q['id'], 1);
// dressitem($id);
// } else {
// dressitem(input::get('dress'));
// }
// } else {
// err('Ошибка: предмет не найден!');
// }
}
if (input::get('destruct')) {
@ -627,7 +606,6 @@ if (isset($_GET['edit'])) {
if (input::get('undress')) {
undressall($_SESSION['uid']);
updstats();
}
if (input::get('delcomplect')) {
@ -839,7 +817,8 @@ try {
<!--Параметры-->
<div>
<div class="container">
Сила: <?= $showUser->getStrength(1) ?> +<?= $getItemsBonuses->getStrengthBonus() ?><br>
Сила: <?= ($showUser->stat_points ? $showUser->getStrength(1).'('.$getItemsBonuses->getStrengthBonus().')':$getItemsBonuses->getStrengthBonus()) ?><br>
Ловкость: <?= $showUser->getDexterity(1) ?> +<?= $getItemsBonuses->getDexterityBonus() ?><br>
Интуиция: <?= $showUser->getIntuition(1) ?> +<?= $getItemsBonuses->getIntuitionBonus() ?><br>
Выносливость: <?= $showUser->getEndurance(1) ?> +<?= $getItemsBonuses->getEnduranceBonus() ?>
@ -892,7 +871,7 @@ try {
<div id="mZeInventory"> <!--рюкзак-->
<table BORDER=0 WIDTH=100% CELLSPACING="1" CELLPADDING="2" BGCOLOR="#A5A5A5">
<caption>Рюкзак
(масса: <?= $getItemsBonuses->getItemsWeight() . '/' . $showUser->strength * 4 ?>)
(масса: <?= '?? /' . $showUser->strength * 4 ?>)
</caption>
<?php
$data_query = 'SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot = 0 AND on_sale = 0';