Зимние правки. MVC/

Signed-off-by: lopar <lopar.4ever@gmail.com>
This commit is contained in:
lopar
2022-08-09 22:57:43 +03:00
parent 0f62ee20e7
commit b9b4c01cf0
104 changed files with 2254 additions and 2086 deletions
-39
View File
@@ -1,39 +0,0 @@
<?php
/**
* Author: lopiu
* Date: 05.07.2020
* Time: 23:32
*/
namespace Battles\Models;
use Battles\Database\Db;
class EffectsModel
{
protected $DB;
const EFFECT_HIDEUSERINFO = 5; // Обезлик
public function __construct(int $user_id)
{
$this->DB = Db::getInstance()->ofetchAll('SELECT * FROM users_effects WHERE owner_id = ?', $user_id);
}
/**
* Проверка обезличен ли персонаж.
* @return int date() до конца эффекта или 0.
*/
public function getHideUserInfoStatus(): int
{
if ($this->DB) {
$i = 0;
while ($i < count($this->DB)) {
if ($this->DB[$i]->type == self::EFFECT_HIDEUSERINFO) {
return $this->DB[$i]->remaining_time;
}
$i++;
}
}
return 0;
}
}
+135
View File
@@ -0,0 +1,135 @@
<?php
# Date: 23.02.2022 (2:47)
namespace Battles\Models;
use Battles\Database\Db;
class Inventory
{
public static function getWeight(int $user_id): int
{
return Db::getInstance()->fetchColumn('
select
sum(weight)
from
inventory
where
owner_id = ?
and on_sale = 0
', $user_id);
}
public static function getBonuses(int $user_id)
{
return Db::getInstance()->ofetch("
select
sum(add_strength) as item_strength,
sum(add_dexterity) as item_dexterity,
sum(add_intuition) as item_intuition,
sum(add_endurance) as item_endurance,
sum(add_intelligence) as item_intelligence,
sum(add_wisdom) as item_wisdom,
sum(add_accuracy) as item_accuracy,
sum(add_evasion) as item_evasion,
sum(add_criticals) as item_criticals,
sum(add_min_physical_damage) as item_min_physical_damage,
sum(add_max_physical_damage) as item_max_physical_damage
from
inventory
where
dressed_slot != 0 and
owner_id = ?
", $user_id);
}
public static function getDressed(int $item_type, int $user_id): object
{
return Db::getInstance()->ofetchAll('
SELECT
dressed_slot
FROM
inventory
WHERE
dressed_slot != 0
AND item_type = ?
AND owner_id = ?
', [$item_type, $user_id]);
}
public static function countDressed(int $item_type, int $user_id): object
{
return Db::getInstance()->ofetchAll('
SELECT
count(dressed_slot)
FROM
inventory
WHERE
dressed_slot != 0
AND item_type = ?
AND owner_id = ?
', [$item_type, $user_id]);
}
public static function undressOne(int $slot, int $user_id)
{
Db::getInstance()->execute('
UPDATE
inventory
SET
dressed_slot = 0
WHERE
dressed_slot = ?
AND owner_id = ?
', [$slot, $user_id]);
}
public static function dressOne(int $item_id, int $user_id)
{
Db::getInstance()->execute('
UPDATE
inventory
SET
dressed_slot = item_type
WHERE
item_id = ?
AND owner_id = ?
', [$item_id, $user_id]);
}
public static function dressOneToSlot(int $item_id, int $slot)
{
Db::getInstance()->execute('UPDATE inventory SET dressed_slot = ? WHERE item_id = ?', [$slot, $item_id]);
}
public static function destroyItem(int $item_id, int $user_id)
{
Db::getInstance()->execute('
delete
from
inventory
where
dressed_slot = 0
and owner_id = ?
and item_id = ?
', [$user_id, $item_id]);
}
public static function changeRings(int $item_id)
{
Db::getInstance()->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = 11');
Db::getInstance()->execute('UPDATE inventory SET dressed_slot = 11 WHERE item_id = ?', $item_id);
}
public static function isWeared(int $item_id): bool
{
return Db::getInstance()->fetchColumn('
select
count(*)
from
inventory
where
item_id = ?
and dressed_slot > 0
', $item_id) > 0;
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php
/**
* Author: lopiu
* Date: 04.07.2020
* Time: 13:17
*/
namespace Battles\Models;
use Battles\Database\Db;
use Battles\User;
class Presents
{
public function getAll($user_id = null)
{
if (is_null($user_id)) {
$user_id = User::getInstance()->getId();
}
return Db::getInstance()->execute('SELECT sender_id, image FROM `users_presents` WHERE owner_id = ?', $user_id);
}
}
-26
View File
@@ -1,26 +0,0 @@
<?php
/**
* Author: lopiu
* Date: 04.07.2020
* Time: 13:17
*/
namespace Battles\Models;
use Battles\Database\Db;
class PresentsModel
{
protected $DB;
public function __construct(int $user_id)
{
if (!$this->DB) {
$this->DB = Db::getInstance()->execute('SELECT sender_id, image FROM `users_presents` WHERE owner_id = ?', $user_id);
}
}
public function getAllPresents()
{
return $this->DB;
}
}
+35
View File
@@ -0,0 +1,35 @@
<?php
# Date: 23.02.2022 (3:02)
namespace Battles\Models\User;
use Battles\Database\Db;
class Effects
{
public static function getStatMods(int $user_id)
{
return Db::getInstance()->ofetch("
select
sum(mod_strength) as effect_strength,
sum(mod_dexterity) as effect_dexterity,
sum(mod_intuition) as effect_intuition,
sum(mod_endurance) as effect_endurance,
sum(mod_intelligence) as effect_intelligence,
sum(mod_wisdom) as effect_wisdom
from
users_effects
where
owner_id = ?
", $user_id);
}
public static function getAll(int $user_id): object
{
return Db::getInstance()->ofetchAll('SELECT * FROM users_effects WHERE owner_id = ?', $user_id);
}
public static function count(int $user_id, int $type)
{
return Db::getInstance()->fetchColumn('select count(*) from users_effects where type = ? and owner_id = ?', [$type, $user_id]);
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
# Date: 23.02.2022 (2:32)
namespace Battles\Models\User;
use Battles\Database\Db;
class Stats
{
/**
* @param int|string $user
*/
public static function getAll($user)
{
$col = ctype_digit(strval($user)) ? 'id' : 'login';
return Db::getInstance()->ofetch('select id, strength, dexterity, intuition, endurance, intelligence, wisdom, health, mana, free_stat_points, level from users where ' . $col . ' = ?', $user);
}
public static function addOne(string $stat, int $user_id)
{
Db::getInstance()->execute("
UPDATE
users
SET
$stat = $stat + 1,
free_stat_points = free_stat_points - 1
WHERE
id = ?
", $user_id);
}
public static function save(array $vars)
{
Db::getInstance()->execute('
update
users
set
strength = ?,
dexterity = ?,
intuition = ?,
endurance = ?,
intelligence = ?,
wisdom = ?,
health = ?,
mana = ?,
free_stat_points = ?,
level = ?
where
id = ?
', $vars);
}
}