Переделка класса Item под новую базу.

This commit is contained in:
Igor Barkov (iwork) 2020-07-21 18:03:46 +03:00
parent bc40aa5004
commit 12feda506a
5 changed files with 151 additions and 216 deletions

View File

@ -7,9 +7,9 @@
class DressedItems class DressedItems
{ {
private static $DB; private $DB;
private static $DBSUM; private $DBSUM;
private static $USERID; private $USERID;
private $dressedItem; private $dressedItem;
/** /**
@ -19,14 +19,13 @@ class DressedItems
*/ */
public function __construct($user_id) public function __construct($user_id)
{ {
//$this->USERID = $user_id; $this->USERID = $user_id;
self::$USERID = $user_id;
} }
private static function getDressedItems() private function getDressedItems()
{ {
try { try {
self::$DB = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', self::$USERID); $this->DB = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $this->USERID);
} catch (Exception $e) { } catch (Exception $e) {
echo '<div class="debug">Не прогрузилась таблица inventory (*) для класса DressedItems.</div>'; echo '<div class="debug">Не прогрузилась таблица inventory (*) для класса DressedItems.</div>';
} }
@ -50,7 +49,7 @@ SELECT SUM(add_strength) as sum_strength,
SUM(weight) as sum_weight SUM(weight) as sum_weight
FROM inventory WHERE owner_id = ?i AND dressed_slot > 0 FROM inventory WHERE owner_id = ?i AND dressed_slot > 0
SQL; SQL;
self::$DBSUM = db::c()->query($query, self::$USERID)->fetch_assoc(); $this->DBSUM = db::c()->query($query, $this->USERID)->fetch_assoc();
} catch (Exception $e) { } catch (Exception $e) {
echo '<div class="debug">Не прогрузилась таблица inventory (SUM) для класса DressedItems:' . $e . '</div>'; echo '<div class="debug">Не прогрузилась таблица inventory (SUM) для класса DressedItems:' . $e . '</div>';
} }
@ -58,66 +57,69 @@ SQL;
public function getItemsInSlots() public function getItemsInSlots()
{ {
if (!self::$DB) { if (!$this->DB) {
//$this->getDressedItems();
self::getDressedItems(); self::getDressedItems();
} }
while ($row = self::$DB->fetch_assoc()) { while ($row = $this->DB->fetch_assoc()) {
$dressed_item[$row['dressed_slot']] = $row; $dressed_item[$row['dressed_slot']] = $row;
$this->dressedItem[$row['dressed_slot']] = $row; $this->dressedItem[$row['dressed_slot']] = $row;
} }
return $this->dressedItem; return $this->dressedItem;
} }
protected function getBonuses() private function getBonuses()
{ {
if (!self::$DBSUM) { if (!$this->DBSUM) {
self::getBonusesFromDressedItems(); self::getBonusesFromDressedItems();
} }
return self::$DBSUM; return $this->DBSUM;
} }
public function getStrengthBonus() public function getStrengthBonus()
{ {
//return $this->getBonuses()['sum_strength'];
return self::getBonuses()['sum_strength']; return self::getBonuses()['sum_strength'];
} }
public function getDexterityBonus() public function getDexterityBonus()
{ {
return $this->getBonuses()['sum_dexterity']; return self::getBonuses()['sum_dexterity'];
} }
public function getIntuitionBonus() public function getIntuitionBonus()
{ {
return $this->getBonuses()['sum_intuition']; return self::getBonuses()['sum_intuition'];
} }
public function getEnduranceBonus() public function getEnduranceBonus()
{ {
return $this->getBonuses()['sum_endurance']; return self::getBonuses()['sum_endurance'];
} }
public function getIntelliganceBonus() public function getIntelliganceBonus()
{ {
return $this->getBonuses()['sum_intelligence']; return self::getBonuses()['sum_intelligence'];
} }
public function getWisdomBonus() public function getWisdomBonus()
{ {
return $this->getBonuses()['sum_wisdom']; return self::getBonuses()['sum_wisdom'];
} }
public function getAccuracyBonus() public function getAccuracyBonus()
{ {
return $this->getBonuses()['sum_accuracy']; return self::getBonuses()['sum_accuracy'];
} }
public function getEvasionBonus() public function getEvasionBonus()
{ {
return $this->getBonuses()['sum_evasion']; return self::getBonuses()['sum_evasion'];
} }
public function getCriticalsBonus() public function getCriticalsBonus()
{ {
return $this->getBonuses()['sum_criticals']; return self::getBonuses()['sum_criticals'];
} }
public function getItemsWeight() public function getItemsWeight()
{ {
return self::getBonuses()['sum_weight']; return self::getBonuses()['sum_weight'];
} }
public function undressItem($slot_id)
{
if (!$slot_id || $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);
}
}
} }

