diff --git a/classes/Battles/Nick.php b/classes/Battles/Nick.php
index 229afdc..89bcf7f 100644
--- a/classes/Battles/Nick.php
+++ b/classes/Battles/Nick.php
@@ -57,7 +57,7 @@ class Nick extends User
*/
public function full($showInvisibility = 0):string
{
- if ($showInvisibility && $this->getInvisibilityStatus()) {
+ if (!$showInvisibility && $this->getInvisibilityStatus()) {
return INVIS;
}
return $this->getAlignToNickname().$this->getClanToNickname().sprintf('%s [%s] ', $this->login, $this->level, $this->login);
diff --git a/classes/Battles/Shop.php b/classes/Battles/Shop.php
index 95a100a..1d22902 100644
--- a/classes/Battles/Shop.php
+++ b/classes/Battles/Shop.php
@@ -7,6 +7,7 @@ use Battles\Database\DBPDO;
class Shop
{
public const GENERAL_SHOP = 1;
+ public const BARTER_SHOP = 2;
public const CATEGORY_SALE_ITEMS = -1;
public static Shop $current;
public int $categoryType = 0;
@@ -20,14 +21,19 @@ class Shop
{
if ($this->categoryType) {
$stmt = DBPDO::$db->ofetchAll('select * from items inner join trade_offers on id = shop_item_id where shop_id = ? and shop_item_quantity !=0 and item_type = ?', [$this->shopId, $this->categoryType]);
+ $stmt2 = DBPDO::$db->ofetchAll('select * from inventory where on_sale != 0 and present is null and item_type = ?', $this->categoryType);
} else {
$stmt = DBPDO::$db->ofetchAll('select * from items inner join trade_offers on id = shop_item_id where shop_id = ? and shop_item_quantity !=0', $this->shopId);
+ $stmt2 = DBPDO::$db->ofetchAll('select * from inventory where on_sale != 0 and present is null');
}
$iteminfo = [];
foreach ($stmt as $item) {
$iteminfo[] = new ShopItem($item, 'buyshop');
}
+ foreach ($stmt2 as $item) {
+ $iteminfo[] = new ShopItem($item, 'buymarket');
+ }
return $this->strFromArr($iteminfo);
}
diff --git a/classes/Battles/ShopItem.php b/classes/Battles/ShopItem.php
index 214ad3f..fb37581 100644
--- a/classes/Battles/ShopItem.php
+++ b/classes/Battles/ShopItem.php
@@ -3,6 +3,7 @@
namespace Battles;
use Battles\Database\DBPDO;
+use Battles\Models\PresentsModel;
use Exceptions\GameException;
class ShopItem extends Item
@@ -13,7 +14,7 @@ class ShopItem extends Item
private const BUTTON = [
'setmarket' => 'Сдать в магазин',
'unsetmarket' => 'Снять с продажи',
- 'buymarket' => 'Совершить обмен',
+ 'buymarket' => 'Купить с рук',
'sellshop' => 'Продать',
'buyshop' => 'Купить',
];
@@ -53,6 +54,7 @@ SQL;
public static string $status = '';
private ?string $jsonBarterList;
private int $offerId;
+ private int $ownerId = 0;
public function __construct($row, $operationType = null)
{
@@ -63,9 +65,12 @@ SQL;
$this->price = $row->price ?? null;
$this->shop_item_quantity = $row->shop_item_quantity ?? null;
$this->item_id = $row->item_id ?? $row->id;
- if ($operationType === 'buyshop') {
- $this->offerId = $row->offer_id; // Ид позиции в магазине.
- $this->jsonBarterList = $row->barter_items_list_json;
+ if ($operationType === 'buyshop' || $operationType === 'buymarket') {
+ $this->offerId = $row->offer_id ?? 0; // Ид позиции в магазине.
+ $this->jsonBarterList = $row->barter_items_list_json ?? null;
+ }
+ if ($operationType === 'buymarket') {
+ $this->ownerId = $row->owner_id;
}
}
@@ -79,6 +84,10 @@ SQL;
if ($this->optype === 'sellshop') {
$str .= $this->getTextBasedOnPrice();
}
+ if ($this->optype === 'buymarket') {
+ $str .= $this->getBarterList();
+ $str .= '
Продавец: ' . Nick::id($this->ownerId)->full(1);
+ }
return $str;
}
@@ -247,6 +256,9 @@ SQL;
return '';
}
$str = $this->optype == 'setmarket' ? '' : '';
+ if ($this->optype === 'buymarket' && $this->ownerId === User::$current->getId()) {
+ $this->optype = 'unsetmarket';
+ }
$hiddenValue = $this->optype === 'buyshop' ? $this->offerId : $this->item_id;
$button_name = self::BUTTON[$this->optype];
return <<