Rework clearing battle from creatures.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
a284641b5a
commit
3742e07b03
|
@ -85,5 +85,6 @@ export uint8_t CreatureLib_Battle_RegisterEventListener(Battle* p, void (*func)(
|
||||||
export const HistoryHolder* CreatureLib_Battle_GetHistory(Battle* p) { return &p->GetHistory(); }
|
export const HistoryHolder* CreatureLib_Battle_GetHistory(Battle* p) { return &p->GetHistory(); }
|
||||||
|
|
||||||
export uint8_t CreatureLib_Battle_EndBattle(Battle* p) { Try(p->EndBattle()) }
|
export uint8_t CreatureLib_Battle_EndBattle(Battle* p) { Try(p->EndBattle()) }
|
||||||
|
export uint8_t CreatureLib_Battle_ClearBattle(Battle* p) { Try(p->ClearBattle()) }
|
||||||
|
|
||||||
SIMPLE_GET_FUNC(Battle, GetLastTurnTimeMicroseconds, long);
|
SIMPLE_GET_FUNC(Battle, GetLastTurnTimeMicroseconds, long);
|
|
@ -48,7 +48,7 @@ namespace CreatureLib::Battling {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Battle() = default;
|
virtual ~Battle() { ClearBattle(); }
|
||||||
|
|
||||||
[[nodiscard]] const ArbUt::BorrowedPtr<const BattleLibrary>& GetLibrary() const noexcept;
|
[[nodiscard]] const ArbUt::BorrowedPtr<const BattleLibrary>& GetLibrary() const noexcept;
|
||||||
[[nodiscard]] uint32_t GetCurrentTurn() const noexcept { return _currentTurn; }
|
[[nodiscard]] uint32_t GetCurrentTurn() const noexcept { return _currentTurn; }
|
||||||
|
@ -117,17 +117,20 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
long GetLastTurnTimeMicroseconds() const noexcept { return _lastTurnTime; }
|
long GetLastTurnTimeMicroseconds() const noexcept { return _lastTurnTime; }
|
||||||
|
|
||||||
void EndBattle() {
|
void EndBattle() { this->_hasEnded = true; }
|
||||||
this->_hasEnded = true;
|
|
||||||
|
void ClearBattle() {
|
||||||
for (size_t i = 0; i < _numberOfSides; i++) {
|
for (size_t i = 0; i < _numberOfSides; i++) {
|
||||||
auto side = _sides[i];
|
auto side = _sides[i];
|
||||||
for (auto c : side->GetCreatures()) {
|
for (auto c : side->GetCreatures()) {
|
||||||
if (c.HasValue()) {
|
if (c.HasValue()) {
|
||||||
|
if (c.GetValue()->GetBattle() == this) {
|
||||||
c.GetValue()->ClearBattleData();
|
c.GetValue()->ClearBattleData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -334,4 +334,43 @@ TEST_CASE("Flee Battle") {
|
||||||
REQUIRE_FALSE(result.IsConclusiveResult());
|
REQUIRE_FALSE(result.IsConclusiveResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue