Several fixes and improvements.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
bbb2691b91
commit
31008c0107
|
@ -10,7 +10,7 @@ export uint8_t PkmnLib_Battle_Construct(Battle*& out, const BattleLibrary* libra
|
|||
Try(out = new Battle(library, partiesList, canFlee, numberOfSides, creaturesPerSide, randomSeed));
|
||||
}
|
||||
|
||||
export void PkmnLib_Battle_Destruct(Battle* p) { delete p; }
|
||||
export void PkmnLib_Battle_Destruct(Battle* p) { p->~Battle(); }
|
||||
export uint8_t PkmnLib_Battle_SetWeather(Battle* p, const char* name) { Try(p->SetWeather(ArbUt::StringView(name))); };
|
||||
export uint8_t PkmnLib_Battle_ClearWeather(Battle* p) { Try(p->ClearWeather()); };
|
||||
export const char* PkmnLib_Battle_GetWeatherName(Battle* p) { return p->GetWeatherName().c_str(); }
|
|
@ -2,23 +2,26 @@
|
|||
#include "../Core.hpp"
|
||||
using namespace PkmnLib::Battling;
|
||||
|
||||
export Pokemon* PkmnLib_Pokemon_Construct(const BattleLibrary* library, const PkmnLib::Library::PokemonSpecies* species,
|
||||
const PkmnLib::Library::PokemonForme* forme, uint8_t level,
|
||||
uint32_t experience, uint32_t uid, CreatureLib::Library::Gender gender,
|
||||
uint8_t coloring, const PkmnLib::Library::Item* heldItem,
|
||||
const char* nickname, bool hiddenAbility, uint8_t abilityIndex,
|
||||
CreatureLib::Battling::LearnedAttack* const* moves, size_t moveCount,
|
||||
uint8_t hpIv, uint8_t attIv, uint8_t defIv, uint8_t sAtIv, uint8_t sDeIv,
|
||||
uint8_t spIv, uint8_t hpEv, uint8_t attEv, uint8_t defEv, uint8_t sAtEv,
|
||||
uint8_t sDeEv, uint8_t spEv, const PkmnLib::Library::Nature* nature) {
|
||||
std::string nick(nickname);
|
||||
std::vector<CreatureLib::Battling::LearnedAttack*> cMoves(moves, moves + moveCount);
|
||||
export uint8_t PkmnLib_Pokemon_Construct(
|
||||
Pokemon*& out, const BattleLibrary* library, const PkmnLib::Library::PokemonSpecies* species,
|
||||
const PkmnLib::Library::PokemonForme* forme, uint8_t level, uint32_t experience, uint32_t uid,
|
||||
CreatureLib::Library::Gender gender, uint8_t coloring, const PkmnLib::Library::Item* heldItem, const char* nickname,
|
||||
bool hiddenAbility, uint8_t abilityIndex, CreatureLib::Battling::LearnedAttack* const* moves, size_t moveCount,
|
||||
uint8_t hpIv, uint8_t attIv, uint8_t defIv, uint8_t sAtIv, uint8_t sDeIv, uint8_t spIv, uint8_t hpEv, uint8_t attEv,
|
||||
uint8_t defEv, uint8_t sAtEv, uint8_t sDeEv, uint8_t spEv, const PkmnLib::Library::Nature* nature) {
|
||||
Try({
|
||||
if (nickname == nullptr) {
|
||||
nickname = "";
|
||||
}
|
||||
std::string nick(nickname);
|
||||
std::vector<CreatureLib::Battling::LearnedAttack*> cMoves(moves, moves + moveCount);
|
||||
|
||||
return new Pokemon(
|
||||
library, species, forme, level, experience, uid, gender, coloring, heldItem, nick,
|
||||
CreatureLib::Library::TalentIndex(hiddenAbility, abilityIndex), cMoves,
|
||||
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 31>(hpIv, attIv, defIv, sAtIv, sDeIv, spIv),
|
||||
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 252>(hpEv, attEv, defEv, sAtEv, sDeEv, spEv), nature);
|
||||
out = new Pokemon(
|
||||
library, species, forme, level, experience, uid, gender, coloring, heldItem, nick,
|
||||
CreatureLib::Library::TalentIndex(hiddenAbility, abilityIndex), cMoves,
|
||||
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 31>(hpIv, attIv, defIv, sAtIv, sDeIv, spIv),
|
||||
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 252>(hpEv, attEv, defEv, sAtEv, sDeEv, spEv), nature);
|
||||
})
|
||||
};
|
||||
|
||||
export void PkmnLib_Pokemon_Destruct(const Pokemon* p) { delete p; }
|
||||
|
|
|
@ -19,6 +19,8 @@ namespace PkmnLib::Battling {
|
|||
.count())
|
||||
: CreatureLib::Battling::Battle(library, parties, canFlee, numberOfSides, creaturesPerSide, randomSeed) {}
|
||||
|
||||
virtual ~Battle() = default;
|
||||
|
||||
void SetWeather(const ArbUt::StringView& name);
|
||||
void ClearWeather();
|
||||
const ArbUt::StringView& GetWeatherName() noexcept {
|
||||
|
|
|
@ -29,8 +29,8 @@ namespace PkmnLib::Battling {
|
|||
ArbUt::BorrowedPtr<const PkmnLib::Library::Nature> nature, bool allowedExperienceGain = true)
|
||||
: CreatureLib::Battling::Creature(library.ForceAs<const CreatureLib::Battling::BattleLibrary>(),
|
||||
species.ForceAs<const CreatureLib::Library::CreatureSpecies>(),
|
||||
forme.As<const CreatureLib::Library::SpeciesVariant>(), level, experience,
|
||||
uid, gender, coloring, heldItem.As<const CreatureLib::Library::Item>(),
|
||||
forme.ForceAs<const CreatureLib::Library::SpeciesVariant>(), level, experience,
|
||||
uid, gender, coloring, heldItem.ForceAs<const CreatureLib::Library::Item>(),
|
||||
nickname, talent, moves, allowedExperienceGain),
|
||||
_individualValues(individualValues), _effortValues(effortValues), _nature(nature),
|
||||
_friendship(species->GetBaseHappiness()) {}
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace PkmnLib::Battling {
|
|||
PokemonParty(std::initializer_list<CreatureLib::Battling::Creature*> party)
|
||||
: CreatureLib::Battling::CreatureParty(party) {}
|
||||
|
||||
ArbUt::BorrowedPtr<Pokemon> GetAtIndex(int index) const {
|
||||
ArbUt::OptionalBorrowedPtr<Pokemon> GetAtIndex(int index) const {
|
||||
return CreatureLib::Battling::CreatureParty::GetAtIndex(index).As<Pokemon>();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#ifdef TESTS_BUILD
|
||||
#include <CreatureLib/Battling/TurnChoices/AttackTurnChoice.hpp>
|
||||
#include <CreatureLib/Battling/TurnChoices/PassTurnChoice.hpp>
|
||||
#include "../../extern/doctest.hpp"
|
||||
#include "../../src/Battling/Battle/Battle.hpp"
|
||||
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||
#include "../../src/Battling/Pokemon/PokemonParty.hpp"
|
||||
#include "../TestLibrary/TestLibrary.hpp"
|
||||
|
||||
TEST_CASE("Create and delete Pokemon") {
|
||||
|
@ -31,4 +35,44 @@ TEST_CASE("Get Attack name from Pokemon") {
|
|||
delete mon;
|
||||
}
|
||||
|
||||
TEST_CASE("Heal pokemon after battle") {
|
||||
auto library = TestLibrary::GetLibrary();
|
||||
auto c1 = PkmnLib::Battling::CreatePokemon(library, "testSpecies"_cnc, 50)
|
||||
.LearnMove("testMove"_cnc, CreatureLib::Battling::AttackLearnMethod::Unknown)
|
||||
.Build();
|
||||
PkmnLib::Battling::PokemonParty party1{c1};
|
||||
auto battleParty1 = new CreatureLib::Battling::BattleParty(&party1, {CreatureLib::Battling::CreatureIndex(0, 0)});
|
||||
auto c2 = PkmnLib::Battling::CreatePokemon(library, "testSpecies"_cnc, 50)
|
||||
.LearnMove("testMove"_cnc, CreatureLib::Battling::AttackLearnMethod::Unknown)
|
||||
.Build();
|
||||
PkmnLib::Battling::PokemonParty party2{c2};
|
||||
auto battleParty2 = new CreatureLib::Battling::BattleParty(&party2, {CreatureLib::Battling::CreatureIndex(1, 0)});
|
||||
|
||||
auto battle = new PkmnLib::Battling::Battle(library, {battleParty1, battleParty2});
|
||||
|
||||
REQUIRE_FALSE(battle->HasEnded());
|
||||
|
||||
battle->SwitchCreature(0, 0, c1);
|
||||
battle->SwitchCreature(1, 0, c2);
|
||||
|
||||
REQUIRE_FALSE(battle->HasEnded());
|
||||
REQUIRE(battle->TrySetChoice(new CreatureLib::Battling::AttackTurnChoice(
|
||||
c1, c1->GetAttacks()[0].GetValue(), CreatureLib::Battling::CreatureIndex(1, 0))));
|
||||
REQUIRE(battle->TrySetChoice(new CreatureLib::Battling::PassTurnChoice(c2)));
|
||||
|
||||
REQUIRE_FALSE(battle->HasEnded());
|
||||
|
||||
REQUIRE(c2->GetCurrentHealth() < c2->GetBoostedStat(PkmnLib::Library::Statistic::HealthPoints));
|
||||
|
||||
c2->Damage(c2->GetCurrentHealth(), CreatureLib::Battling::DamageSource::AttackDamage);
|
||||
|
||||
REQUIRE(battle->HasEnded());
|
||||
auto result = battle->GetResult();
|
||||
REQUIRE(result.IsConclusiveResult());
|
||||
REQUIRE(result.GetWinningSide() == 0);
|
||||
delete battle;
|
||||
c2->Heal(1000, true);
|
||||
REQUIRE(c2->GetCurrentHealth() == c2->GetMaxHealth());
|
||||
}
|
||||
|
||||
#endif
|
|
@ -60,6 +60,7 @@ public:
|
|||
|
||||
static CreatureLib::Library::TypeLibrary* BuildTypeLibrary() {
|
||||
auto lib = new CreatureLib::Library::TypeLibrary();
|
||||
lib->RegisterType("testType1"_cnc);
|
||||
return lib;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue