Initialize Creature talent script when battle library is set, allow talent overriding
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-11-18 18:41:55 +01:00
parent 4d796204f8
commit 49bd4813f6
3 changed files with 43 additions and 21 deletions

View File

@ -1,7 +1,10 @@
#include <cassert>
#include "BattleLibrary.hpp"
CreatureLib::Battling::BattleLibrary::BattleLibrary(CreatureLib::Library::DataLibrary *staticLib,
CreatureLib::Battling::BattleStatCalculator *statCalculator,
using namespace CreatureLib::Battling;
BattleLibrary::BattleLibrary(CreatureLib::Library::DataLibrary *staticLib,
BattleStatCalculator *statCalculator,
DamageLibrary* damageLibrary,
CriticalLibrary* criticalLibrary, ScriptResolver* scriptResolver)
: _staticLib(staticLib), _statCalculator(statCalculator),
@ -9,48 +12,48 @@ CreatureLib::Battling::BattleLibrary::BattleLibrary(CreatureLib::Library::DataLi
_scriptResolver(scriptResolver)
{}
CreatureLib::Battling::BattleLibrary::~BattleLibrary() {
BattleLibrary::~BattleLibrary() {
delete _staticLib;
delete _statCalculator;
delete _damageLibrary;
delete _criticalLibrary;
delete _scriptResolver;
}
const CreatureLib::Library::LibrarySettings& CreatureLib::Battling::BattleLibrary::GetSettings() const {
const CreatureLib::Library::LibrarySettings& BattleLibrary::GetSettings() const {
return _staticLib->GetSettings();
}
const CreatureLib::Battling::BattleStatCalculator *CreatureLib::Battling::BattleLibrary::GetStatCalculator() const {
const BattleStatCalculator *BattleLibrary::GetStatCalculator() const {
return _statCalculator;
}
const CreatureLib::Library::SpeciesLibrary* CreatureLib::Battling::BattleLibrary::GetSpeciesLibrary() const {
const CreatureLib::Library::SpeciesLibrary* BattleLibrary::GetSpeciesLibrary() const {
return _staticLib->GetSpeciesLibrary();
}
const CreatureLib::Library::ItemLibrary* CreatureLib::Battling::BattleLibrary::GetItemLibrary() const {
const CreatureLib::Library::ItemLibrary* BattleLibrary::GetItemLibrary() const {
return _staticLib->GetItemLibrary();
}
const CreatureLib::Library::AttackLibrary *CreatureLib::Battling::BattleLibrary::GetAttackLibrary() const {
const CreatureLib::Library::AttackLibrary *BattleLibrary::GetAttackLibrary() const {
return _staticLib->GetAttackLibrary();
}
const CreatureLib::Library::TypeLibrary *CreatureLib::Battling::BattleLibrary::GetTypeLibrary() const {
const CreatureLib::Library::TypeLibrary *BattleLibrary::GetTypeLibrary() const {
return _staticLib->GetTypeLibrary();
}
const CreatureLib::Battling::DamageLibrary *CreatureLib::Battling::BattleLibrary::GetDamageLibrary() const {
const DamageLibrary *BattleLibrary::GetDamageLibrary() const {
return _damageLibrary;
}
const CreatureLib::Battling::CriticalLibrary *CreatureLib::Battling::BattleLibrary::GetCriticalLibrary() const {
const CriticalLibrary *BattleLibrary::GetCriticalLibrary() const {
return _criticalLibrary;
}
CreatureLib::Battling::Script *
CreatureLib::Battling::BattleLibrary::LoadScript(CreatureLib::Battling::ScriptResolver::ScriptCategory category,
const std::string &scriptName) {
Script* BattleLibrary::LoadScript(ScriptResolver::ScriptCategory category, const std::string &scriptName) {
assert(this->_scriptResolver != nullptr);
return _scriptResolver->LoadScript(category, scriptName);
}

View File

@ -23,8 +23,11 @@ Battling::Creature::Creature(const Library::CreatureSpecies* species, const Libr
__HeldItem(heldItem),
_nickname(std::move(nickname)),
_talentIndex(talent),
_hasOverridenTalent(false),
_attacks(std::move(attacks))
{}
{
__CurrentHealth = GetBoostedStat(Core::Statistic::Health);
}
@ -39,6 +42,7 @@ void Battling::Creature::SetBattle(Battling::Battle *battle) {
void Battling::Creature::SetBattleLibrary(Battling::BattleLibrary *library) {
this->_library = library;
_activeTalent = _library->LoadScript(ScriptResolver::ScriptCategory::Talent, GetActiveTalent());
}
const std::string &Battling::Creature::GetNickname() const {
@ -47,7 +51,10 @@ const std::string &Battling::Creature::GetNickname() const {
return _nickname;
}
const std::string &Battling::Creature::GetTalent() const {
const std::string &Battling::Creature::GetActiveTalent() const {
if (_hasOverridenTalent){
return _overridenTalentName;
}
return __Variant->GetTalent(_talentIndex);
}
@ -131,6 +138,12 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source)
__CurrentHealth -= damage;
}
void Battling::Creature::OverrideActiveTalent(const std::string& talent){
_hasOverridenTalent = true;
_overridenTalentName = talent;
_activeTalent = this->_library->LoadScript(ScriptResolver::ScriptCategory::Talent, talent);
}
const std::vector<uint8_t>& Battling::Creature::GetTypes() const {
//HOOK: override types.
return this->__Variant->GetTypes();

View File

@ -44,6 +44,9 @@ namespace CreatureLib::Battling{
int8_t _talentIndex;
Script* _activeTalent = nullptr;
bool _hasOverridenTalent;
std::string _overridenTalentName = "";
std::vector<LearnedAttack*> _attacks;
Script* _status = nullptr;
@ -57,19 +60,22 @@ namespace CreatureLib::Battling{
virtual ~Creature() = default;
const std::string& GetNickname() const;
const std::string& GetTalent() const;
void ChangeLevel(int8_t amount);
void Damage(uint32_t damage, DamageSource source);
void SetBattleData(Battle* battle, BattleSide* side);
Battle* GetBattle() const;
BattleSide* GetBattleSide() const;
const std::string& GetNickname() const;
const std::string& GetActiveTalent() const;
[[nodiscard]] bool IsFainted() const;
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
[[nodiscard]] bool HasType(uint8_t type) const;
void ChangeLevel(int8_t amount);
void Damage(uint32_t damage, DamageSource source);
void OverrideActiveTalent(const std::string& talent);
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override;
//region Stat APIs