Compare commits
3 Commits
5714ab83f3
...
2b1287397d
Author | SHA1 | Date | |
---|---|---|---|
|
2b1287397d | ||
|
7c7ac67ddb | ||
|
326d93f259 |
@ -1,31 +1,33 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Battles;
|
namespace Battles;
|
||||||
class Item
|
class Item
|
||||||
{
|
{
|
||||||
protected $item_id;
|
protected int $item_id;
|
||||||
protected $name;
|
protected string $name = '';
|
||||||
protected $item_type;
|
protected int $item_type = self::ITEM_TYPE_TRASH;
|
||||||
protected $durability;
|
protected int $durability = 0;
|
||||||
protected $need_strength;
|
protected int $need_strength = 0;
|
||||||
protected $need_dexterity;
|
protected int $need_dexterity = 0;
|
||||||
protected $need_intuition;
|
protected int $need_intuition = 0;
|
||||||
protected $need_endurance;
|
protected int $need_endurance = 0;
|
||||||
protected $need_intelligence;
|
protected int $need_intelligence = 0;
|
||||||
protected $need_wisdom;
|
protected int $need_wisdom = 0;
|
||||||
protected $add_strength;
|
protected int $add_strength = 0;
|
||||||
protected $add_dexterity;
|
protected int $add_dexterity = 0;
|
||||||
protected $add_intuition;
|
protected int $add_intuition = 0;
|
||||||
protected $add_endurance;
|
protected int $add_endurance = 0;
|
||||||
protected $add_intelligence;
|
protected int $add_intelligence = 0;
|
||||||
protected $add_wisdom;
|
protected int $add_wisdom = 0;
|
||||||
protected $add_accuracy;
|
protected int $add_accuracy = 0;
|
||||||
protected $add_evasion;
|
protected int $add_evasion = 0;
|
||||||
protected $add_criticals;
|
protected int $add_criticals = 0;
|
||||||
protected $add_min_physical_damage;
|
protected int $add_min_physical_damage = 0;
|
||||||
protected $add_max_physical_damage;
|
protected int $add_max_physical_damage = 0;
|
||||||
protected $weight;
|
protected int $weight = 0;
|
||||||
protected $image;
|
protected string $image = '';
|
||||||
public const ITEM_TYPES_ALLOWED_IN_SLOTS = [1,2,3,4,5,6,7,8,9,10,11,12];
|
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_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;
|
||||||
@ -39,7 +41,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 $typename;
|
private string $typename;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Item constructor.
|
* Item constructor.
|
||||||
@ -99,9 +101,31 @@ 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>";
|
||||||
@ -114,11 +138,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,
|
||||||
@ -132,6 +156,7 @@ 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) {
|
||||||
|
@ -92,12 +92,12 @@ class ShopItem extends Item
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function printImage(): string
|
public function printImage()
|
||||||
{
|
{
|
||||||
if (!$this->image) {
|
if (!$this->image) {
|
||||||
$this->image = 'noitem.png';
|
$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
|
public static function buyItem($id, User $buyer): string
|
||||||
@ -142,15 +142,6 @@ 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();
|
||||||
@ -162,7 +153,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(), 'shopsell');
|
Bank::setBankMoney($bank->getMoney(), $seller->getId(), 'sellShop');
|
||||||
} 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']]);
|
||||||
}
|
}
|
||||||
@ -183,7 +174,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) / sizeof($arr);
|
return array_sum($arr) / count($arr);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ class UserStats extends User
|
|||||||
*
|
*
|
||||||
* @return string
|
* @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'])) {
|
if (!in_array($stat_name, ['strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'])) {
|
||||||
return self::ERROR_STAT_UNKNOWN;
|
return self::ERROR_STAT_UNKNOWN;
|
||||||
|
89
shop.php
89
shop.php
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
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;
|
||||||
@ -99,49 +98,113 @@ 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 style="width: 100%; border-collapse: collapse; border-spacing: 0; padding: 4px;">
|
<table class="shop">
|
||||||
<tr>
|
<tr>
|
||||||
<td style="vertical-align: top; text-align: left;">
|
<td>
|
||||||
<h3><?= $shopCategoryType ?></h3>
|
<h3><?= $shopCategoryType ?></h3>
|
||||||
<?php if ($saleItems): ?>
|
<?php if ($saleItems): ?>
|
||||||
<div style="text-align: center;">Вы можете продать ваши предметы за сущие копейки.</div>
|
<div>Вы можете продать ваши предметы за сущие копейки.</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<!--Магазин-->
|
<!--Магазин-->
|
||||||
<table class="zebra" style="width: 100%; border-collapse: separate; border-spacing: 1px; padding: 2px;">
|
<table>
|
||||||
<?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 style='width: 150px; text-align: center; padding: 5px;'>";
|
echo "<tr><td>";
|
||||||
echo $ii->printImage();
|
$ii->printImage();
|
||||||
$ii->printControls();
|
$ii->printControls();
|
||||||
echo "<td style='vertical-align: top; padding: 5px;'>";
|
echo "<td>";
|
||||||
$ii->printInfo();
|
$ii->printInfo();
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</table>
|
</table>
|
||||||
<td style="width: 280px; vertical-align: top;">
|
<td>
|
||||||
<strong>
|
<strong>
|
||||||
Масса всех ваших вещей: <?= getItemsMassaInfo() ?> <br>
|
Масса всех ваших вещей: <?= getItemsMassaInfo() ?> <br>
|
||||||
У вас в банке: <span style="color: darkgreen;"><?= $bank->getMoney() ?></span> банкнот.
|
У вас в банке: <span><?= $bank->getMoney() ?></span> банкнот.
|
||||||
</strong>
|
</strong>
|
||||||
<hr>
|
<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=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>
|
||||||
|
Loading…
Reference in New Issue
Block a user