Fixed battle ending after any faint.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
f5aa168f1b
commit
dc9296194e
|
@ -47,6 +47,15 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) final;
|
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) final;
|
||||||
|
|
||||||
|
uint8_t GetSideIndex() { return _index; }
|
||||||
|
uint8_t GetCreatureIndex(Creature* c) {
|
||||||
|
for (size_t i = 0; i < _creatures.size(); i++) {
|
||||||
|
if (c == _creatures[i])
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
throw CreatureException("Unable to find creature on field.");
|
||||||
|
}
|
||||||
|
|
||||||
void MarkSlotAsUnfillable(Creature* creature) {
|
void MarkSlotAsUnfillable(Creature* creature) {
|
||||||
for (uint8_t i = 0; i < _creaturesPerSide; i++) {
|
for (uint8_t i = 0; i < _creaturesPerSide; i++) {
|
||||||
if (_creatures[i] == creature) {
|
if (_creatures[i] == creature) {
|
||||||
|
@ -58,7 +67,8 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
bool IsDefeated() {
|
bool IsDefeated() {
|
||||||
for (auto b : _fillableSlots) {
|
for (auto b : _fillableSlots) {
|
||||||
if (b) return false;
|
if (b)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,8 +99,10 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source)
|
||||||
// HOOK: On Damage
|
// HOOK: On Damage
|
||||||
__CurrentHealth -= damage;
|
__CurrentHealth -= damage;
|
||||||
|
|
||||||
if (IsFainted()){
|
if (IsFainted() && damage > 0) {
|
||||||
|
if (!_battle->CanSlotBeFilled(_side->GetSideIndex(), _side->GetCreatureIndex(this))) {
|
||||||
_side->MarkSlotAsUnfillable(this);
|
_side->MarkSlotAsUnfillable(this);
|
||||||
|
}
|
||||||
_battle->ValidateBattleState();
|
_battle->ValidateBattleState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,37 @@ TEST_CASE("When creature is dealt enough damage, faint it and mark battle as end
|
||||||
REQUIRE(battle.GetResult() == 0);
|
REQUIRE(battle.GetResult() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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", AttackLearnMethod::Unknown)->Create();
|
||||||
|
CreatureParty party1{c1};
|
||||||
|
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
|
||||||
|
auto c2 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
||||||
|
auto c3 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
|
||||||
|
CreatureParty party2{c2, c3};
|
||||||
|
auto battleParty2 = 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());
|
||||||
|
|
||||||
|
battle.SwitchCreature(1, 0, c3);
|
||||||
|
|
||||||
|
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0], CreatureIndex(1, 0)));
|
||||||
|
battle.TrySetChoice(new PassTurnChoice(c3));
|
||||||
|
|
||||||
|
REQUIRE(battle.HasEnded());
|
||||||
|
REQUIRE(battle.GetResult() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue