Compare commits
2 Commits
7434f28fa6
...
d2c8c8d7d5
Author | SHA1 | Date | |
---|---|---|---|
|
d2c8c8d7d5 | ||
|
4cf370327f |
@ -27,7 +27,7 @@ class InventoryItem extends Item
|
|||||||
|
|
||||||
public function printInfo()
|
public function printInfo()
|
||||||
{
|
{
|
||||||
parent::printAllInfo();
|
echo $this->getAllInfo();
|
||||||
if ($this->present) {
|
if ($this->present) {
|
||||||
echo "<p style='color: maroon; font-style: italic'>Это подарок от $this->present. Вы не можете передать его кому-либо ещё.</p>";
|
echo "<p style='color: maroon; font-style: italic'>Это подарок от $this->present. Вы не можете передать его кому-либо ещё.</p>";
|
||||||
}
|
}
|
||||||
@ -48,9 +48,8 @@ IMG;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function printControls()
|
public function printControls(){
|
||||||
{
|
// Для кнопок управления под картинкой.
|
||||||
/* Тут будут кнопки под картинкой. */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function dressStatsChecks(): ?string
|
private function dressStatsChecks(): ?string
|
||||||
@ -130,14 +129,9 @@ IMG;
|
|||||||
return $error ?? true;
|
return $error ?? true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function destroyItem($itemId)
|
||||||
* @param $itemId
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function destroyItem($itemId): bool
|
|
||||||
{
|
{
|
||||||
return DBPDO::INIT()->execute('delete from inventory where dressed_slot = 0 and owner_id = ? and item_id = ?', [$_SESSION['uid'], $itemId]);
|
DBPDO::INIT()->execute('delete from inventory where dressed_slot = 0 and owner_id = ? and item_id = ?', [$_SESSION['uid'], $itemId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Надеюсь, временная заглушка, которая объединяет get_meshok() и другую выдачу одной строкой.
|
/** Надеюсь, временная заглушка, которая объединяет get_meshok() и другую выдачу одной строкой.
|
||||||
|
@ -102,6 +102,14 @@ class Item
|
|||||||
$this->typename = 'Хлам';
|
$this->typename = 'Хлам';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->item_cost = $this->calculateItemCost();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Рассчёт стоимости предмета в зависимости от его характеристик.
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
private function calculateItemCost(): int
|
||||||
|
{
|
||||||
$sum_stats =
|
$sum_stats =
|
||||||
$this->add_strength +
|
$this->add_strength +
|
||||||
$this->add_dexterity +
|
$this->add_dexterity +
|
||||||
@ -121,8 +129,7 @@ class Item
|
|||||||
$mods_cost_modifier = 2 + floor($sum_mods / 50);
|
$mods_cost_modifier = 2 + floor($sum_mods / 50);
|
||||||
$damage_cost_modifier = 1 + floor($sum_damage / 100);
|
$damage_cost_modifier = 1 + floor($sum_damage / 100);
|
||||||
$result = intval($sum_stats * $stats_cost_modifier + $sum_mods * $mods_cost_modifier + $sum_damage * $damage_cost_modifier);
|
$result = intval($sum_stats * $stats_cost_modifier + $sum_mods * $mods_cost_modifier + $sum_damage * $damage_cost_modifier);
|
||||||
|
return $result < 1 ? 1 : $result;
|
||||||
$this->item_cost = $result < 1 ? 1 : $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function wrap(int $number): string
|
protected function wrap(int $number): string
|
||||||
@ -134,50 +141,51 @@ class Item
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function printAllInfo()
|
public function getAllInfo(): string
|
||||||
{
|
{
|
||||||
$needsLines = [
|
$needsLines = [
|
||||||
"сила" => $this->need_strength,
|
'сила' => $this->need_strength,
|
||||||
"ловкость" => $this->need_dexterity,
|
'ловкость' => $this->need_dexterity,
|
||||||
"интуиция" => $this->need_intuition,
|
'интуиция' => $this->need_intuition,
|
||||||
"выносливость" => $this->need_endurance,
|
'выносливость' => $this->need_endurance,
|
||||||
"интеллект" => $this->need_intelligence,
|
'интеллект' => $this->need_intelligence,
|
||||||
"мудрость" => $this->need_wisdom,
|
'мудрость' => $this->need_wisdom,
|
||||||
];
|
];
|
||||||
$addsLines = [
|
$addsLines = [
|
||||||
"Сила" => $this->add_strength,
|
'Сила' => $this->add_strength,
|
||||||
"Ловкость" => $this->add_dexterity,
|
'Ловкость' => $this->add_dexterity,
|
||||||
"Интуиция" => $this->add_intuition,
|
'Интуиция' => $this->add_intuition,
|
||||||
"Выносливость" => $this->add_endurance,
|
'Выносливость' => $this->add_endurance,
|
||||||
"Интеллект" => $this->add_intelligence,
|
'Интеллект' => $this->add_intelligence,
|
||||||
"Мудрость" => $this->add_wisdom,
|
'Мудрость' => $this->add_wisdom,
|
||||||
"Точность" => $this->add_accuracy,
|
'Точность' => $this->add_accuracy,
|
||||||
"Увёртливость" => $this->add_evasion,
|
'Увёртливость' => $this->add_evasion,
|
||||||
"Шанс крита" => $this->add_criticals,
|
'Шанс крита' => $this->add_criticals,
|
||||||
];
|
];
|
||||||
echo "<b>$this->name</b> (Масса: $this->weight)";
|
$str = "<b>$this->name</b> (Масса: $this->weight)";
|
||||||
echo "<br> Стоимость: " . $this->item_cost;
|
$str .= '<br> Стоимость: ' . $this->item_cost;
|
||||||
echo "<br> Долговечность: " . $this->durability;
|
$str .= '<br> Долговечность: ' . $this->durability;
|
||||||
echo "<br><em>$this->typename</em><br>";
|
$str .= "<br><em>$this->typename</em><br>";
|
||||||
foreach ($needsLines as $stat => $value) {
|
foreach ($needsLines as $stat => $value) {
|
||||||
if ($value > 0) {
|
if ($value > 0) {
|
||||||
echo "<br>Требуется $stat" . $this->wrap($value);
|
$str .= "<br>Требуется $stat" . $this->wrap($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($addsLines as $stat => $value) {
|
foreach ($addsLines as $stat => $value) {
|
||||||
if ($value) {
|
if ($value) {
|
||||||
echo "<br>$stat" . $this->wrap($value);
|
$str .= "<br>$stat" . $this->wrap($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($this->add_min_physical_damage && !$this->add_max_physical_damage) {
|
if ($this->add_min_physical_damage && !$this->add_max_physical_damage) {
|
||||||
$damage = $this->add_min_physical_damage . " - " . $this->add_min_physical_damage;
|
$damage = $this->add_min_physical_damage . ' - ' . $this->add_min_physical_damage;
|
||||||
} elseif (!$this->add_min_physical_damage && $this->add_max_physical_damage) {
|
} elseif (!$this->add_min_physical_damage && $this->add_max_physical_damage) {
|
||||||
$damage = $this->add_max_physical_damage . " - " . $this->add_max_physical_damage;
|
$damage = $this->add_max_physical_damage . ' - ' . $this->add_max_physical_damage;
|
||||||
} elseif ($this->add_min_physical_damage && $this->add_max_physical_damage) {
|
} elseif ($this->add_min_physical_damage && $this->add_max_physical_damage) {
|
||||||
$damage = $this->add_min_physical_damage . " - " . $this->add_max_physical_damage;
|
$damage = $this->add_min_physical_damage . ' - ' . $this->add_max_physical_damage;
|
||||||
}
|
}
|
||||||
if (isset($damage)) {
|
if (isset($damage)) {
|
||||||
echo "<br>Урон: " . $damage;
|
$str .= '<br>Урон: ' . $damage;
|
||||||
}
|
}
|
||||||
|
return $str;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -49,6 +49,7 @@ SQL;
|
|||||||
private $optype;
|
private $optype;
|
||||||
private ?int $shop_item_quantity;
|
private ?int $shop_item_quantity;
|
||||||
private ?int $price;
|
private ?int $price;
|
||||||
|
public static string $status = '';
|
||||||
|
|
||||||
public function __construct($row, $operationType = null)
|
public function __construct($row, $operationType = null)
|
||||||
{
|
{
|
||||||
@ -61,11 +62,12 @@ SQL;
|
|||||||
$this->item_id = $row->item_id ?? $row->id;
|
$this->item_id = $row->item_id ?? $row->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function printInfo()
|
public function printInfo(): string
|
||||||
{
|
{
|
||||||
$this->printAllInfo();
|
//$this->printAllInfo();
|
||||||
|
$str = $this->getAllInfo();
|
||||||
if ($this->optype === 'buyshop' && $this->shop_item_quantity > 0 && $this->shop_item_quantity < 20) {
|
if ($this->optype === 'buyshop' && $this->shop_item_quantity > 0 && $this->shop_item_quantity < 20) {
|
||||||
echo "<div style='margin-top: 9px; font-style: italic;'>На складе осталось $this->shop_item_quantity единиц товара!</div>";
|
$str .= "<div style='margin-top: 9px; font-style: italic;'>На складе осталось $this->shop_item_quantity единиц товара!</div>";
|
||||||
}
|
}
|
||||||
if ($this->optype === 'sellshop') {
|
if ($this->optype === 'sellshop') {
|
||||||
if ($this->getSellPriceMean() < 50) {
|
if ($this->getSellPriceMean() < 50) {
|
||||||
@ -79,36 +81,37 @@ SQL;
|
|||||||
} else {
|
} else {
|
||||||
$goods = 'это превосходное изделие';
|
$goods = 'это превосходное изделие';
|
||||||
}
|
}
|
||||||
echo "<div style='margin-top: 9px; font-style: italic;'>В среднем за $goods можно выручить <span class='success'>{$this->getSellPriceMean()}</span> кр.</div>";
|
$str .= "<div style='margin-top: 9px; font-style: italic;'>В среднем за $goods можно выручить <span class='success'>{$this->getSellPriceMean()}</span> кр.</div>";
|
||||||
}
|
}
|
||||||
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function printImage()
|
public function printImage(): string
|
||||||
{
|
{
|
||||||
if (!$this->image) {
|
if (!$this->image) {
|
||||||
$this->image = 'noitem.png';
|
$this->image = 'noitem.png';
|
||||||
}
|
}
|
||||||
echo "<img src='/i/sh/$this->image' class='item-wrap-normal' alt=''>";
|
return "<img src='/i/sh/$this->image' class='item-wrap-normal' alt=''>";
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo наличка после покупки отображается с задержкой.
|
//todo наличка после покупки отображается с задержкой.
|
||||||
public static function buyItem($id, User $buyer): string
|
public static function buyItem($id, User $buyer)
|
||||||
{
|
{
|
||||||
$db = new DBPDO();
|
$db = new DBPDO();
|
||||||
$check = $db->ofetch("select * from trade_offers where shop_item_id = ?", $id);
|
$check = $db->ofetch("select * from trade_offers where shop_item_id = ?", $id);
|
||||||
if (empty($check->shop_item_quantity) || empty($check->shop_item_id)) {
|
if (empty($check->shop_item_quantity) || empty($check->shop_item_id)) {
|
||||||
return self::NO_ITEMS_IN_STOCK;
|
self::$status = self::NO_ITEMS_IN_STOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO БАРТЕР!
|
// TODO БАРТЕР!
|
||||||
if (isset($check->barter_item_list_json)) {
|
if (isset($check->barter_item_list_json)) {
|
||||||
echo "Работаем по бартеру!";
|
self::$status = "Работаем по бартеру!";
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->execute(self::BUY_QUERY, [$buyer->getId(), $check->shop_item_id]);
|
$db->execute(self::BUY_QUERY, [$buyer->getId(), $check->shop_item_id]);
|
||||||
$item = $db->ofetch("select item_id, name, price from inventory where item_id = ?", $db->lastInsertId());
|
$item = $db->ofetch("select item_id, name, price from inventory where item_id = ?", $db->lastInsertId());
|
||||||
if (empty($item->item_id) || empty($item->name)) {
|
if (empty($item->item_id) || empty($item->name)) {
|
||||||
return 'Запрос в базу не прошёл.';
|
self::$status = 'Запрос в базу не прошёл.';
|
||||||
} else {
|
} else {
|
||||||
$user = new User($_SESSION['uid']);
|
$user = new User($_SESSION['uid']);
|
||||||
// Если не хватает налички, снимаем с банка с комиссией.
|
// Если не хватает налички, снимаем с банка с комиссией.
|
||||||
@ -117,14 +120,12 @@ SQL;
|
|||||||
$bank = new Bank($buyer->getId());
|
$bank = new Bank($buyer->getId());
|
||||||
$bank->withdrawMoney($item->price);
|
$bank->withdrawMoney($item->price);
|
||||||
} catch (GameException $e) {
|
} catch (GameException $e) {
|
||||||
echo 'Банковская ошибка!';
|
self::$status = 'Банковская ошибка! ' . self::NO_MONEY;
|
||||||
return self::NO_MONEY;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$user->setMoney($user->getMoney() - $item->price);
|
$user->setMoney($user->getMoney() - $item->price);
|
||||||
$user->saveMoney();
|
$user->saveMoney();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($check->shop_item_quantity != -1) {
|
if ($check->shop_item_quantity != -1) {
|
||||||
@ -133,10 +134,10 @@ SQL;
|
|||||||
|
|
||||||
$deloText = $buyer->getLogin() . " купил товар «" . $item->name . "» id:(" . $item->item_id . ") в магазине за " . $item->price . ".";
|
$deloText = $buyer->getLogin() . " купил товар «" . $item->name . "» id:(" . $item->item_id . ") в магазине за " . $item->price . ".";
|
||||||
GameLogs::addUserLog($buyer->getId(), $deloText);
|
GameLogs::addUserLog($buyer->getId(), $deloText);
|
||||||
return "Предмет " . $item->name . " куплен за " . $item->price . ".";
|
self::$status = "Предмет " . $item->name . " куплен за " . $item->price . ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function sellItem($id, User $seller, $bankTrade = 0): string
|
public static function sellItem($id, User $seller, $bankTrade = 0)
|
||||||
{
|
{
|
||||||
$db = new DBPDO();
|
$db = new DBPDO();
|
||||||
$item = $db->ofetch('select * from inventory where item_id = ?', $id);
|
$item = $db->ofetch('select * from inventory where item_id = ?', $id);
|
||||||
@ -154,11 +155,10 @@ SQL;
|
|||||||
$deloText = "{$seller->getLogin()} продал товар «{$sellingItemName}» id:($id) в магазине за $sellingPrice кр.";
|
$deloText = "{$seller->getLogin()} продал товар «{$sellingItemName}» id:($id) в магазине за $sellingPrice кр.";
|
||||||
GameLogs::addUserLog($seller->getId(), $deloText);
|
GameLogs::addUserLog($seller->getId(), $deloText);
|
||||||
if ($sellingPrice == 0) {
|
if ($sellingPrice == 0) {
|
||||||
$status = "После длительных и изнурительных торгов вы плюнули на всё и просто подарили ваш «{$sellingItemName}» торговцу.";
|
self::$status = "После длительных и изнурительных торгов вы плюнули на всё и просто подарили ваш «{$sellingItemName}» торговцу.";
|
||||||
} else {
|
} else {
|
||||||
$status = "Вы продали «{$sellingItemName}» за $sellingPrice кр.";
|
self::$status = "Вы продали «{$sellingItemName}» за $sellingPrice кр.";
|
||||||
}
|
}
|
||||||
return $status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Подчсчёт средней суммы продажи.
|
/** Подчсчёт средней суммы продажи.
|
||||||
@ -177,19 +177,20 @@ SQL;
|
|||||||
/**
|
/**
|
||||||
* Для кнопок управления под картинкой предмета в зависимости от ситуации.
|
* Для кнопок управления под картинкой предмета в зависимости от ситуации.
|
||||||
*/
|
*/
|
||||||
public function printControls()
|
public function printControls(): string
|
||||||
{
|
{
|
||||||
if (in_array($this->optype, ['setmarket', 'unsetmarket', 'buymarket', 'sellshop', 'buyshop',])) {
|
if (!in_array($this->optype, ['setmarket', 'unsetmarket', 'buymarket', 'sellshop', 'buyshop',])) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
$str = $this->optype == 'setmarket' ? '<input placeholder=" ' . $this->price . ' " name="cost">' : '';
|
$str = $this->optype == 'setmarket' ? '<input placeholder=" ' . $this->price . ' " name="cost">' : '';
|
||||||
$button_name = self::BUTTON[$this->optype];
|
$button_name = self::BUTTON[$this->optype];
|
||||||
echo <<<FORM
|
return <<<FORM
|
||||||
<form method="post">$str
|
<form method="post">$str
|
||||||
<input type="hidden" name="itemId" value="$this->item_id">
|
<input type="hidden" name="itemId" value="$this->item_id">
|
||||||
<br><input type="submit" name="$this->optype" value="$button_name">
|
<br><input type="submit" name="$this->optype" value="$button_name">
|
||||||
</form>
|
</form>
|
||||||
FORM;
|
FORM;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
|
@ -9,6 +9,11 @@
|
|||||||
use Battles\Database\DBPDO;
|
use Battles\Database\DBPDO;
|
||||||
use Battles\User;
|
use Battles\User;
|
||||||
|
|
||||||
|
include_once 'classes/Database/db.php';
|
||||||
|
include_once 'classes/Database/Mysql.php';
|
||||||
|
include_once 'classes/Database/Statement.php';
|
||||||
|
include_once 'classes/Database/Exception.php';
|
||||||
|
|
||||||
ini_set('display_errors', 'On');
|
ini_set('display_errors', 'On');
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
const GAMEDOMAIN = "battles.lan";
|
const GAMEDOMAIN = "battles.lan";
|
||||||
|
BIN
i/1green_.gif
Before Width: | Height: | Size: 37 B |
BIN
i/1yellow.gif
Before Width: | Height: | Size: 37 B |
Before Width: | Height: | Size: 28 KiB |
BIN
i/Mherz.gif
Before Width: | Height: | Size: 298 B |
BIN
i/aaxe5.gif
Before Width: | Height: | Size: 1.3 KiB |
BIN
i/achieve.gif
Before Width: | Height: | Size: 13 KiB |
BIN
i/ages.jpg
Before Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 96 KiB |
BIN
i/align_3.png
Before Width: | Height: | Size: 526 B |
BIN
i/align_4.png
Before Width: | Height: | Size: 519 B |
BIN
i/align_5.png
Before Width: | Height: | Size: 532 B |
BIN
i/align_6.png
Before Width: | Height: | Size: 507 B |
BIN
i/align_7.png
Before Width: | Height: | Size: 520 B |
BIN
i/amolot1.gif
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.3 KiB |
BIN
i/armor53.gif
Before Width: | Height: | Size: 2.4 KiB |
BIN
i/arrow3.gif
Before Width: | Height: | Size: 124 B |
BIN
i/artefact1.gif
Before Width: | Height: | Size: 203 B |
Before Width: | Height: | Size: 43 B |
BIN
i/bagr.gif
Before Width: | Height: | Size: 1.8 KiB |
BIN
i/bank.jpg
Before Width: | Height: | Size: 33 KiB |
BIN
i/blink.gif
Before Width: | Height: | Size: 656 B |
BIN
i/boots15.gif
Before Width: | Height: | Size: 1.8 KiB |
BIN
i/bug1.gif
Before Width: | Height: | Size: 952 B |
Before Width: | Height: | Size: 49 B |
Before Width: | Height: | Size: 95 B |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 107 B |
Before Width: | Height: | Size: 106 B |
Before Width: | Height: | Size: 52 B |
Before Width: | Height: | Size: 80 B |
Before Width: | Height: | Size: 82 B |
Before Width: | Height: | Size: 985 B |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 574 B |
Before Width: | Height: | Size: 766 B |
Before Width: | Height: | Size: 54 B |
Before Width: | Height: | Size: 551 B |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 663 B |
Before Width: | Height: | Size: 520 B |
Before Width: | Height: | Size: 568 B |
Before Width: | Height: | Size: 516 B |
Before Width: | Height: | Size: 573 B |
Before Width: | Height: | Size: 567 B |
Before Width: | Height: | Size: 571 B |
Before Width: | Height: | Size: 626 B |
Before Width: | Height: | Size: 570 B |
Before Width: | Height: | Size: 483 B |
Before Width: | Height: | Size: 407 B |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 693 B |
Before Width: | Height: | Size: 566 B |
Before Width: | Height: | Size: 677 B |
Before Width: | Height: | Size: 570 B |
Before Width: | Height: | Size: 671 B |
Before Width: | Height: | Size: 576 B |
Before Width: | Height: | Size: 720 B |
Before Width: | Height: | Size: 591 B |
Before Width: | Height: | Size: 653 B |
Before Width: | Height: | Size: 599 B |
Before Width: | Height: | Size: 720 B |
Before Width: | Height: | Size: 587 B |
Before Width: | Height: | Size: 508 B |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 52 B |
Before Width: | Height: | Size: 98 B |
Before Width: | Height: | Size: 99 B |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 714 B |
Before Width: | Height: | Size: 635 B |
Before Width: | Height: | Size: 777 B |
Before Width: | Height: | Size: 704 B |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 841 B |