Файл: trade.php
Строк: 123
<?php
include_once("settings.php");
include_once("game_header.php");
include_once("shop.php");
include_once("thing.php");
include_once("player_thing.php");
//check player state
checkPlayerState($player);
//FIX ME
if($room_id!=1){
header("Location: area.php");
break;
}
$game_nav=$smarty->fetch($templ_path.'/game_nav.tpl');
$smarty->assign('GAME_NAV',$game_nav);
$shop = new CShop($db,$room_id);
$things = $shop->getList();
$smarty->assign('ROOM',$room_id);
$player = new CPlayer($db,$vnum);
$player_thing = new CPlayerThings($db,$vnum);
$object = new CThing($db);
if(isset($mode))
{
//check obj
if(!isset($_GET['obj'])){
header("Location: trade.php");
exit();
}
$obj = $_GET['obj'];
//lock tables
$shop->execSQL("LOCK TABLES $table_player write, $table_player_things write, $table_shop write, $table_objects read");
$info_msg="";
switch($mode)
{
case 'buy':
$amount = $_POST['amount'];
$amount=floor($amount);
if($amount<=0){
$info_msg = "чЩ ОЕ НПЦЕФЕ ЛХРЙФШ ФБЛПЗП ЛПМЙЮЕУФЧБ ЧЕЭЕК.";
break;
}
//check player bag
$item_player=$player_thing->getCountThings();
if(($item_player+$amount)>MAX_PLAYER_ITEM){
$info_msg = "чЩ ОЕ НПЦЕФЕ ХИЧБФЙФШ ФБЛПЕ ЛПМЙЮЕУФЧП ЧЕЭЕК.";
break;
}
//check objects in shop
$object->setVnum($obj);
$count=$shop->getObject($obj);
if($count==false) {
$info_msg = "ч НБЗБЪЙОЕ ОЕФ ФБЛПЗП РТЕДНЕФБ.";
break;
}
if($count<$amount){
$info_msg = "ч НБЗБЪЙОЕ ОЕФ ФБЛПЗП ЛПМЙЮЕУФЧБ ЧЕЭЕК";
break;
}
//get objects cos
$obj_cost=$object->getCost()*$amount;
//get player gold
$plr_gold=$player->getGold();
//check player money for buy objects
if($plr_gold-$obj_cost<0){
$info_msg = "х ЧБУ ОЕ ИЧБФБЕФ ДЕОЕЗ.";
break;
}
//remove player gold
$player->updateGold(-$obj_cost);
//delete objects from shop
$shop->delObject($obj,$amount);
//add objects in player inventory
$player_thing->addThing($obj,$amount);
break;
case 'sell':
$vnum_obj = $player_thing->getThingID($obj);
$object->setVnum($vnum_obj);
$amount = $_POST['amount'];
$amount=floor($amount);
if($amount< 1){
$info_msg="чЩ ОЕ НПЦЕФЕ РТПДБФШ ФБЛПЕ ЛПМЙЮЕУФЧП ЧЕЭЕК";
break;
}
//get durability
$max_durability = $player_thing->getDurabilityMax($obj);
$durability = $player_thing->getDurability($obj);
if($player_thing->removeThing($obj,$amount)==false){
$info_msg="х ЧБУ ОЕФ ЬФПЗП РТЕДНЕФБ";
break;
}
//all ok
//add money players
$obj_cost=$object->getCost();
$gold=(int)($obj_cost*SHOP_COMMISSION)*$amount;
$player->updateGold($gold);
//add things to shop
if($durability==$max_durability){
$shop->addThing($vnum_obj,$amount);
$info_msg="чБЫ ФПЧБТ ЧЩУФБЧЙМЙ ОБ ЧЙФТЙОХ. ";
}else{
$info_msg="чБЫ ФПЧБТ УДБМЙ Ч ХФЙМШ. ";
}
$info_msg.="чЩ РПМХЮЙМЙ ЪБ УДЕМЛХ <b>$gold</b> НПОЕФ";
break;
}
$shop->unlockTable();
session_register("info_msg");
header("Location: trade.php");
exit();
}
if(isset($info_msg))
{
$smarty->assign('INFO_MSG',$info_msg);
session_unregister("info_msg");
}
foreach($things as $v)
{
$object->setVnum($v['obj']);
$obj_name=$object->getName();
$obj_cost=$object->getCost();
$smarty->append("things",array(
'VNUM' => $v['obj'],
'NAME' => $obj_name,
'COUNT' => $v['count'],
'COST' => $obj_cost
));
}
$things_in_bag = $player_thing->getAllThings();
foreach($things_in_bag as $v)
{
$object->setVnum($v['vnum_obj']);
$obj_name=$object->getName();
$obj_cost=$object->getCost();
$smarty->append("player_things",array(
'VNUM' => $v['vnum'],
'NAME' => $obj_name,
'COUNT' => $v['count'],
'COST' => (int)($obj_cost*SHOP_COMMISSION)
));
}
//get player gold
$plr_gold=$player->getGold();
$smarty->assign('MONEY',$plr_gold);
$shop_txt=$smarty->fetch($templ_path.'/shop.tpl');
$smarty->assign('MAIN',$shop_txt);
echo($smarty->fetch($templ_path.'/game.tpl'));
?>