Initial support for setting battle choices.
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:
@@ -1,5 +1,21 @@
|
||||
#include "Battle.hpp"
|
||||
#include "../TurnChoices/AttackTurnChoice.hpp"
|
||||
|
||||
const CreatureLib::Battling::BattleLibrary *CreatureLib::Battling::Battle::GetLibrary() const {
|
||||
return _library;
|
||||
}
|
||||
|
||||
bool CreatureLib::Battling::Battle::CanUse(CreatureLib::Battling::BaseTurnChoice *choice) {
|
||||
if (choice->GetKind() == TurnChoiceKind::Attack)
|
||||
//HOOK: change number of uses needed.
|
||||
return static_cast<AttackTurnChoice*>(choice)->GetAttack()->GetRemainingUses() > 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CreatureLib::Battling::Battle::TrySetChoice(CreatureLib::Battling::BaseTurnChoice *choice) {
|
||||
if (!CanUse(choice))
|
||||
return false;
|
||||
choice->GetUser()->GetBattleSide()->SetChoice(choice);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include "BattleSide.hpp"
|
||||
#include "../Library/BattleLibrary.hpp"
|
||||
#include "../TurnChoices/BaseTurnChoice.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class Battle {
|
||||
@@ -11,6 +12,9 @@ namespace CreatureLib::Battling {
|
||||
std::vector<BattleSide*> _sides;
|
||||
public:
|
||||
const BattleLibrary* GetLibrary() const;
|
||||
|
||||
virtual bool CanUse(BaseTurnChoice* choice);
|
||||
virtual bool TrySetChoice(BaseTurnChoice* choice);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1,35 @@
|
||||
#include "BattleSide.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
bool BattleSide::AllChoicesSet() const {
|
||||
for (uint8_t i = 0; i < _creaturesPerSide; i++){
|
||||
if (_choices[i] == nullptr){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void BattleSide::ResetChoices() {
|
||||
for (uint8_t i = 0; i < _creaturesPerSide; i++){
|
||||
_choices[i] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<const BaseTurnChoice *>& BattleSide::GetChoices() const{
|
||||
return _choices;
|
||||
}
|
||||
|
||||
void BattleSide::SetChoice(const BaseTurnChoice *choice) {
|
||||
auto find = std::find(_creatures.begin(), _creatures.end(), choice->GetUser());
|
||||
if (find ==_creatures.end())
|
||||
throw "User not found";
|
||||
uint8_t index = std::distance(_creatures.begin(),find);
|
||||
_choices[index] = choice;
|
||||
}
|
||||
|
||||
void BattleSide::SetCreature(Creature *creature, uint8_t index) {
|
||||
_creatures[index] = creature;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,28 @@
|
||||
|
||||
#include <vector>
|
||||
#include "Creature.hpp"
|
||||
#include "../TurnChoices/BaseTurnChoice.hpp"
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
class BattleSide {
|
||||
uint8_t _creaturesPerSide;
|
||||
std::vector<Creature*> _creatures;
|
||||
std::vector<const BaseTurnChoice*> _choices;
|
||||
public:
|
||||
BattleSide(uint8_t creaturesPerSide)
|
||||
: _creaturesPerSide(creaturesPerSide), _creatures(creaturesPerSide), _choices(creaturesPerSide)
|
||||
{
|
||||
ResetChoices();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool AllChoicesSet() const;
|
||||
[[nodiscard]] const std::vector<const BaseTurnChoice*>& GetChoices() const;
|
||||
|
||||
void SetChoice(const BaseTurnChoice* choice);
|
||||
void ResetChoices();
|
||||
|
||||
void SetCreature(Creature* creature, uint8_t index);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,11 @@ const std::string &Battling::Creature::GetTalent() const {
|
||||
return __Variant->GetTalent(_talentIndex);
|
||||
}
|
||||
|
||||
void Battling::Creature::SetBattleData(Battling::Battle *battle, Battling::BattleSide *side) {
|
||||
_battle = battle;
|
||||
_side = side;
|
||||
}
|
||||
|
||||
//region Stat APIs
|
||||
|
||||
void Battling::Creature::ChangeStatBoost(Core::Statistic stat, int8_t diffAmount){
|
||||
@@ -98,4 +103,13 @@ void Battling::Creature::RecalculateBoostedStat(Core::Statistic stat) {
|
||||
this->_boostedStats.SetStat(stat, s);
|
||||
}
|
||||
|
||||
Battling::Battle *Battling::Creature::GetBattle() const{
|
||||
return _battle;
|
||||
}
|
||||
|
||||
Battling::BattleSide *Battling::Creature::GetBattleSide() const {
|
||||
return _side;
|
||||
}
|
||||
|
||||
|
||||
//endregion
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
namespace CreatureLib::Battling{
|
||||
// Forward declare battle class
|
||||
class Battle;
|
||||
class BattleSide;
|
||||
|
||||
class Creature {
|
||||
GetProperty(const Library::CreatureSpecies*, Species);
|
||||
@@ -29,6 +30,7 @@ namespace CreatureLib::Battling{
|
||||
Core::StatisticSet<uint32_t > _boostedStats;
|
||||
|
||||
Battle* _battle;
|
||||
BattleSide* _side;
|
||||
BattleLibrary* _library;
|
||||
|
||||
std::string _nickname = "";
|
||||
@@ -46,6 +48,11 @@ namespace CreatureLib::Battling{
|
||||
|
||||
void ChangeLevel(int8_t amount);
|
||||
|
||||
void SetBattleData(Battle* battle, BattleSide* side);
|
||||
|
||||
Battle* GetBattle() const;
|
||||
BattleSide* GetBattleSide() const;
|
||||
|
||||
//region Stat APIs
|
||||
|
||||
void SetBattle(Battle* battle);
|
||||
|
||||
Reference in New Issue
Block a user