Нападалка вынесена из Magic.php.

This commit is contained in:
Ivor Barhansky 2023-08-14 16:03:45 +03:00
parent f557dbcd1a
commit 63be6c94b3
6 changed files with 1655 additions and 560 deletions

View File

@ -2,7 +2,7 @@
use Core\ConversionHelper;
use Core\Db;
use Insallah\Math;
use Magic\Attack;
use User\ItemsModel;
class Magic
@ -11,6 +11,7 @@ class Magic
public int $youuse = 0;
public array $cMagic = [4174, 4175, 4176, 4177, 4178, 4179, 4180];
public array $eMagic = [4185, 4186, 4187];
private Attack $attack;
public function __construct()
{
@ -18,6 +19,7 @@ class Magic
if (isset($_POST['useitemon'])) {
$_GET['login'] = $_POST['useitemon'];
}
$this->attack = new Attack($this);
}
public function useItems($id)
@ -2063,514 +2065,14 @@ class Magic
return $g;
}
public function atackUser($uid1, $uid2, $tm, $btl, $addExp = 0, $type = 0, $kulak = 0, $bsid = 0)
public function atackUser($uid1, $uid2, $tm, $btl, $addExp = 0, $type = 0)
{
global $u;
$usr = mysql_fetch_array(
mysql_query(
'SELECT `u`.*,`s`.* FROM `users` AS `u` LEFT JOIN `stats` AS `s` ON `u`.`id` = `s`.`id` WHERE `u`.`id` = "' . $uid2 . '" LIMIT 1'
)
);
$btl_test = mysql_fetch_array(
mysql_query('SELECT * FROM `battle` WHERE `id` = "' . $btl . '" AND `team_win` = -1 LIMIT 1')
);
$clan_test = mysql_fetch_array(
mysql_query(
'SELECT * FROM `clan_wars` WHERE ((`clan1`="' . $u->info['clan'] . '" AND `clan2`="' . $usr['clan'] . '") OR (`clan2`="' . $u->info['clan'] . '" AND `clan1`="' . $usr['clan'] . '")) AND `time_finish` > "' . time() . '" LIMIT 1'
)
);
$good = 0;
//Эффекты из-за которых нельзя нападать
$efsno = mysql_fetch_array(
mysql_query(
'SELECT * FROM `eff_users` WHERE `uid` = "' . $uid2 . '"
AND `name` LIKE "%Лепим снежок%" AND `delete` = "0"
LIMIT 1'
)
);
$check = mysql_fetch_array(
mysql_query(
'SELECT * FROM `eff_users` WHERE `id_eff` = 478 AND `uid` = "' . $u->info['id'] . '" AND `delete` = 0 ORDER BY `overType` DESC LIMIT 1;'
)
);
$check2 = mysql_fetch_array(
mysql_query(
'SELECT * FROM `eff_users` WHERE (`id_eff` = 479 OR `id_eff` = 480 OR `id_eff` = 481) AND `uid` = "' . $usr['id'] . '" AND `delete` = 0 ORDER BY `overType` DESC LIMIT 1;'
)
);
$u->error = 'Нельзя нападать на монстра этого уровня!';
if ($usr['no_ip'] == 'trupojor' && $usr['level'] == 9 && $u->info['level'] > 9) {
$u->error = 'Нельзя нападать на монстра этого уровня!';
} elseif ($usr['no_ip'] == 'trupojor' && $usr['level'] == 10 && ($u->info['level'] < 10 || $u->info['level'] > 11)) {
$u->error = 'Нельзя нападать на монстра этого уровня!';
} elseif ($ua['no_ip'] == 'trupojor' && isset($check['id'])) { //&& $ua['level'] >9
$u->error = 'Нельзя нападать на монстра чаще одного раза в 3 часа!';
} elseif (isset($check2['id'])) { //&& $ua['level'] >9
$u->error = 'Персонаж имеет защиту от нападения!';
} elseif ($usr['level'] == 8 && $usr['no_ip'] != 'trupojor' && self::canAttack8Level(
$u->info['id'], $usr['id']
)) {
$u->error = 'На 8-е уровни нападать нельзя.';
} elseif ($u->info['level'] != $usr['level'] && $usr['no_ip'] != 'trupojor') { //&& !isset ($clan_test['id'])
$u->error = 'Нападать можно на персонажей только своего уровня!!!';
} elseif (isset($btl_test['id']) && $btl_test['noatack'] > 0) {
$u->error = 'Поединок защищен магией! Вы не можете вмешаться!';
} elseif ($usr['level'] < 8) {
$u->error = 'Новички находятся под защитой Мироздателя...';
} elseif ($u->info['level'] < 8) {
$u->error = 'Тренируйтесь вам пока еще рано...';
} elseif (isset($efsno['id']) && $efsno['delete'] > 0) {
$u->error = 'Невозможно напасть, противник чем-то занят...';
} elseif ($usr['admin'] == 1 && $u->info['admin'] == 0) {
$u->error = 'Уважайте хранителей...';
} elseif ($this->testTravma($uid2, 3)) {
$u->error = 'Противник тяжело травмирован, нельзя напасть!';
} elseif ($this->testTravma($uid1, 2)) {
$u->error = 'Вы травмированы, нельзя напасть!';
} elseif ($bsid != 0 && ($u->info['x'] != $usr['x'] || $u->info['y'] != $usr['y'])) {
$u->error = 'Вы находитесь в разных комнатах...';
} elseif ($usr['clan'] != 0 && ($usr['clan'] == $u->info['clan']) && $u->info['admin'] == 0) {
$u->error = 'Чтите честь ваших сокланов.';
} elseif ($btl != 0 && $btl_test['smert'] == 1 && $type != 222) {
$u->error = 'Вы не можете вмешаться в этот кровавый поединок!';
} elseif ($btl == 0) {
$s01 = $u->getStats($uid1, 0);
if ($s01['hpNow'] < floor($s01['hpAll'] / 100 * 33)) {
$u->error = 'Нельзя напасть, у противника не восстановилось здоровье';
} else {
$addExp += $usr['bbexp'];
//effect ненападения
if ($usr['no_ip'] == 'trupojor') {
mysql_query(
'INSERT INTO `eff_users` (`no_Ace`,`id_eff`,`overType`,`uid`,`name`,`data`,`timeUse`) VALUES ("1","479","112","' . $u->info['id'] . '","Защита от нападения","zashitatk=1","' . time() . '")'
);
}
//тут клан вар
//************
//нападаем на персонажа
$timewait = rand(1, 3);
//===Удаление защиты от нападения в результате нападения пользователем
$dsl = mysql_query(
'SELECT * FROM `eff_users` WHERE (`id_eff` = 479 OR `id_eff` = 480 OR `id_eff` = 481) AND `uid` = "' . $u->info['id'] . '" AND `delete` = 0 ORDER BY `overType` DESC;'
);
while ($dpl = mysql_fetch_array($dsl)) {
mysql_query(
'UPDATE `eff_users` SET `delete` = "' . time() . '" WHERE `id` = "' . $dpl['id'] . '";'
);
}
//=======
if ($type == 222) //
{
$ins = mysql_query(
'INSERT INTO `battle` (`kulak`,`city`,`time_start`,`players`,`timeout`,`type`,`invis`,`noinc`,`travmChance`,`typeBattle`,`addExp`,`money`, `inTurnir`, `clan1`, `clan2`, `smert` ) VALUES (
"' . $kulak . '",
"' . $u->info['city'] . '",
"' . time() . '",
"' . $u->info['login'] . ',' . $usr['login'] . '",
"' . (60 * $timewait) . '",
"99",
"0",
"0",
"50",
"9",
"' . $addExp . '",
"0",
"' . $bsid . '",
"' . $u->info['clan'] . '",
"' . $usr['clan'] . '",
"1"
)'
);
} elseif (isset ($clan_test['id'])) //
{
$ins = mysql_query(
'INSERT INTO `battle` (`kulak`,`city`,`time_start`,`players`,`timeout`,`type`,`invis`,`noinc`,`travmChance`,`typeBattle`,`addExp`,`money`, `inTurnir`, `clan1`, `clan2` ) VALUES (
"' . $kulak . '",
"' . $u->info['city'] . '",
"' . time() . '",
"' . $u->info['login'] . ',' . $usr['login'] . '",
"' . (60 * $timewait) . '",
"250",
"0",
"0",
"50",
"9",
"' . $addExp . '",
"0",
"' . $bsid . '",
"' . $u->info['clan'] . '",
"' . $usr['clan'] . '")'
);
} else {
$ins = mysql_query(
'INSERT INTO `battle` (`kulak`,`city`,`time_start`,`players`,`timeout`,`type`,`invis`,`noinc`,`travmChance`,`typeBattle`,`addExp`,`money`, `inTurnir`) VALUES (
"' . $kulak . '",
"' . $u->info['city'] . '",
"' . time() . '",
"' . $u->info['login'] . ',' . $usr['login'] . '",
"' . (60 * $timewait) . '",
"' . $type . '",
"0",
"0",
"50",
"9",
"' . $addExp . '",
"0", "' . $bsid . '")'
);
}
unset($timewait);
if ($ins) {
$btl_id = mysql_insert_id();
//Обновляем НР и МР игрокам
if ($s01['level'] <= 7) {
$s01['tactic7'] = floor(10 / $s01['hpAll'] * $s01['hpNow']);
} elseif ($s01['level'] == 8) {
$s01['tactic7'] = floor(20 / $s01['hpAll'] * $s01['hpNow']);
} elseif ($s01['level'] == 9) {
$s01['tactic7'] = floor(30 / $s01['hpAll'] * $s01['hpNow']);
} elseif ($s01['level'] >= 10) {
$s01['tactic7'] = floor(40 / $s01['hpAll'] * $s01['hpNow']);
}
$s01 = ['hpAll' => $s01['hpAll'], 'hpNow' => $s01['hpNow'], 'mpAll' => $s01['mpAll'], 'mpNow' => $s01['mpNow']];
$s02 = $u->getStats($uid2, 0);
if ($s02['level'] <= 7) {
$s02['tactic7'] = floor(10 / $s02['hpAll'] * $s02['hpNow']);
} elseif ($s02['level'] == 8) {
$s02['tactic7'] = floor(20 / $s02['hpAll'] * $s02['hpNow']);
} elseif ($s02['level'] == 9) {
$s02['tactic7'] = floor(30 / $s02['hpAll'] * $s02['hpNow']);
} elseif ($s02['level'] >= 10) {
$s02['tactic7'] = floor(40 / $s02['hpAll'] * $s02['hpNow']);
}
$s02 = ['hpAll' => $s02['hpAll'], 'hpNow' => $s02['hpNow'], 'mpAll' => $s02['mpAll'], 'mpNow' => $s02['mpNow']];
$upd2 = mysql_query(
'UPDATE `users` SET `battle`="' . $btl_id . '" WHERE `id` = "' . $uid1 . '" OR `id` = "' . $uid2 . '" LIMIT 2'
);
mysql_query(
'UPDATE `stats` SET `lider` = "' . $btl_id . '",`tactic7` = "' . $s01['tactic7'] . '",`hpNow` = "' . $s01['hpNow'] . '",`mpNow` = "' . $s01['mpNow'] . '",`team`="1",`zv` = "0" WHERE `id` = "' . $uid1 . '" LIMIT 1'
);
mysql_query(
'UPDATE `stats` SET `lider` = "' . $btl_id . '",`tactic7` = "' . $s02['tactic7'] . '",`hpNow` = "' . $s02['hpNow'] . '",`mpNow` = "' . $s02['mpNow'] . '",`team`="2",`zv` = "0" WHERE `id` = "' . $uid2 . '" LIMIT 1'
);
if ($kulak > 0 || $btl_test['kulak'] > 0) {
mysql_query(
'UPDATE `items_users` SET `inOdet` = "0" WHERE ( `uid` = "' . $uid1 . '" OR `uid` = "' . $uid2 . '" ) AND `delete` = "0"'
);
}
$good = $btl_id;
if ($bsid != 0) {
$bs = mysql_fetch_array(
mysql_query(
'SELECT * FROM `bs_turnirs` WHERE `id` = "' . $u->info['inTurnir'] . '" LIMIT 1'
)
);
if ($u->info['sex'] == 0) {
$text = '<img src="//img.new-combats.tech/i/items/atackk.gif" /> {u1} напал на {u2} завязался бой <a target=_blank href=/logs.php?log=' . $btl_id . ' >»»</a>';
} else {
$text = '<img src="//img.new-combats.tech/i/items/atackk.gif" /> {u1} напала на {u2} завязался бой <a target=_blank href=/logs.php?log=' . $btl_id . ' >»»</a>';
}
$usr_real = mysql_fetch_array(
mysql_query(
'SELECT `id`, `login`, `align`, `clan`, `battle`, `level` FROM `users` WHERE (`inUser` = "' . $usr['id'] . '" OR `id` = "' . $usr['id'] . '") LIMIT 1'
)
);
if (!isset($usr_real['id'])) {
$usr_real = $usr;
}
if (isset($usr_real['id'])) {
$usrreal = '';
if ($usr_real['align'] > 0) {
$usrreal .= '<img src=//img.new-combats.tech/i/align/align' . $usr_real['align'] . '.gif width=12 height=15 >';
}
if ($usr_real['clan'] > 0) {
$usrreal .= '<img src=//img.new-combats.tech/i/clan/' . $usr_real['clan'] . '.gif width=24 height=15 >';
}
$usrreal .= '<b>' . $usr_real['login'] . '</b>[' . $usr_real['level'] . ']<a target=_blank href=/info/' . $usr_real['id'] . ' ><img width=12 hiehgt=11 src=//img.new-combats.tech/i/inf_capitalcity.gif ></a>';
} else {
$usrreal = '<i>Невидимка</i>[??]';
}
$me_real = mysql_fetch_array(
mysql_query(
'SELECT `id`,`login`,`align`,`clan`,`battle`,`level` FROM `users` WHERE `inUser` = "' . $u->info['id'] . '" AND `login` = "' . $u->info['login'] . '" LIMIT 1'
)
);
if (isset($me_real['id'])) {
$mereal = '';
if ($me_real['align'] > 0) {
$mereal .= '<img src=//img.new-combats.tech/i/align/align' . $me_real['align'] . '.gif width=12 height=15 >';
}
if ($me_real['clan'] > 0) {
$mereal .= '<img src=//img.new-combats.tech/i/clan/' . $me_real['clan'] . '.gif width=24 height=15 >';
}
$mereal .= '<b>' . $me_real['login'] . '</b>[' . $me_real['level'] . ']<a target=_blank href=/info/' . $me_real['id'] . ' ><img width=12 hiehgt=11 src=//img.new-combats.tech/i/inf_capitalcity.gif ></a>';
} else {
$mereal = '<i>Невидимка</i>[??]';
}
$text = str_replace('{u1}', $mereal, $text);
$text = str_replace('{u2}', $usrreal, $text);
mysql_query(
'INSERT INTO `bs_logs` (`type`,`text`,`time`,`id_bs`,`count_bs`,`city`,`m`,`u`) VALUES (
"1", "' . mysql_real_escape_string($text) . '", "' . time() . '", "' . $bs['id'] . '", "' . $bs['count'] . '", "' . $bs['city'] . '",
"' . round($bs['money'] * 0.85, 2) . '","' . $i . '")'
);
unset($text, $usrreal, $mereal, $usr_real, $me_real);
}
}
}
} elseif (isset($btl_test['id']) && $btl_test['type'] == 500 && $usr['team'] == 1) {
$u->error = 'Нельзя сражаться на стороне монстров!';
} elseif (isset($btl_test['id']) && $btl_test['type'] == 250 && $u->info['clan'] != $btl_test['clan1'] && $u->info['clan'] != $btl_test['clan2']) {
$u->error = 'Нельзя попасть в клановые бои - если вы неявляетесь представителем данных кланов!!!';
} elseif (isset($btl_test['id']) && $btl_test['invis'] > 0) {
$u->error = 'Нельзя вмешиваться в невидимый бой!';
} elseif ($btl_test['noatack'] > 0) {
$u->error = 'В этот поединок нельзя вмешиваться!';
} else {
//вмешиваемся в бой
//effect ненападения
if ($usr['no_ip'] == 'trupojor') {
mysql_query(
'INSERT INTO `eff_users` (`no_Ace`,`id_eff`,`overType`,`uid`,`name`,`data`,`timeUse`) VALUES ("1","479","112","' . $u->info['id'] . '","Защита от нападения","zashitatk=1","' . time() . '")'
);
}
$upd = mysql_query('UPDATE `users` SET `battle`="' . $btl . '" WHERE `id` = "' . $uid1 . '" LIMIT 1');
if ($upd) {
if ($kulak > 0 || $btl_test['kulak'] > 0) {
mysql_query(
'UPDATE `items_users` SET `inOdet` = "0" WHERE `uid` = "' . $uid1 . '" AND `delete` = "0"'
);
}
$uid1st = $u->getStats($uid1);
$uid1u = mysql_fetch_array(
mysql_query(
'SELECT `id`,`login`,`level`,`clan`,`align`,`sex` FROM `users` WHERE `id` = "' . $uid1 . '" LIMIT 1'
)
);
if ($uid1u['level'] <= 7) {
$uid1st['tactic7'] = floor((10 + $uid1st['s7']) / $uid1st['hpAll'] * $uid1st['hpNow']);
} elseif ($uid1u['level'] == 8) {
$uid1st['tactic7'] = floor((20 + $uid1st['s7']) / $uid1st['hpAll'] * $uid1st['hpNow']);
} elseif ($uid1u['level'] == 9) {
$uid1st['tactic7'] = floor((30 + $uid1st['s7']) / $uid1st['hpAll'] * $uid1st['hpNow']);
} elseif ($uid1u['level'] >= 10) {
$uid1st['tactic7'] = floor((40 + $uid1st['s7']) / $uid1st['hpAll'] * $uid1st['hpNow']);
} else {
$uid1st['tactic7'] = floor((10 + $uid1st['s7']) / $uid1st['hpAll'] * $uid1st['hpNow']);
}
//Духовность, спасение
if ($uid1st['s7'] > 49) {
mysql_query(
'UPDATE `eff_users` SET `delete`="' . time() . '" WHERE `uid` = "' . $uid1st['id'] . '" AND `overType` = 101 AND `delete` = 0'
);
mysql_query(
"
INSERT INTO `eff_users` ( `id_eff`, `uid`, `name`, `data`, `overType`, `timeUse`, `timeAce`, `user_use`, `delete`, `v1`, `v2`, `img2`, `x`, `hod`, `bj`, `sleeptime`, `no_Ace`, `file_finish`, `tr_life_user`, `deactiveTime`, `deactiveLast`, `mark`, `bs`) VALUES
( 22, '" . $uid1st['id'] . "', 'Спасение', 'add_spasenie=1', 101, 77, 0, '" . $uid1st['id'] . "', 0, 'priem', 324, 'preservation.gif', 1, -1, 'спасение', 0, 0, '', 0, 0, 0, 1, 0);
"
);
}
$btxt = '';
if ($uid1u['align'] > 0) {
$btxt = $btxt . '<img width=12 height=15 src=//img.new-combats.tech/i/align/align' . $uid1u['align'] . '.gif >';
}
if ($uid1u['align2'] > 0) {
$btxt = $btxt . '<img width=12 height=15 src=//img.new-combats.tech/i/align/align' . $uid1u['align2'] . '.gif >';
}
if ($uid1u['clan'] > 0) {
$btxt = $btxt . '<img width=24 height=15 src=//img.new-combats.tech/i/clan/' . $uid1u['clan'] . '.gif >';
}
$btxt = $btxt . '<b>{u1}</b>[' . $uid1u['level'] . ']<a href=info/' . $uid1u['id'] . ' target=_blank ><img width=12 height=11 src=//img.new-combats.tech/i/inf_capitalcity.gif ></a>';
if ($uid1u['sex'] == 1) {
$btxt = $btxt . ' вмешалась в поединок.';
} else {
$btxt = $btxt . ' вмешался в поединок.';
}
if ($kulak > 0) {
$btxt .= ' (Кулачное нападение)';
}
$lastHOD = mysql_fetch_array(
mysql_query(
'SELECT * FROM `battle_logs` WHERE `battle` = "' . $btl . '" ORDER BY `id_hod` DESC LIMIT 1'
)
);
if (isset($lastHOD['id'])) {
$id_hod = $lastHOD['id_hod'];
if ($lastHOD['type'] != 6) {
$id_hod++;
}
mysql_query(
'INSERT INTO `battle_logs` (`time`,`battle`,`id_hod`,`text`,`vars`,`zona1`,`zonb1`,`zona2`,`zonb2`,`type`) VALUES ("' . time() . '","' . $btl . '","' . ($id_hod) . '","{tm1} ' . $btxt . '","login1=' . $uid1st['login'] . '||t1=' . $uid1st['team'] . '||login2=' . $uid1st['login'] . '||t2=' . $uid1st['team'] . '||time1=' . time() . '","","","","","6")'
);
}
// Бафф Зверя animal_bonus ---------------------------------
if ($u->info['animal'] > 0) {
$a = mysql_fetch_array(
mysql_query(
'SELECT * FROM `users_animal` WHERE `uid` = "' . $u->info['id'] . '" AND `id` = "' . $u->info['animal'] . '" AND `pet_in_cage` = "0" AND `delete` = "0" LIMIT 1'
)
);
if (isset($a['id'])) {
if ($a['eda'] >= 1) {
$anl = mysql_fetch_array(
mysql_query(
'SELECT `bonus` FROM `levels_animal` WHERE `type` = "' . $a['type'] . '" AND `level` = "' . $a['level'] . '" LIMIT 1'
)
);
$anl = $anl['bonus'];
$tpa = [1 => 'cat', 2 => 'owl', 3 => 'wisp', 4 => 'demon', 5 => 'dog', 6 => 'pig', 7 => 'dragon'];
$tpa2 = [1 => 'Кота', 2 => 'Совы', 3 => 'Светляка', 4 => 'Чертяки', 5 => 'Пса', 6 => 'Свина', 7 => 'Дракона'];
$tpa3 = [1 => 'Кошачья Ловкость', 2 => 'Интуиция Совы', 3 => 'Сила Стихий', 4 => 'Демоническая Сила', 5 => 'Друг', 6 => 'Полная Броня', 7 => 'Инферно'];
mysql_query(
'UPDATE `eff_users` SET `delete`="' . time() . '" WHERE `uid` = "' . $u->info['id'] . '" AND `overType` = 100 AND `delete` = 0'
);
mysql_query(
'INSERT INTO `eff_users` (`hod`,`v2`,`img2`,`id_eff`,`uid`,`name`,`data`,`overType`,`timeUse`,`v1`,`user_use`) VALUES ("-1","201","summon_pet_' . $tpa[$a['type']] . '.gif",22,"' . $u->info['id'] . '","' . $tpa3[$a['type']] . ' [' . $a['level'] . ']","' . $anl . '","100","77","priem","' . $u->info['id'] . '")'
);
if ($a['type'] == 6) {
if ($a['level'] == 1 || $a['level'] == 2 || $a['level'] == 3) {
$zhp = 50;
} elseif ($a['level'] == 4) {
$zhp = 75;
} elseif ($a['level'] == 5 || $a['level'] == 6) {
$zhp = 125;
} elseif ($a['level'] == 7 || $a['level'] == 8) {
$zhp = 150;
} elseif ($a['level'] == 9) {
$zhp = 200;
} elseif ($a['level'] == 10) {
$zhp = 300;
} else {
$zhp = 0;
}
$u->info['hpNow'] += $zhp;
mysql_query(
'UPDATE `stats` SET `hpNow` = "' . $u->info['hpNow'] . '" WHERE `id` = "' . $u->info['id'] . '" LIMIT 1'
);
}
} else {
$cmsg = new ChatMessage();
$cmsg->setRoom($u->info['room']);
$cmsg->setCity($u->info['city']);
$cmsg->setTo($u->info['login']);
$cmsg->setText('<strong>' . $a['name'] . '</strong> нуждается в еде...');
$cmsg->setType(6);
(new Chat())->sendMsg($cmsg);
}
}
}
// Бафф Зверя animal_bonus ---------------------------------
$ltm = [1 => 2, 2 => 1];
mysql_query(
'UPDATE `stats` SET `hpNow` = "' . $uid1st['hpNow'] . '",`mpNow` = "' . $uid1st['mpNow'] . '",`team`="' . $ltm[$tm] . '",`tactic7`="' . (0 + $uid1st['tactic7']) . '" WHERE `id` = "' . $uid1 . '" LIMIT 1'
);
$good = $btl;
unset($uid1st);
if ($bsid != 0) {
$bs = mysql_fetch_array(
mysql_query('SELECT * FROM `bs_turnirs` WHERE `id` = "' . $u->info['inTurnir'] . '" LIMIT 1')
);
if ($u->info['sex'] == 0) {
$text = '<img src="//img.new-combats.tech/i/items/atackk.gif" /> {u1} вмешался в поединок против {u2} <a target=_blank href=/logs.php?log=' . $btl_id . ' >»»</a>';
} else {
$text = '<img src="//img.new-combats.tech/i/items/atackk.gif" /> {u1} вмешалась в поединок против {u2} <a target=_blank href=/logs.php?log=' . $btl_id . ' >»»</a>';
}
$usr_real = mysql_fetch_array(
mysql_query(
'SELECT `id`, `login`, `align`, `clan`, `battle`, `level` FROM `users` WHERE `inUser` = "' . $usr['id'] . '" LIMIT 1'
)
);
if (!isset($usr_real['id'])) {
$usr_real = $usr;
}
if (isset($usr_real['id'])) {
$usrreal = '';
if ($usr_real['align'] > 0) {
$usrreal .= '<img src=//img.new-combats.tech/i/align/align' . $usr_real['align'] . '.gif width=12 height=15 >';
}
if ($usr_real['clan'] > 0) {
$usrreal .= '<img src=//img.new-combats.tech/i/clan/' . $usr_real['clan'] . '.gif width=24 height=15 >';
}
$usrreal .= '<b>' . $usr_real['login'] . '</b>[' . $usr_real['level'] . ']<a target=_blank href=/info/' . $usr_real['id'] . ' ><img width=12 hiehgt=11 src=//img.new-combats.tech/i/inf_capitalcity.gif ></a>';
} else {
$mereal = '<i>Невидимка</i>[??]';
}
$me_real = mysql_fetch_array(
mysql_query(
'SELECT `id`,`login`,`align`,`clan`,`battle`,`level` FROM `users` WHERE `inUser` = "' . $u->info['id'] . '" AND `login` = "' . $u->info['login'] . '" LIMIT 1'
)
);
if (isset($me_real['id'])) {
$mereal = '';
if ($me_real['align'] > 0) {
$mereal .= '<img src=//img.new-combats.tech/i/align/align' . $me_real['align'] . '.gif width=12 height=15 >';
}
if ($me_real['clan'] > 0) {
$mereal .= '<img src=//img.new-combats.tech/i/clan/' . $me_real['clan'] . '.gif width=24 height=15 >';
}
$mereal .= '<b>' . $me_real['login'] . '</b>[' . $me_real['level'] . ']<a target=_blank href=/info/' . $me_real['id'] . ' ><img width=12 hiehgt=11 src=//img.new-combats.tech/i/inf_capitalcity.gif ></a>';
} else {
$mereal = '<i>Невидимка</i>[??]';
}
$text = str_replace('{u1}', $mereal, $text);
$text = str_replace('{u2}', $usrreal, $text);
mysql_query(
'INSERT INTO `bs_logs` (`type`,`text`,`time`,`id_bs`,`count_bs`,`city`,`m`,`u`) VALUES (
"1", "' . mysql_real_escape_string($text) . '", "' . time() . '", "' . $bs['id'] . '", "' . $bs['count'] . '", "' . $bs['city'] . '",
"' . round($bs['money'] * 0.85, 2) . '","' . $i . '")'
);
unset($text, $usrreal, $mereal, $usr_real, $me_real);
}
}
}
return $good;
return $this->attack->atackUser($uid1, $uid2, $tm, $btl, $addExp, $type);
}
//Проверка травмы
private static function canAttack8Level($attacker, $target): bool
{
$aSum = self::getDressedEkrTotalPrice($attacker);
$tRange = Math::get20PercentRange(self::getDressedEkrTotalPrice($target));
return $aSum >= $tRange['min'] && $aSum <= $tRange['max'];
}
private static function getDressedEkrTotalPrice($uid)
{
return Db::getValue('select sum(2price) from items_users where inOdet > 0 and uid = ?', [$uid]);
}
public function testTravma(int $uid, $vals): bool
{
$v1 = Db::getValue('select v1 from eff_users where id_eff = 4 and uid = ? and `delete` = 0 and v1 >= ?', [$uid, $vals]);
return intval($v1) >= intval($vals);
}
//создаем нападение на персонажа
public function inBattleLog($txt, $usr = null)
private function inBattleLog($txt, $usr = null)
{
global $u;
$lastHOD = Db::getRow('select id_hod, type from battle_logs where battle = ? order by id_hod desc limit 1', [$u->info['battle']]);
@ -2596,4 +2098,12 @@ class Magic
];
Db::sql($sql, $args);
}
//создаем нападение на персонажа
public function testTravma(int $uid, $vals): bool
{
$v1 = Db::getValue('select v1 from eff_users where id_eff = 4 and uid = ? and `delete` = 0 and v1 >= ?', [$uid, $vals]);
return intval($v1) >= intval($vals);
}
}

View File

@ -0,0 +1,331 @@
<?php
namespace Magic;
use Chat;
use ChatMessage;
use Core\Config;
use Core\Db;
use Insallah\Math;
use Magic;
use User;
class Attack
{
private Magic $magic;
private int $pigAnimalBonus = 0;
public function __construct(Magic $magic)
{
$this->magic = $magic;
}
public function atackUser($uid1, $uid2, $tm, $btl, $addExp = 0, $type = 0)
{
global $u;
$attacker = User::getInfo($uid1);
$target = User::getInfo($uid2);
$battleTest = Db::getRow('select * from battle where id = ? and team_win = -1');
$good = 0;
$error = '';
if (
self::isMonster($target) &&
(
$target['level'] == 9 && $attacker['level'] > 9 ||
$target['level'] == 10 && ($attacker['level'] < 10 || $attacker['level'] > 11)
)
) {
$error = 'Нельзя нападать на монстра этого уровня!';
} elseif (self::isMonster($target) && User\Effects::hasAttackTimeLimit($attacker['id'])) {
$error = 'Нельзя нападать на монстра чаще одного раза в 3 часа!';
} elseif (User\Effects::isImmuneToAttack($target['id'])) {
$error = 'Персонаж имеет защиту от нападения!';
} elseif ($target['level'] == 8 && !self::isMonster($target) && self::canAttack8Level(
$attacker['id'], $target['id']
)) {
$error = 'На 8-е уровни нападать нельзя.';
} elseif ($attacker['level'] != $target['level'] && !self::isMonster($target)) {
$error = 'Нападать можно на персонажей только своего уровня!!!';
} elseif (isset($battleTest['id']) && $battleTest['noatack'] > 0) {
$error = 'Поединок защищен магией! Вы не можете вмешаться!';
} elseif ($target['level'] < 8) {
$error = 'Новички находятся под защитой Мироздателя...';
} elseif ($attacker['level'] < 8) {
$error = 'Тренируйтесь вам пока еще рано...';
} elseif ($target['admin'] == 1 && $attacker['admin'] == 0) {
$error = 'Уважайте хранителей...';
} elseif ($this->magic->testTravma($uid2, 3)) {
$error = 'Противник тяжело травмирован, нельзя напасть!';
} elseif ($this->magic->testTravma($uid1, 2)) {
$error = 'Вы травмированы, нельзя напасть!';
} elseif ($target['clan'] != 0 && ($target['clan'] == $attacker['clan']) && $attacker['admin'] == 0) {
$error = 'Чтите честь ваших сокланов.';
} elseif ($btl != 0 && $battleTest['smert'] == 1 && $type != 222) {
$error = 'Вы не можете вмешаться в этот кровавый поединок!';
} elseif ($btl == 0) {
$s01 = $u->getStats($uid1, 0);
if ($s01['hpNow'] < floor($s01['hpAll'] / 100 * 33)) {
$error = 'Нельзя напасть, у противника не восстановилось здоровье';
} else {
$addExp += $target['bbexp'];
//effect ненападения
if (self::isMonster($target)) {
User\Effects::giveAttackImmunity($attacker['id']);
}
//тут клан вар
//************
//нападаем на персонажа
//===Удаление защиты от нападения в результате нападения пользователем
User\Effects::removeByIds($attacker['id'], 479, 480, 481);
//=======
if ($type == 222) {
$battleId = self::battleInit($attacker, $target, 99, $addExp, true, 1);
} elseif (self::haveClanWar($attacker['clan'], $target['clan'])) {
$battleId = self::battleInit($attacker, $target, 250, $addExp, true);
} else {
$battleId = self::battleInit($attacker, $target, $type, $addExp);
}
if ($battleId > 0) {
//
$s01 = self::updateHpAndMp($s01);
$s02 = $u->getStats($uid2, 0);
$s02 = self::updateHpAndMp($s02);
Db::sql('update users set battle = ? where id in (?,?)', [$uid1, $uid2]);
$sql = 'update stats set lider = ?, tactic7 = ?, hpNow = ?, mpNow = ?, team = ? where id = ?';
Db::sql($sql, [
$battleId,
$s01['tactic7'],
$s01['hpNow'],
$s01['mpNow'],
1,
$uid1,
]);
Db::sql($sql, [
$battleId,
$s02['tactic7'],
$s02['hpNow'],
$s02['mpNow'],
2,
$uid2,
]);
unset($sql);
$good = $battleId;
}
}
} elseif (isset($battleTest['id']) && $battleTest['type'] == 500 && $target['team'] == 1) {
$error = 'Нельзя сражаться на стороне монстров!';
} elseif (isset($battleTest['id']) && $battleTest['type'] == 250 && $attacker['clan'] != $battleTest['clan1'] && $attacker['clan'] != $battleTest['clan2']) {
$error = 'Нельзя попасть в клановые бои - если вы неявляетесь представителем данных кланов!!!';
} elseif (isset($battleTest['id']) && $battleTest['invis'] > 0) {
$error = 'Нельзя вмешиваться в невидимый бой!';
} elseif ($battleTest['noatack'] > 0) {
$error = 'В этот поединок нельзя вмешиваться!';
} else {
//вмешиваемся в бой
//effect ненападения
if (self::isMonster($target)) {
User\Effects::giveAttackImmunity($attacker['id']);
}
Db::sql('update users set battle = ? where id = ?', [$btl, $uid1]);
$uid1st = $u->getStats($uid1);
$uid1u = User::getInfo($uid1);
if ($uid1u['level'] <= 7) {
$uid1st['tactic7'] = floor((10 + $uid1st['s7']) / $uid1st['hpAll'] * $uid1st['hpNow']);
} elseif ($uid1u['level'] == 8) {
$uid1st['tactic7'] = floor((20 + $uid1st['s7']) / $uid1st['hpAll'] * $uid1st['hpNow']);
} elseif ($uid1u['level'] == 9) {
$uid1st['tactic7'] = floor((30 + $uid1st['s7']) / $uid1st['hpAll'] * $uid1st['hpNow']);
} elseif ($uid1u['level'] >= 10) {
$uid1st['tactic7'] = floor((40 + $uid1st['s7']) / $uid1st['hpAll'] * $uid1st['hpNow']);
} else {
$uid1st['tactic7'] = floor((10 + $uid1st['s7']) / $uid1st['hpAll'] * $uid1st['hpNow']);
}
//Духовность, спасение
if ($uid1st['s7'] > 49) {
User\Effects::addSpasenie($uid1st['id']);
}
$btxt = '';
if ($uid1u['align'] > 0) {
$btxt = $btxt . '<img src=' . Config::img() . '/i/align/align' . $uid1u['align'] . '.gif >';
}
if ($uid1u['align2'] > 0) {
$btxt = $btxt . '<img src=' . Config::img() . '/i/align/align' . $uid1u['align2'] . '.gif >';
}
if ($uid1u['clan'] > 0) {
$btxt = $btxt . '<img src=' . Config::img() . '/i/clan/' . $uid1u['clan'] . '.gif >';
}
$btxt = $btxt . '<b>{u1}</b>[' . $uid1u['level'] . ']<a href=info/' . $uid1u['id'] . ' target=_blank ><img src=' . Config::img() . '/i/inf_capitalcity.gif alt=""></a>';
if ($uid1u['sex'] == 1) {
$btxt = $btxt . ' вмешалась в поединок.';
} else {
$btxt = $btxt . ' вмешался в поединок.';
}
$lastHOD = Db::getRow('select id, id_hod, type from battle_logs where battle = ? order by id_hod desc limit 1');
if (isset($lastHOD['id'])) {
$idHod = $lastHOD['id_hod'];
if ($lastHOD['type'] != 6) {
$idHod++;
}
Db::sql('insert into battle_logs (time, battle, id_hod, text, vars, zona1, zonb1, zona2, zonb2, type) values (unix_timestamp(),?,?,?,?,?,?,?,?,6)', [
$btl,
$idHod,
"{tm1} $btxt",
"login1={$uid1st['login']}||t1={$uid1st['team']}||login2={$uid1st['login']}||t2={$uid1st['team']}||time=" . time(),
"",
"",
"",
"",
]);
}
// Бафф Зверя animal_bonus ---------------------------------
$this->setAnimalBonus($attacker);
User::start()->info['hpNow'] += $this->pigAnimalBonus;
// Бафф Зверя animal_bonus ---------------------------------
$ltm = [1 => 2, 2 => 1];
Db::sql('update stats set hpNow = ?, hpAll = ?, team = ?, tactic7 = ? where id = ?', [$uid1st['hpNow'], $uid1st['mpNow'], $ltm[$tm], (int)$uid1st['tactic7'], $uid1]);
$good = $btl;
unset($uid1st);
}
$u->error = $error;
return $good;
}
private static function isMonster(array $target): bool
{
return $target['no_ip'] === 'trupojor';
}
private static function canAttack8Level($attacker, $target): bool
{
$aSum = User\ItemsModel::getDressedEkrTotalPrice($attacker);
$tRange = Math::get20PercentRange(User\ItemsModel::getDressedEkrTotalPrice($target));
return $aSum >= $tRange['min'] && $aSum <= $tRange['max'];
}
private static function battleInit(array $attacker, array $defender, int $type, float $addExp, bool $isClanWar = false, $smert = 0): int
{
$fighters = "{$attacker['login']},{$defender['login']}";
$clan1 = 0;
$clan2 = 0;
if ($isClanWar) {
$clan1 = $attacker['clan'];
$clan2 = $defender['clan'];
}
$sql = 'insert into battle (city, time_start, players, timeout, type, travmChance, typeBattle, addExp, clan1, clan2, smert) values (?,unix_timestamp(),?,60 * ?,?,50,9,?,?,?,?)';
$args = ['capitalcity', $fighters, mt_rand(1, 3), $type, $addExp, $clan1, $clan2, $smert];
Db::sql($sql, $args);
return (int)Db::lastInsertId();
}
private static function haveClanWar(int $clan1, int $clan2): bool
{
$listStr = "$clan1, $clan2";
return Db::getValue('select count(*) from clan_wars where clan1 in (?) and clan2 in (?) and clan1 != clan2', [$listStr, $listStr]) > 0;
}
/**
* Обновляем НР и МР игрокам.
* @param array $userStats
* @return array
*/
private static function updateHpAndMp(array $userStats): array
{
if ($userStats['level'] <= 7) {
$userStats['tactic7'] = floor(10 / $userStats['hpAll'] * $userStats['hpNow']);
} elseif ($userStats['level'] == 8) {
$userStats['tactic7'] = floor(20 / $userStats['hpAll'] * $userStats['hpNow']);
} elseif ($userStats['level'] == 9) {
$userStats['tactic7'] = floor(30 / $userStats['hpAll'] * $userStats['hpNow']);
} elseif ($userStats['level'] >= 10) {
$userStats['tactic7'] = floor(40 / $userStats['hpAll'] * $userStats['hpNow']);
}
return $userStats;
}
private function setAnimalBonus(array $owner)
{
if ($owner['animal'] < 1) {
return;
}
$animal = Db::getRow('select * from users_animal where uid = ? and id = ? and pet_in_cage = 0', [$owner['id'], $owner['animal']]);
if (!$animal) {
return;
}
if ($animal['eda'] < 1) {
$cmsg = new ChatMessage();
$cmsg->setRoom($owner['room']);
$cmsg->setTo($owner['login']);
$cmsg->setText('<strong>' . $animal['name'] . '</strong> нуждается в еде...');
$cmsg->setType(6);
(new Chat())->sendMsg($cmsg);
return;
}
$animalBonus = Db::getValue('select bonus from levels_animal where type = ? and level = ?', [$animal['type'], $animal['level']]);
$statusName = [
1 => ['cat', 'Кошачья Ловкость'],
2 => ['owl', 'Интуиция Совы'],
3 => ['wisp', 'Сила Стихий'],
4 => ['demon', 'Демоническая Сила'],
5 => ['dog', 'Друг'],
6 => ['pig', 'Полная Броня'],
7 => ['dragon', 'Инферно'],
];
User\Effects::removeByOverType($owner['id'], 100);
User\Effects::addCustom([
'v2' => 201,
'img2' => "summon_pet_{$statusName[$animal['type']][0]}.gif",
'id_eff' => 22,
'uid' => $owner['id'],
'name' => "{$statusName[$animal['type']][1]}[{$animal['level']}]",
'data' => $animalBonus,
'overType' => 100,
'timeUse' => 77,
'v1' => 'priem',
'user_use' => $owner['id'],
]);
if ($animal['type'] == 6) {
if ($animal['level'] == 1 || $animal['level'] == 2 || $animal['level'] == 3) {
$this->pigAnimalBonus = 50;
} elseif ($animal['level'] == 4) {
$this->pigAnimalBonus = 75;
} elseif ($animal['level'] == 5 || $animal['level'] == 6) {
$this->pigAnimalBonus = 125;
} elseif ($animal['level'] == 7 || $animal['level'] == 8) {
$this->pigAnimalBonus = 150;
} elseif ($animal['level'] == 9) {
$this->pigAnimalBonus = 200;
} elseif ($animal['level'] == 10) {
$this->pigAnimalBonus = 300;
}
Db::sql('update stats set hpNow = hpNow + ? where id = ?', [$this->pigAnimalBonus, $owner['id']]);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -6,10 +6,91 @@ use Core\Db;
class Effects
{
public static function addCustom(array $values)
{
$sql = '
insert into eff_users
(
id_eff,
uid,
name,
data,
overType,
timeUse,
timeAce,
user_use,
v1,
v2,
img2,
x,
hod,
bj,
sleeptime,
no_Ace,
file_finish,
tr_life_user,
deactiveTime,
deactiveLast,
mark,
bs
) values (
:id_eff,
:uid,
:name,
:data,
:overType,
:timeUse,
:timeAce,
:user_use,
:v1,
:v2,
:img2,
:x,
:hod,
:bj,
:sleeptime,
:no_Ace,
:file_finish,
:tr_life_user,
:deactiveTime,
:deactiveLast,
:mark,
:bs
)';
$args = [
'id_eff' => null,
'uid' => null,
'name' => null,
'data' => '',
'overType' => 0,
'timeUse' => null,
'timeAce' => 0,
'user_use' => '',
'v1' => '0',
'v2' => 0,
'img2' => '',
'x' => 1,
'hod' => -1,
'bj' => '0',
'sleeptime' => 0,
'no_Ace' => 0,
'file_finish' => '',
'tr_life_user' => 0,
'deactiveTime' => 0,
'deactiveLast' => 0,
'mark' => 0,
'bs' => 0,
];
$args = array_replace($args, $values);
if (!isset($args['id_eff'], $args['uid'], $args['name'], $args['timeUse'])) {
return;
}
Db::sql($sql, $args);
}
/** Дать игроку эффект.
* @param int $uid id игрока
* @param int $id id эффекта
* @param int $id id эффекта
* @return void
*/
public static function addById(int $uid, int $id)
@ -34,8 +115,47 @@ class Effects
return Db::getValue('select count(*) from eff_users where (id_eff between 301 and 304 or id_eff between 321 and 332) and id = ? and uid = ?', [$addictionId, $uid]) > 0;
}
public static function removeById(int $id): void
public static function removeById(int $userId, int $id): void
{
Db::sql('update eff_users set delete = unix_timestamp() where id = ?', [$id]);
Db::sql('delete from eff_users where id = ? and uid = ?', [$id, $userId]);
}
public static function removeByIds(int $userId, ...$ids): void
{
Db::sql('delete from eff_users where id in (?) and uid = ?', [implode(',', $ids), $userId]);
}
public static function removeByOverType(int $userId, int $overType): void
{
Db::sql('delete from eff_users where overType = ? and uid = ?', [$overType, $userId]);
}
public static function hasAttackTimeLimit(int $attackerId): bool
{
return Db::getValue('select count(*) from eff_users where id_eff = 478 and `delete` = 0 and uid = ?', [$attackerId]) > 0;
}
public static function isImmuneToAttack(int $targetId): bool
{
return Db::getValue('select count(*) from eff_users where id_eff in (479, 480, 481) and `delete` = 0 and uid = ?', [$targetId]) > 0;
}
public static function giveAttackImmunity(int $userId)
{
Db::sql("insert into eff_users (no_Ace, id_eff, overType, uid, name, data, timeUse) values (1,479,112,?,'Защита от нападения','zashitatk=1',unix_timestamp())", [$userId]);
}
/**
* Духовность. Спасение.
* Из свитка нападения.
* @param $id
* @return void
*/
public static function addSpasenie($id): void
{
Db::sql('delete from eff_users where uid = ? and overType = 101');
Db::sql("insert into eff_users (id_eff, uid, name, data, overType, timeUse, user_use, v1, v2, img2, bj, mark)
values (22,?,'Спасение','add_spasenie=1',101,77,?,'priem',324,'preservation.gif','спасение',1)", [$id, $id]);
}
}

View File

@ -58,7 +58,8 @@ class ItemsModel
public static function deleteItemsById(int $id, int $coldel = 1)
{
Db::sql(
'update items_users set `delete` = unix_timestamp() where id in (select id from items_users where item_id = ? and uid = ? and (`delete` = 0 or `delete` = 1000) order by inGroup desc limit ?)',
'update items_users set `delete` = unix_timestamp()
where id in (select id from items_users where item_id = ? and uid = ? and (`delete` = 0 or `delete` = 1000) order by inGroup desc limit ?)',
[$id, User::start()->info['id'], $coldel]
);
}
@ -70,7 +71,8 @@ class ItemsModel
$stats = User::start()->stats;
return [
'now' => Db::getValue('select sum(massa) from items_users left join items_main on item_id = items_main.id where uid = ? and (`delete` = 0 or (`delete` = 1000 and inGroup > 0)) and inShop = 0 and inOdet = 0', [$uid]),
'now' => Db::getValue('select sum(massa) from items_users left join items_main on item_id = items_main.id
where uid = ? and (`delete` = 0 or (`delete` = 1000 and inGroup > 0)) and inShop = 0 and inOdet = 0', [$uid]),
'max' => 40 + ($stats['os7'] * 10) + $stats['s4'] + $stats['maxves'] + $stats['s1'] * 4,
'items' => Db::getValue('select count(*) from items_users where uid = ? and `delete` = 0 and inShop = 0 and inOdet = 0', [$uid]),
];
@ -140,12 +142,17 @@ class ItemsModel
*/
public static function getOwnedItemById(int $itemId, int $ownerId): array
{
return Db::getRow('select * from items_users left join items_main on item_id = items_main.id where uid = ? and items_users.id = ? and `delete` = 0 and inOdet = 0 and inShop = 0', [$ownerId, $itemId]);
return Db::getRow('select * from items_users left join items_main on item_id = items_main.id
where uid = ? and items_users.id = ? and `delete` = 0 and inOdet = 0 and inShop = 0', [$ownerId, $itemId]);
}
public static function delete(int $id)
{
Db::sql('update items_users set `delete` = unix_timestamp() where id = ?', [$id]);
Db::sql('delete from items_users where id = ?', [$id]);
}
public static function getDressedEkrTotalPrice($uid)
{
return Db::getValue('select sum(2price) from items_users where inOdet > 0 and uid = ?', [$uid]);
}
}

View File

@ -77,7 +77,7 @@ $vinos = [
"10" => 16,
"11" => 21,
"12" => 41,
"21" => 41
"21" => 41,
];
//минимальный уровень для статов
$minlvl = [
@ -91,7 +91,7 @@ $minlvl = [
8 => 12,
9 => 15,
10 => 20,
11 => 0
11 => 0,
];
if (Effects::hasInjury($u->info['id'])) {
@ -101,7 +101,7 @@ if (Effects::hasInjury($u->info['id'])) {
if (Effects::hasAddiction($addictionId, $u->info['id'])) {
zact(4);
//сброс пристрастия
Effects::removeById($addictionId);
Effects::removeById($u->info['id'], $addictionId);
$st = ConversionHelper::dataStringToArray($u->info['stats']);
$err = 'Все прошло успешно.';
} else {