2021-11-27 10:27:19 +00:00
|
|
|
using System;
|
2020-07-19 10:33:22 +00:00
|
|
|
using System.Linq;
|
2020-12-23 11:27:58 +00:00
|
|
|
using NUnit.Framework;
|
2020-07-19 10:33:22 +00:00
|
|
|
using PkmnLibSharp.Battling;
|
|
|
|
using PkmnLibSharp.Library;
|
|
|
|
using PkmnLibSharp.Library.GrowthRates;
|
|
|
|
using PkmnLibSharp.Library.Items;
|
|
|
|
using PkmnLibSharp.Library.Moves;
|
|
|
|
|
|
|
|
namespace PkmnLibSharpTests.Battling
|
|
|
|
{
|
|
|
|
public static class BattleLibraryHelper
|
|
|
|
{
|
|
|
|
private static BattleLibrary _cache;
|
2020-12-23 11:27:58 +00:00
|
|
|
private static readonly object Lock = new object();
|
2021-11-27 10:27:19 +00:00
|
|
|
|
2020-07-19 10:33:22 +00:00
|
|
|
public static BattleLibrary GetLibrary()
|
|
|
|
{
|
2020-12-23 11:27:58 +00:00
|
|
|
lock (Lock)
|
|
|
|
{
|
2021-11-27 10:27:19 +00:00
|
|
|
if (_cache != null)
|
2020-12-23 11:27:58 +00:00
|
|
|
return _cache;
|
2021-11-27 10:27:19 +00:00
|
|
|
|
2020-12-23 11:27:58 +00:00
|
|
|
TestContext.WriteLine("Building battle library");
|
|
|
|
var scriptLibrary = new AngelScriptResolver();
|
|
|
|
_cache = new BattleLibrary(BuildStatic(), new StatCalculator(), new DamageLibrary(),
|
2021-11-27 10:27:19 +00:00
|
|
|
new ExperienceLibrary(), scriptLibrary, new MiscLibrary(GetTime));
|
2020-12-23 11:27:58 +00:00
|
|
|
scriptLibrary.Initialize(_cache);
|
|
|
|
return _cache;
|
|
|
|
}
|
2020-07-19 10:33:22 +00:00
|
|
|
}
|
|
|
|
|
2021-07-09 16:20:01 +00:00
|
|
|
public static TimeOfDay GetTime()
|
|
|
|
{
|
|
|
|
return TimeOfDay.Morning;
|
|
|
|
}
|
|
|
|
|
2020-07-19 10:33:22 +00:00
|
|
|
private static PokemonLibrary BuildStatic()
|
|
|
|
{
|
|
|
|
var settings = new LibrarySettings(100, 4, 4096);
|
|
|
|
var species = new SpeciesLibrary(10);
|
2021-11-27 10:27:19 +00:00
|
|
|
var abilities = new AbilityLibrary(10);
|
|
|
|
var testAbility1 = new Ability("testAbility1", "", Array.Empty<EffectParameter>());
|
|
|
|
var testAbility2 = new Ability("testAbility2", "", Array.Empty<EffectParameter>());
|
|
|
|
var testHiddenAbility = new Ability("testHiddenAbility", "", Array.Empty<EffectParameter>());
|
|
|
|
abilities.Insert("testAbility1", testAbility1);
|
|
|
|
abilities.Insert("testAbility2", testAbility2);
|
|
|
|
abilities.Insert("testHiddenAbility", testHiddenAbility);
|
|
|
|
|
|
|
|
species.Insert("testSpecies",
|
|
|
|
new Species(1, "testSpecies",
|
|
|
|
new Forme("default", 10f, 10f, 100, new byte[] { 0, 1 }, 100, 100, 100, 100, 100, 100,
|
|
|
|
new[] { testAbility1, testAbility2 }, new[] { testHiddenAbility }, new LearnableMoves(100),
|
|
|
|
new string[0]), 0.5f, "growthRate", 20, 100, new[] { "testEggGroup" }, new string[0]));
|
|
|
|
|
2020-08-08 11:57:54 +00:00
|
|
|
var moves = new MoveLibrary(10);
|
2021-11-27 10:27:19 +00:00
|
|
|
moves.Insert("testMove",
|
|
|
|
new MoveData("testMove", 0, MoveCategory.Physical, 100, 100, 20, MoveTarget.Any, 0, 0f, "",
|
|
|
|
new EffectParameter[0], new string[0]));
|
|
|
|
moves.Insert("testMove2",
|
|
|
|
new MoveData("testMove2", 0, MoveCategory.Physical, 100, 100, 20, MoveTarget.Any, 0, 0f, "",
|
|
|
|
new EffectParameter[0], new string[0]));
|
|
|
|
|
2020-07-19 10:33:22 +00:00
|
|
|
var items = new ItemLibrary(10);
|
2021-11-27 10:27:19 +00:00
|
|
|
items.Insert("testItem",
|
|
|
|
new Item("testItem", ItemCategory.MiscItem, BattleItemCategory.None, 500, "", new EffectParameter[0],
|
|
|
|
new string[] { }, 20));
|
2020-07-19 10:33:22 +00:00
|
|
|
var gr = new GrowthRateLibrary(10);
|
2021-11-27 10:27:19 +00:00
|
|
|
gr.AddGrowthRate("growthRate",
|
|
|
|
new LookupGrowthRate(Enumerable.Range(1, 100).Select(x => (uint)x * 100).ToArray()));
|
2020-07-19 10:33:22 +00:00
|
|
|
var types = new TypeLibrary(10);
|
2020-07-31 12:19:21 +00:00
|
|
|
types.RegisterType("normal");
|
|
|
|
types.RegisterType("fighting");
|
2020-07-19 10:33:22 +00:00
|
|
|
var natures = new NatureLibrary(10);
|
|
|
|
natures.LoadNature("testNature", new Nature());
|
2021-11-27 10:27:19 +00:00
|
|
|
|
|
|
|
var lib = new PokemonLibrary(settings, species, moves, items, gr, types, abilities, natures);
|
2020-07-19 10:33:22 +00:00
|
|
|
return lib;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|