Файл: include/players.php
Строк: 269
<?php
include_once("table_name.php");
include_once("base.php");
include_once("player.php");
include_once("skill.php");
include_once("thing.php");
include_once("things.php");
include_once("formulas.php");
include_once("player_thing.php");
include_once("log.php");
include_once("constants.php");
include_once("chain.php");
/**
class for work with players
*/
class CPlayers extends CBase
{
var $player;
var $player_thing;
var $skill;
var $thing;
var $things;
var $log_players;
var $chain;
/**
Constructor
*/
function CPlayers($database)
{
$this->db=$database;
$this->player = new CPlayer($database);
$this->player_thing = new CPlayerThings($database);
$this->skill = new CSkill($database);
$this->thing = new CThing($database);
$this->log_players = new CLogPlayers($database);
$this->chain = new CChain($database);
$this->table_name=$GLOBALS['table_player'];
$this->things = new CThings($database);
}
/**
get count all players
*/
function getCountPlayers()
{
$sql = "select vnum from ".$GLOBALS['table_player'];
$result = $this->execSQL($sql);
return $result->numRows();
}
function getPlayersRaiting($type,$limit=10)
{
if($type!='gold'){
$sql = "select vnum,$type,name from ".$GLOBALS['table_player']." order by $type desc limit $limit";
}else{
$sql = "select vnum,(gold+bank_gold),name from ".$GLOBALS['table_player']." order by (gold+bank_gold) desc limit $limit";
}
$result = $this->execSQL($sql);
$players = array();
//cycle on all player
while($row = $result->fetchRow())
{
$players[]=array('vnum' => $row[0],'type' => $row[1], 'name' => $row[2]);
}
return $players;
}
function getPlayersSkillLevel($type,$limit=10)
{
$sql = "select t1.vnum,t1.level,t2.name from ".$GLOBALS['table_player_skill']." as t1,".$GLOBALS['table_player']." as t2 where t1.type='$type' and t1.vnum=t2.vnum order by t1.level desc limit $limit";
$result = $this->execSQL($sql);
$players = array();
//cycle on all player
while($row = $result->fetchRow())
{
$players[]=array('vnum' => $row[0],'type' => $row[1], 'name' => $row[2]);
}
return $players;
}
function getPlayersInRoom($room)
{
$sql = "select vnum from ".$GLOBALS['table_player']." where room_id='$room'";
$result = $this->execSQL($sql);
return $result->numRows();
}
/**
Get player in room ( 10 man)
*/
function getPlayersInRoomAndName($room,$limit=10)
{
$ts_now = time();
$ts_old = $ts_now - ONE_DAY_SECOND;
$sql = "select vnum,name,online,active,clan from ".$GLOBALS['table_player']." where room_id='$room' and active>'$ts_old' order by online desc, active desc limit $limit";
$players = $this->db->getAll($sql,DB_FETCHMODE_ASSOC);
return $players;
}
function getPlayersInRoomAndAction($room,$action)
{
$sql = "select vnum from ".$GLOBALS['table_player']." where room_id='$room' and action='$action' and online='1' and state='".STATE_WORK."'";
$result = $this->execSQL($sql);
return $result->numRows();
}
function updateOnlinePlayers()
{
$ts_now = time();
$ts_old = $ts_now - PLAYER_LIFE_TIME;
$sql = "update ".$GLOBALS['table_player']." set online='0',state='".STATE_STAND."' where online='1' and active<'$ts_old'";
$result = $this->execSQL($sql);
}
/**
get count players which online
*/
function getOnlinePlayers()
{
$sql = "select vnum from $this->table_name where online='1'";
$result = $this->execSQL($sql);
return $result->numRows();
}
/**
get game list players whis online
*/
function getOnlinePlayersList()
{
$sql = "select vnum,active,name,state,action from $this->table_name where online='1'";
$result = $this->execSQL($sql);
$players_online=array();
//cycle on all player
while($row = $result->fetchRow())
{
$players_online[] = array('vnum' => $row[0], 'active' => $row[1], 'name' =>$row[2],
'state' => $row[3], 'action' => $row[4] );
}
return $players_online;
}
/**
Update player hitpoint in time slice, restore 5 hp in time
*/
function updatePlayerHP()
{
//if player is battle, when hp don`t increase
$sql = "select hit,max_hit,vnum from ".$GLOBALS['table_player']." where hit<max_hit and state!='".STATE_COMBAT."'";
$result = $this->execSQL($sql);
//cycle on all player
while($row = $result->fetchRow())
{
$hp=$row[0]+5;//+$row[1]/10;
if($hp>$row[1]) $hp=$row[1];
$sql = "update ".$GLOBALS['table_player']." set hit='$hp' where vnum='$row[2]'";
$this->execSQL($sql);
}
}
function getMininigMessage()
{
$m=rand(1,4);
$msg="";
switch($m)
{
case 1:
$msg="чБН ОЕ ХДБМПУШ ДПВЩФШ ТХДЩ";
break;
case 2:
$msg="чЩ ОЕ ТБУУЮЙФБМЙ ЧБЫ ХДБТ, Й ТХДБ РТЕЧТБФЙМБУШ Ч РЩМШ";
break;
case 3:
$msg="чБЫЙИ УЙМЕОПЛ ОЕ ИЧБФЙМП ТБЪВЙФШ ЬФПФ ЛХУПЛ РПТПДЩ";
break;
case 4:
$msg="лФП-ФП ЕМ ЛБЫЛЙ НБМП Х НБНЩ";
break;
}
return $msg;
}
function getWoodcutMessage()
{
$m=rand(1,4);
$msg="";
switch($m)
{
case 1:
$msg="чЩ ОЕ УНПЗМЙ УТХВЙФШ ДЕТЕЧП";
break;
case 2:
$msg="чБЫ ФПРПТ РТПНБИОХМУС НЙНП ЬФПЗП ДЕТЕЧБ, ОЕ РШСОЩ МЙ ЧЩ";
break;
case 3:
$msg="чЩ УЕМЙ Й ЪБФСОХМЙ РЕУОА РТП ДТПЧПУЕЛБ, ЛПФПТЩК ЪБТЦБЧЕМ Ч МЕУХ";
break;
case 4:
$msg="чБЫ ФПРПТ ОЕ ЧЩДЕТЦЙФ ФБЛПЗП ЙЪДЕЧБФЕМШУФЧБ";
break;
}
return $msg;
}
function updateAction($action,$skill)
{
//get all players action
$sql = "select vnum,object from ".$GLOBALS['table_player']." where state=".STATE_WORK." and action=".$action;
$result = $this->execSQL($sql);
//cycle on all player
while($row = $result->fetchRow())
{
//set vnum for all players
$this->player->setVnum($row[0]);
$this->skill->setVnum($row[0]);
$this->log_players->setVNum($row[0]);
$uuid_log = $this->player->getUuid();
$this->log_players->uuid_log=$uuid_log;
//get level mining
$level_skill=$this->skill->getSkillLevel($skill);
//get objects player minigs
$object=$row[1];
$this->thing->setVNum($object);
//gte level objects
$object_level=$this->thing->getLevel();
$prop=getProbability($object_level,$level_skill);
//echo($object_level."<br>".$level_skill."<br>");
//make rand
$prop_cubic=rand(0,100);
//echo($prop_cubic.";".$prop."<br>");
//consider
if($prop>=$prop_cubic){
//player get object
$this->player_thing->setVNum($row[0]);
if($action==ACTION_MINIG || $action == ACTION_WOODCUT){
$this->player_thing->addThing($object);
//descrease tool durability
$tool = $this->player_thing->getWearThing(WEAR_TWO_HAND);
$this->player_thing->decreaseDurability($tool);
//check tool
$tool = $this->player_thing->getWearThing(WEAR_TWO_HAND);
$tool_obj = $this->player_thing->getThingID($tool);
if($action==ACTION_MINIG){
if(($tool_obj!=7) && ($tool_obj!=28)){
$this->player->setWork(STATE_STAND,ACTION_CITY,0);
$this->log_players->addLogMsg("<b>х ЧБУ ОЕФ ПТХДЙС ДМС ДПВЩЮЙ ТХДЩ!</b>");
}
}
if($action==ACTION_WOODCUT){
if(($tool_obj!=4) && ($tool_obj!=5)){
$this->player->setWork(STATE_STAND,ACTION_CITY,0);
$this->log_players->addLogMsg("<b>х ЧБУ ОЕФ ПТХДЙС ДМС ТХВЛЙ ДЕТЕЧШЕЧ</b>");
}
}
}
if($action==ACTION_SMELT){
$this->chain->setVNum($object);
//check components and things
if($this->chain->makeThings($this->player_thing)==false || $this->chain->checkComponents($this->player_thing)==false){
echo("End");
$this->player->setWork(STATE_STAND,ACTION_CITY,0);
$this->log_players->addLogMsg("<b>чЩ РЕТЕРМБЧЙМЙ ЧУА ТХДХ</b>");
}
}
//update exp
$object_exp=$this->thing->getV0();
$object_name=$this->thing->getName();
$this->skill->setSkill($skill,$object_exp);
$this->log_players->addLogMsg("чЩ ДПВЩМЙ РТЕДНЕФ <b>$object_name</b>( <b>+$object_exp exp</b>)");
//check player bag
if($action==ACTION_MINIG || $action == ACTION_WOODCUT){
$count=$this->player_thing->getCountThings();
if($count>=MAX_PLAYER_ITEM)
{
$this->player->setWork(STATE_STAND,ACTION_CITY,0);
$this->log_players->addLogMsg("<b>чБЫБ УХНЛБ ХЦЕ ЪБРПМОЙМБУШ</b>");
}
}
//check player time for work
//$minutes=$this->log_players->getContinueLogs();
//echo($minutes);
}else{
//player not get object
switch($action){
case ACTION_MINIG:
$msg=$this->getMininigMessage();
break;
case ACTION_WOODCUT:
$msg=$this->getWoodcutMessage();
break;
default:
$msg="чЩ ОЕ ДПВЩМЙ РТЕДНЕФ";
break;
}
$this->log_players->addLogMsg($msg);
}
//check player minings stone
if($action == ACTION_MINIG){
$stones = $this->things->getAllThingsType("stone");
}
}
}
}
?>