Practice battles work
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -28,6 +28,7 @@ public class GlobalsImporter
|
||||
JsonElement? mypageIndex = LoadCapture(capturesDir, "mypage-index");
|
||||
JsonElement? deckInfo = LoadCapture(capturesDir, "deck-info");
|
||||
JsonElement? paymentItemList = LoadCapture(capturesDir, "payment-item-list");
|
||||
JsonElement? practiceInfo = LoadCapture(capturesDir, "practice-info");
|
||||
|
||||
int total = 0;
|
||||
|
||||
@@ -69,6 +70,11 @@ public class GlobalsImporter
|
||||
total += await ImportPaymentItems(context, paymentItemList.Value);
|
||||
}
|
||||
|
||||
if (practiceInfo.HasValue)
|
||||
{
|
||||
total += await ImportPracticeOpponents(context, practiceInfo.Value);
|
||||
}
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
Console.WriteLine($"[GlobalsImporter] Done: {total} total rows changed.");
|
||||
return total;
|
||||
@@ -694,6 +700,47 @@ public class GlobalsImporter
|
||||
private static decimal ParseDecimal(string s) =>
|
||||
decimal.TryParse(s, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out var d) ? d : 0m;
|
||||
|
||||
// ---------- Practice Opponents ----------
|
||||
|
||||
/// <summary>
|
||||
/// Capture is the full /practice/info envelope; <c>data</c> is a JSON ARRAY (not an object,
|
||||
/// unlike most endpoints). Each row is one AI opponent row keyed on practice_id. Prod sends
|
||||
/// numeric fields as strings — GetInt tolerates both. Rows present in the DB but missing
|
||||
/// from the capture are LEFT INTACT (consistent with the rest of GlobalsImporter; partial
|
||||
/// captures shouldn't silently delete entries).
|
||||
/// </summary>
|
||||
private async Task<int> ImportPracticeOpponents(SVSimDbContext context, JsonElement practiceData)
|
||||
{
|
||||
if (practiceData.ValueKind != JsonValueKind.Array) return 0;
|
||||
|
||||
var existing = await context.PracticeOpponents.ToDictionaryAsync(e => e.Id);
|
||||
int created = 0, updated = 0;
|
||||
|
||||
foreach (var row in practiceData.EnumerateArray())
|
||||
{
|
||||
int practiceId = GetInt(row, "practice_id");
|
||||
if (practiceId == 0) continue; // malformed row
|
||||
|
||||
var entry = existing.TryGetValue(practiceId, out var ex) ? ex : new PracticeOpponentEntry { Id = practiceId };
|
||||
entry.TextId = GetString(row, "text_id");
|
||||
entry.ClassId = GetInt(row, "class_id");
|
||||
entry.CharaId = GetInt(row, "chara_id");
|
||||
entry.DegreeId = GetInt(row, "degree_id");
|
||||
entry.AiDeckLevel = GetInt(row, "ai_deck_level");
|
||||
entry.AiLogicLevel = GetInt(row, "ai_logic_level");
|
||||
entry.AiMaxLife = GetInt(row, "ai_max_life");
|
||||
entry.Battle3dFieldId = GetString(row, "battle3dfield_id", "1");
|
||||
entry.IsMaintenance = GetBool(row, "is_maintenance");
|
||||
entry.IsCampaignPractice = GetBool(row, "is_campaign_practice");
|
||||
|
||||
if (ex is null) { context.PracticeOpponents.Add(entry); created++; }
|
||||
else updated++;
|
||||
}
|
||||
|
||||
Console.WriteLine($"[GlobalsImporter] PracticeOpponents: +{created}/~{updated}");
|
||||
return created + updated;
|
||||
}
|
||||
|
||||
// ---------- Helpers ----------
|
||||
|
||||
private static void WarnOrphans(string label, int count)
|
||||
|
||||
Reference in New Issue
Block a user