game/_incl_data/class/User/WearedScrolls.php

63 lines
2.0 KiB
PHP

<?php
namespace User;
use Core\Db;
/**
* Íåïîíÿòíûé êóñîê ôóíêöèè, êîòîðûé ëåæàë âíóòðè ñèñòåìû ïîäñ÷¸òà áîíóñîâ ê ïàðàìåòðàì,
* ïðè ýòîì íèêàê íà ýòî íå âëèÿÿ è íè ñ ÷åì íå âçàèìîäåéñòâóÿ. Íàäî ïîíÿòü ÷òî åãî
* âûçûâàåò è âûãíàòü åãî èç User\Stats.
*/
class WearedScrolls
{
public static function ScrollsChange(array &$u): void
{
//Çàìåíà ñâèòêîâ
if ($u['autospell'] == 0 || $u['battle'] != 0) {
return;
}
//ïðîâåðÿåì ñâèòêè
$sparr = [];
foreach (Db::getRows('select item_id, inOdet from items_users where inOdet between 40 and 50 and uid = ? order by item_id desc', [$u['id']]) as $scroll) {
$sparr[] = "{$scroll['item_id']} - {$scroll['inOdet']}";
}
$splink = implode(',', $sparr);
//Çàïîìèíàåì íîâûé êîìïëåêò ñâèòêîâ
if ($u['autospell'] == 1) {
$u['autospell'] = $splink;
Db::sql('update users set autospell = ? where id = ?', [$splink, $u['id']]);
}
//Âûäàåì íóæíûé ñâèòîê, åñëè îí åñòü â èíâåíòàðå
if ($u['autospell'] != $splink) {
$spe1 = explode(',', $splink);
$spe2 = explode(',', $u['autospell']);
$spe1g = [];
$spe2g = [];
for ($i = 0; $i <= 20; $i++) {
$spe1a = explode('-', $spe1[$i]);
$spe2a = explode('-', $spe2[$i]);
if (isset($spe1a[0])) {
$spe1g[$spe1a[1]] = $spe1a[0];
}
if (isset($spe2a[0])) {
$spe2g[$spe2a[1]] = $spe2a[0];
}
}
for ($i = 40; $i <= 50; $i++) {
if ($spe1g[$i] == $spe2g[$i] || $spe1g[$i] != 0) {
continue;
}
Db::sql('update items_users set inOdet = ? where inOdet = 0 and `delete` = 0 and inTransfer = 0 and inShop = 0 and inGroup = 0 and item_id = ? and uid = ?',
[$i, $spe2g[$i], $u['id']]);
}
}
}
}