Further implementation of types.
This commit is contained in:
parent
168e14d394
commit
db2a577a85
|
@ -1,5 +1,4 @@
|
||||||
#include "TurnHandler.hpp"
|
#include "TurnHandler.hpp"
|
||||||
#include "../Models/Creature.hpp"
|
|
||||||
#include "../Models/Battle.hpp"
|
#include "../Models/Battle.hpp"
|
||||||
#include "../Models/ExecutingAttack.hpp"
|
#include "../Models/ExecutingAttack.hpp"
|
||||||
#include "../../Core/Exceptions/NotImplementedException.hpp"
|
#include "../../Core/Exceptions/NotImplementedException.hpp"
|
||||||
|
@ -7,7 +6,9 @@
|
||||||
void CreatureLib::Battling::TurnHandler::RunTurn(CreatureLib::Battling::ChoiceQueue &queue) {
|
void CreatureLib::Battling::TurnHandler::RunTurn(CreatureLib::Battling::ChoiceQueue &queue) {
|
||||||
//HOOK: On Before Turn hook for all choices
|
//HOOK: On Before Turn hook for all choices
|
||||||
while (queue.HasNext()){
|
while (queue.HasNext()){
|
||||||
ExecuteChoice(queue.Dequeue());
|
auto item = queue.Dequeue();
|
||||||
|
ExecuteChoice(item);
|
||||||
|
delete item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,14 +39,12 @@ void CreatureLib::Battling::TurnHandler::ExecuteChoice(const CreatureLib::Battli
|
||||||
switch (choiceKind){
|
switch (choiceKind){
|
||||||
case TurnChoiceKind::Pass: return;
|
case TurnChoiceKind::Pass: return;
|
||||||
case TurnChoiceKind::Attack:
|
case TurnChoiceKind::Attack:
|
||||||
return ExecuteAttackChoice(static_cast<const AttackTurnChoice*>(choice));
|
return ExecuteAttackChoice(dynamic_cast<const AttackTurnChoice*>(choice));
|
||||||
case TurnChoiceKind::Item:
|
case TurnChoiceKind::Item:
|
||||||
case TurnChoiceKind::Switch:
|
case TurnChoiceKind::Switch:
|
||||||
case TurnChoiceKind::RunAway:
|
case TurnChoiceKind::RunAway:
|
||||||
throw NotImplementedException();
|
throw NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
delete choice;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatureLib::Battling::TurnHandler::ExecuteAttackChoice(const CreatureLib::Battling::AttackTurnChoice *choice) {
|
void CreatureLib::Battling::TurnHandler::ExecuteAttackChoice(const CreatureLib::Battling::AttackTurnChoice *choice) {
|
||||||
|
@ -100,6 +99,9 @@ void CreatureLib::Battling::TurnHandler::HandleAttackForTarget(CreatureLib::Batt
|
||||||
}
|
}
|
||||||
auto hit = targetData.GetHit(hitIndex);
|
auto hit = targetData.GetHit(hitIndex);
|
||||||
//TODO: calculate data for hit
|
//TODO: calculate data for hit
|
||||||
|
|
||||||
|
hit.SetEffectiveness(user->GetBattle()->GetLibrary()->GetTypeLibrary()->GetEffectiveness(hit.GetType(), target->GetTypes()));
|
||||||
|
|
||||||
if (attackData->GetCategory() == Library::AttackCategory::Status){
|
if (attackData->GetCategory() == Library::AttackCategory::Status){
|
||||||
//HOOK: Status attack
|
//HOOK: Status attack
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ namespace CreatureLib::Battling {
|
||||||
const Library::SpeciesLibrary* GetSpeciesLibrary() const;
|
const Library::SpeciesLibrary* GetSpeciesLibrary() const;
|
||||||
const Library::ItemLibrary* GetItemLibrary() const;
|
const Library::ItemLibrary* GetItemLibrary() const;
|
||||||
const Library::AttackLibrary* GetAttackLibrary() const;
|
const Library::AttackLibrary* GetAttackLibrary() const;
|
||||||
|
const Library::TypeLibrary* GetTypeLibrary() const;
|
||||||
|
|
||||||
const BattleStatCalculator* GetStatCalculator() const;
|
const BattleStatCalculator* GetStatCalculator() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -124,3 +124,8 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source)
|
||||||
// HOOK: On Damage
|
// HOOK: On Damage
|
||||||
__CurrentHealth -= damage;
|
__CurrentHealth -= damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<uint8_t>& Battling::Creature::GetTypes() const {
|
||||||
|
//HOOK: override types.
|
||||||
|
return this->__Variant->GetTypes();
|
||||||
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ namespace CreatureLib::Battling{
|
||||||
BattleSide* GetBattleSide() const;
|
BattleSide* GetBattleSide() const;
|
||||||
|
|
||||||
bool IsFainted() const;
|
bool IsFainted() const;
|
||||||
|
const std::vector<uint8_t>& GetTypes() const;
|
||||||
|
|
||||||
//region Stat APIs
|
//region Stat APIs
|
||||||
|
|
||||||
|
|
|
@ -14,31 +14,34 @@ namespace CreatureLib::Battling {
|
||||||
uint8_t _basePower = 0;
|
uint8_t _basePower = 0;
|
||||||
float _effectiveness = 1;
|
float _effectiveness = 1;
|
||||||
uint32_t _damage = 0;
|
uint32_t _damage = 0;
|
||||||
|
uint8_t _type = 0;
|
||||||
public:
|
public:
|
||||||
HitData(){}
|
HitData(){}
|
||||||
|
|
||||||
inline bool IsCritical() const{ return _critical;}
|
[[nodiscard]] inline bool IsCritical() const{ return _critical;}
|
||||||
inline uint8_t GetBasePower() const{ return _basePower;}
|
[[nodiscard]] inline uint8_t GetBasePower() const{ return _basePower;}
|
||||||
inline float GetEffectiveness() const{ return _effectiveness;}
|
[[nodiscard]] inline float GetEffectiveness() const{ return _effectiveness;}
|
||||||
inline uint32_t GetDamage() const{ return _damage;}
|
[[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 SetBasePower(uint8_t value) { _basePower = value; }
|
||||||
inline void SetEffectiveness(float value) {_effectiveness = value;}
|
inline void SetEffectiveness(float value) {_effectiveness = value;}
|
||||||
inline void OverrideDamage(uint32_t value) {_damage = value;}
|
inline void OverrideDamage(uint32_t value) {_damage = value;}
|
||||||
|
inline void SetType(uint8_t value) {_type = value;}
|
||||||
};
|
};
|
||||||
|
|
||||||
class TargetData {
|
class TargetData {
|
||||||
bool _isHit = true;
|
bool _isHit = true;
|
||||||
std::vector<HitData> _hits;
|
std::vector<HitData> _hits;
|
||||||
public:
|
public:
|
||||||
TargetData(uint8_t numberOfHits) : _hits(numberOfHits)
|
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits)
|
||||||
{
|
{
|
||||||
for (uint8_t i = 0; i < numberOfHits; i++){
|
for (uint8_t i = 0; i < numberOfHits; i++){
|
||||||
_hits[i] = HitData();
|
_hits[i] = HitData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TargetData(){}
|
TargetData()= default;
|
||||||
|
|
||||||
HitData& GetHit(uint8_t index){
|
HitData& GetHit(uint8_t index){
|
||||||
return _hits[index];
|
return _hits[index];
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
#include "SpeciesVariant.hpp"
|
#include "SpeciesVariant.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
const std::vector<uint8_t>& CreatureLib::Library::SpeciesVariant::GetTypes() const {
|
||||||
|
return _types;
|
||||||
|
}
|
||||||
|
|
||||||
size_t CreatureLib::Library::SpeciesVariant::GetTypeCount() const {
|
size_t CreatureLib::Library::SpeciesVariant::GetTypeCount() const {
|
||||||
return _types.size();
|
return _types.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CreatureLib::Library::SpeciesVariant::GetType(size_t index) const {
|
uint8_t CreatureLib::Library::SpeciesVariant::GetType(size_t index) const {
|
||||||
return _types[index];
|
return _types[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +30,7 @@ const std::string& CreatureLib::Library::SpeciesVariant::GetTalent(int32_t index
|
||||||
return &_moves;
|
return &_moves;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
int8_t CreatureLib::Library::SpeciesVariant::GetTalentIndex(std::string talent) const{
|
int8_t CreatureLib::Library::SpeciesVariant::GetTalentIndex(const std::string& talent) const{
|
||||||
auto i = std::find(_talents.begin(), _talents.end(), talent);
|
auto i = std::find(_talents.begin(), _talents.end(), talent);
|
||||||
if (i != _talents.end()){
|
if (i != _talents.end()){
|
||||||
return std::distance(_talents.begin(), i);
|
return std::distance(_talents.begin(), i);
|
||||||
|
@ -46,18 +51,18 @@ const CreatureLib::Library::LearnableAttacks *CreatureLib::Library::SpeciesVaria
|
||||||
}
|
}
|
||||||
|
|
||||||
CreatureLib::Library::SpeciesVariant::SpeciesVariant(std::string name, float height, float weight,
|
CreatureLib::Library::SpeciesVariant::SpeciesVariant(std::string name, float height, float weight,
|
||||||
uint32_t baseExperience, std::vector<std::string> types,
|
uint32_t baseExperience, std::vector<uint8_t> types,
|
||||||
CreatureLib::Core::StatisticSet<uint16_t > baseStats,
|
CreatureLib::Core::StatisticSet<uint16_t > baseStats,
|
||||||
std::vector<std::string> talents,
|
std::vector<std::string> talents,
|
||||||
std::vector<std::string> secretTalents, const LearnableAttacks* attacks)
|
std::vector<std::string> secretTalents, const LearnableAttacks* attacks)
|
||||||
: __Name(name),
|
: __Name(std::move(name)),
|
||||||
__Height(height),
|
__Height(height),
|
||||||
__Weight(weight),
|
__Weight(weight),
|
||||||
__BaseExperience(baseExperience),
|
__BaseExperience(baseExperience),
|
||||||
_types(types),
|
_types(std::move(types)),
|
||||||
_baseStatistics(baseStats),
|
_baseStatistics(baseStats),
|
||||||
_talents(talents),
|
_talents(std::move(talents)),
|
||||||
_secretTalents(secretTalents),
|
_secretTalents(std::move(secretTalents)),
|
||||||
_attacks(attacks)
|
_attacks(attacks)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
|
@ -19,24 +19,25 @@ namespace CreatureLib::Library {
|
||||||
GetProperty(float, Weight);
|
GetProperty(float, Weight);
|
||||||
GetProperty(uint32_t, BaseExperience);
|
GetProperty(uint32_t, BaseExperience);
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> _types;
|
std::vector<uint8_t > _types;
|
||||||
const Core::StatisticSet<uint16_t > _baseStatistics;
|
const Core::StatisticSet<uint16_t > _baseStatistics;
|
||||||
std::vector<std::string> _talents;
|
std::vector<std::string> _talents;
|
||||||
std::vector<std::string> _secretTalents;
|
std::vector<std::string> _secretTalents;
|
||||||
const LearnableAttacks* _attacks;
|
const LearnableAttacks* _attacks;
|
||||||
public:
|
public:
|
||||||
SpeciesVariant(std::string name, float height, float weight, uint32_t baseExperience,
|
SpeciesVariant(std::string name, float height, float weight, uint32_t baseExperience,
|
||||||
std::vector<std::string> types, Core::StatisticSet<uint16_t > baseStats, std::vector<std::string> talents,
|
std::vector<uint8_t> types, Core::StatisticSet<uint16_t > baseStats, std::vector<std::string> talents,
|
||||||
std::vector<std::string> secretTalents, const LearnableAttacks* attacks);
|
std::vector<std::string> secretTalents, const LearnableAttacks* attacks);
|
||||||
|
|
||||||
~SpeciesVariant();
|
~SpeciesVariant();
|
||||||
|
|
||||||
[[nodiscard]] size_t GetTypeCount() const;
|
[[nodiscard]] size_t GetTypeCount() const;
|
||||||
[[nodiscard]] std::string GetType(size_t index) const;
|
[[nodiscard]] uint8_t GetType(size_t index) const;
|
||||||
|
[[nodiscard]] const std::vector<uint8_t >& GetTypes() const;
|
||||||
[[nodiscard]] uint32_t GetStatistic(Core::Statistic stat) const;
|
[[nodiscard]] uint32_t GetStatistic(Core::Statistic stat) const;
|
||||||
[[nodiscard]] const std::string& GetTalent(int32_t index) const;
|
[[nodiscard]] const std::string& GetTalent(int32_t index) const;
|
||||||
[[nodiscard]] const LearnableAttacks* GetLearnableAttacks() const;
|
[[nodiscard]] const LearnableAttacks* GetLearnableAttacks() const;
|
||||||
[[nodiscard]] int8_t GetTalentIndex(std::string talent) const;
|
[[nodiscard]] int8_t GetTalentIndex(const std::string& talent) const;
|
||||||
[[nodiscard]] int8_t GetRandomTalent(Core::Random* rand) const;
|
[[nodiscard]] int8_t GetRandomTalent(Core::Random* rand) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ static BattleLibrary* __library = nullptr;
|
||||||
static SpeciesLibrary* BuildSpeciesLibrary(){
|
static SpeciesLibrary* BuildSpeciesLibrary(){
|
||||||
auto l = new SpeciesLibrary();
|
auto l = new SpeciesLibrary();
|
||||||
l->LoadSpecies("testSpecies1", new CreatureSpecies(0, "testSpecies1",
|
l->LoadSpecies("testSpecies1", new CreatureSpecies(0, "testSpecies1",
|
||||||
new SpeciesVariant("default", 1,1, 10, {"fire", "water"},
|
new SpeciesVariant("default", 1,1, 10, {0, 1},
|
||||||
StatisticSet<uint16_t >(10,10,10,10,10,10),
|
StatisticSet<uint16_t >(10,10,10,10,10,10),
|
||||||
{"testTalent"}, {"testSecretTalent"},
|
{"testTalent"}, {"testSecretTalent"},
|
||||||
new LearnableAttacks(100)),
|
new LearnableAttacks(100)),
|
||||||
|
|
Loading…
Reference in New Issue