diff --git a/_incl_data/class/Dungeon.php b/_incl_data/class/Dungeon.php index 0de2bcbf..6b656185 100644 --- a/_incl_data/class/Dungeon.php +++ b/_incl_data/class/Dungeon.php @@ -961,7 +961,7 @@ class Dungeon ); if (isset($eff_d['id2'])) { //добавляем эффект - $us = $magic->add_eff($u->info['id'], $itm[0], 1); + $us = $magic->addEffect($u->info['id'], $itm[0], 1); if ($us[0] == 1) { $r .= '
На Вас наложили заклятие "' . $eff_d['mname'] . '".
'; } else { diff --git a/_incl_data/class/Magic.php b/_incl_data/class/Magic.php index 97ee811c..6db881c3 100644 --- a/_incl_data/class/Magic.php +++ b/_incl_data/class/Magic.php @@ -3,6 +3,7 @@ use Core\ConversionHelper; use Core\Db; use Magic\Attack; +use User\Effects; use User\ItemsModel; class Magic @@ -291,7 +292,7 @@ class Magic } } if ($goodUse == 1) { - $us = $this->add_eff($u->info['id'], $itm['magic_inc']); + $us = $this->addEffect($u->info['id'], $itm['magic_inc']); if ($us[0] == 1) { $itm['iznosNOW']++; if ($itm['inGroup'] > 0 && $itm['delete'] == 0) { @@ -1404,7 +1405,7 @@ class Magic $u->error = 'Вы не можете переманивать данного персонажа...'; } } elseif ($goodUse == 1) { - $us = $this->add_eff($usr['id'], $itm['magic_inc']); + $us = $this->addEffect($usr['id'], $itm['magic_inc']); if ($us[0] == 1) { $mmmid = mysql_insert_id(); $itm['iznosNOW']++; @@ -1509,7 +1510,7 @@ class Magic mysql_query( 'DELETE FROM `eff_users` WHERE `uid` = "' . $u->info['id'] . '" AND `id_eff` = 290 AND `delete` =0' ); - $this->add_eff($u->info['id'], 290); + $this->addEffect($u->info['id'], 290); $echotext = 'Настойка на жучьей требухе!'; $u->error = 'Вы получили эфект от ' . $echotext . ''; } elseif ($slech == 2) { @@ -1521,7 +1522,7 @@ class Magic mysql_query( 'DELETE FROM `eff_users` WHERE `uid` = "' . $u->info['id'] . '" AND `id_eff` = 470 AND `delete` =0' ); - $this->add_eff($u->info['id'], 472); + $this->addEffect($u->info['id'], 472); $echotext = 'Амброзия подмастерья Владык!'; $u->error = 'Вы получили эфект от ' . $echotext . ''; } elseif ($slech == 3) { @@ -1533,7 +1534,7 @@ class Magic mysql_query( 'DELETE FROM `eff_users` WHERE `uid` = "' . $u->info['id'] . '" AND `id_eff` = 470 AND `delete` =0' ); - $this->add_eff($u->info['id'], 470); + $this->addEffect($u->info['id'], 470); $echotext = 'Амброзия Скучающих Владык!'; $u->error = 'Вы получили эфект от ' . $echotext . ''; } elseif ($slech == 4) { @@ -1542,7 +1543,7 @@ class Magic mysql_query( 'DELETE FROM `eff_users` WHERE `uid` = "' . $u->info['id'] . '" AND `id_eff` = 35 AND `delete` =0' ); - $this->add_eff($u->info['id'], 35); + $this->addEffect($u->info['id'], 35); $echotext = 'Звездное Сияние!'; $u->error = 'Вы получили эфект от ' . $echotext . ''; } else { @@ -1962,7 +1963,7 @@ class Magic if ($itm['magic_inc'] == '') { $itm['magic_inc'] = $itm['magic_inci']; } - $us = $this->add_eff($u->info['id'], $itm['magic_inc']); + $us = $this->addEffect($u->info['id'], $itm['magic_inc']); if ($us[0] == 1) { $itm['iznosNOW']++; mysql_query( @@ -2020,49 +2021,9 @@ class Magic //Использование предмета - public function add_eff($uid, $id, $is_no = null) + public function addEffect($uid, $id, $isNo = null): array { - $g = [0 => 0, 1 => '']; - $eff = mysql_fetch_array(mysql_query('SELECT * FROM `eff_main` WHERE `id2` = "' . $id . '" LIMIT 1')); - - if ($is_no != null) { - //добавляем эффект персонажу - if ($eff['onlyOne'] > 0) { - //убираем прошлые эффекты - $goodUse = 0; - $upd1 = mysql_query( - 'UPDATE `eff_users` SET `delete` = "' . time() . '" WHERE `uid` = "' . $uid . '" AND `delete` = "0" AND `id_eff` = "' . $eff['id2'] . '"' - ); - if ($upd1) { - $goodUse = 1; - } - } - if ($st['oneType'] > 0) { - //убираем прошлые эффекты - $goodUse = 0; - $upd2 = mysql_query( - 'UPDATE `eff_users` SET `delete` = "' . time() . '" WHERE `uid` = "' . $uid . '" AND `delete` = "0" AND `overType` = "' . $eff['overType'] . '"' - ); - if ($upd2) { - $goodUse = 1; - } - } - } - if ($goodUse == 1 || $is_no == null) { - if (isset($eff['id2'])) { - //$eff = $this->paguba($eff); - $n = $eff['mname']; - $d = $eff['mdata']; - $ins = mysql_query( - 'INSERT INTO `eff_users` (`overType`,`id_eff`,`uid`,`name`,`timeUse`,`data`,`no_Ace`) VALUES ("' . $eff['oneType'] . '","' . $eff['id2'] . '","' . $uid . '","' . $n . '","' . time() . '","' . $d . '","' . $eff['noAce'] . '")' - ); - if ($ins) { - $g[0] = 1; - $g[1] = '...'; - } - } - } - return $g; + return Effects::addById($uid, $id, (bool)$isNo) ? [1, '...'] : [0, '']; } public function atackUser($uid1, $uid2, $tm, $btl, $addExp = 0, $type = 0) diff --git a/_incl_data/class/Model/Effect.php b/_incl_data/class/Model/Effect.php new file mode 100644 index 00000000..6c9ec4be --- /dev/null +++ b/_incl_data/class/Model/Effect.php @@ -0,0 +1,13 @@ + 0) { - $magic->add_eff($u->info['id'], $j[$i], 1); + $magic->addEffect($u->info['id'], $j[$i], 1); } $i++; } @@ -1003,7 +1003,7 @@ class Quests $j = explode('=', $d['add_eff']); while ($i < count($j)) { if ($j[$i] > 0) { - $magic->add_eff($u->info['id'], $j[$i], 1); + $magic->addEffect($u->info['id'], $j[$i], 1); } $i++; } diff --git a/_incl_data/class/User.php b/_incl_data/class/User.php index df2e6a10..fc2168a5 100644 --- a/_incl_data/class/User.php +++ b/_incl_data/class/User.php @@ -3185,7 +3185,7 @@ FROM `levels` WHERE `upLevel` = "' . $u['upLevel'] . '" LIMIT 1' if ($smt < 10) { $this->addAction(time(), 'create_snowball_cp', $this->info['city']); - $magic->add_eff($this->info['id'], 24); + $magic->addEffect($this->info['id'], 24); $this->error2 = 'Начинаем лепить снежок, осталось ' . (10 - $smt) . ' раз на сегодня ...'; } else { $this->error2 = 'Вы уже слепили 10 снежка за сегодня ...'; diff --git a/_incl_data/class/User/Effects.php b/_incl_data/class/User/Effects.php index 3838dc52..4819045d 100644 --- a/_incl_data/class/User/Effects.php +++ b/_incl_data/class/User/Effects.php @@ -3,6 +3,7 @@ namespace User; use Core\Db; +use Model\Effect; class Effects { @@ -91,18 +92,39 @@ insert into eff_users /** Дать игроку эффект. * @param int $uid id игрока * @param int $id id эффекта - * @return void + * @return bool */ - public static function addById(int $uid, int $id) + public static function addById(int $uid, int $id, bool $ignoreLimits = false): bool { - $eff = Db::getRow('select mname, mdata, oneType, id2 from eff_main where id2 = ?', [$id]); + $eff = Effect::getAllbyId($id); if (!$eff['id2']) { - return; + return false; } + + if (!$ignoreLimits) { + if ($eff['onlyOne'] > 0) { + self::removeByEffectId($uid, $eff['id2']); + } + if ($eff['oneType'] > 0) { + self::removeByOverType($uid, $eff['overType']); + } + } + Db::sql( - 'insert into eff_users (overType, id_eff, uid, name, timeUse, data) values (?,?,?,?,unix_timestamp(),?)', - [$eff['oneType'], $eff['id2'], $uid, $eff['mname'], $eff['mdata']] + 'insert into eff_users (overType, id_eff, uid, name, timeUse, data, no_Ace) values (?,?,?,?,unix_timestamp(),?,?)', + [$eff['oneType'], $eff['id2'], $uid, $eff['mname'], $eff['mdata'], $eff['noAce']] ); + return true; + } + + public static function removeByEffectId(int $userId, int $overType): void + { + Db::sql('delete from eff_users where id_eff = ? and uid = ?', [$overType, $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 hasInjury(int $uid): bool @@ -125,11 +147,6 @@ insert into eff_users 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;