Support for adding and replacing attacks.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
e39b352934
commit
9c6d149ad9
|
@ -112,3 +112,9 @@ export uint32_t CreatureLib_Creature_GetBaseStat(Creature* p, CreatureLib::Libra
|
||||||
export int8_t CreatureLib_Creature_GetStatBoost(Creature* p, CreatureLib::Library::Statistic stat) {
|
export int8_t CreatureLib_Creature_GetStatBoost(Creature* p, CreatureLib::Library::Statistic stat) {
|
||||||
return p->GetStatBoost(stat);
|
return p->GetStatBoost(stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SIMPLE_GET_FUNC(Creature, GetAvailableAttackSlot, uint8_t);
|
||||||
|
export uint8_t CreatureLib_Creature_AddAttack(Creature* p, LearnedAttack* attack) { Try(p->AddAttack(attack);) }
|
||||||
|
export uint8_t CreatureLib_Creature_ReplaceAttack(Creature* p, size_t index, LearnedAttack* attack) {
|
||||||
|
Try(p->ReplaceAttack(index, attack);)
|
||||||
|
}
|
|
@ -9,4 +9,4 @@ export const LibrarySettings* CreatureLib_LibrarySettings_Construct(uint8_t maxi
|
||||||
export void CreatureLib_LibrarySettings_Destruct(const LibrarySettings* p) { delete p; }
|
export void CreatureLib_LibrarySettings_Destruct(const LibrarySettings* p) { delete p; }
|
||||||
|
|
||||||
SIMPLE_GET_FUNC(LibrarySettings, GetMaximalLevel, uint8_t);
|
SIMPLE_GET_FUNC(LibrarySettings, GetMaximalLevel, uint8_t);
|
||||||
SIMPLE_GET_FUNC(LibrarySettings, GetMaximalMoves, uint8_t);
|
SIMPLE_GET_FUNC(LibrarySettings, GetMaximalAttacks, uint8_t);
|
|
@ -22,7 +22,7 @@ CreateCreature CreateCreature::WithGender(Library::Gender gender) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateCreature CreateCreature::WithAttack(const ArbUt::StringView& attackName, AttackLearnMethod learnMethod) {
|
CreateCreature CreateCreature::WithAttack(const ArbUt::StringView& attackName, AttackLearnMethod learnMethod) {
|
||||||
if (_attacks.Count() >= _library->GetSettings()->GetMaximalMoves()) {
|
if (_attacks.Count() >= _library->GetSettings()->GetMaximalAttacks()) {
|
||||||
THROW_CREATURE("You have already set the maximum amount of allowed moves.");
|
THROW_CREATURE("You have already set the maximum amount of allowed moves.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CreateCreature(ArbUt::BorrowedPtr<const BattleLibrary> library, const ArbUt::StringView& species, uint8_t level)
|
CreateCreature(ArbUt::BorrowedPtr<const BattleLibrary> library, const ArbUt::StringView& species, uint8_t level)
|
||||||
: _library(library), _species(species), _level(level), _attacks(library->GetSettings()->GetMaximalMoves()) {
|
: _library(library), _species(species), _level(level),
|
||||||
}
|
_attacks(library->GetSettings()->GetMaximalAttacks()) {}
|
||||||
|
|
||||||
CreateCreature WithVariant(const ArbUt::StringView& variant);
|
CreateCreature WithVariant(const ArbUt::StringView& variant);
|
||||||
CreateCreature WithNickname(std::string nickname);
|
CreateCreature WithNickname(std::string nickname);
|
||||||
|
|
|
@ -271,3 +271,36 @@ void Battling::Creature::AddVolatileScript(Script* script) { _volatile.Add(scrip
|
||||||
void Battling::Creature::RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
|
void Battling::Creature::RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
|
||||||
void Battling::Creature::RemoveVolatileScript(Battling::Script* script) { _volatile.Remove(script->GetName()); }
|
void Battling::Creature::RemoveVolatileScript(Battling::Script* script) { _volatile.Remove(script->GetName()); }
|
||||||
bool Battling::Creature::HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
|
bool Battling::Creature::HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
|
||||||
|
void Battling::Creature::AddAttack(Battling::LearnedAttack* attack) {
|
||||||
|
for (size_t i = 0; i < _attacks.Count(); i++) {
|
||||||
|
if (_attacks[i] == nullptr) {
|
||||||
|
_attacks.Set(i, attack);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_attacks.Count() < _library->GetStaticLib()->GetSettings()->GetMaximalAttacks()) {
|
||||||
|
_attacks.Append(attack);
|
||||||
|
}
|
||||||
|
THROW_CREATURE("Can't add attack. The creature already has the maximum amount of attacks.");
|
||||||
|
}
|
||||||
|
uint8_t Battling::Creature::GetAvailableAttackSlot() const noexcept {
|
||||||
|
for (uint8_t i = 0; i < (uint8_t)_attacks.Count(); i++) {
|
||||||
|
if (_attacks[i] == nullptr) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_attacks.Count() < _library->GetStaticLib()->GetSettings()->GetMaximalAttacks()) {
|
||||||
|
return _attacks.Count();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
void Battling::Creature::ReplaceAttack(size_t index, Battling::LearnedAttack* attack) {
|
||||||
|
if (_attacks.Count() <= index) {
|
||||||
|
if (_attacks.Count() < _library->GetStaticLib()->GetSettings()->GetMaximalAttacks()) {
|
||||||
|
_attacks.Append(attack);
|
||||||
|
}
|
||||||
|
THROW_CREATURE("Can't replace attack at index " << index << ". Number of attacks is " << _attacks.Count()
|
||||||
|
<< ".");
|
||||||
|
}
|
||||||
|
_attacks.Set(index, attack);
|
||||||
|
}
|
||||||
|
|
|
@ -161,6 +161,10 @@ namespace CreatureLib::Battling {
|
||||||
inline bool AllowedExperienceGain() const noexcept { return _allowedExperienceGain; }
|
inline bool AllowedExperienceGain() const noexcept { return _allowedExperienceGain; }
|
||||||
inline void SetAllowedExperienceGain(bool allowed) noexcept { _allowedExperienceGain = allowed; }
|
inline void SetAllowedExperienceGain(bool allowed) noexcept { _allowedExperienceGain = allowed; }
|
||||||
|
|
||||||
|
uint8_t GetAvailableAttackSlot() const noexcept;
|
||||||
|
void AddAttack(LearnedAttack* attack);
|
||||||
|
void ReplaceAttack(size_t index, LearnedAttack* attack);
|
||||||
|
|
||||||
// region Stat APIs
|
// region Stat APIs
|
||||||
|
|
||||||
bool ChangeStatBoost(Library::Statistic stat, int8_t diffAmount);
|
bool ChangeStatBoost(Library::Statistic stat, int8_t diffAmount);
|
||||||
|
|
|
@ -6,15 +6,15 @@
|
||||||
namespace CreatureLib::Library {
|
namespace CreatureLib::Library {
|
||||||
class LibrarySettings {
|
class LibrarySettings {
|
||||||
uint8_t _maximalLevel;
|
uint8_t _maximalLevel;
|
||||||
uint8_t _maximalMoves;
|
uint8_t _maximalAttacks;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LibrarySettings(uint8_t maximalLevel, uint8_t maximalMoves)
|
LibrarySettings(uint8_t maximalLevel, uint8_t maximalAttacks)
|
||||||
: _maximalLevel(maximalLevel), _maximalMoves(maximalMoves) {}
|
: _maximalLevel(maximalLevel), _maximalAttacks(maximalAttacks) {}
|
||||||
|
|
||||||
inline uint8_t GetMaximalLevel() const noexcept { return _maximalLevel; }
|
inline uint8_t GetMaximalLevel() const noexcept { return _maximalLevel; }
|
||||||
|
|
||||||
inline uint8_t GetMaximalMoves() const noexcept { return _maximalMoves; }
|
inline uint8_t GetMaximalAttacks() const noexcept { return _maximalAttacks; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue