Support for changing variants.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2020-06-10 14:39:20 +02:00
parent 637649c993
commit c8314d6018
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 34 additions and 1 deletions

View File

@ -25,6 +25,11 @@ export void CreatureLib_Creature_Destruct(const Creature* p) { delete p; }
SIMPLE_GET_FUNC_SMART_PTR(Creature, GetSpecies, const CreatureLib::Library::CreatureSpecies*);
SIMPLE_GET_FUNC_SMART_PTR(Creature, GetVariant, const CreatureLib::Library::SpeciesVariant*);
export uint8_t CreatureLib_Creature_ChangeVariant(Creature* p, const CreatureLib::Library::SpeciesVariant* variant) {
Try(p->ChangeVariant(variant);)
}
SIMPLE_GET_FUNC(Creature, GetLevel, uint8_t);
SIMPLE_GET_FUNC(Creature, GetExperience, uint32_t);
SIMPLE_GET_FUNC(Creature, GetGender, CreatureLib::Library::Gender);

View File

@ -30,6 +30,33 @@ Battling::Creature::Creature(ArbUt::BorrowedPtr<const BattleLibrary> library,
}
}
void Battling::Creature::ChangeVariant(ArbUt::BorrowedPtr<const Library::SpeciesVariant> variant) {
AssertNotNull(variant)
_variant = variant;
// Set the types to the new variant.
_types.clear();
for (auto t : variant->GetTypes()) {
_types.insert(t);
}
// Grab the new active talent.
_activeTalent =
std::unique_ptr<CreatureLib::Battling::Script>(_library->LoadScript(ScriptCategory::Talent, GetActiveTalent()));
// We modify the health of the creature by the change in its max health.
auto prevHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health);
RecalculateFlatStats();
int32_t diffHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health) - prevHealth;
if (_currentHealth < -diffHealth) {
_currentHealth = 0;
} else {
_currentHealth += diffHealth;
}
// TODO: consider variant specific attacks?
}
void Battling::Creature::ChangeLevelBy(int8_t amount) {
auto level = _level + amount;
if (level > _library->GetSettings()->GetMaximalLevel())

View File

@ -84,6 +84,7 @@ namespace CreatureLib::Battling {
return _species;
}
inline const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& GetVariant() const noexcept { return _variant; }
virtual void ChangeVariant(ArbUt::BorrowedPtr<const Library::SpeciesVariant> variant);
inline uint8_t GetLevel() const noexcept { return _level; }
inline uint32_t GetExperience() const noexcept { return _experience; }
inline Library::Gender GetGender() const noexcept { return _gender; }