Furter rework on script hooks, simplifying required logic.
This commit is contained in:
@@ -14,7 +14,7 @@ const BattleLibrary *Battle::GetLibrary() const {
|
||||
bool Battle::CanUse(const BaseTurnChoice *choice) {
|
||||
if (choice->GetKind() == TurnChoiceKind::Attack){
|
||||
//HOOK: change number of uses needed.
|
||||
return static_cast<const AttackTurnChoice*>(choice)->GetAttack()->GetRemainingUses() > 1;
|
||||
return dynamic_cast<const AttackTurnChoice*>(choice)->GetAttack()->GetRemainingUses() > 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ void Battle::CheckChoicesSetAndRun() {
|
||||
auto choices = std::vector<const BaseTurnChoice*>(_numberOfSides * _creaturesPerSide);
|
||||
auto i = 0;
|
||||
for (auto side: _sides){
|
||||
for (auto choice: side->GetChoices()){
|
||||
for (const BaseTurnChoice* choice: side->GetChoices()){
|
||||
if (choice->GetKind() == TurnChoiceKind::Attack){
|
||||
auto attack = dynamic_cast<const AttackTurnChoice*>(choice)->GetAttack();
|
||||
uint8_t uses = 1;
|
||||
@@ -92,3 +92,7 @@ void Battle::FillRecall(uint8_t side, uint8_t, Creature *c) {
|
||||
TurnHandler::RunTurn(this, _currentTurnQueue);
|
||||
}
|
||||
}
|
||||
|
||||
void Battle::GetActiveScripts(ScriptAggregator &aggr) const {
|
||||
aggr.Add(&_volatile);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "Target.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class Battle {
|
||||
class Battle : public ScriptSource{
|
||||
const BattleLibrary* _library;
|
||||
uint8_t _numberOfSides;
|
||||
uint8_t _creaturesPerSide;
|
||||
@@ -18,6 +18,7 @@ namespace CreatureLib::Battling {
|
||||
ChoiceQueue* _currentTurnQueue = nullptr;
|
||||
|
||||
uint8_t _numberOfRecalledSlots = 0;
|
||||
ScriptSet _volatile;
|
||||
public:
|
||||
[[nodiscard]] const BattleLibrary* GetLibrary() const;
|
||||
|
||||
@@ -40,6 +41,8 @@ namespace CreatureLib::Battling {
|
||||
void ForceRecall(uint8_t side, uint8_t index);
|
||||
|
||||
void FillRecall(uint8_t side, uint8_t, Creature* c);
|
||||
|
||||
void GetActiveScripts(ScriptAggregator &aggr) const override;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "BattleSide.hpp"
|
||||
#include "../../Core/Exceptions/CreatureException.hpp"
|
||||
#include <algorithm>
|
||||
#include "Battle.hpp"
|
||||
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
@@ -39,3 +40,8 @@ bool BattleSide::CreatureOnSide(const Creature *creature) const {
|
||||
Creature *BattleSide::GetCreature(uint8_t index) const {
|
||||
return _creatures[index];
|
||||
}
|
||||
|
||||
void BattleSide::GetActiveScripts(ScriptAggregator &aggr) const {
|
||||
aggr.Add(&_volatile);
|
||||
_battle->GetActiveScripts(aggr);
|
||||
}
|
||||
|
||||
@@ -6,14 +6,16 @@
|
||||
#include "../TurnChoices/BaseTurnChoice.hpp"
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
class BattleSide {
|
||||
class BattleSide : public ScriptSource{
|
||||
uint8_t _creaturesPerSide;
|
||||
std::vector<Creature*> _creatures;
|
||||
std::vector<const BaseTurnChoice*> _choices;
|
||||
uint8_t _choicesSet = 0;
|
||||
ScriptSet _volatile;
|
||||
Battle* _battle;
|
||||
public:
|
||||
BattleSide(uint8_t creaturesPerSide)
|
||||
: _creaturesPerSide(creaturesPerSide), _creatures(creaturesPerSide), _choices(creaturesPerSide)
|
||||
explicit BattleSide(Battle* battle, uint8_t creaturesPerSide)
|
||||
: _creaturesPerSide(creaturesPerSide), _creatures(creaturesPerSide), _choices(creaturesPerSide), _battle(battle)
|
||||
{
|
||||
ResetChoices();
|
||||
}
|
||||
@@ -29,6 +31,8 @@ namespace CreatureLib::Battling{
|
||||
Creature* GetCreature(uint8_t index) const;
|
||||
bool CreatureOnSide(const Creature* creature) const;
|
||||
|
||||
void GetActiveScripts(ScriptAggregator &aggr) const override;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -139,3 +139,9 @@ bool Battling::Creature::HasType(uint8_t type) const {
|
||||
auto t = GetTypes();
|
||||
return std::find(t.begin(), t.end(), type) != t.end();
|
||||
}
|
||||
|
||||
void Battling::Creature::GetActiveScripts(Battling::ScriptAggregator &aggr) const {
|
||||
aggr.Add(_status);
|
||||
aggr.Add(&_volatile);
|
||||
_side->GetActiveScripts(aggr);
|
||||
}
|
||||
|
||||
@@ -65,10 +65,7 @@ namespace CreatureLib::Battling{
|
||||
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
|
||||
[[nodiscard]] bool HasType(uint8_t type) const;
|
||||
|
||||
void GetActiveScripts(ScriptAggregator& aggr) override{
|
||||
aggr.Add(_status);
|
||||
aggr.Add(&_volatile);
|
||||
}
|
||||
void GetActiveScripts(ScriptAggregator& aggr) const override;
|
||||
|
||||
//region Stat APIs
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace CreatureLib::Battling {
|
||||
return _attack;
|
||||
}
|
||||
|
||||
void GetActiveScripts(ScriptAggregator &aggr) override {
|
||||
void GetActiveScripts(ScriptAggregator &aggr) const override {
|
||||
aggr.Add(_script);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user