using PkmnLib.Dynamic.ScriptHandling; using PkmnLib.Dynamic.ScriptHandling.Registry; using PkmnLib.Static.Libraries; namespace PkmnLib.Dynamic.Libraries; /// /// The dynamic library stores a static data library, as well as holding different libraries and /// calculators that might be customized between different generations and implementations. /// public interface IDynamicLibrary { /// /// The static data is the immutable storage data for this library. /// IStaticLibrary StaticLibrary { get; } /// /// The stat calculator deals with the calculation of flat and boosted stats, based on the /// Pokémon's attributes. /// IBattleStatCalculator StatCalculator { get; } /// /// The damage calculator deals with the calculation of things relating to damage. /// IDamageCalculator DamageCalculator { get; } /// /// The Misc Library holds minor functions that do not fall in any of the other libraries and /// calculators. /// IMiscLibrary MiscLibrary { get; } /// /// The capture library deals with the calculation of the capture rate of a Pokémon. /// ICaptureLibrary CaptureLibrary { get; } /// /// A holder of the script types that can be resolved by this library. /// ScriptResolver ScriptResolver { get; } } /// public class DynamicLibraryImpl : IDynamicLibrary { /// /// Initializes a new instance of the class, with the given /// plugins and static library. /// public static IDynamicLibrary Create(IStaticLibrary staticLibrary, IEnumerable plugins) { var registry = new ScriptRegistry(); foreach (var plugin in plugins.OrderBy(x => x.LoadOrder)) { plugin.Register(registry); } if (registry.DamageCalculator is null) throw new InvalidOperationException("Damage calculator not found in plugins."); if (registry.BattleStatCalculator is null) throw new InvalidOperationException("Stat calculator not found in plugins."); if (registry.MiscLibrary is null) throw new InvalidOperationException("Misc library not found in plugins."); if (registry.CaptureLibrary is null) throw new InvalidOperationException("Capture library not found in plugins."); var scriptResolver = new ScriptResolver(registry.ScriptTypes, registry.ItemScriptTypes); return new DynamicLibraryImpl(staticLibrary, registry.BattleStatCalculator, registry.DamageCalculator, registry.MiscLibrary, registry.CaptureLibrary, scriptResolver); } private DynamicLibraryImpl(IStaticLibrary staticLibrary, IBattleStatCalculator statCalculator, IDamageCalculator damageCalculator, IMiscLibrary miscLibrary, ICaptureLibrary captureLibrary, ScriptResolver scriptResolver) { StaticLibrary = staticLibrary; StatCalculator = statCalculator; DamageCalculator = damageCalculator; MiscLibrary = miscLibrary; ScriptResolver = scriptResolver; CaptureLibrary = captureLibrary; } /// public IStaticLibrary StaticLibrary { get; } /// public IBattleStatCalculator StatCalculator { get; } /// public IDamageCalculator DamageCalculator { get; } /// public IMiscLibrary MiscLibrary { get; } /// public ICaptureLibrary CaptureLibrary { get; } /// public ScriptResolver ScriptResolver { get; } }