Файл: include/drop.php
Строк: 149
<?php
include_once("table_name.php");
include_once("base.php");
include_once("player_thing.php");
include_once("thing.php");
/**
class for work with player drop things
*/
class CDrop extends CBase
{
var $player_things;
var $room_id;
/**
Constructor
*/
function CDrop($database,$room_id,$vnum = 0)
{
global $table_drop;
$this->db = $database;
$this->table_name=$table_drop;
$this->vnum=$vnum;
$this->room_id=$room_id;
$this->player_things = new CPlayerThings($database,$vnum);
//$this->execSQL("LOCK TABLES $this->table_name write, $table_objects write, $table_player write, $table_player_skill write,$table_room write");
}
function playerDropThing($vnum_obj)
{
//get count thing
$count_things=$this->player_things->getCountThing($vnum_obj);
$obj=$this->player_things->getThingID($vnum_obj);
$thing = new CThing($this->db,$obj);
$collect = $thing->getCollect();
if($collect == 1){
$durability=1;
$max_durability=$durability;
}else{
$durability = $this->player_things->getDurability($vnum_obj);
$max_durability = $this->player_things->getDurabilityMax($vnum_obj);
}
//remove this things
$this->player_things->removeThing($vnum_obj,$count_things);
//drop things in room
$this->addRoomThings($obj,$durability,$max_durability,$count_things);
}
function playerGetThing($vnum)
{
global $table_objects;
global $table_player_things;
$this->execSQL("LOCK TABLES $this->table_name write, $table_objects write,$table_player_things write");
//check things in ground
$sql = "select vnum_obj,count,durability,max_durability from $this->table_name where room_id='$this->room_id' and vnum='$vnum' LIMIT 1";
$result = $this->execSQL($sql);
if($result->numRows()==0){
$status=false;
}else{
$row = $result->fetchRow();
//add things in in inventory
$vnum_obj=$row[0];
$count=$row[1];
$durability=$row[2];
$max_durability=$row[3];
//add player things
$this->player_things->addThing($vnum_obj,$count,0,$durability,$max_durability);
//remove thing on ground
$this->removeRoomThings($vnum,0);
$status=true;
}
$this->execSQL("UNLOCK TABLES");
return $status;
}
function getListThingsInRoom()
{
$things =array();
$sql = "select vnum,vnum_obj,count from $this->table_name where room_id='$this->room_id'";
$result = $this->execSQL($sql);
//cycle on all things in room
while($row = $result->fetchRow())
{
$things[] = array("vnum" => $row[0], "vnum_obj" => $row[1], "count" => $row[2]);
}
return $things;
}
function getCountThingsInRoom()
{
$sql = "select count(*) from $this->table_name where room_id='$this->room_id'";
$result = $this->execSQL($sql);
$row = $result->fetchRow();
return $row[0];
}
function addRoomThings($vnum_obj,$durability,$max_durability,$count=1)
{
$vnum = getUniqID();
$sql = "insert into $this->table_name(vnum,vnum_obj,room_id,durability,max_durability,count)".
"values ('$vnum','$vnum_obj','$this->room_id','$durability','$max_durability','$count')";
$result = $this->execSQL($sql);
}
function removeRoomThings($vnum,$count)
{
//FIX ME: count not realized
$sql = "delete from $this->table_name where room_id='$this->room_id' and vnum='$vnum'";
$result = $this->execSQL($sql);
}
}
?>