defined('AntiBK') or die("Доступ запрещен!");
/*Информация о персонаже*/
class Info
{
public $guid;
public $db;
function& initialization ($guid, $adb)
{
$object = new Info;
$object->guid = $guid;
$object->db = $adb;
return $object;
}
/*Получение информации о персонаже*/
function getChar ()
{
$args = func_get_args();
$args_num = func_num_args();
$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 ($args_num == 2)
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 getLang ()
{
$lang = $this->db->selectCell("SELECT `language` FROM `server_info`;");
return $this->db->selectCol("SELECT `key` AS ARRAY_KEY, ?# FROM `server_language`;", $lang);
}
/*Проверка существования персонажа*/
function Guid ()
{
if (checki($this->guid))
error('Указанный персонаж не найден...');
$char_db = $this->getChar('char_db', 'guid');
$char_stats = $this->getChar('char_stats', 'guid');
$char_info = $this->getChar('char_info', 'guid');
if (!$char_db || !$char_stats || !$char_info)
error('Указанный персонаж не найден...');
}
/*Проверка заключения персонажа*/
function Prison ()
{
$prison = $this->getChar('char_db', 'prison');
if (!$prison || intval($prison - time()) > 0)
return;
$this->db->query("UPDATE `characters` SET `prison` = '0' WHERE `guid` = ?d", $this->guid);
}
/*Проверка молчанки у персонажа*/
function Shut ()
{
$chat_shut = $this->getChar('char_db', 'chat_shut');
if (!$chat_shut || $chat_shut > time())
return;
$this->db->query("UPDATE `characters` SET `chat_shut` = '0' WHERE `guid` = ?d", $this->guid);
}
/*Восстановление здоровья/маны*/
function Regen ()
{
if ($this->getChar('char_db', 'battle') != 0)
return;
$char_stats = $this->getChar('char_stats', 'hp', 'hp_cure', 'hp_all', 'hp_regen', 'mp', 'mp_cure', 'mp_all', 'mp_regen');
list($now["hp"], $cure["hp"], $all["hp"], $regen["hp"], $now["mp"], $cure["mp"], $all["mp"], $regen["mp"]) = array_values($char_stats);
foreach ($all as $key => $value)
{
if ($cure[$key] == 0 && $now[$key] < $value)
{
getCureValue($now[$key], $value, $regen[$key], $cure[$key]);
$this->db->query("UPDATE `character_stats` SET ?# = ?d WHERE `guid` = ?d", $key.'_cure' ,$cure[$key] ,$this->guid);
}
else if ($cure[$key] == 0)
continue;
$regenerated = getRegeneratedValue($value, ($cure[$key] - time()), $regen[$key]);
if ($regenerated >= 0 && $regenerated < $value)
$this->db->query("UPDATE `character_stats` SET ?# = ?d WHERE `guid` = ?d", $key ,$regenerated ,$this->guid);
else
{
$this->db->query("UPDATE `character_stats` SET ?# = ?d, ?# = '0' WHERE `guid` = ?d", $key ,$value ,$key.'_cure' ,$this->guid);
continue;
}
}
}
/*Проверка онлайн*/
function Online ()
{
$last_time = $this->getChar('char_db', 'last_time');
if ((time() - $last_time) > 100)
$this->db->query("DELETE FROM `online` WHERE `guid` = ?d", $this->guid);
}
/*Отображение дополнительной характеристики*/
function showStatAddition ()
{
global $added;
$added = array('str' => 0, 'dex' => 0, 'con' => 0, 'int' => 0);
$rows = $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`
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 ($rows 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'];
}
$rows = $this->db->select("SELECT `stats` FROM `character_travms` WHERE `guid` = ?d and `stats` != '';", $this->guid);
foreach ($rows 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];
}
}
}
/*Отображение снаряжения*/
function showCharacter ()
{
$char_equip = $this->getChar('char_equip', '*');
$char_db = $this->getChar('char_db', 'login', 'shape', 'block');
$char_stats = $this->getChar('char_stats', 'hp', 'hp_all', 'hp_regen', 'mp', 'mp_all', 'mp_regen');
$char_feat = array_merge($char_db, $char_stats);
$char_feat['name'] = "alt='$char_feat[login]'";
$char_equip['armor'] = ($char_equip['cloak']) ?$char_equip['cloak'] :(($char_equip['armor']) ?$char_equip['armor'] :$char_equip['shirt']);
$char_equip['hand_l_s'] = (!$char_equip['hand_l_free']) ?"hand_l" :"hand_l_f";
echo $this->getLogin();
echo "
";
echo $this->getCharacterEquipped($char_equip, $char_feat);
echoScript("showHP($char_feat[hp], $char_feat[hp_all], $char_feat[hp_regen]);".
"showMP($char_feat[mp], $char_feat[mp_all], $char_feat[mp_regen]);");
}
/*Получение одетых вещей*/
function getCharacterEquipped ($char_equip, $char_feat)
{
if (!$char_equip || !$char_feat)
return;
$effects = $this->getEffects();
$equipped = "";
if ($char_feat['block'])
$equipped .= "Персонаж заблокирован! |
";
$equipped .= ""
. ""
. $this->getItemEquiped($char_equip['helmet'], "helmet")
. $this->getItemEquiped($char_equip['bracer'], "bracer")
. $this->getItemEquiped($char_equip['hand_r'], "hand_r")
. $this->getItemEquiped($char_equip['armor'], "armor")
. $this->getItemEquiped($char_equip['belt'], "belt")
. " | "
. ""
. " | "
. " $effects | "
. " | "
. " | "
. ""
. $this->getItemEquiped($char_equip['earring'], "earring")
. $this->getItemEquiped($char_equip['amulet'], "amulet")
. $this->getItemEquiped($char_equip['ring1'], "ring")
. $this->getItemEquiped($char_equip['ring2'], "ring")
. $this->getItemEquiped($char_equip['ring3'], "ring")
. $this->getItemEquiped($char_equip['gloves'], "gloves")
. $this->getItemEquiped($char_equip['hand_l'], $char_equip['hand_l_s'])
. $this->getItemEquiped($char_equip['pants'], "pants")
. $this->getItemEquiped($char_equip['boots'], "boots")
. " |
";
return $equipped;
}
/*Получение отображаемых эффектов*/
function getEffects ()
{
$i = 1;
$left = 0;
$top = 0;
$return = '';
$lang = $this->getLang();
$travms = $this->db->select("SELECT * FROM `character_travms` AS `c` LEFT JOIN `player_travms` AS `i` ON `c`.`travm_id` = `i`.`id` WHERE `c`.`guid` = ?d and `c`.`stats` != '';", $this->guid);
foreach ($travms as $travm)
{
$name = (isset($lang['travm_p_'.$travm['power']])) ?$lang['travm_p_'.$travm['power']].' ('.$travm['name'].')' :$travm['name'];
$stats = ($travm['type'] == 1) ?'
У персонажа '.lowercase($lang['travm_p_'.$travm['power']]).' - ослаблены характеристики.' :'';
$modifiers = split(",", $travm['stats']);
foreach ($modifiers as $modifier)
{
$stat = split("=", $modifier);
$stats .= '
'.$lang[$stat[0]].' -'.$stat[1];
}
$end_time = 'Осталось: '.getFormatedTime($travm['end_time']);
$img = ($travm['type'] == 0) ?'' :$travm['power'];
$return .= "
";
$left += 36;
if ($i % 3 == 0)
{
$top += 23;
$left = 0;
}
$i++;
}
return $return;
}
/*Получение изображения предмета, одетого на персонажа*/
function getItemEquiped ($item_id, $i_type)
{
$lang = $this->getLang();
$image = $this->db->selectRow("SELECT `width`, `height`, `default`, `low_level`, `level` FROM `server_images` WHERE `name` = ?s", 'item_'.$i_type);
$default = "
";
if (!is_numeric($item_id))
return $default;
$level = $this->getChar('char_db', 'level');
if ($item_id == 0 && $level < $image['level'])
return "
";
else if ($item_id == 0)
return $default;
$color = '';
$img = $image['default'];
$desc = $this->getItemAlt($item_id, $color, $img);
if (!$desc)
return $default;
$slot = $this->getItemSlot($item_id);
return "
";
}
/*Получение всплывающей подсказки о предмете*/
function getItemAlt ($item_id, &$color = '', &$img = '')
{
if (checki($item_id))
return '';
$lang = $this->getLang();
$i_info = $this->db->selectRow("SELECT `c`.`tear_cur`, `c`.`tear_max`,
`i`.`attack`, `i`.`brick`,
`i`.`name`, `i`.`img`,
`i`.`add_hp`, `i`.`add_mp`,
`i`.`def_h`, `i`.`def_a`,
`i`.`def_b`, `i`.`def_l`
FROM `character_inventory` AS `c`
LEFT JOIN `item_template` AS `i`
ON `c`.`item_entry` = `i`.`entry`
WHERE `c`.`guid` = ?d
and `c`.`id` = ?d", $this->guid, $item_id);
if (!$i_info)
return '';
$img = $i_info['img'];
$tear_check = ($i_info['tear_cur'] >= $i_info['tear_max'] * 0.90);
$tear_show = ($tear_check) ?'%s' :'%s';
$color = ($tear_check) ?" class='broken'" :'';
$def = array('h', 'a', 'b', 'l');
$desc = $i_info['name'];
if ($i_info['attack'] > 0)
$desc .= "
$lang[damage] $i_info[attack] - ".($i_info['attack'] + $i_info['brick']);
$desc .= "
$lang[durability] ".sprintf($tear_show, intval($i_info['tear_cur'])."/".ceil($i_info['tear_max']));
return $desc;
}
/*Получение отформатированного кубика*/
private function getFormatedBrick ($min, $brick)
{
$first = $min - 1;
$second = $brick + 1;
if ($min == 1) return "(d$second)";
if ($brick == 0) return '';
if ($min <= 0) return '';
return "($first+d$second)";
}
/*Получение слота в который одет предмет*/
function getItemSlot ($item_id)
{
if (checki($item_id))
return;
$char_equip = $this->getChar('char_equip', 'helmet', 'bracer', 'hand_r', 'armor', 'shirt', 'cloak', 'belt', 'earring', 'amulet', 'ring1', 'ring2', 'ring3', 'gloves', 'hand_l', 'pants', 'boots');
foreach ($char_equip as $key => $value)
{
if ($item_id == $value)
return $key;
}
return;
}
/*Показ строки персонажа*/
function getLogin ()
{
$char_db = $this->getChar('char_db', 'login', 'level', 'orden', 'clan', 'clan_short', 'rang');
list($login, $level, $orden, $clan_f, $clan_s, $rang) = array_values($char_db);
switch ($orden)
{
case 1: $orden_img = "
"; break;
case 2: $orden_img = "
"; break;
case 3: $orden_img = "
"; break;
case 4: $orden_img = "
"; break;
case 5: $orden_img = "
"; break;
default: $orden_img = ""; break;
}
$clan = ($clan_s != '') ?"
" :"";
$login_link = str_replace(" ", "%20", $login);
$login_info = "
";
return "
$orden_img$clan$login [$level]$login_info";
}
/*Показ дополнительной информации по персонажу*/
function showInfDetail ()
{
$char_db = $this->getChar('char_db', 'dealer', 'sex', 'block', 'block_reason', 'chat_shut', 'prison', 'prison_reason');
$lang = $this->getLang();
echo ($char_db['dealer']) ?"
" :""; /*Дилер*/
echo ($char_db['block']) ?"Причина блока :
$char_db[block_reason]
" :""; /*Блок*/
echo ($char_db['chat_shut']) ?"
На персонажа наложено заклятие молчания. Будет молчать еще ".getFormatedTime($char_db['chat_shut'])."
" :""; /*Молчанка*/
echo ($char_db['prison']) ?"
В заточении еще ".getFormatedTime($char_db['prison'])."
Сообщение от юстициары:
$char_db[prison_reason]
" :""; /*Тюрьма*/
/*Травма*/
$travms = $this->db->select("SELECT *
FROM `character_travms` AS `c`
LEFT JOIN `player_travms` AS `i`
ON `c`.`travm_id` = `i`.`id`
WHERE `c`.`guid` = ?d", $this->guid);
foreach ($travms as $travm)
{
$format = '
%1$s';
switch ($travm['type'])
{
case 0:
if ($travm['id'] == 100)
printf($format, "Персонаж ослаблен из-за смерти в бою, еще ".getFormatedTime($travm['end_time']));
else if ($travm['id'] == 1)
printf($format, "У персонажа тяжелая травма, \"$travm[name]\" еще ".getFormatedTime($travm['end_time'])."");
break;
case 1:
$alt = ($travm['power'] == 5) ?"Не может драться, перемещаться и передавать предметы" :"Ослаблены характеристики";
printf($format, "У персонажа ".lowercase($lang['travm_p_'.$travm['power']])." - \"$travm[name]\" еще ".getFormatedTime($travm['end_time'])."");
break;
case 2:
$format = '
%1$s';
printf($format, "У персонажа магическая травма, еще ".getFormatedTime($travm['end_time']));
break;
}
}
}
/*Получение информации о городе*/
function getCity ()
{
$args = func_get_args();
$args_num = func_num_args();
$city = $args[0];
unset($args[0]);
if ($args_num == 2)
return $this->db->selectCell("SELECT ?# FROM `server_cities` WHERE `city` = ?s", $args, $city);
else
return $this->db->selectRow("SELECT ?# FROM `server_cities` WHERE `city` = ?s", $args, $city);
}
/*Получение информации о комнате*/
function getRoom ()
{
$args = func_get_args();
$args_num = func_num_args();
$room = $args[0];
$city = $this->getCity($args[1], 'flag');
unset($args[0], $args[1]);
if ($args_num == 3)
return $this->db->selectCell("SELECT ?# FROM `city_rooms` WHERE `room` = ?s and `city` & ?d", $args, $room, $city);
else
return $this->db->selectRow("SELECT ?# FROM `city_rooms` WHERE `room` = ?s and `city` & ?d", $args, $room, $city);
}
}
/*Вывод js скрипта*/
function echoScript ($str, $die = false)
{
echo "";
if ($die)
die();
}
/*Преобразование массива в переменные*/
function ArrToVar ($arr, $pref = '')
{
foreach ($arr as $key => $value)
{
$var = (empty($pref)) ?$key :$pref.$key;
global ${$var};
${$var} = $value;
}
}
/*Получение времени восстановления здоровья*/
function getCureValue ($now, $all, $regen, &$value)
{
$value = intval(30000*($all-$now)/($all*$regen)) + time();
}
/*Получение количества восстановленного здоровья*/
function getRegeneratedValue ($all, $cure, $regen)
{
return ($all - intval(0.0001*$all*$cure*$regen/3));
}
/*Получение отформатированного времени*/
function getFormatedTime ($timestamp)
{
if (!$timestamp)
return "0 сек.";
if (!is_numeric($timestamp))
$timestamp = time();
$seconds = ($timestamp > time()) ?$timestamp - time() :time() - $timestamp;
$seconds = ($seconds > 0) ?$seconds :0;
$y = intval($seconds / 31536000);
$seconds %= 31536000;
$m = intval($seconds / 2592000);
$seconds %= 2592000;
$d = intval($seconds / 86400);
$seconds %= 86400;
$h = intval($seconds / 3600);
$seconds %= 3600;
$n = intval($seconds / 60);
$seconds %= 60;
$s = $seconds;
if ($y && $m == 0) return "$y г.";
if ($y) return "$y г. $m мес.";
if ($m && $d == 0) return "$m мес.";
if ($m) return "$m мес. $d дн.";
if ($d && $h == 0) return "$d дн.";
if ($d) return "$d дн. $h ч.";
if ($h && $n == 0) return "$h ч.";
if ($h) return "$h ч. $n мин.";
if ($n && $s == 0) return "$n мин.";
if ($n) return "$n мин. $s сек.";
return "$s сек.";
}
/*Получение цвета улучшения*/
function getColor ($cur, $add)
{
$diff = ($add > 0) ?(1 - (($cur - $add) / $cur)) * 255 :($add < 0) ?(1 -(($cur - $add*(-1)) / $cur)) * 255 :-50;
$diff = abs (intval ($diff)) + 50;
if ($diff > 150 && $add > 0) return "#00AA00";
if ($diff > 150 && $add < 0) return "#AA0000";
if ($add > 0) return "RGB(0, $diff, 0)";
if ($add < 0) return "RGB($diff, 0, 0)";
return "RGB(0, 0, 0)";
}
/*Получение разбивки статов*/
function getBraces ($stat, $added_stat, $type = '')
{
if ($added_stat > 0) return " (".($stat-$added_stat)." + $added_stat)";
if ($added_stat < 0) return " (".($stat-$added_stat)." - ".abs($added_stat).")";
}
/*Error log function*/
function databaseErrorHandler ($message, $info)
{
if (!error_reporting())
return;
echo "";
echo "";
echo "SQL Error: $message
".print_r($info, true)." |
";
echo "";
echo "
";
}
/*Получение переменной GET, POST и COOKIE*/
function getVar ($var, $stand = '', $flags = 3)
{
if (isset($_GET[$var]) && ($flags & 1))
$value = $_GET[$var];
else if (isset($_POST[$var]) && ($flags & 2))
$value = $_POST[$var];
else if (isset($_COOKIE[$var]) && ($flags & 4))
$value = $_COOKIE[$var];
else
return $stand;
if (is_numeric($stand) && is_numeric($value)) return ($flags & 8) ?rdf($value) :$value;
else if (!is_numeric($stand)) return htmlspecialchars($value);
else return $stand;
}
/*Получение место перехода*/
function toIndex ()
{
echoScript("location.href = 'index.php';", true);
}
/*Проверка существования и правильного формата числа*/
function checki ($int)
{
return (!is_numeric($int) || $int == 0);
}
/*Получение названия таблицы*/
function getTable ($name)
{
switch ($name)
{
case 'char_db': return 'characters';
case 'char_stats': return 'character_stats';
case 'char_info': return 'character_info';
case 'char_equip': return 'character_equip';
case 'char_bars': return 'character_bars';
}
}
/*Преобразование русско-язычной строки в нижний и верхний регистр*/
define('UPCASE', 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯABCDEFGHIKLMNOPQRSTUVWXYZ');
define('LOCASE', 'абвгдеёжзийклмнопрстуфхцчшщъыьэюяabcdefghiklmnopqrstuvwxyz');
function mb_str_split ($str)
{
preg_match_all('/.{1}|[^\x00]{1}$/us', $str, $ar);
return $ar[0];
}
function mb_strtr ($str, $from, $to)
{
return str_replace(mb_str_split($from), mb_str_split($to), $str);
}
function lowercase ($arg = '')
{
return mb_strtr($arg, UPCASE, LOCASE);
}
function uppercase ($arg = '')
{
return mb_strtr($arg, LOCASE, UPCASE);
}
/*Определение знака зодиака (Неиспользуется)
function getZodiac ($birthday)
{
$b = split('\.', $birthday);
$zodiac = array('1.3.21.4.20', '2.4.21.5.20', '3.5.21.6.20', '4.6.21.7.22', '5.7.23.8.22', '6.8.23.9.23', '7.9.24.10.23', '8.10.24.11.21', '9.11.22.12.21', '10.12.22.1.19', '11.1.20.2.18', '12.2.19.3.20');
foreach ($zodiac as $value)
{
$d = split('\.', $value);
if (($b[1] == $d[1] && $b[0] >= $d[2] && $b[0] <= 31) || ($b[1] == $d[3] && $b[0] >= 1 && $b[0] <= $d[4]))
return $d[0];
}
}*/
/*Вывод ошибки*/
function error ($text)
{
echoScript("$('title').html('Произошла ошибка');");
echoScript("$('link[rel=StyleSheet]').remove();");
die("Произошла ошибка:
$text
Назад
(c) Анти Бойцовский клуб
");
}
?>