Code smell.
This commit is contained in:
@@ -6,130 +6,114 @@ use Battles\Database\Db;
|
||||
|
||||
class Inventory
|
||||
{
|
||||
public static function getWeight(int $user_id): int
|
||||
public static function getWeight(int $userId): int
|
||||
{
|
||||
return Db::getInstance()->fetchColumn('
|
||||
select
|
||||
sum(weight)
|
||||
from
|
||||
inventory
|
||||
where
|
||||
owner_id = ?
|
||||
and on_sale = 0
|
||||
', $user_id);
|
||||
return Db::getInstance()->fetchColumn(
|
||||
'select sum(weight) from inventory where owner_id = ? and on_sale = 0',
|
||||
$userId
|
||||
);
|
||||
}
|
||||
|
||||
public static function getBonuses(int $user_id)
|
||||
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 = ?
|
||||
", $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 = ?",
|
||||
$userId
|
||||
);
|
||||
}
|
||||
|
||||
public static function getDressed(int $item_type, int $user_id): object
|
||||
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 = ?
|
||||
', [$item_type, $user_id]);
|
||||
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 $item_type, int $user_id): object
|
||||
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 = ?
|
||||
', [$item_type, $user_id]);
|
||||
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 $user_id)
|
||||
public static function undressOne(int $slot, int $userId)
|
||||
{
|
||||
Db::getInstance()->execute('
|
||||
UPDATE
|
||||
inventory
|
||||
SET
|
||||
dressed_slot = 0
|
||||
WHERE
|
||||
dressed_slot = ?
|
||||
AND owner_id = ?
|
||||
', [$slot, $user_id]);
|
||||
Db::getInstance()->execute(
|
||||
'UPDATE
|
||||
inventory
|
||||
SET
|
||||
dressed_slot = 0
|
||||
WHERE
|
||||
dressed_slot = ? AND owner_id = ?',
|
||||
[$slot, $userId]
|
||||
);
|
||||
}
|
||||
|
||||
public static function dressOne(int $item_id, int $user_id)
|
||||
public static function dressOne(int $itemId, int $userId)
|
||||
{
|
||||
Db::getInstance()->execute('
|
||||
UPDATE
|
||||
inventory
|
||||
SET
|
||||
dressed_slot = item_type
|
||||
WHERE
|
||||
item_id = ?
|
||||
AND owner_id = ?
|
||||
', [$item_id, $user_id]);
|
||||
Db::getInstance()->execute(
|
||||
'UPDATE
|
||||
inventory
|
||||
SET
|
||||
dressed_slot = item_type
|
||||
WHERE
|
||||
item_id = ? AND owner_id = ?',
|
||||
[$itemId, $userId]
|
||||
);
|
||||
}
|
||||
|
||||
public static function dressOneToSlot(int $item_id, int $slot)
|
||||
public static function dressOneToSlot(int $itemId, int $slot)
|
||||
{
|
||||
Db::getInstance()->execute('UPDATE inventory SET dressed_slot = ? WHERE item_id = ?', [$slot, $item_id]);
|
||||
Db::getInstance()->execute('UPDATE inventory SET dressed_slot = ? WHERE item_id = ?', [$slot, $itemId]);
|
||||
}
|
||||
|
||||
public static function destroyItem(int $item_id, int $user_id)
|
||||
public static function destroyItem(int $itemId, int $userId)
|
||||
{
|
||||
Db::getInstance()->execute('
|
||||
delete
|
||||
from
|
||||
inventory
|
||||
where
|
||||
dressed_slot = 0
|
||||
and owner_id = ?
|
||||
and item_id = ?
|
||||
', [$user_id, $item_id]);
|
||||
Db::getInstance()->execute(
|
||||
'delete
|
||||
from
|
||||
inventory
|
||||
where
|
||||
dressed_slot = 0 and owner_id = ? and item_id = ?',
|
||||
[$userId, $itemId]
|
||||
);
|
||||
}
|
||||
|
||||
public static function changeRings(int $item_id)
|
||||
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 = ?', $item_id);
|
||||
Db::getInstance()->execute('UPDATE inventory SET dressed_slot = 11 WHERE item_id = ?', $itemId);
|
||||
}
|
||||
|
||||
public static function isWeared(int $item_id): bool
|
||||
public static function isWeared(int $itemId): bool
|
||||
{
|
||||
return Db::getInstance()->fetchColumn('
|
||||
select
|
||||
count(*)
|
||||
from
|
||||
inventory
|
||||
where
|
||||
item_id = ?
|
||||
and dressed_slot > 0
|
||||
', $item_id) > 0;
|
||||
return Db::getInstance()->fetchColumn('select count(*) from inventory where item_id = ? and dressed_slot > 0', $itemId) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user