defined('AntiBK') or die("Доступ запрещен!");
class Char
{
public $guid;
public $db;
public $test;
public $equip;
public $city;
public $mail;
public $bank;
public $chat;
public $history;
public $error;
function& initialization ($guid, $adb)
{
$object = new Char;
$object->guid = $guid;
$object->db = $adb;
$classes = array('test', 'equip', 'city', 'mail', 'bank', 'chat', 'history', 'error');
foreach ($classes as $class)
{
$object->{$class} = new $class;
}
foreach ($classes as $class)
{
$object->{$class}->Init($object);
}
return $object;
}
/*Получение информации о персонаже*/
function getChar ()
{
$args = func_get_args();
$a_num = func_num_args();
$m_guid = (isset($args[2])) ?$args[2] :"-";
if (is_numeric($args[$a_num-1]))
{
$guid = $args[$a_num-1];
unset($args[$a_num-1]);
}
else
$guid = $this->guid;
$table = getTable($args[0]);
unset($args[0]);
if ($args[1] == '*')
return $this->db->selectRow("SELECT * FROM ?# WHERE `guid` = ?d", $table ,$guid);
else if ($a_num == 2 || ($a_num == 3 && is_numeric($m_guid)))
return $this->db->selectCell("SELECT ?# FROM ?# WHERE `guid` = ?d", $args ,$table ,$guid);
else
return $this->db->selectRow("SELECT ?# FROM ?# WHERE `guid` = ?d", $args ,$table ,$guid);
}
/*Обновление информации о персонаже*/
function setChar ()
{
$args = func_get_args();
$a_num = func_num_args();
if (is_numeric($args[$a_num-1]))
{
$guid = $args[$a_num-1];
unset($args[$a_num-1]);
}
else
$guid = $this->guid;
$table = getTable($args[0]);
unset($args[0]);
if ($a_num == 4 || ($a_num == 3 && !is_array($args[1])))
return $this->db->query("UPDATE ?# SET ?# = ? WHERE `guid` = ?d", $table ,$args[1] ,$args[2] ,$guid);
else
return $this->db->query("UPDATE ?# SET ?a WHERE `guid` = ?d", $table ,$args[1] ,$guid);
}
/*Получение информации о языке*/
function getLang ()
{
$lang = $this->db->selectCell("SELECT `language` FROM `server_info`;");
return $this->db->selectCol("SELECT `key` AS ARRAY_KEY, ?# FROM `server_language`;", $lang);
}
/*Увеличение/уменьшение характеристики*/
function changeStats ()
{
$stats = func_get_args();
$a_num = func_num_args();
if (is_numeric($stats[$a_num-1]))
{
$guid = $stats[$a_num-1];
unset($stats[$a_num-1]);
}
else
$guid = $this->guid;
$stats = (is_array($stats[0])) ?$stats[0] :array($stats[0] => $stats[1]);
foreach ($stats as $stat => $count)
{
switch ($stat)
{
case 'str':
$this->db->query("UPDATE `character_stats`
SET `str` = `str` + ?d,
`hitmin` = `hitmin` + ?d,
`hitmax` = `hitmax` + ?d
WHERE `guid` = ?d", $count ,$count ,$count ,$guid);
$this->statsBonus($stat);
break;
case 'dex':
$mf_dodge = $count * 7;
$mf_adodge = $count * 3;
$this->db->query("UPDATE `character_stats`
SET `dex` = `dex` + ?d,
`mf_dodge` = `mf_dodge` + ?d,
`mf_adodge` = `mf_adodge` + ?d
WHERE `guid` = ?d", $count ,$mf_dodge ,$mf_adodge ,$guid);
$this->statsBonus($stat);
break;
case 'con':
$mf_crit = $count * 7;
$mf_acrit = $count * 3;
$this->db->query("UPDATE `character_stats`
SET `con` = `con` + ?d,
`mf_crit` = `mf_crit` + ?d,
`mf_acrit` = `mf_acrit` + ?d
WHERE `guid` = ?d", $count ,$mf_crit ,$mf_acrit ,$guid);
$this->statsBonus($stat);
break;
case 'vit':
$hp = $count * 6;
$bron = rdf($count * 1.5);
$this->db->query("UPDATE `character_stats`
SET `vit` = `vit` + ?d,
`hp` = `hp` + ?d,
`hp_all` = `hp_all` + ?d,
`maxmass` = `maxmass` + ?d,
`res_sting` = `res_sting` + ?f,
`res_slash` = `res_slash` + ?f,
`res_crush` = `res_crush` + ?f,
`res_sharp` = `res_sharp` + ?f,
`res_fire` = `res_fire` + ?f,
`res_water` = `res_water` + ?f,
`res_air` = `res_air` + ?f,
`res_earth` = `res_earth` + ?f,
`res_light` = `res_light` + ?f,
`res_gray` = `res_gray` + ?f,
`res_dark` = `res_dark` + ?f
WHERE `guid` = ?d", $count ,$hp ,$hp ,$count ,$bron ,$bron ,$bron ,$bron ,$bron ,$bron ,$bron ,$bron ,$bron ,$bron ,$bron ,$guid);
$this->statsBonus($stat);
break;
case 'int':
$mf = rdf($count * 0.5);
$this->db->query("UPDATE `character_stats`
SET `int` = `int` + ?d,
`mf_fire` = `mf_fire` + ?f,
`mf_water` = `mf_water` + ?f,
`mf_air` = `mf_air` + ?f,
`mf_earth` = `mf_earth` + ?f,
`mf_light` = `mf_light` + ?f,
`mf_gray` = `mf_gray` + ?f,
`mf_dark` = `mf_dark` + ?f
WHERE `guid` = ?d", $count ,$mf ,$mf ,$mf ,$mf ,$mf ,$mf ,$mf ,$guid);
$this->statsBonus($stat);
break;
case 'wis':
$mp = $count * 10;
$this->db->query("UPDATE `character_stats`
SET `wis` = `wis` + ?d,
`mp` = `mp` + ?d,
`mp_all` = `mp_all` + ?d
WHERE `guid` = ?d", $count ,$mp ,$mp ,$guid);
$this->statsBonus($stat);
break;
case 'spi':
$this->db->query("UPDATE `character_stats`
SET `spi` = `spi` + ?d
WHERE `guid` = ?d", $count ,$guid);
break;
default:
return false;
}
}
return true;
}
/*Увеличение/уменьшение кол-ва денег у персонажа*/
function changeMoney ($sum, $guid = 0)
{
if (!is_numeric($sum))
return false;
$sum = rdf($sum);
if ($sum == 0)
return false;
$guid = $this->getGuid($guid);
$money = $this->getChar('char_db', 'money');
if (($money = $money + $sum) < 0)
return false;
$this->setChar('char_db', 'money', $money, $guid);
return true;
}
/*Увеличение/уменьшение массы у персонажа*/
function changeMass ($mass, $guid = 0)
{
if (checki($mass))
return false;
$guid = $this->getGuid($guid);
$mass = $this->getChar('char_stats', 'mass') + rdf($mass);
$this->setChar('char_stats', 'mass', $mass, $guid);
return true;
}
/*Время востановления здоровья*/
function setTimeToHPMP ($now, $all, $regen, $type, $guid = 0)
{
$guid = $this->getGuid($guid);
if ($now > $all)
$this->setChar('char_stats', array($type => $all, $type.'_cure' => 0), $guid);
else
{
getCureValue($now, $all, $regen, $cure);
$this->setChar('char_stats', $type.'_cure', $cure, $guid);
}
}
/*Отображение дополнительной характеристики*/
function showStatAddition ($type = 'skills')
{
global $added;
$added = array('str' => 0, 'dex' => 0, 'con' => 0, 'int' => 0, 'sword' => 0, 'bow' => 0, 'crossbow' => 0, 'axe' => 0, 'fail' => 0, 'knife' => 0, 'staff' => 0, 'fire' => 0, 'water' => 0, 'air' => 0, 'earth' => 0, 'light' => 0, 'gray' => 0, 'dark' => 0);
$items = $this->db->select("SELECT `i`.`add_str`, `c`.`inc_str`,
`i`.`add_dex`, `c`.`inc_dex`,
`i`.`add_con`, `c`.`inc_con`,
`i`.`add_int`, `c`.`inc_int`,
`i`.`all_mastery`,
`i`.`sword`, `i`.`axe`,
`i`.`bow`, `i`.`crossbow`,
`i`.`fail`, `i`.`knife`,
`i`.`staff`,
`i`.`all_magic`,
`i`.`fire`, `i`.`water`,
`i`.`air`, `i`.`earth`,
`i`.`light`, `i`.`gray`,
`i`.`dark`
FROM `character_inventory` AS `c`
LEFT JOIN `item_template` AS `i`
ON `c`.`item_entry` = `i`.`entry`
WHERE `c`.`guid` = ?d
and `c`.`wear` = '1';", $this->guid);
foreach ($items as $dat)
{
$added['str'] += $dat['add_str'] + $dat['inc_str'];
$added['dex'] += $dat['add_dex'] + $dat['inc_dex'];
$added['con'] += $dat['add_con'] + $dat['inc_con'];
$added['int'] += $dat['add_int'] + $dat['inc_int'];
}
$travms = $this->db->select("SELECT `stats` FROM `character_travms` WHERE `guid` = ?d and `stats` != '';", $this->guid);
foreach ($travms as $travm)
{
$stats = split(",", $travm['stats']);
foreach ($stats as $stat)
{
$stat = split("=", $stat);
if (array_key_exists($stat[0], $added))
$added[$stat[0]] += -$stat[1];
}
}
if ($type != 'skills')
return;
foreach ($items as $dat)
{
$added['sword'] += $dat['sword'] + $dat['all_mastery'];
$added['bow'] += $dat['bow'] + $dat['all_mastery'];
$added['crossbow'] += $dat['crossbow'] + $dat['all_mastery'];
$added['axe'] += $dat['axe'] + $dat['all_mastery'];
$added['fail'] += $dat['fail'] + $dat['all_mastery'];
$added['knife'] += $dat['knife'] + $dat['all_mastery'];
$added['staff'] += $dat['staff'];
$added['fire'] += $dat['fire'] + $dat['all_magic'];
$added['water'] += $dat['water'] + $dat['all_magic'];
$added['air'] += $dat['air'] + $dat['all_magic'];
$added['earth'] += $dat['earth'] + $dat['all_magic'];
$added['light'] += $dat['light'];
$added['gray'] += $dat['gray'];
$added['dark'] += $dat['dark'];
}
}
/*Проверка доступности образа*/
function checkShape ($id)
{
$shape = $this->db->selectRow("SELECT * FROM `player_shapes` WHERE `id` = ?d", $id);
if (!$shape)
return false;
$char_db = $this->getChar('char_db', 'level', 'sex', 'next_shape');
$char_stats = $this->getChar('char_stats', 'str', 'dex', 'con', 'vit', 'int', 'wis', 'sword', 'axe', 'fail', 'knife', 'fire', 'water', 'air', 'earth', 'light', 'dark');
$char_feat = array_merge($char_db, $char_stats);
if ($char_feat['next_shape'] && $char_feat['next_shape'] > time())
$this->error->Inventory(111, getFormatedTime($char_feat['next_shape']));
if ($shape['sex'] != $char_feat['sex'])
return false;
unset($char_feat['sex'], $char_feat['next_shape']);
foreach ($char_feat as $key => $value)
{
if ($shape[$key] > 0 && $shape[$key] > $value)
return false;
}
return true;
}
/*Отображение модуля инвентаря*/
function showInventoryBar ($bar, $value, $max_num)
{
global $behaviour;
$flag = explode('|', $value);
$lang = $this->getLang();
$char_stats = $this->getChar('char_stats', '*');
$char_equip = $this->getChar('char_equip', 'hand_r', 'hand_l', 'hand_r', 'hand_r_type', 'hand_l_type');
list($hand_r, $hand_l, $hand_r_type, $hand_l_type) = array_values($char_equip);
$content = '';
$link_text = '';
$link = '';
$flags = ($flag[1]) ?1 :0;
$flags += ($flag[0] > 1) ?2 :0;
$flags += ($flag[0] < $max_num) ?4 :0;
switch ($bar)
{
default:
case 'stat': /*Характеристики*/
$level = $this->db->selectCell("SELECT `level` FROM `characters` WHERE `guid` = ?d", $this->guid);
foreach ($behaviour as $key => $min_level)
$content .= ($level >= $min_level) ?"$lang[$key] $char_stats[$key]
" :"";
$content .= ($char_stats['ups'] > 0) ?"+ $lang[ups] " :"";
$content .= ($char_stats['skills'] > 0) ?"• $lang[skills]" :"";
break;
case 'mod': /*Модификаторы*/
$hitmin = $char_stats['hitmin'];
$hitmax = $char_stats['hitmax'];
$hand_r_hitmin = $char_stats['hand_r_hitmin'];
$hand_l_hitmin = $char_stats['hand_l_hitmin'];
$hand_r_hitmax = $char_stats['hand_r_hitmax'];
$hand_l_hitmax = $char_stats['hand_l_hitmax'];
$hand_r_critp = $char_stats['hand_r_critp'];
$hand_l_critp = $char_stats['hand_l_critp'];
$hand_r_crit = $char_stats['hand_r_crit'];
$hand_l_crit = $char_stats['hand_l_crit'];
$hand_r_adodge = $char_stats['hand_r_adodge'];
$hand_l_adodge = $char_stats['hand_l_adodge'];
$mf_critp = $char_stats['mf_critp'];
$mf_crit = $char_stats['mf_crit'];
$mf_dodge = $char_stats['mf_dodge'];
$mf_acrit = $char_stats['mf_acrit'];
$mf_adodge = $char_stats['mf_adodge'];
$mf_contr = $char_stats['mf_contr'];
$mf_parry = $char_stats['mf_parry'];
$mf_shieldb = $char_stats['mf_shieldb'];
$hand_status_r = $this->equip->checkHandStatus('r');
$hand_status_l = $this->equip->checkHandStatus('l');
$show_r_udar = ($hand_status_r) ?($hand_r_hitmin + $hitmin + $char_stats[$hand_r_type])."-".($hand_r_hitmax + $hitmax + $char_stats[$hand_r_type]) :"";
$show_l_udar = ($hand_status_l) ?(($hand_r != 0) ?" / " :"").($hand_l_hitmin + $hitmin + $char_stats[$hand_l_type])."-".($hand_l_hitmax + $hitmax + $char_stats[$hand_l_type]) :"";
$show_r_cpower = ($hand_status_r) ?$hand_r_critp + $mf_critp :"";
$show_l_cpower = ($hand_status_l) ?(($hand_r != 0) ?" / " :"").($hand_l_critp + $mf_critp) :"";
$show_r_crit = ($hand_status_r) ?$hand_r_crit + $mf_crit :"";
$show_l_crit = ($hand_status_l) ?(($hand_r != 0) ?" / " :"").($hand_l_crit + $mf_crit) :"";
$show_r_adodge = ($hand_status_r) ?$hand_r_adodge + $mf_adodge :"";
$show_l_adodge = ($hand_status_l) ?(($hand_r != 0) ?" / " :"").($hand_l_adodge + $mf_adodge) :"";
$show_r_mastery = ($hand_status_r) ?$char_stats[$hand_r_type] + $char_stats['hand_r_'.$hand_r_type] :"";
$show_l_mastery = ($hand_status_l) ?(($hand_r != 0) ?" / " :"").($char_stats[$hand_l_type] + $char_stats['hand_l_'.$hand_r_type]) :"";
$content .= "$lang[damage] $show_r_udar$show_l_udar
"
. "$lang[mf_crit_i] $show_r_crit$show_l_crit
";
$content .= ($hand_r_critp != 0 || $hand_l_critp != 0 || $mf_critp != 0) ?"$lang[mf_critp_i] $show_r_cpower$show_l_cpower
" :"";
$content .= "$lang[mf_acrit_i] $mf_acrit
"
. "$lang[mf_dodge_i] $mf_dodge
"
. "$lang[mf_adodge_i] $show_r_adodge$show_l_adodge
"
. "$lang[mf_contr_i] $mf_contr
"
. "$lang[mf_parry_i] $mf_parry
"
. "$lang[mf_shieldb_i] $mf_shieldb
";
$content .= ($hand_r != 0 || $hand_l != 0) ?"$lang[mastery] $show_r_mastery$show_l_mastery
" :"";
break;
case 'power': /*Мощность*/
$mf_damage = array('sting', 'slash', 'crush', 'sharp');
$mf_magic = array('fire', 'water', 'air', 'earth', 'light', 'gray', 'dark');
foreach ($mf_damage as $key)
{
$plus_r = $char_stats['hand_r_'.$key] + $char_stats['mf_'.$key];
$plus_l = $char_stats['hand_l_'.$key] + $char_stats['mf_'.$key];
$show_r[$key] = ($this->equip->checkHandStatus('r')) ?(($plus_r > 0) ?'+' :'')."$plus_r" :"";
$show_l[$key] = ($this->equip->checkHandStatus('l')) ?(($hand_r != 0) ?"% / ".(($plus_l > 0) ?'+' :'') :"").$plus_l :"";
}
foreach ($mf_damage as $key)
$content .= ($char_stats['mf_'.$key] != 0 || $char_stats['hand_r_'.$key] != 0 || $char_stats['hand_l_'.$key] != 0) ?"".$lang[$key.'_i']." $show_r[$key]$show_l[$key]%
" :"";
foreach ($mf_magic as $key)
$content .= ($char_stats['mf_'.$key] != 0) ?"".$lang[$key.'_i']." ".(($char_stats['mf_'.$key] > 0) ?'+' :'')."".$char_stats['mf_'.$key]."%
" :"";
break;
case 'def': /*Защита*/
$ress = array ('sting', 'slash', 'crush', 'sharp', 'fire', 'water', 'air', 'earth', 'light', 'dark', 'gray');
foreach ($ress as $key)
$content .= "".$lang[$key.'_i']." ".$char_stats['res_'.$key]."
";
break;
case 'btn': /*Кнопки*/
$content .= "
";
break;
case 'set': /*Комплекты*/
$sets = $this->db->select("SELECT * FROM `character_sets` WHERE `guid` = ?d", $this->guid);
$link_text = "запомнить";
$link = "javascript:kmp();";
$content .= "
"; if ($flags & 1) $return .= ""; else $return .= ""; $return .= " | "; $return .= "".$lang['bar_'.$bar]." | "; if ($link_text) $return .= "$link_text | "; $return .= ""; if ($flags & 2) $return .= ""; else $return .= ""; if ($flags & 4) $return .= ""; else $return .= ""; $return .= " | "; $return .= "