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:
@@ -5,15 +5,16 @@ using namespace CreatureLib::Battling;
|
||||
|
||||
BattleLibrary::BattleLibrary(CreatureLib::Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator,
|
||||
DamageLibrary* damageLibrary, CriticalLibrary* criticalLibrary,
|
||||
ScriptResolver* scriptResolver)
|
||||
ExperienceLibrary* experienceLibrary, ScriptResolver* scriptResolver)
|
||||
: _staticLib(staticLib), _statCalculator(statCalculator), _damageLibrary(damageLibrary),
|
||||
_criticalLibrary(criticalLibrary), _scriptResolver(scriptResolver) {}
|
||||
_criticalLibrary(criticalLibrary), _experienceLibrary(experienceLibrary), _scriptResolver(scriptResolver) {}
|
||||
|
||||
BattleLibrary::~BattleLibrary() {
|
||||
delete _staticLib;
|
||||
delete _statCalculator;
|
||||
delete _damageLibrary;
|
||||
delete _criticalLibrary;
|
||||
delete _experienceLibrary;
|
||||
delete _scriptResolver;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "BattleStatCalculator.hpp"
|
||||
#include "CriticalLibrary.hpp"
|
||||
#include "DamageLibrary.hpp"
|
||||
#include "ExperienceLibrary.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class BattleLibrary {
|
||||
@@ -13,11 +14,13 @@ namespace CreatureLib::Battling {
|
||||
BattleStatCalculator* _statCalculator = nullptr;
|
||||
DamageLibrary* _damageLibrary = nullptr;
|
||||
CriticalLibrary* _criticalLibrary = nullptr;
|
||||
ExperienceLibrary* _experienceLibrary = nullptr;
|
||||
ScriptResolver* _scriptResolver = nullptr;
|
||||
|
||||
public:
|
||||
BattleLibrary(Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator,
|
||||
DamageLibrary* damageLibrary, CriticalLibrary* criticalLibrary, ScriptResolver* scriptResolver);
|
||||
DamageLibrary* damageLibrary, CriticalLibrary* criticalLibrary,
|
||||
ExperienceLibrary* experienceLibrary, ScriptResolver* scriptResolver);
|
||||
~BattleLibrary();
|
||||
|
||||
[[nodiscard]] const Library::LibrarySettings& GetSettings() const;
|
||||
@@ -25,10 +28,14 @@ namespace CreatureLib::Battling {
|
||||
[[nodiscard]] const Library::ItemLibrary* GetItemLibrary() const;
|
||||
[[nodiscard]] const Library::AttackLibrary* GetAttackLibrary() const;
|
||||
[[nodiscard]] const Library::TypeLibrary* GetTypeLibrary() const;
|
||||
[[nodiscard]] const Library::GrowthRateLibrary* GetGrowthRateLibrary() const {
|
||||
return _staticLib->GetGrowthRates();
|
||||
}
|
||||
|
||||
[[nodiscard]] const BattleStatCalculator* GetStatCalculator() const;
|
||||
[[nodiscard]] const DamageLibrary* GetDamageLibrary() const;
|
||||
[[nodiscard]] const CriticalLibrary* GetCriticalLibrary() const;
|
||||
[[nodiscard]] const ExperienceLibrary* GetExperienceLibrary() const { return _experienceLibrary; }
|
||||
|
||||
[[nodiscard]] Script* LoadScript(ScriptResolver::ScriptCategory category, const std::string& scriptName) const;
|
||||
};
|
||||
|
||||
13
src/Battling/Library/ExperienceLibrary.cpp
Normal file
13
src/Battling/Library/ExperienceLibrary.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "ExperienceLibrary.hpp"
|
||||
#include "../Models/Creature.hpp"
|
||||
|
||||
void CreatureLib::Battling::ExperienceLibrary::HandleExperienceGain(
|
||||
CreatureLib::Battling::Creature* faintedMon, const std::unordered_set<Creature*>& opponents) const {
|
||||
for (auto opponent : opponents) {
|
||||
auto levelDiff = faintedMon->GetLevel() - opponent->GetLevel() + 10;
|
||||
if (levelDiff <= 0)
|
||||
continue;
|
||||
auto experienceGain = levelDiff * 10;
|
||||
opponent->AddExperience(static_cast<uint32_t>(experienceGain));
|
||||
}
|
||||
}
|
||||
16
src/Battling/Library/ExperienceLibrary.hpp
Normal file
16
src/Battling/Library/ExperienceLibrary.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef CREATURELIB_EXPERIENCELIBRARY_HPP
|
||||
#define CREATURELIB_EXPERIENCELIBRARY_HPP
|
||||
#include <unordered_set>
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class Creature;
|
||||
|
||||
class ExperienceLibrary {
|
||||
public:
|
||||
virtual ~ExperienceLibrary() = default;
|
||||
|
||||
virtual void HandleExperienceGain(Creature* faintedMon, const std::unordered_set<Creature*>& opponents) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_EXPERIENCELIBRARY_HPP
|
||||
Reference in New Issue
Block a user