2019-12-05 11:56:41 +00:00
|
|
|
#ifdef TESTS_BUILD
|
2022-02-05 12:59:15 +00:00
|
|
|
#include <doctest.h>
|
2019-12-05 11:56:41 +00:00
|
|
|
#include "../../src/Battling/Models/Battle.hpp"
|
|
|
|
#include "../../src/Battling/Models/BattleParty.hpp"
|
|
|
|
#include "../../src/Battling/Models/CreateCreature.hpp"
|
|
|
|
#include "../../src/Battling/TurnChoices/AttackTurnChoice.hpp"
|
|
|
|
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
|
2019-12-14 11:15:30 +00:00
|
|
|
#include "../../src/Battling/TurnChoices/SwitchTurnChoice.hpp"
|
2019-12-07 12:45:44 +00:00
|
|
|
#include "../TestLibrary/TestLibrary.hpp"
|
2019-12-05 11:56:41 +00:00
|
|
|
|
|
|
|
using namespace CreatureLib;
|
|
|
|
using namespace Battling;
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Create Party") {
|
2019-12-07 12:45:44 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-25 08:41:15 +00:00
|
|
|
auto c1 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-05 11:56:41 +00:00
|
|
|
CreatureParty party1{c1};
|
|
|
|
auto battleParty = BattleParty(&party1, {CreatureIndex(0, 0)});
|
|
|
|
REQUIRE(battleParty.GetParty()->GetAtIndex(0) == c1);
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Create Battle") {
|
2019-12-07 12:45:44 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-25 08:41:15 +00:00
|
|
|
auto c1 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-05 11:56:41 +00:00
|
|
|
CreatureParty party1{c1};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
|
2020-04-25 08:41:15 +00:00
|
|
|
auto c2 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-05 11:56:41 +00:00
|
|
|
CreatureParty party2{c2};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
|
2019-12-05 11:56:41 +00:00
|
|
|
|
|
|
|
auto battle = Battle(library, {battleParty1, battleParty2});
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Use damaging move") {
|
2019-12-07 12:45:44 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-25 08:41:15 +00:00
|
|
|
auto c1 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-05 11:56:41 +00:00
|
|
|
CreatureParty party1{c1};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
|
2020-04-25 08:41:15 +00:00
|
|
|
auto c2 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-05 11:56:41 +00:00
|
|
|
CreatureParty party2{c2};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
|
2019-12-05 11:56:41 +00:00
|
|
|
|
|
|
|
auto battle = Battle(library, {battleParty1, battleParty2});
|
|
|
|
|
2019-12-07 12:45:44 +00:00
|
|
|
battle.SwitchCreature(0, 0, c1);
|
|
|
|
battle.SwitchCreature(1, 0, c2);
|
2019-12-05 11:56:41 +00:00
|
|
|
|
2020-12-12 14:10:18 +00:00
|
|
|
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0].GetValue(), CreatureIndex(1, 0)));
|
2019-12-05 11:56:41 +00:00
|
|
|
battle.TrySetChoice(new PassTurnChoice(c2));
|
|
|
|
|
|
|
|
REQUIRE(c2->GetCurrentHealth() < c2->GetBoostedStat(Statistic::Health));
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Run more turns") {
|
2020-08-30 11:14:33 +00:00
|
|
|
auto library = TestLibrary::Get();
|
|
|
|
auto c1 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
|
|
|
CreatureParty party1{c1};
|
|
|
|
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
|
|
|
|
auto c2 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
|
|
|
auto c3 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
|
|
|
CreatureParty party2{c2, c3};
|
|
|
|
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
|
|
|
|
|
|
|
|
auto battle = Battle(library, {battleParty1, battleParty2});
|
|
|
|
|
|
|
|
battle.SwitchCreature(0, 0, c1);
|
|
|
|
battle.SwitchCreature(1, 0, c2);
|
|
|
|
|
2020-12-12 14:10:18 +00:00
|
|
|
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0].GetValue(), CreatureIndex(1, 0)));
|
2020-08-30 11:14:33 +00:00
|
|
|
battle.TrySetChoice(new PassTurnChoice(c2));
|
|
|
|
|
|
|
|
REQUIRE(c2->IsFainted());
|
|
|
|
battle.SwitchCreature(1, 0, c3);
|
2020-12-12 14:10:18 +00:00
|
|
|
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0].GetValue(), CreatureIndex(1, 0)));
|
2020-08-30 11:14:33 +00:00
|
|
|
battle.TrySetChoice(new PassTurnChoice(c3));
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Finish battle when all battle of one side have fainted") {
|
2019-12-07 20:56:29 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-25 08:41:15 +00:00
|
|
|
auto c1 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-07 20:56:29 +00:00
|
|
|
CreatureParty party1{c1};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
|
2020-04-25 08:41:15 +00:00
|
|
|
auto c2 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-07 20:56:29 +00:00
|
|
|
CreatureParty party2{c2};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
|
2019-12-07 20:56:29 +00:00
|
|
|
|
|
|
|
auto battle = Battle(library, {battleParty1, battleParty2});
|
|
|
|
|
|
|
|
REQUIRE_FALSE(battle.HasEnded());
|
|
|
|
|
|
|
|
battle.SwitchCreature(0, 0, c1);
|
|
|
|
battle.SwitchCreature(1, 0, c2);
|
|
|
|
|
|
|
|
REQUIRE_FALSE(battle.HasEnded());
|
2020-12-12 14:10:18 +00:00
|
|
|
REQUIRE(battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0].GetValue(), CreatureIndex(1, 0))));
|
2020-03-22 14:25:38 +00:00
|
|
|
REQUIRE(battle.TrySetChoice(new PassTurnChoice(c2)));
|
2019-12-07 20:56:29 +00:00
|
|
|
|
|
|
|
REQUIRE_FALSE(battle.HasEnded());
|
|
|
|
|
|
|
|
REQUIRE(c2->GetCurrentHealth() < c2->GetBoostedStat(Statistic::Health));
|
|
|
|
|
|
|
|
c2->Damage(c2->GetCurrentHealth(), DamageSource::AttackDamage);
|
|
|
|
|
|
|
|
REQUIRE(battle.HasEnded());
|
2019-12-15 10:52:10 +00:00
|
|
|
auto result = battle.GetResult();
|
|
|
|
REQUIRE(result.IsConclusiveResult());
|
|
|
|
REQUIRE(result.GetWinningSide() == 0);
|
2019-12-07 20:56:29 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("When creature is dealt enough damage, faint it and mark battle as ended") {
|
2019-12-07 20:56:29 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-10 14:44:25 +00:00
|
|
|
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 100)
|
|
|
|
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
|
2020-04-25 08:41:15 +00:00
|
|
|
.Create();
|
2019-12-07 20:56:29 +00:00
|
|
|
CreatureParty party1{c1};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
|
2020-02-27 17:23:23 +00:00
|
|
|
auto c2 =
|
2020-04-25 08:41:15 +00:00
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-07 20:56:29 +00:00
|
|
|
CreatureParty party2{c2};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
|
2019-12-07 20:56:29 +00:00
|
|
|
|
|
|
|
auto battle = Battle(library, {battleParty1, battleParty2});
|
|
|
|
|
|
|
|
REQUIRE_FALSE(battle.HasEnded());
|
|
|
|
|
|
|
|
battle.SwitchCreature(0, 0, c1);
|
|
|
|
battle.SwitchCreature(1, 0, c2);
|
|
|
|
|
|
|
|
REQUIRE_FALSE(battle.HasEnded());
|
|
|
|
|
2020-12-12 14:10:18 +00:00
|
|
|
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0].GetValue(), CreatureIndex(1, 0)));
|
2019-12-07 20:56:29 +00:00
|
|
|
battle.TrySetChoice(new PassTurnChoice(c2));
|
|
|
|
|
|
|
|
REQUIRE(battle.HasEnded());
|
2019-12-15 10:52:10 +00:00
|
|
|
auto result = battle.GetResult();
|
|
|
|
REQUIRE(result.IsConclusiveResult());
|
|
|
|
REQUIRE(result.GetWinningSide() == 0);
|
2019-12-07 20:56:29 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("When another creature is available on faint, make sure the battle hasn't ended") {
|
2019-12-07 21:52:43 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-10 14:44:25 +00:00
|
|
|
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 100)
|
|
|
|
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
|
2020-04-25 08:41:15 +00:00
|
|
|
.Create();
|
2019-12-07 21:52:43 +00:00
|
|
|
CreatureParty party1{c1};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
|
2020-02-27 17:23:23 +00:00
|
|
|
auto c2 =
|
2020-04-25 08:41:15 +00:00
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2020-02-27 17:23:23 +00:00
|
|
|
auto c3 =
|
2020-04-25 08:41:15 +00:00
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-07 21:52:43 +00:00
|
|
|
CreatureParty party2{c2, c3};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
|
2019-12-07 21:52:43 +00:00
|
|
|
|
|
|
|
auto battle = Battle(library, {battleParty1, battleParty2});
|
|
|
|
|
|
|
|
REQUIRE_FALSE(battle.HasEnded());
|
|
|
|
|
|
|
|
battle.SwitchCreature(0, 0, c1);
|
|
|
|
battle.SwitchCreature(1, 0, c2);
|
2019-12-07 20:56:29 +00:00
|
|
|
|
2019-12-07 21:52:43 +00:00
|
|
|
REQUIRE_FALSE(battle.HasEnded());
|
|
|
|
|
2020-12-12 14:10:18 +00:00
|
|
|
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0].GetValue(), CreatureIndex(1, 0)));
|
2019-12-07 21:52:43 +00:00
|
|
|
battle.TrySetChoice(new PassTurnChoice(c2));
|
|
|
|
|
|
|
|
REQUIRE_FALSE(battle.HasEnded());
|
|
|
|
|
|
|
|
battle.SwitchCreature(1, 0, c3);
|
|
|
|
|
2020-12-12 14:10:18 +00:00
|
|
|
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0].GetValue(), CreatureIndex(1, 0)));
|
2019-12-07 21:52:43 +00:00
|
|
|
battle.TrySetChoice(new PassTurnChoice(c3));
|
|
|
|
|
|
|
|
REQUIRE(battle.HasEnded());
|
2019-12-15 10:52:10 +00:00
|
|
|
auto result = battle.GetResult();
|
|
|
|
REQUIRE(result.IsConclusiveResult());
|
|
|
|
REQUIRE(result.GetWinningSide() == 0);
|
2019-12-07 21:52:43 +00:00
|
|
|
}
|
2019-12-07 20:56:29 +00:00
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Switch Creature in") {
|
2019-12-14 11:15:30 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-10 14:44:25 +00:00
|
|
|
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 100)
|
|
|
|
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
|
2020-04-25 08:41:15 +00:00
|
|
|
.Create();
|
2020-02-27 17:23:23 +00:00
|
|
|
auto c2 =
|
2020-04-25 08:41:15 +00:00
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-14 11:15:30 +00:00
|
|
|
CreatureParty party1{c1, c2};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
|
2020-02-27 17:23:23 +00:00
|
|
|
auto c3 =
|
2020-04-25 08:41:15 +00:00
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-14 11:15:30 +00:00
|
|
|
CreatureParty party2{c3};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
|
2019-12-14 11:15:30 +00:00
|
|
|
|
|
|
|
auto battle = Battle(library, {battleParty1, battleParty2});
|
|
|
|
|
|
|
|
battle.SwitchCreature(0, 0, c1);
|
|
|
|
battle.SwitchCreature(1, 0, c3);
|
|
|
|
|
2020-03-09 09:16:57 +00:00
|
|
|
REQUIRE(battle.GetCreature(CreatureIndex(0, 0)) == c1);
|
2019-12-14 11:15:30 +00:00
|
|
|
|
|
|
|
battle.TrySetChoice(new SwitchTurnChoice(c1, c2));
|
|
|
|
battle.TrySetChoice(new PassTurnChoice(c3));
|
|
|
|
|
2020-03-09 09:16:57 +00:00
|
|
|
REQUIRE(battle.GetCreature(CreatureIndex(0, 0)) == c2);
|
2019-12-14 11:15:30 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Switch Creature in with event listener") {
|
2020-08-07 18:11:03 +00:00
|
|
|
auto library = TestLibrary::Get();
|
|
|
|
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 100)
|
|
|
|
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
|
|
|
|
.Create();
|
|
|
|
auto c2 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
|
|
|
CreatureParty party1{c1, c2};
|
|
|
|
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
|
|
|
|
auto c3 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
|
|
|
CreatureParty party2{c3};
|
|
|
|
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
|
|
|
|
|
|
|
|
auto battle = Battle(library, {battleParty1, battleParty2});
|
|
|
|
std::vector<const EventData*> events;
|
|
|
|
battle.RegisterEventListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
|
|
|
|
|
|
|
|
battle.SwitchCreature(0, 0, c1);
|
|
|
|
battle.SwitchCreature(1, 0, c3);
|
|
|
|
|
|
|
|
REQUIRE(events.size() == 2);
|
|
|
|
|
|
|
|
REQUIRE(battle.GetCreature(CreatureIndex(0, 0)) == c1);
|
|
|
|
|
|
|
|
battle.TrySetChoice(new SwitchTurnChoice(c1, c2));
|
|
|
|
battle.TrySetChoice(new PassTurnChoice(c3));
|
|
|
|
|
|
|
|
REQUIRE(battle.GetCreature(CreatureIndex(0, 0)) == c2);
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Switch Creature in, but have attack aimed at it. Attack should hit new creature") {
|
2019-12-14 11:15:30 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-25 08:41:15 +00:00
|
|
|
auto c1 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
|
|
|
auto c2 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-14 11:15:30 +00:00
|
|
|
CreatureParty party1{c1, c2};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
|
2020-04-25 08:41:15 +00:00
|
|
|
auto c3 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-14 11:15:30 +00:00
|
|
|
CreatureParty party2{c3};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
|
2019-12-14 11:15:30 +00:00
|
|
|
|
|
|
|
auto battle = Battle(library, {battleParty1, battleParty2});
|
|
|
|
|
|
|
|
battle.SwitchCreature(0, 0, c1);
|
|
|
|
battle.SwitchCreature(1, 0, c3);
|
|
|
|
|
|
|
|
battle.TrySetChoice(new SwitchTurnChoice(c1, c2));
|
2020-12-12 14:10:18 +00:00
|
|
|
battle.TrySetChoice(new AttackTurnChoice(c3, c3->GetAttacks()[0].GetValue(), CreatureIndex(0, 0)));
|
2019-12-14 11:15:30 +00:00
|
|
|
|
2020-03-22 09:11:53 +00:00
|
|
|
REQUIRE(c2->GetCurrentHealth() < c2->GetBoostedStat(Library::Statistic::Health));
|
|
|
|
REQUIRE(c1->GetCurrentHealth() == c1->GetBoostedStat(Library::Statistic::Health));
|
2019-12-14 11:15:30 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Switch Creature in, mark as seen opponent for opponent") {
|
2019-12-14 11:40:50 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-10 14:44:25 +00:00
|
|
|
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 100)
|
|
|
|
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
|
2020-04-25 08:41:15 +00:00
|
|
|
.Create();
|
2020-02-27 17:23:23 +00:00
|
|
|
auto c2 =
|
2020-04-25 08:41:15 +00:00
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-14 11:40:50 +00:00
|
|
|
CreatureParty party1{c1, c2};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
|
2020-02-27 17:23:23 +00:00
|
|
|
auto c3 =
|
2020-04-25 08:41:15 +00:00
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-14 11:40:50 +00:00
|
|
|
CreatureParty party2{c3};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
|
2019-12-14 11:40:50 +00:00
|
|
|
|
|
|
|
auto battle = Battle(library, {battleParty1, battleParty2});
|
|
|
|
|
|
|
|
battle.SwitchCreature(0, 0, c1);
|
|
|
|
battle.SwitchCreature(1, 0, c3);
|
|
|
|
|
|
|
|
auto seen = c3->GetSeenOpponents();
|
|
|
|
REQUIRE(seen.size() == 1);
|
2020-06-26 15:08:23 +00:00
|
|
|
REQUIRE(seen.contains(c1));
|
2019-12-14 11:40:50 +00:00
|
|
|
|
|
|
|
battle.TrySetChoice(new SwitchTurnChoice(c1, c2));
|
|
|
|
battle.TrySetChoice(new PassTurnChoice(c3));
|
|
|
|
|
|
|
|
seen = c3->GetSeenOpponents();
|
|
|
|
REQUIRE(seen.size() == 2);
|
2020-06-26 15:08:23 +00:00
|
|
|
REQUIRE(seen.contains(c1));
|
|
|
|
REQUIRE(seen.contains(c2));
|
2019-12-14 11:40:50 +00:00
|
|
|
|
|
|
|
battle.TrySetChoice(new SwitchTurnChoice(c2, c1));
|
|
|
|
battle.TrySetChoice(new PassTurnChoice(c3));
|
|
|
|
|
|
|
|
seen = c3->GetSeenOpponents();
|
|
|
|
REQUIRE(seen.size() == 2);
|
2020-06-26 15:08:23 +00:00
|
|
|
REQUIRE(seen.contains(c1));
|
|
|
|
REQUIRE(seen.contains(c2));
|
2019-12-14 11:40:50 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Flee Battle") {
|
2019-12-15 10:52:10 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-10 14:44:25 +00:00
|
|
|
auto c1 = CreateCreature(library, "testSpecies1"_cnc, 100)
|
|
|
|
.WithAttack("standard"_cnc, AttackLearnMethod::Unknown)
|
2020-04-25 08:41:15 +00:00
|
|
|
.Create();
|
2019-12-15 10:52:10 +00:00
|
|
|
CreatureParty party1{c1};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
|
2020-02-27 17:23:23 +00:00
|
|
|
auto c2 =
|
2020-04-25 08:41:15 +00:00
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
2019-12-15 10:52:10 +00:00
|
|
|
CreatureParty party2{c2};
|
2020-03-07 10:00:48 +00:00
|
|
|
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
|
2019-12-15 10:52:10 +00:00
|
|
|
|
|
|
|
auto battle = Battle(library, {battleParty1, battleParty2});
|
|
|
|
|
|
|
|
battle.SwitchCreature(0, 0, c1);
|
|
|
|
battle.SwitchCreature(1, 0, c2);
|
|
|
|
|
|
|
|
battle.TrySetChoice(new FleeTurnChoice(c1));
|
|
|
|
battle.TrySetChoice(new PassTurnChoice(c2));
|
|
|
|
|
|
|
|
REQUIRE(battle.HasEnded());
|
|
|
|
auto result = battle.GetResult();
|
|
|
|
REQUIRE_FALSE(result.IsConclusiveResult());
|
|
|
|
}
|
|
|
|
|
2020-12-28 14:10:49 +00:00
|
|
|
TEST_CASE("Heal creature after battle") {
|
|
|
|
auto library = TestLibrary::Get();
|
|
|
|
auto c1 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
|
|
|
CreatureParty party1{c1};
|
|
|
|
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
|
|
|
|
auto c2 =
|
|
|
|
CreateCreature(library, "testSpecies1"_cnc, 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
|
|
|
|
CreatureParty party2{c2};
|
|
|
|
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
|
|
|
|
|
|
|
|
auto battle = new Battle(library, {battleParty1, battleParty2});
|
|
|
|
std::vector<const EventData*> events;
|
|
|
|
battle->RegisterEventListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
|
|
|
|
|
|
|
|
REQUIRE_FALSE(battle->HasEnded());
|
|
|
|
|
|
|
|
battle->SwitchCreature(0, 0, c1);
|
|
|
|
battle->SwitchCreature(1, 0, c2);
|
|
|
|
|
|
|
|
REQUIRE_FALSE(battle->HasEnded());
|
|
|
|
REQUIRE(battle->TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0].GetValue(), CreatureIndex(1, 0))));
|
|
|
|
REQUIRE(battle->TrySetChoice(new PassTurnChoice(c2)));
|
|
|
|
|
|
|
|
REQUIRE_FALSE(battle->HasEnded());
|
|
|
|
|
|
|
|
REQUIRE(c2->GetCurrentHealth() < c2->GetBoostedStat(Statistic::Health));
|
|
|
|
|
|
|
|
c2->Damage(c2->GetCurrentHealth(), DamageSource::AttackDamage);
|
|
|
|
|
|
|
|
REQUIRE(battle->HasEnded());
|
|
|
|
auto result = battle->GetResult();
|
|
|
|
REQUIRE(result.IsConclusiveResult());
|
|
|
|
REQUIRE(result.GetWinningSide() == 0);
|
|
|
|
delete battle;
|
|
|
|
c2->Heal(1000, true);
|
|
|
|
REQUIRE(c2->GetCurrentHealth() == c2->GetMaxHealth());
|
|
|
|
}
|
|
|
|
|
2019-12-05 11:56:41 +00:00
|
|
|
#endif
|