Fixed issue where base stats of a variant got corrupted.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-03-22 15:25:38 +01:00
parent 899e432271
commit 475392f9b6
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
8 changed files with 13 additions and 13 deletions

View File

@ -27,15 +27,15 @@ Battling::BattleStatCalculator::CalculateBoostedStats(Battling::Creature* creatu
uint32_t CalculateHealthStat(Battling::Creature* creature) { uint32_t CalculateHealthStat(Battling::Creature* creature) {
AssertNotNull(creature) AssertNotNull(creature)
auto level = creature->GetLevel(); auto level = creature->GetLevel();
auto a = (creature->GetBaseStat(Library::Statistic::Health)) * 2 * level; float a = (creature->GetBaseStat(Library::Statistic::Health)) * 2.0 * level;
return floor(a / 100) + level + 10; return static_cast<uint32_t>(floor(a / 100.0) + level + 10);
} }
uint32_t CalculateOtherStat(Battling::Creature* creature, Library::Statistic stat) { uint32_t CalculateOtherStat(Battling::Creature* creature, Library::Statistic stat) {
AssertNotNull(creature) AssertNotNull(creature)
auto level = creature->GetLevel(); auto level = creature->GetLevel();
auto a = (creature->GetBaseStat(stat)) * 2 * level; float a = (creature->GetBaseStat(stat)) * 2.0 * level;
return floor(a / 100) + 10; return static_cast<uint32_t>(floor(a / 100.0) + 5);
} }
uint32_t Battling::BattleStatCalculator::CalculateFlatStat(Battling::Creature* creature, uint32_t Battling::BattleStatCalculator::CalculateFlatStat(Battling::Creature* creature,

View File

@ -6,7 +6,7 @@ using namespace CreatureLib::Battling;
uint32_t DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const { uint32_t DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const {
AssertNotNull(attack) AssertNotNull(attack)
AssertNotNull(target) AssertNotNull(target)
auto levelMod = static_cast<float>(2 * attack->GetUser()->GetLevel()); auto levelMod = static_cast<float>(2 * attack->GetUser()->GetLevel()) / 5 + 2;
auto hit = attack->GetAttackDataForTarget(target)->GetHit(hitIndex); auto hit = attack->GetAttackDataForTarget(target)->GetHit(hitIndex);
auto bp = hit->GetBasePower(); auto bp = hit->GetBasePower();
auto statMod = GetStatModifier(attack, target, hitIndex); auto statMod = GetStatModifier(attack, target, hitIndex);

View File

@ -59,6 +59,7 @@ void Battle::CheckChoicesSetAndRun() {
} }
side->ResetChoices(); side->ResetChoices();
} }
_currentTurn++;
TurnOrdering::OrderChoices(choices, _random.GetRNG()); TurnOrdering::OrderChoices(choices, _random.GetRNG());
this->_currentTurnQueue = new ChoiceQueue(choices); this->_currentTurnQueue = new ChoiceQueue(choices);
TurnHandler::RunTurn(this->_currentTurnQueue); TurnHandler::RunTurn(this->_currentTurnQueue);

View File

@ -26,6 +26,7 @@ namespace CreatureLib::Battling {
bool _hasEnded = false; bool _hasEnded = false;
BattleResult _battleResult = BattleResult::Empty(); BattleResult _battleResult = BattleResult::Empty();
EventHook _eventHook = EventHook(); EventHook _eventHook = EventHook();
uint32_t _currentTurn = 0;
ScriptSet _volatile; ScriptSet _volatile;
@ -55,6 +56,7 @@ namespace CreatureLib::Battling {
} }
[[nodiscard]] const BattleLibrary* GetLibrary() const; [[nodiscard]] const BattleLibrary* GetLibrary() const;
[[nodiscard]] uint32_t GetCurrentTurn() const noexcept { return _currentTurn; }
virtual bool CanUse(const BaseTurnChoice* choice); virtual bool CanUse(const BaseTurnChoice* choice);
virtual bool TrySetChoice(BaseTurnChoice* choice); virtual bool TrySetChoice(BaseTurnChoice* choice);

View File

@ -37,7 +37,7 @@ const CreatureLib::Library::LearnableAttacks* CreatureLib::Library::SpeciesVaria
CreatureLib::Library::SpeciesVariant::SpeciesVariant(ConstString name, float height, float weight, CreatureLib::Library::SpeciesVariant::SpeciesVariant(ConstString name, float height, float weight,
uint32_t baseExperience, std::vector<uint8_t> types, uint32_t baseExperience, std::vector<uint8_t> types,
const CreatureLib::Library::StatisticSet<uint16_t>& baseStats, CreatureLib::Library::StatisticSet<uint16_t> baseStats,
std::vector<ConstString> talents, std::vector<ConstString> talents,
std::vector<ConstString> secretTalents, std::vector<ConstString> secretTalents,
const LearnableAttacks* attacks) const LearnableAttacks* attacks)

View File

@ -23,14 +23,14 @@ namespace CreatureLib::Library {
private: private:
std::vector<uint8_t> _types; std::vector<uint8_t> _types;
const Library::StatisticSet<uint16_t>& _baseStatistics; Library::StatisticSet<uint16_t> _baseStatistics;
std::vector<ConstString> _talents; std::vector<ConstString> _talents;
std::vector<ConstString> _secretTalents; std::vector<ConstString> _secretTalents;
const LearnableAttacks* _attacks; const LearnableAttacks* _attacks;
public: public:
SpeciesVariant(ConstString name, float height, float weight, uint32_t baseExperience, SpeciesVariant(ConstString name, float height, float weight, uint32_t baseExperience,
std::vector<uint8_t> types, const Library::StatisticSet<uint16_t>& baseStats, std::vector<uint8_t> types, Library::StatisticSet<uint16_t> baseStats,
std::vector<ConstString> talents, std::vector<ConstString> secretTalents, std::vector<ConstString> talents, std::vector<ConstString> secretTalents,
const LearnableAttacks* attacks); const LearnableAttacks* attacks);

View File

@ -15,9 +15,6 @@ namespace CreatureLib::Library {
T _magicalDefense; T _magicalDefense;
T _speed; T _speed;
private:
StatisticSet<T>(const StatisticSet<T>& v) = delete;
public: public:
StatisticSet(T health, T physicalAttack, T physicalDefense, T magicalAttack, T magicalDefense, T speed) StatisticSet(T health, T physicalAttack, T physicalDefense, T magicalAttack, T magicalDefense, T speed)
: _health(health), _physicalAttack(physicalAttack), _physicalDefense(physicalDefense), : _health(health), _physicalAttack(physicalAttack), _physicalDefense(physicalDefense),

View File

@ -76,8 +76,8 @@ TEST_CASE("Finish battle when all battle of one side have fainted", "[Integratio
REQUIRE_FALSE(battle.HasEnded()); REQUIRE_FALSE(battle.HasEnded());
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0], CreatureIndex(1, 0))); REQUIRE(battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0], CreatureIndex(1, 0))));
battle.TrySetChoice(new PassTurnChoice(c2)); REQUIRE(battle.TrySetChoice(new PassTurnChoice(c2)));
REQUIRE_FALSE(battle.HasEnded()); REQUIRE_FALSE(battle.HasEnded());