CreatureLib/tests/Integration/BattleIntegrations.cpp

275 lines
11 KiB
C++
Raw Normal View History

#ifdef TESTS_BUILD
#include "../../extern/catch.hpp"
#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"
#include "../../src/Battling/TurnChoices/SwitchTurnChoice.hpp"
#include "../TestLibrary/TestLibrary.hpp"
using namespace CreatureLib;
using namespace Battling;
TEST_CASE("Create Party", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1};
auto battleParty = BattleParty(&party1, {CreatureIndex(0, 0)});
REQUIRE(battleParty.GetParty()->GetAtIndex(0) == c1);
}
TEST_CASE("Create Battle", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c2};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
}
TEST_CASE("Use damaging move", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c2};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
battle.SwitchCreature(0, 0, c1);
battle.SwitchCreature(1, 0, c2);
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0], CreatureIndex(1, 0)));
battle.TrySetChoice(new PassTurnChoice(c2));
REQUIRE(c2->GetCurrentHealth() < c2->GetBoostedStat(Statistic::Health));
}
TEST_CASE("Finish battle when all battle of one side have fainted", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c2};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
REQUIRE_FALSE(battle.HasEnded());
battle.SwitchCreature(0, 0, c1);
battle.SwitchCreature(1, 0, c2);
REQUIRE_FALSE(battle.HasEnded());
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0], CreatureIndex(1, 0)));
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());
2019-12-15 10:52:10 +00:00
auto result = battle.GetResult();
REQUIRE(result.IsConclusiveResult());
REQUIRE(result.GetWinningSide() == 0);
}
TEST_CASE("When creature is dealt enough damage, faint it and mark battle as ended", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c2};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
REQUIRE_FALSE(battle.HasEnded());
battle.SwitchCreature(0, 0, c1);
battle.SwitchCreature(1, 0, c2);
REQUIRE_FALSE(battle.HasEnded());
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0], CreatureIndex(1, 0)));
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 21:52:43 +00:00
TEST_CASE("When another creature is available on faint, make sure the battle hasn't ended", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
2019-12-07 21:52:43 +00:00
CreatureParty party1{c1};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c3 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
2019-12-07 21:52:43 +00:00
CreatureParty party2{c2, c3};
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 21:52:43 +00:00
REQUIRE_FALSE(battle.HasEnded());
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0], CreatureIndex(1, 0)));
battle.TrySetChoice(new PassTurnChoice(c2));
REQUIRE_FALSE(battle.HasEnded());
battle.SwitchCreature(1, 0, c3);
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0], CreatureIndex(1, 0)));
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
}
TEST_CASE("Switch Creature in", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1, c2};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c3 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c3};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
battle.SwitchCreature(0, 0, c1);
battle.SwitchCreature(1, 0, c3);
REQUIRE(battle.GetTarget(CreatureIndex(0, 0)) == c1);
battle.TrySetChoice(new SwitchTurnChoice(c1, c2));
battle.TrySetChoice(new PassTurnChoice(c3));
REQUIRE(battle.GetTarget(CreatureIndex(0, 0)) == c2);
}
TEST_CASE("Switch Creature in, but have attack aimed at it. Attack should hit new creature", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c2 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1, c2};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c3 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c3};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
battle.SwitchCreature(0, 0, c1);
battle.SwitchCreature(1, 0, c3);
battle.TrySetChoice(new SwitchTurnChoice(c1, c2));
battle.TrySetChoice(new AttackTurnChoice(c3, c3->GetAttacks()[0], CreatureIndex(0, 0)));
REQUIRE(c2->GetCurrentHealth() < c2->GetBoostedStat(Core::Statistic::Health));
REQUIRE(c1->GetCurrentHealth() == c1->GetBoostedStat(Core::Statistic::Health));
}
2019-12-14 11:40:50 +00:00
TEST_CASE("Switch Creature in, mark as seen opponent for opponent", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
2019-12-14 11:40:50 +00:00
CreatureParty party1{c1, c2};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c3 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
2019-12-14 11:40:50 +00:00
CreatureParty party2{c3};
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);
REQUIRE(seen.find(c1) != seen.end());
battle.TrySetChoice(new SwitchTurnChoice(c1, c2));
battle.TrySetChoice(new PassTurnChoice(c3));
seen = c3->GetSeenOpponents();
REQUIRE(seen.size() == 2);
REQUIRE(seen.find(c1) != seen.end());
REQUIRE(seen.find(c2) != seen.end());
battle.TrySetChoice(new SwitchTurnChoice(c2, c1));
battle.TrySetChoice(new PassTurnChoice(c3));
seen = c3->GetSeenOpponents();
REQUIRE(seen.size() == 2);
REQUIRE(seen.find(c1) != seen.end());
REQUIRE(seen.find(c2) != seen.end());
}
2019-12-15 10:52:10 +00:00
TEST_CASE("Flee Battle", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
2019-12-15 10:52:10 +00:00
CreatureParty party1{c1};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
2019-12-15 10:52:10 +00:00
CreatureParty party2{c2};
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());
}
#endif