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

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

/**
    class player things
*/

class CPlayerThings extends CBase
{
    
/**
        Constructor
    */
    
function CPlayerThings($database,$vnum 0)
    {
        
$this->db=$database;
        
$this->table_name=$GLOBALS['table_player_things'];
        
$this->vnum=$vnum;
    }
    
    
/**
        Add things in player inventory
    */
    
function addThing($vnum_obj,$count 1,$bank 0$durability = -1$max_durability = -1)
    {    
        
$thing = new CThing($this->db,$vnum_obj);
        
        
$collect $thing->getCollect();
        
        if(
$collect == 1){
            
//collect things already have small durability
    
            
$durability=1;
            
$max_durability=$durability;
        
            
            
//check things
            
$vnum $this->getThingVnum($vnum_obj,$bank);
            
            
//player don`t have this things
            
if($vnum==-1){
                
//generate uniq id
                
$vnum getUniqID();
                
//need add things
                
$sql "insert into $this->table_name(vnum,vnum_player,vnum_obj,count,durability,max_durability,bank)".
                    
"values ('$vnum','$this->vnum','$vnum_obj','$count','$durability','$max_durability','$bank')";
            }else{
                
//need plus things
                
$sql "update $this->table_name set count=count+$count where vnum='$vnum' LIMIT 1";
            }
            
            
$result $this->execSQL($sql);
        }else{
            
            if(
$durability==-1){
                
$thing = new CThing($this->db,$vnum_obj);
                
$durability $thing->getDurability();
            }
            
            if(
$max_durability==-1$max_durability=$durability;
            
            for(
$i=0;$i<$count;$i++){
                
//no collect things
                
$vnum getUniqID();
                
                
$sql "insert into $this->table_name(vnum,vnum_player,vnum_obj,durability,max_durability,count,bank)".
                    
"values ('$vnum','$this->vnum','$vnum_obj','$durability','$max_durability','1','$bank')";
                    
                
$result $this->execSQL($sql);
            }
        }
    }
    
    
/**
        Remove thing from player inventory
        param vnum uniq number things
        param count count things
        param bank flag bank=1 or bag=0
    */
    
    
function removeThing($vnum,$count,$bank 0)
    {
        
$count floor($count);
        
        
$count_t $this->getCountThing($vnum,$bank);
        
        if(
$count==|| $count_t<$count) return false;
        
        if(
$count_t == $count){
            
//remove things from bank
            
$sql "delete from $this->table_name where vnum='$vnum' and bank='$bank' LIMIT 1";
        }else{
            
//update things
            
$sql "update $this->table_name set count=count-$count where vnum='$vnum' and bank='$bank' LIMIT 1";
        }
        
        
$this->execSQL($sql);
        
        return 
true;
    }
    
    
/**
        Get all things 
        param bank if 0 get things in player bag, else 1 in bank
    */
    
function getAllThings($bank 0)
    {
        
$sql "select t1.vnum_obj,t1.count,t1.vnum,t2.name from $this->table_name as t1, ".$GLOBALS['table_objects']." as t2 where t1.vnum_player='$this->vnum' and t1.bank='$bank' and t1.wear='0' and t1.vnum_obj=t2.vnum ORDER BY t2.name";
                
        
$all_things $this->db->getAll($sql,DB_FETCHMODE_ASSOC);
        
        return 
$all_things;
    }
    
    function 
getWearThings()
    {
        
$sql "select vnum_obj,vnum,wear from $this->table_name where vnum_player='$this->vnum' and wear>0";
        
        
$result $this->execSQL($sql);
        
        
$wear_things=array();
        
        
//cycle on all player
        
while($row $result->fetchRow())
        {
            
$wear_things[]=array("obj_id" => $row[0], "vnum" => $row[1],"wear" => $row[2]);
        }
        
        return 
$wear_things;
    }
    
    
//get things player one type
    
function getAllThingsOneType($type,$bank 0)
    {
        global 
$table_objects;
        
        
$sql "SELECT t1.vnum_obj, t1.count,t2.level,t2.name
FROM 
$this->table_name as t1, $table_objects as t2
WHERE t1.vnum_obj = t2.vnum AND t2.type = '
$type' AND t1.vnum_player='$this->vnum' AND t1.bank = '$bank' ORDER BY level";
            
        
$all_things=$this->db->getAll($sql,DB_FETCHMODE_ASSOC);
        
        return 
$all_things;
    }
    
    function 
getCountThings($bank 0)
    {
        
//wear things not calculated
        
$sql "select count from $this->table_name where vnum_player='$this->vnum' and bank='$bank' and wear='0'";
        
        
$result $this->execSQL($sql);
        
        
$count=0;
        
//cycle on all player things
        
while($row $result->fetchRow())
        {
            
$count+=$row[0];
        }
        
        return 
$count;
    }
    
    function 
getCountThing($vnum$bank 0)
    {
        
$sql "select count from $this->table_name where vnum_player='$this->vnum' and bank='$bank' and vnum='$vnum' LIMIT 1";
        
        
$result $this->execSQL($sql);
        
        if(
$result->numRows()==0) return -1;

        
$row $result->fetchRow();

        return 
$row[0];
        
        return 
$count;
    }
    
    function 
getThingID($vnum)
    {
        
$sql "select vnum_obj from $this->table_name where vnum='$vnum'";
        
        
$result $this->execSQL($sql);

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

        
$row $result->fetchRow();

        return 
$row[0];
    }
    
    function 
getThingVnum($vnum_obj,$bank =)
    {
        
$sql "select vnum from $this->table_name where vnum_obj='$vnum_obj' AND vnum_player='$this->vnum' AND bank='$bank'";
        
        
$result $this->execSQL($sql);

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

        
$row $result->fetchRow();

        return 
$row[0];
    }
    
    function 
getDurability($vnum_obj)
    {
        
$sql "select durability from $this->table_name where vnum='$vnum_obj'";
        
        
$result $this->execSQL($sql);

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

        
$row $result->fetchRow();

        return 
$row[0];
    }
    
    function 
getDurabilityMax($vnum_obj)
    {
        
$sql "select max_durability from $this->table_name where vnum='$vnum_obj'";
        
        
$result $this->execSQL($sql);

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

        
$row $result->fetchRow();

        return 
$row[0];
    }
    
    function 
decreaseDurability($vnum_obj)
    {
        
$durab $this->getDurability($vnum_obj);
        if(
$durab>1){
            
//decriase thinng 
            
$durab--;
            
$sql "update $this->table_name set durability='$durab' where vnum='$vnum_obj'";
            
            
$this->execSQL($sql);
        }else{
            
//things in broken
            
$this->removeThing($vnum_obj,1);
        }
    }
    
    function 
wearThing($vnum_obj,$wear_flag)
    {
        
$sql "update $this->table_name set wear='$wear_flag' where vnum='$vnum_obj'";
        
        
$this->execSQL($sql);
        
        return 
true;
    }
    
    
/**
        Get player things
    */
    
function getWearThing($wear_flag)
    {
        
$sql "select vnum from $this->table_name where vnum_player='$this->vnum' and wear='$wear_flag' LIMIT 1";
        
        
$result $this->execSQL($sql);
        
        if(
$result->numRows()==0) return -1;
        
        
$row $result->fetchRow();

        return 
$row[0];
    }
    
    
/**
        Get things in player hand
    */
    
    
function getWearThingsInHand()
    {
        
$wear_things = array();
        
        
//check two-hand things
        
$wear_two_hand $this->getWearThing(WEAR_TWO_HAND);
        
        if(
$wear_two_hand!=-1){
            
$wear_things[WEAR_TWO_HAND] = $wear_two_hand;
        }else{
            
//check separate hand
            
$wear_left_hand $this->getWearThing(WEAR_LEFT_HAND);
            
            if(
$wear_left_hand!=-1){
                
$wear_things[WEAR_LEFT_HAND] = $wear_left_hand;
            }
            
            
$wear_right_hand $this->getWearThing(WEAR_RIGHT_HAND);
            
            if(
$wear_right_hand!=-1){
                
$wear_things[WEAR_RIGHT_HAND] = $wear_right_hand;
            }
        }
        
        return 
$wear_things;
    }
    
    
/**
        Get skill for thing
    */
    
function getThingSkill($vnum)
    {
        
$skill_id=-1;
        
        
$vnum_obj=$this->getThingID($vnum);
        
        
$thing = new CThing($this->db,$vnum_obj);
        
        
$skill_id=$thing->getSkill();
        
        return 
$skill_id;    
    }
}

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