Support for battle event listeners.

This commit is contained in:
2020-08-04 17:32:20 +02:00
parent 00c5f51c55
commit b0dea8b6e7
19 changed files with 201 additions and 39 deletions

View File

@@ -1,6 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using PkmnLibSharp.Battling;
using PkmnLibSharp.Battling.ChoiceTurn;
using PkmnLibSharp.Battling.Events;
namespace PkmnLibSharpTests.Battling.BattleTests
{
@@ -60,13 +63,55 @@ namespace PkmnLibSharpTests.Battling.BattleTests
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();
}
[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>();
battle.RegisterEventListener(new BattleEventListener(evt =>
{
evts.Add(evt);
}));
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(1, battle.CurrentTurn);
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));
battle.Dispose();
}