Breaking change: rework of talents.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-11-15 12:04:45 +01:00
parent 33d384c464
commit 59313e6da8
15 changed files with 152 additions and 67 deletions

View File

@@ -20,8 +20,11 @@ namespace CreatureLib::Battling {
_weight(variant->GetWeight()), _height(variant->GetHeight()), _nickname(std::move(nickname)),
_talentIndex(talent), _hasOverridenTalent(false), _attacks(attacks),
_allowedExperienceGain(allowedExperienceGain) {
_activeTalent =
std::unique_ptr<BattleScript>(_library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()));
_activeTalent = std::unique_ptr<BattleScript>(
_library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()->GetEffect()));
if (_activeTalent != nullptr) {
_activeTalent->OnInitialize(GetActiveTalent()->GetParameters());
}
for (auto t : _variant->GetTypes()) {
_types.push_back(t);
}
@@ -65,8 +68,11 @@ namespace CreatureLib::Battling {
_height = variant->GetHeight();
// Grab the new active talent.
_activeTalent =
std::unique_ptr<BattleScript>(_library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()));
_activeTalent = std::unique_ptr<BattleScript>(
_library->LoadScript(this, ScriptCategory::Talent, GetActiveTalent()->GetEffect()));
if (_activeTalent != nullptr) {
_activeTalent->OnInitialize(GetActiveTalent()->GetParameters());
}
// We modify the health of the creature by the change in its max health.
auto prevHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health);
@@ -96,9 +102,9 @@ namespace CreatureLib::Battling {
RecalculateFlatStats();
}
const ArbUt::StringView& Creature::GetActiveTalent() const {
if (_hasOverridenTalent) {
return _overridenTalentName;
ArbUt::BorrowedPtr<const Library::Talent> Creature::GetActiveTalent() const {
if (_hasOverridenTalent && _overridenTalent.HasValue()) {
return _overridenTalent.GetValue();
}
return _variant->GetTalent(_talentIndex);
}
@@ -233,7 +239,7 @@ namespace CreatureLib::Battling {
_activeTalent->OnRemove();
_activeTalent.reset(this->_library->LoadScript(this, ScriptCategory::Talent, talent));
}
_overridenTalentName = talent;
_overridenTalent = _library->GetStaticLib()->GetTalentLibrary()->Get(talent);
}
const std::vector<uint8_t>& Creature::GetTypes() const noexcept { return _types; }
@@ -384,7 +390,7 @@ namespace CreatureLib::Battling {
c->_activeTalent = std::unique_ptr<BattleScript>(_activeTalent->Clone(c));
}
c->_hasOverridenTalent = _hasOverridenTalent;
c->_overridenTalentName = _overridenTalentName;
c->_overridenTalent = _overridenTalent;
if (_status != nullptr) {
c->_status = std::unique_ptr<BattleScript>(_status->Clone(c));
}

View File

@@ -56,7 +56,7 @@ namespace CreatureLib::Battling {
std::unique_ptr<BattleScript> _activeTalent = {};
bool _hasOverridenTalent = false;
ArbUt::StringView _overridenTalentName = {};
ArbUt::OptionalBorrowedPtr<const Library::Talent> _overridenTalent = {};
ArbUt::OptionalUniquePtrList<LearnedAttack> _attacks = {};
bool _allowedExperienceGain = {};
@@ -144,7 +144,7 @@ namespace CreatureLib::Battling {
}
inline void SetNickname(std::string nickname) noexcept { _nickname = nickname; }
const CreatureLib::Library::TalentIndex& GetRealTalent() const noexcept { return _talentIndex; }
const ArbUt::StringView& GetActiveTalent() const;
ArbUt::BorrowedPtr<const Library::Talent> GetActiveTalent() const;
/// Are we allowed to use this creature in a battle?
[[nodiscard]] virtual bool IsUsable() const noexcept;