Основные классы переехали на обёртку PDO. Плановое №16.

This commit is contained in:
lopar
2021-01-28 23:05:34 +02:00
parent 0099c235a7
commit 8402912098
22 changed files with 284 additions and 1940 deletions
+32 -24
View File
@@ -1,5 +1,7 @@
<?php
namespace Battles;
use Battles\Database\DBPDO;
class ShopItem extends Item
{
public function printInfo()
@@ -10,54 +12,61 @@ class ShopItem extends Item
public function buyItem($owner)
{
if ($owner) {
db::c()->query('
INSERT INTO `inventory` (`prototype`,`owner`,`name`,`type`,`massa`,`cost`,`img`,`maxdur`,`isrep`,`gsila`,`glovk`,`ginta`,`gintel`,
`ghp`,`gnoj`,`gtopor`,`gdubina`,`gmech`,`gfire`,`gwater`,`gair`,`gearth`,`glight`,`ggray`,`gdark`,
`needident`,`nsila`,`nlovk`,`ninta`,`nintel`,`nmudra`,`nvinos`,`nnoj`,`ntopor`,`ndubina`,`nmech`,
`nfire`,`nwater`,`nair`,`nearth`,`nlight`,`ngray`,`ndark`,`mfkrit`,`mfakrit`,`mfuvorot`,`mfauvorot`,
`bron1`,`bron2`,`bron3`,`bron4`,`maxu`,`minu`,`magic`,`nlevel`,`nalign`,`dategoden`,`goden`,`otdel`,
`artefact`, `koll`) VALUES (?i,?i,"?s",?i,?i,?i,"?s",?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,
?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,"?s",?i,?i)
', $this->id, $owner, $this->name, $this->type, $this->massa, $this->cost, $this->img, $this->maxdur, $this->isrep, $this->gsila, $this->glovk, $this->ginta, $this->gintel,
$this->ghp, $this->gnoj, $this->gtopor, $this->gdubina, $this->gmech, $this->gfire, $this->gwater, $this->gair, $this->gearth, $this->glight, $this->ggray, $this->gdark,
$this->needident, $this->nsila, $this->nlovk, $this->ninta, $this->nintel, $this->nmudra, $this->nvinos, $this->nnoj, $this->ntopor, $this->ndubina, $this->nmech,
$this->nfire, $this->nwater, $this->nair, $this->nearth, $this->nlight, $this->ngray, $this->ndark, $this->mfkrit, $this->mfakrit, $this->mfuvorot, $this->mfauvorot,
$this->bron1, $this->bron2, $this->bron3, $this->bron4, $this->maxu, $this->minu, $this->magic, $this->nlevel, $this->nalign, $this->dategoden, $this->goden, $this->razdel,
$this->artefact, $this->koll);
$db = new DBPDO();
$query = "INSERT INTO inventory (
owner_id, name, item_type, durability, price,
need_strength, need_dexterity, need_intuition,
need_endurance, need_intelligence, need_wisdom,
add_strength, add_dexterity, add_intuition,
add_endurance, add_intelligence, add_wisdom,
add_accuracy, add_evasion, add_criticals,
add_min_physical_damage, add_max_physical_damage,
image, weight)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$values = [
$owner, $this->name, $this->item_type, $this->durability, $this->price,
$this->need_strength, $this->need_dexterity, $this->need_intuition,
$this->need_endurance, $this->need_intelligence, $this->need_wisdom,
$this->add_strength, $this->add_dexterity, $this->add_intuition,
$this->add_endurance, $this->add_intelligence, $this->add_wisdom,
$this->add_accuracy, $this->add_evasion, $this->add_criticals,
$this->add_min_physical_damage, $this->add_max_physical_damage,
$this->image, $this->weight
];
$db->execute($query, $values);
}
}
/**
* Для кнопок управления под картинкой прелмета в зависимости от ситуации.
* Для кнопок управления под картинкой предмета в зависимости от ситуации.
*/
public function printControls($shopType = false)
{
if ($shopType === 'marketput') {
echo <<<BTN
<form method="post">
<input placeholder="{$this->cost}" name="cost">
<input type="hidden" name="putId" value="{$this->id}">
<input placeholder="{$this->price}" name="cost">
<input type="hidden" name="putId" value="{$this->item_id}">
<br><input type="submit" name="putToMarket" value="Cдать в магазин">
</form>
BTN;
} else {
switch ($shopType) {
default:
$btnValue = "Купить за " . intval($this->cost) . " кр.";
$btnLink = "/shop.php?buy={$this->id}&rnd=" . mt_rand();
$btnValue = "Купить за " . intval($this->price) . " кр.";
$btnLink = "/shop.php?buy={$this->item_id}&rnd=" . mt_rand();
break;
case 'sell':
$btnValue = "Продать";
$btnLink = "/shop.php?sell={$this->id}&rnd=" . mt_rand();
$btnLink = "/shop.php?sell={$this->item_id}&rnd=" . mt_rand();
break;
case 'marketgetback':
$btnValue = "Снять с продажи";
$btnLink = "?back={$this->id}&rnd=" . mt_rand();
$btnLink = "?back={$this->item_id}&rnd=" . mt_rand();
break;
case 'marketbuy':
$btnValue = "Купить за " . intval($this->setsale) . " кр.";
$btnLink = "?otdel={$this->otdel}&set={$this->id}&rnd=" . mt_rand();
$btnLink = "?otdel={$this->item_type}&set={$this->item_id}&rnd=" . mt_rand();
break;
}
@@ -65,7 +74,6 @@ BTN;
<p><input type="button" style="background: darkgrey; border: 1px solid grey; border-radius: 2px;" value="{$btnValue}"
onclick="location='{$btnLink}'">
BTN;
if ($this->count > 0) echo "<br><small>В наличии: {$this->count} штук</small>";
}
}
}