Implements critical calculation, fixes some library pointers being unset, causing segfaults.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
b290f16a15
commit
2ecc5cfccd
|
@ -103,8 +103,7 @@ void CreatureLib::Battling::TurnHandler::HandleAttackForTarget(CreatureLib::Batt
|
||||||
|
|
||||||
//HOOK: Change move type
|
//HOOK: Change move type
|
||||||
hit.SetEffectiveness(library->GetTypeLibrary()->GetEffectiveness(hit.GetType(), target->GetTypes()));
|
hit.SetEffectiveness(library->GetTypeLibrary()->GetEffectiveness(hit.GetType(), target->GetTypes()));
|
||||||
//TODO: Critical calculation
|
hit.SetCritical(library->GetCriticalLibrary()->IsCritical(&attack, target, hitIndex));
|
||||||
hit.SetCritical(false);
|
|
||||||
hit.SetBasePower(dmgLibrary->GetBasePower(&attack, target, hitIndex));
|
hit.SetBasePower(dmgLibrary->GetBasePower(&attack, target, hitIndex));
|
||||||
hit.SetDamage(dmgLibrary->GetDamage(&attack, target, hitIndex));
|
hit.SetDamage(dmgLibrary->GetDamage(&attack, target, hitIndex));
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
#include "BattleLibrary.hpp"
|
#include "BattleLibrary.hpp"
|
||||||
|
|
||||||
CreatureLib::Battling::BattleLibrary::BattleLibrary(CreatureLib::Library::DataLibrary *staticLib,
|
CreatureLib::Battling::BattleLibrary::BattleLibrary(CreatureLib::Library::DataLibrary *staticLib,
|
||||||
CreatureLib::Battling::BattleStatCalculator *statCalculator)
|
CreatureLib::Battling::BattleStatCalculator *statCalculator,
|
||||||
: _staticLib(staticLib), _statCalculator(statCalculator)
|
DamageLibrary* damageLibrary,
|
||||||
|
CriticalLibrary* criticalLibrary)
|
||||||
|
: _staticLib(staticLib), _statCalculator(statCalculator),
|
||||||
|
_damageLibrary(damageLibrary), _criticalLibrary(criticalLibrary)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
CreatureLib::Battling::BattleLibrary::~BattleLibrary() {
|
CreatureLib::Battling::BattleLibrary::~BattleLibrary() {
|
||||||
delete _staticLib;
|
delete _staticLib;
|
||||||
delete _statCalculator;
|
delete _statCalculator;
|
||||||
delete _damageLibrary;
|
delete _damageLibrary;
|
||||||
|
delete _criticalLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreatureLib::Library::LibrarySettings& CreatureLib::Battling::BattleLibrary::GetSettings() const {
|
const CreatureLib::Library::LibrarySettings& CreatureLib::Battling::BattleLibrary::GetSettings() const {
|
||||||
|
@ -39,3 +43,7 @@ const CreatureLib::Battling::DamageLibrary *CreatureLib::Battling::BattleLibrary
|
||||||
return _damageLibrary;
|
return _damageLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CreatureLib::Battling::CriticalLibrary *CreatureLib::Battling::BattleLibrary::GetCriticalLibrary() const {
|
||||||
|
return _criticalLibrary;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,17 @@
|
||||||
#include "BattleStatCalculator.hpp"
|
#include "BattleStatCalculator.hpp"
|
||||||
#include "../../Library/DataLibrary.hpp"
|
#include "../../Library/DataLibrary.hpp"
|
||||||
#include "DamageLibrary.hpp"
|
#include "DamageLibrary.hpp"
|
||||||
|
#include "CriticalLibrary.hpp"
|
||||||
|
|
||||||
namespace CreatureLib::Battling {
|
namespace CreatureLib::Battling {
|
||||||
class BattleLibrary {
|
class BattleLibrary {
|
||||||
const Library::DataLibrary* _staticLib;
|
const Library::DataLibrary* _staticLib;
|
||||||
BattleStatCalculator* _statCalculator;
|
BattleStatCalculator* _statCalculator;
|
||||||
DamageLibrary* _damageLibrary;
|
DamageLibrary* _damageLibrary;
|
||||||
|
CriticalLibrary* _criticalLibrary;
|
||||||
public:
|
public:
|
||||||
BattleLibrary(Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator);
|
BattleLibrary(Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator, DamageLibrary* damageLibrary,
|
||||||
|
CriticalLibrary* criticalLibrary);
|
||||||
~BattleLibrary();
|
~BattleLibrary();
|
||||||
|
|
||||||
const Library::LibrarySettings& GetSettings() const;
|
const Library::LibrarySettings& GetSettings() const;
|
||||||
|
@ -22,6 +25,7 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
const BattleStatCalculator* GetStatCalculator() const;
|
const BattleStatCalculator* GetStatCalculator() const;
|
||||||
const DamageLibrary* GetDamageLibrary() const;
|
const DamageLibrary* GetDamageLibrary() const;
|
||||||
|
const CriticalLibrary* GetCriticalLibrary() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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
|
|
@ -52,7 +52,8 @@ static TypeLibrary* BuildTypeLibrary(){
|
||||||
static BattleLibrary* BuildLibrary(){
|
static BattleLibrary* BuildLibrary(){
|
||||||
auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(),
|
auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(),
|
||||||
BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary());
|
BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary());
|
||||||
auto battleLib = new BattleLibrary(l, new BattleStatCalculator());
|
auto battleLib = new BattleLibrary(l, new BattleStatCalculator(), new DamageLibrary(),
|
||||||
|
new CriticalLibrary());
|
||||||
return battleLib;
|
return battleLib;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue