Further implementation of types.

This commit is contained in:
Deukhoofd 2019-11-05 08:06:12 +01:00
parent 168e14d394
commit db2a577a85
8 changed files with 42 additions and 24 deletions

View File

@ -1,5 +1,4 @@
#include "TurnHandler.hpp"
#include "../Models/Creature.hpp"
#include "../Models/Battle.hpp"
#include "../Models/ExecutingAttack.hpp"
#include "../../Core/Exceptions/NotImplementedException.hpp"
@ -7,7 +6,9 @@
void CreatureLib::Battling::TurnHandler::RunTurn(CreatureLib::Battling::ChoiceQueue &queue) {
//HOOK: On Before Turn hook for all choices
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){
case TurnChoiceKind::Pass: return;
case TurnChoiceKind::Attack:
return ExecuteAttackChoice(static_cast<const AttackTurnChoice*>(choice));
return ExecuteAttackChoice(dynamic_cast<const AttackTurnChoice*>(choice));
case TurnChoiceKind::Item:
case TurnChoiceKind::Switch:
case TurnChoiceKind::RunAway:
throw NotImplementedException();
}
delete 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);
//TODO: calculate data for hit
hit.SetEffectiveness(user->GetBattle()->GetLibrary()->GetTypeLibrary()->GetEffectiveness(hit.GetType(), target->GetTypes()));
if (attackData->GetCategory() == Library::AttackCategory::Status){
//HOOK: Status attack
}

View File

@ -16,6 +16,7 @@ namespace CreatureLib::Battling {
const Library::SpeciesLibrary* GetSpeciesLibrary() const;
const Library::ItemLibrary* GetItemLibrary() const;
const Library::AttackLibrary* GetAttackLibrary() const;
const Library::TypeLibrary* GetTypeLibrary() const;
const BattleStatCalculator* GetStatCalculator() const;
};

View File

@ -124,3 +124,8 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source)
// HOOK: On Damage
__CurrentHealth -= damage;
}
const std::vector<uint8_t>& Battling::Creature::GetTypes() const {
//HOOK: override types.
return this->__Variant->GetTypes();
}

View File

@ -54,6 +54,7 @@ namespace CreatureLib::Battling{
BattleSide* GetBattleSide() const;
bool IsFainted() const;
const std::vector<uint8_t>& GetTypes() const;
//region Stat APIs

View File

@ -14,31 +14,34 @@ namespace CreatureLib::Battling {
uint8_t _basePower = 0;
float _effectiveness = 1;
uint32_t _damage = 0;
uint8_t _type = 0;
public:
HitData(){}
inline bool IsCritical() const{ return _critical;}
inline uint8_t GetBasePower() const{ return _basePower;}
inline float GetEffectiveness() const{ return _effectiveness;}
inline uint32_t GetDamage() const{ return _damage;}
[[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 SetBasePower(uint8_t value) { _basePower = value; }
inline void SetEffectiveness(float value) {_effectiveness = value;}
inline void OverrideDamage(uint32_t value) {_damage = value;}
inline void SetType(uint8_t value) {_type = value;}
};
class TargetData {
bool _isHit = true;
std::vector<HitData> _hits;
public:
TargetData(uint8_t numberOfHits) : _hits(numberOfHits)
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits)
{
for (uint8_t i = 0; i < numberOfHits; i++){
_hits[i] = HitData();
}
}
TargetData(){}
TargetData()= default;
HitData& GetHit(uint8_t index){
return _hits[index];

View File

@ -1,11 +1,16 @@
#include "SpeciesVariant.hpp"
#include <algorithm>
#include <utility>
const std::vector<uint8_t>& CreatureLib::Library::SpeciesVariant::GetTypes() const {
return _types;
}
size_t CreatureLib::Library::SpeciesVariant::GetTypeCount() const {
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];
}
@ -25,7 +30,7 @@ const std::string& CreatureLib::Library::SpeciesVariant::GetTalent(int32_t index
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);
if (i != _talents.end()){
return std::distance(_talents.begin(), i);
@ -46,21 +51,21 @@ const CreatureLib::Library::LearnableAttacks *CreatureLib::Library::SpeciesVaria
}
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,
std::vector<std::string> talents,
std::vector<std::string> secretTalents, const LearnableAttacks* attacks)
: __Name(name),
: __Name(std::move(name)),
__Height(height),
__Weight(weight),
__BaseExperience(baseExperience),
_types(types),
_types(std::move(types)),
_baseStatistics(baseStats),
_talents(talents),
_secretTalents(secretTalents),
_talents(std::move(talents)),
_secretTalents(std::move(secretTalents)),
_attacks(attacks)
{}
CreatureLib::Library::SpeciesVariant::~SpeciesVariant() {
delete _attacks;
}
}

View File

@ -19,24 +19,25 @@ namespace CreatureLib::Library {
GetProperty(float, Weight);
GetProperty(uint32_t, BaseExperience);
private:
std::vector<std::string> _types;
std::vector<uint8_t > _types;
const Core::StatisticSet<uint16_t > _baseStatistics;
std::vector<std::string> _talents;
std::vector<std::string> _secretTalents;
const LearnableAttacks* _attacks;
public:
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);
~SpeciesVariant();
[[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]] const std::string& GetTalent(int32_t index) 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;
};
}

View File

@ -10,7 +10,7 @@ static BattleLibrary* __library = nullptr;
static SpeciesLibrary* BuildSpeciesLibrary(){
auto l = new SpeciesLibrary();
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),
{"testTalent"}, {"testSecretTalent"},
new LearnableAttacks(100)),