Вход Регистрация
Файл: include/shop.php
Строк: 85
<?php

include_once("table_name.php");
include_once(
"base.php");

/**
    Shop class for trade with player
*/

class CShop extends CBase
{
    
/**
        Constructor
    */
    
function CShop($database,$room_id)
    {
        
$this->db=$database;
        
$this->table_name=$GLOBALS['table_shop'];
        
$this->room_id=$room_id;
    }

    function 
getList()
    {        
        
$sql "select t1.vnum, t1.count from $this->table_name AS t1, game_objects as t2 where room_id='$this->room_id' and t1.vnum = t2.vnum ORDER BY t2.name";
        

        
$result=$this->execSQL($sql);

        
$thing = array();

        while(
$row $result->fetchRow())
        {
            
$thing[] = array("obj" => $row[0],"count" => $row[1]);
        }

        return 
$thing;
    }

    function 
getObject($obj_id)
    {
        
$sql "select count from $this->table_name where room_id='$this->room_id' and vnum='$obj_id'";

        
$result=$this->execSQL($sql);

        if(
$result->numRows()==0) return 0;

        
$row $result->fetchRow();

        return 
$row[0];
    }

    function 
delObject($obj_id,$count)
    {
        
$count_shop=$this->getObject($obj_id);

        if(
$count_shop==$count){
            
//need remove objects from shop
            
$sql "delete from $this->table_name where room_id='$this->room_id' and vnum='$obj_id'";
        }else{
            
$sql "update $this->table_name set count=count-$count where room_id='$this->room_id' and vnum='$obj_id'";
        }
        
$result=$this->execSQL($sql);
    }
    
    function 
addThing($obj_id,$count)
    {
        
//check things
        
$count_t=$this->getObject($obj_id);

        if(
$count_t==0){
            
//need add things
            
$sql "insert into $this->table_name(room_id,vnum,count)".
            
"values ('$this->room_id','$obj_id','$count')";
        }else{
            
//need plus things
            
$sql "update $this->table_name set count=count+$count where vnum='$obj_id' and
room_id='
$this->room_id'";
        }

        
$result $this->execSQL($sql);
        
        return 
true;
    }
    
    function 
removeEachOneThings()
    {
        
$list_shop=$this->getList();
        
        
$sql "LOCK TABLES $this->table_name read";
        
        
$thing = new CThing($this->db);
        
        foreach(
$list_shop as $v){
            
$thing->setVnum($v['obj']);
            
$type=$thing->getType();
            if(
$typ=="bar" || $type=="fish"){
                
$this->delObject($v['obj'],1);
            }
        }

        
$this->execSQL("UNLOCK TABLES");
    }
}

?>
Онлайн: 2
Реклама