Add new Creature::IsUsable function, which replaces IsFainted functionality in several places.
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
8241a2d7b1
commit
762915b1f7
|
@ -50,8 +50,8 @@ void TurnHandler::ExecuteChoice(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice
|
|||
if (battle->HasEnded()) {
|
||||
return;
|
||||
}
|
||||
// If the user is fainted, we don't want to execute its choice.
|
||||
if (user->IsFainted()) {
|
||||
// If the user is not usable, we don't want to execute its choice.
|
||||
if (!user->IsUsable()) {
|
||||
return;
|
||||
}
|
||||
// If the user is not in the field, we don't want to execute its choice.
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
void CreatureLib::Battling::ExperienceLibrary::HandleExperienceGain(
|
||||
CreatureLib::Battling::Creature* faintedMon,
|
||||
const std::unordered_set<ArbUt::BorrowedPtr<Creature>>& opponents) const {
|
||||
for (auto opponent : opponents) {
|
||||
for (const auto& opponent : opponents) {
|
||||
if (opponent->IsFainted())
|
||||
continue;
|
||||
if (!opponent->AllowedExperienceGain())
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace CreatureLib::Battling {
|
|||
for (const auto& creature : p) {
|
||||
if (creature == nullptr)
|
||||
continue;
|
||||
if (creature->IsFainted())
|
||||
if (!creature->IsUsable())
|
||||
continue;
|
||||
if (creature->IsOnBattleField())
|
||||
continue;
|
||||
|
|
|
@ -10,7 +10,7 @@ bool BattleSide::AllPossibleSlotsFilled() const {
|
|||
try {
|
||||
for (size_t i = 0; i < _creatures.Count(); i++) {
|
||||
auto c = _creatures[i];
|
||||
if (!c.HasValue() || c.GetValue()->IsFainted()) {
|
||||
if (!c.HasValue() || !c.GetValue()->IsUsable()) {
|
||||
if (_battle->CanSlotBeFilled(_index, i)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -143,6 +143,8 @@ namespace CreatureLib::Battling {
|
|||
this->_boostedStats.SetStat(stat, s);
|
||||
}
|
||||
|
||||
bool Creature::IsUsable() const noexcept { return !this->IsFainted(); }
|
||||
|
||||
bool Creature::IsFainted() const noexcept { return this->_currentHealth == 0; }
|
||||
|
||||
void Creature::OnFaint() {
|
||||
|
|
|
@ -122,6 +122,8 @@ namespace CreatureLib::Battling {
|
|||
const CreatureLib::Library::TalentIndex& GetRealTalent() const noexcept { return _talentIndex; }
|
||||
const ArbUt::StringView& GetActiveTalent() const;
|
||||
|
||||
/// Are we allowed to use this creature in a battle?
|
||||
[[nodiscard]] virtual bool IsUsable() const noexcept;
|
||||
[[nodiscard]] bool IsFainted() const noexcept;
|
||||
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const noexcept;
|
||||
[[nodiscard]] bool HasType(uint8_t type) const noexcept;
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace CreatureLib::Battling {
|
|||
for (Creature* c : _party) {
|
||||
if (c == nullptr)
|
||||
continue;
|
||||
if (c->IsFainted())
|
||||
if (!c->IsUsable())
|
||||
continue;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <exception>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
|
Loading…
Reference in New Issue