battles/classes/Battles/Models/Inventory.php
lopar b9b4c01cf0 Зимние правки. MVC/
Signed-off-by: lopar <lopar.4ever@gmail.com>
2022-08-09 22:57:43 +03:00

135 lines
3.8 KiB
PHP

<?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;
}
}