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

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

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