diff --git a/db/scitemcustom.php b/db/scitemcustom.php index 4e3d04c..49302a1 100644 --- a/db/scitemcustom.php +++ b/db/scitemcustom.php @@ -59,7 +59,6 @@ function scitemcustom_bootstrap(): void cl_scitemcustom_obj_id INT(10) UNSIGNED NOT NULL, cl_scitemcustom_created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (cl_scitemcustom_id), - UNIQUE KEY uq_scitemcustom_owner_obj (cl_scitemcustom_owner_auth_id, cl_scitemcustom_obj_id), KEY idx_scitemcustom_owner (cl_scitemcustom_owner_auth_id), KEY idx_scitemcustom_obj (cl_scitemcustom_obj_id), CONSTRAINT fk_scitemcustom_owner_auth FOREIGN KEY (cl_scitemcustom_owner_auth_id) @@ -91,11 +90,8 @@ function scitemcustom_bootstrap(): void ); } - if (!scitemcustom_index_exists($db, 'tbl_scitemcustom', 'uq_scitemcustom_owner_obj')) { - $db->exec( - 'ALTER TABLE tbl_scitemcustom - ADD UNIQUE KEY uq_scitemcustom_owner_obj (cl_scitemcustom_owner_auth_id, cl_scitemcustom_obj_id)' - ); + if (scitemcustom_index_exists($db, 'tbl_scitemcustom', 'uq_scitemcustom_owner_obj')) { + $db->exec('ALTER TABLE tbl_scitemcustom DROP INDEX uq_scitemcustom_owner_obj'); } if (!scitemcustom_foreign_key_exists($db, 'tbl_scitemcustom', 'fk_scitemcustom_owner_auth')) { diff --git a/db/scmanutention.php b/db/scmanutention.php index 3b33803..e0ce0a9 100644 --- a/db/scmanutention.php +++ b/db/scmanutention.php @@ -760,3 +760,37 @@ function scmanutention_fetch_custom_stats_map(PDO $db, array $item_rows): array return $stats_map; } + +function scmanutention_fetch_custom_stats_preview_map(PDO $db, array $custom_ids): array +{ + $custom_ids = array_values(array_unique(array_map('intval', array_filter($custom_ids)))); + if ($custom_ids === []) { + return []; + } + + $placeholders = implode(',', array_fill(0, count($custom_ids), '?')); + $stmt = $db->prepare( + "SELECT + cs.cl_scitemcustomstat_itemcustom_id, + st.cl_scstatsitem_name, + st.cl_scstatsitem_unit, + cs.cl_scitemcustomstat_sign, + cs.cl_scitemcustomstat_value + FROM tbl_scitemcustomstat cs + INNER JOIN tbl_scstatsitem st ON st.cl_scstatsitem_id = cs.cl_scitemcustomstat_stat_id + WHERE cs.cl_scitemcustomstat_itemcustom_id IN ({$placeholders}) + ORDER BY st.cl_scstatsitem_name ASC, cs.cl_scitemcustomstat_id ASC" + ); + $stmt->execute($custom_ids); + + $stats_map = []; + foreach ($stmt->fetchAll() as $row) { + $itemcustom_id = (int) $row['cl_scitemcustomstat_itemcustom_id']; + if (!isset($stats_map[$itemcustom_id])) { + $stats_map[$itemcustom_id] = []; + } + $stats_map[$itemcustom_id][] = $row; + } + + return $stats_map; +} diff --git a/scitemcustom.php b/scitemcustom.php index 77ac88d..e1f7f79 100644 --- a/scitemcustom.php +++ b/scitemcustom.php @@ -55,6 +55,35 @@ function scitemcustom_escape_like(string $value): string ]); } +function scitemcustom_normalize_rarity(?string $rarity): string +{ + return strtoupper(trim((string) $rarity)); +} + +function scitemcustom_rarity_class(?string $rarity): string +{ + return match (scitemcustom_normalize_rarity($rarity)) { + 'L' => 'rarity-L', + 'E' => 'rarity-E', + 'R' => 'rarity-R', + 'U' => 'rarity-U', + 'C' => 'rarity-C', + default => '', + }; +} + +function scitemcustom_rarity_label(?string $rarity): string +{ + return match (scitemcustom_normalize_rarity($rarity)) { + 'L' => 'Légendaire', + 'E' => 'Épique', + 'R' => 'Rare', + 'U' => 'Peu commun', + 'C' => 'Commun', + default => '', + }; +} + function scitemcustom_search_available_items(PDO $db, int $ownerAuthId, string $query, ?int $limit = null): array { $query = trim($query); @@ -71,14 +100,9 @@ function scitemcustom_search_available_items(PDO $db, int $ownerAuthId, string $ $limitClause = ' LIMIT ' . (int) $limit; } - $sql = "SELECT cl_scobjs_id, cl_scobjs_name, cl_scobjs_uuid, cl_scobjs_type, cl_scobjs_subtype + $sql = "SELECT cl_scobjs_id, cl_scobjs_name, cl_scobjs_uuid, cl_scobjs_type, cl_scobjs_subtype, cl_scobjs_rarity FROM tbl_scobjs - WHERE cl_scobjs_id NOT IN ( - SELECT cl_scitemcustom_obj_id - FROM tbl_scitemcustom - WHERE cl_scitemcustom_owner_auth_id = :owner_auth_id - ) - AND ( + WHERE ( cl_scobjs_name LIKE :contains_name OR cl_scobjs_type LIKE :contains_type OR cl_scobjs_subtype LIKE :contains_subtype @@ -101,7 +125,6 @@ function scitemcustom_search_available_items(PDO $db, int $ownerAuthId, string $ $stmt = $db->prepare($sql); $stmt->execute([ - 'owner_auth_id' => $ownerAuthId, 'contains_name' => $contains, 'contains_type' => $contains, 'contains_subtype' => $contains, @@ -379,12 +402,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET' && (string) ($_GET['ajax'] ?? '') === ' if (mb_strlen($query) >= 3) { $items = array_map(static function (array $row): array { + $rarity = (string) ($row['cl_scobjs_rarity'] ?? ''); + return [ 'id' => (int) $row['cl_scobjs_id'], 'name' => (string) $row['cl_scobjs_name'], 'uuid' => (string) $row['cl_scobjs_uuid'], 'type' => (string) $row['cl_scobjs_type'], 'subtype' => (string) ($row['cl_scobjs_subtype'] ?? ''), + 'rarity' => scitemcustom_normalize_rarity($rarity), + 'rarity_class' => scitemcustom_rarity_class($rarity), + 'rarity_label' => scitemcustom_rarity_label($rarity), ]; }, scitemcustom_search_available_items($db, $current_owner_auth_id, $query)); } @@ -452,6 +480,11 @@ $current_session_user = $_SESSION['user'] ?? ''; --border-glow: rgba(162, 155, 120, 0.25); --danger: #ff4d4d; --success: #00ff88; + --rarity-L: #ff8000; + --rarity-E: #a335ee; + --rarity-R: #0070dd; + --rarity-U: #1eff00; + --rarity-C: #ffffff; } @font-face { @@ -850,6 +883,12 @@ $current_session_user = $_SESSION['user'] ?? ''; font-size: 0.92rem; } + .rarity-L { color: var(--rarity-L); text-shadow: 0 0 12px rgba(255, 128, 0, 0.28); } + .rarity-E { color: var(--rarity-E); text-shadow: 0 0 12px rgba(163, 53, 238, 0.28); } + .rarity-R { color: var(--rarity-R); text-shadow: 0 0 12px rgba(0, 112, 221, 0.28); } + .rarity-U { color: var(--rarity-U); text-shadow: 0 0 12px rgba(30, 255, 0, 0.28); } + .rarity-C { color: var(--rarity-C); } + .item-submeta { color: #96a0b5; font-size: 0.78rem; @@ -1227,7 +1266,8 @@ $current_session_user = $_SESSION['user'] ?? '';