battles/classes/Battles/Models/Inventory.php
Ivor Barhansky 0398425205 Code smell.
2022-12-17 03:03:56 +02:00

120 lines
3.4 KiB
PHP

<?php
# Date: 23.02.2022 (2:47)
namespace Battles\Models;
use Battles\Database\Db;
class Inventory
{
public static function getWeight(int $userId): int
{
return Db::getInstance()->fetchColumn(
'select sum(weight) from inventory where owner_id = ? and on_sale = 0',
$userId
);
}
public static function getBonuses(int $userId)
{
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 = ?",
$userId
);
}
public static function getDressed(int $itemType, int $userId): object
{
return Db::getInstance()->ofetchAll(
'SELECT
dressed_slot
FROM
inventory
WHERE
dressed_slot != 0 AND item_type = ? AND owner_id = ?',
[$itemType, $userId]
);
}
public static function countDressed(int $itemType, int $userId): object
{
return Db::getInstance()->ofetchAll(
'SELECT
count(dressed_slot)
FROM
inventory
WHERE
dressed_slot != 0 AND item_type = ? AND owner_id = ?',
[$itemType, $userId]
);
}
public static function undressOne(int $slot, int $userId)
{
Db::getInstance()->execute(
'UPDATE
inventory
SET
dressed_slot = 0
WHERE
dressed_slot = ? AND owner_id = ?',
[$slot, $userId]
);
}
public static function dressOne(int $itemId, int $userId)
{
Db::getInstance()->execute(
'UPDATE
inventory
SET
dressed_slot = item_type
WHERE
item_id = ? AND owner_id = ?',
[$itemId, $userId]
);
}
public static function dressOneToSlot(int $itemId, int $slot)
{
Db::getInstance()->execute('UPDATE inventory SET dressed_slot = ? WHERE item_id = ?', [$slot, $itemId]);
}
public static function destroyItem(int $itemId, int $userId)
{
Db::getInstance()->execute(
'delete
from
inventory
where
dressed_slot = 0 and owner_id = ? and item_id = ?',
[$userId, $itemId]
);
}
public static function changeRings(int $itemId)
{
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 = ?', $itemId);
}
public static function isWeared(int $itemId): bool
{
return Db::getInstance()->fetchColumn('select count(*) from inventory where item_id = ? and dressed_slot > 0', $itemId) > 0;
}
}