function attack_npc($char, $npc_id, $FROM_aggro_npc = 0, $shadow = 0) { //Запишем специалиации игрока $skill = take_skills($char['user_id']); if ($shadow == 0 and $FROM_aggro_npc == 0) { $est_plash_monaha_char = mysql_result(myquery("SELECT COUNT(*) FROM game_items WHERE user_id=" . $char['user_id'] . " AND priznak=0 AND used=5 AND item_id=" . plash_monaha . ""), 0, 0); if ($est_plash_monaha_char == 1) { return 0; } } $user_id = $char['user_id']; //NPC всегда атакует "владелец" скрипта if (close_combat == 1 and $user_id != 612 and $FROM_aggro_npc == 0) { return 0; } $current_time = time(); $online_range = $current_time - 300; $boy_exist_flag = 0; $uid = 0; $res = myquery("SELECT combat_id FROM combat_users WHERE npc=1 AND user_id={$npc_id} LIMIT 1"); if (mysql_num_rows($res) > 0) { $res_arr = mysql_fetch_array($res); include_once getenv("DOCUMENT_ROOT") . '/combat/class_combat.php'; if (check_boy($res_arr['combat_id']) != 1) { // Бот уже с кем-то бьётся // Запоминаем uid $uid = $res_arr['combat_id']; $boy_exist_flag = 1; } } //начинаем бой с ботом list($npc_quest_id) = mysql_fetch_array(myquery("SELECT npc_quest_id FROM game_npc WHERE id={$npc_id}")); if ($npc_quest_id == 1) { $user_quest = mysql_result(myquery("SELECT COUNT(*) FROM game_quest_users WHERE user_id={$user_id} AND quest_id=1"), 0, 0); if ($user_quest == 0) { echo '<br>Это квестовый бот, ты не можешь его атаковать<br>'; if (function_exists("save_debug")) { save_debug(); } return 0; } } //движок квестов. проверим, не является ли этот бот созданным движком квестов $attack_user_id = $user_id; include getenv("DOCUMENT_ROOT") . "/quest/quest_engine_types/quests_engine_start_combat.php"; $text = ''; if ($char['HP'] == 0) { if (function_exists("save_debug")) { save_debug(); } return 0; } $join = 1; $current_hod = 0; $combat_type = 1; if ($shadow != 0) { $combat_type = 10; } $npc = mysql_fetch_array(myquery("SELECT game_npc.*,game_npc_template.* FROM game_npc,game_npc_template WHERE game_npc.id={$npc_id} AND game_npc.npc_id=game_npc_template.npc_id")); list($maze, $map, $k_exp, $k_gp) = mysql_fetch_array(myquery("SELECT maze,name,k_exp,k_gp FROM game_maps WHERE id=" . $char['map_name'] . "")); if ($maze == 1 and $npc['prizrak'] == 1) { //update_maze_npc_for_user($user_id,$npc_id); $npc = mysql_fetch_array(myquery("SELECT game_npc.*,game_npc_template.* FROM game_npc,game_npc_template WHERE game_npc.id={$npc_id} AND game_npc.npc_id=game_npc_template.npc_id")); } if ($uid == 0) { $join = 0; $uid = create_combat($combat_type, $char['map_name'], $char['map_xpos'], $char['map_ypos'], 0, 0, 0, 1); $side = $npc_id; $npc_ms_kulak = 0; $npc_ms_weapon = 0; $npc_ms_art = 0; $npc_ms_parir = 0; $npc_ms_luk = 0; $npc_ms_sword = 0; $npc_ms_axe = 0; $npc_ms_spear = 0; $npc_ms_throw = 0; $check_options = myquery("SELECT gnso.opt_id, gnsov.number, gnsov.value\n\t\t\t\t\t\t\t\t\tFROM game_npc_set_option gnso\n\t\t\t\t\t\t\t\t\tLEFT JOIN game_npc_set_option_value gnsov ON gnso.id = gnsov.id\n\t\t\t\t \t\t\t WHERE gnso.npc_id=" . $npc['npc_id'] . "\n\t\t\t\t\t\t\t\t ORDER BY opt_id, number"); while ($options = mysql_fetch_array($check_options)) { $npc_options[$options['opt_id']][$options['number']]['value'] = $options['value']; } // Бот копирует навыки игрока if (isset($npc_options[8])) { $npc_ms_parir = $skill['MS_PARIR']; } // Бот копирует жизни игрока if (isset($npc_options[9])) { $koef = $options[9][1]['value']; $npc['HP'] = round($char['HP_MAX'] * $koef / 100); $npc['npc_max_hp'] = $npc['HP']; } // Бот копирует ману игрока if (isset($npc_options[10])) { $koef = $options[10][1]['value']; $npc['MP'] = round($char['MP_MAX'] * $koef / 100); $npc['npc_max_mp'] = $npc['MP']; } // Харки боты основаны на харках игрока if (isset($npc_options[11])) { $type = $options[11][1]['value']; $koef1 = $options[11][2]['value']; $koef2 = $options[11][3]['value']; $koef_har = $koef1 / 100; $koef_dev = $koef2 / 100; switch ($type) { case 1: if ($npc['npc_id'] != npc_id_olen) { $koef_lev = 0.5; } else { $koef_lev = 0; } $npc['npc_pie'] = (mt_rand($char['SPD'] * (1 - $koef_dev), $char['SPD'] * (1 + $koef_dev)) + $koef_lev * $char['clevel'] * 3) * $koef_har; $npc['npc_vit'] = (mt_rand($char['VIT'] * (1 - $koef_dev), $char['VIT'] * (1 + $koef_dev)) + $koef_lev * $char['clevel'] * 1) * $koef_har; $npc['npc_spd'] = (mt_rand($char['PIE'] * (1 - $koef_dev), $char['PIE'] * (1 + $koef_dev)) + $koef_lev * $char['clevel'] * 2) * $koef_har; if ($char['NTL'] > $char['STR']) { $npc['npc_str'] = (mt_rand($char['NTL'] * (1 - $koef_dev), $char['NTL'] * (1 + $koef_dev)) + $koef_lev * $char['clevel'] * 3) * $koef_har; $npc['npc_dex'] = mt_rand($char['NTL'] * (1 - $koef_dev), $char['NTL'] * (1 + $koef_dev)) * $koef_har; $npc['npc_ntl'] = (mt_rand($char['NTL'] * (1 - $koef_dev) / 10, $char['NTL'] * (1 + $koef_dev)) / 10 + $koef_lev * $char['clevel'] * 3) * $koef_har; } else { $npc['npc_str'] = (mt_rand($char['STR'] * (1 - $koef_dev) / 10, $char['STR'] * (1 + $koef_dev)) / 10 + $koef_lev * $char['clevel'] * 3) * $koef_har; $npc['npc_dex'] = mt_rand($char['STR'] * (1 - $koef_dev), $char['STR'] * (1 + $koef_dev)) * $koef_har; $npc['npc_ntl'] = (mt_rand($char['STR'] * (1 - $koef_dev), $char['STR'] * (1 + $koef_dev)) + $koef_lev * $char['clevel'] * 3) * $koef_har; } $npc_hp0 = $npc['npc_dex'] * 10 + 10 + 1.5 * $char['clevel']; $npc_mp0 = $npc['npc_ntl'] * 10 + 10 + 1.5 * $char['clevel']; //TODO сделать шаблон бота с расой "Минотавр Лабиринта" if ($npc['npc_race'] == 'Минотавр Лабиринта') { $npc['HP'] = $npc_hp0 * 10; $npc['MP'] = $npc_mp0 * 10; $npc['npc_max_hp'] = $npc_hp0 * 10; $npc['npc_max_mp'] = $npc_mp0 * 10; $npc['npc_str'] = $npc['npc_str'] * 3; $npc['npc_dex'] = $npc['npc_dex'] * 3; $npc['npc_spd'] = $npc['npc_spd'] * 3; $npc['npc_vit'] = $npc['npc_vit'] * 3; $npc['npc_ntl'] = $npc['npc_ntl'] * 3; $npc['npc_pie'] = $npc['npc_pie'] * 3; } if ($npc['HP'] == 0) { $npc['HP'] = 50; $npc['MP'] = 50; $npc['npc_max_hp'] = 50; $npc['npc_max_mp'] = 50; } $npc['npc_str_deviation'] = 0; $npc['npc_dex_deviation'] = 0; $npc['npc_spd_deviation'] = 0; $npc['npc_vit_deviation'] = 0; $npc['npc_ntl_deviation'] = 0; $npc['npc_pie_deviation'] = 0; break; case 2: $npc['npc_str'] = $char['NTL'] * $koef_har; $npc['npc_str_deviation'] = max(0, $char['NTL'] * $koef_dev); $npc['npc_dex'] = $char['DEX'] * $koef_har; $npc['npc_dex_deviation'] = max(0, $char['DEX'] * $koef_dev); $npc['npc_spd'] = $char['SPD'] * $koef_har; $npc['npc_spd_deviation'] = max(0, $char['SPD'] * $koef_dev); $npc['npc_vit'] = $char['VIT'] * $koef_har; $npc['npc_vit_deviation'] = max(0, $char['VIT'] * $koef_dev); $npc['npc_ntl'] = $char['STR'] * $koef_har; $npc['npc_ntl_deviation'] = max(0, $char['STR'] * $koef_dev); $npc['npc_pie'] = $char['PIE'] * $koef_har; $npc['npc_pie_deviation'] = max(0, $char['PIE'] * $koef_dev); break; } } // Бот восстанавливает здоровье при начале нового боя if (isset($npc_options[13])) { $npc['HP'] = $npc['npc_max_hp']; $npc['MP'] = $npc['npc_max_mp']; } if ($npc['HP'] == 0 or $npc['HP'] > $npc['npc_max_hp']) { $npc['HP'] = $npc['npc_max_hp']; } if ($npc['MP'] == 0 or $npc['MP'] > $npc['npc_max_mp']) { $npc['MP'] = $npc['npc_max_mp']; } myquery("DELETE FROM combat_users WHERE npc=1 AND user_id={$npc_id}"); $ins = myquery("INSERT INTO combat_users (\n\t\tcombat_id,user_id,npc,time_last_active,name,clevel,reinc,side,\n\t\tHP,MP,STM,STR,DEX,SPD,VIT,NTL,PIE,HP_MAX,MP_MAX,STM_MAX,\n\t\tlucky,pol,avatar,race,HP_start,MS_PARIR\n\t\t) VALUES (\n\t\t{$uid},{$npc_id},1," . time() . ",'" . $npc['npc_name'] . "'," . $npc['npc_level'] . ",0,{$side},\n\t\t" . $npc['HP'] . "," . $npc['MP'] . ",10000,\n\t\t" . mt_rand($npc['npc_str'] - $npc['npc_str_deviation'], $npc['npc_str'] + $npc['npc_str_deviation']) . ",\n\t\t" . mt_rand($npc['npc_dex'] - $npc['npc_dex_deviation'], $npc['npc_dex'] + $npc['npc_dex_deviation']) . ",\n\t\t" . mt_rand($npc['npc_spd'] - $npc['npc_spd_deviation'], $npc['npc_spd'] + $npc['npc_spd_deviation']) . ",\n\t\t" . mt_rand($npc['npc_vit'] - $npc['npc_vit_deviation'], $npc['npc_vit'] + $npc['npc_vit_deviation']) . ",\n\t\t" . mt_rand($npc['npc_ntl'] - $npc['npc_ntl_deviation'], $npc['npc_ntl'] + $npc['npc_ntl_deviation']) . ",\n\t\t" . mt_rand($npc['npc_pie'] - $npc['npc_pie_deviation'], $npc['npc_pie'] + $npc['npc_pie_deviation']) . ",\t\t\n\t\t" . $npc['npc_max_hp'] . "," . $npc['npc_max_mp'] . ",10000,\n\t\t'" . $char['lucky'] . "','','" . $npc['npc_img'] . "','" . $npc['npc_race'] . "'," . $npc['npc_max_hp'] . "," . $npc_ms_parir . ")"); combat_setFunc($npc_id, 6, $uid); $check_call = myquery("SELECT t1.npc_id, t2.value as kogo, t3.value as kol\n\t\t\t\t\t\t\tFROM game_npc_set_option AS t1\n\t\t\t\t\t\t\tJOIN game_npc_set_option_value AS t2 ON t1.id = t2.id AND t2.number =1\n\t\t\t\t\t\t\tJOIN game_npc_set_option_value AS t3 ON t1.id = t3.id AND t3.number =2\n\t\t\t\t\t\t\tWHERE t1.opt_id =6 and t1.npc_id=" . $npc['npc_id'] . ""); if (mysql_num_rows($check_call) > 0) { myquery("INSERT INTO game_combats_log_text (combat_id, name, mode) VALUES (" . $uid . ", '" . $npc['npc_name'] . "', " . $npc['id'] . ")"); $text_id = mysql_insert_id(); myquery("INSERT INTO game_combats_log_data (boy, user_id, hod, action, kto, text_id) VALUES (" . $uid . ", " . $npc['id'] . ", 0, 81, " . $npc['id'] . ", " . $text_id . ")"); while ($call = mysql_fetch_array($check_call)) { npc_call($npc['id'], $call['kogo'], $call['kol'], $uid); } } } else { $current_hod = mysqlresult(myquery("SELECT hod FROM combat WHERE combat_id={$uid}"), 0, 0); $check_option2 = myquery("SELECT id FROM game_npc_set_option WHERE opt_id=12 and npc_id=" . $npc['npc_id'] . ""); if (mysql_num_rows($check_option2) > 0) { list($npc_opt) = mysql_fetch_array($check_option2); list($type_npc) = mysql_fetch_array(myquery("SELECT value FROM game_npc_set_option_value WHERE id={$npc_opt}")); switch ($type_npc) { case 1: $no_boy = 1; break; case 2: $check_boy = myquery("SELECT * FROM game_combats_log_data WHERE user_id={$user_id} and boy={$uid}"); if (mysql_num_rows($check_boy) > 0) { $no_boy = 1; } break; } } } if (!isset($no_boy) or $no_boy != 1) { $side = 1; if ($join == 0) { $func = 5; } else { $func = 6; } if ($shadow == 0) { $delay = 12; save_stat($user_id, '', '', 8, '', '', $npc_id, '', '', '', '', ''); } else { $delay = 45; } //Закинем игрока в бой combat_insert($char, 0, $uid, $combat_type, $side, $current_hod, $join, 0, 0, $k_exp / 100, $k_gp / 100, $skill, $func, $delay, 0, 0); //Отработаем действие навыка "Убийца" if ($skill['SLAYER'] > 0) { $r = mt_rand(1, 100); if ($r <= $skill['SLAYER'] * 2 + 5) { $effect = $skill['SLAYER'] * 5; insert_fast_effect($user_id, $npc_id, $uid, $current_hod + 1, 42, $effect); } } setLocation("http://" . domain_name . "/combat.php"); } else { echo '<b><center>Дождитесь, пока закончится текущий бой!</center></b>'; } }
myquery("update game_users set CW=CW + {$weight} where user_id=" . $char['user_id'] . ""); myquery("update game_users_archive set CW=CW + {$weight} where user_id=" . $char['user_id'] . ""); } } $j++; myquery("UPDATE game_cron_log SET step='" . $j . ". Сбрасываем неактивных игроков из крафта', timecron=" . time() . " WHERE id={$idcronlog}"); myquery("UPDATE craft_build_lumberjack SET user_id=0 WHERE user_id NOT IN (SELECT user_id FROM view_active_users)"); myquery("UPDATE craft_build_stonemason SET user_id=0 WHERE user_id NOT IN (SELECT user_id FROM view_active_users)"); myquery("UPDATE craft_build_lumberjack SET reserve_user_id=0,reserve_time=0 WHERE user_id NOT IN (SELECT user_id FROM view_active_users)"); myquery("UPDATE craft_build_stonemason SET reserve_user_id=0,reserve_time=0 WHERE user_id NOT IN (SELECT user_id FROM view_active_users)"); myquery("UPDATE craft_build_mining SET user_id=0 WHERE user_id NOT IN (SELECT user_id FROM view_active_users)"); $j++; $r = mt_rand(1, 100); if ($r <= 4) { myquery("UPDATE game_cron_log SET step='" . $j . ". Автомногоклан', timecron=" . time() . " WHERE id={$idcronlog}"); start_combat(4, 3); } $j++; myquery("UPDATE game_cron_log SET step='" . $j . ". Очистка пустых боев', timecron=" . time() . " WHERE id={$idcronlog}"); require_once "/home/vhosts/rpg.su/web/inc/define.inc.php"; //require_once("/home/vhosts/rpg.su/web/inc/lib.inc.php"); require_once "/home/vhosts/rpg.su/web/class/class_timer.php"; require_once "/home/vhosts/rpg.su/web/class/class_item.php"; require_once "/home/vhosts/rpg.su/web/combat/class_combat.php"; require_once "/home/vhosts/rpg.su/web/inc/combat/combat.inc.php"; $close_combat = 60 * 60 * 24 * 2; $sel = myquery("SELECT combat_id FROM combat WHERE time_last_hod<" . (time() - $close_combat) . ""); while (list($combat_id) = mysql_fetch_array($sel)) { check_boy($combat_id); } myquery("UPDATE game_cron_log SET step='final', timecron=" . time() . " WHERE id={$idcronlog}");
public function user_out($user_id) { $this->break_items($user_id, 0); //уменьшим текущий ресурс прочности предметов $this->user_teleport($user_id); $travma = 0; if ($this->combat['npc'] == 0) { if ($this->all[$user_id]['clevel'] >= 15) { $travma = 1; } myquery("UPDATE game_users_data SET last_timeout=" . time() . ",last_timeout_boy=" . $this->combat['combat_id'] . " WHERE user_id={$user_id}"); //!!!Отключено!!! //если среди противников только 1 живой игрок - тогда победу дадим ему, если несколько, то победу даем рандомно // $prot = array(); // foreach($this->all AS $key=>$value) // { // if ($value['side']!=$this->all[$user_id]['side']) // { // $prot[] = $key; // } // } // $user_win_id = 0; // if (count($prot)==1) // { // $user_win_id = $prot[0]; // } // else // { // $r = mt_rand(0,count($prot)-1); // $user_win_id = $prot[$r]; // } // if ($user_win_id>0) // { // if ($this->all[$user_win_id]['npc']==0) // { // myquery("UPDATE game_users SET WIN=WIN+1 WHERE user_id=$user_win_id"); // } // else // { // myquery("UPDATE game_npc SET WIN=WIN+1 WHERE id=$user_win_id"); // } // } } else { //таймаут в бою с ботами $this->check_quest_lose($user_id); } //статистика if (function_exists("save_stat")) { save_stat($user_id, '', '', 3, '', '', '', '', '', '', '', ''); } //за вылетевшего по тайму дадим опыта = опыт за полное убийство/количество противников, но не более 10% и если вылет идет на первом ходу $all = array(); foreach ($this->all as $key => $value) { if ($this->all[$key]['side'] == $this->all[$user_id]['side']) { continue; } if ($this->all[$key]['npc'] == 0) { if ($this->all[$key]['HP'] > 0) { $all[] = $key; } } } if (count($all) > 0) { $k = min(0.1, 1 / count($all)); } else { $k = 0; } $gp = 0; foreach ($all as $key => $value) { $exp = $this->formula_exp($this->all[$user_id], $this->all[$value], -1); if ($exp != 0 or $gp != 0) { myquery("INSERT INTO combat_users_exp (combat_id,user_id,prot_id,exp,gp) VALUES (" . $this->combat['combat_id'] . "," . $value . "," . $user_id . ",{$exp},{$gp}) ON DUPLICATE KEY UPDATE exp=exp+{$exp},gp=gp+{$gp}"); } } //переводим накопленный опыт в очки опыта $this->nachisl_exp_gp($user_id, 1); $query = "UPDATE game_users SET HP=1,MP=1,STM=1"; //$travma = 0;//Временно убираем травмы! if ($travma == 1) { $query .= ",injury=LEAST(1300,injury+13)"; } if ($this->combat['npc'] == 0) { $query .= ",LOSE=LOSE+1"; } $query .= " WHERE user_id={$user_id}"; myquery($query); combat_setFunc($user_id, 8, $this->combat['combat_id'], $this->combat['hod']); $this->clear_user($user_id); check_boy($this->combat['combat_id']); //запишем в лог хода if ($this->all[$user_id]['pol'] == 'female') { $log_id = 53; $mes = "Ты сбежала с поля боя"; } else { $log_id = 54; $mes = "Ты сбежал с поля боя"; } $text_id = 0; $sel_text_id = myquery("SELECT id FROM game_combats_log_text WHERE name='" . $this->all[$user_id]['name'] . "' AND mode='" . $user_id . "'"); if (mysql_num_rows($sel_text_id) == 0) { myquery("INSERT INTO game_combats_log_text (combat_id, name,mode) VALUES ('" . $this->combat['combat_id'] . "', '" . $this->all[$user_id]['name'] . "', " . $user_id . ")"); $text_id = mysql_insert_id(); } else { list($text_id) = mysql_fetch_array($sel_text_id); } myquery("INSERT INTO game_combats_log_data (boy,user_id,hod,action,na_kogo) VALUES (" . $this->combat['combat_id'] . ", 0, " . $this->combat['hod'] . ", " . $log_id . ", " . $text_id . ")"); myquery("INSERT game_battles SET attacker_id=" . $user_id . ", target_id=0, map_name=" . $this->combat['map_name'] . ", map_xpos=" . $this->combat['map_xpos'] . ", map_ypos=" . $this->combat['map_ypos'] . ", contents='" . mysql_real_escape_string($mes) . "', post_time=" . time() . ""); }