Used ClangFormat style guide I'm happy with.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-11-28 12:55:22 +01:00
parent 3b685ae782
commit a8730d983f
91 changed files with 946 additions and 1121 deletions

View File

@@ -2,10 +2,7 @@
#define CREATURELIB_ATTACKLEARNMETHOD_HPP
namespace CreatureLib::Battling {
enum class AttackLearnMethod {
Unknown,
Level
};
enum class AttackLearnMethod { Unknown, Level };
}
#endif //CREATURELIB_ATTACKLEARNMETHOD_HPP
#endif // CREATURELIB_ATTACKLEARNMETHOD_HPP

View File

@@ -1,25 +1,22 @@
#include "Battle.hpp"
#include "../Flow/TurnHandler.hpp"
#include "../TurnChoices/AttackTurnChoice.hpp"
#include "../Flow/TurnOrdering.hpp"
#include "../../Core/Exceptions/NotImplementedException.hpp"
#include "../Flow/TurnHandler.hpp"
#include "../Flow/TurnOrdering.hpp"
using namespace CreatureLib;
using namespace CreatureLib::Battling;
const BattleLibrary *Battle::GetLibrary() const {
return _library;
}
const BattleLibrary* Battle::GetLibrary() const { return _library; }
bool Battle::CanUse(const BaseTurnChoice *choice) {
if (choice->GetKind() == TurnChoiceKind::Attack){
//HOOK: change number of uses needed.
bool Battle::CanUse(const BaseTurnChoice* choice) {
if (choice->GetKind() == TurnChoiceKind::Attack) {
// HOOK: change number of uses needed.
return dynamic_cast<const AttackTurnChoice*>(choice)->GetAttack()->GetRemainingUses() > 1;
}
return true;
}
bool Battle::TrySetChoice(BaseTurnChoice *choice) {
bool Battle::TrySetChoice(BaseTurnChoice* choice) {
if (!CanUse(choice))
return false;
choice->GetUser()->GetBattleSide()->SetChoice(choice);
@@ -28,29 +25,29 @@ bool Battle::TrySetChoice(BaseTurnChoice *choice) {
}
void Battle::CheckChoicesSetAndRun() {
for (auto side: _sides){
if (!side->AllChoicesSet()){
for (auto side : _sides) {
if (!side->AllChoicesSet()) {
return;
}
}
auto choices = std::vector<BaseTurnChoice*>(_numberOfSides * _creaturesPerSide);
auto i = 0;
for (auto side: _sides){
for (BaseTurnChoice* choice: side->GetChoices()){
if (choice->GetKind() == TurnChoiceKind::Attack){
auto attack = dynamic_cast<const AttackTurnChoice*>(choice)->GetAttack();
uint8_t uses = 1;
//HOOK: change number of uses needed.
if (attack->GetRemainingUses() < uses){
//TODO: Implement default move
throw NotImplementedException("Not enough remaining uses, change to default move.");
}
//HOOK: Check if we need to change the move
}
choices[i] = choice;
i++;
}
side->ResetChoices();
for (auto side : _sides) {
for (BaseTurnChoice* choice : side->GetChoices()) {
if (choice->GetKind() == TurnChoiceKind::Attack) {
auto attack = dynamic_cast<const AttackTurnChoice*>(choice)->GetAttack();
uint8_t uses = 1;
// HOOK: change number of uses needed.
if (attack->GetRemainingUses() < uses) {
// TODO: Implement default move
throw NotImplementedException("Not enough remaining uses, change to default move.");
}
// HOOK: Check if we need to change the move
}
choices[i] = choice;
i++;
}
side->ResetChoices();
}
TurnOrdering::OrderChoices(choices, _random);
auto choiceQueue = new ChoiceQueue(choices);
@@ -60,39 +57,31 @@ void Battle::CheckChoicesSetAndRun() {
_currentTurnQueue = nullptr;
}
ChoiceQueue* Battle::GetCurrentTurnQueue() const {
return _currentTurnQueue;
}
ChoiceQueue* Battle::GetCurrentTurnQueue() const { return _currentTurnQueue; }
Core::Random &Battle::GetRandom(){
return _random;
}
Core::Random& Battle::GetRandom() { return _random; }
bool Battle::CreatureInField(const Creature *creature) const {
for (auto s: _sides){
bool Battle::CreatureInField(const Creature* creature) const {
for (auto s : _sides) {
if (s->CreatureOnSide(creature))
return true;
}
return false;
}
bool Battle::HasRecalledSlots() const {
return _numberOfRecalledSlots > 0;
}
bool Battle::HasRecalledSlots() const { return _numberOfRecalledSlots > 0; }
void Battle::ForceRecall(uint8_t side, uint8_t index) {
_numberOfRecalledSlots++;
//TODO: Switch out.
// TODO: Switch out.
}
void Battle::FillRecall(uint8_t side, uint8_t, Creature *c) {
void Battle::FillRecall(uint8_t side, uint8_t, Creature* c) {
_numberOfRecalledSlots--;
//TODO: switch in.
if (_numberOfRecalledSlots == 0 && _currentTurnQueue != nullptr){
// TODO: switch in.
if (_numberOfRecalledSlots == 0 && _currentTurnQueue != nullptr) {
TurnHandler::RunTurn(this, _currentTurnQueue);
}
}
void Battle::GetActiveScripts(std::vector<ScriptWrapper> &scripts) {
scripts.emplace_back(&_volatile);
}
void Battle::GetActiveScripts(std::vector<ScriptWrapper>& scripts) { scripts.emplace_back(&_volatile); }

View File

@@ -2,14 +2,14 @@
#define CREATURELIB_BATTLE_HPP
#include <vector>
#include "BattleSide.hpp"
#include "../Flow/ChoiceQueue.hpp"
#include "../Library/BattleLibrary.hpp"
#include "../TurnChoices/BaseTurnChoice.hpp"
#include "../Flow/ChoiceQueue.hpp"
#include "BattleSide.hpp"
#include "Target.hpp"
namespace CreatureLib::Battling {
class Battle : public ScriptSource{
class Battle : public ScriptSource {
const BattleLibrary* _library;
uint8_t _numberOfSides;
uint8_t _creaturesPerSide;
@@ -19,6 +19,7 @@ namespace CreatureLib::Battling {
uint8_t _numberOfRecalledSlots = 0;
ScriptSet _volatile;
public:
[[nodiscard]] const BattleLibrary* GetLibrary() const;
@@ -32,7 +33,7 @@ namespace CreatureLib::Battling {
bool CreatureInField(const Creature* creature) const;
Creature* GetTarget(const Target& target){
Creature* GetTarget(const Target& target) {
return _sides[target.GetSideIndex()]->GetCreature(target.GetCreatureIndex());
}
@@ -42,9 +43,8 @@ namespace CreatureLib::Battling {
void FillRecall(uint8_t side, uint8_t, Creature* c);
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override;
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override;
};
}
#endif //CREATURELIB_BATTLE_HPP
#endif // CREATURELIB_BATTLE_HPP

View File

@@ -1,47 +1,39 @@
#include "BattleSide.hpp"
#include "../../Core/Exceptions/CreatureException.hpp"
#include <algorithm>
#include "../../Core/Exceptions/CreatureException.hpp"
#include "Battle.hpp"
using namespace CreatureLib::Battling;
bool BattleSide::AllChoicesSet() const {
return _choicesSet == _creaturesPerSide;
}
bool BattleSide::AllChoicesSet() const { return _choicesSet == _creaturesPerSide; }
void BattleSide::ResetChoices() {
_choicesSet = 0;
for (uint8_t i = 0; i < _creaturesPerSide; i++){
for (uint8_t i = 0; i < _creaturesPerSide; i++) {
_choices[i] = nullptr;
}
}
const std::vector<BaseTurnChoice *>& BattleSide::GetChoices() const{
return _choices;
}
const std::vector<BaseTurnChoice*>& BattleSide::GetChoices() const { return _choices; }
void BattleSide::SetChoice(BaseTurnChoice *choice) {
void BattleSide::SetChoice(BaseTurnChoice* choice) {
auto find = std::find(_creatures.begin(), _creatures.end(), choice->GetUser());
if (find ==_creatures.end())
if (find == _creatures.end())
throw CreatureException("User not found");
uint8_t index = std::distance(_creatures.begin(),find);
uint8_t index = std::distance(_creatures.begin(), find);
_choices[index] = choice;
_choicesSet++;
}
void BattleSide::SetCreature(Creature *creature, uint8_t index) {
_creatures[index] = creature;
}
void BattleSide::SetCreature(Creature* creature, uint8_t index) { _creatures[index] = creature; }
bool BattleSide::CreatureOnSide(const Creature *creature) const {
bool BattleSide::CreatureOnSide(const Creature* creature) const {
return std::find(_creatures.begin(), _creatures.end(), creature) != _creatures.end();
}
Creature *BattleSide::GetCreature(uint8_t index) const {
return _creatures[index];
}
Creature* BattleSide::GetCreature(uint8_t index) const { return _creatures[index]; }
void BattleSide::GetActiveScripts(std::vector<ScriptWrapper> &scripts) {
void BattleSide::GetActiveScripts(std::vector<ScriptWrapper>& scripts) {
scripts.emplace_back(&_volatile);
_battle->GetActiveScripts(scripts);
}

View File

@@ -2,21 +2,22 @@
#define CREATURELIB_BATTLESIDE_HPP
#include <vector>
#include "Creature.hpp"
#include "../TurnChoices/BaseTurnChoice.hpp"
#include "Creature.hpp"
namespace CreatureLib::Battling{
class BattleSide : public ScriptSource{
namespace CreatureLib::Battling {
class BattleSide : public ScriptSource {
uint8_t _creaturesPerSide;
std::vector<Creature*> _creatures;
std::vector<BaseTurnChoice*> _choices;
uint8_t _choicesSet = 0;
ScriptSet _volatile;
Battle* _battle;
public:
explicit BattleSide(Battle* battle, uint8_t creaturesPerSide)
: _creaturesPerSide(creaturesPerSide), _creatures(creaturesPerSide), _choices(creaturesPerSide), _battle(battle)
{
: _creaturesPerSide(creaturesPerSide), _creatures(creaturesPerSide), _choices(creaturesPerSide),
_battle(battle) {
ResetChoices();
}
@@ -31,10 +32,8 @@ namespace CreatureLib::Battling{
Creature* GetCreature(uint8_t index) const;
bool CreatureOnSide(const Creature* creature) const;
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override;
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override;
};
}
#endif //CREATURELIB_BATTLESIDE_HPP
#endif // CREATURELIB_BATTLESIDE_HPP

View File

@@ -1 +0,0 @@
#include "BattleTeam.hpp"

View File

@@ -1,10 +0,0 @@
#ifndef CREATURELIB_BATTLETEAM_HPP
#define CREATURELIB_BATTLETEAM_HPP
class BattleTeam {
};
#endif //CREATURELIB_BATTLETEAM_HPP

View File

@@ -1,7 +1,7 @@
#include "CreateCreature.hpp"
#include "../../Core/Exceptions/CreatureException.hpp"
#include "../Library/BattleLibrary.hpp"
#include <utility>
#include "../Library/BattleLibrary.hpp"
using namespace CreatureLib::Battling;
@@ -10,25 +10,25 @@ CreateCreature* CreateCreature::WithVariant(std::string variant) {
return this;
}
CreateCreature *CreateCreature::WithNickname(std::string nickname) {
CreateCreature* CreateCreature::WithNickname(std::string nickname) {
this->_nickname = std::move(nickname);
return this;
}
CreateCreature *CreateCreature::WithStatPotential(CreatureLib::Core::Statistic stat, uint32_t value) {
switch (stat){
case Core::Health:_healthPotential = value;
CreateCreature* CreateCreature::WithStatPotential(CreatureLib::Core::Statistic stat, uint32_t value) {
switch (stat) {
case Core::Health: _healthPotential = value;
case Core::PhysicalAttack: _physAttackPotential = value;
case Core::PhysicalDefense: _physDefensePotential = value;
case Core::MagicalAttack: _magAttackPotential = value;
case Core::MagicalDefense:_magDefensePotential = value;
case Core::MagicalDefense: _magDefensePotential = value;
case Core::Speed: _speedPotential = value;
}
return this;
}
CreateCreature * CreateCreature::WithStatPotentials(uint32_t health, uint32_t physAttack, uint32_t physDefense,
uint32_t magAttack, uint32_t magDefense, uint32_t speed) {
CreateCreature* CreateCreature::WithStatPotentials(uint32_t health, uint32_t physAttack, uint32_t physDefense,
uint32_t magAttack, uint32_t magDefense, uint32_t speed) {
_healthPotential = health;
_physAttackPotential = physAttack;
_physDefensePotential = physDefense;
@@ -39,20 +39,19 @@ CreateCreature * CreateCreature::WithStatPotentials(uint32_t health, uint32_t ph
}
CreateCreature* CreateCreature::WithStatExperience(Core::Statistic stat, uint32_t value) {
switch (stat){
case Core::Health:_healthExperience = value;
switch (stat) {
case Core::Health: _healthExperience = value;
case Core::PhysicalAttack: _physAttackExperience = value;
case Core::PhysicalDefense: _physDefenseExperience = value;
case Core::MagicalAttack: _magAttackExperience = value;
case Core::MagicalDefense:_magDefenseExperience = value;
case Core::MagicalDefense: _magDefenseExperience = value;
case Core::Speed: _speedExperience = value;
}
return this;
}
CreateCreature *
CreateCreature::WithStatExperiences(uint32_t health, uint32_t physAttack, uint32_t physDefense, uint32_t magAttack,
uint32_t magDefense, uint32_t speed) {
CreateCreature* CreateCreature::WithStatExperiences(uint32_t health, uint32_t physAttack, uint32_t physDefense,
uint32_t magAttack, uint32_t magDefense, uint32_t speed) {
_healthExperience = health;
_physAttackExperience = physAttack;
_physDefenseExperience = physDefense;
@@ -62,12 +61,12 @@ CreateCreature::WithStatExperiences(uint32_t health, uint32_t physAttack, uint32
return this;
}
CreateCreature *CreateCreature::WithGender(Library::Gender gender) {
CreateCreature* CreateCreature::WithGender(Library::Gender gender) {
this->_gender = gender;
return this;
}
CreateCreature *CreateCreature::WithAttack(const std::string& attackName, AttackLearnMethod learnMethod) {
CreateCreature* CreateCreature::WithAttack(const std::string& attackName, AttackLearnMethod learnMethod) {
if (_attacks.size() >= _library->GetSettings().GetMaximalMoves())
throw CreatureException("You have already set the maximum amount of allowed moves.");
@@ -76,44 +75,42 @@ CreateCreature *CreateCreature::WithAttack(const std::string& attackName, Attack
return this;
}
Creature *CreateCreature::Create() {
Creature* CreateCreature::Create() {
_hasCreated = true;
auto rand = Core::Random();
auto species = this->_library->GetSpeciesLibrary()->GetSpecies(this->_species);
auto variant = species->GetVariant(this->_variant);
int8_t talent;
if (this->_talent.empty()){
if (this->_talent.empty()) {
talent = variant->GetRandomTalent(&rand);
}
else{
} else {
talent = variant->GetTalentIndex(this->_talent);
}
auto identifier = this->_identifier;
if (identifier == 0){
if (identifier == 0) {
identifier = rand.Get();
}
auto gender = this->_gender;
if (gender == static_cast<Library::Gender >(-1)){
if (gender == static_cast<Library::Gender>(-1)) {
gender = species->GetRandomGender(rand);
}
const Library::Item* heldItem = nullptr;
if (!this->_heldItem.empty()){
if (!this->_heldItem.empty()) {
heldItem = _library->GetItemLibrary()->GetItem(this->_heldItem);
}
//FIXME: implement experience
// FIXME: implement experience
auto experience = 0;
auto statExperience = Core::StatisticSet(_healthExperience, _physAttackExperience,_physDefenseExperience, _magAttackExperience,
_magDefenseExperience, _speedExperience);
auto statPotential = Core::StatisticSet(_healthPotential, _physAttackPotential,_physDefensePotential, _magAttackPotential,
_magDefensePotential, _speedPotential);
auto statExperience = Core::StatisticSet(_healthExperience, _physAttackExperience, _physDefenseExperience,
_magAttackExperience, _magDefenseExperience, _speedExperience);
auto statPotential = Core::StatisticSet(_healthPotential, _physAttackPotential, _physDefensePotential,
_magAttackPotential, _magDefensePotential, _speedPotential);
auto attacks = std::vector<LearnedAttack*>(_attacks.size());
for (auto kv: _attacks){
for (auto kv : _attacks) {
attacks.push_back(new LearnedAttack(std::get<0>(kv), std::get<1>(kv)));
}
return new Creature(species, variant, _level, experience, statExperience,statPotential, identifier,gender, _coloring,
heldItem, _nickname, talent, attacks);
return new Creature(species, variant, _level, experience, statExperience, statPotential, identifier, gender,
_coloring, heldItem, _nickname, talent, attacks);
}

View File

@@ -1,13 +1,12 @@
#ifndef CREATURELIB_CREATECREATURE_HPP
#define CREATURELIB_CREATECREATURE_HPP
#include "../../Library/DataLibrary.hpp"
#include "Creature.hpp"
namespace CreatureLib::Battling {
class CreateCreature {
const BattleLibrary *_library;
const BattleLibrary* _library;
std::string _species;
std::string _variant = "default";
uint8_t _level;
@@ -28,7 +27,7 @@ namespace CreatureLib::Battling {
uint8_t _speedExperience = 0;
std::string _talent = "";
Library::Gender _gender = static_cast<Library::Gender>(-1);
Library::Gender _gender = static_cast<Library::Gender>(-1);
uint8_t _coloring = 0;
std::string _heldItem = "";
uint32_t _identifier = 0;
@@ -37,26 +36,22 @@ namespace CreatureLib::Battling {
bool _hasCreated;
public:
CreateCreature(const BattleLibrary *library, std::string species, uint8_t level)
: _library(library), _species(std::move(species)), _level(level)
{
}
CreateCreature(const BattleLibrary* library, std::string species, uint8_t level)
: _library(library), _species(std::move(species)), _level(level) {}
CreateCreature* WithVariant(std::string variant);
CreateCreature* WithNickname(std::string nickname);
CreateCreature* WithStatPotential(Core::Statistic stat, uint32_t value);
CreateCreature* WithStatPotentials(uint32_t health, uint32_t physAttack, uint32_t physDefense, uint32_t magAttack,
uint32_t magDefense,uint32_t speed);
CreateCreature* WithStatPotentials(uint32_t health, uint32_t physAttack, uint32_t physDefense,
uint32_t magAttack, uint32_t magDefense, uint32_t speed);
CreateCreature* WithStatExperience(Core::Statistic stat, uint32_t value);
CreateCreature* WithStatExperiences(uint32_t health, uint32_t physAttack, uint32_t physDefense, uint32_t magAttack,
uint32_t magDefense,uint32_t speed);
CreateCreature* WithStatExperiences(uint32_t health, uint32_t physAttack, uint32_t physDefense,
uint32_t magAttack, uint32_t magDefense, uint32_t speed);
CreateCreature* WithGender(Library::Gender gender);
CreateCreature* WithAttack(const std::string& attackName, AttackLearnMethod learnMethod);
Creature* Create();
};
}
#endif //CREATURELIB_CREATECREATURE_HPP
#endif // CREATURELIB_CREATECREATURE_HPP

View File

@@ -1,6 +1,6 @@
#include "Creature.hpp"
#include <algorithm>
#include <utility>
#include "Creature.hpp"
#include "../Models/Battle.hpp"
using namespace CreatureLib;
@@ -8,64 +8,48 @@ using namespace CreatureLib;
Battling::Creature::Creature(const Library::CreatureSpecies* species, const Library::SpeciesVariant* variant,
uint8_t level, uint32_t experience, Core::StatisticSet<uint8_t> statExp,
Core::StatisticSet<uint8_t> statPotential, uint32_t uid, Library::Gender gender,
uint8_t coloring, const Library::Item *heldItem, std::string nickname, int8_t talent,
std::vector<LearnedAttack *> attacks)
:
__Species(species),
__Variant(variant),
__Level(level),
__Experience(experience),
__StatExperience(statExp),
__StatPotential(statPotential),
__UniqueIdentifier(uid),
__Gender(gender),
__Coloring(coloring),
__HeldItem(heldItem),
_nickname(std::move(nickname)),
_talentIndex(talent),
_hasOverridenTalent(false),
_attacks(std::move(attacks))
{
uint8_t coloring, const Library::Item* heldItem, std::string nickname, int8_t talent,
std::vector<LearnedAttack*> attacks)
: __Species(species), __Variant(variant), __Level(level), __Experience(experience), __StatExperience(statExp),
__StatPotential(statPotential), __UniqueIdentifier(uid), __Gender(gender), __Coloring(coloring),
__HeldItem(heldItem), _nickname(std::move(nickname)), _talentIndex(talent), _hasOverridenTalent(false),
_attacks(std::move(attacks)) {
__CurrentHealth = GetBoostedStat(Core::Statistic::Health);
}
void Battling::Creature::ChangeLevel(int8_t amount) {
this->__Level += amount;
RecalculateFlatStats();
}
void Battling::Creature::SetBattle(Battling::Battle *battle) {
this->_battle = battle;
}
void Battling::Creature::SetBattle(Battling::Battle* battle) { this->_battle = battle; }
void Battling::Creature::SetBattleLibrary(Battling::BattleLibrary *library) {
void Battling::Creature::SetBattleLibrary(Battling::BattleLibrary* library) {
this->_library = library;
_activeTalent = _library->LoadScript(ScriptResolver::ScriptCategory::Talent, GetActiveTalent());
}
const std::string &Battling::Creature::GetNickname() const {
const std::string& Battling::Creature::GetNickname() const {
if (_nickname.empty())
return __Species->GetName();
return _nickname;
}
const std::string &Battling::Creature::GetActiveTalent() const {
if (_hasOverridenTalent){
const std::string& Battling::Creature::GetActiveTalent() const {
if (_hasOverridenTalent) {
return _overridenTalentName;
}
return __Variant->GetTalent(_talentIndex);
}
void Battling::Creature::SetBattleData(Battling::Battle *battle, Battling::BattleSide *side) {
void Battling::Creature::SetBattleData(Battling::Battle* battle, Battling::BattleSide* side) {
_battle = battle;
_side = side;
}
//region Stat APIs
// region Stat APIs
void Battling::Creature::ChangeStatBoost(Core::Statistic stat, int8_t diffAmount){
void Battling::Creature::ChangeStatBoost(Core::Statistic stat, int8_t diffAmount) {
if (diffAmount > 0)
this->_statBoost.IncreaseStatBy(stat, diffAmount);
else
@@ -73,29 +57,17 @@ void Battling::Creature::ChangeStatBoost(Core::Statistic stat, int8_t diffAmount
this->RecalculateBoostedStat(stat);
}
uint32_t Battling::Creature::GetFlatStat(Core::Statistic stat) const{
return _flatStats.GetStat(stat);
}
uint32_t Battling::Creature::GetFlatStat(Core::Statistic stat) const { return _flatStats.GetStat(stat); }
uint32_t Battling::Creature::GetBoostedStat(Core::Statistic stat) const{
return _boostedStats.GetStat(stat);
}
uint32_t Battling::Creature::GetBoostedStat(Core::Statistic stat) const { return _boostedStats.GetStat(stat); }
uint32_t Battling::Creature::GetBaseStat(Core::Statistic stat) const {
return __Variant->GetStatistic(stat);
}
uint32_t Battling::Creature::GetBaseStat(Core::Statistic stat) const { return __Variant->GetStatistic(stat); }
uint32_t Battling::Creature::GetStatPotential(Core::Statistic stat) const {
return __StatPotential.GetStat(stat);
}
uint32_t Battling::Creature::GetStatPotential(Core::Statistic stat) const { return __StatPotential.GetStat(stat); }
uint32_t Battling::Creature::GetStatExperience(Core::Statistic stat) const {
return __StatExperience.GetStat(stat);
}
uint32_t Battling::Creature::GetStatExperience(Core::Statistic stat) const { return __StatExperience.GetStat(stat); }
int8_t Battling::Creature::GetStatBoost(Core::Statistic stat) const {
return _statBoost.GetStat(stat);
}
int8_t Battling::Creature::GetStatBoost(Core::Statistic stat) const { return _statBoost.GetStat(stat); }
void Battling::Creature::RecalculateFlatStats() {
this->_flatStats = this->_library->GetStatCalculator()->CalculateFlatStats(this);
@@ -116,36 +88,30 @@ void Battling::Creature::RecalculateBoostedStat(Core::Statistic stat) {
this->_boostedStats.SetStat(stat, s);
}
//endregion
// endregion
Battling::Battle *Battling::Creature::GetBattle() const{
return _battle;
}
Battling::Battle* Battling::Creature::GetBattle() const { return _battle; }
Battling::BattleSide *Battling::Creature::GetBattleSide() const {
return _side;
}
Battling::BattleSide* Battling::Creature::GetBattleSide() const { return _side; }
bool Battling::Creature::IsFainted() const {
return this->__CurrentHealth <= 0;
}
bool Battling::Creature::IsFainted() const { return this->__CurrentHealth <= 0; }
void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source) {
if (damage > __CurrentHealth){
if (damage > __CurrentHealth) {
damage = __CurrentHealth;
}
// HOOK: On Damage
__CurrentHealth -= damage;
}
void Battling::Creature::OverrideActiveTalent(const std::string& talent){
void Battling::Creature::OverrideActiveTalent(const std::string& talent) {
_hasOverridenTalent = true;
_overridenTalentName = talent;
_activeTalent = this->_library->LoadScript(ScriptResolver::ScriptCategory::Talent, talent);
}
const std::vector<uint8_t>& Battling::Creature::GetTypes() const {
//HOOK: override types.
// HOOK: override types.
return this->__Variant->GetTypes();
}
@@ -154,7 +120,7 @@ bool Battling::Creature::HasType(uint8_t type) const {
return std::find(t.begin(), t.end(), type) != t.end();
}
void Battling::Creature::GetActiveScripts(std::vector<ScriptWrapper> &scripts) {
void Battling::Creature::GetActiveScripts(std::vector<ScriptWrapper>& scripts) {
scripts.emplace_back(&_activeTalent);
scripts.emplace_back(&_status);
scripts.emplace_back(&_volatile);

View File

@@ -4,37 +4,36 @@
#include "../../GenericTemplates.cpp"
#include "../../Library/CreatureData/CreatureSpecies.hpp"
#include "../../Library/Items/Item.hpp"
#include "LearnedAttack.hpp"
#include "DamageSource.hpp"
#include "../ScriptHandling/ScriptSet.hpp"
#include "../ScriptHandling/ScriptAggregator.hpp"
#include "../ScriptHandling/ScriptSet.hpp"
#include "../ScriptHandling/ScriptSource.hpp"
#include "DamageSource.hpp"
#include "LearnedAttack.hpp"
namespace CreatureLib::Battling{
namespace CreatureLib::Battling {
// Forward declare battle class
class Battle;
class BattleSide;
class BattleLibrary;
class Creature : public ScriptSource{
class Creature : public ScriptSource {
GetProperty(const Library::CreatureSpecies*, Species);
GetProperty(const Library::SpeciesVariant*, Variant)
GetProperty(const Library::SpeciesVariant*, Variant);
GetProperty(uint8_t, Level);
GetProperty(uint32_t, Experience);
GetProperty(Core::StatisticSet<uint8_t >, StatExperience);
GetProperty(Core::StatisticSet<uint8_t >, StatPotential);
GetProperty(Core::StatisticSet<uint8_t>, StatExperience);
GetProperty(Core::StatisticSet<uint8_t>, StatPotential);
GetProperty(uint32_t, UniqueIdentifier);
GetProperty(Library::Gender, Gender);
GetProperty(uint8_t, Coloring);
GetProperty(const Library::Item*, HeldItem);
GetProperty(uint32_t, CurrentHealth);
private:
Core::StatisticSet<int8_t > _statBoost;
Core::StatisticSet<uint32_t > _flatStats;
Core::StatisticSet<uint32_t > _boostedStats;
Core::StatisticSet<int8_t> _statBoost;
Core::StatisticSet<uint32_t> _flatStats;
Core::StatisticSet<uint32_t> _boostedStats;
Battle* _battle;
BattleSide* _side;
@@ -54,9 +53,9 @@ namespace CreatureLib::Battling{
public:
Creature(const Library::CreatureSpecies* species, const Library::SpeciesVariant* variant, uint8_t level,
uint32_t experience, Core::StatisticSet<uint8_t > statExp, Core::StatisticSet<uint8_t > statPotential,
uint32_t uid, Library::Gender gender, uint8_t coloring, const Library::Item* heldItem, std::string nickname,
int8_t talent, std::vector<LearnedAttack*> attacks);
uint32_t experience, Core::StatisticSet<uint8_t> statExp, Core::StatisticSet<uint8_t> statPotential,
uint32_t uid, Library::Gender gender, uint8_t coloring, const Library::Item* heldItem,
std::string nickname, int8_t talent, std::vector<LearnedAttack*> attacks);
virtual ~Creature() = default;
@@ -75,10 +74,9 @@ namespace CreatureLib::Battling{
void Damage(uint32_t damage, DamageSource source);
void OverrideActiveTalent(const std::string& talent);
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override;
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override;
//region Stat APIs
// region Stat APIs
void SetBattle(Battle* battle);
void SetBattleLibrary(BattleLibrary* library);
@@ -95,11 +93,8 @@ namespace CreatureLib::Battling{
void RecalculateFlatStat(Core::Statistic);
void RecalculateBoostedStat(Core::Statistic);
//endregion
// endregion
};
}
#endif //CREATURELIB_CREATURE_HPP
#endif // CREATURELIB_CREATURE_HPP

View File

@@ -4,29 +4,27 @@
#include <array>
#include "Creature.hpp"
namespace CreatureLib::Battling{
template <int max>
class CreatureParty {
namespace CreatureLib::Battling {
template <int max> class CreatureParty {
std::array<Creature*, max> _party;
public:
CreatureParty(std::array<Creature*, max> party) : _party(party){
}
CreatureParty(std::array<Creature*, max> party) : _party(party) {}
Creature* GetAtIndex(int index) const{
return _party[index];
}
Creature* GetAtIndex(int index) const { return _party[index]; }
void Switch(int a, int b){
void Switch(int a, int b) {
auto ca = _party[a];
_party[a] = _party[b];
_party[b] = ca;
}
bool HasAvailableCreatures() const{
for (Creature* c: _party){
if (c == nullptr) continue;
if (c->IsFainted()) continue;
bool HasAvailableCreatures() const {
for (Creature* c : _party) {
if (c == nullptr)
continue;
if (c->IsFainted())
continue;
return true;
}
return false;
@@ -34,5 +32,4 @@ namespace CreatureLib::Battling{
};
}
#endif //CREATURELIB_CREATUREPARTY_HPP
#endif // CREATURELIB_CREATUREPARTY_HPP

View File

@@ -9,4 +9,4 @@ namespace CreatureLib::Battling {
};
}
#endif //CREATURELIB_DAMAGESOURCE_HPP
#endif // CREATURELIB_DAMAGESOURCE_HPP

View File

@@ -2,63 +2,55 @@
#define CREATURELIB_EXECUTINGATTACK_HPP
#include <cstdint>
#include <vector>
#include <unordered_map>
#include <vector>
#include "Creature.hpp"
namespace CreatureLib::Battling {
class ExecutingAttack : public ScriptSource {
public:
class HitData{
class HitData {
bool _critical = false;
uint8_t _basePower = 0;
float _effectiveness = 1;
uint32_t _damage = 0;
uint8_t _type = 0;
public:
HitData(){}
HitData() {}
[[nodiscard]] inline bool IsCritical() const{ return _critical;}
[[nodiscard]] inline uint8_t GetBasePower() const{ return _basePower;}
[[nodiscard]] inline float GetEffectiveness() const{ return _effectiveness;}
[[nodiscard]] inline uint32_t GetDamage() const{ return _damage;}
[[nodiscard]] inline uint8_t GetType() const {return _type;}
[[nodiscard]] inline bool IsCritical() const { return _critical; }
[[nodiscard]] inline uint8_t GetBasePower() const { return _basePower; }
[[nodiscard]] inline float GetEffectiveness() const { return _effectiveness; }
[[nodiscard]] inline uint32_t GetDamage() const { return _damage; }
[[nodiscard]] inline uint8_t GetType() const { return _type; }
inline void SetCritical(bool value) {_critical = value;}
inline void SetCritical(bool value) { _critical = value; }
inline void SetBasePower(uint8_t value) { _basePower = value; }
inline void SetEffectiveness(float value) {_effectiveness = value;}
inline void SetDamage(uint32_t value) { _damage = value;}
inline void SetType(uint8_t value) {_type = value;}
inline void SetEffectiveness(float value) { _effectiveness = value; }
inline void SetDamage(uint32_t value) { _damage = value; }
inline void SetType(uint8_t value) { _type = value; }
};
class TargetData {
bool _isHit = true;
std::vector<HitData> _hits;
public:
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits)
{
for (uint8_t i = 0; i < numberOfHits; i++){
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits) {
for (uint8_t i = 0; i < numberOfHits; i++) {
_hits[i] = HitData();
}
}
TargetData()= default;
TargetData() = default;
const HitData& GetHit(uint8_t index) const{
return _hits[index];
}
const HitData& GetHit(uint8_t index) const { return _hits[index]; }
HitData* GetHitPtr(uint8_t index){
return &_hits[index];
}
HitData* GetHitPtr(uint8_t index) { return &_hits[index]; }
uint8_t GetNumberOfHits() const{
return _hits.size();
}
bool IsHit() const{
return _isHit;
}
uint8_t GetNumberOfHits() const { return _hits.size(); }
bool IsHit() const { return _isHit; }
};
private:
@@ -66,45 +58,35 @@ namespace CreatureLib::Battling {
Creature* _user;
LearnedAttack* _attack;
Script* _script;
public:
ExecutingAttack(const std::vector<Creature*>& targets, uint8_t numberHits, Creature* user, LearnedAttack* attack,
Script* script)
: _user(user), _attack(attack), _script(script)
{
ExecutingAttack(const std::vector<Creature*>& targets, uint8_t numberHits, Creature* user,
LearnedAttack* attack, Script* script)
: _user(user), _attack(attack), _script(script) {
_targets.reserve(targets.size());
for (auto target: targets){
for (auto target : targets) {
_targets.insert({target, TargetData(numberHits)});
}
}
virtual ~ExecutingAttack() = default;
TargetData& GetAttackDataForTarget(Creature* creature){
return _targets[creature];
}
TargetData& GetAttackDataForTarget(Creature* creature) { return _targets[creature]; }
bool IsCreatureTarget(Creature* creature){
return _targets.find(creature) != _targets.end();
}
bool IsCreatureTarget(Creature* creature) { return _targets.find(creature) != _targets.end(); }
const std::unordered_map<Creature*, TargetData>& GetTargets(){
return _targets;
}
const std::unordered_map<Creature*, TargetData>& GetTargets() { return _targets; }
Creature* GetUser(){
return _user;
}
Creature* GetUser() { return _user; }
LearnedAttack* GetAttack(){
return _attack;
}
LearnedAttack* GetAttack() { return _attack; }
protected:
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override {
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override {
scripts.emplace_back(&_script);
GetUser()->GetActiveScripts(scripts);
}
};
}
#endif //CREATURELIB_EXECUTINGATTACK_HPP
#endif // CREATURELIB_EXECUTINGATTACK_HPP

View File

@@ -1,48 +1,32 @@
#include "LearnedAttack.hpp"
CreatureLib::Battling::LearnedAttack::LearnedAttack(CreatureLib::Library::AttackData *attack, uint8_t maxUses, AttackLearnMethod learnMethod)
:_attack(attack), _maxUses(maxUses), _remainingUses(maxUses), _learnMethod(learnMethod)
{
CreatureLib::Battling::LearnedAttack::LearnedAttack(CreatureLib::Library::AttackData* attack, uint8_t maxUses,
AttackLearnMethod learnMethod)
: _attack(attack), _maxUses(maxUses), _remainingUses(maxUses), _learnMethod(learnMethod) {}
}
CreatureLib::Battling::LearnedAttack::LearnedAttack(const CreatureLib::Library::AttackData* attack,
AttackLearnMethod learnMethod)
: _attack(attack), _maxUses(attack->GetBaseUsages()), _remainingUses(_maxUses), _learnMethod(learnMethod) {}
CreatureLib::Battling::LearnedAttack::LearnedAttack(const CreatureLib::Library::AttackData *attack, AttackLearnMethod learnMethod)
: _attack(attack), _maxUses(attack->GetBaseUsages()), _remainingUses(_maxUses), _learnMethod(learnMethod)
{}
const CreatureLib::Library::AttackData* CreatureLib::Battling::LearnedAttack::GetAttack() const { return _attack; }
uint8_t CreatureLib::Battling::LearnedAttack::GetMaxUses() const { return _maxUses; }
const CreatureLib::Library::AttackData *CreatureLib::Battling::LearnedAttack::GetAttack() const {
return _attack;
}
uint8_t CreatureLib::Battling::LearnedAttack::GetMaxUses() const {
return _maxUses;
}
uint8_t CreatureLib::Battling::LearnedAttack::GetRemainingUses() const {
return _remainingUses;
}
uint8_t CreatureLib::Battling::LearnedAttack::GetRemainingUses() const { return _remainingUses; }
CreatureLib::Battling::AttackLearnMethod CreatureLib::Battling::LearnedAttack::GetLearnMethod() const {
return _learnMethod;
}
bool CreatureLib::Battling::LearnedAttack::TryUse(uint8_t uses) {
if (uses > _remainingUses) return false;
if (uses > _remainingUses)
return false;
_remainingUses -= uses;
return true;
}
void CreatureLib::Battling::LearnedAttack::DecreaseUses(uint8_t amount) {
_remainingUses -= amount;
}
void CreatureLib::Battling::LearnedAttack::DecreaseUses(uint8_t amount) { _remainingUses -= amount; }
void CreatureLib::Battling::LearnedAttack::RestoreUses(uint8_t amount) {
_remainingUses += amount;
}
void CreatureLib::Battling::LearnedAttack::RestoreUses() {
_remainingUses = _maxUses;
}
void CreatureLib::Battling::LearnedAttack::RestoreUses(uint8_t amount) { _remainingUses += amount; }
void CreatureLib::Battling::LearnedAttack::RestoreUses() { _remainingUses = _maxUses; }

View File

@@ -4,12 +4,13 @@
#include "../../Library/Attacks/AttackData.hpp"
#include "AttackLearnMethod.hpp"
namespace CreatureLib::Battling{
namespace CreatureLib::Battling {
class LearnedAttack {
const Library::AttackData* _attack;
uint8_t _maxUses;
uint8_t _remainingUses;
AttackLearnMethod _learnMethod;
public:
LearnedAttack(Library::AttackData* attack, uint8_t maxUses, AttackLearnMethod learnMethod);
LearnedAttack(const Library::AttackData* attack, AttackLearnMethod learnMethod);
@@ -26,5 +27,4 @@ namespace CreatureLib::Battling{
};
}
#endif //CREATURELIB_LEARNEDATTACK_HPP
#endif // CREATURELIB_LEARNEDATTACK_HPP

View File

@@ -8,17 +8,14 @@ namespace CreatureLib::Battling {
class Target {
uint8_t _side;
uint8_t _creature;
public:
Target(uint8_t side, uint8_t creature) : _side(side), _creature(creature){}
Target(uint8_t side, uint8_t creature) : _side(side), _creature(creature) {}
uint8_t GetSideIndex() const{
return _side;
}
uint8_t GetSideIndex() const { return _side; }
uint8_t GetCreatureIndex() const{
return _creature;
}
uint8_t GetCreatureIndex() const { return _creature; }
};
}
#endif //CREATURELIB_TARGET_HPP
#endif // CREATURELIB_TARGET_HPP