Initialize Creature talent script when battle library is set, allow talent overriding
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
4d796204f8
commit
49bd4813f6
|
@ -1,7 +1,10 @@
|
||||||
|
#include <cassert>
|
||||||
#include "BattleLibrary.hpp"
|
#include "BattleLibrary.hpp"
|
||||||
|
|
||||||
CreatureLib::Battling::BattleLibrary::BattleLibrary(CreatureLib::Library::DataLibrary *staticLib,
|
using namespace CreatureLib::Battling;
|
||||||
CreatureLib::Battling::BattleStatCalculator *statCalculator,
|
|
||||||
|
BattleLibrary::BattleLibrary(CreatureLib::Library::DataLibrary *staticLib,
|
||||||
|
BattleStatCalculator *statCalculator,
|
||||||
DamageLibrary* damageLibrary,
|
DamageLibrary* damageLibrary,
|
||||||
CriticalLibrary* criticalLibrary, ScriptResolver* scriptResolver)
|
CriticalLibrary* criticalLibrary, ScriptResolver* scriptResolver)
|
||||||
: _staticLib(staticLib), _statCalculator(statCalculator),
|
: _staticLib(staticLib), _statCalculator(statCalculator),
|
||||||
|
@ -9,48 +12,48 @@ CreatureLib::Battling::BattleLibrary::BattleLibrary(CreatureLib::Library::DataLi
|
||||||
_scriptResolver(scriptResolver)
|
_scriptResolver(scriptResolver)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
CreatureLib::Battling::BattleLibrary::~BattleLibrary() {
|
BattleLibrary::~BattleLibrary() {
|
||||||
delete _staticLib;
|
delete _staticLib;
|
||||||
delete _statCalculator;
|
delete _statCalculator;
|
||||||
delete _damageLibrary;
|
delete _damageLibrary;
|
||||||
delete _criticalLibrary;
|
delete _criticalLibrary;
|
||||||
|
delete _scriptResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreatureLib::Library::LibrarySettings& CreatureLib::Battling::BattleLibrary::GetSettings() const {
|
const CreatureLib::Library::LibrarySettings& BattleLibrary::GetSettings() const {
|
||||||
return _staticLib->GetSettings();
|
return _staticLib->GetSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreatureLib::Battling::BattleStatCalculator *CreatureLib::Battling::BattleLibrary::GetStatCalculator() const {
|
const BattleStatCalculator *BattleLibrary::GetStatCalculator() const {
|
||||||
return _statCalculator;
|
return _statCalculator;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreatureLib::Library::SpeciesLibrary* CreatureLib::Battling::BattleLibrary::GetSpeciesLibrary() const {
|
const CreatureLib::Library::SpeciesLibrary* BattleLibrary::GetSpeciesLibrary() const {
|
||||||
return _staticLib->GetSpeciesLibrary();
|
return _staticLib->GetSpeciesLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreatureLib::Library::ItemLibrary* CreatureLib::Battling::BattleLibrary::GetItemLibrary() const {
|
const CreatureLib::Library::ItemLibrary* BattleLibrary::GetItemLibrary() const {
|
||||||
return _staticLib->GetItemLibrary();
|
return _staticLib->GetItemLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreatureLib::Library::AttackLibrary *CreatureLib::Battling::BattleLibrary::GetAttackLibrary() const {
|
const CreatureLib::Library::AttackLibrary *BattleLibrary::GetAttackLibrary() const {
|
||||||
return _staticLib->GetAttackLibrary();
|
return _staticLib->GetAttackLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreatureLib::Library::TypeLibrary *CreatureLib::Battling::BattleLibrary::GetTypeLibrary() const {
|
const CreatureLib::Library::TypeLibrary *BattleLibrary::GetTypeLibrary() const {
|
||||||
return _staticLib->GetTypeLibrary();
|
return _staticLib->GetTypeLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreatureLib::Battling::DamageLibrary *CreatureLib::Battling::BattleLibrary::GetDamageLibrary() const {
|
const DamageLibrary *BattleLibrary::GetDamageLibrary() const {
|
||||||
return _damageLibrary;
|
return _damageLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreatureLib::Battling::CriticalLibrary *CreatureLib::Battling::BattleLibrary::GetCriticalLibrary() const {
|
const CriticalLibrary *BattleLibrary::GetCriticalLibrary() const {
|
||||||
return _criticalLibrary;
|
return _criticalLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
CreatureLib::Battling::Script *
|
Script* BattleLibrary::LoadScript(ScriptResolver::ScriptCategory category, const std::string &scriptName) {
|
||||||
CreatureLib::Battling::BattleLibrary::LoadScript(CreatureLib::Battling::ScriptResolver::ScriptCategory category,
|
assert(this->_scriptResolver != nullptr);
|
||||||
const std::string &scriptName) {
|
|
||||||
return _scriptResolver->LoadScript(category, scriptName);
|
return _scriptResolver->LoadScript(category, scriptName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,11 @@ Battling::Creature::Creature(const Library::CreatureSpecies* species, const Libr
|
||||||
__HeldItem(heldItem),
|
__HeldItem(heldItem),
|
||||||
_nickname(std::move(nickname)),
|
_nickname(std::move(nickname)),
|
||||||
_talentIndex(talent),
|
_talentIndex(talent),
|
||||||
|
_hasOverridenTalent(false),
|
||||||
_attacks(std::move(attacks))
|
_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) {
|
void Battling::Creature::SetBattleLibrary(Battling::BattleLibrary *library) {
|
||||||
this->_library = library;
|
this->_library = library;
|
||||||
|
_activeTalent = _library->LoadScript(ScriptResolver::ScriptCategory::Talent, GetActiveTalent());
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &Battling::Creature::GetNickname() const {
|
const std::string &Battling::Creature::GetNickname() const {
|
||||||
|
@ -47,7 +51,10 @@ const std::string &Battling::Creature::GetNickname() const {
|
||||||
return _nickname;
|
return _nickname;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &Battling::Creature::GetTalent() const {
|
const std::string &Battling::Creature::GetActiveTalent() const {
|
||||||
|
if (_hasOverridenTalent){
|
||||||
|
return _overridenTalentName;
|
||||||
|
}
|
||||||
return __Variant->GetTalent(_talentIndex);
|
return __Variant->GetTalent(_talentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +138,12 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source)
|
||||||
__CurrentHealth -= damage;
|
__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 {
|
const std::vector<uint8_t>& Battling::Creature::GetTypes() const {
|
||||||
//HOOK: override types.
|
//HOOK: override types.
|
||||||
return this->__Variant->GetTypes();
|
return this->__Variant->GetTypes();
|
||||||
|
|
|
@ -44,6 +44,9 @@ namespace CreatureLib::Battling{
|
||||||
int8_t _talentIndex;
|
int8_t _talentIndex;
|
||||||
Script* _activeTalent = nullptr;
|
Script* _activeTalent = nullptr;
|
||||||
|
|
||||||
|
bool _hasOverridenTalent;
|
||||||
|
std::string _overridenTalentName = "";
|
||||||
|
|
||||||
std::vector<LearnedAttack*> _attacks;
|
std::vector<LearnedAttack*> _attacks;
|
||||||
|
|
||||||
Script* _status = nullptr;
|
Script* _status = nullptr;
|
||||||
|
@ -57,19 +60,22 @@ namespace CreatureLib::Battling{
|
||||||
|
|
||||||
virtual ~Creature() = default;
|
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);
|
void SetBattleData(Battle* battle, BattleSide* side);
|
||||||
Battle* GetBattle() const;
|
Battle* GetBattle() const;
|
||||||
BattleSide* GetBattleSide() const;
|
BattleSide* GetBattleSide() const;
|
||||||
|
|
||||||
|
const std::string& GetNickname() const;
|
||||||
|
const std::string& GetActiveTalent() const;
|
||||||
|
|
||||||
[[nodiscard]] bool IsFainted() const;
|
[[nodiscard]] bool IsFainted() const;
|
||||||
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
|
[[nodiscard]] const std::vector<uint8_t>& GetTypes() const;
|
||||||
[[nodiscard]] bool HasType(uint8_t type) 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;
|
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override;
|
||||||
|
|
||||||
//region Stat APIs
|
//region Stat APIs
|
||||||
|
|
Loading…
Reference in New Issue