Compare commits

..

No commits in common. "2b1287397db4838087bed2d58c0939d0a1aa7896" and "5714ab83f3cfc2e21fe20df06d7648f100098797" have entirely different histories.

4 changed files with 58 additions and 137 deletions

View File

@ -1,33 +1,31 @@
<?php <?php
namespace Battles; namespace Battles;
class Item class Item
{ {
protected int $item_id; protected $item_id;
protected string $name = ''; protected $name;
protected int $item_type = self::ITEM_TYPE_TRASH; protected $item_type;
protected int $durability = 0; protected $durability;
protected int $need_strength = 0; protected $need_strength;
protected int $need_dexterity = 0; protected $need_dexterity;
protected int $need_intuition = 0; protected $need_intuition;
protected int $need_endurance = 0; protected $need_endurance;
protected int $need_intelligence = 0; protected $need_intelligence;
protected int $need_wisdom = 0; protected $need_wisdom;
protected int $add_strength = 0; protected $add_strength;
protected int $add_dexterity = 0; protected $add_dexterity;
protected int $add_intuition = 0; protected $add_intuition;
protected int $add_endurance = 0; protected $add_endurance;
protected int $add_intelligence = 0; protected $add_intelligence;
protected int $add_wisdom = 0; protected $add_wisdom;
protected int $add_accuracy = 0; protected $add_accuracy;
protected int $add_evasion = 0; protected $add_evasion;
protected int $add_criticals = 0; protected $add_criticals;
protected int $add_min_physical_damage = 0; protected $add_min_physical_damage;
protected int $add_max_physical_damage = 0; protected $add_max_physical_damage;
protected int $weight = 0; protected $weight;
protected string $image = ''; protected $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_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_HELMET = 1;
public const ITEM_TYPE_ARMOR = 2; public const ITEM_TYPE_ARMOR = 2;
public const ITEM_TYPE_LEGS = 3; public const ITEM_TYPE_LEGS = 3;
@ -41,7 +39,7 @@ class Item
public const ITEM_TYPE_CONSUMABLE = 20; public const ITEM_TYPE_CONSUMABLE = 20;
public const ITEM_TYPE_OTHER = 50; public const ITEM_TYPE_OTHER = 50;
public const ITEM_TYPE_TRASH = 100; public const ITEM_TYPE_TRASH = 100;
private string $typename; private $typename;
/** /**
* Item constructor. * Item constructor.
@ -101,31 +99,9 @@ class Item
default: default:
$this->typename = 'Хлам'; $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 protected function wrap(int $number):string
{ {
if ($number > 0) { if ($number > 0) {
return ": <b>" . $number . "</b>"; return ": <b>" . $number . "</b>";
@ -138,11 +114,11 @@ class Item
{ {
$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,
@ -156,7 +132,6 @@ class Item
"Шанс крита" => $this->add_criticals, "Шанс крита" => $this->add_criticals,
]; ];
echo "<b>$this->name</b> (Масса: $this->weight)"; echo "<b>$this->name</b> (Масса: $this->weight)";
echo "<br> Стоимость: " . $this->item_cost;
echo "<br> Долговечность: " . $this->durability; echo "<br> Долговечность: " . $this->durability;
echo "<br><em>$this->typename</em><br>"; echo "<br><em>$this->typename</em><br>";
foreach ($needsLines as $stat => $value) { foreach ($needsLines as $stat => $value) {

View File

@ -92,12 +92,12 @@ class ShopItem extends Item
} }
} }
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=''>";
} }
public static function buyItem($id, User $buyer): string public static function buyItem($id, User $buyer): string
@ -142,6 +142,15 @@ class ShopItem extends Item
return "Предмет " . $boughtItemName . " куплен за " . $boughtItemPrice . " банкнот."; 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 public static function sellItem($id, User $seller, $bankTrade = 0): string
{ {
$db = new DBPDO(); $db = new DBPDO();
@ -153,7 +162,7 @@ class ShopItem extends Item
if ($bankTrade) { if ($bankTrade) {
$bank = new Bank($seller->getId()); $bank = new Bank($seller->getId());
$bank->setMoney($bank->getMoney() + $sellingPrice); $bank->setMoney($bank->getMoney() + $sellingPrice);
Bank::setBankMoney($bank->getMoney(), $seller->getId(), 'sellShop'); Bank::setBankMoney($bank->getMoney(), $seller->getId(), 'shopsell');
} else { } else {
$db->execute('update users set money = money - ? where id = ?', [$sellingPrice, $_SESSION['uid']]); $db->execute('update users set money = money - ? where id = ?', [$sellingPrice, $_SESSION['uid']]);
} }
@ -174,7 +183,7 @@ class ShopItem extends Item
{ {
if ($this->price) { if ($this->price) {
$arr = range(0, $this->price / 2); $arr = range(0, $this->price / 2);
return array_sum($arr) / count($arr); return array_sum($arr) / sizeof($arr);
} }
return null; return null;
} }

View File

@ -55,7 +55,7 @@ class UserStats extends User
* *
* @return string * @return string
*/ */
public function getStat($stat_name, int $isMainWindow = 0): string public function getStat($stat_name, $isMainWindow = 0): string
{ {
if (!in_array($stat_name, ['strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'])) { if (!in_array($stat_name, ['strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'])) {
return self::ERROR_STAT_UNKNOWN; return self::ERROR_STAT_UNKNOWN;

View File

@ -2,6 +2,7 @@
use Battles\Bank; use Battles\Bank;
use Battles\Database\DBPDO; use Battles\Database\DBPDO;
use Battles\GameLogs;
use Battles\Item; use Battles\Item;
use Battles\ShopItem; use Battles\ShopItem;
use Battles\Template; use Battles\Template;
@ -98,113 +99,49 @@ Template::header('Магазин');
background-color: #ccc; background-color: #ccc;
display: block; display: block;
} }
a.sell { a.sell {
background-color: #cdc; background-color: #cdc;
} }
a.alltypes { a.alltypes {
background-color: #ccd; background-color: #ccd;
} }
.status { .status {
color: darkgreen; color:darkgreen;
background: #afa; 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> </style>
<h1>Государственный магазин</h1> <h1>Государственный магазин</h1>
<a href=# onclick=hrefToFrame('city.php?cp')> ← выйти на Центральную площадь</a> <a href=# onclick=hrefToFrame('city.php?cp')> ← выйти на Центральную площадь</a>
<div class="status"><?= $status ?></div> <div class="status"><?= $status ?></div>
<table class="shop"> <table style="width: 100%; border-collapse: collapse; border-spacing: 0; padding: 4px;">
<tr> <tr>
<td> <td style="vertical-align: top; text-align: left;">
<h3><?= $shopCategoryType ?></h3> <h3><?= $shopCategoryType ?></h3>
<?php if ($saleItems): ?> <?php if ($saleItems): ?>
<div>Вы можете продать ваши предметы за сущие копейки.</div> <div style="text-align: center;">Вы можете продать ваши предметы за сущие копейки.</div>
<?php endif; ?> <?php endif; ?>
<!--Магазин--> <!--Магазин-->
<table> <table class="zebra" style="width: 100%; border-collapse: separate; border-spacing: 1px; padding: 2px;">
<?php <?php
foreach ($iteminfo as $ii) { foreach ($iteminfo as $ii) {
if ($ii->getItemType() != $shopCategoryTypeNumber && $shopCategoryTypeNumber != 'sale') { if ($ii->getItemType() != $shopCategoryTypeNumber && $shopCategoryTypeNumber != 'sale') {
continue; continue;
} }
echo "<tr><td>"; echo "<tr><td style='width: 150px; text-align: center; padding: 5px;'>";
$ii->printImage(); echo $ii->printImage();
$ii->printControls(); $ii->printControls();
echo "<td>"; echo "<td style='vertical-align: top; padding: 5px;'>";
$ii->printInfo(); $ii->printInfo();
} }
?> ?>
</table> </table>
<td> <td style="width: 280px; vertical-align: top;">
<strong> <strong>
Масса всех ваших вещей: <?= getItemsMassaInfo() ?> <br> Масса всех ваших вещей: <?= getItemsMassaInfo() ?> <br>
У вас в банке: <span><?= $bank->getMoney() ?></span> банкнот. У вас в банке: <span style="color: darkgreen;"><?= $bank->getMoney() ?></span> банкнот.
</strong> </strong>
<hr> <hr>
<div>Отделы магазина</div> <div style="text-align: center; font-weight: bold;">Отделы магазина</div>
<a class="waretype" href="?otdel=6&rnd=<?= mt_rand() ?>">Оружие</a> <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=1&rnd=<?= mt_rand() ?>">Шлемы</a>
<a class="waretype" href="?otdel=2&rnd=<?= mt_rand() ?>">Броня</a> <a class="waretype" href="?otdel=2&rnd=<?= mt_rand() ?>">Броня</a>