Implements critical calculation, fixes some library pointers being unset, causing segfaults.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2019-11-05 17:42:45 +01:00
parent b290f16a15
commit 2ecc5cfccd
6 changed files with 41 additions and 6 deletions

View File

@ -103,8 +103,7 @@ void CreatureLib::Battling::TurnHandler::HandleAttackForTarget(CreatureLib::Batt
//HOOK: Change move type
hit.SetEffectiveness(library->GetTypeLibrary()->GetEffectiveness(hit.GetType(), target->GetTypes()));
//TODO: Critical calculation
hit.SetCritical(false);
hit.SetCritical(library->GetCriticalLibrary()->IsCritical(&attack, target, hitIndex));
hit.SetBasePower(dmgLibrary->GetBasePower(&attack, target, hitIndex));
hit.SetDamage(dmgLibrary->GetDamage(&attack, target, hitIndex));

View File

@ -1,14 +1,18 @@
#include "BattleLibrary.hpp"
CreatureLib::Battling::BattleLibrary::BattleLibrary(CreatureLib::Library::DataLibrary *staticLib,
CreatureLib::Battling::BattleStatCalculator *statCalculator)
: _staticLib(staticLib), _statCalculator(statCalculator)
CreatureLib::Battling::BattleStatCalculator *statCalculator,
DamageLibrary* damageLibrary,
CriticalLibrary* criticalLibrary)
: _staticLib(staticLib), _statCalculator(statCalculator),
_damageLibrary(damageLibrary), _criticalLibrary(criticalLibrary)
{}
CreatureLib::Battling::BattleLibrary::~BattleLibrary() {
delete _staticLib;
delete _statCalculator;
delete _damageLibrary;
delete _criticalLibrary;
}
const CreatureLib::Library::LibrarySettings& CreatureLib::Battling::BattleLibrary::GetSettings() const {
@ -39,3 +43,7 @@ const CreatureLib::Battling::DamageLibrary *CreatureLib::Battling::BattleLibrary
return _damageLibrary;
}
const CreatureLib::Battling::CriticalLibrary *CreatureLib::Battling::BattleLibrary::GetCriticalLibrary() const {
return _criticalLibrary;
}

View File

@ -4,14 +4,17 @@
#include "BattleStatCalculator.hpp"
#include "../../Library/DataLibrary.hpp"
#include "DamageLibrary.hpp"
#include "CriticalLibrary.hpp"
namespace CreatureLib::Battling {
class BattleLibrary {
const Library::DataLibrary* _staticLib;
BattleStatCalculator* _statCalculator;
DamageLibrary* _damageLibrary;
CriticalLibrary* _criticalLibrary;
public:
BattleLibrary(Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator);
BattleLibrary(Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator, DamageLibrary* damageLibrary,
CriticalLibrary* criticalLibrary);
~BattleLibrary();
const Library::LibrarySettings& GetSettings() const;
@ -22,6 +25,7 @@ namespace CreatureLib::Battling {
const BattleStatCalculator* GetStatCalculator() const;
const DamageLibrary* GetDamageLibrary() const;
const CriticalLibrary* GetCriticalLibrary() const;
};
}

View File

@ -0,0 +1,9 @@
#include "CriticalLibrary.hpp"
#include "../Models/Battle.hpp"
bool CreatureLib::Battling::CriticalLibrary::IsCritical(CreatureLib::Battling::ExecutingAttack *attack,
CreatureLib::Battling::Creature *target, uint8_t hit) const {
auto rand = target->GetBattle()->GetRandom();
//HOOK: Increase chance for critical hits.
return rand.Get(10) <= 0;
}

View File

@ -0,0 +1,14 @@
#ifndef CREATURELIB_CRITICALLIBRARY_HPP
#define CREATURELIB_CRITICALLIBRARY_HPP
#include "../Models/ExecutingAttack.hpp"
namespace CreatureLib::Battling {
class CriticalLibrary {
public:
virtual bool IsCritical(ExecutingAttack* attack, Creature* target, uint8_t hit) const;
};
}
#endif //CREATURELIB_CRITICALLIBRARY_HPP

View File

@ -52,7 +52,8 @@ static TypeLibrary* BuildTypeLibrary(){
static BattleLibrary* BuildLibrary(){
auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(),
BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary());
auto battleLib = new BattleLibrary(l, new BattleStatCalculator());
auto battleLib = new BattleLibrary(l, new BattleStatCalculator(), new DamageLibrary(),
new CriticalLibrary());
return battleLib;
}