Файл: include/player.php
Строк: 295
<?php
include_once("table_name.php");
include_once("creature_base.php");
include_once("skill.php");
include_once("constants.php");
/**
class for work with player information
*/
class CPlayer extends CCreatureBase
{
//player points
var $gold;
var $bank_gold;
var $exp;
//player info
var $password;
var $last_ip;
var $age;
var $email;
var $active;
var $ban;
var $online;
var $type_player;
/**
Constructor
*/
function CPlayer($database,$vnum = 0)
{
$this->db=$database;
$this->table_name=$GLOBALS['table_player'];
$this->vnum=$vnum;
}
/**
add player in game
*/
function addPlayer($name,$password,$email,$sex,$subscription)
{
global $skill_exp_table;
//begin initialization
$password_md5 = md5($password);
$level=1;
$gold=0;
$exp=0;
$age=time();
$hit=10;
$max_hit=10;
$sql = "insert into $this->table_name(name,level,sex,gold,exp,password,age,email)".
"values ('$name','$level','$sex','$gold','$exp','$password_md5','$age','$email')";
$result = $this->db->query($sql);
if (DB::isError($result)) {
die($result->toString());
}
$this->vnum = $this->checkPlayer($name,$password);
//set skills
$skill = new CSkill($this->db,$this->vnum);
$skill->setSkill(SKILL_HP,$skill_exp_table[1]);
$skill->setSkill(SKILL_WEAPON_MELEE,$skill_exp_table[1]);
$skill->setSkill(SKILL_HAND_TO_HAND,$skill_exp_table[1]);
$skill->setSkill(SKILL_MUTANT,$skill_exp_table[1]);
//calculate HP
$hp=0;
for($i=0;$i<$skill->getSkillLevel(SKILL_HP);$i++)
{
$hp+=rand(8,12);
}
//set hp
$this->setMaxHP($hp);
$this->setHP($hp);
}
/**
check player in database
*/
function checkPlayer($name,$password)
{
$password_md5=md5($password);
$sql = "SELECT vnum FROM $this->table_name WHERE name='$name' AND password='$password_md5' LIMIT 1";
$result = $this->execSQL($sql);
if($result->numRows()==0) return false;
$row = $result->fetchRow();
return $row[0];
}
/**
check player in database
*/
function checkPlayerEmail($name,$email)
{
$sql = "SELECT vnum FROM $this->table_name WHERE name='$name' AND email='$email' LIMIT 1";
$result = $this->execSQL($sql);
if($result->numRows()==0) return false;
$row = $result->fetchRow();
return $row[0];
}
/**
get player id for name
*/
function checkPlayerName($name)
{
$sql = "SELECT vnum FROM $this->table_name WHERE name='$name' LIMIT 1";
$result = $this->execSQL($sql);
if($result->numRows()==0) return false;
$row = $result->fetchRow();
return $row[0];
}
/**
get player information
*/
function getPlayerInfo()
{
$sql = "SELECT name,level,sex,gold,exp,age,hit,max_hit,active,state,online,clan FROM $this->table_name WHERE
vnum='$this->vnum' LIMIT 1";
$result = $this->db->query($sql);
if (DB::isError($result)) {
die($result->toString());
}
if($result->numRows()==0) return false;
$row = $result->fetchRow();
//$age = date("Y",$row[5])-date("Y",time())+17;
//$age.=".";
//$age.= date("z",time())-date("z",$row[5]);
$age = getDatesYear($row[5]);
$online_days = floor((time()-$row[5])/ONE_DAY_SECOND);
$p_info=array("name" => $row[0],"level" => $row[1],"sex" => $row[2],
"gold" => $row[3],"exp" => $row[4],"age" => $age,
"hit" => $row[6],"max_hit" => $row[7], "active" => $row[8], "state" => $row[9],"online" => $row[10],"online_days" => $online_days, "clan" => $row[11] );
return $p_info;
}
function getRoom()
{
return $this->getProperty('room_id');
}
function setRoom($room)
{
return $this->setProperty('room_id',$room);
}
function setMaxHP($max_hp)
{
$this->setProperty('max_hit',$max_hp);
}
function getMaxHP()
{
return $this->getProperty('max_hit');
}
function setHP($hp)
{
return $this->setProperty('hit',$hp);
}
function getHP()
{
return $this->getProperty('hit');
}
/**
get player level
*/
function getLevel()
{
$skill = new CSkill($this->db,$this->vnum);
//return $skill->getSkillLevel(SKILL_HP);
return 1;
}
/**
get player gold
*/
function getGold()
{
return $this->getProperty("gold");
}
function getChron()
{
return $this->getProperty("chron");
}
function updateChron($chron)
{
return $this->changeProperty("chron",$chron);
}
function getBankGold()
{
return $this->getProperty("bank_gold");
}
function updateGold($gold)
{
$this->changeProperty('gold',$gold);
}
function updateBankGold($gold)
{
$this->changeProperty('bank_gold',$gold);
}
function getState()
{
return $this->getProperty("state");
}
function setState($state)
{
$this->setProperty('state',$state);
}
function getAction()
{
return $this->getProperty('action');
}
function setAction($action)
{
$this->setProperty('action',$action);
}
function getObject()
{
return $this->getProperty("object");
}
function setObject($object)
{
$sql = "update $this->table_name set object='$object' where vnum='$this->vnum'";
$result = $this->execSQL($sql);
}
function getUuid()
{
$sql = "SELECT uuid_log FROM $this->table_name WHERE vnum='$this->vnum' LIMIT 1";
$result = $this->execSQL($sql);
$row = $result->fetchRow();
return $row[0];
}
function setUuid($uuid_log)
{
$sql = "update $this->table_name set uuid_log='$uuid_log' where vnum='$this->vnum'";
$result = $this->execSQL($sql);
}
//start player work on obj and make action
function setWork($state,$action,$obj)
{
$this->setState($state);
$this->setAction($action);
$this->setObject($obj);
}
function setPlayerActivity()
{
$ts = time();
$sql = "update $this->table_name set active='$ts',online='1' where vnum='$this->vnum'";
$result = $this->execSQL($sql);
}
function getOnline()
{
return $this->getProperty("online");
}
function setOnline($value)
{
$this->setProperty("online",$value);
}
function getRound()
{
return $this->getProperty("round");
}
function setRound($value)
{
$this->setProperty("round",$value);
}
/**
Set password
*/
function setPassword($password)
{
return $this->setProperty('password',$password);
}
/**
Get password
*/
function getPassword()
{
return $this->getProperty("password");
}
function getCurIP()
{
return $this->getProperty("cur_ip");
}
function setCurIP($cur_ip)
{
return $this->setProperty('cur_ip',$cur_ip);
}
function getLastIP()
{
return $this->getProperty("last_ip");
}
function setLastIP($last_ip)
{
return $this->setProperty('last_ip',$last_ip);
}
function getLastActive()
{
return $this->getProperty("active_last");
}
function setLastActive($last_active)
{
return $this->setProperty('active_last',$last_active);
}
function getV0()
{
return $this->getProperty("v0");
}
function setV0($v0)
{
return $this->setProperty('v0',$v0);
}
function getClan()
{
return $this->getProperty("clan");
}
function setClan($clan)
{
return $this->setProperty('clan',$clan);
}
function getChatAngel()
{
return $this->getProperty("chat_angel");
}
function setClanAngel($chat_angel)
{
return $this->setProperty('chat_andel',$chat_angel);
}
function checkLeader()
{
$sql = "SELECT vnum FROM data_clan WHERE leader=$this->vnum LIMIT 1";
$result = $this->execSQL($sql);
if($result->numRows()==0) return 0;
$row = $result->fetchRow();
return $row[0];
}
}
?>