battles/cronjobs/cron_bots_battle.php

1549 lines
86 KiB
PHP
Raw Normal View History

2018-01-28 16:40:49 +00:00
<?php
/**
* Copyright (c) 2018.
* Author: Igor Barkov <lopar.4ever@gmail.com>
* Project name: Battles-Game
*/
2018-01-28 16:40:49 +00:00
include('config.php');
include('functions.php');
include('cave/cave_bots.php');
$cavebots = $botnames;
function addlogs($id, $log) {
$fp = fopen("backup/logs/battle".$id.".txt", "a");
flock($fp, LOCK_EX);
fputs($fp, $log);
fflush($fp);
flock($fp, LOCK_UN);
fclose($fp);
unset($id, $log);
}
class fbattle {
public $status = integer;
public $battle = array();
public $battle_data = array();
public $enemy = null;
public $damage = array();
public $t1 = array();
public $t2 = array();
public $team_enemy = array();
public $team_mine = array();
public $user = array();
public $enemyhar = array();
public $enemy_dress = array();
public $user_dress = array();
public $en_class, $my_class;
public $bots = array();
public $botsid = array();
public $log = '';
public $to1;
public $to2;
public $exp = array();
public $log_debug = '';
public $needrefresh = 0;
public $rep = 0;
public $needupdate = 0;
public $har = array();
public $color_battle = array();
public $mf = array();
public $user_inf_1 = array();
public $user_inf_2 = array();
public $max = 70;
public $err = '';
function fbattle($battle_id) {
global $user, $_POST, $cavedata, $caverooms;
$this->user = $user;
if($battle_id > 0) {
$this->status = 1;
$this->battle_data = mysql_fetch_array(mysql_query("SELECT `id`, `coment`, `teams`, `timeout`, `razmen_time`, `type`, `status`, `t1`, `t2`, `date`, `time_m`, `win`, `damage`, `to1`, `to2`, `exp`, `blood`, `t1hist`, `t2hist`, `magic`, `open`, `close`, `protivnik`, `protivnik_type`, `dungeon_bot`, `dn_id`, `aren_of`, `needbb`, `clone`, `fiz` FROM `battle` WHERE `id` = '{$battle_id}' LIMIT 1"));
$this->GetUserTeam();
$this->damage = unserialize($this->battle_data['damage']);
$this->magic = unserialize($this->battle_data['magic']);
$this->battle = unserialize($this->battle_data['teams']);
$this->exp = unserialize($this->battle_data['exp']);
$this->to1 = $this->battle_data['to1'];
$this->to2 = $this->battle_data['to2'];
#######################
$bit1 = 0; $bit2 = 0;
foreach($this->battle as $k => $v) {
if($k < _BOTSEPARATOR_) continue;
$bot['id'] = $k;
if(in_array($k, $this->t1)) {
if(count($v) < count($this->t2)) {
foreach($this->t2 as $k2 => $v2) {
$this->battle[$k][$v2] = array(0, 0, time());
}
}
$bit1 = 1;
}
if(in_array($k, $this->t2)) {
if(count($v) < count($this->t1)) {
foreach($this->t1 as $k2 => $v2) {
$this->battle[$k][$v2] = array(0, 0, time());
}
}
$bit2 = 1;
}
foreach($this->battle[$bot['id']] as $k => $v) {
if($this->battle[$bot['id']][$k][0] == 0) {
$this->battle[$bot['id']][$k] = array(rand(2, 3), rand(2, 3), time());
if($this->battle[$k][$bot['id']][0] != 0 && $k < _BOTSEPARATOR_) {
$this->battle[$k][$bot['id']] = array(0, 0, time());
}
if($k > _BOTSEPARATOR_) {
$this->needupdate = 1;
}
}
if($this->battle[$k][$bot['id']][0] == 0 && $k < _BOTSEPARATOR_) {
if(in_array($user['id'], array_keys($this->battle[$bot['id']]))) {
if($this->my_class == 'B2') {
if($this->to2 <= $this->to1) {
$endr = ((time()-$this->to2) > $this->battle_data['timeout']*60);
}
} else {
if($this->to2 >= $this->to1) {
$endr = ((time()-$this->to1) > $this->battle_data['timeout']*60);
}
}
}
}
if($endr && !$uje && 0) {
if($user['caveleader'] > 0) {
$this->needrefresh = 1;
}
$this->needupdate = 1;
$this->needrefresh = 1;
$uje = true;
$this->AddToLog("<span class=date>".date("H:i")."</span> Бой закончен по таймауту.<BR>");
foreach($this->battle[$bot['id']] as $k => $v) {
if($k > _BOTSEPARATOR_) {
$bots = mysql_fetch_array(mysql_query('SELECT `hp`, `prototype` FROM `bots` WHERE `id` = "'.$k.'" LIMIT 1'));
$us['hp'] = $bots['hp'];
$b = mysql_fetch_array(mysql_query('SELECT `id`, `level` FROM `users` WHERE `id` = "'.$bots['prototype'].'" LIMIT 1'));
$us['level'] = $b['level'];
} else {
$us = mysql_fetch_array(mysql_query('SELECT `hp`, `level` FROM `users` WHERE `id` = "'.$k.'" LIMIT 1'));
}
if($us && (int)$us['hp'] > 0 && $us['level'] > 6) {
$tr = settravma($k, 0, 86400, 1);
if($k < _BOTSEPARATOR_ && $tr) {
$this->AddToLog('<span class=date>'.date("H:i").'</span> <b>'.nick7($k).'</b> получил повреждение: <font color=red>'.$tr.'</font><BR>');
}
}
}
foreach($this->battle[$bot['id']] as $k => $v) {
$this->user[$k]['hp'] = 0;
mysql_query('UPDATE `users` SET `hp` = 0, `fullhptime` = '.time().' WHERE `id` = "'.$k.'"');
}
}
}
}
$bb = ($bit1+$bit2);
if($this->battle_data['needbb'] != $bb) {
mysql_query("UPDATE `battle` SET `needbb` = '$bb' WHERE `id` = '".$this->battle_data['id']."' LIMIT 1");
}
#######################
if($_POST['enemy'] > 0 && (int)$_POST['attack'] > 0 && (int)$_POST['defend'] > 0) {
$this->InitRazmen($_POST['enemy'], $_POST['attack'], $_POST['defend']);
$this->magic[$user['id']] = 0;
mysql_query("UPDATE `battle` SET `magic` = '".serialize($this->magic)."' WHERE `id` = '".$this->battle_data['id']."' LIMIT 1");
header("Location: fbattle.php");
} else {
$this->GetUserTeam();
$this->FastDeath();
$this->enemy = $this->SelectEnemy();
if($this->enemy) {
$this->return = 1;
} else {
if($this->GetTimeout() && (int)$this->user['hp'] > 0 && !$_POST['victory_time_out2']) {
$this->return = 3;
} else {
$this->magic[$user['id']] = 0;
mysql_query("UPDATE `battle` SET `magic` = '".serialize($this->magic)."' WHERE `id` = '{$this->battle_data['id']}' LIMIT 1");
$this->return = 2;
}
}
}
if($_POST['victory_time_out2']) {
$this->end_draft();
}
if($_POST['victory_time_out']) {
$this->end_gora();
}
if($this->battle_end()) {
$this->return = 2;
}
$this->write_log();
return $this->return;
} else {
$this->status = 0;
}
}
function getmfs($mf, $antimf) {
$vsh = 5 + (($mf - $antimf) / 3);
if($vsh <= 0) {
$final = 0;
} else {
$final = 70 + ($vsh / 100);
}
return $final;
}
function chanse($p) {
if($p > mt_rand(1, 100)) {
return true;
} else {
return false;
}
}
function get_info_by_id($id) {
$valid_login = mysql_query('SELECT `id`, `login`, `align`, `level`, `sila`, `lovk`, `inta`, `vinos`, `intel`, `maxhp`, `weap`, `noj`, `dubina`, `topor`, `mec`, `ubron1`, `ubron2`, `ubron3`, `ubron4`, `bot` FROM `users` WHERE `id` = "'.$id.'" AND `bot` = 0 LIMIT 1');
if(mysql_num_rows($valid_login) == 1) {
$user_info = mysql_fetch_array($valid_login);
} else {
$prototype = mysql_fetch_array(mysql_query('SELECT `id`, `name`, `prototype`, `battle`, `hp` FROM `bots` WHERE `id` = "'.$id.'" LIMIT 1'));
$user_info = mysql_fetch_array(mysql_query('SELECT `id`, `login`, `align`, `level`, `sila`, `lovk`, `inta`, `vinos`, `intel`, `maxhp`, `weap`, `noj`, `dubina`, `topor`, `mec`, `ubron1`, `ubron2`, `ubron3`, `ubron4`, `bot` FROM `users` WHERE `id` = "'.$prototype['prototype'].'" LIMIT 1'));
}
return $user_info;
}
function get_wep_type($idwep) {
if($idwep == 0 || $idwep == null || $idwep == '') {
return "kulak";
}
$wep = mysql_fetch_array(mysql_query('SELECT `otdel`, `minu` FROM `inventory` WHERE `id` = "'.$idwep.'" LIMIT 1'));
if($wep[0] == '1') {
return "noj";
} elseif($wep[0] == '12') {
return "dubina";
} elseif($wep[0] == '11') {
return "topor";
} elseif($wep[0] == '13') {
return "mech";
} elseif($wep[0] == '52') {
return "posoh";
} elseif($wep[1] > 0) {
return "buket";
} else {
return "kulak";
}
}
function get_chanse($persent) {
$mm = 1000000;
if(mt_rand($mm, 100*$mm) <= $persent*$mm) {
return true;
} else {
return false;
}
}
function get_block($who, $where_atack, $whom, $where_defend) {
$blocks = array('1' => array(1, 2), '2' => array(2, 3), '3' => array(3, 4), '4' => array(4, 1));
if(!in_array($where_atack, $blocks[$where_defend])) {
return true;
} else {
return false;
}
}
function add_log($text) {
$this->log .= $text;
}
function battle_end() {
global $caverooms, $user, $cavebots, $party, $rep;
if($this->battle_data) {
$ss = @array_keys($this->battle);
$t1life = 0; $t2life = 0;
foreach($this->t1 as $k => $v) {
if(in_array($v, array_keys($this->battle))) {
$t1life++;
}
}
foreach($this->t2 as $k => $v) {
if(in_array($v, array_keys($this->battle))) {
$t2life++;
}
}
if($t2life == 0 || $t1life == 0) {
$charge = mysql_fetch_array(mysql_query('SELECT `win` FROM `battle` WHERE `id` = "'.$this->battle_data['id'].'" LIMIT 1'));
}
if(($t2life == 0 || $t1life == 0) && ($charge[0] == 3 || $charge[0] == 9)) {
mysql_query("UPDATE `battle` SET `win` = 0 WHERE `id` = '{$this->battle_data['id']}' LIMIT 1");
foreach($this->t1 as $k => $v) {
$nks1[] = nick7($v);
$nks1hist[] = nick3($v);
}
foreach($this->t2 as $k => $v) {
$nks2[] = nick7($v);
$nks2hist[] = nick3($v);
}
if(in_array($ss[0], $this->t1)) {
$flag = 1;
foreach($this->t1 as $k => $v) {
mysql_query('UPDATE `battle` SET `win` = 1 WHERE `id` = "'.$this->battle_data['id'].'" LIMIT 1');
$this->t1[$k] = nick5($v, " ");
if($this->battle_data['aren_of'] == 1 && $this->t1[$k] && $v < _BOTSEPARATOR_) {
mysql_query('INSERT INTO `logs_arena` (`battle`, `user`, `uid`, `damage`, `team`) VALUES ("'.$this->battle_data['id'].'", "'.$this->t1[$k].'", "'.$v.'", "'.$this->damage[$v].'", "1")');
}
if($this->user['in_tower'] > 0) {
}
if($this->user['x'] != 0 || $this->user['y'] != 0 && $this->user['laba'] > 0) {
$lobj = mysql_fetch_array(mysql_query('SELECT * FROM `laba_obj` WHERE `lib` = "'.$this->user['laba'].'" AND `x` = "'.$this->user['x'].'" AND `y` = "'.$this->user['y'].'" LIMIT 1'));
if(isset($lobj['id'])) {
$q2 = mysql_fetch_array(mysql_query('SELECT * FROM `qst_user` WHERE `uid` = "'.$this->user['id'].'" AND `cancel` = "0" AND `finish` = "0" LIMIT 1'));
if(isset($q2['id'])) {
$q1 = mysql_fetch_array(mysql_query('SELECT * FROM `qst` WHERE `id` = "'.$q2['qid'].'" LIMIT 1'));
if($q1['type'] == 3) {
$jobs = 0;
$sp = mysql_query('SELECT * FROM `bots` WHERE `battle` = "'.$this->battle_data['id'].'"');
while($pl = mysql_fetch_array($sp)) {
if($q1['obj_id'] == $pl['prototype']) {
$jobs++;
}
}
mysql_query('UPDATE `qst_user` SET `val` = "'.($q2['val'] + $jobs).'" WHERE `id` = "'.$q2['id'].'" LIMIT 1');
}
}
mysql_query('UPDATE `laba_obj` SET `use` = "'.time().'" WHERE `lib` = "'.$lobj['lib'].'" AND `x` = "'.$lobj['x'].'" AND `y` = "'.$lobj['y'].'"');
}
}
$this->exp[$v] = round($this->exp[$v]);
$dop_exp = check_proc($this->user['id']);
if($dop_exp > 100) {
$add = ($dop_exp-100);
$this->exp[$v] += round(($this->exp[$v]*$add)/100, 0);
}
if($user['caveleader'] > 0 || $user['laba'] > 0) {
if($this->damage[$v] > 1) {
$this->exp[$v] = mt_rand(5, 10);
} else {
$this->exp[$v] = 0;
}
}
if(empty($this->damage[$v])) {
$this->damage[$v] = 0;
}
if($user['caveleader'] > 0 || $user['laba'] > 0) {
$rep = floor($this->damage[$v]/300);
if($rep <= 0) {
$rep = 0;
}
$ads = '. Репутации: '.$rep.' ед.';
} else {
$rep = 0;
$ads = '.';
}
if($this->battle_data['clone'] == 1 && $this->battle_data['fiz'] == 0) {
addActions(time(), 'kill_clone', 0, $this->user['id']);
}
if($this->battle_data['type'] == 3) {
addActions(time(), 'win_haot', 0, $this->user['id']);
}
if($this->battle_data['fiz'] == 1) {
addActions(time(), 'win_fiz', 0, $this->user['id']);
}
addchp('<font color=red>Внимание!</font> Победа! Бой окончен. Всего вами нанесено урона : '.$this->damage[$v].' HP. Получено опыта : '.$this->exp[$v].' ('.$dop_exp.'%)'.$ads.' ', '{[]}'.nick7 ($v).'{[]}');
mysql_query('UPDATE `users` SET `win` = (`win` +1), `fullhptime` = '.time().' WHERE `id` = "'.$v.'"');
GiveExp($v, $this->exp[$v]);
if($user['caveleader'] > 0 || $user['laba'] > 0) {
GiveRep($v, $rep);
}
if($user['klan']) {
mysql_query('UPDATE `clans` SET `clanexp` = (`clanexp`+'.(int)$this->exp[$user['id']].') WHERE `id` = "'.$v[$user['klan']].'" LIMIT 1');
}
}
$winers .= implode("</B>, <B>", $this->t1);
$lomka = $this->t2;
include('cave/win.php');
} elseif(in_array($ss[0], $this->t2)) {
$flag = 2;
foreach($this->t2 as $k => $v) {
mysql_query('UPDATE `battle` SET `win` = 2 WHERE `id` = "'.$this->user['battle'].'" LIMIT 1');
$this->t2[$k] = nick5($v, "");
if($this->battle_data['aren_of'] == 1 && $this->t2[$k] && $v < _BOTSEPARATOR_) {
mysql_query('INSERT INTO `logs_arena` (`battle`, `user`, `uid`, `damage`, `team`) VALUES ("'.$this->user['battle'].'", "'.$this->t1[$k].'", "'.$v.'", "'.$this->damage[$v].'", "2")');
}
if($this->user['laba'] > 0) {
mysql_query('UPDATE `users` SET `x` = "'.$this->user['xf'].'", `y` = "'.$this->user['yr'].'" WHERE `id` = "'.$this->user['id'].'" LIMIT 1');
}
$this->exp[$v] = round($this->exp[$v]);
$dop_exp = check_proc($this->user['id']);
if($dop_exp > 100) {
$add = ($dop_exp-100);
$this->exp[$v] += round(($this->exp[$v]*$add)/100, 0);
}
if($user['caveleader'] > 0 || $user['laba'] > 0) {
if($this->damage[$v] > 1) {
$this->exp[$v] = mt_rand(5, 10);
} else {
$this->exp[$v] = 0;
}
}
if($this->battle_data['clone'] == 1 && $this->battle_data['fiz'] == 0) {
addActions(time(), 'kill_clone', 0, $this->user['id']);
}
if($this->battle_data['type'] == 3) {
addActions(time(), 'win_haot', 0, $this->user['id']);
}
if($this->battle_data['fiz'] == 1) {
addActions(time(), 'win_fiz', 0, $this->user['id']);
}
if(in_array($user['room'], $caverooms)) {
$location = mysql_fetch_array(mysql_query("SELECT `x`, `y`, `dir` FROM `caveparties` WHERE `user` = '".$this->user['id']."' LIMIT 1"));
if($location['dir'] == 0) { $y = $location['y']*2; $x = ($location['x']-1)*2; }
if($location['dir'] == 1) { $y = ($location['y']-1)*2; $x = $location['x']*2; }
if($location['dir'] == 2) { $y = $location['y']*2; $x = ($location['x']+1)*2; }
if($location['dir'] == 3) { $y = ($location['y']+1)*2; $x = $location['x']*2; }
mysql_query("UPDATE `cavebots` SET `battle` = 0 WHERE `battle` = '".$this->battle_data['id']."'");
}
addchp('<font color=red>Внимание!</font> Победа! Бой окончен. Всего вами нанесено урона : '.(int)$this->damage[$v].' HP. Получено опыта '.$this->exp[$v].' ('.$dop_exp.'%). ','{[]}'.nick7 ($v).'{[]}');
mysql_query('UPDATE `users` SET `win` = (`win`+1), `fullhptime` = '.time().' WHERE `id` = "'.$v.'"');
GiveExp($v, $this->exp[$v]);
}
$winers .= implode("</B>, <B>", $this->t2);
$lomka = $this->t1;
} else {
if(in_array($user['room'], $caverooms)) {
$location = mysql_fetch_array(mysql_query("SELECT `x`, `y`, `dir` FROM `caveparties` WHERE `user` = '".$this->user['id']."' LIMIT 1"));
if($location['dir'] == 0) { $y = $location['y']*2; $x = ($location['x']-1)*2; }
if($location['dir'] == 1) { $y = ($location['y']-1)*2; $x = $location['x']*2; }
if($location['dir'] == 2) { $y = $location['y']*2; $x = ($location['x']+1)*2; }
if($location['dir'] == 3) { $y = ($location['y']+1)*2; $x = $location['x']*2; }
mysql_query("UPDATE `cavebots` SET `battle` = 0 WHERE `battle` = '".$this->battle_data['id']."'");
}
if($this->battle_data['x'] > 0 || $this->battle_data['y'] > 0 && $this->user['laba'] > 0) {
mysql_query('UPDATE `users` SET `x` = "'.$this->user['xf'].'", `y` = "'.$this->user['yr'].'" WHERE `laba` = "'.$this->user['laba'].'" AND `x` = "'.$this->battle_data['x'].'" AND `y` = "'.$this->battle_data['y'].'" AND `battle` = "'.$this->battle_data['id'].'" LIMIT 1');
}
include("cave/lose.php");
}
if($lomka) {
$haos_flag = 0;
foreach($lomka as $k => $v) {
if(mt_rand(1, 6) == 1) {
$us = mysql_query('UPDATE `inventory` SET `duration` = (`duration`+1) WHERE `type` != 12 AND `dressed` = 1 AND `owner` = \''.$v.'\'');
}
$inv_broken = mysql_query("SELECT * FROM `inventory` WHERE `type` != 12 AND `dressed` = 1 AND ((`maxdur` <= `duration`) OR (`dategoden` > 0 AND `dategoden` <= '".time()."')) AND `owner` = '{$v}'");
while($br = mysql_fetch_array($inv_broken)) {
dropitemid($br['type'], $v);
}
$its = mysql_query("SELECT `id` FROM `inventory` WHERE `dressed` = 0 AND ((`maxdur` <= `duration`) OR (`dategoden` > 0 AND `dategoden` <= '".time()."')) AND `owner` = '{$v}'");
while($it = mysql_fetch_array($its)) {
mysql_query("DELETE FROM `inventory` WHERE `id` = '".$it['id']."' LIMIT 1");
mysql_query("INSERT INTO `delo` (`author`, `pers`, `text`, `type`, `date`) VALUES ('0', '\"".$it['name']."\" разрушился id : (".$it['id'].").', '1', '".time()."')");
}
$this->exp[$v] = 0;
addchp('<font color=red>Внимание!</font> Поражение! Бой окончен. Всего вами нанесено урона : '.(int)$this->damage[$v].' HP. Получено опыта 0.', '{[]}'.nick7 ($v).'{[]}');
mysql_query('UPDATE `users` SET `lose` = (`lose`+1) WHERE `id` = \''.$v.'\'');
}
}
foreach($this->t1 as $k => $v) {
$us = mysql_query('SELECT `duration`, `maxdur`, `name` FROM `inventory` WHERE `type` != 12 AND `dressed` = 1 AND `owner` = \''.$v.'\'');
while($rrow = mysql_fetch_row($us)) {
if(($rrow[1]-$rrow[0]) == 1) {
$this->AddToLog('<span class=date>'.date("H:i").'</span> Внимание! У "'.nick7($v).'" предмет "'.$rrow[2].'" в критическом состоянии! <BR><small>(на правах рекламы) <b>Ремонтная мастерская </b>. Мы даем вторую жизнь старым вещам!</small><BR>');
} elseif(($rrow[1]-$rrow[0]) == 2) {
$this->AddToLog('<span class=date>'.date("H:i").'</span> Внимание! У "'.nick7($v).'" предмет "'.$rrow[2].'" нуждается в ремонте! <BR><small>(на правах рекламы) <b>Ремонтная мастерская </b>. Мы даем вторую жизнь старым вещам!</small><BR>');
}
}
}
foreach($this->t2 as $k => $v) {
$us = mysql_query('SELECT `duration`, `maxdur`, `name` FROM `inventory` WHERE `type` != 12 AND `dressed` = 1 AND `owner` = \''.$v.'\'');
while($rrow = mysql_fetch_row($us)) {
if(($rrow[1]-$rrow[0]) == 1) {
$this->AddToLog('<span class=date>'.date("H:i").'</span> Внимание! У "'.nick7($v).'" предмет '.$rrow[2].' в критическом состоянии! <BR><small>(на правах рекламы) <b>Ремонтная мастерская </b>. Мы даем вторую жизнь старым вещам!</small><BR>');
} elseif(($rrow[1]-$rrow[0]) == 2) {
$this->AddToLog('<span class=date>'.date("H:i").'</span> Внимание! У "'.nick7($v).'" предмет "'.$rrow[2].'" нуждается в ремонте! <BR><small>(на правах рекламы) <b>Ремонтная мастерская </b>. Мы даем вторую жизнь старым вещам!</small><BR>');
}
}
}
if($winers) {
if($this->battle_data['aren_of'] == 1) {
$arr_battle = mysql_fetch_array(mysql_query('SELECT `id`, `win`, `aren_of` FROM `battle` WHERE `id` = "'.$this->battle_data['id'].'" LIMIT 1'));
$us_win = mysql_query('SELECT `id`, `user`, `uid`, `team` FROM `logs_arena` WHERE `team` = "'.$arr_battle['win'].'" AND `battle` = "'.$this->battle_data['id'].'" ORDER BY `damage` DESC LIMIT 3');
while($win = mysql_fetch_array($us_win)) {
$uss .= ', ';
$uss .= $win['user'];
mysql_query('INSERT INTO `effects` (`type`, `name`, `time`, `hp`, `owner`) VALUES ("7", "Эйфория", "'.(time()+60*60*24).'", "200", "'.$win['uid'].'")');
mysql_query('UPDATE `users` SET `maxhp` = (`maxhp`+200) WHERE `id` = "'.$win['uid'].'" LIMIT 3');
mysql_query('INSERT INTO `effects` (`type`, `name`, `time`, `proc_exp`, `owner`) VALUES ("6", "Повешенный опыт (200%)", "'.(time()+60*60*24).'", "100", "'.$win['uid'].'")');
}
$bad = mysql_query('SELECT `id`, `uid`, `team` FROM `logs_arena` WHERE `team` != "'.$arr_battle['win'].'" AND `battle` = "'.$this->battle_data['id'].'" ORDER BY `damage` DESC LIMIT 3');
while($give = mysql_fetch_array($bad)) {
mysql_query('INSERT INTO `effects` (`type`, `name`, `time`, `proc_exp`, `owner`) VALUES ("6", "Повешенный опыт (150%)", "'.(time()+60*60*24).'", "50", "'.$give['uid'].'")');
}
if($uss != '') {
$uss = ltrim($uss, ', ');
} else {
$uss = '-Игроков не было в бою-';
}
if($arr_battle['win'] == 1) {
AddChatSystem("<font color=red>Внимание! Тьма одержала победу благодаря великим воинам : <b>$uss</b></font>");
$this->AddToLog('<span class=date>'.date("H:i").'</span> '.'Бой закончен, победа за <B>Силами Тьмы</B><BR>');
} else {
AddChatSystem("<font color=red>Внимание! Свет одержал победу благодаря великим воинам : <b>$uss</b></font>");
$this->AddToLog('<span class=date>'.date("H:i").'</span> '.'Бой закончен, победа за <B>Силами Света</B><BR>');
}
mysql_query('UPDATE `variables` SET `value` = "'.$arr_battle['win'].'" WHERE `var` = "arena_win" LIMIT 1');
mysql_query('UPDATE `battle` SET `aren_of` = 0 WHERE `id` = "'.$arr_battle['id'].'" AND `aren_of` = 1 LIMIT 1');
} else {
$this->AddToLog('<span class=date>'.date("H:i").'</span> '.'Бой закончен, победа за <B>'.$winers.'</B><BR>');
}
unset($uss);
if($this->battle_data['blood']) {
$this->AddToLog('<span class=date>'.date("H:i").'</span> ... и победители стали калечить проигравших...<BR>');
foreach($lomka as $k => $v) {
if($this->battle_data['blood'] == 2) {
$tr = settravma($v, 13, 86400, 1);
} else{
$tr = settravma($v, 0, 86400, 1);
}
if($v < _BOTSEPARATOR_) {
$this->AddToLog('<span class=date>'.date("H:i").'</span> <b>'.nick7($v).'</b> получил повреждение: <font color=red>'.$tr.'</font><BR>');
$inv_broken = mysql_query("SELECT `id`, `type`, `dressed`, `duration`, `maxdur`, `dategoden`, `owner` FROM `inventory` WHERE `type` != 12 AND `dressed` = 1 AND ((`maxdur` <= `duration`) OR (`dategoden` > 0 AND `dategoden` <= '".time()."')) AND `owner` = '{$v}'");
while($br = mysql_fetch_array($inv_broken)) {
dropitemid($br['type'], $v);
}
}
}
}
} else {
if($this->battle_data['aren_of'] == 1) {
AddChatSystem("<font color=red>Внимание! Бой на Арене Ангелов завершился ничьей, на этой недели силы тьмы и света равны.</font>");
mysql_query('UPDATE `variables` SET `value` = 3 WHERE `var` = "arena_win" LIMIT 1');
mysql_query('UPDATE `battle` SET `aren_of` = 0 WHERE `id` = "'.$arr_battle['id'].'" AND `aren_of` = 1 LIMIT 1');
}
$this->AddToLog('<span class=date>'.date("H:i").'</span> '.'Бой закончен. Ничья.<BR>');
mysql_query("UPDATE `users` SET `battle` = 0, `nich` = (`nich`+1), `fullhptime` = ".time()." WHERE `battle` = '{$this->user['battle']}'");
$this->exp = 0;
}
if($flag == 1) {
$rr = implode("</B>, <B>", $nks1). "<img src=../i/flag.gif></B> и <B>" .implode("</B>, <B>", $nks2);
2018-01-28 16:40:49 +00:00
} elseif($flag == 2) {
$rr = implode("</B>, <B>", $nks1)."</B> и <B>".implode("</B>, <B>", $nks2). "<img src=../i/flag.gif />";
2018-01-28 16:40:49 +00:00
} else {
$rr = implode("</B>, <B>", $nks1)."</B> и <B>".implode("</B>, <B>", $nks2)."";
}
mysql_query('UPDATE `battle` SET `t1hist` = \''.implode(", ", $nks1hist).'\', `t2hist` = \''.implode(", ", $nks2hist).'\' WHERE `id` = "'.$this->battle_data['id'].'" LIMIT 1');
mysql_query('UPDATE `battle` SET `exp` = \''.serialize($this->exp).'\' WHERE `id` = "'.$this->battle_data['id'].'" LIMIT 1');
mysql_query("UPDATE `users` SET `battle` = 0, `fullhptime` = '".time()."' WHERE `battle` = '{$this->battle_data['id']}'");
unset($this->battle);
return true;
}
}
return false;
}
function end_gora() {
if($this->GetTimeout()) {
foreach($this->team_mine as $v) {
if(in_array($v, array_keys($this->battle))) {
$vvv = $v;
}
}
$this->AddToLog("<span class=date>".date("H:i")."</span> Бой закончен по таймауту.<BR>");
foreach($this->team_enemy as $v => $k) {
if($k > _BOTSEPARATOR_) {
$bots = mysql_fetch_array(mysql_query('SELECT `hp` FROM `bots` WHERE `id` = "'.$k.'" LIMIT 1'));
$us['hp'] = $bots['hp'];
} else {
$us = mysql_fetch_array(mysql_query('SELECT `hp` FROM `users` WHERE `id` = "'.$k.'" LIMIT 1'));
}
if($us && (int)$us['hp'] > 0) {
if(!$this->battle_data['blood']) {
$tr = settravma($k, 0, 86400, 1);
if($k < _BOTSEPARATOR_) {
$this->AddToLog('<span class=date>'.date("H:i").'</span> <b>'.nick7($k).'</b> получил повреждение: <font color=red>'.$tr.'</font><BR>');
}
}
}
}
foreach($this->team_enemy as $v => $k) {
mysql_query('UPDATE `users` SET `hp` = 0, `fullhptime` = '.time().' WHERE `id` = "'.$k.'"');
}
header("Location: ".$_SERVER['PHP_SELF']."?batl=".$this->user['battle']);
}
}
function end_draft() {
if(!$this->user['in_tower']) {
if($this->GetTimeout()) {
$this->battle = null;
mysql_query("UPDATE `users` SET `battle` = 0, `nich` = (`nich`+1), `fullhptime` = ".time()." WHERE `battle` = {$this->battle_data['id']}");
mysql_query("UPDATE `battle` SET `win` = 0 WHERE `id` = '{$this->battle_data['id']}' LIMIT 1");
$this->AddToLog("<span class=date>".date("H:i")."</span> Бой закончен по таймауту. <b>Ничья</b>.<BR>");
$this->exp = 0;
$this->write_log();
}
}
}
function FastDeath() {
if($this->battle) {
foreach($this->battle as $k => $v) {
if($k > _BOTSEPARATOR_) {
$bot = mysql_fetch_array(mysql_query("SELECT `hp`, `battle`, `prototype` FROM `bots` WHERE `id` = '{$k}' LIMIT 1"));
$us = mysql_fetch_array(mysql_query("SELECT `maxhp`, `sex` FROM `users` WHERE `id` = '{$bot['prototype']}' LIMIT 1"));
$us['hp'] = $bot['hp'];
$us['battle'] = $bot['battle'];
} else {
$us = mysql_fetch_array(mysql_query("SELECT `hp`, `maxhp`, `sex`, `battle` FROM `users` WHERE `id` = '{$k}' LIMIT 1"));
}
if($us['hp'] <= 0) {
if($us['sex'] == 1) {
$this->AddToLog('<span class=date>'.date("H:i").'</span> '.nick5($k, 'b').' умер!<BR>');
} else {
$this->AddToLog('<span class=date>'.date("H:i").'</span> '.nick5($k, 'b').' погибла!<BR>');
}
if($k < _BOTSEPARATOR_) {
mysql_query("UPDATE `users` SET `hp` = 0, `fullhptime` = '".time()."' WHERE `id` = '{$k}' LIMIT 1");
} else {
mysql_query("UPDATE `bots` SET `hp` = 0 WHERE `id` = '{$k}' LIMIT 1");
}
foreach($this->battle as $kak => $vav) {
unset($this->battle[$kak][$k]);
}
unset($this->battle[$k]);
}
if($k == null ) {
foreach($this->battle as $kak => $vav) {
unset($this->battle[$kak][$k]);
}
}
if($us['battle'] == 0) {
foreach($this->battle as $kak => $vav) {
unset($this->battle[$kak][$k]);
}
unset($this->battle[$k]);
}
unset($us);
}
$this->UpdateBattle();
}
}
function gen_color($u, $enemy) {
$this->t1 = explode(";", $this->battle_data['t1']);
$this->t2 = explode(";", $this->battle_data['t2']);
$c = array();
if(in_array($u, $this->t1)) {
$c['me'] = "B1";
$c['he'] = "B2";
} else {
$c['me'] = "B2";
$c['he'] = "B1";
}
return $c;
}
function GetUserTeam() {
$this->t1 = explode(";", $this->battle_data['t1']);
$this->t2 = explode(";", $this->battle_data['t2']);
if(in_array($this->user['id'], $this->t1)) {
$this->my_class = "B1";
$this->en_class = "B2";
$this->team_mine = $this->t1;
$this->team_enemy = $this->t2;
} else {
$this->my_class = "B2";
$this->en_class = "B1";
$this->team_mine = $this->t2;
$this->team_enemy = $this->t1;
}
}
function init_botRazmen($uid, $enemy, $attack, $defend) {
$RazmenValues = array(1, 2, 3, 4);
$hp_1 = mysql_fetch_array(mysql_query('SELECT `id`, `hp`, `prototype` FROM `bots` WHERE `id` = "'.$uid.'" LIMIT 1'));
$maxhp_1 = mysql_fetch_array(mysql_query('SELECT `maxhp` FROM `users` WHERE `id` = "'.$hp_1['prototype'].'" LIMIT 1'));
$hp_2 = mysql_fetch_array(mysql_query('SELECT `id`, `hp`, `prototype` FROM `bots` WHERE `id` = "'.$enemy.'" LIMIT 1'));
$maxhp_2 = mysql_fetch_array(mysql_query('SELECT `maxhp` FROM `users` WHERE `id` = "'.$hp_2['prototype'].'" LIMIT 1'));
$color = $this->gen_color($uid, $enemy);
if(in_array($attack, $RazmenValues) && in_array($defend, $RazmenValues) && $enemy && $hp_1['hp'] > 0) {
if($this->battle[$enemy][$uid][0] > 0) {
$this->AddToLogBot($this->GetComment());
$mf = $this->solve_mfs($uid, $enemy, $attack);
$uvorotme = $this->chanse($mf['me']['chanse']);
$krithe = $this->chanse($mf['he']['chanse_krit']);
if($uvorotme && !$krithe) {
$uve = 1;
} elseif(!$uvorotme && $krithe) {
$uve = 2;
} elseif($uvorotme && $krithe) {
$uve = rand(1, 2);
} else {
$uve = 0;
}
if($uve == 1) {
$this->AddToLogBot($this->razmen_log("uvorot", $this->battle[$enemy][$uid][0], $this->GetWeaponType($this->enemyhar['weap']), 0, $enemy, $color['he'], $uid, $color['me'], 0, 0));
} elseif($uve == 2) {
if($this->GetBlock("me", $this->battle[$enemy][$uid][0], $defend, $enemy)) {
$hs = 1; $m = 'a';
} else {
$hs = 2; $m = '';
}
$yron = $mf['he']['udar']*$hs;
$us = mysql_fetch_array(mysql_query('SELECT `id`, `hp` FROM `bots` WHERE `id` = "'.$uid.'" LIMIT 1'));
if($us['hp'] < $yron) {
$yron = $us['hp'];
}
$this->damage[$enemy] += $yron;
$jv = ($hp_1['hp']-$yron);
$this->exp[$enemy] += SolveExp($enemy, $uid, $yron);
$this->AddToLogBot($this->razmen_log("krit".$m, $this->battle[$enemy][$uid][0], $this->GetWeaponType($this->enemyhar['weap']), $yron, $enemy, $color['he'], $uid, $color['me'], ($hp_1['hp']-$yron), $maxhp_2['maxhp']));
mysql_query('UPDATE `bots` SET `hp` = (`hp` - '.$yron.') WHERE `id` = "'.$uid.'" LIMIT 1'); ### Maybe not limited
} elseif(!$this->GetBlock("me", $this->battle[$enemy][$uid][0], $defend, $enemy)) {
$yron = $mf['he']['udar'];
$us = mysql_fetch_array(mysql_query('SELECT `id`, `hp` FROM `bots` WHERE `id` = "'.$uid.'" LIMIT 1'));
if($us['hp'] < $yron) {
$yron = $us['hp'];
}
$jv = ($hp_1['hp']-$yron);
$this->AddToLogBot($this->razmen_log("udar", $this->battle[$enemy][$uid][0], $this->GetWeaponType($this->enemyhar['weap']), $yron, $enemy, $color['he'], $uid, $color['me'], ($hp_1['hp']-$yron), $maxhp_2['maxhp']));
mysql_query('UPDATE `bots` SET `hp` = (`hp` - '.$yron.') WHERE `id` = "'.$uid.'" LIMIT 1');
} else {
$this->AddToLogBot($this->razmen_log("block", $this->battle[$enemy][$uid][0], $this->GetWeaponType($this->enemyhar['weap']), 0, $enemy, $color['he'], $uid, $color['me'], 0, 0));
}
$uvorothe = $this->chanse($mf['he']['chanse']);
$kritme = $this->chanse($mf['me']['chanse_krit']);
if($uvorothe && !$kritme) {
$uve = 1;
} elseif(!$uvorothe && $kritme) {
$uve = 2;
} elseif($uvorothe && $kritme) {
$uve = rand(1, 2);
} else {
$uve = 0;
}
if($uve == 1) {
$this->AddToLogBot($this->razmen_log("uvorot", $attack, $this->GetWeaponType($this->user['weap']), 0, $uid, $color['me'], $enemy, $color['he'], 0, 0));
} elseif($uve == 2) {
if($this->GetBlock("he", $attack, $this->battle[$enemy][$uid][1], $enemy)) {
$hs = 1; $m = 'a';
} else {
$hs = 2; $m = '';
}
$yron = $mf['me']['udar']*$hs;
$us = mysql_fetch_array(mysql_query('SELECT `id`, `hp` FROM `bots` WHERE `id` = "'.$enemy.'" LIMIT 1'));
if($us['hp'] < $yron) {
$yron = $us['hp'];
}
$this->AddToLogBot($this->razmen_log("krit".$m, $attack, $this->GetWeaponType($this->user['weap']), $yron, $uid, $color['me'], $enemy, $color['he'], ($this->enemyhar['hp']-$yron), $this->enemyhar['maxhp']));
if($enemy > _BOTSEPARATOR_) {
mysql_query('UPDATE `bots` SET `hp` = (`hp` - '.$yron.') WHERE `id` = "'.$enemy.'" LIMIT 1');
} else {
mysql_query('UPDATE `bots` SET `hp` = (`hp` - '.$yron.') WHERE `id` = "'.$enemy.'" LIMIT 1');
}
} elseif(!$this->GetBlock("he", $attack, $this->battle[$enemy][$uid][1], $enemy)) {
$yron = $mf['me']['udar'];
$us = mysql_fetch_array(mysql_query('SELECT `id`, `hp` FROM `bots` WHERE `id` = "'.$enemy.'" LIMIT 1'));
if($us['hp'] < $yron) {
$yron = $us['hp'];
}
$this->AddToLogBot($this->razmen_log("udar", $attack, $this->GetWeaponType($this->user['weap']), $yron, $uid, $color['me'], $enemy, $color['he'], ($this->enemyhar['hp']-$yron), $this->enemyhar['maxhp']));
if($enemy > _BOTSEPARATOR_) {
mysql_query('UPDATE `bots` SET `hp` = (`hp` - '.$yron.') WHERE `id` = "'.$enemy.'" LIMIT 1');
} else {
mysql_query('UPDATE `bots` SET `hp` = (`hp` - '.$yron.') WHERE `id` = "'.$enemy.'" LIMIT 1');
}
} else {
$this->AddToLogBot($this->razmen_log("block", $attack, $this->GetWeaponType($this->user['weap']), 0, $uid, $color['me'], $enemy, $color['he'], 0, 0));
}
$this->battle[$enemy][$uid] = array(0, 0, time());
mysql_query("UPDATE `battle` SET `to1` = '".time()."', `to2` = '".time()."' WHERE `id` = '".$this->battle_data['id']."' LIMIT 1");
$this->UpdateBattle();
} else {
$this->battle[$uid][$enemy] = array($attack, $defend, time());
if($this->my_class == "B1" && $jv > 0) {
mysql_query("UPDATE `battle` SET `to1` = '".time()."', `to2` = '".(time()-1)."' WHERE `id` = '".$this->battle_data['id']."' LIMIT 1");
} elseif($jv > 0) {
mysql_query("UPDATE `battle` SET `to2` = '".time()."', `to1` = '".(time()-1)."' WHERE `id` = '".$this->battle_data['id']."' LIMIT 1");
} else {
mysql_query("UPDATE `battle` SET `to2` = '".time()."', `to1` = '".(time())."' WHERE `id` = '".$this->battle_data['id']."' LIMIT 1");
}
$this->FastDeath();
$this->UpdateBattle();
#header('Location: fbattle.php');
die();
}
} else {
return false;
}
}
function InitRazmen($enemy, $attack, $defend) {
$RazmenValues = array(1, 2, 3, 4); $DefValues = array(1, 2, 3, 4);
if(in_array($attack, $RazmenValues) && in_array($defend, $DefValues) && $enemy && $this->user['hp'] > 0) {
if($this->battle[$enemy][$this->user['id']][0] > 0) {
$this->AddToLog($this->GetComment());
$mfs = $this->solve_mfs($this->user['id'], $enemy, $attack);
$color = $this->gen_color($this->user['id'], $enemy);
if($mfs['me']['chanse'] > 0) {
$uvorotme = $this->chanse($mfs['me']['chanse']);
} else {
$uvorotme = false;
}
if($mfs['me']['chanse_krit'] > 0) {
$krithe = $this->chanse($mfs['he']['chanse_krit']);
} else {
$krithe = false;
}
if($uvorotme && !$krithe) {
$uve = 1;
} elseif(!$uvorotme && $krithe) {
$uve = 2;
} elseif($uvorotme && $krithe) {
$uve = rand(1, 2);
} else {
$uve = 0;
}
if($uve == 1) {
$this->AddToLog($this->razmen_log("uvorot", $this->battle[$enemy][$this->user['id']][0], $this->GetWeaponType($this->enemyhar['weap']), 0, $enemy, $color['me'], $this->user['id'], $color['he'], 0, 0));
} elseif($uve == 2) {
$this->battle[$enemy][$this->user['id']] = array($attack, $defend, time());
if($this->get_blocks($this->battle[$this->user['id']][$enemy][0], $this->battle[$enemy][$this->user['id']][1])) {
$hs = 1; $m = 'a';
} else {
$hs = 2; $m = '';
}
$yron = $mfs['he']['udar']*$hs;
$hp_u = mysql_fetch_array(mysql_query('SELECT `id`, `hp` FROM `users` WHERE `id` = "'.$this->user['id'].'" LIMIT 1'));
if($hp_u['hp'] < ($mfs['he']['udar']*$hs)) {
$yron = $hp_u['hp'];
}
$this->damage[$enemy] += $yron;
$jv = ($this->user['hp']-$yron);
$this->exp[$enemy] += SolveExp($enemy, $this->user['id'], $yron);
$this->AddToLog($this->razmen_log("krit".$m, $this->battle[$this->user['id']][$enemy][0], $this->GetWeaponType($this->enemyhar['weap']), $yron, $enemy, $color['me'], $this->user['id'], $color['he'], ($this->user['hp']-$yron), $this->user['maxhp']));
mysql_query('UPDATE `users` SET `hp` = (`hp` - '.$yron.') WHERE `id` = "'.$this->user['id'].'" LIMIT 1');
if(!($this->user['align'] == '2' || $this->user['align'] == '8.31')) {
$tmphp = mysql_fetch_array(mysql_query("SELECT `hp` FROM `users` WHERE `id` = {$this->user['id']} LIMIT 1"));
$tmphp = $tmphp['hp'];
if($tmphp <= 0) {
if(mt_rand(0, 100) <= 40 && $this->user['level'] > 6) {
$tr = settravma($this->user['id'], 0, 86400, 0);
if($this->user['id'] < _BOTSEPARATOR_) {
$this->AddToLog('<span class=date>'.date("H:i").'</span> <b>'.nick7($this->user['id']).'</b> получил повреждение: <font color=red>'.$tr.'</font><BR>');
}
}
}
}
} elseif(!$this->get_blocks($this->user['id'], $this->battle[$enemy][$this->user['id']][0], $enemy, $this->battle[$this->user['id']][$enemy][1])) {
$yron = $mfs['he']['udar'];
$hp_u = mysql_fetch_array(mysql_query('SELECT `id`, `hp` FROM `users` WHERE `id` = "'.$this->user['id'].'" LIMIT 1'));
if($hp_u['hp'] < $mfs['he']['udar']) {
$yron = $hp_u['hp'];
}
$this->damage[$enemy] += $yron;
$jv = ($this->user['hp']-$yron);
$this->exp[$enemy] += SolveExp($enemy, $this->user['id'], $yron);
$this->AddToLog($this->razmen_log("udar", $this->battle[$enemy][$this->user['id']][0], $this->GetWeaponType($this->enemyhar['weap']), $yron, $enemy, $color['me'], $this->user['id'], $color['he'], ($this->user['hp']-$yron), $this->user['maxhp']));
mysql_query('UPDATE `users` SET `hp` = (`hp` - '.$yron.') WHERE `id` = "'.$this->user['id'].'" LIMIT 1');
} else {
$this->AddToLog($this->razmen_log("block", $this->battle[$enemy][$this->user['id']][1], $this->GetWeaponType($this->enemyhar['weap']), 0, $enemy, $color['me'], $this->user['id'], $color['he'], 0, 0));
}
if($mfs['he']['chanse'] > 0) {
$uvorothe = $this->chanse($mfs['he']['chanse']);
} else {
$uvorothe = false;
}
if($mfs['me']['chanse_krit'] > 0) {
$kritme = $this->chanse($mfs['me']['chanse_krit']);
} else {
$kritme = false;
}
if($uvorothe && !$kritme) {
$uve_1 = 1;
} elseif(!$uvorothe && $kritme) {
$uve_1 = 2;
} elseif($uvorothe && $kritme) {
$uve_1 = rand(1, 2);
} else {
$uve_1 = 0;
}
if($uve_1 == 1) {
$this->AddToLog($this->razmen_log("uvorot", $attack, $this->GetWeaponType($this->user['weap']), 0, $this->user['id'], $color['me'], $enemy, $color['he'], 0, 0));
} elseif($uve_1 == 2) {
if($this->get_blocks($enemy, $this->battle[$this->user['id']][$enemy][0], $this->user['id'], $this->battle[$enemy][$this->user['id']][1])) {
$hs = 1; $m = 'a';
} else {
$hs = 2; $m = '';
}
$yron = $mfs['me']['udar']*$hs;
if($enemy > _BOTSEPARATOR_) {
$hp_u = mysql_fetch_array(mysql_query('SELECT `id`, `hp` FROM `bots` WHERE `id` = "'.$enemy.'" LIMIT 1'));
} else {
$hp_u = mysql_fetch_array(mysql_query('SELECT `id`, `hp` FROM `users` WHERE `id` = "'.$enemy.'" LIMIT 1'));
}
if($hp_u['hp'] < $yron) {
$yron = $hp_u['hp'];
}
$this->damage[$this->user['id']] += $yron;
$this->exp[$this->user['id']] += SolveExp($this->user['id'], $enemy, $yron);
$this->AddToLog($this->razmen_log("krit".$m, $attack, $this->GetWeaponType($this->user['weap']), $yron, $this->user['id'], $color['me'], $enemy, $color['he'], ($this->enemyhar['hp']-$yron), $this->enemyhar['maxhp']));
if($enemy > _BOTSEPARATOR_) {
mysql_query('UPDATE `bots` SET `hp` = (`hp` - '.$yron.') WHERE `id` = "'.$enemy.'" LIMIT 1');
} else {
mysql_query('UPDATE `users` SET `hp` = (`hp` - '.$yron.') WHERE `id` = "'.$enemy.'" LIMIT 1');
$tmpen = mysql_fetch_array(mysql_query("SELECT `id`, `align`, `hp`, `level` FROM `users` WHERE `id`= '{$enemy}' LIMIT 1"));
if(!($tmpen['align'] == '2' || $tmpen['align'] == '8.31')) {
$tmphp = $tmpen['hp'];
if($tmphp <= 0) {
if(mt_rand(0, 100) <= 40 && $tmpen['level'] > 6) {
$tr = settravma($tmpen['id'], $tmptravma, 86400, 0);
if($tmpen['id'] < _BOTSEPARATOR_) {
$this->AddToLog('<span class=date>'.date("H:i").'</span> <b>'.nick7($tmpen['id']).'</b> получил повреждение: <font color=red>'.$tr.'</font><BR>');
}
}
}
}
}
} elseif($this->get_blocks("he", $this->battle[$this->user['id']][$enemy][0], $this->user['id'], $this->battle[$enemy][$this->user['id']][1])) {
$yron = $mfs['me']['udar'];
if($enemy > _BOTSEPARATOR_) {
$hp_u = mysql_fetch_array(mysql_query('SELECT `id`, `hp` FROM `bots` WHERE `id` = "'.$enemy.'" LIMIT 1'));
} else {
$hp_u = mysql_fetch_array(mysql_query('SELECT `id`, `hp` FROM `users` WHERE `id` = "'.$enemy.'" LIMIT 1'));
}
if($hp_u['hp'] < $yron) {
$yron = $hp_u['hp'];
}
$this->damage[$this->user['id']] += $yron;
$this->exp[$this->user['id']] += SolveExp($this->user['id'], $enemy, $yron);
$this->AddToLog($this->razmen_log("udar", $attack, $this->GetWeaponType($this->user['weap']), $yron, $this->user['id'], $color['me'], $enemy, $color['he'], ($this->enemyhar['hp']-$yron), $this->enemyhar['maxhp']));
if($enemy > _BOTSEPARATOR_) {
mysql_query('UPDATE `bots` SET `hp` = (`hp` - '.$yron.') WHERE `id` = "'.$enemy.'" LIMIT 1');
} else {
mysql_query('UPDATE `users` SET `hp` = (`hp` - '.$yron.') WHERE `id` = "'.$enemy.'" LIMIT 1');
}
} else {
$this->AddToLog($this->razmen_log("block", $defend, $this->GetWeaponType($this->user['weap']), 0, $this->user['id'], $color['me'], $enemy, $color['he'], 0, 0));
}
$this->battle[$enemy][$this->user['id']] = array(0, 0, time());
mysql_query("UPDATE `battle` SET `to1` = '".time()."', `to2` = '".time()."' WHERE `id` = '".$this->user['battle']."' LIMIT 1");
$this->UpdateBattle();
} else {
$this->battle[$this->user['id']][$enemy] = array($attack, $defend, time());
if($this->my_class == "B1" && $jv > 0) {
mysql_query("UPDATE `battle` SET `to1` = '".time()."', `to2` = '".(time()-1)."' WHERE `id` = '".$this->battle_data['id']."' LIMIT 1");
} elseif($jv > 0) {
mysql_query("UPDATE `battle` SET `to2` = '".time()."', `to1` = '".(time()-1)."' WHERE `id` = '".$this->battle_data['id']."' LIMIT 1");
} else {
mysql_query("UPDATE `battle` SET `to2` = '".time()."', `to1` = '".(time())."' WHERE `id` = '".$this->battle_data['id']."' LIMIT 1");
}
$this->UpdateBattle();
header("Location: ".$_SERVER['PHP_SELF']."");
die();
}
} else {
return false;
}
}
function addAction($time, $vars, $vls, $uid = NULL) {
if($uid == NULL) {
$uid = $this->user['id'];
}
$ins = mysql_query('INSERT INTO `actions` (`uid`, `time`, `city`, `room`, `vars`, `ip`, `vals`) VALUES ("'.$uid.'", "'.$time.'", "capitalcity", "0", "'.mysql_real_escape_string($vars).'", "'.mysql_real_escape_string($_SERVER['HTTP_X_REAL_IP']).'", "'.mysql_real_escape_string($vls).'")');
if($ins) {
return true;
} else {
return false;
}
}
function GetWeaponType($idwep) {
if($idwep == 0 || $idwep == null || $idwep == '') {
return "kulak";
}
$wep = mysql_fetch_array(mysql_query("SELECT `otdel`, `minu` FROM `inventory` WHERE `id` = '{$idwep}' LIMIT 1"));
if($wep[0] == '1') {
return "noj";
} elseif($wep[0] == '12') {
return "dubina";
} elseif($wep[0] == '11') {
return "topor";
} elseif($wep[0] == '13') {
return "mech";
} elseif($wep[1] > 0) {
return "buket";
} else {
return "kulak";
}
}
function razmen_log($type, $kuda, $chem, $uron, $kto, $c1, $pokomy, $c2, $hp, $maxhp) {
$color = $this->gen_color($kto, $pokomy);
if($this->enemyhar['sex'] && $kto == $this->enemyhar['id']) { $sex1 = false; }
if(!$this->enemyhar['sex'] && $kto == $this->enemyhar['id']) { $sex1 = true; }
if($this->enemyhar['sex'] && $pokomy == $this->enemyhar['id']) { $sex2 = false; }
if(!$this->enemyhar['sex'] && $pokomy == $this->enemyhar['id']) { $sex2 = true; }
if($this->user['sex'] && $kto == $this->user['id']) { $sex1 = false; }
if(!$this->user['sex'] && $kto == $this->user['id']) { $sex1 = true; }
if($this->user['sex'] && $pokomy == $this->user['id']) { $sex2 = false; }
if(!$this->user['sex'] && $pokomy == $this->user['id']) { $sex2 = true; }
if($hp < 0) { $hp = 0; }
$hiden_warior = mysql_fetch_array(mysql_query('SELECT `id`, `invis` FROM `users` WHERE `id` = "'.$pokomy.'" LIMIT 1'));
if($hiden_warior['invis'] == 1) {
$hp = '??';
$maxhp = '??';
$uron = '??';
}
if(!$sex1) {
$textfail = array('думал о <вырезано цензурой>, вследствие чего', 'пытался нанести удар, но ', 'подскользнулся, и', 'старался провести удар, но', 'закашлялся, и', 'пытался провести удар, но', 'потерял самоконтроль, вследствие чего', 'думал не о том, и');
} else {
$textfail = array('думала о <вырезано цензурой>, вследствие чего', 'пыталась нанести удар, но ', 'подскользнулась, и', 'старалась провести удар, но', 'закашлялась, и', 'пыталась провести удар, но ', 'потеряла самоконтроль, вследствие чего', 'думала не о том, и');
}
$textchem = array (
"kulak" => array("грудью","ребром руки","лбом","кулаком","ногой","левой ногой","правой ногой","коленом"),
"noj" => array("ножом","тыльной стороной лезвия ножа","рукоятью ножа","лезвием ножа"),
"dubina" => array("сучковатой палкой","поленом","тяжелой дубиной","дубиной","рукоятью молота"),
"topor" => array("секирой","топором","лезвием секиры","алебардой","тяжелым держаком","длинной секирой"),
"mech" => array("ножнами","гардой","мечом","лезвием меча","рукоятью меча","тупым лезвием","острой стороной меча","огромным мечом",),
"buket" => array("охапкой цветов","веником","букетом","колючками","снопом","стеблем","листьями","бутоном",)
);
$textchem = $textchem[$chem];
$udars = array(
1 => array('в нос','в глаз','в челюсть','по переносице','в кадык','по затылку','в правый глаз','в левый глаз','в скулу'),
2 => array('в грудь','в корпус','в солнечное сплетение','в сердце','в бок','в область лопаток','по желудку','по левой руке','по правой руке'),
3 => array('по <вырезано цензурой>','в пах','в промежность','по левой ягодице','по правой ягодице'),
4 => array('по ногам','в область правой пятки','в область левой пятки','по коленной чашечке','по икрам')
);
$kuda = $udars[$kuda][mt_rand(0, count($udars[$kuda])-1)];
if(!$sex1) {
$hark = array('бесчувственный','расстроенный','храбрый','обезумевший','неустрашимый','злобный','жестокий','наглый','разъяренный','продвинутый','хитрый','мужественный','','','','','','');
} else {
$hark = array('бесчувственная','расстроенная','храбрая','обезумевшая','неустрашимая','злобная','жестокая','наглая', 'разъяренная','продвинутая','хитрая','прекрасная','','','','','','');
}
if(!$sex2) {
$hark2 = array('бесчувственный','расстроенный','храбрый','обезумевший','неустрашимый','злобный','жестокий','наглый','разъяренный','продвинутый','хитрый','мужественный','','','','','','');
} else {
$hark2 = array('бесчувственная','расстроенная','храбрая','обезумевшая','неустрашимая','злобная','жестокая','наглая','разъяренная','продвинутая','хитрая','прекрасная','','','','','','');
}
if(!$sex2) {
$textud = array('забылся, и тут', 'замешкался, и за это', 'растерялся, как вдруг', 'ковырялся в зубах, и тут', 'поперхнулся, но вдруг', 'пытался что-то сказать но вдруг, неожиданно', 'растерялся, как вдруг', 'засмотрелся на <вырезано цензурой>, а в это время', 'высморкался, и в это время', 'думал не о том, и', 'пришел в себя, но в это время', 'обернулся, как внезапно');
} else {
$textud = array('забылась, и тут', 'замешкалась, и за это ', 'растерялась, как вдруг ', 'ковырялась в зубах, и тут ', 'поперхнулась, но вдруг ', 'пыталась что-то сказать но вдруг, неожиданно', 'растерялась, как вдруг', 'засмотрелась на <вырезано цензурой>, а в это время', 'высморкалась, и в это время', 'думала не о том, и', 'пришла в себя, но в это время ', 'обернулась, как внезапно');
}
switch($type) {
case "uvorot":
if($sex2) {
$textuvorot = array(" <font color=green><B>уклонилась</B></font> от удара "," <font color=green><B>увернулась</B></font> от удара "," <font color=green><B>отскочила</B></font> от удара ");
} else {
$textuvorot = array(" <font color=green><B>уклонился</B></font> от удара "," <font color=green><B>увернулся</B></font> от удара "," <font color=green><B>отскочил</B></font> от удара ");
}
return '<span class=date>'.date("H:i").'</span> '.nick5($kto, $color['me']).' '.$textfail[mt_rand(0, count($textfail)-1)].' '.$hark2[mt_rand(0,count($hark2)-1)].' '.nick5($pokomy, $color['he']).' '.$textuvorot[mt_rand(0,count($textuvorot)-1)].' '.$textchem[mt_rand(0,count($textchem)-1)].' '.$kuda.'.<BR>';
break;
case "block":
if($sex2) {
$textblock = array(" заблокировала удар "," остановила удар "," отбила удар ");
} else {
$textblock = array(" заблокировал удар "," остановил удар "," отбил удар ");
}
return '<span class=date>'.date("H:i").'</span> '.nick5($kto, $color['me']).' '.$textfail[mt_rand(0, count($textfail)-1)].' '.$hark2[mt_rand(0, count($hark2)-1)].' '.nick5($pokomy, $color['he']).' '.$textblock[mt_rand(0,count($textblock)-1)].' '.$textchem[mt_rand(0,count($textchem)-1)].' '.$kuda.'.<BR>';
break;
case "krit":
if($sex1) {
$textkrit = array(", напугав всех, неслышно подойдя сзади ударила по голове булыжником оппонента.",", сказав \"БУ!\", ласково заломила руку за спину соперника.",", расслабившись, расцарапала нос соперника.",", показав сразу два пальца, наступила на ногу врага.",", напугав всех, укусила в нос противника.",", проклиная этот сайт, провела ужасный бросок через пупок оппонента.");
} else {
$textkrit = array(", напугав всех, неслышно подойдя сзади ударил по голове булыжником оппонента.",", сказав \"БУ!\", ласково заломил руку за спину соперника.",", расслабившись, расцарапал нос соперника.",", показав сразу два пальца, наступил на ногу врага.",", напугав всех, укусил в нос противника.",", проклиная этот сайт, провел ужасный бросок через пупок оппонента.");
}
return '<span class=date>'.date("H:i").'</span> '.nick5($pokomy, $color['he']).' '.$textud[mt_rand(0, count($textud)-1)].' '.$hark[mt_rand(0,count($hark)-1)].' '.nick5($kto, $color['me']).' '.$textkrit[mt_rand(0,count($textkrit)-1)].' <b><font color=red>-'.$uron.'</font></b> ['.$hp.'/'.$maxhp.']'.'<BR>';
break;
case "krita":
if($sex1) {
$textkrit = array(", напугав всех, неслышно подойдя сзади ударила, пробив блок, по голове булыжником оппонента.",", пробив блок, ласково заломила руку за спину соперника.",", пробив блок, расцарапала нос соперника.",", пробив блок, наступила на ногу врага.",", пробив блок, укусила в нос противника.",", пробив блок, провела ужасный бросок через пупок оппонента.");
} else {
$textkrit = array(", напугав всех, неслышно подойдя сзади ударил, пробив блок, по голове булыжником оппонента.",", пробив блок, ласково заломил руку за спину соперника.",", пробив блок, расцарапал нос соперника.",", пробив блок, наступил на ногу врага.",", пробив блок, укусил в нос противника.",", пробив блок, провел ужасный бросок через пупок оппонента.");
}
return '<span class=date>'.date("H:i").'</span> '.nick5($pokomy, $color['he']).' '.$textud[mt_rand(0, count($textud)-1)].' '.$hark[mt_rand(0, count($hark)-1)].' '.nick5($kto, $color['me']).' '.$textkrit[mt_rand(0,count($textkrit)-1)].' <b><font color=red>-'.$uron.'</font></b> ['.$hp.'/'.$maxhp.']'.'<BR>';
break;
case "udar":
if($sex1) {
$textudar = array(", разбежавшись, рубанула"," отчаянно проткнула "," нехотя уколола "," не подумав, рубанула ",", улыбаясь, саданула укол "," приложила удар "," ударила "," сдуру вмазала ");
} else {
$textudar = array(", разбежавшись, рубанул"," отчаянно проткнул "," нехотя уколол "," не подумав, рубанул ",", улыбаясь, саданул укол "," приложил удар "," ударил "," сдуру вмазал ");
}
return '<span class=date>'.date("H:i").'</span> '.nick5($pokomy, $color['he']).' '.$textud[mt_rand(0, count($textud)-1)].' '.$hark[mt_rand(0, count($hark)-1)].' '.nick5($kto, $color['me']).''.$textudar[mt_rand(0,count($textudar)-1)].' '.$textchem[mt_rand(0,count($textchem)-1)].' '.$kuda.' <b>-'.$uron.'</b> ['.$hp.'/'.$maxhp.']'.'<BR>';
break;
}
}
function get_blocks($where_atack, $where_defend) {
$blocks = array('1' => array(1, 2), '2' => array(2, 3), '3' => array(3, 4), '4' => array(4, 1));
if(!in_array($where_atack, $blocks[$where_defend])) {
return true;
} else {
return false;
}
}
function GetBlock($komy, $att, $def, $enemy) {
$blocks = array(1 => array(1, 2), 2 => array(2, 3), 3 => array(3, 4), 4 => array(4, 1));
switch($komy) {
case "me" :
if(in_array($this->battle[$enemy][$this->user['id']][0], $blocks[$def])) {
return true;
} else {
return false;
}
break;
case "he" :
if(in_array($this->battle[$enemy][$this->user['id']][1], $blocks[$att])) {
return true;
} else {
return false;
}
break;
}
}
function GetChance($percent) {
$mm = 1;
if(rand($mm, 100*$mm) <= $percent*$mm) {
return true;
} else {
return false;
}
}
function SelectEnemy() {
if(($this->user['hp'] > 0) && $this->battle) {
foreach($this->battle[$this->user['id']] as $k => $v) {
if($this->battle[$this->user['id']][$k][0] == 0) {
$enemies[] = $k;
}
}
if(isset($enemies[0])) {
$enemy = $enemies[mt_rand(0, count($enemies)-1)];
if($enemy > 0) {
return $enemy;
}
} else {
return false;
}
} else {
return false;
}
}
function chancebymf($mf, $antimf, $min = 1, $max = 85, $mid = 10, $div = 250) {
if($mf <= $antimf) return 0;
$diff = 1-pow(0.5, abs($mf-$antimf)/$div);
if($mf > $antimf) {
return ($max-$mid)*$diff+$mid;
} else {
return ($mid-$min)*(1-$diff)+$min;
}
$min = $min/100;
$max = $max/100;
$diffup = (1/(1+(abs($mf-$antimf)/(($max-$mid)*100))));
$diffdown = (1/(1+(abs($mf-$antimf)/(($mid-$min)*100))));
$ret = $mid;
if($mf > $antimf) {
$ret = $ret*(2-$diff);
} else {
$ret = $ret*$diff;
}
if($ret < $min) {
$ret = $min;
}
if($ret > $max) {
$ret = $max;
}
return (int)round($ret*100);
}
function check_bonus($uid) {
$us = mysql_fetch_array(mysql_query('SELECT `id`, `sila`, `lovk`, `inta`, `vinos` FROM `users` WHERE `id` = "'.mysql_real_escape_string($uid).'" LIMIT 1'));
$i_uminu = 0;
$i_fkrit = 0;
$i_fauvorot = 0;
$i_fakrit = 0;
$i_umaxu = 0;
if($us['sila'] >= 25) { $sila['fauvorot'] = 10; $sila['fakrit'] = 10; $sila['uminu'] = 0; $sila['umaxu'] = 0; }
if($us['sila'] >= 50) { $sila['fauvorot'] = 20; $sila['fakrit'] = 25; $sila['uminu'] = 0; $sila['umaxu'] = 0; }
if($us['sila'] >= 75) { $sila['fauvorot'] = 30; $sila['fakrit'] = 40; $sila['uminu'] = 0; $sila['umaxu'] = 0; }
if($us['sila'] >= 100) { $sila['fauvorot'] = 40; $sila['fakrit'] = 50; $sila['uminu'] = 2; $sila['umaxu'] = 2; }
if($us['sila'] >= 125) { $sila['fauvorot'] = 60; $sila['fakrit'] = 75; $sila['uminu'] = 5; $sila['umaxu'] = 5; }
if($us['sila'] >= 150) { $sila['fauvorot'] = 90; $sila['fakrit'] = 110; $sila['uminu'] = 8; $sila['umaxu'] = 8; }
if($us['sila'] >= 175) { $sila['fauvorot'] = 120; $sila['fakrit'] = 150; $sila['uminu'] = 12; $sila['umaxu'] = 12; }
if($us['sila'] >= 200) { $sila['fauvorot'] = 150; $sila['fakrit'] = 200; $sila['uminu'] = 15; $sila['umaxu'] = 15; }
if($us['lovk'] >= 25) { $lovk['fuvorot'] = 10; $lovk['fauvorot'] = 10; $lovk['fakrit'] = 20; $lovk['uminu'] = 0; $lovk['umaxu'] = 0; }
if($us['lovk'] >= 50) { $lovk['fuvorot'] = 20; $lovk['fauvorot'] = 25; $lovk['fakrit'] = 40; $lovk['uminu'] = 0; $lovk['umaxu'] = 0; }
if($us['lovk'] >= 75) { $lovk['fuvorot'] = 30; $lovk['fauvorot'] = 30; $lovk['fakrit'] = 60; $lovk['uminu'] = 0; $lovk['umaxu'] = 0; }
if($us['lovk'] >= 100) { $lovk['fuvorot'] = 40; $lovk['fauvorot'] = 40; $lovk['fakrit'] = 75; $lovk['uminu'] = 5; $lovk['umaxu'] = 5; }
if($us['lovk'] >= 125) { $lovk['fuvorot'] = 40; $lovk['fauvorot'] = 70; $lovk['fakrit'] = 90; $lovk['uminu'] = 6; $lovk['umaxu'] = 6; }
if($us['lovk'] >= 150) { $lovk['fuvorot'] = 40; $lovk['fauvorot'] = 150; $lovk['fakrit'] = 120; $lovk['uminu'] = 8; $lovk['umaxu'] = 8; }
if($us['lovk'] >= 175) { $lovk['fuvorot'] = 40; $lovk['fauvorot'] = 200; $lovk['fakrit'] = 140; $lovk['uminu'] = 10; $lovk['umaxu'] = 10; }
if($us['lovk'] >= 200) { $lovk['fuvorot'] = 40; $lovk['fauvorot'] = 250; $lovk['fakrit'] = 160; $lovk['uminu'] = 15; $lovk['umaxu'] = 15; }
if($us['inta'] >= 25) { $inta['fkrit'] = 10; $inta['fauvorot'] = 10; $inta['fakrit'] = 15; $inta['uminu'] = 0; $inta['umaxu'] = 0; }
if($us['inta'] >= 50) { $inta['fkrit'] = 25; $inta['fauvorot'] = 25; $inta['fakrit'] = 25; $inta['uminu'] = 0; $inta['umaxu'] = 0; }
if($us['inta'] >= 75) { $inta['fkrit'] = 60; $inta['fauvorot'] = 30; $inta['fakrit'] = 30; $inta['uminu'] = 0; $inta['umaxu'] = 0; }
if($us['inta'] >= 100) { $inta['fkrit'] = 40; $inta['fauvorot'] = 40; $inta['fakrit'] = 75; $inta['uminu'] = 0; $inta['umaxu'] = 0; }
if($us['inta'] >= 125) { $inta['fkrit'] = 40; $inta['fauvorot'] = 50; $inta['fakrit'] = 100; $inta['uminu'] = 1; $inta['umaxu'] = 1; }
if($us['inta'] >= 150) { $inta['fkrit'] = 60; $inta['fauvorot'] = 40; $inta['fakrit'] = 130; $inta['uminu'] = 5; $inta['umaxu'] = 5; }
if($us['inta'] >= 175) { $inta['fkrit'] = 40; $inta['fauvorot'] = 80; $inta['fakrit'] = 170; $inta['uminu'] = 10; $inta['umaxu'] = 10; }
if($us['inta'] >= 200) { $inta['fkrit'] = 40; $inta['fauvorot'] = 120; $inta['fakrit'] = 200; $inta['uminu'] = 15; $inta['umaxu'] = 15; }
if($us['vinos'] >= 25) { $vinos['fkrit'] = 10; $vinos['fauvorot'] = 10; $vinos['fakrit'] = 15; $vinos['uminu'] = 0; $vinos['umaxu'] = 0; }
if($us['vinos'] >= 50) { $vinos['fkrit'] = 25; $vinos['fauvorot'] = 25; $vinos['fakrit'] = 25; $vinos['uminu'] = 0; $vinos['umaxu'] = 0; }
if($us['vinos'] >= 75) { $vinos['fkrit'] = 60; $vinos['fauvorot'] = 30; $vinos['fakrit'] = 30; $vinos['uminu'] = 0; $vinos['umaxu'] = 0; }
if($us['vinos'] >= 100) { $vinos['fkrit'] = 40; $vinos['fauvorot'] = 40; $vinos['fakrit'] = 75; $vinos['uminu'] = 0; $vinos['umaxu'] = 1; }
if($us['vinos'] >= 125) { $vinos['fkrit'] = 40; $vinos['fauvorot'] = 50; $vinos['fakrit'] = 100; $vinos['uminu'] = 1; $vinos['umaxu'] = 1; }
if($us['vinos'] >= 150) { $vinos['fkrit'] = 60; $vinos['fauvorot'] = 40; $vinos['fakrit'] = 130; $vinos['uminu'] = 5; $vinos['umaxu'] = 5; }
if($us['vinos'] >= 175) { $vinos['fkrit'] = 40; $vinos['fauvorot'] = 80; $vinos['fakrit'] = 170; $vinos['uminu'] = 10; $vinos['umaxu'] = 10; }
if($us['vinos'] >= 200) { $vinos['fkrit'] = 40; $vinos['fauvorot'] = 120; $vinos['fakrit'] = 200; $vinos['uminu'] = 15; $vinos['umaxu'] = 15; }
if($us['vinos'] >= $us['sila'] && $us['vinos'] >= $us['lovk'] && $us['vinos'] >= $us['inta']) {
$i_uminu = $vinos['uminu'];
$i_fkrit = $vinos['fkrit'];
$i_fauvorot = $vinos['fauvorot'];
$i_fakrit = $vinos['fakrit'];
$i_umaxu = $vinos['umaxu'];
}
if($us['inta'] >= $us['sila'] && $us['inta'] >= $us['lovk'] && $us['inta'] >= $us['vinos']) {
$i_uminu = $inta['uminu'];
$i_fkrit = $inta['fkrit'];
$i_fauvorot = $inta['fauvorot'];
$i_fakrit = $inta['fakrit'];
$i_umaxu = $inta['umaxu'];
}
if($us['lovk'] >= $us['sila'] && $us['lovk'] >= $us['inta']&& $us['lovk'] >= $us['vinos']) {
$i_uminu = $lovk['uminu'];
$i_fkrit = $lovk['fkrit'];
$i_fauvorot = $lovk['fauvorot'];
$i_fakrit = $lovk['fakrit'];
$i_umaxu = $lovk['umaxu'];
}
if($us['sila'] >= $us['lovk'] && $us['sila'] >= $us['inta'] && $us['sila'] >= $us['vinos']) {
$i_uminu = $sila['uminu'];
$i_fkrit = $sila['fkrit'];
$i_fauvorot = $sila['fauvorot'];
$i_fakrit = $sila['fakrit'];
$i_umaxu = $sila['umaxu'];
}
return array('minu' => $i_uminu, 'maxu' => $i_umaxu, 'fkrit' => $i_fkrit, 'fauvorot' => $i_fauvorot, 'fakrit' => $i_fakrit);
}
function solve_mfs($user_1, $user_2, $attack) {
$mfs = array();
$uid_1 = $this->get_info_by_id($user_1);
$uid_2 = $this->get_info_by_id($user_2);
$b_u_1 = $this->check_bonus($uid_1['id']);
$b_u_2 = $this->check_bonus($uid_2['id']);
$zo = mysql_fetch_row(mysql_query("SELECT `id` FROM `effects` WHERE `type` = 201 AND `owner` = '".$uid_1['id']."' LIMIT 1"));
$zo1 = mysql_fetch_row(mysql_query("SELECT `id` FROM `effects` WHERE `type` = 201 AND `owner` = '".$uid_2['id']."' LIMIT 1"));
$sokr = mysql_fetch_row(mysql_query("SELECT `id` FROM `effects` WHERE `type` = 202 AND `owner` = '".$uid_1['id']."' LIMIT 1"));
$sokr1 = mysql_fetch_row(mysql_query("SELECT `id` FROM `effects` WHERE `type` = 202 AND `owner` = '".$uid_2['id']."' LIMIT 1"));
if($sokr[0] > 0) { $bmfud = 5; } else { $bmfud = 0; }
if($zo[0] > 0) { $bmfbron = 25; } else { $bmfbron = 0; }
if($sokr1[0] > 0) { $bmfud1 = 5; } else { $bmfud1 = 0; }
if($zo1[0] > 0) { $bmfbron1 = 25; } else { $bmfbron1 = 0; }
if($user_2 > _BOTSEPARATOR_) {
$bots = mysql_fetch_array(mysql_query('SELECT `id`, `name`, `prototype`, `battle`, `hp` FROM `bots` WHERE `id` = "'.$user_2.'" LIMIT 1'));
$this->enemyhar = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "'.$bots['prototype'].'" LIMIT 1'));
$this->enemy_dress = mysql_fetch_array(mysql_query('SELECT SUM(`minu`), SUM(`maxu`), SUM(`mfkrit`), SUM(`mfakrit`), SUM(`mfuvorot`), SUM(`mfauvorot`), SUM(`bron1`), SUM(`bron2`), SUM(`bron3`), SUM(`bron4`) FROM `inventory` WHERE `dressed` = 1 AND `owner` = "'.$this->enemyhar['id'].'"'));
$this->enemyhar['hp'] = $bots['hp'];
} else {
$this->enemyhar = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "'.$uid_2['id'].'" LIMIT 1'));
$this->enemy_dress = mysql_fetch_array(mysql_query('SELECT SUM(`minu`), SUM(`maxu`), SUM(`mfkrit`), SUM(`mfakrit`), SUM(`mfuvorot`), SUM(`mfauvorot`), SUM(`bron1`), SUM(`bron2`), SUM(`bron3`), SUM(`bron4`) FROM `inventory` WHERE `dressed` = 1 AND `owner` = "'.$uid_2['id'].'"'));
}
$this->user_dress = mysql_fetch_array(mysql_query('SELECT SUM(`minu`), SUM(`maxu`), SUM(`mfkrit`), SUM(`mfakrit`), SUM(`mfuvorot`), SUM(`mfauvorot`), SUM(`bron1`), SUM(`bron2`), SUM(`bron3`), SUM(`bron4`) FROM `inventory` WHERE `dressed` = 1 AND `owner` = "'.$uid_1['id'].'"'));
$this->enemy_dress[6] += $bmfbron1;
$this->enemy_dress[7] += $bmfbron1;
$this->enemy_dress[8] += $bmfbron1;
$this->enemy_dress[9] += $bmfbron1;
$this->user_dress[6] += $bmfbron;
$this->user_dress[7] += $bmfbron;
$this->user_dress[8] += $bmfbron;
$this->user_dress[9] += $bmfbron;
$mykrit = floor($this->user_dress[2]+($uid_1['inta']*2.95)+$b_u_1['fkrit']);
$heakrit = floor($this->enemy_dress[3]+($uid_2['inta']*2.75)+$b_u_2['fkrit']);
$myuvorot = floor($this->user_dress[4]+$uid_1['lovk']*5); #5 #3
$heauvorot = floor($this->enemy_dress[5]+$uid_2['lovk']*4); #4 #7 #6
$he_koef_armor = $this->enemy_dress[5+$attack]/50;
$mfs['me'] = array(
'udars' => rand(floor($uid_1['sila']/3)+$b_u_1['minu']+1+$this->user_dress[0], floor($uid_1['sila']/3)+$b_u_1['maxu']+4+$this->user_dress[1]),
'chanse' => $this->getmfs($myuvorot, $heauvorot),
'chanse_krit' => $this->getmfs($mykrit, $heakrit)
);
$mfs['me']['udar'] = $mfs['me']['udars']-($this->enemy_dress[5+$attack]*$he_koef_armor);
$uron_vlad_me = 0;
switch($this->GetWeaponType($uid_1['weap'])) {
case "noj": $uron_vlad_me += $uid_1['noj']; break;
case "dubina": $uron_vlad_me += $uid_1['dubina']; break;
case "topor": $uron_vlad_me += $uid_1['topor']; break;
case "mech": $uron_vlad_me += $uid_1['mec']; break;
default : 0; break;
}
$mfs['me']['udar'] += $uron_vlad_me;
if($bmfud > 5) { $mfs['me']['udar'] += $bmfud; }
if($mfs['me']['udar'] < 0) { $mfs['me']['udar'] = 0; }
if($bmfud <= 5) { $mfs['me']['udar'] += $bmfud; }
$mfs['me']['udar'] = round($mfs['me']['udar']);
if($mfs['me']['udar'] < 1) { $mfs['me']['udar'] = 1; }
#$this->AddToLog('{Id = '.$uid_1['id'].'| No_Koef = '.$mfs['me']['udars'].'| Finish = '.$mfs['me']['udar'].'| Koef = '.$he_koef_armor.'| Armor = '.$this->enemy_dress[5+$attack].' | Um = '.$uron_vlad_me.'| Weap = '.$this->GetWeaponType($uid_1['weap']).'| Function = '.$mfs['me']['udars'].'-'.($this->enemy_dress[5+$attack]*$he_koef_armor).'| Min = '.(floor($uid_1['sila']/3)+$b_u_1['minu']+1+$this->user_dress[0]).'| Max = '.(floor($uid_1['sila']/3)+$b_u_1['maxu']+4+$this->user_dress[1]).'}<BR>');
$mykrits = floor($this->enemy_dress[2]+($uid_2['inta']*2.95)+$b_u_2['fkrit']);
$heakrits = floor($this->user_dress[3]+($uid_1['inta']*2.75)+$b_u_1['fkrit']);
$myuvorots = floor($this->enemy_dress[4]+$uid_2['lovk']*5);
$heauvorots = floor($this->user_dress[5]+$uid_1['lovk']*4);
$me_koef_armor = $this->user_dress[5+$this->battle[$user_2][$user_1][0]]/50;
$mfs['he'] = array(
'udars' => floor(rand(floor($uid_2['sila']/3)+$b_u_2['minu']+1+$this->enemy_dress[0], floor($uid_2['sila']/3)+$b_u_2['maxu']+4+$this->enemy_dress[1])),
'chanse' => $this->getmfs($myuvorots, $heauvorots),
'chanse_krit' => $this->getmfs($mykrits, $heakrits)
);
$mfs['he']['udar'] = $mfs['he']['udars']-($this->user_dress[5+$this->battle[$user_2][$user_1][0]]*$me_koef_armor);
if($bmfud1 < 5) { $mfs['he']['udar'] += $bmfud1; }
if($mfs['he']['udar'] < 0) { $mfs['he']['udar'] = 0; }
if($bmfud1 >= 5) { $mfs['he']['udar'] += $bmfud1; }
$uron_vlad_he = 0;
switch($this->GetWeaponType($uid_2['weap'])) {
case "noj": $uron_vlad_he += $uid_2['noj']; break;
case "dubina": $uron_vlad_he += $uid_2['dubina']; break;
case "topor": $uron_vlad_he += $uid_2['topor']; break;
case "mech": $uron_vlad_he += $uid_2['mec']; break;
}
$mfs['he']['udar'] += $uron_vlad_he;
#$this->AddToLog('{ Id = '.$uid_2['id'].'| URON_not_koef = '.$mfs['he']['udars'].'| Uron_finish = '.$mfs['he']['udar'].'| Koef_arm = '.$me_koef_armor.'| Armor = '.$this->user_dress[5+$this->battle[$user_2][$user_1][0]].' | Um = '.$uron_vlad_he.'| Weap = '.$this->GetWeaponType($uid_2['weap']).' }<BR>');
$mfs['he']['udar'] = round($mfs['he']['udar']);
if($mfs['he']['udar'] < 1) { $mfs['he']['udar'] = 1; }
return $mfs;
}
function makechange($u1, $u2, $at_1, $at_2, $def_1, $def_2) {
$this->init_botRazmen($u1, $u2, $at_1, $def_1);
}
function UpdateBattle () {
return mysql_query("UPDATE `battle` SET `exp` = '".serialize($this->exp)."', `teams` = '".serialize($this->battle)."', `damage` = '".serialize($this->damage)."' WHERE `id` = '".$this->battle_data['id']."' LIMIT 1");
}
function GetComment() {
$boycom = array('А танцуешь ты лучше.','А мы что, в прятки тут играем?','А вы разве пингвинов никогда не видели?','А, ведь когда-то, вы были красивыми… А теперь? Ну и рожи! Жуть!','А потом еще труп пинать будут.','А я вчера ночью за соседями подглядывал. Они точно так же кувыркались','А ведь вы живых людей дубасите...','А вот я вчера в зоопарке был...','А вы в стройбате не служили?','А вы видели, чтобы так на улице делали!?','А вы знали что ёжики размножаются в интернете?','А жить-то, как хочется:','А из-за чего вы собственно дерётесь?','А чего ржёте, вы ещё остальных не видели','А что произойдёт если ты испугаешся до полусмерти дважды?!','Больше так не делай. Ты же не садист?','Без комментариев...','Больно ведь!','Быстро ты за монитор спрятался!','Все хотят попасть в рай, но никто не хочет умирать!','Вчера с такой девчонкой познакомился.','Всего 5 минут знакомы, а дерутся, словно супруги с 20-ти летним стажем...','Все. Я так больше не могу.','В конце концов, кто-то победит?','Вы чего, с дерева упали?','Возятся как сонные мухи... давайте я вам лучше анекдот расскажу: ...','Вот видишь, как полезно чистить зубы на ночь?','Вот вы все руками махаете, а за вами уже очередь','Вот попадёте вы в плен и вас там будут долго бить. Но вы ничего не расскажете... и не потому, что вы такой стойкий, просто вы ничего не знаете','Вы бы лучше пошли потренировались!','Вы все еще разминаетесь? Позовите, когда кости в муку друг другу разминать будете.','Вы же бойцы! Имейте совесть!','Гаси недоумка!','Да, если бы я смог это остановить, то получил бы нобелевскую премию `За мир` ','Да куда они бьют?!','Давайте быстрее! За вами уже очередь образовалась.','Давайте обойдемся сегодня таймаутом. А? А то мне уже кошмары скоро будут сниться.','Дерутся как девчонки!','Дети, посмотрите налево... Ой!.. Нет, туда лучше не смотреть.','Если так будет продолжаться, то скоро мы заснем!','Если бы у меня было кресло-качалка, я бы в нём качался...','Если вы что-то сказать хотите, то лучше молчите :)','Жестокость не порок.','Жизнь вне нашего клуба - это пустая трата кислорода!!!','Жми! Дави! Кусай! Царапай!','За такие бои надо в хаос отправлять!','Знаете откуда в комиссионном магазине столько вещей? Это я после ваших гулянок собираю и сдаю туда. Иногда вместе с частями тела, застрявшими в них.','Здесь люди так близки друг к другу. Просто иначе ударить нельзя.','<EFBFBD>
if(mt_rand(0, 4) == 1) {
return '<span class=date>'.date("H:i").'</span> <i>Комментатор: '.$boycom[mt_rand(0, count($boycom)-1)].'</i><BR>';
} else {
return false;
}
}
function GetTimeout() {
if($this->battle) {
if($this->my_class == 'B1') {
if($this->to2 <= $this->to1) {
return ((time()-$this->to2) > $this->battle_data['timeout']*60);
} else {
return false;
}
} else {
if($this->to2 >= $this->to1) {
return ((time()-$this->to1) > $this->battle_data['timeout']*60);
} else {
return false;
}
}
}
}
function AddToLog($text) {
$this->log .= $text;
}
function AddToLogBot($text) {
if($this->log != $text) {
$this->log .= $text;
}
}
function write_log() {
if($this->log) {
$this->log = $this->log."<hr>";
}
addlogs($this->battle_data['id'], $this->log);
$this->log = '';
}
}
$r = mysql_query("SELECT `id`, `win` FROM `battle` WHERE `win` = 3");
while($rec = mysql_fetch_array($r)) {
$fbattle = new fbattle($rec['id']);
if($fbattle->battle_data['needbb']) {
foreach($fbattle->battle as $k => $v) {
if($k > _BOTSEPARATOR_) {
foreach($v as $k2 => $v2) {
if($k2 < _BOTSEPARATOR_) continue;
$hp_1 = mysql_fetch_array(mysql_query('SELECT `hp` FROM `bots` WHERE `id` = "'.$k.'" LIMIT 1'));
$hp_2 = mysql_fetch_array(mysql_query('SELECT `hp` FROM `bots` WHERE `id` = "'.$k2.'" LIMIT 1'));
if($fbattle->battle[$k][$k2][0] && $fbattle->battle[$k2][$k][0] && $hp_1['hp'] > 0 && $hp_2['hp'] > 0) {
$at_1 = $fbattle->battle[$k][$k2][0];
$def_1 = $fbattle->battle[$k][$k2][1];
$at_2 = $fbattle->battle[$k2][$k][0];
$def_2 = $fbattle->battle[$k2][$k][1];
$fbattle->makechange($k, $k2, $at_1, $at_2, $def_1, $def_2);
$fbattle->write_log();
$fbattle->battle[$k][$k2] = array(0, 0, time());
$fbattle->battle[$k2][$k] = array(0, 0, time());
$fbattle->needupdate = 1;
$fbattle->battle_end();
}
}
}
}
if($fbattle->needupdate) {
$fbattle->UpdateBattle();
}
echo 'Bb id = |'.$rec['id'].'|';
} else {
echo '{No bb Id = |'.$rec['id'].'|}';
}
}