Убрано дублирование кода.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user