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