2022-08-11 10:38:38 +00:00
< ? php
2023-04-15 19:52:33 +00:00
namespace User ;
2023-11-02 13:57:39 +00:00
use Core\Config ;
2022-12-30 19:03:37 +00:00
use Core\Db ;
2023-11-10 15:52:38 +00:00
use Helper\Comparsion ;
2023-08-15 22:48:29 +00:00
use Helper\Conversion ;
2023-12-05 01:01:04 +00:00
use Model\Constant\Stat ;
2023-04-15 19:52:33 +00:00
use User ;
2022-08-11 10:38:38 +00:00
2023-04-15 19:52:33 +00:00
class Stats
2022-08-11 10:38:38 +00:00
{
2023-08-15 22:48:29 +00:00
private User $u ;
2023-11-10 15:52:38 +00:00
/** Список разрешённых для бонусов системных названий статов
2024-01-16 07:13:15 +00:00
* @ var Stat
2023-11-10 15:52:38 +00:00
*/
2024-01-16 07:13:15 +00:00
private Stat $sysNames ;
2023-08-15 22:48:29 +00:00
2023-12-05 01:01:04 +00:00
private array $statsKeys = [];
2023-08-15 22:48:29 +00:00
public function __construct ( User $user )
{
$this -> u = $user ;
2024-01-16 07:13:15 +00:00
$this -> sysNames = new Stat ();
$this -> sysNames -> getBonus ();
2023-12-05 01:01:04 +00:00
2023-08-15 22:48:29 +00:00
}
2022-08-11 10:38:38 +00:00
/**
2023-08-15 22:48:29 +00:00
* Собирает суммы всех бонусов с одетых предметов , комплектов предметов , активных эфектов .
* @ param int $userId
2022-08-11 10:38:38 +00:00
* @ return array
*/
2023-08-15 22:48:29 +00:00
public static function getAllBonuses ( int $userId ) : array
2022-08-11 10:38:38 +00:00
{
2023-08-15 22:48:29 +00:00
$iData = [];
$im = ItemsModel :: getWearedItems ( $userId );
foreach ( $im as $item ) {
$iData [] = $item [ 'data' ];
}
$iData [] = Db :: getValue ( 'select data from eff_users where uid = ? and `delete` = 0' , [ $userId ]);
2022-12-30 19:03:37 +00:00
2022-08-11 10:38:38 +00:00
$params = [];
2023-08-15 22:48:29 +00:00
$complects = [];
2022-08-11 10:38:38 +00:00
foreach ( $iData as $datum ) {
2023-08-15 22:48:29 +00:00
$arr = Conversion :: dataStringToArray ( $datum );
foreach ( $arr as $k => $v ) {
if ( $k === 'complect' ) {
if ( isset ( $complects [ $v ])) {
$complects [ $v ] ++ ;
2022-08-11 10:38:38 +00:00
} else {
2023-08-15 22:48:29 +00:00
$complects [ $v ] = 1 ;
2022-08-11 10:38:38 +00:00
}
}
2023-11-10 15:52:38 +00:00
if ( ! str_contains ( $k , 'add_' )) {
2023-08-15 22:48:29 +00:00
continue ;
}
$k = str_replace ( 'add_' , '' , $k );
self :: setBonusValue ( $params , $k , $v );
}
}
2023-11-10 15:52:38 +00:00
return self :: addComplectsBonuses ( $complects , $params );
2023-08-15 22:48:29 +00:00
}
2023-11-10 15:52:38 +00:00
private static function setBonusValue ( array & $array , $key , $value ) : void
2023-08-15 22:48:29 +00:00
{
if ( isset ( $array [ $key ])) {
$array [ $key ] += $value ;
} else {
$array [ $key ] = $value ;
}
}
/**
* @ param array $complects
* @ param array $params
* @ return array
*/
private static function addComplectsBonuses ( array $complects , array $params ) : array
{
$cdata = [];
if ( ! empty ( $complects )) {
foreach ( $complects as $complectId => $wearedItemsQuantity ) {
$cdata [] = Db :: getValue ( 'select data from complects where com = ? and x <= ? order by x desc limit 1' , [ $complectId , $wearedItemsQuantity ]);
}
foreach ( $cdata as $datum ) {
$arr = Conversion :: dataStringToArray ( $datum );
foreach ( $arr as $k => $v ) {
self :: setBonusValue ( $params , $k , $v );
}
2022-08-11 10:38:38 +00:00
}
}
return $params ;
}
2023-04-15 19:17:40 +00:00
/** Данные для отрисовки логина и полосок жизни\маны .
* @ param User $u
* @ return object
*/
public static function getLoginHpManaBars ( User $u ) : object
{
$hpNow = floor ( $u -> stats [ 'hpNow' ]);
$hpAll = $u -> stats [ 'hpAll' ];
$mpNow = floor ( $u -> stats [ 'mpNow' ]);
$mpAll = $u -> stats [ 'mpAll' ];
//floor(120 / 100 * ($hpNow / $hpAll * 100)); // ??????
$ph = ( $hpAll > 0 && $hpNow > 0 ) ? floor ( 120 / $hpNow / $hpAll ) : 0 ;
$pm = ( $mpAll > 0 && $mpNow > 0 ) ? floor ( 120 / $mpNow / $mpAll ) : 0 ;
return ( object )[
'uid' => $u -> info [ 'id' ],
2023-12-05 01:01:04 +00:00
'login' => User :: getLogin ( $u -> info [ 'id' ]),
2023-04-15 19:17:40 +00:00
'hpbarwidth' => $ph ,
'mpbarwidth' => $pm ,
'hpbartext' => ' ' . $hpNow . '/' . $hpAll ,
'mpbartext' => ' ' . $mpNow . '/' . $mpAll ,
'divstyle' => $pm === 0 ? ' margin-top:13px;' : '' ,
'hasmana' => $mpAll > 0 ,
];
}
2023-04-15 19:52:33 +00:00
2023-12-19 01:58:37 +00:00
public function getStats ( int | array | null $uid = null , $i1 = 0 , $reimg = false , $btl_cache = false ) : array
2023-08-15 22:48:29 +00:00
{
2023-12-19 01:58:37 +00:00
$u = match ( true ) {
2024-01-05 22:14:35 +00:00
empty ( $uid ) => $this -> u -> info ,
2023-12-19 01:58:37 +00:00
is_array ( $uid ) => $uid ,
default => User :: getInfo ( $uid ),
};
2023-08-15 22:48:29 +00:00
2024-01-05 22:14:35 +00:00
2023-11-02 13:57:39 +00:00
if ( ! isset ( $u [ 'id' ])) {
2023-08-15 22:48:29 +00:00
return [];
}
2023-11-10 15:52:38 +00:00
// Как? Нахуя 4 переменные разные для одного и того же?
2024-01-16 07:13:15 +00:00
$st = array_fill_keys ( $this -> sysNames -> sysBonusNames , 0 );
2023-11-10 15:52:38 +00:00
$sti = $st ;
$s_v = $st ;
$s_vi = $st ;
2023-11-09 17:24:47 +00:00
2023-08-15 22:48:29 +00:00
$u [ 'clanpos' ] = 0 ;
if ( $u [ 'clan' ] > 0 ) {
$r1 = Db :: getValue ( 'select pos from aaa_clan_reting_list where clan = ? and date = ? limit 1' , [ $u [ 'clan' ], date ( 'dmY' )]);
2023-12-05 01:01:04 +00:00
if ( $r1 ) {
$this -> addKeyIfNotExist ( 'clanpos' , $r1 , $st );
2023-08-15 22:48:29 +00:00
}
}
$lvl = Db :: getRow ( 'select * from levels where upLevel = ?' , [ $u [ 'upLevel' ]]);
if ( isset ( $lvl [ 'upLevel' ])) {
$st [ 'levels' ] = $lvl ;
} else {
$st [ 'levels' ] = 'undefined' ;
}
2023-11-02 13:57:39 +00:00
2023-08-15 22:48:29 +00:00
$st [ 'id' ] = $u [ 'id' ];
$st [ 'login' ] = $u [ 'login' ];
2023-12-05 01:01:04 +00:00
$st [ 'level' ] = $u [ 'level' ];
2023-08-15 22:48:29 +00:00
$st [ 'hpNow' ] = $u [ 'hpNow' ];
2023-12-05 01:01:04 +00:00
2023-08-15 22:48:29 +00:00
$st [ 'mpNow' ] = $u [ 'mpNow' ];
2023-12-05 01:01:04 +00:00
2023-08-15 22:48:29 +00:00
$st [ 'zona' ] = 1 ;
$st [ 'zonb' ] = 2 ;
$st [ 'items' ] = [];
$st [ 'effects' ] = [];
2023-12-05 01:01:04 +00:00
2024-01-05 22:14:35 +00:00
2023-08-15 22:48:29 +00:00
$st [ 'vip' ] = $u [ 'vip' ];
2023-12-05 01:01:04 +00:00
foreach ( Conversion :: dataStringToArray ( $u [ 'stats' ]) as $stat => $value ) {
2024-01-05 22:14:35 +00:00
//fixme несуществующие статы mg5 mg6 a6 s8-s15
2023-12-05 01:01:04 +00:00
$this -> addKeyIfNotExist ( $stat , ( int ) $value , $st );
2023-08-15 22:48:29 +00:00
}
2023-11-02 13:57:39 +00:00
$baseStats = $st ;
2023-08-15 22:48:29 +00:00
//Шаблонные картинки
if ( $this -> u -> info [ 'id' ] === $u [ 'id' ] || $reimg ) {
$itemsImages = Db :: getRows ( 'select * from items_img where uid = ? and img_id != 0' , [ $u [ 'id' ]]);
2023-04-15 19:52:33 +00:00
2023-08-15 22:48:29 +00:00
foreach ( $itemsImages as $itemsImage ) {
$reimage = Db :: getRow ( 'select * from reimage where ((uid = ? and clan = 0) or clan = ?) and good > 0 and bad = 0 and id = ?' , [ $u [ 'id' ], $u [ 'clan' ], $itemsImage [ 'img_id' ]]);
if ( isset ( $reimage [ 'id' ])) {
$st [ 'items_img' ][ $itemsImage [ 'type' ]] = $reimage [ 'id' ] . '.' . $reimage [ 'format' ];
} else {
Db :: sql ( 'update items_img set img_id = 0 where id = ?' , [ $itemsImage [ 'id' ]]);
}
}
}
2024-01-08 01:33:20 +00:00
[ $hnd1 , $hnd2 , $sht1 , $dom , $coms ] = $this -> addWearedItemsBonuses ( $u [ 'id' ], $st , $s_v , $baseStats );
2023-11-10 15:52:38 +00:00
$this -> addMedalsBonuses ( $u [ 'id' ], $st );
$noeffectbattle = false ;
if ( $u [ 'battle' ] > 0 ) {
$noeffectbattle = ( bool ) Db :: getValue ( " select 1 from battle_actions where uid = ? and vars = 'noeffectbattle1' and btl = ? limit 1 " , [ $u [ 'id' ], $u [ 'battle' ]]);
}
//Характеристики от эффектов
$h = 0 ;
$nbs = array_fill_keys ( range ( 4899 , 4909 ), 0 );
$prsu = [];
if ( ! $noeffectbattle ) {
$efs = Db :: getRows ( " select * from eff_users left join eff_main on id2 = id_eff where uid = ? and deactiveTime < unix_timestamp() and v1 != 'priem' order by id desc " , [ $u [ 'id' ]]);
foreach ( $efs as $e ) {
if ( $u [ 'dnow' ] == 0 ) {
if ( $u [ 'battle' ] == 0 ) {
Db :: sql ( 'delete from eff_users where id_eff = ? and uid = ? and id != ?' , [ $e [ 'id_eff' ], $u [ 'id' ], $e [ 'id' ]]);
//Переводим в заряды
if ( $e [ 'hod' ] != - 1 ) {
Db :: sql ( 'update eff_users set hod = -1, timeUse = unix_timestamp() + ? where id = ?' , [ $e [ 'hod' ] * Config :: get ( 'effz' ) - $e [ 'actionTime' ], $e [ 'id' ]]);
}
} elseif ( Config :: get ( 'effz' ) > 0 && $e [ 'hod' ] == - 1 ) {
$efzz = round (( $e [ 'timeUse' ] + $e [ 'actionTime' ] + $e [ 'timeAce' ]) - time ());
if ( $efzz > 0 ) {
Db :: sql ( 'update eff_users set hod = ? where id = ?' , [ $efzz / Config :: get ( 'effz' ), $e [ 'id' ]]);
}
}
}
if ( $e [ 'timeUse' ] + $e [ 'timeAce' ] + $e [ 'actionTime' ] > time () || $e [ 'timeUse' ] == 77 ) {
if ( $e [ 'v1' ] == 'priem' ) {
$prsu [ $e [ 'v2' ]] = 0 + $prsu [ 'x' ];
}
$st [ 'effects' ][ $h ] = $e ;
$h ++ ;
$sts = Conversion :: dataStringToArray ( $e [ 'data' ]);
if ( isset ( $sts [ 'itempl' ]) && $sts [ 'itempl' ] > 0 ) {
$nbs [ $sts [ 'itempl' ]] += 1 ;
}
if ( isset ( $sts [ 'puti' ])) {
2023-12-05 01:01:04 +00:00
$this -> addKeyIfNotExist ( 'puti' , $sts [ 'puti' ], $st );
2023-11-10 15:52:38 +00:00
}
if ( isset ( $sts [ 'add_silver' ])) {
2023-12-05 01:01:04 +00:00
$this -> addKeyIfNotExist ( 'slvtm' , $e [ 'timeUse' ] + $e [ 'actionTime' ], $st );
2023-11-10 15:52:38 +00:00
}
$this -> addValuesToAllArrays ( $sts , $st , $sti , $s_v , $s_vi );
} else {
//удаляем эффект
if (
$e [ 'img2' ] != 'tz.gif' ||
$u [ 'id' ] == $this -> u -> info [ 'id' ]
) {
if ( $e [ 'sleeptime' ] == 0 ) {
$this -> u -> endEffect ( $e [ 'id' ], $u );
}
$st [ 'act' ] = 1 ;
}
}
}
} else {
$st [ 'noeffectbattle1' ] = 1 ;
}
$this -> addWearedItemsIllusion ( $nbs , $st );
$this -> addInBattlePriemsBonuses ( $u , $st , $prsu , $sti , $s_v , $s_vi );
//Характеристики от статов
2023-12-05 01:01:04 +00:00
$st [ 'hpall' ] += $st [ 's4' ] * 5 ;
$st [ 'mpall' ] += $st [ 's6' ] * 10 ;
2023-11-10 15:52:38 +00:00
//Турнир
$st [ 'm1' ] += $st [ 's3' ] * 5 ;
// мф.анти-крит = 2.5
$st [ 'm2' ] += $st [ 's3' ] * 5 ;
// мф.уворот = 2.5
$st [ 'm4' ] += $st [ 's2' ] * 5 ;
// мф.анти-уворот = 2.5
$st [ 'm5' ] += $st [ 's2' ] * 5 ;
2024-01-05 22:14:35 +00:00
$st [ 'za' ] += $st [ 's4' ];
$st [ 'm19' ] += ( int )( $st [ 's3' ] * 0.03 );
2023-11-10 15:52:38 +00:00
//Бонусы комплектов
if ( is_iterable ( $coms [ 'new' ])) {
foreach ( $coms [ 'new' ] as $complect ) {
2023-12-19 01:58:37 +00:00
$com = Db :: getValue (
'select data from complects where com = ? and x <= ? order by x desc limit 1' ,
2023-11-10 15:52:38 +00:00
[
( int ) $complect ,
( int ) $coms [ 'com' ][ $complect ], // кол-во предметов данного комплекта
2023-12-19 01:58:37 +00:00
]
);
2023-11-10 15:52:38 +00:00
if ( ! $com ) {
continue ;
}
$sti = Conversion :: dataStringToArray ( $com );
2024-01-16 07:13:15 +00:00
foreach ( $this -> sysNames -> sysBonusNames as $stat ) {
2023-11-10 15:52:38 +00:00
if ( ! isset ( $sti [ $stat ])) {
continue ;
}
$st [ $stat ] += $sti [ $stat ];
}
}
}
2023-12-05 01:01:04 +00:00
//Что за нахер?
WearedScrolls :: ScrollsChange ( $u );
2023-11-10 15:52:38 +00:00
//Бонусы статов
$this -> addStatBonuses ( $st );
2024-01-05 22:14:35 +00:00
/* Владения */
2023-11-10 15:52:38 +00:00
//mib1-mib4, mab1-mab4 armor??
2024-01-05 22:14:35 +00:00
if ( ! empty ( $st [ 's5' ])) {
$st [ 'pm1' ] += ( int )( $st [ 's5' ] * 0.5 );
$st [ 'pm2' ] += ( int )( $st [ 's5' ] * 0.5 );
$st [ 'pm3' ] += ( int )( $st [ 's5' ] * 0.5 );
$st [ 'pm4' ] += ( int )( $st [ 's5' ] * 0.5 );
$st [ 'pm7' ] += ( int )( $st [ 's5' ] * 0.5 );
2023-11-10 15:52:38 +00:00
}
2024-01-05 22:14:35 +00:00
if ( ! empty ( $st [ 'aall' ])) {
2023-11-10 15:52:38 +00:00
$st [ 'a1' ] += $st [ 'aall' ];
$st [ 'a2' ] += $st [ 'aall' ];
$st [ 'a3' ] += $st [ 'aall' ];
$st [ 'a4' ] += $st [ 'aall' ];
$st [ 'a5' ] += $st [ 'aall' ];
}
2024-01-05 22:14:35 +00:00
if ( ! empty ( $st [ 'zm' ])) {
2023-11-10 15:52:38 +00:00
$st [ 'zm1' ] += $st [ 'zm' ];
$st [ 'zm2' ] += $st [ 'zm' ];
$st [ 'zm3' ] += $st [ 'zm' ];
$st [ 'zm4' ] += $st [ 'zm' ];
}
2024-01-05 22:14:35 +00:00
if ( ! empty ( $st [ 'mall' ])) {
2023-11-10 15:52:38 +00:00
$st [ 'mg1' ] += $st [ 'mall' ];
$st [ 'mg2' ] += $st [ 'mall' ];
$st [ 'mg3' ] += $st [ 'mall' ];
$st [ 'mg4' ] += $st [ 'mall' ];
}
2023-12-05 01:01:04 +00:00
2024-01-05 22:14:35 +00:00
if ( ! empty ( $st [ 'm11' ])) {
2023-11-10 15:52:38 +00:00
$st [ 'pm1' ] += $st [ 'm11' ];
$st [ 'pm2' ] += $st [ 'm11' ];
$st [ 'pm3' ] += $st [ 'm11' ];
$st [ 'pm4' ] += $st [ 'm11' ];
}
2023-12-05 01:01:04 +00:00
2024-01-05 22:14:35 +00:00
if ( ! empty ( $st [ 'm10' ])) {
2023-11-10 15:52:38 +00:00
$st [ 'pa1' ] += $st [ 'm10' ];
$st [ 'pa2' ] += $st [ 'm10' ];
$st [ 'pa3' ] += $st [ 'm10' ];
$st [ 'pa4' ] += $st [ 'm10' ];
}
2023-12-05 01:01:04 +00:00
2024-01-05 22:14:35 +00:00
if ( ! empty ( $st [ 'za' ])) {
2023-11-10 15:52:38 +00:00
$st [ 'za1' ] += $st [ 'za' ];
$st [ 'za2' ] += $st [ 'za' ];
$st [ 'za3' ] += $st [ 'za' ];
$st [ 'za4' ] += $st [ 'za' ];
}
if ( ! empty ( $st [ 'hpVinos' ])) {
2024-01-05 22:14:35 +00:00
$st [ 'hpall' ] += ( int )( $st [ 'hpVinos' ] * $st [ 's4' ]);
2023-11-10 15:52:38 +00:00
}
if ( ! empty ( $st [ 'mpVinos' ])) {
2024-01-05 22:14:35 +00:00
$st [ 'mpall' ] += ( int )( $st [ 'mpVinos' ] * $st [ 's6' ]);
2023-11-10 15:52:38 +00:00
}
if ( ! empty ( $st [ 'hpProc' ])) {
2024-01-05 22:14:35 +00:00
$st [ 'hpall' ] += ( int )( $st [ 'hpall' ] / 100 * $st [ 'hpProc' ]);
2023-11-10 15:52:38 +00:00
}
if ( ! empty ( $st [ 'mpProc' ])) {
2024-01-05 22:14:35 +00:00
$st [ 'mpall' ] += ( int )( $st [ 'mpall' ] / 100 * $st [ 'mpProc' ]);
2023-11-10 15:52:38 +00:00
}
//Реген. - 250 ед.
//конец бонусов
2023-12-05 01:01:04 +00:00
$st [ 'hpNow' ] = Comparsion :: minimax ( $st [ 'hpNow' ], 0 , $st [ 'hpall' ]);
$st [ 'mpNow' ] = Comparsion :: minimax ( $st [ 'mpNow' ], 0 , $st [ 'mpall' ]);
2023-11-10 15:52:38 +00:00
//зоны блока и удара
2024-01-05 22:14:35 +00:00
//если второе оружие одето
if ( $hnd2 == 1 && $hnd1 == 1 ) {
$st [ 'zona' ] ++ ;
}
if ( $sht1 == 1 ) {
$st [ 'zonb' ] ++ ;
}
2024-01-08 01:33:20 +00:00
$st [ 'zona' ] = Comparsion :: minimax ( $st [ 'zona' ], 1 , 5 );
$st [ 'zonb' ] = Comparsion :: minimax ( $st [ 'zonb' ], 1 , 3 );
2023-11-10 15:52:38 +00:00
$st [ 'weapon1' ] = $hnd1 ;
$st [ 'weapon2' ] = $hnd2 ;
$st [ 'sheld1' ] = $sht1 ;
$st [ 'sv_' ] = $s_v ;
$st [ 'sv_i' ] = $s_vi ;
$st [ 'dom' ] = $dom ;
$st [ 'prsu' ] = $prsu ;
$st [ 'x' ] = $u [ 'x' ];
$st [ 'y' ] = $u [ 'y' ];
$st [ 's' ] = $u [ 's' ];
$this -> addDungeonsBonuses ( $u [ 'id' ], $st );
//Добавочный подьем для игроков
2023-12-05 01:01:04 +00:00
$this -> addKeyIfNotExist ( 'maxves' , 100 , $st );
2023-11-10 15:52:38 +00:00
$this -> addAdminBonuses ( $u , $st );
if ( date ( 'H' ) >= 22 && date ( 'H' ) <= 10 ) {
2023-12-05 01:01:04 +00:00
$this -> addKeyIfNotExist ( 'exp' , 25 , $st );
2023-11-10 15:52:38 +00:00
}
if ( isset ( $st [ 'btl_cof' ], $st [ 'prckr' ]) && $st [ 'btl_cof' ] != $st [ 'prckr' ]) {
$st [ 'btl_cof' ] = $st [ 'prckr' ];
Db :: sql ( 'update stats set btl_cof = ? where id = ?' , [ $st [ 'prckr' ], $st [ 'id' ]]);
}
2024-01-05 22:14:35 +00:00
$st [ 'hpall' ] = max ( $st [ 'hpall' ], 1 );
$st [ 'mpall' ] = max ( $st [ 'mpall' ], 0 );
2023-11-10 15:52:38 +00:00
if ( stristr ( $u [ 'login' ], '(зверь ' ) || ( stristr ( $u [ 'login' ], 'Каменный страж' ) && $u [ 'ip' ] == '0' )) {
$st [ 'this_animal' ] = 1 ;
} else {
$st [ 'this_animal' ] = 0 ;
}
2023-12-05 01:01:04 +00:00
$this -> renameArrayKeys ( $st );
2023-11-10 15:52:38 +00:00
$rt = [];
if ( $i1 == 1 ) {
$rt [ 0 ] = $st ;
$rt [ 1 ] = $baseStats ; //родные статы
} else {
$rt = $st ;
}
2024-01-05 22:14:35 +00:00
if ( $u [ 'hpAll' ] != $st [ 'hpAll' ] || $u [ 'mpAll' ] != $st [ 'mpAll' ]) {
Db :: sql ( 'update stats set hpAll = ?, mpAll = ? where id = ?' , [ $st [ 'hpAll' ], $st [ 'mpAll' ], $u [ 'id' ]]);
2023-11-10 15:52:38 +00:00
}
if ( $btl_cache ) {
$dataca = [
'st' => $st ,
'st2' => $baseStats ,
];
$dataca = json_encode ( $dataca );
Db :: sql ( 'insert into battle_cache (battle, uid, time, data) values (?,?,unix_timestamp(),?)' , [ $u [ 'battle' ], $u [ 'id' ], $dataca ]);
}
return $rt ;
}
2023-12-05 01:01:04 +00:00
/** Собираем динамически создаваемые параметры . Если ключа нет - создаём .
* @ param string $key
2023-12-19 01:58:37 +00:00
* @ param int $value
* @ param array $st
2023-12-05 01:01:04 +00:00
* @ return void
*/
private function addKeyIfNotExist ( string $key , int $value , array & $st ) : void
{
if ( ! isset ( $st [ $key ])) {
$st [ $key ] = 0 ;
$this -> statsKeys [] = $key ;
}
$st [ $key ] += $value ;
}
2024-01-08 01:33:20 +00:00
/**
* Добавляет бонусы к статам игрока .
* Генерирует переменную User : class -> stats [ 'items' ], где лежат одетые предметы .
* @ param int $uid
* @ param array $st
* @ param array $s_v
* @ param array $baseStats
* @ return array
*/
2023-11-10 15:52:38 +00:00
private function addWearedItemsBonuses ( int $uid , array & $st , array & $s_v , array $baseStats ) : array
{
2023-08-15 22:48:29 +00:00
//Характеристики от предметов //Т У Т tr_lvl
// Вся вторая строчка - спасибо Users.
2023-12-19 01:58:37 +00:00
$wearedItems = Db :: getRows (
' select type , data , inOdet ,
2023-08-15 22:48:29 +00:00
item_id , inslot , useInBattle , btl_zd , iznosNOW , iznosMAX , magic_inci , name , items_users . id , img , `2h`
2023-12-19 01:58:37 +00:00
from items_users left join items_main on items_main . id = item_id where inOdet != 0 and uid = ? ' , [ $uid ]
);
2023-08-15 22:48:29 +00:00
$h = 0 ;
$hnd1 = 0 ;
$hnd2 = 0 ;
$sht1 = 0 ;
$reitm = [];
$coms = []; // комплекты
$dom = [];
2024-01-08 01:33:20 +00:00
$wi = new WearedItem (); // на замену User:class->stats['items']
$st [ 'items_o' ] = $wi ;
2024-01-05 22:14:35 +00:00
2023-08-15 22:48:29 +00:00
foreach ( $wearedItems as $wearedItem ) {
2024-01-08 01:33:20 +00:00
// Генерируем всратую пепяку User:class->stats['wpXid'] > 0, которая показывает, что определённый слот
// чем-то занят. Странное решение.
2023-12-05 01:01:04 +00:00
$this -> addKeyIfNotExist ( 'wp' . $wearedItem [ 'inOdet' ] . 'id' , $h , $st );
2023-08-15 22:48:29 +00:00
$st [ 'items' ][ $h ] = $wearedItem ;
$h ++ ;
2024-01-08 01:33:20 +00:00
$wi -> add ( new Item ( $wearedItem ));
// Если в левой руке (3) предметы определённого типа, то рука занята оружием.
2023-11-10 15:52:38 +00:00
if ( $wearedItem [ 'inOdet' ] == 3 &&
(( $wearedItem [ 'type' ] >= 18 && $wearedItem [ 'type' ] <= 24 ) ||
$wearedItem [ 'type' ] == 26 ||
$wearedItem [ 'type' ] == 27 ||
$wearedItem [ 'type' ] == 28 )) {
2023-08-15 22:48:29 +00:00
$hnd1 = 1 ;
}
2024-01-08 01:33:20 +00:00
// Если в правой руке (14) предметы определённого типа, то рука занята оружием или щитом.
2023-11-10 15:52:38 +00:00
if ( $wearedItem [ 'inOdet' ] == 14 &&
(( $wearedItem [ 'type' ] >= 18 && $wearedItem [ 'type' ] <= 24 ) ||
$wearedItem [ 'type' ] == 26 ||
$wearedItem [ 'type' ] == 27 ||
$wearedItem [ 'type' ] == 28 )) {
2023-08-15 22:48:29 +00:00
$hnd2 = 1 ;
} elseif ( $wearedItem [ 'inOdet' ] == 14 && $wearedItem [ 'type' ] == 13 ) {
$sht1 = 1 ;
}
2024-01-08 01:33:20 +00:00
// Если в любом слоте что-то есть, повышается User:class->stats['reting'] за каждый слот
// Используется каким-то непонятным образом в хаотах.
2023-08-15 22:48:29 +00:00
if ( $wearedItem [ 'inOdet' ] <= 18 && $wearedItem [ 'inOdet' ] > 0 ) {
2023-12-05 01:01:04 +00:00
$this -> addKeyIfNotExist ( 'reting' , 1 , $st );
2023-08-15 22:48:29 +00:00
}
2024-01-08 01:33:20 +00:00
$data = Conversion :: dataStringToArray ( $wearedItem [ 'data' ]);
2023-12-05 01:01:04 +00:00
if ( isset ( $data [ 'art' ])) {
$this -> addKeyIfNotExist ( 'art' , $data [ 'art' ], $st );
}
if ( isset ( $data [ 'maks_itm' ])) {
$this -> addKeyIfNotExist ( 'maks_itm' , $data [ 'maks_itm' ], $st );
}
if ( isset ( $data [ 'complect' ])) {
$coms [ count ( $coms )][ 'id' ] = $data [ 'complect' ];
if ( ! isset ( $coms [ 'com' ][ $data [ 'complect' ]])) {
$coms [ 'com' ][ $data [ 'complect' ]] = 0 ;
2023-08-15 22:48:29 +00:00
if ( ! isset ( $coms [ 'new' ])) {
$coms [ 'new' ] = [];
}
2023-12-05 01:01:04 +00:00
$coms [ 'new' ][ count ( $coms [ 'new' ])] = $data [ 'complect' ];
2023-08-15 22:48:29 +00:00
}
2023-12-05 01:01:04 +00:00
$coms [ 'com' ][ $data [ 'complect' ]] ++ ;
2023-08-15 22:48:29 +00:00
}
2023-11-10 15:52:38 +00:00
2023-12-05 01:01:04 +00:00
if ( isset ( $data [ 'complect2' ])) {
$coms [ count ( $coms )][ 'id' ] = $data [ 'complect2' ];
if ( ! isset ( $coms [ 'com' ][ $data [ 'complect2' ]])) {
$coms [ 'com' ][ $data [ 'complect2' ]] = 0 ;
2023-08-15 22:48:29 +00:00
if ( ! isset ( $coms [ 'new' ])) {
$coms [ 'new' ] = [];
}
2023-12-05 01:01:04 +00:00
$coms [ 'new' ][ count ( $coms [ 'new' ])] = $data [ 'complect2' ];
2023-08-15 22:48:29 +00:00
}
2023-12-05 01:01:04 +00:00
$coms [ 'com' ][ $data [ 'complect2' ]] ++ ;
2023-08-15 22:48:29 +00:00
}
2023-12-05 01:01:04 +00:00
if ( ! empty ( $data [ 'zonb' ])) {
$this -> addKeyIfNotExist ( 'zonb' , $data [ 'zonb' ], $st );
2023-08-15 22:48:29 +00:00
}
2023-12-05 01:01:04 +00:00
if ( ! empty ( $data [ 'zona' ])) {
$this -> addKeyIfNotExist ( 'zona' , $data [ 'zona' ], $st );
2023-08-15 22:48:29 +00:00
}
//Добавляем статы от данного предмета
2023-12-05 01:01:04 +00:00
if ( ! isset ( $data [ 'restart_stats' ])) {
2024-01-16 07:13:15 +00:00
foreach ( $this -> sysNames -> sysBonusNames as $stat ) {
2023-12-05 01:01:04 +00:00
if ( ! isset ( $data [ 'add_' . $stat ])) {
2023-11-10 15:52:38 +00:00
continue ;
2023-08-15 22:48:29 +00:00
}
2023-12-05 01:01:04 +00:00
$st [ $stat ] += ( int ) $data [ 'add_' . $stat ];
2023-08-15 22:48:29 +00:00
}
} else {
2023-12-05 01:01:04 +00:00
$reitm [] = $data ;
2023-08-15 22:48:29 +00:00
}
}
//Сохраненные х а р -ки и умения
2023-12-05 01:01:04 +00:00
if ( ! empty ( $reitm ) && is_iterable ( $reitm )) {
$i39 = [];
foreach ( $reitm as $item ) {
if ( isset ( $item [ 'sm_skill' ]) && $i39 [ 0 ] == 0 ) {
2023-08-15 22:48:29 +00:00
//умения
$i39 [ 0 ] = 1 ;
2023-12-05 01:01:04 +00:00
$st [ 'a1' ] -= $baseStats [ 'a1' ] + $item [ 'add_a1' ];
$st [ 'a2' ] -= $baseStats [ 'a2' ] + $item [ 'add_a2' ];
$st [ 'a3' ] -= $baseStats [ 'a3' ] + $item [ 'add_a3' ];
$st [ 'a4' ] -= $baseStats [ 'a4' ] + $item [ 'add_a4' ];
$st [ 'a5' ] -= $baseStats [ 'a5' ] + $item [ 'add_a5' ];
$st [ 'mg1' ] -= $baseStats [ 'mg1' ] + $item [ 'add_mg1' ];
$st [ 'mg2' ] -= $baseStats [ 'mg2' ] + $item [ 'add_mg2' ];
$st [ 'mg3' ] -= $baseStats [ 'mg3' ] + $item [ 'add_mg3' ];
$st [ 'mg4' ] -= $baseStats [ 'mg4' ] + $item [ 'add_mg4' ];
$st [ 'mg7' ] -= $baseStats [ 'mg7' ] + $item [ 'add_mg7' ];
} elseif ( isset ( $item [ 'sm_abil' ]) && $i39 [ 1 ] == 0 ) {
2023-08-15 22:48:29 +00:00
//статы
$i39 [ 1 ] = 1 ;
2023-12-05 01:01:04 +00:00
$st [ 's1' ] -= $baseStats [ 's1' ] + $item [ 'add_s1' ];
$st [ 's2' ] -= $baseStats [ 's2' ] + $item [ 'add_s2' ];
$st [ 's3' ] -= $baseStats [ 's3' ] + $item [ 'add_s3' ];
$st [ 's4' ] -= $baseStats [ 's4' ] + $item [ 'add_s4' ];
$st [ 's5' ] -= $baseStats [ 's5' ] + $item [ 'add_s5' ];
$st [ 's6' ] -= $baseStats [ 's6' ] + $item [ 'add_s6' ];
$st [ 's7' ] -= $baseStats [ 's7' ] + $item [ 'add_s7' ];
} elseif ( isset ( $item [ 'sm_skill2' ]) && $i39 [ 2 ] == 0 ) {
2023-08-15 22:48:29 +00:00
//навыки
$i39 [ 2 ] = 1 ;
}
}
}
2024-01-08 01:33:20 +00:00
return [ $hnd1 , $hnd2 , $sht1 , $dom , $coms ];
2023-11-10 15:52:38 +00:00
}
2023-08-15 22:48:29 +00:00
2023-11-10 15:52:38 +00:00
private function addMedalsBonuses ( int $uid , array & $st ) : void
{
//Харки от иконок
2023-08-15 22:48:29 +00:00
2023-11-10 15:52:38 +00:00
$efs = Db :: getColumn ( 'select bonus from users_ico where uid = ? and (endTime > unix_timestamp() or endTime = 0)' , [ $uid ]);
foreach ( $efs as $data ) {
$sts = Conversion :: dataStringToArray ( $data );
foreach ( $sts as $paramName => $value ) {
2024-01-16 07:13:15 +00:00
if ( ! in_array ( $paramName , $this -> sysNames -> sysBonusNames , true )) { // есть ли параметр в разрешенных?
2023-11-10 15:52:38 +00:00
continue ;
2023-08-15 22:48:29 +00:00
}
2023-12-05 01:01:04 +00:00
$st [ $paramName ] += $value ;
2023-11-10 15:52:38 +00:00
}
}
}
2023-11-09 17:24:47 +00:00
2023-11-10 15:52:38 +00:00
private function addValuesToAllArrays ( array $sts , array & $st , array & $sti , array & $s_v , array & $s_vi ) : void
{
2024-01-16 07:13:15 +00:00
foreach ( $this -> sysNames -> sysBonusNames as $stat ) {
2023-11-10 15:52:38 +00:00
if ( ! isset ( $sts [ 'add_' . $stat ])) {
continue ;
}
$st [ $stat ] += intval ( $sts [ 'add_' . $stat ]);
$sti [ $stat ] += intval ( $sts [ 'add_' . $stat ]);
2023-11-09 17:24:47 +00:00
2023-11-10 15:52:38 +00:00
if ( ! isset ( $sts [ 'sv_' . $stat ])) {
continue ;
2023-08-15 22:48:29 +00:00
}
2023-11-10 15:52:38 +00:00
$s_v [ $stat ] += intval ( $sts [ 'sv_' . $stat ]);
$s_vi [ $stat ] += intval ( $sts [ 'sv_' . $stat ]);
}
}
private function addWearedItemsIllusion ( array $nbs , array & $st ) : void
{
//Заглушки от эффектов
2023-08-15 22:48:29 +00:00
if ( $nbs [ 4899 ] > 0 ) {
//Зеленый комплект
$st [ 'items_img' ][ 8 ] = 'robe_illusion4.gif' ;
$st [ 'items_img' ][ 11 ] = 'leg_illusion4.gif' ;
} elseif ( $nbs [ 4900 ] > 0 ) {
//Золото комплект
$st [ 'items_img' ][ 8 ] = 'robe_illusion5.gif' ;
$st [ 'items_img' ][ 11 ] = 'leg_illusion5.gif' ;
} elseif ( $nbs [ 4901 ] > 0 ) {
//Голубой комплект
$st [ 'items_img' ][ 8 ] = 'robe_illusion3.gif' ;
$st [ 'items_img' ][ 11 ] = 'leg_illusion3.gif' ;
} elseif ( $nbs [ 4902 ] > 0 ) {
//Синий комплект
$st [ 'items_img' ][ 8 ] = 'robe_illusion6.gif' ;
$st [ 'items_img' ][ 11 ] = 'leg_illusion6.gif' ;
} elseif ( $nbs [ 4903 ] > 0 ) {
//Желтый комплект
$st [ 'items_img' ][ 8 ] = 'robe_illusion8.gif' ;
$st [ 'items_img' ][ 11 ] = 'leg_illusion8.gif' ;
} elseif ( $nbs [ 4904 ] > 0 ) {
//Сиреневое платье
$st [ 'items_img' ][ 8 ] = 'robe_illusion7.gif' ;
$st [ 'items_img' ][ 11 ] = 'leg_illusion7.gif' ;
} elseif ( $nbs [ 4905 ] > 0 ) {
//Оранжевое платье
$st [ 'items_img' ][ 8 ] = 'robe_illusion9.gif' ;
$st [ 'items_img' ][ 11 ] = 'leg_illusion9.gif' ;
} elseif ( $nbs [ 4908 ] > 0 ) {
//Н а б о р Темной Одежды
$st [ 'items_img' ][ 8 ] = 'robe_illusion2.gif' ;
$st [ 'items_img' ][ 11 ] = 'leg_illusion2.gif' ;
$st [ 'items_img' ][ 10 ] = 'boots_illusion2.gif' ;
$st [ 'items_img' ][ 9 ] = 'belt_illusion2.gif' ;
$st [ 'items_img' ][ 5 ] = 'naruchi_illusion2.gif' ;
$st [ 'items_img' ][ 4 ] = 'helmet_illusion2.gif' ;
$st [ 'items_img' ][ 12 ] = 'perchi_illusion2.gif' ;
} elseif ( $nbs [ 4906 ] > 0 ) {
//Н а б о р Бриллиантовой Одежды
$st [ 'items_img' ][ 8 ] = 'robe_illusion1.gif' ;
$st [ 'items_img' ][ 11 ] = 'leg_illusion1.gif' ;
$st [ 'items_img' ][ 10 ] = 'boots_illusion1.gif' ;
$st [ 'items_img' ][ 9 ] = 'belt_illusion1.gif' ;
$st [ 'items_img' ][ 5 ] = 'naruchi_illusion1.gif' ;
$st [ 'items_img' ][ 4 ] = 'helmet_illusion1.gif' ;
$st [ 'items_img' ][ 12 ] = 'perchi_illusion1.gif' ;
}
if ( $nbs [ 4909 ] > 0 ) {
//Н а б о р Золотых украшений
$st [ 'items_img' ][ 13 ] = 'ring_illusion2.gif' ;
$st [ 'items_img' ][ 17 ] = 'ring_illusion2.gif' ;
$st [ 'items_img' ][ 18 ] = 'ring_illusion2.gif' ;
$st [ 'items_img' ][ 14 ] = 'amulet_illusion2.gif' ;
$st [ 'items_img' ][ 15 ] = 'earrings_illusion2.gif' ;
} elseif ( $nbs [ 4907 ] > 0 ) {
//Н а б о р Золотых украшений
$st [ 'items_img' ][ 13 ] = 'ring_illusion1.gif' ;
$st [ 'items_img' ][ 17 ] = 'ring_illusion1.gif' ;
$st [ 'items_img' ][ 18 ] = 'ring_illusion1.gif' ;
$st [ 'items_img' ][ 14 ] = 'amulet_illusion1.gif' ;
$st [ 'items_img' ][ 15 ] = 'earrings_illusion1.gif' ;
}
2023-11-10 15:52:38 +00:00
}
2023-08-15 22:48:29 +00:00
2023-11-10 15:52:38 +00:00
private function addInBattlePriemsBonuses ( array $u , array & $st , array & $prsu , array & $sti , array & $s_v , array & $s_vi ) : void
{
if ( $u [ 'battle' ] <= 0 ) {
return ;
}
//Характеристики от приемов
$st [ 'set_pog' ] = [];
$st [ 'set_pog2' ] = [];
$efs = Db :: getRows ( " select * from eff_users where uid = ? and deactiveTime < unix_timestamp() and v1 = 'priem' order by id " , [ $u [ 'id' ]]);
$h = 0 ;
foreach ( $efs as $e ) {
$e [ 'type1' ] = 14 ;
$e [ 'img' ] = $e [ 'img2' ];
if ( $e [ 'tr_life_user' ] > 0 ) {
$trlu = Db :: getValue ( 'select hpNow from stats where id = ?' , [ $e [ 'tr_life_user' ]]);
if ( ! $trlu || $trlu < 1 ) {
2023-08-15 22:48:29 +00:00
$this -> u -> endEffect ( $e [ 'id' ], $u );
$st [ 'act' ] = 1 ;
}
}
2023-11-10 15:52:38 +00:00
if ( $e [ 'timeUse' ] + $e [ 'timeAce' ] + $e [ 'actionTime' ] > time () || $e [ 'timeUse' ] == 77 ) {
if ( $e [ 'v1' ] == 'priem' ) {
$prsu [ $e [ 'v2' ]] = 0 + $prsu [ 'x' ];
2023-08-15 22:48:29 +00:00
}
2023-11-10 15:52:38 +00:00
$st [ 'effects' ][ $h ] = $e ;
$h ++ ;
$sts = Conversion :: dataStringToArray ( $e [ 'data' ]);
if ( $e [ 'v2' ] == 217 ) {
$st [ 'raztac' ] = 1 ;
2023-11-02 13:57:39 +00:00
}
2023-11-10 15:52:38 +00:00
if ( isset ( $sts [ 'add_pog' ])) {
$ctt = count ( $st [ 'set_pog' ]);
$st [ 'set_pog' ][ $ctt ][ 'id' ] = $h ;
$st [ 'set_pog' ][ $ctt ][ 'y' ] = $sts [ 'add_pog' ];
unset ( $ctt );
2023-11-02 13:57:39 +00:00
}
2023-11-10 15:52:38 +00:00
if ( isset ( $sts [ 'natoe' ])) {
$st [ 'set_natoe' ][ 'id' ] = $h ;
$st [ 'set_natoe' ][ 'a' ] = 0 + $sts [ 'natoe_end' ];
$st [ 'set_natoe' ][ 'b' ] = 0 + $sts [ 'natoe' ];
$st [ 'set_natoe' ][ 'eff_id' ] = $e [ 'id' ];
$st [ 'set_natoe' ][ 't' ] = 0 + $sts [ 'natoe_type' ];
$st [ 'set_natoe' ][ 'user_id' ] = $e [ 'tr_life_user' ];
2023-11-02 13:57:39 +00:00
}
2023-11-10 15:52:38 +00:00
if ( isset ( $sts [ 'add_pog2' ])) {
$ctt = count ( $st [ 'set_pog2' ]);
$st [ 'set_pog2' ][ $ctt ][ 'id' ] = $h ;
$st [ 'set_pog2' ][ $ctt ][ 'y' ] = $sts [ 'add_pog2' ];
$st [ 'set_pog2' ][ $ctt ][ 'p' ] = $sts [ 'add_pog2p' ];
$st [ 'set_pog2' ][ $ctt ][ 'm' ] = $sts [ 'add_pog2mp' ];
unset ( $ctt );
2023-11-02 13:57:39 +00:00
}
2023-11-10 15:52:38 +00:00
$this -> addValuesToAllArrays ( $sts , $st , $sti , $s_v , $s_vi );
2023-11-02 13:57:39 +00:00
2023-11-10 15:52:38 +00:00
} else {
//удаляем эффект
$this -> u -> endEffect ( $e [ 'id' ], $u );
$st [ 'act' ] = 1 ;
2023-11-02 13:57:39 +00:00
}
}
}
private function addStatBonuses ( array & $st ) : void
{
$this -> addStrengthBonuses ( $st );
$this -> addDexterityBonuses ( $st );
$this -> addIntuitionBonuses ( $st );
$this -> addEnduranceBonuses ( $st );
$this -> addIntelligenceBonuses ( $st );
$this -> addWisdomBonuses ( $st );
}
private function addStrengthBonuses ( array & $st ) : void
{
2023-08-15 22:48:29 +00:00
if ( $st [ 's1' ] > 24 && $st [ 's1' ] < 50 ) {
$st [ 'm2' ] += 15 ;
}
if ( $st [ 's1' ] > 49 && $st [ 's1' ] < 75 ) {
$st [ 'pa2' ] += 2 ;
$st [ 'm2' ] += 35 ;
}
if ( $st [ 's1' ] > 74 && $st [ 's1' ] < 100 ) {
$st [ 'pa2' ] += 5 ;
$st [ 'm2' ] += 50 ;
}
if ( $st [ 's1' ] > 99 && $st [ 's1' ] < 125 ) {
$st [ 'pa2' ] += 8 ;
$st [ 'm2' ] += 80 ;
}
if ( $st [ 's1' ] > 124 && $st [ 's1' ] < 150 ) {
$st [ 'pa2' ] += 12 ;
$st [ 'm2' ] += 105 ;
}
if ( $st [ 's1' ] > 149 && $st [ 's1' ] < 175 ) {
$st [ 'pa2' ] += 17 ;
$st [ 'm7' ] += 2 ;
}
if ( $st [ 's1' ] > 174 && $st [ 's1' ] < 200 ) {
$st [ 'pa2' ] += 23 ;
$st [ 'm7' ] += 5 ;
}
if ( $st [ 's1' ] > 199 ) {
$st [ 'pa2' ] += 30 ;
$st [ 'm7' ] += 7 ;
}
2023-11-02 13:57:39 +00:00
}
private function addDexterityBonuses ( array & $st ) : void
{
2023-08-15 22:48:29 +00:00
if ( $st [ 's2' ] > 24 && $st [ 's2' ] < 50 ) {
$st [ 'pa1' ] += 2 ;
$st [ 'm4' ] += 35 ;
}
if ( $st [ 's2' ] > 49 && $st [ 's2' ] < 75 ) {
$st [ 'pa1' ] += 5 ;
$st [ 'm2' ] += 40 ;
$st [ 'm4' ] += 75 ;
}
if ( $st [ 's2' ] > 74 && $st [ 's2' ] < 100 ) {
$st [ 'pa1' ] += 8 ;
$st [ 'm2' ] += 65 ;
$st [ 'm4' ] += 90 ;
}
if ( $st [ 's2' ] > 99 && $st [ 's2' ] < 125 ) {
$st [ 'pa1' ] += 12 ;
$st [ 'm2' ] += 75 ;
$st [ 'm4' ] += 105 ;
}
if ( $st [ 's2' ] > 124 && $st [ 's2' ] < 150 ) {
$st [ 'pa1' ] += 17 ;
$st [ 'm2' ] += 85 ;
$st [ 'm4' ] += 105 ;
$st [ 'm15' ] += 1 ;
}
if ( $st [ 's2' ] > 149 && $st [ 's2' ] < 175 ) {
$st [ 'pa1' ] += 20 ;
$st [ 'm2' ] += 110 ;
$st [ 'm4' ] += 115 ;
$st [ 'm15' ] += 2 ;
}
if ( $st [ 's2' ] > 174 && $st [ 's2' ] < 200 ) {
$st [ 'pa1' ] += 23 ;
$st [ 'm2' ] += 145 ;
$st [ 'm4' ] += 145 ;
$st [ 'm15' ] += 3 ;
}
if ( $st [ 's2' ] > 199 ) {
$st [ 'pa1' ] += 30 ;
$st [ 'm2' ] += 165 ;
$st [ 'm4' ] += 165 ;
$st [ 'm15' ] += 5 ;
2023-11-02 13:57:39 +00:00
}
}
private function addIntuitionBonuses ( array & $st ) : void
{
2023-11-10 15:52:38 +00:00
if ( $st [ 's3' ] >= 200 ) {
2023-08-15 22:48:29 +00:00
$st [ 'm1' ] += 185 ;
2023-11-10 15:52:38 +00:00
$st [ 'm3' ] += 40 ;
2023-08-15 22:48:29 +00:00
$st [ 'm5' ] += 65 ;
$st [ 'm14' ] += 5 ;
2023-11-10 15:52:38 +00:00
$st [ 'pa4' ] += 30 ;
} elseif ( $st [ 's3' ] >= 175 ) {
$st [ 'm1' ] += 165 ;
$st [ 'm3' ] += 35 ;
$st [ 'm5' ] += 55 ;
$st [ 'm14' ] += 3 ;
$st [ 'pa4' ] += 23 ;
} elseif ( $st [ 's3' ] >= 150 ) {
$st [ 'm1' ] += 145 ;
$st [ 'm3' ] += 30 ;
$st [ 'm5' ] += 50 ;
$st [ 'm14' ] += 2 ;
$st [ 'pa4' ] += 20 ;
} elseif ( $st [ 's3' ] >= 125 ) {
$st [ 'm1' ] += 125 ;
$st [ 'm3' ] += 20 ;
$st [ 'm5' ] += 45 ;
$st [ 'm14' ] += 1 ;
$st [ 'pa4' ] += 17 ;
} elseif ( $st [ 's3' ] >= 100 ) {
$st [ 'm1' ] += 105 ;
$st [ 'm3' ] += 15 ;
$st [ 'm5' ] += 35 ;
$st [ 'pa4' ] += 12 ;
} elseif ( $st [ 's3' ] >= 75 ) {
$st [ 'm1' ] += 75 ;
$st [ 'm3' ] += 10 ;
$st [ 'm5' ] += 25 ;
$st [ 'pa4' ] += 8 ;
} elseif ( $st [ 's3' ] >= 50 ) {
$st [ 'm1' ] += 55 ;
$st [ 'm3' ] += 5 ;
$st [ 'pa4' ] += 5 ;
} elseif ( $st [ 's3' ] >= 25 ) {
$st [ 'm1' ] += 25 ;
$st [ 'm3' ] += 2 ;
$st [ 'pa4' ] += 2 ;
2023-11-02 13:57:39 +00:00
}
}
private function addEnduranceBonuses ( array & $st ) : void
{
//выносливость
2023-08-15 22:48:29 +00:00
if ( $st [ 's4' ] > 0 ) {
2023-12-05 01:01:04 +00:00
$st [ 'hpall' ] += 30 ;
2023-08-15 22:48:29 +00:00
}
if ( $st [ 's4' ] > 24 && $st [ 's4' ] < 50 ) {
2023-12-05 01:01:04 +00:00
$st [ 'hpall' ] += 50 ;
2023-08-15 22:48:29 +00:00
}
if ( $st [ 's4' ] > 49 && $st [ 's4' ] < 75 ) {
2023-12-05 01:01:04 +00:00
$st [ 'hpall' ] += 100 ;
2023-08-15 22:48:29 +00:00
}
if ( $st [ 's4' ] > 74 && $st [ 's4' ] < 100 ) {
2023-12-05 01:01:04 +00:00
$st [ 'hpall' ] += 175 ;
2023-08-15 22:48:29 +00:00
$st [ 'm19' ] += 2 ;
}
if ( $st [ 's4' ] > 99 && $st [ 's4' ] < 125 ) {
2023-12-05 01:01:04 +00:00
$st [ 'hpall' ] += 250 ;
2023-08-15 22:48:29 +00:00
$st [ 'm19' ] += 4 ;
}
if ( $st [ 's4' ] > 124 && $st [ 's4' ] < 150 ) {
2023-12-05 01:01:04 +00:00
$st [ 'hpall' ] += 400 ;
2023-08-15 22:48:29 +00:00
$st [ 'za' ] += 25 ;
$st [ 'zm' ] += 25 ;
}
if ( $st [ 's4' ] > 149 && $st [ 's4' ] < 175 ) {
2023-12-05 01:01:04 +00:00
$st [ 'hpall' ] += 450 ;
2023-08-15 22:48:29 +00:00
$st [ 'za' ] += 50 ;
$st [ 'zm' ] += 50 ;
}
if ( $st [ 's4' ] > 174 && $st [ 's4' ] < 200 ) {
2023-12-05 01:01:04 +00:00
$st [ 'hpall' ] += 600 ;
2023-08-15 22:48:29 +00:00
$st [ 'za' ] += 100 ;
$st [ 'zm' ] += 100 ;
}
if ( $st [ 's4' ] > 199 ) {
2023-12-05 01:01:04 +00:00
$st [ 'hpall' ] += 850 ;
2023-08-15 22:48:29 +00:00
$st [ 'za' ] += 125 ;
$st [ 'zm' ] += 125 ;
2023-11-02 13:57:39 +00:00
}
}
private function addIntelligenceBonuses ( array & $st ) : void
{
2023-12-19 01:58:37 +00:00
//интелект
2023-08-15 22:48:29 +00:00
if ( $st [ 's5' ] > 24 && $st [ 's5' ] < 50 ) {
$st [ 'm11' ] += 10 ;
}
if ( $st [ 's5' ] > 49 && $st [ 's5' ] < 75 ) {
$st [ 'm11' ] += 15 ;
}
if ( $st [ 's5' ] > 74 && $st [ 's5' ] < 100 ) {
$st [ 'm11' ] += 20 ;
}
if ( $st [ 's5' ] > 99 && $st [ 's5' ] < 125 ) {
$st [ 'm11' ] += 25 ;
}
if ( $st [ 's5' ] > 124 && $st [ 's5' ] < 150 ) {
$st [ 'm11' ] += 35 ;
}
if ( $st [ 's5' ] > 149 && $st [ 's5' ] < 175 ) {
$st [ 'm11' ] += 50 ;
}
if ( $st [ 's5' ] > 174 ) {
$st [ 'm11' ] += 65 ;
$st [ 'pzm' ] += 2 ;
}
if ( $st [ 's5' ] > 199 ) {
$st [ 'pzm' ] += 5 ;
2023-11-02 13:57:39 +00:00
}
}
private function addWisdomBonuses ( array & $st ) : void
{
2023-12-19 01:58:37 +00:00
//мудрость
2023-08-15 22:48:29 +00:00
if ( $st [ 's6' ] > 24 && $st [ 's6' ] < 50 ) {
2023-12-05 01:01:04 +00:00
$st [ 'mpall' ] += 150 ;
2023-08-15 22:48:29 +00:00
$st [ 'speedmp' ] += 100 ;
}
if ( $st [ 's6' ] > 49 && $st [ 's6' ] < 75 ) {
2023-12-05 01:01:04 +00:00
$st [ 'mpall' ] += 200 ;
2023-08-15 22:48:29 +00:00
$st [ 'speedmp' ] += 200 ;
}
if ( $st [ 's6' ] > 74 && $st [ 's6' ] < 100 ) {
2023-12-05 01:01:04 +00:00
$st [ 'mpall' ] += 250 ;
2023-08-15 22:48:29 +00:00
$st [ 'speedmp' ] += 350 ;
}
if ( $st [ 's6' ] > 99 && $st [ 's6' ] < 125 ) {
2023-12-05 01:01:04 +00:00
$st [ 'mpall' ] += 350 ;
2023-08-15 22:48:29 +00:00
$st [ 'speedmp' ] += 500 ;
}
if ( $st [ 's6' ] > 124 && $st [ 's6' ] < 150 ) {
2023-12-05 01:01:04 +00:00
$st [ 'mpall' ] += 500 ;
2023-08-15 22:48:29 +00:00
$st [ 'speedmp' ] += 500 ;
$st [ 'pzm' ] += 2 ;
}
if ( $st [ 's6' ] > 149 && $st [ 's6' ] < 175 ) {
2023-12-05 01:01:04 +00:00
$st [ 'mpall' ] += 700 ;
2023-08-15 22:48:29 +00:00
$st [ 'speedmp' ] += 600 ;
$st [ 'pzm' ] += 3 ;
}
if ( $st [ 's6' ] > 174 && $st [ 's6' ] < 200 ) {
2023-12-05 01:01:04 +00:00
$st [ 'mpall' ] += 900 ;
2023-08-15 22:48:29 +00:00
$st [ 'speedmp' ] += 700 ;
$st [ 'pzm' ] += 5 ;
}
if ( $st [ 's6' ] > 199 ) {
2023-12-05 01:01:04 +00:00
$st [ 'mpall' ] += 900 ;
2023-08-15 22:48:29 +00:00
$st [ 'speedmp' ] += 700 ;
$st [ 'pzm' ] += 7 ;
}
2023-11-02 13:57:39 +00:00
}
2023-08-15 22:48:29 +00:00
2023-11-02 13:57:39 +00:00
private function addDungeonsBonuses ( int $id , array & $st ) : void
{
2023-12-19 01:58:37 +00:00
$finishedDungeons = Db :: getValue (
' select
2023-11-02 13:57:39 +00:00
if ( repcapitalcity > 24999 , 1 , 0 ) +
if ( repdemonscity > 24999 , 1 , 0 ) +
if ( repangelscity > 24999 , 1 , 0 ) +
if ( repdevilscity > 24999 , 1 , 0 ) +
if ( repmooncity > 24999 , 1 , 0 ) +
if ( repsuncity > 24999 , 1 , 0 ) +
if ( repsandcity > 24999 , 1 , 0 ) +
if ( repemeraldscity > 24999 , 1 , 0 ) +
if ( repizlom > 24999 , 1 , 0 ) +
2023-12-19 01:58:37 +00:00
0 as finished from rep where id = ? ' , [ $id ]
);
2023-11-02 13:57:39 +00:00
//Бонус за количество полностью вырытых пещер.
2024-01-05 22:14:35 +00:00
if ( isset ( $st [ 'm10' ])) {
$st [ 'm10' ] += 10 * $finishedDungeons ;
} else {
$st [ 'm10' ] = 10 * $finishedDungeons ;
}
2023-08-15 22:48:29 +00:00
}
2023-11-10 15:52:38 +00:00
private function addAdminBonuses ( array $u , array & $st ) : void
{
if ( ! $u [ 'admin' ]) {
return ;
}
2023-12-05 01:01:04 +00:00
$this -> addKeyIfNotExist ( 'speed_dungeon' , 500 , $st );
$this -> addKeyIfNotExist ( 'speedhp' , 500 , $st );
2023-11-10 15:52:38 +00:00
if ( ! $u [ 'battle' ]) {
return ;
}
2023-12-19 01:58:37 +00:00
Db :: sql (
" update stats set
2023-11-10 15:52:38 +00:00
tactic1 = tactic2 = tactic3 = tactic4 = tactic5 = tactic6 = tactic7 = 25 ,
priems_z = '0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|'
2023-12-19 01:58:37 +00:00
where id = ? " , [ $u['id'] ]
);
2023-11-10 15:52:38 +00:00
}
2023-12-05 01:01:04 +00:00
/** Переименовывает элементы массива с несовпадающими с остальным скриптом именами полей .
* @ param array $st
* @ return void
*/
private function renameArrayKeys ( array & $st ) : void
{
2024-01-05 22:14:35 +00:00
if ( isset ( $st [ 'level' ])) {
$st [ 'lvl' ] = $st [ 'level' ];
}
if ( isset ( $st [ 'hpall' ])) {
$st [ 'hpAll' ] = $st [ 'hpall' ];
}
if ( isset ( $st [ 'mpall' ])) {
$st [ 'mpAll' ] = $st [ 'mpall' ];
}
if ( isset ( $st [ 'hpnow' ])) {
$st [ 'hpNow' ] = $st [ 'hpnow' ];
}
if ( isset ( $st [ 'mpnow' ])) {
$st [ 'mpNow' ] = $st [ 'mpnow' ];
}
unset ( $st [ 'level' ], $st [ 'hpnow' ], $st [ 'mpnow' ], $st [ 'hpall' ], $st [ 'mpall' ]);
2023-12-05 01:01:04 +00:00
}
2023-12-19 01:58:37 +00:00
public static function saveBattleStats ( array $stats , int $id ) : void
{
if ( ! isset (
$stats [ 'hpnow' ],
$stats [ 'mpNow' ],
$stats [ 'tactic1' ],
$stats [ 'tactic2' ],
$stats [ 'tactic3' ],
$stats [ 'tactic4' ],
$stats [ 'tactic5' ],
$stats [ 'tactic6' ],
$stats [ 'tactic7' ],
$stats [ 'enemy' ],
$stats [ 'battle_yron' ],
$stats [ 'battle_exp' ],
$stats [ 'last_hp' ],
$stats [ 'priems_z' ],
)
) {
return ;
}
Db :: sql (
' update stats set hpNow = ? , mpNow = ? ,
tactic1 = ? , tactic2 = ? , tactic3 = ? , tactic4 = ? , tactic5 = ? , tactic6 = ? , tactic7 = ? ,
enemy = ? , battle_yron = ? , last_hp = ? , battle_exp = ? , priems_z = ?
where id = ? ' ,
[
$stats [ 'hpnow' ],
$stats [ 'mpNow' ],
$stats [ 'tactic1' ],
$stats [ 'tactic2' ],
$stats [ 'tactic3' ],
$stats [ 'tactic4' ],
$stats [ 'tactic5' ],
$stats [ 'tactic6' ],
$stats [ 'tactic7' ],
$stats [ 'enemy' ],
$stats [ 'battle_yron' ],
$stats [ 'battle_exp' ],
$stats [ 'last_hp' ],
$stats [ 'priems_z' ],
$id ,
]
);
}
2023-08-15 22:48:29 +00:00
}