2018-01-28 16:40:49 +00:00
< ? php
2021-01-27 15:19:05 +00:00
2021-03-12 16:26:15 +00:00
use Battles\Database\DBPDO ;
2021-01-27 15:19:05 +00:00
use Battles\GameLogs ;
use Battles\ShopItem ;
use Battles\Template ;
use Battles\User ;
2018-01-28 16:40:49 +00:00
ob_start ();
session_start ();
2019-01-15 15:56:15 +00:00
require_once 'functions.php' ;
2021-01-27 15:19:05 +00:00
$user = $user ? ? new User ( $_SESSION [ 'uid' ]);
2021-03-12 16:26:15 +00:00
$db = new DBPDO ();
2019-02-12 14:00:13 +00:00
/*
* aheroshop . php
* $data = db :: c () -> query ( 'SELECT * FROM `ahero_shop` WHERE `count` > 0 AND `razdel` = ?i ORDER by `point` ASC' , $_GET [ 'otdel' ]);
* db :: c () -> query ( 'UPDATE `shop` SET `count` = `count`- ?i WHERE `id` = ?i' , $_POST [ 'count' ], $set );
* db :: c () -> query ( 'UPDATE `users` set `doblest` = `doblest` - ?i * ?i WHERE id = ?i' , $_POST [ 'count' ], $dress [ 'point' ], $user [ 'id' ]);
2019-02-12 14:14:51 +00:00
*
* shop_luka . php
* $data = mysql_query ( " SELECT * FROM `shop` WHERE `count` > 0 AND `razdel` = ' { $_GET [ 'otdel' ] } ' AND `zeton` != '0' ORDER by `cost` ASC " );
* $vsego = $zetons - $_POST [ 'count' ] * $dress [ 'zeton' ];
* if ( $vsego <= '0' ){
* mysql_query ( " DELETE FROM `inventory` WHERE `type`='200' and `name`='Жетон' and owner=' " . $user [ " id " ] . " ' " );
* } else { mysql_query ( " UPDATE `inventory` set `maxdur` = ' $vsego ' WHERE `type`='200' and `name`='Жетон' and owner=' " . $user [ " id " ] . " ' " );}
2019-02-12 14:00:13 +00:00
* */
2018-06-23 18:08:07 +00:00
$saleItems = false ;
2020-09-29 22:39:06 +00:00
$shopCategoryType = $_POST [ 'sale' ] ? ? '' ;
$shopCategoryTypeNumber = $_GET [ 'otdel' ] ? ? 0 ;
2019-01-14 20:37:35 +00:00
switch ( $shopCategoryTypeNumber ) {
default :
$shopCategoryType = " Предметы в инвентаре " ;
$saleItems = true ;
break ;
case 1 :
2019-01-14 23:47:13 +00:00
$shopCategoryType = " Кинжалы " ;
2019-01-14 20:37:35 +00:00
break ;
case 11 :
$shopCategoryType = " Топоры " ;
break ;
case 12 :
2019-01-14 23:47:13 +00:00
$shopCategoryType = " Дубины " ;
2019-01-14 20:37:35 +00:00
break ;
case 13 :
$shopCategoryType = " Мечи " ;
break ;
case 2 :
$shopCategoryType = " Сапоги " ;
break ;
case 21 :
$shopCategoryType = " Перчатки " ;
break ;
case 22 :
$shopCategoryType = " Легкая броня " ;
break ;
case 23 :
$shopCategoryType = " Тяжелая броня " ;
break ;
case 24 :
$shopCategoryType = " Шлемы " ;
break ;
case 3 :
$shopCategoryType = " Щиты " ;
break ;
case 4 :
$shopCategoryType = " Серьги " ;
break ;
case 41 :
$shopCategoryType = " Ожерелья " ;
break ;
case 42 :
$shopCategoryType = " Кольца " ;
break ;
case 5 :
$shopCategoryType = " Заклинания: нейтральные " ;
break ;
case 51 :
$shopCategoryType = " Заклинания: боевые и защитные " ;
break ;
case 6 :
$shopCategoryType = " Амуниция " ;
break ;
}
2018-01-28 16:40:49 +00:00
2020-09-30 19:12:34 +00:00
if ( ! $saleItems ) {
2019-01-14 20:28:47 +00:00
$shopItems = db :: c () -> query ( ' SELECT `shop` .* ,
`magic` . `name` AS `magic_name` ,
`magic` . `chanse` AS `magic_chanse` ,
`magic` . `time` AS `magic_time` ,
`magic` . `file` AS `magic_file` ,
`magic` . `targeted` AS `magic_targeted` ,
`magic` . `needcharge` AS `magic_needcharge` ,
`magic` . `img` AS `magic_img`
FROM `shop` LEFT JOIN `magic` ON `magic` = `magic` . `id` WHERE `count` > 0 AND `cost` > 0 AND `razdel` = ? i ORDER by `nlevel` ASC , `id` ASC ' , $shopCategoryTypeNumber );
$iteminfo = [];
while ( $row = $shopItems -> fetch_assoc ()) {
2021-01-27 15:19:05 +00:00
$iteminfo [] = new ShopItem ( $row );
2018-01-28 16:40:49 +00:00
}
2019-01-14 20:28:47 +00:00
} else {
$inventoryItems = db :: c () -> query ( ' SELECT `inventory` .* ,
`magic` . `name` AS `magic_name` ,
`magic` . `chanse` AS `magic_chanse` ,
`magic` . `time` AS `magic_time` ,
`magic` . `file` AS `magic_file` ,
`magic` . `targeted` AS `magic_targeted` ,
`magic` . `needcharge` AS `magic_needcharge` ,
2019-01-14 21:54:20 +00:00
`magic` . `img` AS `magic_img` ,
0 AS `maxdur`
2019-01-14 20:28:47 +00:00
2019-01-15 15:56:15 +00:00
FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic` . `id` WHERE
`dressed` = 0 AND `setsale` = 0 AND `cost` > 0 AND `present` = " ?s " AND
`tradesale` = 0 AND `podzem` = 0 AND `goden` = 0 AND `artefact` = 0 AND `owner` = ? i
ORDER BY `update` DESC ', null, $_SESSION[' uid ' ]);
2019-01-14 20:28:47 +00:00
$iteminfo = [];
while ( $row = $inventoryItems -> fetch_assoc ()) {
2021-01-27 15:19:05 +00:00
$iteminfo [] = new ShopItem ( $row );
2018-01-28 16:40:49 +00:00
}
2019-01-14 20:28:47 +00:00
}
2020-09-30 19:12:34 +00:00
$sellItemId = $_GET [ 'sell' ] ? ? 0 ;
2019-01-14 20:28:47 +00:00
if ( $sellItemId ) {
2021-03-12 16:26:15 +00:00
ShopItem :: sellItem ( $sellItemId , $user );
2018-01-28 16:40:49 +00:00
}
2019-01-12 21:35:48 +00:00
if ( ! empty ( $_GET [ 'buy' ])) {
2021-03-12 16:26:15 +00:00
ShopItem :: buyItem ( $_GET [ 'buy' ], $user );
/* $dress = db :: c () -> query ( 'SELECT * FROM `shop` WHERE `id`=?i' , $_GET [ 'buy' ]) -> fetch_assoc ();
2019-01-14 17:40:14 +00:00
$itemWeight = db :: c () -> query ( 'SELECT sum(`massa`) AS `m` FROM `inventory` WHERE `owner` = ?i AND `setsale` = 0' , $_SESSION [ 'uid' ]) -> fetch_assoc ();
2018-06-23 16:22:20 +00:00
2020-09-30 19:12:34 +00:00
if (( $dress [ 'massa' ] + $itemWeight [ 'm' ]) > ( get_meshok ())) {
$status = 'Недостаточно места в рюкзаке.' ;
}
elseif ( $user [ 'money' ] >= $dress [ 'cost' ] && ( $dress [ 'count' ] > 0 || $dress [ 'count' ] == - 1 )) {
2018-06-23 12:44:38 +00:00
$newItem = [
'prototype' => $dress [ 'id' ],
'owner' => $user [ 'id' ],
'name' => $dress [ 'name' ], //s
'type' => $dress [ 'type' ],
'massa' => $dress [ 'massa' ],
'cost' => $dress [ 'cost' ],
'img' => $dress [ 'img' ], //s
'maxdur' => $dress [ 'maxdur' ],
'isrep' => $dress [ 'isrep' ],
'gsila' => $dress [ 'gsila' ],
'glovk' => $dress [ 'glovk' ],
'ginta' => $dress [ 'ginta' ],
'gintel' => $dress [ 'gintel' ],
2019-01-15 15:56:15 +00:00
2018-06-23 12:44:38 +00:00
'ghp' => $dress [ 'ghp' ],
'gnoj' => $dress [ 'gnoj' ],
'gtopor' => $dress [ 'gtopor' ],
'gdubina' => $dress [ 'gdubina' ],
'gmech' => $dress [ 'gmech' ],
'gfire' => $dress [ 'gfire' ],
'gwater' => $dress [ 'gwater' ],
'gair' => $dress [ 'gair' ],
'gearth' => $dress [ 'gearth' ],
'glight' => $dress [ 'glight' ],
'ggray' => $dress [ 'ggray' ],
'gdark' => $dress [ 'gdark' ],
2019-01-15 15:56:15 +00:00
2018-06-23 12:44:38 +00:00
'needident' => $dress [ 'needident' ],
'nsila' => $dress [ 'nsila' ],
'nlovk' => $dress [ 'nlovk' ],
'ninta' => $dress [ 'ninta' ],
'nintel' => $dress [ 'nintel' ],
'nmudra' => $dress [ 'nmudra' ],
'nvinos' => $dress [ 'nvinos' ],
'nnoj' => $dress [ 'nnoj' ],
'ntopor' => $dress [ 'ntopor' ],
'ndubina' => $dress [ 'ndubina' ],
'nmech' => $dress [ 'nmech' ],
2019-01-15 15:56:15 +00:00
'nfire' => $dress [ 'nfire' ],
'nwater' => $dress [ 'nwater' ],
'nair' => $dress [ 'nair' ],
'nearth' => $dress [ 'nearth' ],
'nlight' => $dress [ 'nlight' ],
'ngray' => $dress [ 'ngray' ],
'ndark' => $dress [ 'ndark' ],
'mfkrit' => $dress [ 'mfkrit' ],
'mfakrit' => $dress [ 'mfakrit' ],
'mfuvorot' => $dress [ 'mfuvorot' ],
'mfauvorot' => $dress [ 'mfauvorot' ],
2018-06-23 12:44:38 +00:00
'bron1' => $dress [ 'bron1' ],
'bron2' => $dress [ 'bron2' ],
'bron3' => $dress [ 'bron3' ],
'bron4' => $dress [ 'bron4' ],
'minu' => $dress [ 'minu' ],
'maxu' => $dress [ 'maxu' ],
'magic' => $dress [ 'magic' ],
'nlevel' => $dress [ 'nlevel' ],
'nalign' => $dress [ 'nalign' ],
'dategoden' => $dress [ 'dategoden' ],
'goden' => $dress [ 'goden' ],
'gmp' => $dress [ 'gmp' ],
'artefact' => $dress [ 'artefact' ],
2019-01-15 15:56:15 +00:00
'koll' => $dress [ 'koll' ],
2018-06-23 12:44:38 +00:00
];
2018-06-22 23:00:48 +00:00
2019-01-15 15:56:15 +00:00
db :: c () -> query ( 'INSERT INTO `inventory` SET ?A[?i,?i,"?s",?i,?i,?i,"?s",?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i]' , $newItem );
2019-01-14 17:40:14 +00:00
$inventoryItemId = db :: c () -> getLastInsertId ();
2020-09-30 19:12:34 +00:00
if ( $dress [ 'count' ] != - 1 ) {
db :: c () -> query ( 'UPDATE `shop` SET `count` = `count` - 1 WHERE `id` = ?i' , $_GET [ 'buy' ]);
}
2019-01-14 23:47:13 +00:00
$status = " Вы купили « { $dress [ 'name' ] } » за { $dress [ 'cost' ] } кр. " ;
2019-01-14 23:52:33 +00:00
db :: c () -> query ( 'UPDATE `users` set `money` = `money` - ?i WHERE `id` = ?i' , $dress [ 'cost' ], $_SESSION [ 'uid' ]);
2021-02-01 16:42:52 +00:00
$deloText = " { $user -> getLogin () } купил товар « { $dress [ 'name' ] } » id:( { $inventoryItemId } ) в магазине за { $dress [ 'cost' ] } кр. " ;
GameLogs :: addUserLog ( $user -> getId (), $deloText );
2019-01-14 23:57:10 +00:00
// Для обновления данных о деньгах на странице
$user [ 'money' ] -= $dress [ 'cost' ];
2019-01-14 17:05:15 +00:00
2018-06-22 23:00:48 +00:00
} else {
2019-01-14 17:40:14 +00:00
$status = " Недостаточно денег или нет вещей в наличии. " ;
2021-03-12 16:26:15 +00:00
} */
2018-01-28 16:40:49 +00:00
}
2021-01-27 15:19:05 +00:00
Template :: header ( 'Магазин' );
2018-01-28 16:40:49 +00:00
?>
2019-01-15 11:52:15 +00:00
< script src = " js/main.js " ></ script >
2018-06-22 23:00:48 +00:00
< h1 > Государственный магазин </ h1 >
2019-01-15 19:34:35 +00:00
< a href = # onclick=hrefToFrame('city.php?cp')> ← выйти на Центральную площадь</a>
2019-01-14 17:40:14 +00:00
< div >< ? php if ( ! empty ( $status )) err ( $status ); ?> </div>
2018-06-23 17:14:10 +00:00
< TABLE width = 100 % cellspacing = " 0 " cellpadding = " 4 " >
2018-06-22 23:00:48 +00:00
< TR >
< TD valign = top align = left >
2019-01-15 15:56:15 +00:00
< h3 >< ? = $shopCategoryType ?> </h3>
< ? php if ( $saleItems ) : ?>
< div style = " text-align: center; " > Вы можете продать ваши предметы за сущие копейки .</ div >
< ? php endif ; ?>
2018-06-22 23:00:48 +00:00
<!-- Магазин -->
2019-01-15 15:56:15 +00:00
< TABLE class = " zebra " WIDTH = 100 % CELLSPACING = " 1 " CELLPADDING = " 2 " >
< ? php
if ( $saleItems == true ) {
foreach ( $iteminfo as $ii ) {
echo " <tr><td style='width: 150px; text-align: center;'> " ;
$ii -> printImage ();
$ii -> printControls ( 'sell' );
echo " </td> " ;
echo " <td style='vertical-align: top;'> " ;
$ii -> printInfo ();
echo " </td></tr> " ;
}
} else {
foreach ( $iteminfo as $ii ) {
echo " <tr><td style='width: 150px; text-align: center;'> " ;
$ii -> printImage ();
$ii -> printControls ();
echo " </td> " ;
echo " <td style='vertical-align: top;'> " ;
$ii -> printInfo ();
echo " </td></tr> " ;
}
}
?>
2018-06-22 23:00:48 +00:00
</ TABLE >
</ TD >
< TD valign = top width = 280 >
2018-12-12 20:21:47 +00:00
< B > М а с с а всех ваших вещей : < ? = getItemsMassaInfo () ?>
< BR > У вас в наличии : < span style = " color: darkgreen; " >< ? = $user [ 'money' ] ?> </span> кр.</B>
2018-06-22 23:00:48 +00:00
< hr >
2019-01-15 15:56:15 +00:00
< div style = " text-align: center; font-weight: bold; " > Отделы магазина </ div >
2018-06-23 18:26:38 +00:00
< a href = " shop.php?otdel=sale&rnd=<?= mt_rand() ?> " > Продать вещи </ a >
2018-06-22 23:00:48 +00:00
< dl >
< dt >< b > Оружие :</ b ></ dt >
2019-01-15 15:56:15 +00:00
< dd >< a href = " ?otdel=1&rnd=<?= mt_rand() ?> " > кинжалы </ a ></ dd >
< dd >< a href = " ?otdel=11&rnd=<?= mt_rand() ?> " > топоры </ a ></ dd >
< dd >< a href = " ?otdel=12&rnd=<?= mt_rand() ?> " > дубины </ a ></ dd >
< dd >< a href = " ?otdel=13&rnd=<?= mt_rand() ?> " > мечи </ a ></ dd >
2018-06-22 23:00:48 +00:00
< dt >< b > Одежда :</ b ></ dt >
2019-01-15 15:56:15 +00:00
< dd >< a href = " ?otdel=24&rnd=<?= mt_rand() ?> " > шлемы </ a ></ dd >
< dd >< a href = " ?otdel=23&rnd=<?= mt_rand() ?> " > тяжелая броня </ a ></ dd >
< dd >< a href = " ?otdel=22&rnd=<?= mt_rand() ?> " > легкая броня </ a ></ dd >
< dd >< a href = " ?otdel=3&rnd=<?= mt_rand() ?> " > щиты </ a ></ dd >
< dd >< a href = " ?otdel=21&rnd=<?= mt_rand() ?> " > перчатки </ a ></ dd >
< dd >< a href = " ?otdel=2&rnd=<?= mt_rand() ?> " > сапоги </ a ></ dd >
2018-06-22 23:00:48 +00:00
< dt >< b > Ювелирные товары :</ b ></ dt >
2019-01-15 15:56:15 +00:00
< dd >< a href = " ?otdel=4&rnd=<?= mt_rand() ?> " > серьги </ a ></ dd >
< dd >< a href = " ?otdel=41&rnd=<?= mt_rand() ?> " > ожерелья </ a ></ dd >
< dd >< a href = " ?otdel=42&rnd=<?= mt_rand() ?> " > кольца </ a ></ dd >
2018-06-22 23:00:48 +00:00
< dt >< b > Магия :</ b ></ dt >
2019-01-15 15:56:15 +00:00
< dd >< a href = " ?otdel=51&rnd=<?= mt_rand() ?> " > боевые </ a ></ dd >
< dd >< a href = " ?otdel=5&rnd=<?= mt_rand() ?> " > разные </ a ></ dd >
2018-06-22 23:00:48 +00:00
< dt >< b > Разное :</ b ></ dt >
2019-01-15 15:56:15 +00:00
< dd >< a href = " ?otdel=6&rnd=<?= mt_rand() ?> " > амуниция </ a ></ dd >
2018-06-22 23:00:48 +00:00
</ dl >
< div id = " hint3 " class = " ahint " ></ div >
</ TD >
</ TR >
2020-09-30 19:12:34 +00:00
</ TABLE >