163 lines
6.3 KiB
PHP
163 lines
6.3 KiB
PHP
<?php
|
||
# Date: 16.02.2022 (23:01)
|
||
namespace Battles;
|
||
|
||
use Battles\Database\Db;
|
||
|
||
class UserEffect
|
||
{
|
||
public static array $effectName = [
|
||
2 => 'Заклинание молчания',
|
||
3 => 'Заклятие форумного молчания',
|
||
4 => 'Заклятие хаоса',
|
||
5 => 'Заклятие обезличивания',
|
||
8 => 'Сон',
|
||
10 => 'паралич',
|
||
11 => 'Легкая травма',
|
||
12 => 'Средняя травма',
|
||
13 => 'Тяжёлая травма',
|
||
14 => 'Неизлечимая травма',
|
||
20 => 'Проверка Паладинов',
|
||
21 => 'Сила нейтралитета',
|
||
22 => 'Защита от кулачного нападения',
|
||
51 => 'Опьянение',
|
||
201 => 'Защита от оружия',
|
||
202 => 'Сокрушение',
|
||
203 => 'Туманный образ [1]',
|
||
204 => 'Туманный образ [2]',
|
||
205 => 'Туманный образ [3]',
|
||
206 => 'Гравитация [1]',
|
||
207 => 'Гравитация [2]',
|
||
208 => 'Гравитация [3]',
|
||
209 => 'Стена Огня [1]',
|
||
210 => 'Стена Огня [2]',
|
||
211 => 'Стена Огня [3]',
|
||
212 => 'Чистота Воды [1]',
|
||
213 => 'Чистота Воды [2]',
|
||
214 => 'Чистота Воды [3]',
|
||
215 => 'Защита эфира [1]',
|
||
216 => 'Защита эфира [2]',
|
||
217 => 'Защита эфира [3]',
|
||
218 => 'Песчаный щит [1]',
|
||
219 => 'Песчаный щит [2]',
|
||
220 => 'Песчаный щит [3]',
|
||
221 => 'Огненный Щит [1]',
|
||
222 => 'Огненный Щит [2]',
|
||
223 => 'Огненный Щит [3]',
|
||
224 => 'Стена Воды [1]',
|
||
225 => 'Стена Воды [2]',
|
||
226 => 'Стена Воды [3]',
|
||
227 => 'Защита от нападений',
|
||
405 => 'Микстура жизненных сил',
|
||
1022 => 'невидимость',
|
||
9994 => 'Антидот/Путы (Эликсир?)',
|
||
];
|
||
|
||
public static array $effectImage = [
|
||
1 => 'travma.gif',
|
||
2 => 'magic/sleep.gif',
|
||
3 => 'magic/sleepf.gif',
|
||
4 => 'magic/haos.gif',
|
||
5 => 'magic/obezl.gif',
|
||
6 => 'expx15.gif',
|
||
7 => 'euphoria.png',
|
||
8 => 'sleep_obj.gif',
|
||
10 => 'magic/chains.gif',
|
||
11 => 'travma.gif',
|
||
12 => 'travma.gif',
|
||
13 => 'travma.gif',
|
||
14 => 'travma.gif',
|
||
20 => 'check.gif',
|
||
21 => 'magic/al_neut_power.gif',
|
||
22 => 'magic/fist_def.gif',
|
||
201 => 'magic/defence.gif',
|
||
202 => 'magic/devastate.gif',
|
||
203 => 'magic/spell_luck.gif',
|
||
215 => 'magic/wis_air_def1.gif',
|
||
216 => 'magic/wis_air_def2.gif',
|
||
217 => 'magic/wis_air_def3.gif',
|
||
218 => 'magic/wis_earth_def1.gif',
|
||
219 => 'magic/wis_earth_def2.gif',
|
||
220 => 'magic/wis_earth_def3.gif',
|
||
221 => 'magic/wis_fire_def1.gif',
|
||
222 => 'magic/wis_fire_def2.gif',
|
||
223 => 'magic/wis_fire_def3.gif',
|
||
224 => 'magic/wis_water_def1.gif',
|
||
225 => 'magic/wis_water_def2.gif',
|
||
226 => 'magic/wis_water_def3.gif',
|
||
227 => 'magic/attack_defence.gif',
|
||
1022 => 'sh/hidden.gif',
|
||
];
|
||
|
||
/**
|
||
* @param int $userId
|
||
* @param int $type
|
||
* @param string $name
|
||
* @param int $time
|
||
* @param string|null $jsonModifiersList (str, dex, int, end, intel, wis).
|
||
*/
|
||
public static function add(int $userId, int $type, string $name, int $time, string $jsonModifiersList = null)
|
||
{
|
||
$mods = json_decode($jsonModifiersList);
|
||
Db::getInstance()->execute('INSERT INTO users_effects (owner_id, type, name, remaining_time, mod_strength, mod_dexterity, mod_intuition, mod_endurance, mod_intelligence, mod_wisdom) VALUES (?,?,?,?,?,?,?,?,?,?)', [$userId, $type, $name, $time, $mods->str ?? null, $mods->dex ?? null, $mods->int ?? null, $mods->end ?? null, $mods->intel ?? null, $mods->wis ?? null]);
|
||
}
|
||
|
||
public static function updateTime(int $userId, int $type, int $time)
|
||
{
|
||
if (self::hasEffect($userId, $type)) {
|
||
Db::getInstance()->execute('update users_effects set remaining_time = remaining_time + ? where owner_id = ? and type = ?', [$time, $userId, $type]);
|
||
}
|
||
}
|
||
|
||
public static function remove(int $userId, int $type): bool
|
||
{
|
||
if (self::hasEffect($userId, $type)) {
|
||
Db::getInstance()->execute('DELETE FROM users_effects WHERE owner_id = ? AND type = ?', [$userId, $type]);
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
public static function massRemove(int $userId, array $type): bool
|
||
{
|
||
if (Db::getInstance()->fetchColumn('SELECT count(*) FROM users_effects WHERE owner_id = ? AND type in (?)', [$userId, $type])) {
|
||
Db::getInstance()->execute('DELETE FROM users_effects WHERE owner_id = ? AND type in (?)', [$userId, $type]);
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
public static function hasEffect(int $userId, int $type): bool
|
||
{
|
||
return Db::getInstance()->fetchColumn('select count(*) from users_effects where owner_id = ? and type = ?', [$userId, $type]) > 0;
|
||
}
|
||
|
||
public static function getRemainingEffectTime(int $userId, int $type): int
|
||
{
|
||
return Db::getInstance()->fetchColumn('select remaining_time from users_effects where owner_id = ? and type = ?', [$userId, $type]);
|
||
}
|
||
|
||
public static function isInvisible(int $userId): bool
|
||
{
|
||
return self::hasEffect($userId, 1022);
|
||
}
|
||
|
||
public static function hasHiddenProfile(int $userId): string
|
||
{
|
||
$time = self::getRemainingEffectTime($userId, 5);
|
||
if (empty($time)) {
|
||
return '';
|
||
}
|
||
if ($time === -1) {
|
||
return 'навсегда';
|
||
}
|
||
return 'до' . date('d.m.Y', strtotime($time));
|
||
}
|
||
|
||
public static function isOverEncumbered(int $userid, int $addWeight = 0): bool
|
||
{
|
||
$query = 'select strength * 5 + ' . $addWeight . ' as max from inventory left join users u on owner_id = id where owner_id = ? having sum(weight) > max';
|
||
return Db::getInstance()->fetchColumn($query, $userid) > 0;
|
||
}
|
||
}
|