# Полный пересид ботов, кланов и всего бот-мира.
# НЕ трогает: твои аккаунты и персонажей, твои кланы (если создашь), купленные тобой холлы.
# Стирает и пересоздаёт: бот-персонажей, бот-кланы, войны, их холлы/замки,
# прогресс/память/слухи ботов, олимпиаду, Семь Печатей, манор.
# Использование: powershell -ExecutionPolicy Bypass -File reset-bots.ps1

$ErrorActionPreference = "Stop"
$Compose = Join-Path $PSScriptRoot "server\docker\docker-compose.yml"

$sql = @"
DELETE FROM characters WHERE account_name='sppbots';
DELETE FROM clan_data WHERE clan_id BETWEEN 300000001 AND 300000999;
DELETE FROM clan_wars WHERE CAST(clan1 AS UNSIGNED) BETWEEN 300000001 AND 300000999 OR CAST(clan2 AS UNSIGNED) BETWEEN 300000001 AND 300000999;
UPDATE clanhall SET ownerId=0, paid=0, paidUntil=0 WHERE ownerId BETWEEN 300000001 AND 300000999;
DELETE FROM items WHERE owner_id BETWEEN 300000001 AND 300000999;
DELETE FROM crests WHERE crest_id BETWEEN 9000 AND 9999;
DELETE FROM olympiad_nobles WHERE charId >= 270001000;
DELETE FROM heroes WHERE charId >= 270001000;
DELETE FROM seven_signs WHERE charId >= 270001000;
DROP TABLE IF EXISTS fake_player_progress;
DROP TABLE IF EXISTS fake_player_memory;
DROP TABLE IF EXISTS fake_player_rumor;
"@

Write-Host "Стираю бот-данные..."
$sql | docker compose -f $Compose exec -T db mariadb -uroot -pl2j l2jmobiusinterlude
if ($LASTEXITCODE -ne 0) { Write-Host "Ошибка SQL — сервер запущен? (docker compose up)" -ForegroundColor Red; exit 1 }

Write-Host "Перезапускаю сервер (логин зальёт свежий сид)..."
docker compose -f $Compose restart login
Start-Sleep -Seconds 8
docker compose -f $Compose restart game

Write-Host "Готово. Гейм-сервер поднимется ~1 мин, боты пересозданы со стартовых уровней." -ForegroundColor Green
