Further implementation of types.
This commit is contained in:
		@@ -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
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    };
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -54,6 +54,7 @@ namespace CreatureLib::Battling{
 | 
			
		||||
        BattleSide* GetBattleSide() const;
 | 
			
		||||
 | 
			
		||||
        bool IsFainted() const;
 | 
			
		||||
        const std::vector<uint8_t>& GetTypes() const;
 | 
			
		||||
 | 
			
		||||
        //region Stat APIs
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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];
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user