battles/classes/Battles/ShopItem.php

79 lines
3.2 KiB
PHP
Raw Normal View History

2019-01-11 20:26:10 +00:00
<?php
namespace Battles;
use Battles\Database\DBPDO;
2019-01-11 20:26:10 +00:00
class ShopItem extends Item
{
public function printInfo()
{
parent::printAllInfo();
2019-01-11 20:26:10 +00:00
}
public function buyItem($owner)
{
if ($owner) {
$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);
}
}
2019-01-11 20:26:10 +00:00
/**
* Для кнопок управления под картинкой предмета в зависимости от ситуации.
2019-01-11 20:26:10 +00:00
*/
public function printControls($shopType = false)
2019-01-11 20:26:10 +00:00
{
2019-02-15 15:00:01 +00:00
if ($shopType === 'marketput') {
echo <<<BTN
<form method="post">
<input placeholder="{$this->price}" name="cost">
<input type="hidden" name="putId" value="{$this->item_id}">
2019-02-15 15:00:01 +00:00
<br><input type="submit" name="putToMarket" value="ать в магазин">
</form>
BTN;
} else {
switch ($shopType) {
default:
$btnValue = "Купить за " . intval($this->price) . " кр.";
$btnLink = "/shop.php?buy={$this->item_id}&rnd=" . mt_rand();
2019-02-15 15:00:01 +00:00
break;
case 'sell':
$btnValue = "Продать";
$btnLink = "/shop.php?sell={$this->item_id}&rnd=" . mt_rand();
2019-02-15 15:00:01 +00:00
break;
case 'marketgetback':
$btnValue = "Снять с продажи";
$btnLink = "?back={$this->item_id}&rnd=" . mt_rand();
2019-02-15 15:00:01 +00:00
break;
2019-02-15 16:39:47 +00:00
case 'marketbuy':
2019-02-15 17:02:03 +00:00
$btnValue = "Купить за " . intval($this->setsale) . " кр.";
$btnLink = "?otdel={$this->item_type}&set={$this->item_id}&rnd=" . mt_rand();
2019-02-15 15:00:01 +00:00
break;
}
echo <<<BTN
2019-01-16 20:20:47 +00:00
<p><input type="button" style="background: darkgrey; border: 1px solid grey; border-radius: 2px;" value="{$btnValue}"
2019-01-14 16:42:45 +00:00
onclick="location='{$btnLink}'">
2019-01-11 20:26:10 +00:00
BTN;
2019-02-15 15:00:01 +00:00
}
2019-01-11 20:26:10 +00:00
}
}