Compare commits
3 Commits
5714ab83f3
...
2b1287397d
Author | SHA1 | Date | |
---|---|---|---|
|
2b1287397d | ||
|
7c7ac67ddb | ||
|
326d93f259 |
@ -1,30 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Battles;
|
||||
class Item
|
||||
{
|
||||
protected $item_id;
|
||||
protected $name;
|
||||
protected $item_type;
|
||||
protected $durability;
|
||||
protected $need_strength;
|
||||
protected $need_dexterity;
|
||||
protected $need_intuition;
|
||||
protected $need_endurance;
|
||||
protected $need_intelligence;
|
||||
protected $need_wisdom;
|
||||
protected $add_strength;
|
||||
protected $add_dexterity;
|
||||
protected $add_intuition;
|
||||
protected $add_endurance;
|
||||
protected $add_intelligence;
|
||||
protected $add_wisdom;
|
||||
protected $add_accuracy;
|
||||
protected $add_evasion;
|
||||
protected $add_criticals;
|
||||
protected $add_min_physical_damage;
|
||||
protected $add_max_physical_damage;
|
||||
protected $weight;
|
||||
protected $image;
|
||||
protected int $item_id;
|
||||
protected string $name = '';
|
||||
protected int $item_type = self::ITEM_TYPE_TRASH;
|
||||
protected int $durability = 0;
|
||||
protected int $need_strength = 0;
|
||||
protected int $need_dexterity = 0;
|
||||
protected int $need_intuition = 0;
|
||||
protected int $need_endurance = 0;
|
||||
protected int $need_intelligence = 0;
|
||||
protected int $need_wisdom = 0;
|
||||
protected int $add_strength = 0;
|
||||
protected int $add_dexterity = 0;
|
||||
protected int $add_intuition = 0;
|
||||
protected int $add_endurance = 0;
|
||||
protected int $add_intelligence = 0;
|
||||
protected int $add_wisdom = 0;
|
||||
protected int $add_accuracy = 0;
|
||||
protected int $add_evasion = 0;
|
||||
protected int $add_criticals = 0;
|
||||
protected int $add_min_physical_damage = 0;
|
||||
protected int $add_max_physical_damage = 0;
|
||||
protected int $weight = 0;
|
||||
protected string $image = '';
|
||||
protected int $item_cost = 0;
|
||||
public const ITEM_TYPES_ALLOWED_IN_SLOTS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
||||
public const ITEM_TYPE_HELMET = 1;
|
||||
public const ITEM_TYPE_ARMOR = 2;
|
||||
@ -39,7 +41,7 @@ class Item
|
||||
public const ITEM_TYPE_CONSUMABLE = 20;
|
||||
public const ITEM_TYPE_OTHER = 50;
|
||||
public const ITEM_TYPE_TRASH = 100;
|
||||
private $typename;
|
||||
private string $typename;
|
||||
|
||||
/**
|
||||
* Item constructor.
|
||||
@ -99,6 +101,28 @@ class Item
|
||||
default:
|
||||
$this->typename = 'Хлам';
|
||||
}
|
||||
|
||||
$sum_stats =
|
||||
$this->add_strength +
|
||||
$this->add_dexterity +
|
||||
$this->add_intuition +
|
||||
$this->add_endurance +
|
||||
$this->add_intelligence +
|
||||
$this->add_wisdom;
|
||||
$sum_mods =
|
||||
$this->add_accuracy +
|
||||
$this->add_evasion +
|
||||
$this->add_criticals;
|
||||
$sum_damage =
|
||||
$this->add_min_physical_damage +
|
||||
$this->add_max_physical_damage;
|
||||
// За каждые N параметров повышаем множитель на 1 чтобы цена пропрорционально росла.
|
||||
$stats_cost_modifier = 5 + floor($sum_stats / 10);
|
||||
$mods_cost_modifier = 2 + floor($sum_mods / 50);
|
||||
$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);
|
||||
|
||||
$this->item_cost = $result < 1 ? 1 : $result;
|
||||
}
|
||||
|
||||
protected function wrap(int $number): string
|
||||
@ -132,6 +156,7 @@ class Item
|
||||
"Шанс крита" => $this->add_criticals,
|
||||
];
|
||||
echo "<b>$this->name</b> (Масса: $this->weight)";
|
||||
echo "<br> Стоимость: " . $this->item_cost;
|
||||
echo "<br> Долговечность: " . $this->durability;
|
||||
echo "<br><em>$this->typename</em><br>";
|
||||
foreach ($needsLines as $stat => $value) {
|
||||
|
@ -92,12 +92,12 @@ class ShopItem extends Item
|
||||
}
|
||||
}
|
||||
|
||||
public function printImage(): string
|
||||
public function printImage()
|
||||
{
|
||||
if (!$this->image) {
|
||||
$this->image = 'noitem.png';
|
||||
}
|
||||
return "<img src='/i/sh/$this->image' class='item-wrap-normal' alt=''>";
|
||||
echo "<img src='/i/sh/$this->image' class='item-wrap-normal' alt=''>";
|
||||
}
|
||||
|
||||
public static function buyItem($id, User $buyer): string
|
||||
@ -142,15 +142,6 @@ class ShopItem extends Item
|
||||
return "Предмет " . $boughtItemName . " куплен за " . $boughtItemPrice . " банкнот.";
|
||||
}
|
||||
|
||||
//TODO не пишутся логи продажи!
|
||||
|
||||
/** TODO
|
||||
* Notice: Undefined index: shopsell in /volume2/web/battles/classes/Battles/Bank.php on line 199 Call Stack: 0.0003 430192
|
||||
* 1. {main}() /volume2/web/battles/shop.php:0 0.0051 966928
|
||||
* 2. Battles\ShopItem::sellItem() /volume2/web/battles/shop.php:21 0.1067 998536
|
||||
* 3. Battles\Bank::setBankMoney() /volume2/web/battles/classes/Battles/ShopItem.php:162
|
||||
* Не отработал запрос в БД в файле /volume2/web/battles/classes/Battles/GameLogs.php(20)
|
||||
*/
|
||||
public static function sellItem($id, User $seller, $bankTrade = 0): string
|
||||
{
|
||||
$db = new DBPDO();
|
||||
@ -162,7 +153,7 @@ class ShopItem extends Item
|
||||
if ($bankTrade) {
|
||||
$bank = new Bank($seller->getId());
|
||||
$bank->setMoney($bank->getMoney() + $sellingPrice);
|
||||
Bank::setBankMoney($bank->getMoney(), $seller->getId(), 'shopsell');
|
||||
Bank::setBankMoney($bank->getMoney(), $seller->getId(), 'sellShop');
|
||||
} else {
|
||||
$db->execute('update users set money = money - ? where id = ?', [$sellingPrice, $_SESSION['uid']]);
|
||||
}
|
||||
@ -183,7 +174,7 @@ class ShopItem extends Item
|
||||
{
|
||||
if ($this->price) {
|
||||
$arr = range(0, $this->price / 2);
|
||||
return array_sum($arr) / sizeof($arr);
|
||||
return array_sum($arr) / count($arr);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class UserStats extends User
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStat($stat_name, $isMainWindow = 0): string
|
||||
public function getStat($stat_name, int $isMainWindow = 0): string
|
||||
{
|
||||
if (!in_array($stat_name, ['strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'])) {
|
||||
return self::ERROR_STAT_UNKNOWN;
|
||||
|
85
shop.php
85
shop.php
@ -2,7 +2,6 @@
|
||||
|
||||
use Battles\Bank;
|
||||
use Battles\Database\DBPDO;
|
||||
use Battles\GameLogs;
|
||||
use Battles\Item;
|
||||
use Battles\ShopItem;
|
||||
use Battles\Template;
|
||||
@ -99,49 +98,113 @@ Template::header('Магазин');
|
||||
background-color: #ccc;
|
||||
display: block;
|
||||
}
|
||||
|
||||
a.sell {
|
||||
background-color: #cdc;
|
||||
}
|
||||
|
||||
a.alltypes {
|
||||
background-color: #ccd;
|
||||
}
|
||||
|
||||
.status {
|
||||
color: darkgreen;
|
||||
background: #afa;
|
||||
}
|
||||
|
||||
table.shop {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
table.shop > tbody > tr > td {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
table.shop > tbody > tr > td:nth-child(1) {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
table.shop > tbody > tr > td:nth-child(2) {
|
||||
width: 280px;
|
||||
}
|
||||
|
||||
table.shop table {
|
||||
width: 100%;
|
||||
border-collapse: separate;
|
||||
border-spacing: 1px;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
table.shop table tr {
|
||||
background-color: #C7C7C7;
|
||||
}
|
||||
|
||||
table.shop table td {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
table.shop table tr:nth-child(even) {
|
||||
background-color: #D5D5D5;
|
||||
}
|
||||
|
||||
table.shop table td:nth-child(1) {
|
||||
width: 150px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
table.shop table td:nth-child(2) {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
h3 + div {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
table.shop strong span:last-child {
|
||||
color: darkgreen;
|
||||
}
|
||||
|
||||
hr + div {
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
</style>
|
||||
<h1>Государственный магазин</h1>
|
||||
<a href=# onclick=hrefToFrame('city.php?cp')> ← выйти на Центральную площадь</a>
|
||||
<div class="status"><?= $status ?></div>
|
||||
<table style="width: 100%; border-collapse: collapse; border-spacing: 0; padding: 4px;">
|
||||
<table class="shop">
|
||||
<tr>
|
||||
<td style="vertical-align: top; text-align: left;">
|
||||
<td>
|
||||
<h3><?= $shopCategoryType ?></h3>
|
||||
<?php if ($saleItems): ?>
|
||||
<div style="text-align: center;">Вы можете продать ваши предметы за сущие копейки.</div>
|
||||
<div>Вы можете продать ваши предметы за сущие копейки.</div>
|
||||
<?php endif; ?>
|
||||
<!--Магазин-->
|
||||
<table class="zebra" style="width: 100%; border-collapse: separate; border-spacing: 1px; padding: 2px;">
|
||||
<table>
|
||||
<?php
|
||||
foreach ($iteminfo as $ii) {
|
||||
if ($ii->getItemType() != $shopCategoryTypeNumber && $shopCategoryTypeNumber != 'sale') {
|
||||
continue;
|
||||
}
|
||||
echo "<tr><td style='width: 150px; text-align: center; padding: 5px;'>";
|
||||
echo $ii->printImage();
|
||||
echo "<tr><td>";
|
||||
$ii->printImage();
|
||||
$ii->printControls();
|
||||
echo "<td style='vertical-align: top; padding: 5px;'>";
|
||||
echo "<td>";
|
||||
$ii->printInfo();
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<td style="width: 280px; vertical-align: top;">
|
||||
<td>
|
||||
<strong>
|
||||
Масса всех ваших вещей: <?= getItemsMassaInfo() ?> <br>
|
||||
У вас в банке: <span style="color: darkgreen;"><?= $bank->getMoney() ?></span> банкнот.
|
||||
У вас в банке: <span><?= $bank->getMoney() ?></span> банкнот.
|
||||
</strong>
|
||||
<hr>
|
||||
<div style="text-align: center; font-weight: bold;">Отделы магазина</div>
|
||||
<div>Отделы магазина</div>
|
||||
<a class="waretype" href="?otdel=6&rnd=<?= mt_rand() ?>">Оружие</a>
|
||||
<a class="waretype" href="?otdel=1&rnd=<?= mt_rand() ?>">Шлемы</a>
|
||||
<a class="waretype" href="?otdel=2&rnd=<?= mt_rand() ?>">Броня</a>
|
||||
|
Loading…
Reference in New Issue
Block a user