battles/magic/wis_water_r2.php

149 lines
6.0 KiB
PHP
Raw Normal View History

2018-01-28 16:40:49 +00:00
<?php
//параметры
$basedmg = 210;
$needmana = 65;
$needint = 100;
$elem = 'w';
$t_min = 1;
$t_max = 3;
$count = mt_rand($t_min, $t_max);
$mag_id = 124;
$log_text = "<strong><font color=#0d2b99>Регенерация [2]</font></strong>";
$book = 908;
$have_book = mysql_fetch_array(mysql_query("SELECT `id` FROM `inventory` WHERE `prototype`='{$book}' AND `owner`='{$user['id']}' LIMIT 1;"));
2018-01-28 16:40:49 +00:00
if (empty($_SESSION['uid'])) {
header("Location: index.php");
exit;
}
2018-01-28 16:40:49 +00:00
$magic = mysql_fetch_array(mysql_query("SELECT `chanse` FROM `magic` WHERE `id` = '{$mag_id}' LIMIT 1 ;"));
$bat = mysql_fetch_array(mysql_query("SELECT * FROM `battle` WHERE `id`='{$user['battle']}';"));
2018-01-28 16:40:49 +00:00
//mana needed
$t1 = explode(";", $bat['t1']);
$t2 = explode(";", $bat['t2']);
if (in_array($user['id'], $t1)) $e_team = $t1;
if (in_array($user['id'], $t2)) $e_team = $t2;
foreach ($e_team as $k => $l) {
if ($l > _BOTSEPARATOR_) $e_hp = mysql_fetch_array(mysql_query("SELECT `hp` FROM `bots` WHERE `id`='{$l}' LIMIT 1;"));
else $e_hp = mysql_fetch_array(mysql_query("SELECT `hp` FROM `users` WHERE `id`='{$l}' LIMIT 1;"));
if ($e_hp['hp'] < 1) unset($e_team[$k]);
2018-01-28 16:40:49 +00:00
}
shuffle($e_team);
if ($user['battle'] == 0) {
echo "Это боевая магия...";
2018-01-28 16:40:49 +00:00
} elseif (!$have_book['id']) {
echo("У Вас нет необходимой книги магии!");
} elseif ($user['mana'] < $needmana) {
echo "Недостаточно энергии!";
2018-01-28 16:40:49 +00:00
} else {
//attack script
if ($user['intel'] >= $needint) {
$int = $magic['chanse'] + ($user['intel'] - $needint) * 3;
if ($int > 98) {
$int = 99;
}
} else {
$int = 0;
}
2018-01-28 16:40:49 +00:00
if (rand(1, 100) < $int) {
global $elem_align, $elem_bonus;
$user_elem = element(star_sign(substr($user['borndate'], 3, 2), substr($user['borndate'], 0, 2)));
2018-01-28 16:40:49 +00:00
switch ($user_elem) {
case 'f':
$uel = 'mfire';
break;
case 'a':
$uel = 'mair';
break;
case 'w':
$uel = 'mwater';
break;
case 'e':
$uel = 'mearth';
break;
}
switch ($elem) {
case 'f':
$sel = 'mfire';
break;
case 'a':
$sel = 'mair';
break;
case 'w':
$sel = 'mwater';
break;
case 'e':
$sel = 'mearth';
break;
}
$sex_action = "применил";
if ($user['sex'] == 0) $sex_action .= "а";
addlog($user['battle'], '<span class=date>' . date("H:i") . '</span> ' . Nick::id($user['id'])->short() . ' ' . $sex_action . $targeted . ' заклинание ' . $log_text . '<BR>');
2018-01-28 16:40:49 +00:00
//mass magic
mysql_query("UPDATE `users` SET `mana` = `mana`-'" . $needmana . "' WHERE `id` = '" . $user['id'] . "';");
foreach ($e_team as $v)
if ($count > 0) {
$count--;
$bat = mysql_fetch_array(mysql_query("SELECT * FROM `battle` WHERE `id`='{$user['battle']}';"));
$us = mysql_fetch_array(mysql_query("SELECT *,(select `id` from `online` WHERE `real_time` >= " . (time() - 60) . " AND `id` = users.`id`) as `online` FROM `users` WHERE `id` = '{$v}' LIMIT 1;"));
if (!$us) {
$bot = mysql_fetch_array(mysql_query("SELECT * FROM `bots` WHERE `id` = '{$v}' LIMIT 1;"));
$b_maxhp = mysql_fetch_array(mysql_query("SELECT `maxhp` FROM `users`WHERE `id`='{$bot['prototype']}' LIMIT 1;"));
$b_maxhp = $b_maxhp['maxhp'];
}
//dmg=base+INT/LVL+X_magic
$dmg = $basedmg + ($user['intel'] / $user['level']) + $user[$sel];
//MF
$dmg *= $elem_align[$user_elem][$elem];
if ($us) $dmg *= $elem_bonus[element(star_sign(substr($user['borndate'], 3, 2), substr($user['borndate'], 0, 2)))][element(star_sign(substr($us['borndate'], 3, 2), substr($us['borndate'], 0, 2)))];
//rand +- 25%
$dmg = mt_rand(0.75 * $dmg, 1.25 * $dmg);
$dmg = round($dmg);
if ($us) $delta = $us['maxhp'] - $us['hp'];
else $delta = $b_maxhp - $bot['hp'];
if ($delta < $dmg) $dmg = floor($delta);
if ($dmg < 1) $dmg = 0;
2018-01-28 16:40:49 +00:00
if ($us) $target = $us['id'];
else $target = $bot['id'];
2018-01-28 16:40:49 +00:00
$targeted = '';
//dmg >0 - go
$all_dmg = unserialize($bat['damage']);
$all_exp = unserialize($bat['exp']);
$all_dmg[$user['id']] += $dmg;
$all_exp[$user['id']] += SolveExp($user['id'], $target, $dmg);
2018-01-28 16:40:49 +00:00
//сработало
if ($dmg > 0) $hit = '-1'; else $hit = 0;
$action = preg_replace("/Х/", Nick::id($target)->short(), magic_log($elem, $hit, $target));
if ($dmg > 0) {
if ($us)
mysql_query("UPDATE `users` SET `hp` = `hp`+'" . $dmg . "' WHERE `id` = '" . $target . "';");
else
mysql_query("UPDATE `bots` SET `hp` = `hp`+'" . $dmg . "' WHERE `id` = '" . $target . "';");
mysql_query("UPDATE `battle` SET `damage`='" . serialize($all_dmg) . "', `exp`='" . serialize($all_exp) . "' WHERE `id`='{$user['battle']}';");
2018-01-28 16:40:49 +00:00
addlog($user['battle'], '<span class=date>' . date("H:i") . '</span> ' . $action . ' <strong>+' . $dmg . '</strong><BR>');
2018-01-28 16:40:49 +00:00
$bet = 1;
} else //не сработало
{
addlog($user['battle'], '<span class=date>' . date("H:i") . '</span> ' . $action . '<BR>');
$bet = 1;
}
}
2018-01-28 16:40:49 +00:00
} else {
echo "Свиток рассыпался в ваших руках...";
$bet = 1;
}
2018-01-28 16:40:49 +00:00
}