2023-04-15 19:17:40 +00:00
< ? php
2023-04-15 19:52:33 +00:00
namespace User ;
2023-04-15 19:17:40 +00:00
use Core\Db ;
2023-08-14 13:37:37 +00:00
use Model\Effect ;
2023-04-15 19:17:40 +00:00
2023-04-15 19:52:33 +00:00
class Effects
2023-04-15 19:17:40 +00:00
{
2023-11-02 13:57:39 +00:00
public static function addCustom ( array $values ) : void
2023-08-14 13:03:45 +00:00
{
$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 );
}
2023-04-15 19:17:40 +00:00
2023-04-15 22:54:07 +00:00
/** Дать игроку эффект .
* @ param int $uid id игрока
2023-08-14 13:03:45 +00:00
* @ param int $id id эффекта
2023-11-02 13:57:39 +00:00
* @ param bool $ignoreLimits
2023-08-14 13:37:37 +00:00
* @ return bool
2023-04-15 19:17:40 +00:00
*/
2023-08-14 13:37:37 +00:00
public static function addById ( int $uid , int $id , bool $ignoreLimits = false ) : bool
2023-04-15 19:17:40 +00:00
{
2023-08-14 13:37:37 +00:00
$eff = Effect :: getAllbyId ( $id );
2023-04-15 19:17:40 +00:00
if ( ! $eff [ 'id2' ]) {
2023-08-14 13:37:37 +00:00
return false ;
}
if ( ! $ignoreLimits ) {
if ( $eff [ 'onlyOne' ] > 0 ) {
self :: removeByEffectId ( $uid , $eff [ 'id2' ]);
}
if ( $eff [ 'oneType' ] > 0 ) {
self :: removeByOverType ( $uid , $eff [ 'overType' ]);
}
2023-04-15 19:17:40 +00:00
}
2023-08-14 13:37:37 +00:00
2023-04-15 19:17:40 +00:00
Db :: sql (
2023-08-14 13:37:37 +00:00
'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' ]]
2023-04-15 19:17:40 +00:00
);
2023-08-14 13:37:37 +00:00
return true ;
}
2024-01-06 15:30:34 +00:00
public static function addInjury ( $uid , $type , $lvl ) : void
{
$stat = rand ( 1 , 3 ); // пока без духовности
$img = " eff_travma $type .gif " ;
if ( $type == 1 ) {
$name = 'Легкая травма' ;
$timeEnd = rand ( 1 , 3 ); // время травмы от 1.30 до 6 часов
$data = 'add_s' . $stat . '=-' . $lvl ;
} elseif ( $type == 2 ) {
$name = 'Средняя травма' ;
$timeEnd = rand ( 3 , 5 ); // время травмы от 6 до 12 часов
$data = 'add_s' . $stat . '=-' . ( $lvl * 2 );
} elseif ( $type == 3 ) {
$name = 'Тяжелая травма' ;
$timeEnd = rand ( 5 , 7 ); // время травмы от 12 до 6 часов
$data = 'add_s' . $stat . '=-' . ( $lvl * 3 );
} else {
$name = 'Неизлечимая травма' ;
$timeEnd = 24 ; // время травмы от 24 часа
$data = 'add_s' . $stat . '=-' . ( $lvl * 50 );
}
$timeEnd *= 3600 ;
Db :: sql (
" insert into eff_users (id_eff, uid, name, timeUse, data, img2, v1, timeace) values (4,?,?,unix_timestamp(),?,?,?,?) " ,
[ $uid , $name , $data , $img , $type , $timeEnd ]
);
self :: addById ( $uid , 263 );
}
2023-11-05 02:46:07 +00:00
public static function removeByEffectId ( int $userId , int $effectId ) : void
2023-08-14 13:37:37 +00:00
{
2023-11-05 02:46:07 +00:00
Db :: sql ( 'delete from eff_users where id_eff = ? and uid = ?' , [ $effectId , $userId ]);
2023-08-14 13:37:37 +00:00
}
public static function removeByOverType ( int $userId , int $overType ) : void
{
Db :: sql ( 'delete from eff_users where overType = ? and uid = ?' , [ $overType , $userId ]);
2023-06-19 14:40:15 +00:00
}
public static function hasInjury ( int $uid ) : bool
{
2023-11-02 13:57:39 +00:00
return Db :: getValue ( 'select count(*) from eff_users where id_eff in (4,5,6) and `delete` = 0 and uid = ?' , [ $uid ]) > 0 ;
2023-06-19 14:40:15 +00:00
}
2023-04-15 19:17:40 +00:00
2023-06-19 14:40:15 +00:00
public static function hasAddiction ( int $addictionId , int $uid ) : bool // пристрастие
{
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 ;
}
2024-02-10 16:41:23 +00:00
/**
* @ param int $userId если 0 , удаление только по id .
* @ param int $id
* @ return void
*/
2023-08-14 13:03:45 +00:00
public static function removeById ( int $userId , int $id ) : void
{
2024-02-10 16:41:23 +00:00
if ( $userId === 0 ) {
Db :: sql ( 'delete from eff_users where id = ?' , [ $id ]);
return ;
}
2023-08-14 13:03:45 +00:00
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 ]);
}
2023-12-19 01:58:37 +00:00
public static function removePriems ( int $userid ) : void
{
Db :: sql ( " delete from eff_users where v1 = 'priem' and uid = ? " , [ $userid ]);
}
2023-08-14 13:03:45 +00:00
public static function hasAttackTimeLimit ( int $attackerId ) : bool
2023-06-19 14:40:15 +00:00
{
2023-08-14 13:03:45 +00:00
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 ;
}
2023-11-02 13:57:39 +00:00
public static function giveAttackImmunity ( int $userId ) : void
2023-08-14 13:03:45 +00:00
{
Db :: sql ( " insert into eff_users (no_Ace, id_eff, overType, uid, name, data, timeUse) values (1,479,112,?,'Защита от нападения','zashitatk=1',unix_timestamp()) " , [ $userId ]);
}
2024-02-10 17:31:02 +00:00
/**
* @ param int $id
* @ param int $hod
* @ param int | string $x для запроса x = x + 1 , вводить 'x + 1'
* @ param string $data
* @ return void
*/
2024-02-10 16:18:11 +00:00
public static function setHod ( int $id , int $hod , int | string $x = 0 , string $data = '' ) : void
{
$args = [ 'id' => $id , 'hod' => $hod ];
$xsql = '' ;
$datasql = '' ;
if ( $x === 'x + 1' ) {
$xsql = ', x = x + 1' ;
} elseif ( is_numeric ( $x )) {
$xsql = ', x = :x' ;
$args [ 'x' ] = $x ;
}
if ( ! empty ( $data )) {
$datasql = ', data = :data' ;
$args [ 'data' ] = $data ;
}
$sql = " update eff_users set hod = :hod $xsql $datasql where id = :id " ;
Db :: sql ( $sql , $args );
}
2023-08-14 13:03:45 +00:00
/**
* Духовность . Спасение .
* Из свитка нападения .
2023-12-19 01:58:37 +00:00
* @ param $uid
2023-08-14 13:03:45 +00:00
* @ return void
*/
2023-12-19 01:58:37 +00:00
public static function addSpasenie ( $uid ) : void
2023-08-14 13:03:45 +00:00
{
2023-12-19 01:58:37 +00:00
self :: removeByOverType ( $uid , 101 );
2023-08-14 13:03:45 +00:00
Db :: sql ( " insert into eff_users (id_eff, uid, name, data, overType, timeUse, user_use, v1, v2, img2, bj, mark)
2023-12-19 01:58:37 +00:00
values ( 22 , ? , 'Спасение' , 'add_spasenie=1' , 101 , 77 , ? , 'priem' , 324 , 'preservation.gif' , 'спасение' , 1 ) " , [ $uid , $uid ]);
2023-08-14 13:03:45 +00:00
2023-04-15 19:17:40 +00:00
}
2023-11-02 13:57:39 +00:00
public static function getActive ( int $userId ) : array
{
return Db :: getRows ( 'select * from eff_users where uid = ?' , [ $userId ]);
}
public static function getAllInjuries ( int $uid ) : array
{
return Db :: getRows ( 'select * from eff_users where uid = ? and id_eff in (4,5,6) order by id_eff' , [ $uid ]);
}
2023-06-19 14:40:15 +00:00
}