Support for adding and replacing attacks.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
@@ -22,7 +22,7 @@ CreateCreature CreateCreature::WithGender(Library::Gender gender) {
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace CreatureLib::Battling {
|
||||
|
||||
public:
|
||||
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 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(Battling::Script* script) { _volatile.Remove(script->GetName()); }
|
||||
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 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
|
||||
|
||||
bool ChangeStatBoost(Library::Statistic stat, int8_t diffAmount);
|
||||
|
||||
Reference in New Issue
Block a user