2020-08-04 15:32:20 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-08-14 14:15:19 +00:00
|
|
|
using System.Threading;
|
2020-08-07 18:28:38 +00:00
|
|
|
using System.Threading.Tasks;
|
2020-07-26 13:40:08 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using PkmnLibSharp.Battling;
|
2020-07-31 12:19:21 +00:00
|
|
|
using PkmnLibSharp.Battling.ChoiceTurn;
|
2020-08-04 15:32:20 +00:00
|
|
|
using PkmnLibSharp.Battling.Events;
|
2020-07-26 13:40:08 +00:00
|
|
|
|
|
|
|
namespace PkmnLibSharpTests.Battling.BattleTests
|
|
|
|
{
|
|
|
|
public class BasicBattleTests
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void InitializeBattle()
|
|
|
|
{
|
|
|
|
var lib = BattleLibraryHelper.GetLibrary();
|
|
|
|
var battle = new BattleBuilder(lib, true, 2, 1).Build();
|
|
|
|
Assert.AreEqual(lib, battle.Library);
|
|
|
|
Assert.AreEqual(true, battle.CanFlee);
|
|
|
|
Assert.AreEqual(2, battle.SidesCount);
|
|
|
|
Assert.AreEqual(false, battle.HasEnded);
|
|
|
|
Assert.AreEqual(0, battle.PartiesCount);
|
|
|
|
battle.Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static PokemonParty BuildTestParty(BattleLibrary lib)
|
|
|
|
{
|
|
|
|
var party = new PokemonParty();
|
2020-07-31 12:19:21 +00:00
|
|
|
party.SwapInto(0,
|
|
|
|
new PokemonBuilder(lib, "testSpecies", 50)
|
|
|
|
.LearnMove("testMove", MoveLearnMethod.Unknown)
|
|
|
|
.Build());
|
2020-07-26 13:40:08 +00:00
|
|
|
return party;
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void InitializeBattleWithParties()
|
|
|
|
{
|
|
|
|
var lib = BattleLibraryHelper.GetLibrary();
|
2020-07-31 12:19:21 +00:00
|
|
|
var p1 = BuildTestParty(lib);
|
|
|
|
var p2 = BuildTestParty(lib);
|
2020-07-26 13:40:08 +00:00
|
|
|
var battle =
|
|
|
|
new BattleBuilder(lib, true, 2, 1)
|
2020-07-31 12:19:21 +00:00
|
|
|
.WithPartyOnPositions(p1, new BattlePosition(0, 0))
|
|
|
|
.WithPartyOnPositions(p2, new BattlePosition(1, 0))
|
2020-07-26 13:40:08 +00:00
|
|
|
.Build();
|
|
|
|
Assert.AreEqual(2, battle.PartiesCount);
|
2020-07-31 12:19:21 +00:00
|
|
|
Assert.AreEqual(p1, battle.Parties[0].Party);
|
|
|
|
Assert.AreEqual(p2, battle.Parties[1].Party);
|
|
|
|
battle.Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void RunTurn()
|
|
|
|
{
|
|
|
|
var lib = BattleLibraryHelper.GetLibrary();
|
|
|
|
var p1 = BuildTestParty(lib);
|
|
|
|
var p2 = BuildTestParty(lib);
|
|
|
|
var battle =
|
|
|
|
new BattleBuilder(lib, true, 2, 1)
|
|
|
|
.WithPartyOnPositions(p1, new BattlePosition(0, 0))
|
|
|
|
.WithPartyOnPositions(p2, new BattlePosition(1, 0))
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
battle.SwitchPokemon(0, 0, p1.GetAtIndex(0));
|
|
|
|
battle.SwitchPokemon(1, 0, p2.GetAtIndex(0));
|
2020-08-04 15:32:20 +00:00
|
|
|
Assert.AreEqual(0, battle.CurrentTurn);
|
|
|
|
|
|
|
|
var moveTurn1 = new MoveTurnChoice(p1.GetAtIndex(0), p1.GetAtIndex(0).Moves[0], 1, 0 );
|
|
|
|
var moveTurn2 = new MoveTurnChoice(p2.GetAtIndex(0), p2.GetAtIndex(0).Moves[0], 0, 0 );
|
|
|
|
|
|
|
|
Assert.That(battle.TrySetChoice(moveTurn1));
|
|
|
|
Assert.That(battle.TrySetChoice(moveTurn2));
|
|
|
|
|
|
|
|
Assert.AreEqual(battle.CurrentTurn, 1);
|
2020-07-31 12:19:21 +00:00
|
|
|
|
2020-08-04 15:32:20 +00:00
|
|
|
battle.Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void EventListener()
|
|
|
|
{
|
|
|
|
var lib = BattleLibraryHelper.GetLibrary();
|
|
|
|
var p1 = BuildTestParty(lib);
|
|
|
|
var p2 = BuildTestParty(lib);
|
|
|
|
var battle =
|
|
|
|
new BattleBuilder(lib, true, 2, 1)
|
|
|
|
.WithPartyOnPositions(p1, new BattlePosition(0, 0))
|
|
|
|
.WithPartyOnPositions(p2, new BattlePosition(1, 0))
|
|
|
|
.WithRandomSeed(20)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var evts = new List<EventData>();
|
2020-08-14 14:15:19 +00:00
|
|
|
var eventListener = new BattleEventListener(evt =>
|
2020-08-04 15:32:20 +00:00
|
|
|
{
|
|
|
|
evts.Add(evt);
|
2020-08-07 18:28:38 +00:00
|
|
|
return Task.CompletedTask;
|
2020-08-14 14:15:19 +00:00
|
|
|
});
|
|
|
|
battle.RegisterEventListener(eventListener);
|
2020-08-04 15:32:20 +00:00
|
|
|
|
|
|
|
battle.SwitchPokemon(0, 0, p1.GetAtIndex(0));
|
|
|
|
battle.SwitchPokemon(1, 0, p2.GetAtIndex(0));
|
|
|
|
Assert.AreEqual(0, battle.CurrentTurn);
|
|
|
|
|
2020-07-31 12:19:21 +00:00
|
|
|
var moveTurn1 = new MoveTurnChoice(p1.GetAtIndex(0), p1.GetAtIndex(0).Moves[0], 1, 0 );
|
|
|
|
var moveTurn2 = new MoveTurnChoice(p2.GetAtIndex(0), p2.GetAtIndex(0).Moves[0], 0, 0 );
|
|
|
|
|
|
|
|
Assert.That(battle.TrySetChoice(moveTurn1));
|
|
|
|
Assert.That(battle.TrySetChoice(moveTurn2));
|
2020-08-04 15:32:20 +00:00
|
|
|
Assert.AreEqual(1, battle.CurrentTurn);
|
2020-08-14 14:15:19 +00:00
|
|
|
|
|
|
|
eventListener.EnsureFinishedListening();
|
2020-08-04 15:32:20 +00:00
|
|
|
|
|
|
|
var damageEvents = evts.Where(x => x.Kind == EventDataKind.Damage).Cast<DamageEvent>().ToArray();
|
|
|
|
Assert.AreEqual(2, damageEvents.Length);
|
|
|
|
Assert.AreEqual(damageEvents[0].Pokemon, p2.GetAtIndex(0));
|
|
|
|
Assert.AreEqual(damageEvents[1].Pokemon, p1.GetAtIndex(0));
|
2020-07-31 12:19:21 +00:00
|
|
|
|
2020-07-26 13:40:08 +00:00
|
|
|
battle.Dispose();
|
|
|
|
}
|
2020-12-28 14:11:25 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void HealAfterBattle()
|
|
|
|
{
|
|
|
|
var lib = BattleLibraryHelper.GetLibrary();
|
|
|
|
var p1 = BuildTestParty(lib);
|
|
|
|
var mon1 = p1.GetAtIndex(0);
|
|
|
|
var p2 = BuildTestParty(lib);
|
|
|
|
var mon2 = p2.GetAtIndex(0);
|
|
|
|
var battle =
|
|
|
|
new BattleBuilder(lib, true, 2, 1)
|
|
|
|
.WithPartyOnPositions(p1, new BattlePosition(0, 0))
|
|
|
|
.WithPartyOnPositions(p2, new BattlePosition(1, 0))
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var evts = new List<EventData>();
|
|
|
|
var eventListener = new BattleEventListener(evt =>
|
|
|
|
{
|
|
|
|
evts.Add(evt);
|
|
|
|
return Task.CompletedTask;
|
|
|
|
});
|
|
|
|
battle.RegisterEventListener(eventListener);
|
|
|
|
|
|
|
|
battle.SwitchPokemon(0, 0, p1.GetAtIndex(0));
|
|
|
|
battle.SwitchPokemon(1, 0, p2.GetAtIndex(0));
|
|
|
|
Assert.AreEqual(0, battle.CurrentTurn);
|
|
|
|
|
|
|
|
var moveTurn1 = new MoveTurnChoice(p1.GetAtIndex(0), p1.GetAtIndex(0).Moves[0], 1, 0 );
|
|
|
|
var moveTurn2 = new MoveTurnChoice(p2.GetAtIndex(0), p2.GetAtIndex(0).Moves[0], 0, 0 );
|
|
|
|
|
|
|
|
Assert.That(battle.TrySetChoice(moveTurn1));
|
|
|
|
Assert.That(battle.TrySetChoice(moveTurn2));
|
|
|
|
|
|
|
|
Assert.AreEqual(battle.CurrentTurn, 1);
|
|
|
|
|
|
|
|
battle.Dispose();
|
|
|
|
|
|
|
|
mon1.Heal(1000, true);
|
|
|
|
mon2.Heal(1000, true);
|
|
|
|
}
|
2020-07-31 12:19:21 +00:00
|
|
|
|
2020-07-26 13:40:08 +00:00
|
|
|
}
|
|
|
|
}
|