Fixed battle ending after any faint.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2019-12-07 22:52:43 +01:00
parent f5aa168f1b
commit dc9296194e
3 changed files with 51 additions and 8 deletions

View File

@@ -47,18 +47,28 @@ namespace CreatureLib::Battling {
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) final;
void MarkSlotAsUnfillable(Creature* creature){
for (uint8_t i = 0; i < _creaturesPerSide; i++){
if (_creatures[i] == creature){
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) {
for (uint8_t i = 0; i < _creaturesPerSide; i++) {
if (_creatures[i] == creature) {
_fillableSlots[i] = false;
return;
}
}
}
bool IsDefeated(){
for (auto b: _fillableSlots){
if (b) return false;
bool IsDefeated() {
for (auto b : _fillableSlots) {
if (b)
return false;
}
return true;
}

View File

@@ -99,8 +99,10 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source)
// HOOK: On Damage
__CurrentHealth -= damage;
if (IsFainted()){
_side->MarkSlotAsUnfillable(this);
if (IsFainted() && damage > 0) {
if (!_battle->CanSlotBeFilled(_side->GetSideIndex(), _side->GetCreatureIndex(this))) {
_side->MarkSlotAsUnfillable(this);
}
_battle->ValidateBattleState();
}
}