View File

@ -8,28 +8,25 @@ class InventoryItem extends Item
{ {
parent::__construct($row); parent::__construct($row);
$this->present = $row['present']; $this->present = $row['present'];
if ($this->artefact) $this->name = <<<NAME
<b style='color: crimson;'>{$this->name}</b> <img src="//{$_SERVER['SERVER_NAME']}/i/artefact1.gif">
NAME;
} }
public function printInfo() public function printInfo()
{ {
parent::printBaseInfo(); parent::printAllInfo();
parent::printRequirements(); if ($this->present) {
parent::printBonuses(); echo "<p style='color: maroon; font-style: italic'>Это подарок от {$this->present}. Вы не можете передать его кому-либо ещё.</p>";
if ($this->present) echo "<p style='color: maroon; font-style: italic'>Это подарок от {$this->present}. Вы не можете передать его кому-либо ещё.</p>"; }
} }
public function printImage() public function printImage()
{ {
if (!in_array($this->type,[12,50,200])) { if (!in_array($this->item_type, [12, 50, 200])) {
echo "<a href=//{$_SERVER['SERVER_NAME']}/main.php?edit=1&dress={$this->id} title='Надеть'>"; echo "<a href=//{$_SERVER['SERVER_NAME']}/main.php?edit=1&dress={$this->item_id} title='Надеть'>";
parent::printImage(); parent::printImage();
echo "</a>"; echo "</a>";
} else {
parent::printImage();
} }
else parent::printImage();
} }
/** /**
@ -45,6 +42,6 @@ BTN;
public function getId() public function getId()
{ {
return $this->id; return $this->item_id;
} }
} }

View File

@ -2,91 +2,30 @@
abstract class Item abstract class Item
{ {
public $id; public $item_id;
public $name; public $name;
public $nalign; public $item_type;
public $massa; public $durability;
public $maxdur; public $price;
public $img; public $need_strength;
public $need_dexterity;
public $cost; public $need_intuition;
public $artefact; public $need_endurance;
public $need_intelligence;
public $type; public $need_wisdom;
public $add_strength;
public $nlevel; public $add_dexterity;
public $nsila; public $add_intuition;
public $nlovk; public $add_endurance;
public $ninta; public $add_intelligence;
public $nvinos; public $add_wisdom;
public $nintel; public $add_accuracy;
public $nmudra; public $add_evasion;
public $nnoj; public $add_criticals;
public $ntopor; public $add_min_physical_damage;
public $ndubina; public $add_max_physical_damage;
public $nmech; public $weight;
public $nfire; public $image;
public $nwater;
public $nair;
public $nearth;
public $nlight;
public $ngray;
public $ndark;
public $minu;
public $maxu;
public $gsila;
public $glovk;
public $ginta;
public $gintel;
public $gnoj;
public $gtopor;
public $gdubina;
public $gmech;
public $gfire;
public $gwater;
public $gair;
public $gearth;
public $glight;
public $ggray;
public $gdark;
public $ghp;
public $bron1;
public $bron2;
public $bron3;
public $bron4;
public $mfkrit;
public $mfakrit;
public $mfuvorot;
public $mfauvorot;
public $dategoden;
public $goden;
public $needident;
public $magic;
public $magic_name;
public $magic_img;
public $isrep;
public $gmp;
public $encicl;
public $koll;
public $prof;
public $prof1;
public $count;
public $razdel;
public $ecost;
public $zeton;
public $onlyone;
public $shshop;
public $otdel;
public $setsale;
/** /**
* Item constructor. * Item constructor.
@ -101,46 +40,38 @@ abstract class Item
} }
} }
switch ($this->type) { switch ($this->item_type) {
case 1: case 1:
$this->typename = 'Серьги';
break;
case 2:
$this->typename = 'Ожерелье';
break;
case 3:
$this->typename = 'Оружие';
break;
case 4:
$this->typename = 'Броня';
break;
case 5:
$this->typename = 'Кольцо';
break;
case 8:
$this->typename = 'Шлем'; $this->typename = 'Шлем';
break; break;
case 9: case 2:
$this->typename = 'Броня';
break;
case 3:
$this->typename = 'Поножи';
break;
case 4:
$this->typename = 'Сапоги';
break;
case 5:
$this->typename = 'Перчатки'; $this->typename = 'Перчатки';
break; break;
case 10: case 6:
$this->typename = 'Оружие';
break;
case 7:
$this->typename = 'Щит'; $this->typename = 'Щит';
break; break;
case 8:
$this->typename = 'Пояс';
break;
case 9:
case 10:
case 11: case 11:
$this->typename = 'Обувь'; $this->typename = 'Кольцо';
break; break;
case 12: case 12:
$this->typename = 'Магический свиток'; $this->typename = 'Амулет';
break;
case 22:
$this->typename = 'Рубашка';
break;
case 50:
$this->typename = 'Волшебное зелье';
break;
case 200:
$this->typename = 'Сувенир';
break; break;
default: default:
$this->typename = 'Хлам'; $this->typename = 'Хлам';
@ -152,73 +83,80 @@ abstract class Item
public function printImage() public function printImage()
{ {
echo <<<IMG echo <<<IMG
<img src="//{$_SERVER['SERVER_NAME']}/i/sh/{$this->img}" class="item-wrap-normal"> <img src="//{$_SERVER['SERVER_NAME']}/i/sh/{$this->image}" class="item-wrap-normal">
IMG; IMG;
} }
protected function wrap($number) protected function wrap($number)
{ {
if ($number > 0) return ": <b>" . $number . "</b>"; if ($number > 0) {
else return ": <b style='color: maroon;'>" . $number . "</b>"; return ": <b>" . $number . "</b>";
} else {
return ": <b style='color: maroon;'>" . $number . "</b>";
}
} }
protected function printBaseInfo() protected function printAllInfo()
{ {
echo "<b>" . $this->name . "</b> (Масса: " . $this->massa . ")"; echo "<b>" . $this->name . "</b> (Масса: " . $this->weight . ")";
if ($this->nalign) echo " <img src=i/align_{$this->nalign}.gif title='Этот предмет могут использовать только игроки с определённой склонностью.'> "; if ($this->durability) {
if ($this->maxdur > 0) echo "<br>Долговечность: {$this->maxdur}"; echo "<br> Долговечность:" . $this->durability;
if ($this->maxdur == -1) echo "<br>Долговечность: <i>неразрушимо</i>"; }
echo "<br><i>{$this->typename}</i>"; echo "<br><em>{$this->typename}</em><br>";
} if ($this->need_strength > 0) {
echo "<br>Требуется сила" . $this->wrap($this->need_strength);
protected function printRequirements() }
{ if ($this->need_dexterity > 0) {
if ($this->nlevel > 0) echo "<br>Требуется уровень" . $this->wrap($this->nlevel); echo "<br>Требуется ловкость" . $this->wrap($this->need_dexterity);
if ($this->nnoj > 0) echo "<br>Требуется владение колющим оружиием" . $this->wrap($this->nnoj); }
if ($this->ndubina > 0) echo "<br>Требуется владение дробящим оружием" . $this->wrap($this->ndubina); if ($this->need_intuition > 0) {
if ($this->ntopor > 0) echo "<br>Требуется владение рубящим оружием" . $this->wrap($this->ntopor); echo "<br>Требуется интуиция" . $this->wrap($this->need_intuition);
if ($this->nmech > 0) echo "<br>Требуется владение режущим оружием" . $this->wrap($this->nmech); }
if ($this->nsila > 0) echo "<br>Требуется сила" . $this->wrap($this->nsila); if ($this->need_endurance > 0) {
if ($this->nlovk > 0) echo "<br>Требуется ловкость" . $this->wrap($this->nlovk); echo "<br>Требуется выносливость" . $this->wrap($this->need_endurance);
if ($this->ninta > 0) echo "<br>Требуется интуиция" . $this->wrap($this->ninta); }
if ($this->nvinos > 0) echo "<br>Требуется выносливость" . $this->wrap($this->nvinos); if ($this->need_intelligence > 0) {
if ($this->nintel > 0) echo "<br>Требуется интеллект" . $this->wrap($this->nintel); echo "<br>Требуется интеллект" . $this->wrap($this->need_intelligence);
} }
if ($this->need_wisdom > 0) {
protected function printBonuses() echo "<br>Требуется мудрость" . $this->wrap($this->need_wisdom);
{ }
if ($this->gsila) echo "<br>Сила" . $this->wrap($this->gsila); if ($this->add_strength > 0) {
if ($this->glovk) echo "<br>Ловкость" . $this->wrap($this->glovk); echo "<br>Сила" . $this->wrap($this->add_strength);
if ($this->ginta) echo "<br>Интуиция" . $this->wrap($this->ginta); }
if ($this->gintel) echo "<br>Интеллект" . $this->wrap($this->gintel); if ($this->add_dexterity) {
if ($this->minu AND $this->maxu) echo "<br>Урон: {$this->minu} - {$this->maxu}"; echo "<br>Ловкость" . $this->wrap($this->add_dexterity);
if ($this->ghp) echo "<br>Здоровье" . $this->wrap($this->ghp); }
if ($this->gnoj) echo "<br>Владение колющим оружиием" . $this->wrap($this->gnoj); if ($this->add_intuition) {
if ($this->gdubina) echo "<br>Владение дробящим оружием" . $this->wrap($this->gdubina); echo "<br>Интуиция" . $this->wrap($this->add_intuition);
if ($this->gtopor) echo "<br>Владение рубящим оружием" . $this->wrap($this->gtopor); }
if ($this->gmech) echo "<br>Владение режущим оружием" . $this->wrap($this->gmech); if ($this->add_endurance) {
if ($this->gfire) echo "<br>Владение магией огня" . $this->wrap($this->gfire); echo "<br>Выносливость" . $this->wrap($this->add_endurance);
if ($this->gwater) echo "<br>Владение магией воды" . $this->wrap($this->gwater); }
if ($this->gair) echo "<br>Владение магией воздуха" . $this->wrap($this->gair); if ($this->add_intelligence) {
if ($this->gearth) echo "<br>Владение магией земли" . $this->wrap($this->gearth); echo "<br>Интеллект" . $this->wrap($this->add_intelligence);
if ($this->glight) echo "<br>Владение магией света" . $this->wrap($this->glight); }
if ($this->ggray) echo "<br>Владение магией серости" . $this->wrap($this->ggray); if ($this->add_wisdom) {
if ($this->gdark) echo "<br>Владение магией тьмы" . $this->wrap($this->gdark); echo "<br>Мудрость" . $this->wrap($this->add_wisdom);
if ($this->mfkrit) echo "<br>Шанс крита" . $this->wrap($this->mfkrit); }
if ($this->mfakrit) echo "<br>Шанс антикрита" . $this->wrap($this->mfakrit); if ($this->add_accuracy) {
if ($this->mfuvorot) echo "<br>Шанс уворота" . $this->wrap($this->mfuvorot); echo "<br>Точность" . $this->wrap($this->add_accuracy);
if ($this->mfauvorot) echo "<br>Шанс антиуворота" . $this->wrap($this->mfauvorot); }
if ($this->bron1) echo "<br>Броня головы" . $this->wrap($this->bron1); if ($this->add_evasion) {
if ($this->bron2) echo "<br>Броня корпуса" . $this->wrap($this->bron2); echo "<br>Увёртливость" . $this->wrap($this->add_evasion);
if ($this->bron3) echo "<br>Броня пояса" . $this->wrap($this->bron3); }
if ($this->bron4) echo "<br>Броня ног" . $this->wrap($this->bron4); if ($this->add_criticals) {
if ($this->magic AND $this->type != 12) { echo "<br>Шанс крита" . $this->wrap($this->add_criticals);
echo "<br>Магические свойства:"; }
if ($this->magic_name) echo "<br><i style='color: dimgray;'>{$this->magic_name}</i>"; if ($this->add_min_physical_damage && !$this->add_max_physical_damage) {
else echo "<br><i style='color: dimgray;'>Неопознанная магия</i>"; $damage = $this->add_min_physical_damage . " - " . $this->add_min_physical_damage;
if ($this->magic_img AND $this->type != 50) echo <<<IMG } elseif (!$this->add_min_physical_damage && $this->add_max_physical_damage) {
<br><img src="//{$_SERVER['SERVER_NAME']}/i/sh/{$this->magic_img}" class="item-wrap-normal"> $damage = $this->add_max_physical_damage . " - " . $this->add_max_physical_damage;
IMG; } elseif ($this->add_min_physical_damage && $this->add_max_physical_damage) {
$damage = $this->add_min_physical_damage . " - " . $this->add_max_physical_damage;
}
if ($damage) {
echo "Урон: " . $damage;
} }
} }
} }

View File

@ -4,9 +4,7 @@ class ShopItem extends Item
{ {
public function printInfo() public function printInfo()
{ {
parent::printBaseInfo(); parent::printAllInfo();
parent::printRequirements();
parent::printBonuses();
} }
public function buyItem($owner) public function buyItem($owner)

View File

@ -563,7 +563,7 @@ if (input::post('setshadow')) {
die(); die();
} }
if (input::get('edit')) { if (isset($_GET['edit'])) {
if (input::get('ups')) { if (input::get('ups')) {
addOnePoint(input::get('ups'), 'stat'); addOnePoint(input::get('ups'), 'stat');
@ -573,9 +573,9 @@ if (input::get('edit')) {
addOnePoint(input::get('upm'), 'mastery'); addOnePoint(input::get('upm'), 'mastery');
} }
if (input::get('drop')) { if (isset($_GET['drop'])) {
dropitem(input::get('drop')); $items = new DressedItems($_SESSION['uid']);
updstats(); $items->undressItem($_GET['drop']);
} }
if (input::get('dress')) { if (input::get('dress')) {