Reset seen opponents on ClearBattle.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2021-01-15 15:46:48 +01:00
parent 6edc9da536
commit 66b95a6e4d
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
4 changed files with 10 additions and 11 deletions

View File

@ -18,8 +18,9 @@ bool Battle::CanUse(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice) {
bool Battle::TrySetChoice(BaseTurnChoice* choice) {
EnsureNotNull(choice)
if (!CanUse(choice))
if (!CanUse(choice)) {
return false;
}
Ensure(choice->GetUser()->GetBattleSide().HasValue())
choice->GetUser()->GetBattleSide().GetValue()->SetChoice(choice);
CheckChoicesSetAndRun();
@ -28,12 +29,12 @@ bool Battle::TrySetChoice(BaseTurnChoice* choice) {
void Battle::CheckChoicesSetAndRun() {
try {
for (auto side : _sides) {
for (auto* side : _sides) {
if (!side->AllChoicesSet()) {
return;
}
}
for (auto side : _sides) {
for (auto* side : _sides) {
if (!side->AllPossibleSlotsFilled()) {
return;
}
@ -48,7 +49,7 @@ void Battle::CheckChoicesSetAndRun() {
auto choices = std::vector<std::shared_ptr<BaseTurnChoice>>(_numberOfSides * _creaturesPerSide);
auto i = 0;
try {
for (auto side : _sides) {
for (auto* side : _sides) {
for (auto choice : side->GetChoices()) {
EnsureNotNull(choice)
if (choice->GetKind() == TurnChoiceKind::Attack) {

View File

@ -11,8 +11,9 @@ bool BattleSide::AllPossibleSlotsFilled() const {
for (size_t i = 0; i < _creatures.Count(); i++) {
auto c = _creatures[i];
if (!c.HasValue() || c.GetValue()->IsFainted()) {
if (_battle->CanSlotBeFilled(_index, i))
if (_battle->CanSlotBeFilled(_index, i)) {
return false;
}
}
}
} catch (const std::exception& e) {

View File

@ -103,6 +103,7 @@ namespace CreatureLib::Battling {
void Creature::ClearBattleData() noexcept {
_battle = nullptr;
_side = nullptr;
_seenOpponents = {};
}
bool Creature::ChangeStatBoost(Library::Statistic stat, int8_t diffAmount) {
@ -135,10 +136,6 @@ namespace CreatureLib::Battling {
this->_boostedStats.SetStat(stat, s);
}
const ArbUt::OptionalBorrowedPtr<Battle>& Creature::GetBattle() const { return _battle; }
const ArbUt::OptionalBorrowedPtr<BattleSide>& Creature::GetBattleSide() const { return _side; }
bool Creature::IsFainted() const noexcept { return this->_currentHealth == 0; }
void Creature::OnFaint() {

View File

@ -106,8 +106,8 @@ namespace CreatureLib::Battling {
void SetBattleData(const ArbUt::BorrowedPtr<Battle>& battle, const ArbUt::BorrowedPtr<BattleSide>& side);
void ClearBattleData() noexcept;
const ArbUt::OptionalBorrowedPtr<Battle>& GetBattle() const;
const ArbUt::OptionalBorrowedPtr<BattleSide>& GetBattleSide() const;
inline const ArbUt::OptionalBorrowedPtr<Battle>& GetBattle() const { return _battle; }
inline const ArbUt::OptionalBorrowedPtr<BattleSide>& GetBattleSide() const { return _side; }
inline void SetOnBattleField(bool value) { _onBattleField = value; }
inline bool IsOnBattleField() const { return _onBattleField; }