Deal with Creatures being deleted before a battle they're part of.
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2021-08-28 19:05:52 +02:00
parent d89e0b0d77
commit 512a39e158
5 changed files with 23 additions and 3 deletions

View File

@@ -54,7 +54,7 @@ void BattleSide::SetCreature(ArbUt::OptionalBorrowedPtr<Creature> creature, uint
if (old.HasValue()) {
old.GetValue()->SetOnBattleField(false);
}
_creatures[index] = creature.GetValue();
_creatures[index] = creature;
if (!creature.HasValue()) {
return;
}

View File

@@ -40,6 +40,7 @@ namespace CreatureLib::Battling {
void SetChoice(BaseTurnChoice* choice);
void ResetChoices() noexcept;
void ForceClearCreature(uint8_t index) { _creatures[index] = {}; }
void SetCreature(ArbUt::OptionalBorrowedPtr<Creature> creature, uint8_t index);
const ArbUt::OptionalBorrowedPtr<Creature>& GetCreature(uint8_t index) const;

View File

@@ -391,4 +391,10 @@ void CreatureLib::Battling::Creature::ClearStatus() {
if (_battleData.Battle.HasValue()) {
_battleData.Battle.GetValue()->TriggerEventListener<StatusChangeEvent>(this, ""_cnc);
}
}
}
Battling::Creature::~Creature() {
if (_battleData.OnBattleField && _battleData.Side.HasValue()) {
_battleData.Side.GetValue()->ForceClearCreature(_battleData.Index.GetCreatureIndex());
}
}

View File

@@ -75,7 +75,7 @@ namespace CreatureLib::Battling {
const Library::TalentIndex& talent, const std::vector<LearnedAttack*>& attacks,
bool allowedExperienceGain = true);
virtual ~Creature() = default;
virtual ~Creature();
virtual void Initialize() {
RecalculateFlatStats();