feat(lib): YGOLegacy.Bots, netstandard2.1 / C# 9, the game through BotHost

What came from the game now comes through YGOLegacy.Bots.BotHost (Host/BotHost.cs): Log (was UnityEngine.Debug),
Cards (the SQLite connection; was Mono.Data.Sqlite), Files (locale and the expansions' .cdb; was
MDPro3 Language/ResourceManager, GamePaths.PATH_EXPANSIONS), DeckLimits (#ruleset -> caps; was the game's
DeckLimits/Rulesets) and BotConf (bot.conf; was SoloLoader). CharacterRegistry loses its UniTask surface and
keeps Scan/Publish (now public) and LoadFromDisk. No YGOL_STANDALONE branches are left. Internals stay internal,
visible to Assembly-CSharp(-Editor), BotArena and the tests. References the engine release's binding (engine.json
pins v1.4.1). No change to how the bots play.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
donnyandClaude Opus 5.5 committed 2026-10-19 18:19:14 -07:00
1 parent 6dbc9e78d8
commit 0818987cea
20 files changed
+305 -117

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
* text=auto eol=lf
*.cdb binary
*.zip binary
*.dll binary
+6
View File
@@ -0,0 +1,6 @@
# build output
bin/
obj/
/out/
# the engine release build/fetch-engine.sh fetches
/.engine/
+17
View File
@@ -0,0 +1,17 @@
<Project>
<!-- Shared by every project. The engine pin (engine.json) and where its release was fetched to (.engine/,
build/fetch-engine.sh). -->
<PropertyGroup>
<RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot>
<EngineDir Condition="'$(EngineDir)' == ''">$(RepoRoot).engine/</EngineDir>
<EnginePin>$([System.IO.File]::ReadAllText('$(RepoRoot)engine.json'))</EnginePin>
<EngineVersion>$([System.Text.RegularExpressions.Regex]::Match($(EnginePin), '"version"\s*:\s*"([^"]+)"').Groups[1].Value)</EngineVersion>
<BotsVersion Condition="'$(BotsVersion)' == ''">local</BotsVersion>
<Deterministic>true</Deterministic>
<Nullable>disable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>
</Project>
+7
View File
@@ -0,0 +1,7 @@
{
"version": "v1.4.1",
"exports": 856,
"protocol": 9,
"capabilities": 10239,
"binding": "v1.4.1"
}
+3 -3
View File
@@ -9,10 +9,10 @@ namespace YGOLegacy.Bot
// ------------------------------------------------------------------------
// The Bot Arena report model + the pure helpers that build it. This file is
// deliberately Unity-free (no UnityEngine, no UniTask, no MDPro3): it is
// compiled BOTH by the game (BotArena.cs, the in-editor arena of TICKET-030)
// and by Tools/BotArena (the standalone parallel arena of TICKET-035), so
// used BOTH by the game (BotArena.cs, the in-editor arena of TICKET-030)
// and by src/BotArena (the standalone parallel arena of TICKET-035), so
// the two produce byte-compatible JSON. Keep it that way — anything that
// needs Unity belongs in BotArena.cs.
// needs Unity belongs in the game's BotArena.cs.
// ------------------------------------------------------------------------
/// <summary>
+3 -3
View File
@@ -47,8 +47,8 @@ namespace YGOLegacy.Bot
/// seat was told, so a brain can see the human's hand without a new parser
/// and without any server change.
///
/// Nothing here touches UnityEngine, so it compiles into
/// <c>Tools/BotArena</c> as well as the game.
/// Nothing here touches UnityEngine, so the game and BotArena run the
/// same code.
///
/// Cost when nobody listens: <see cref="Active"/> is false, so both taps
/// are one static bool read per packet and allocate nothing. The bus only
@@ -259,7 +259,7 @@ namespace YGOLegacy.Bot
internal static void Warn(string message)
{
try { UnityEngine.Debug.LogWarning(LogPrefix + message); } catch (Exception) { }
try { YGOLegacy.Bots.BotHost.Log.Warning(LogPrefix + message); } catch (Exception) { }
}
// ==================================================================
+2 -2
View File
@@ -20,8 +20,8 @@ namespace YGOLegacy.Bot
// seat(s) that may see it (blanking what they may not), and feed prompt
// answers back with set_responseb.
//
// Deliberately Unity-free (Assembly-CSharp compiles it, Tools/BotArena links
// it) and deliberately transport-free: a seat is an ILoopbackSeat, so the
// Deliberately Unity-free (the game and BotArena run this library) and
// deliberately transport-free: a seat is an ILoopbackSeat, so the
// standalone arena can plug two WindBot GameClients in with no socket at all
// (LoopbackBotSeat). Nothing in the game uses this yet.
//
+1 -1
View File
@@ -15,7 +15,7 @@ namespace YGOLegacy.Bot
// currently in progress. NOTHING implements it inside the
// game: ocgcore cannot clone a live duel, so the only
// implementation is the arena's perfect-information
// ReplayOracle (Tools/BotArena/ReplayOracle.cs).
// ReplayOracle (src/BotArena/ReplayOracle.cs).
//
// With no oracle installed — every in-game duel today — SmartExecutor's
// planner declines and the executor walk runs exactly once, unchanged.
+7 -7
View File
@@ -35,7 +35,7 @@ namespace YGOLegacy.Bot
/// broken file -> empty rules -> DefaultExecutor-grade play, never a crash.
///
/// Threading: everything here runs on the WindBot thread. No UnityEngine
/// objects are touched; logging is UnityEngine.Debug.Log only, prefixed
/// objects are touched; logging is BotHost.Log only, prefixed
/// <c>[YGOL bot]</c>, and gated by <see cref="Verbose"/> (or knob
/// <c>verbose: 1</c>) except for the one line at construction.
///
@@ -279,7 +279,7 @@ namespace YGOLegacy.Bot
journalDuel = JournalDuel;
if (journalFile != null) JournalOpen();
UnityEngine.Debug.Log(LogPrefix + "SmartExecutor for deck '" + (DeckPath ?? "?") + "'"
YGOLegacy.Bots.BotHost.Log.Info(LogPrefix + "SmartExecutor for deck '" + (DeckPath ?? "?") + "'"
+ (character != null ? " as character '" + character.id + "'" : " (no owning character)")
+ " difficulty=" + Difficulty + " aggression=" + Aggression + " tradeTolerance=" + TradeTolerance
+ " seed=" + Seed + " insight=" + YGOLegacy.Bot.Insight.LevelName(Insight.Level) + " rules=" + (Rules.IsEmpty ? "none" : Rules.source + " (" + Rules.combos.Count + " combos, " + Rules.effects.Count + " effect models)")
@@ -2325,7 +2325,7 @@ namespace YGOLegacy.Bot
private void Log(string message)
{
if (!Chatty) return;
UnityEngine.Debug.Log(LogPrefix + (CharacterId ?? "smart") + " T" + Duel.Turn + " " + Duel.Phase + ": " + message);
YGOLegacy.Bots.BotHost.Log.Info(LogPrefix + (CharacterId ?? "smart") + " T" + Duel.Turn + " " + Duel.Phase + ": " + message);
}
private void LogRanked(string head, List<Candidate> ranked)
@@ -2443,7 +2443,7 @@ namespace YGOLegacy.Bot
}
catch (Exception e)
{
UnityEngine.Debug.LogWarning(LogPrefix + "journal: cannot create " + journalFile + ": " + e.Message);
YGOLegacy.Bots.BotHost.Log.Warning(LogPrefix + "journal: cannot create " + journalFile + ": " + e.Message);
}
GameBehavior.YGOL_DuelResult += OnJournalDuelResult;
// The fields are not initialised until the duel starts: the start
@@ -2497,7 +2497,7 @@ namespace YGOLegacy.Bot
line["offered"] = new List<int>(journalOffered);
JournalWrite(line);
}
catch (Exception e) { UnityEngine.Debug.LogWarning(LogPrefix + "journal duelEnd: " + e.Message); }
catch (Exception e) { YGOLegacy.Bots.BotHost.Log.Warning(LogPrefix + "journal duelEnd: " + e.Message); }
}
private Dictionary<string, object> JournalLine(string kind)
@@ -2525,11 +2525,11 @@ namespace YGOLegacy.Bot
{
string text;
try { text = JsonConvert.SerializeObject(line, Formatting.None); }
catch (Exception e) { UnityEngine.Debug.LogWarning(LogPrefix + "journal serialize: " + e.Message); return; }
catch (Exception e) { YGOLegacy.Bots.BotHost.Log.Warning(LogPrefix + "journal serialize: " + e.Message); return; }
lock (journalLock)
{
try { File.AppendAllText(journalFile, text + "\n"); }
catch (Exception e) { UnityEngine.Debug.LogWarning(LogPrefix + "journal write: " + e.Message); }
catch (Exception e) { YGOLegacy.Bots.BotHost.Log.Warning(LogPrefix + "journal write: " + e.Message); }
}
}
+1 -1
View File
@@ -203,7 +203,7 @@ namespace YGOLegacy.Characters
// Empty = master only.
public string[] rulesets = System.Array.Empty<string>();
// Equals Ruleset.MasterId; BotArena links this file without Ruleset.cs.
// Equals the game's Ruleset.MasterId; rulesets stay in the game.
public const string DefaultRuleset = "master";
public bool Plays(string rulesetId)
@@ -2,10 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using UnityEngine;
#if !YGOL_STANDALONE
using Cysharp.Threading.Tasks;
#endif
using YGOLegacy.Bots;
namespace YGOLegacy.Characters
{
@@ -16,15 +13,12 @@ namespace YGOLegacy.Characters
/// <c>[YGOL characters] &lt;path&gt;: &lt;error&gt;</c> and skipped — a
/// broken character never breaks boot.
///
/// The scan runs on the thread pool; the results are published on the
/// main thread. Before Init completes (or if it was never called) the
/// registry is simply empty, and BotRoster falls back to its built-in
/// Dovphin, so callers need not await Loaded unless they need everyone.
///
/// Outside Unity (Tools/BotArena, compiled with YGOL_STANDALONE) the
/// UniTask surface is compiled out and <see cref="LoadFromDisk"/> — the
/// same scan + publish, synchronous — is the entry point. Both paths share
/// Scan/Publish, so the two never drift.
/// Two ways in, sharing Scan/Publish so they never drift: the game runs
/// <see cref="Scan"/> on the thread pool and <see cref="Publish"/> on the
/// main thread (its own UniTask Init/Loaded); a host without a player loop
/// (BotArena, tests) calls <see cref="LoadFromDisk"/>, the same two,
/// synchronous. Before the first Publish the registry is simply empty, and
/// BotRoster falls back to its built-in Dovphin.
/// </summary>
public static class CharacterRegistry
{
@@ -36,12 +30,6 @@ namespace YGOLegacy.Characters
new(StringComparer.OrdinalIgnoreCase);
private static readonly Dictionary<string, Character> byDeck =
new(StringComparer.OrdinalIgnoreCase);
#if !YGOL_STANDALONE
private static UniTaskCompletionSource loadedSource;
/// Completes when the first Init() has published its results.
public static UniTask Loaded => (loadedSource ??= new UniTaskCompletionSource()).Task;
#endif
public static bool IsLoaded { get; private set; }
public static IReadOnlyList<Character> All() => all;
@@ -95,36 +83,10 @@ namespace YGOLegacy.Characters
return key.Length > 0 && byDeck.TryGetValue(key, out var c) ? c : null;
}
#if !YGOL_STANDALONE
/// <summary>
/// Scan the characters folder off the main thread and publish. Safe to
/// call again (a rescan replaces the tables); the first call is what
/// Program.Initialize awaits via Loaded.
/// </summary>
public static async UniTask Init()
{
loadedSource ??= new UniTaskCompletionSource();
List<Character> found;
List<string> problems;
try
{
(found, problems) = await UniTask.RunOnThreadPool(() => Scan(Root));
}
catch (Exception e)
{
found = new List<Character>();
problems = new List<string> { Root + ": " + e.Message };
}
await UniTask.SwitchToMainThread();
Publish(found, problems);
loadedSource.TrySetResult();
}
#endif
/// <summary>
/// Synchronous scan + publish on the calling thread, for hosts without
/// a player loop (Tools/BotArena). `charactersRoot` defaults to
/// a player loop (BotArena, tests). `charactersRoot` defaults to
/// <see cref="Root"/> relative to the current directory; pass an
/// absolute path to read another game root. Safe to call again.
/// </summary>
@@ -178,24 +140,28 @@ namespace YGOLegacy.Characters
var root = string.IsNullOrEmpty(charactersRoot) ? Root : charactersRoot;
LoadedRoot = root;
lock (groupKnobs) groupKnobs.Clear();
List<Character> found;
List<string> problems;
try
Publish(Scan(root));
}
/// What one scan of a characters folder found, for <see cref="Publish"/>.
public sealed class ScanResult
{
public readonly List<Character> found;
public readonly List<string> problems;
public ScanResult(List<Character> found, List<string> problems)
{
(found, problems) = Scan(root);
this.found = found;
this.problems = problems;
}
catch (Exception e)
{
found = new List<Character>();
problems = new List<string> { root + ": " + e.Message };
}
Publish(found, problems);
}
/// Replace the tables with a scan's results and log its problems.
/// Main thread in Unity (readers are main-thread callers).
private static void Publish(List<Character> found, List<string> problems)
public static void Publish(ScanResult scan)
{
var found = scan.found;
var problems = scan.problems;
all.Clear();
byId.Clear();
byDeck.Clear();
@@ -224,13 +190,27 @@ namespace YGOLegacy.Characters
}
foreach (var problem in problems)
Debug.LogError("[YGOL characters] " + problem);
BotHost.Log.Error("[YGOL characters] " + problem);
IsLoaded = true;
}
/// Worker-thread part: pure file IO + JSON, no Unity API.
private static (List<Character>, List<string>) Scan(string root)
/// Worker-thread part: pure file IO + JSON, no Unity API. Never throws:
/// a folder that cannot be read is one problem line.
public static ScanResult Scan(string root)
{
try
{
var (found, problems) = ScanFolder(root);
return new ScanResult(found, problems);
}
catch (Exception e)
{
return new ScanResult(new List<Character>(), new List<string> { root + ": " + e.Message });
}
}
private static (List<Character>, List<string>) ScanFolder(string root)
{
var found = new List<Character>();
var problems = new List<string>();
+120
View File
@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Data;
namespace YGOLegacy.Bots
{
/// <summary>
/// What the bots need from the program that runs them: the game (solo duels, the in-editor arena) or the
/// headless BotArena. The host sets these once at start-up, before the first bot is built or the character
/// registry is loaded. Every path the bots read is relative to the current directory, which is the game root.
/// </summary>
public static class BotHost
{
/// Where the bots' log lines go. Default: the console.
public static IBotLog Log { get; set; } = new ConsoleBotLog();
/// Opens the card databases (cards.cdb and the expansions' .cdb). No default: the host must set it.
public static ICardDatabase Cards { get; set; }
/// The active locale and the .cdb files the host extracted from Expansions/*.ypk. Default: en-US, none.
public static IGameFiles Files { get; set; } = new DefaultGameFiles();
/// The deck size caps of a ruleset. Default: 60 / 99 / 15 for every ruleset.
public static IDeckLimits DeckLimits { get; set; } = new DefaultDeckLimits();
/// The active locale's bot.conf. Default: empty (BotRoster then uses its built-in Dovphin command).
public static IBotConf BotConf { get; set; } = new EmptyBotConf();
internal static ICardDatabase RequireCards()
=> Cards ?? throw new InvalidOperationException("YGOLegacy.Bots: BotHost.Cards is not set; the host must set it before the card databases load");
}
/// The bots' log. The game routes it to UnityEngine.Debug; the arena to the worker's log.
public interface IBotLog
{
void Info(string message);
void Warning(string message);
void Error(string message);
}
/// The card databases are SQLite files. The game opens them with Mono.Data.Sqlite, the arena with
/// Microsoft.Data.Sqlite (read-only).
public interface ICardDatabase
{
/// A connection to the .cdb at `path`, not yet opened.
IDbConnection Connect(string path);
}
public interface IGameFiles
{
/// The active locale: Data/locales/&lt;Locale&gt;/ holds cards.cdb and bot.conf.
string Locale { get; }
/// The .cdb files inside Expansions/*.ypk, extracted to real files (SQLite needs a file), in load order.
IReadOnlyList<string> ExpansionCardDatabases();
}
/// The deck size caps WindBot checks a bot's deck file against.
public interface IDeckLimits
{
/// `rulesetId` is the deck file's `#ruleset` line, or null when it has none.
DeckCaps For(string rulesetId);
}
public readonly struct DeckCaps
{
public readonly int MainMax;
public readonly int ExtraMax;
public readonly int SideMax;
public DeckCaps(int mainMax, int extraMax, int sideMax)
{
MainMax = mainMax;
ExtraMax = extraMax;
SideMax = sideMax;
}
}
/// The bot list in Data/locales/&lt;locale&gt;/bot.conf.
public interface IBotConf
{
IReadOnlyList<BotConfEntry> Entries();
/// Read bot.conf again (the locale changed).
void Reload();
}
/// One `!name` block of bot.conf: the name, the WindBot command line, the description and the flags.
public class BotConfEntry
{
public string name;
public string command;
public string desc;
public string[] flags;
}
internal sealed class ConsoleBotLog : IBotLog
{
public void Info(string message) => Console.Error.WriteLine(message);
public void Warning(string message) => Console.Error.WriteLine("[warn] " + message);
public void Error(string message) => Console.Error.WriteLine("[error] " + message);
}
internal sealed class DefaultGameFiles : IGameFiles
{
public string Locale => "en-US";
public IReadOnlyList<string> ExpansionCardDatabases() => Array.Empty<string>();
}
internal sealed class DefaultDeckLimits : IDeckLimits
{
public DeckCaps For(string rulesetId) => new DeckCaps(60, 99, 15);
}
internal sealed class EmptyBotConf : IBotConf
{
public IReadOnlyList<BotConfEntry> Entries() => Array.Empty<BotConfEntry>();
public void Reload() { }
}
}
@@ -0,0 +1,8 @@
using System.Runtime.CompilerServices;
// The code was one assembly with the game (Assembly-CSharp) and the arena, which call some of WindBot's internal
// members (WindBot.Program.YGOL_Main, Program.Rand, ...). Kept internal; these assemblies may use them.
[assembly: InternalsVisibleTo("Assembly-CSharp")]
[assembly: InternalsVisibleTo("Assembly-CSharp-Editor")]
[assembly: InternalsVisibleTo("BotArena")]
[assembly: InternalsVisibleTo("YGOLegacy.Bots.Tests")]
+4 -16
View File
@@ -1,8 +1,7 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using MDPro3.Utility;
using YGOLegacy.Bots;
using YGOLegacy.Characters;
using YGOLegacy.Core;
namespace YGOLegacy.Services
{
@@ -56,21 +55,10 @@ namespace YGOLegacy.Services
private const string UseYourDeckFlag = "SELECT_DECKFILE";
private const string DovphinFallbackCommand = "Name=Dovphin Deck=Lucky";
#if !YGOL_STANDALONE
public static void Reload() => YGOLegacy.Core.Bot.SoloLoader.Reload();
// The host reads the locale's bot.conf (the game: SoloLoader; BotArena: Setup.ReadBots).
public static void Reload() => BotHost.BotConf.Reload();
private static IReadOnlyList<YGOLegacy.Core.Bot.SoloLoader.BotInfo> Conf()
{
if (!YGOLegacy.Core.Bot.SoloLoader.IsReady)
YGOLegacy.Core.Bot.SoloLoader.Initialize();
return YGOLegacy.Core.Bot.SoloLoader.Catalog;
}
#else
// Tools/BotArena parses the locale's bot.conf into this shim (Setup.ReadBots).
public static void Reload() { }
private static IReadOnlyList<MDPro3.Servant.SoloSelector.BotInfo> Conf() => MDPro3.Servant.SoloSelector.bots;
#endif
private static IReadOnlyList<BotConfEntry> Conf() => BotHost.BotConf.Entries();
/// The Name= token in a bot.conf command line, quoted or bare.
private static readonly Regex NameToken =
+9 -3
View File
@@ -38,6 +38,12 @@ namespace WindBot.Game
Cards.Add(card);
}
// [YGOL] TICKET-263: the deck file's "#ruleset <id>" line (the game's DeckLimits.RulesetTag).
private const string RulesetTag = "#ruleset";
private static string RulesetOf(string line)
=> line != null && line.StartsWith(RulesetTag, StringComparison.Ordinal) ? line.Substring(RulesetTag.Length).Trim() : null;
public static Deck Load(string name)
{
StreamReader reader = null;
@@ -56,7 +62,7 @@ namespace WindBot.Game
continue;
line = line.Trim();
ruleset = YGOLegacy.Services.DeckLimits.RulesetOf(line) ?? ruleset; // [YGOL] TICKET-263
ruleset = RulesetOf(line) ?? ruleset; // [YGOL] TICKET-263
if (line.StartsWith("#"))
continue;
if (line.Equals("!side"))
@@ -76,10 +82,10 @@ namespace WindBot.Game
// [YGOL] TICKET-012/263: bot-deck file gate follows the deck's
// Ruleset, so bots load the same decks the editor saves.
var limits = YGOLegacy.Services.DeckLimits.For(ruleset);
var limits = YGOLegacy.Bots.BotHost.DeckLimits.For(ruleset);
if (deck.Cards.Count > limits.MainMax)
return null;
if (deck.ExtraCards.Count > limits.ExtraLimit())
if (deck.ExtraCards.Count > limits.ExtraMax)
return null;
if (deck.SideCards.Count > limits.SideMax)
return null;
+2 -2
View File
@@ -7,7 +7,7 @@ namespace WindBot
public static void WriteLine(string message)
{
Console.WriteLine("[" + DateTime.Now.ToString("yy-MM-dd HH:mm:ss") + "] " + message);
UnityEngine.Debug.Log("[WindBot] " + message); // [YGOL] Console.WriteLine is invisible in Unity
YGOLegacy.Bots.BotHost.Log.Info("[WindBot] " + message); // [YGOL] Console.WriteLine is invisible in Unity; the host routes the log
}
public static void DebugWriteLine(string message)
{
@@ -21,7 +21,7 @@ namespace WindBot
Console.ForegroundColor = ConsoleColor.White;
Console.Error.WriteLine("[" + DateTime.Now.ToString("yy-MM-dd HH:mm:ss") + "] " + message);
Console.ResetColor();
UnityEngine.Debug.LogWarning("[WindBot] " + message); // [YGOL]
YGOLegacy.Bots.BotHost.Log.Warning("[WindBot] " + message); // [YGOL]
}
}
}
+4 -5
View File
@@ -6,8 +6,7 @@ using WindBot.Game;
using WindBot.Game.AI;
using YGOSharp.OCGWrapper;
using System.Collections.Specialized;
using MDPro3.IO;
using YGOLegacy.Core;
using YGOLegacy.Bots;
namespace WindBot
{
@@ -84,7 +83,7 @@ namespace WindBot
//if (!File.Exists(absolutePath))
// // In case windbot is placed in a folder under ygopro2 folder
// absolutePath = Path.GetFullPath("../cdb/" + databasePath);
absolutePath = Path.GetFullPath("Data/locales/" + MDPro3.Utility.Language.GetConfig() + "/" + databasePath);
absolutePath = Path.GetFullPath("Data/locales/" + BotHost.Files.Locale + "/" + databasePath); // [YGOL]
if (!File.Exists(absolutePath))
{
Logger.WriteErrorLine("Can't find cards database file.");
@@ -94,10 +93,10 @@ namespace WindBot
System.Environment.Exit(1);
}
var paths = new System.Collections.Generic.List<string> { absolutePath };
var zipCdbs = ResourceManager.GetAllCdbInZipPaths();
var zipCdbs = BotHost.Files.ExpansionCardDatabases(); // [YGOL] the .cdb inside Expansions/*.ypk
if (zipCdbs != null)
paths.AddRange(zipCdbs);
foreach (var cdb in Directory.GetFiles(GamePaths.PATH_EXPANSIONS, "*.cdb"))
foreach (var cdb in Directory.GetFiles("Expansions/", "*.cdb"))
paths.Add(cdb);
NamedCardsManager.InitForMulti(paths);
}
+56
View File
@@ -0,0 +1,56 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- The bots: WindBot, the YGOSharp parts it uses, the SmartExecutor brain, the in-process duel host, the
character registry and the roster. What Unity compiles: .NET Standard 2.1, C# 9, no Unity reference.
What the bots need from the game comes in through BotHost (Host/BotHost.cs). -->
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>9</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>YGOLegacy.Bots</AssemblyName>
<RootNamespace>YGOLegacy.Bots</RootNamespace>
<DebugType>portable</DebugType>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<InformationalVersion>$(BotsVersion)</InformationalVersion>
<!-- Upstream WindBot is noisy; keep the build output readable. -->
<NoWarn>$(NoWarn);CS0108;CS0114;CS0162;CS0164;CS0168;CS0169;CS0219;CS0414;CS0618;CS0649;CS0659;CS0661;CS1522;CS1570;CS1572;CS1573;CS1587;CS1591;CS8981</NoWarn>
</PropertyGroup>
<ItemGroup>
<!-- Compile-time only: the game has Unity's com.unity.nuget.newtonsoft-json 3.2.1 (13.0.2), the arena its own. -->
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<!-- The engine release's C# binding (EngineApi, MessageScan, the wire protocol). Never shipped with this
library: the game and the arena have their own copy of the same release. -->
<Reference Include="YGOLegacy.Engine">
<HintPath>$(EngineDir)YGOLegacy.Engine.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
<Target Name="GenerateBotsBuild" BeforeTargets="CoreCompile">
<PropertyGroup>
<BotsBuildFile>$(IntermediateOutputPath)BotsBuild.cs</BotsBuildFile>
</PropertyGroup>
<ItemGroup>
<BotsBuildLine Include="namespace YGOLegacy.Bots" />
<BotsBuildLine Include="{" />
<BotsBuildLine Include=" /// This library's release and the engine release it was built and tested against (bots.json)." />
<BotsBuildLine Include=" public static class BotsBuild" />
<BotsBuildLine Include=" {" />
<BotsBuildLine Include=" public const string Version = &quot;$(BotsVersion)&quot;%3B" />
<BotsBuildLine Include=" public const string Engine = &quot;$(EngineVersion)&quot;%3B" />
<BotsBuildLine Include=" }" />
<BotsBuildLine Include="}" />
</ItemGroup>
<WriteLinesToFile File="$(BotsBuildFile)" Lines="@(BotsBuildLine)" Overwrite="true" WriteOnlyWhenDifferent="true" />
<ItemGroup>
<Compile Include="$(BotsBuildFile)" />
<FileWrites Include="$(BotsBuildFile)" />
</ItemGroup>
</Target>
</Project>
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Data;
using Mono.Data.Sqlite;
using YGOLegacy.Bots; // [YGOL] the host opens the SQLite file (Mono.Data.Sqlite in Unity)
namespace YGOSharp.OCGWrapper
{
@@ -12,12 +12,13 @@ namespace YGOSharp.OCGWrapper
{
_cards = new Dictionary<int, Card>();
using (SqliteConnection connection = new SqliteConnection("Data Source=" + databaseFullPath))
using (IDbConnection connection = BotHost.RequireCards().Connect(databaseFullPath))
{
connection.Open();
using (IDbCommand command = new SqliteCommand("SELECT id, ot, alias, setcode, type, level, race, attribute, atk, def FROM datas", connection))
using (IDbCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT id, ot, alias, setcode, type, level, race, attribute, atk, def FROM datas";
using (IDataReader reader = command.ExecuteReader())
{
while (reader.Read())
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Data;
using Mono.Data.Sqlite;
using YGOLegacy.Bots; // [YGOL] the host opens the SQLite file (Mono.Data.Sqlite in Unity)
using System;
using System.IO;
@@ -21,15 +21,13 @@ namespace YGOSharp.OCGWrapper
_cards = new Dictionary<int, NamedCard>();
using (SqliteConnection connection = new SqliteConnection("Data Source=" + databaseFullPath))
using (IDbConnection connection = BotHost.RequireCards().Connect(databaseFullPath))
{
connection.Open();
using (IDbCommand command = new SqliteCommand(
"SELECT datas.id, ot, alias, setcode, type, level, race, attribute, atk, def, texts.name, texts.desc"
+ " FROM datas INNER JOIN texts ON datas.id = texts.id",
connection))
using (IDbCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT datas.id, ot, alias, setcode, type, level, race, attribute, atk, def, texts.name, texts.desc" + " FROM datas INNER JOIN texts ON datas.id = texts.id";
using (IDataReader reader = command.ExecuteReader())
{
while (reader.Read())
@@ -57,15 +55,13 @@ namespace YGOSharp.OCGWrapper
if (!File.Exists(databaseFullPath))
continue;
using (SqliteConnection connection = new SqliteConnection("Data Source=" + databaseFullPath))
using (IDbConnection connection = BotHost.RequireCards().Connect(databaseFullPath))
{
connection.Open();
using (IDbCommand command = new SqliteCommand(
"SELECT datas.id, ot, alias, setcode, type, level, race, attribute, atk, def, texts.name, texts.desc"
+ " FROM datas INNER JOIN texts ON datas.id = texts.id",
connection))
using (IDbCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT datas.id, ot, alias, setcode, type, level, race, attribute, atk, def, texts.name, texts.desc" + " FROM datas INNER JOIN texts ON datas.id = texts.id";
using (IDataReader reader = command.ExecuteReader())
{
while (reader.Read())