Fixed battle ending after any faint.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user