Implements experience gain on opponent faint.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -92,6 +92,16 @@ Battling::BattleSide* Battling::Creature::GetBattleSide() const { return _side;
|
||||
|
||||
bool Battling::Creature::IsFainted() const { return this->__CurrentHealth <= 0; }
|
||||
|
||||
void Battling::Creature::OnFaint() {
|
||||
// HOOK: On Faint
|
||||
_library->GetExperienceLibrary()->HandleExperienceGain(this, _seenOpponents);
|
||||
|
||||
if (!_battle->CanSlotBeFilled(_side->GetSideIndex(), _side->GetCreatureIndex(this))) {
|
||||
_side->MarkSlotAsUnfillable(this);
|
||||
}
|
||||
_battle->ValidateBattleState();
|
||||
}
|
||||
|
||||
void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source) {
|
||||
if (damage > __CurrentHealth) {
|
||||
damage = __CurrentHealth;
|
||||
@@ -100,10 +110,7 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source)
|
||||
__CurrentHealth -= damage;
|
||||
|
||||
if (IsFainted() && damage > 0) {
|
||||
if (!_battle->CanSlotBeFilled(_side->GetSideIndex(), _side->GetCreatureIndex(this))) {
|
||||
_side->MarkSlotAsUnfillable(this);
|
||||
}
|
||||
_battle->ValidateBattleState();
|
||||
OnFaint();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,3 +137,16 @@ void Battling::Creature::GetActiveScripts(std::vector<ScriptWrapper>& scripts) {
|
||||
_side->GetActiveScripts(scripts);
|
||||
}
|
||||
void Battling::Creature::ClearVolatileScripts() { _volatile.Clear(); }
|
||||
void Battling::Creature::AddExperience(uint32_t amount) {
|
||||
auto maxLevel = _library->GetSettings().GetMaximalLevel();
|
||||
if (__Level >= maxLevel) {
|
||||
return;
|
||||
}
|
||||
auto exp = __Experience + amount;
|
||||
auto level = _library->GetGrowthRateLibrary()->CalculateLevel(this->GetSpecies()->GetGrowthRate(), exp);
|
||||
if (level >= maxLevel) {
|
||||
exp = _library->GetGrowthRateLibrary()->CalculateExperience(this->GetSpecies()->GetGrowthRate(), maxLevel);
|
||||
}
|
||||
__Experience = exp;
|
||||
__Level = level;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,8 @@ namespace CreatureLib::Battling {
|
||||
Script* _status = nullptr;
|
||||
ScriptSet _volatile = {};
|
||||
|
||||
void OnFaint();
|
||||
|
||||
public:
|
||||
Creature(const BattleLibrary* library, const Library::CreatureSpecies* species,
|
||||
const Library::SpeciesVariant* variant, uint8_t level, uint32_t experience,
|
||||
@@ -83,6 +85,7 @@ namespace CreatureLib::Battling {
|
||||
void ChangeLevel(int8_t amount);
|
||||
void Damage(uint32_t damage, DamageSource source);
|
||||
void OverrideActiveTalent(const std::string& talent);
|
||||
void AddExperience(uint32_t amount);
|
||||
|
||||
void MarkOpponentAsSeen(Creature* creature) { _seenOpponents.insert(creature); }
|
||||
const std::unordered_set<Creature*>& GetSeenOpponents() const { return _seenOpponents; }
|
||||
|
||||
Reference in New Issue
Block a user