2018-01-28 16:40:49 +00:00
< ? php
2021-01-27 15:19:05 +00:00
use Battles\Bank ;
2022-01-26 23:15:33 +00:00
use Battles\Database\Db ;
2021-01-27 15:19:05 +00:00
use Battles\GameLogs ;
2021-08-27 15:55:18 +00:00
use Battles\InventoryItem ;
2021-01-27 15:19:05 +00:00
use Battles\Template ;
2022-01-26 23:15:33 +00:00
use Battles\User ;
2021-01-27 15:19:05 +00:00
2018-12-11 23:00:19 +00:00
require_once ( " functions.php " );
2021-08-23 18:51:34 +00:00
const GRAV_LIMIT = 32 ;
const GRAV_COST = 30 ;
const REPAIR_STATUS = [
2020-08-29 23:21:22 +00:00
'OK_GRAV_ADDED' => 'Гравировка добавлена!' ,
'OK_GRAV_REMOVED' => 'Гравировка удалена!' ,
'OK_REPAIRED' => 'Предмет отремонтирован!' ,
'ERROR_SIZE_LIMIT' => 'Превышен лимит в ' . GRAV_LIMIT . ' символа!' ,
'ERROR_NO_MONEY' => 'Недостаточно денег!' ,
2021-08-23 18:51:34 +00:00
];
2020-08-29 23:21:22 +00:00
$gravirovkaText = $_POST [ 'gravirovka_text' ] ? ? null ;
$itemId = $_POST [ 'itemId' ] ? ? null ;
$gravirovkaRemove = $_POST [ 'gravirovka_remove' ] ? ? null ;
$action = $_POST [ 'action' ] ? ? null ;
$goto = $_POST [ 'goto' ] ? ? null ;
2021-02-01 14:39:48 +00:00
$remont_query = null ;
$gravirovka_query = null ;
2018-01-28 16:40:49 +00:00
2018-12-12 17:16:36 +00:00
// Гравировка 30 кред. Максимум 32 символа.
2020-08-29 23:21:22 +00:00
if ( $gravirovkaText && $itemId ) {
2022-01-26 23:15:33 +00:00
if ( User :: getInstance () -> getMoney () >= GRAV_COST ) {
2020-08-29 23:21:22 +00:00
if ( iconv_strlen ( $gravirovkaText ) <= GRAV_LIMIT ) {
2022-01-26 23:15:33 +00:00
Db :: getInstance () -> execute ( 'UPDATE inventory SET text = ? WHERE dressed_slot = 0 AND on_sale = 0 AND owner_id = ? AND id = ?' , [ $gravirovkaText , User :: getInstance () -> getId (), $itemId ]);
User :: getInstance () -> setMoney ( User :: getInstance () -> getMoney () - GRAV_COST );
Bank :: setWalletMoney ( User :: getInstance () -> getMoney (), User :: getInstance () -> getId ());
2020-08-29 23:21:22 +00:00
$status = REPAIR_STATUS [ 'OK_GRAV_ADDED' ];
} else {
$status = REPAIR_STATUS [ 'ERROR_SIZE_LIMIT' ];
}
} else {
$status = REPAIR_STATUS [ 'ERROR_NO_MONEY' ];
}
2018-01-28 16:40:49 +00:00
}
2018-12-12 17:16:36 +00:00
// Снять гравировку.
2020-08-29 23:21:22 +00:00
if ( $gravirovkaRemove ) {
2022-01-26 23:15:33 +00:00
if ( User :: getInstance () -> getMoney () >= GRAV_COST ) {
Db :: getInstance () -> execute ( 'UPDATE inventory SET text = null WHERE dressed_slot = 0 AND on_sale = 0 AND owner_id = ? AND id = ?' , [ User :: getInstance () -> getId (), $itemId ]);
User :: getInstance () -> setMoney ( User :: getInstance () -> getMoney () - GRAV_COST );
Bank :: setWalletMoney ( User :: getInstance () -> getMoney (), User :: getInstance () -> getId ());
2020-08-29 23:21:22 +00:00
$status = REPAIR_STATUS [ 'OK_GRAV_REMOVED' ];
} else {
$status = REPAIR_STATUS [ 'ERROR_NO_MONEY' ];
}
2018-01-28 16:40:49 +00:00
}
2018-12-12 16:09:39 +00:00
// Ремонт 0,5 кред за единицу.
2021-02-01 14:39:48 +00:00
// Пока что лимит ремонта поставлен на 25. Дальше можно обыграть.
2020-08-29 23:21:22 +00:00
if ( $action == 'repair' && $itemId ) {
2022-01-26 23:15:33 +00:00
$q = Db :: getInstance () -> ofetch ( 'SELECT name, durability FROM inventory WHERE item_id = ?' , $itemId );
if ( User :: getInstance () -> getMoney () > ceil ( $q -> duration / 2 )) {
Db :: getInstance () -> execute ( 'UPDATE inventory SET duration = 25 WHERE dressed_slot = 0 AND on_sale = 0 AND owner_id = ? AND id = ?' , [ User :: getInstance () -> getId (), $itemId ]);
User :: getInstance () -> setMoney ( User :: getInstance () -> getMoney () - ceil ( $q -> duration / 2 ));
Bank :: setWalletMoney ( User :: getInstance () -> getMoney (), User :: getInstance () -> getId ());
GameLogs :: addUserLog ( User :: getInstance () -> getId (), 'Отремонтирован предмет «' . $q -> name . '» id:(' . $itemId . ') за ' . ceil ( $q -> duration / 2 ) . ' кр.' );
2020-08-29 23:21:22 +00:00
$status = REPAIR_STATUS [ 'OK_REPAIRED' ];
} else {
$status = REPAIR_STATUS [ 'ERROR_NO_MONEY' ];
}
2018-12-11 23:20:11 +00:00
}
2020-08-29 23:21:22 +00:00
if ( $goto == 'remont' ) {
2022-01-26 23:15:33 +00:00
$remont_query = Db :: getInstance () -> ofetchAll ( 'SELECT item_id, name, image, durability FROM inventory WHERE item_type < 12 AND dressed_slot = 0 AND on_sale = 0 AND durability < 25 AND owner_id = ? ORDER BY name' , User :: getInstance () -> getId ());
2018-12-12 14:58:41 +00:00
}
2020-08-29 23:21:22 +00:00
if ( $goto == 'gravirovka' ) {
2022-01-26 23:15:33 +00:00
$gravirovka_query = Db :: getInstance () -> ofetchAll ( 'SELECT item_id, name, image, text FROM inventory WHERE owner_id = ? AND dressed_slot = 0 AND item_type = 3 AND name NOT LIKE "%Букет%" AND on_sale = 0 OR text IS NOT NULL AND owner_id = ? AND dressed_slot = 0 AND on_sale = 0 ORDER BY name' , [ User :: getInstance () -> getId (), User :: getInstance () -> getId ()]);
2018-12-12 14:37:00 +00:00
}
2021-01-27 15:19:05 +00:00
Template :: header ( 'Кузня' );
2018-01-28 16:40:49 +00:00
?>
2021-02-01 14:39:48 +00:00
< link href = " css/secondary.css " rel = " stylesheet " />
< script src = " js/main.js " ></ script >
2018-12-11 23:20:11 +00:00
< h1 > Ремонтная мастерская </ h1 >
2019-01-15 19:34:35 +00:00
< a href = # onclick=hrefToFrame('city.php?cp')> ← выйти из мастерской</a><br>
2018-12-12 14:18:11 +00:00
< div class = " appblock appblock-main " >
< span class = " legend " > Информация </ span >
< span class = " wrap " > Кредиты < span class = " num " >< ? = $user [ 'money' ] ?> </span></span>
2021-08-27 15:55:18 +00:00
< span class = " wrap " > М а с с а вещей < span class = " num " >< ? = InventoryItem :: getWeightData () ?> </span></span>
2018-12-12 14:18:11 +00:00
</ div >
< div class = " appblock " >
< span class = " legend " > Зал ремонта </ span >
< form method = " post " >
< input type = " hidden " name = " goto " value = " remont " >
< input type = " submit " value = " Войти " >
</ form >
2018-12-12 17:16:36 +00:00
< span class = " wrap " > Починка поврежденных предметов . В процессе ремонта состояние предмета
уменьшится на единицу !</ span >
2018-12-12 14:18:11 +00:00
</ div >
< div class = " appblock " >
< span class = " legend " > Зал гравировки </ span >
< form method = " post " >
< input type = " hidden " name = " goto " value = " gravirovka " >
2020-08-29 23:21:22 +00:00
< input type = " submit " value = " Войти " disabled >
2018-12-12 14:18:11 +00:00
</ form >
2018-12-12 17:16:36 +00:00
< span class = " wrap " > Нанесение надписей на оружие и удаление надписей из любого обмундирования .
Максимум 32 символа !</ span >
2018-12-12 14:18:11 +00:00
</ div >
2018-12-12 14:23:58 +00:00
< div style = " clear: both; " >
< ? php if ( isset ( $status )) : ?>
< span class = " wrap " >< ? = $status ?> </span>
< ? php endif ; ?>
</ div >
2020-08-29 23:21:22 +00:00
< ? php if ( $goto == 'remont' ) :
2021-02-01 14:39:48 +00:00
$i = 0 ;
while ( $i < count ( $remont_query )) : ?>
2018-12-12 14:37:00 +00:00
< div class = " appblock " >
2021-02-01 14:39:48 +00:00
< span class = " legend " >< ? = $remont_query [ $i ] -> name ?> </span>
< span class = " wrap " > Состояние предмета < span class = " num " >< ? = $remont_query [ $i ] -> duration ?> /25</span></span>
< span class = " wrap " > Стоимость услуги < span class = " num " >< ? = ceil ( $remont_query [ $i ] -> duration / 2 ) ?> </span></span>
2018-12-12 14:37:00 +00:00
< div style = " text-align: center " >
2021-02-01 14:39:48 +00:00
< img src = " i/sh/<?= $remont_query[$i] ->img ?> " alt = " item " >
2018-12-12 16:09:39 +00:00
< form method = " post " >
2021-02-01 14:39:48 +00:00
< input type = " hidden " name = " itemId " value = " <?= $remont_query[$i] ->id ?> " >
2018-12-12 16:09:39 +00:00
< input type = " hidden " name = " action " value = " repair " >
< input type = " submit " value = " Ремонт " >
</ form >
2018-12-12 14:37:00 +00:00
</ div >
</ div >
2021-02-01 14:39:48 +00:00
< ? php $i ++ ; endwhile ;
unset ( $i ); endif ; ?>
2018-12-12 14:58:41 +00:00
2020-08-29 23:21:22 +00:00
< ? php if ( $goto == 'gravirovka' ) :
2021-02-01 14:39:48 +00:00
$i = 0 ;
while ( $i < count ( $gravirovka_query )) : ?>
2018-12-12 14:58:41 +00:00
< div class = " appblock " >
2021-02-01 14:39:48 +00:00
< span class = " legend " >< ? = $gravirovka_query [ $i ] -> name ?> </span>
2018-12-12 17:16:36 +00:00
< span class = " wrap " > Стоимость услуги < span class = " num " > 30 </ span ></ span >
2018-12-12 14:58:41 +00:00
< div style = " text-align: center " >
2021-02-01 14:39:48 +00:00
< ? php if ( empty ( $gravirovka_query [ $i ] -> text )) : ?>
2018-12-12 17:16:36 +00:00
< form method = " post " id = " gravirovka " >
2021-02-01 14:39:48 +00:00
< label >
< input maxlength = " 32 " placeholder = " Текст гравировки " name = " gravirovka_text " >
</ label >
< br >< img src = " i/sh/<?= $gravirovka_query[$i] ->img ?> " alt = " item " >< br >
< input type = " hidden " name = " itemId " value = " <?= $gravirovka_query[$i] ->id ?> " >
2018-12-12 17:16:36 +00:00
< input type = " submit " value = " Добавить надпись " >
</ form >
< ? php else : ?>
< form method = " post " id = " gravirovka " >
2021-02-01 14:39:48 +00:00
< input value = " <?= $gravirovka_query[$i] ->text ?> " readonly title >
< br >< img src = " i/sh/<?= $gravirovka_query[$i] ->img ?> " alt = " item " >< br >
< input type = " hidden " name = " gravirovka_remove " value = " <?= $gravirovka_query[$i] ->id ?> " >
2018-12-12 17:16:36 +00:00
< input type = " submit " value = " Удалить надпись " >
</ form >
< ? php endif ; ?>
2018-12-12 14:58:41 +00:00
</ div >
</ div >
2021-02-01 14:39:48 +00:00
< ? php $i ++ ; endwhile ;
unset ( $i ); endif ; ?>