Update to newer Arbutils version.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -60,7 +60,7 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
|
||||
|
||||
// FIXME: Resolve all targets
|
||||
auto target = choice->GetUser()->GetBattle()->GetCreature(choice->GetTarget());
|
||||
Arbutils::Collections::List<Creature*> targets = {target};
|
||||
ArbUt::List<Creature*> targets = {target};
|
||||
|
||||
auto attack = new ExecutingAttack(targets, 1, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript());
|
||||
bool prevented = false;
|
||||
|
||||
@@ -29,6 +29,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void TurnOrdering::OrderChoices(std::vector<BaseTurnChoice*>& vec, Arbutils::Random& rand) {
|
||||
void TurnOrdering::OrderChoices(std::vector<BaseTurnChoice*>& vec, ArbUt::Random& rand) {
|
||||
std::sort(vec.begin(), vec.end(), ChoiceCompare());
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace CreatureLib::Battling {
|
||||
class TurnOrdering {
|
||||
public:
|
||||
static void OrderChoices(std::vector<BaseTurnChoice*>& vec, Arbutils::Random& rand);
|
||||
static void OrderChoices(std::vector<BaseTurnChoice*>& vec, ArbUt::Random& rand);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ const std::unique_ptr<const DamageLibrary>& BattleLibrary::GetDamageLibrary() co
|
||||
|
||||
const std::unique_ptr<const MiscLibrary>& BattleLibrary::GetMiscLibrary() const noexcept { return _miscLibrary; }
|
||||
|
||||
Script* BattleLibrary::LoadScript(ScriptCategory category,
|
||||
const Arbutils::CaseInsensitiveConstString& scriptName) const {
|
||||
Script* BattleLibrary::LoadScript(ScriptCategory category, const ArbUt::CaseInsensitiveConstString& scriptName) const {
|
||||
return _scriptResolver->LoadScript(category, scriptName);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ namespace CreatureLib::Battling {
|
||||
}
|
||||
|
||||
[[nodiscard]] Script* LoadScript(ScriptCategory category,
|
||||
const Arbutils::CaseInsensitiveConstString& scriptName) const;
|
||||
const ArbUt::CaseInsensitiveConstString& scriptName) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ bool CreatureLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::Execu
|
||||
static CreatureLib::Battling::LearnedAttack* _replacementAttack = nullptr;
|
||||
static std::unique_ptr<const CreatureLib::Library::AttackData> _replacementAttackData = nullptr;
|
||||
|
||||
static borrowed_ptr<const CreatureLib::Library::AttackData> GetReplacementAttackData() {
|
||||
static ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData> GetReplacementAttackData() {
|
||||
if (_replacementAttackData == nullptr) {
|
||||
_replacementAttackData =
|
||||
std::unique_ptr<const CreatureLib::Library::AttackData>(new CreatureLib::Library::AttackData(
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
using namespace CreatureLib;
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
const BattleLibrary* Battle::GetLibrary() const noexcept { return _library; }
|
||||
const ArbUt::BorrowedPtr<const BattleLibrary>& Battle::GetLibrary() const noexcept { return _library; }
|
||||
|
||||
bool Battle::CanUse(const BaseTurnChoice* choice) {
|
||||
AssertNotNull(choice)
|
||||
@@ -86,7 +86,7 @@ bool Battle::CreatureInField(const Creature* creature) const {
|
||||
void Battle::ForceRecall(uint8_t side, uint8_t index) { _sides[side]->SetCreature(nullptr, index); }
|
||||
|
||||
size_t Battle::ScriptCount() const { return 1; }
|
||||
void Battle::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) {
|
||||
void Battle::GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) {
|
||||
scripts.Append(ScriptWrapper::FromSet(&_volatile));
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <memory>
|
||||
#include "../EventHooks/EventHook.hpp"
|
||||
#include "../Flow/ChoiceQueue.hpp"
|
||||
#include "../Library/BattleLibrary.hpp"
|
||||
@@ -13,17 +14,15 @@
|
||||
#include "BattleSide.hpp"
|
||||
#include "CreatureIndex.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class Battle : public ScriptSource {
|
||||
protected:
|
||||
const BattleLibrary* _library;
|
||||
List<BattleParty*> _parties;
|
||||
ArbUt::BorrowedPtr<const BattleLibrary> _library;
|
||||
ArbUt::List<std::unique_ptr<BattleParty>> _parties;
|
||||
bool _canFlee;
|
||||
uint8_t _numberOfSides;
|
||||
uint8_t _creaturesPerSide;
|
||||
List<BattleSide*> _sides;
|
||||
ArbUt::List<BattleSide*> _sides;
|
||||
BattleRandom _random;
|
||||
ChoiceQueue* _currentTurnQueue = nullptr;
|
||||
bool _hasEnded = false;
|
||||
@@ -34,14 +33,17 @@ namespace CreatureLib::Battling {
|
||||
ScriptSet _volatile;
|
||||
|
||||
public:
|
||||
Battle(const BattleLibrary* library, List<BattleParty*> parties, bool canFlee = true, uint8_t numberOfSides = 2,
|
||||
uint8_t creaturesPerSide = 1)
|
||||
: _library(library), _parties(std::move(parties)), _canFlee(canFlee), _numberOfSides(numberOfSides),
|
||||
Battle(const BattleLibrary* library, ArbUt::List<BattleParty*> parties, bool canFlee = true,
|
||||
uint8_t numberOfSides = 2, uint8_t creaturesPerSide = 1)
|
||||
: _library(library), _parties(parties.Count()), _canFlee(canFlee), _numberOfSides(numberOfSides),
|
||||
_creaturesPerSide(creaturesPerSide) {
|
||||
AssertNotNull(_library);
|
||||
AssertAllNotNull(parties);
|
||||
for (size_t i = 0; i < parties.Count(); i++) {
|
||||
_parties.GetStdList().push_back(std::unique_ptr<BattleParty>(parties[i]));
|
||||
}
|
||||
|
||||
_sides = List<BattleSide*>(numberOfSides);
|
||||
_sides = ArbUt::List<BattleSide*>(numberOfSides);
|
||||
for (size_t i = 0; i < numberOfSides; i++) {
|
||||
_sides.Append(new BattleSide(i, this, creaturesPerSide));
|
||||
}
|
||||
@@ -51,13 +53,10 @@ namespace CreatureLib::Battling {
|
||||
for (auto s : _sides) {
|
||||
delete s;
|
||||
}
|
||||
for (auto party : _parties) {
|
||||
delete party;
|
||||
}
|
||||
delete _currentTurnQueue;
|
||||
}
|
||||
|
||||
[[nodiscard]] const BattleLibrary* GetLibrary() const noexcept;
|
||||
[[nodiscard]] const ArbUt::BorrowedPtr<const BattleLibrary>& GetLibrary() const noexcept;
|
||||
[[nodiscard]] uint32_t GetCurrentTurn() const noexcept { return _currentTurn; }
|
||||
|
||||
virtual bool CanUse(const BaseTurnChoice* choice);
|
||||
@@ -82,14 +81,14 @@ namespace CreatureLib::Battling {
|
||||
bool CanSlotBeFilled(uint8_t side, uint8_t index) const;
|
||||
|
||||
size_t ScriptCount() const override;
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;
|
||||
|
||||
void ValidateBattleState();
|
||||
inline bool HasEnded() const noexcept { return _hasEnded; }
|
||||
inline const BattleResult& GetResult() const noexcept { return _battleResult; }
|
||||
|
||||
const List<BattleParty*>& GetParties() const noexcept { return _parties; }
|
||||
const List<BattleSide*>& GetSides() const noexcept { return _sides; }
|
||||
const ArbUt::List<std::unique_ptr<BattleParty>>& GetParties() const noexcept { return _parties; }
|
||||
const ArbUt::List<BattleSide*>& GetSides() const noexcept { return _sides; }
|
||||
Script* GetVolatileScript(const ConstString& key) const { return _volatile.Get(key); }
|
||||
Script* GetVolatileScript(uint32_t keyHash) const noexcept { return _volatile.Get(keyHash); }
|
||||
void AddVolatileScript(const ConstString& key);
|
||||
|
||||
@@ -6,21 +6,19 @@
|
||||
#include "CreatureIndex.hpp"
|
||||
#include "CreatureParty.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class BattleParty {
|
||||
CreatureParty* _party;
|
||||
List<CreatureIndex> _responsibleIndices;
|
||||
ArbUt::List<CreatureIndex> _responsibleIndices;
|
||||
|
||||
public:
|
||||
BattleParty(CreatureParty* party, const List<CreatureIndex>& responsibleIndices)
|
||||
BattleParty(CreatureParty* party, const ArbUt::List<CreatureIndex>& responsibleIndices)
|
||||
: _party(party), _responsibleIndices(responsibleIndices) {
|
||||
AssertNotNull(_party)
|
||||
}
|
||||
|
||||
inline CreatureParty* GetParty() const { return _party; }
|
||||
inline const List<CreatureIndex>& GetResponsibleIndices() const { return _responsibleIndices; }
|
||||
inline const ArbUt::List<CreatureIndex>& GetResponsibleIndices() const { return _responsibleIndices; }
|
||||
|
||||
inline bool IsResponsibleForIndex(const CreatureIndex& index) const {
|
||||
return _responsibleIndices.Contains(index);
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace CreatureLib::Battling {
|
||||
|
||||
class BattleRandom {
|
||||
private:
|
||||
Arbutils::Random _random;
|
||||
ArbUt::Random _random;
|
||||
|
||||
public:
|
||||
BattleRandom() noexcept : _random() {}
|
||||
@@ -19,7 +19,7 @@ namespace CreatureLib::Battling {
|
||||
int32_t Get() noexcept { return _random.Get(); }
|
||||
int32_t Get(int32_t max) noexcept { return _random.Get(max); }
|
||||
int32_t Get(int32_t min, int32_t max) noexcept { return _random.Get(min, max); }
|
||||
Arbutils::Random& GetRNG() noexcept { return _random; }
|
||||
ArbUt::Random& GetRNG() noexcept { return _random; }
|
||||
uint_fast32_t GetSeed() const noexcept { return _random.GetSeed(); }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ void BattleSide::ResetChoices() noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
const List<BaseTurnChoice*>& BattleSide::GetChoices() const noexcept { return _choices; }
|
||||
const ArbUt::List<BaseTurnChoice*>& BattleSide::GetChoices() const noexcept { return _choices; }
|
||||
|
||||
void BattleSide::SetChoice(BaseTurnChoice* choice) {
|
||||
AssertNotNull(choice)
|
||||
@@ -69,7 +69,7 @@ bool BattleSide::CreatureOnSide(const Creature* creature) const {
|
||||
|
||||
Creature* BattleSide::GetCreature(uint8_t index) const { return _creatures[index]; }
|
||||
|
||||
void BattleSide::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) {
|
||||
void BattleSide::GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) {
|
||||
scripts.Append(ScriptWrapper::FromSet(&_volatile));
|
||||
_battle->GetActiveScripts(scripts);
|
||||
}
|
||||
|
||||
@@ -7,15 +7,13 @@
|
||||
#include "../TurnChoices/BaseTurnChoice.hpp"
|
||||
#include "Creature.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class BattleSide : public ScriptSource {
|
||||
uint8_t _index;
|
||||
uint8_t _creaturesPerSide;
|
||||
List<Creature*> _creatures;
|
||||
List<BaseTurnChoice*> _choices;
|
||||
List<bool> _fillableSlots;
|
||||
ArbUt::List<Creature*> _creatures;
|
||||
ArbUt::List<BaseTurnChoice*> _choices;
|
||||
ArbUt::List<bool> _fillableSlots;
|
||||
uint8_t _choicesSet = 0;
|
||||
ScriptSet _volatile;
|
||||
Battle* _battle;
|
||||
@@ -36,7 +34,7 @@ namespace CreatureLib::Battling {
|
||||
virtual ~BattleSide() = default;
|
||||
|
||||
[[nodiscard]] bool AllChoicesSet() const noexcept;
|
||||
[[nodiscard]] const List<BaseTurnChoice*>& GetChoices() const noexcept;
|
||||
[[nodiscard]] const ArbUt::List<BaseTurnChoice*>& GetChoices() const noexcept;
|
||||
|
||||
[[nodiscard]] bool AllPossibleSlotsFilled() const;
|
||||
|
||||
@@ -49,9 +47,9 @@ namespace CreatureLib::Battling {
|
||||
bool CreatureOnSide(const Creature* creature) const;
|
||||
|
||||
size_t ScriptCount() const override;
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;
|
||||
|
||||
const List<Creature*>& GetCreatures() { return _creatures; }
|
||||
const ArbUt::List<Creature*>& GetCreatures() { return _creatures; }
|
||||
|
||||
uint8_t GetSideIndex() noexcept { return _index; }
|
||||
uint8_t GetCreatureIndex(Creature* c) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
CreateCreature CreateCreature::WithVariant(const Arbutils::CaseInsensitiveConstString& variant) {
|
||||
CreateCreature CreateCreature::WithVariant(const ArbUt::CaseInsensitiveConstString& variant) {
|
||||
this->_variant = variant;
|
||||
return *this;
|
||||
}
|
||||
@@ -20,7 +20,7 @@ CreateCreature CreateCreature::WithGender(Library::Gender gender) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
CreateCreature CreateCreature::WithAttack(const Arbutils::CaseInsensitiveConstString& attackName,
|
||||
CreateCreature CreateCreature::WithAttack(const ArbUt::CaseInsensitiveConstString& attackName,
|
||||
AttackLearnMethod learnMethod) {
|
||||
if (_attacks.Count() >= _library->GetSettings()->GetMaximalMoves())
|
||||
throw CreatureException("You have already set the maximum amount of allowed moves.");
|
||||
@@ -31,7 +31,7 @@ CreateCreature CreateCreature::WithAttack(const Arbutils::CaseInsensitiveConstSt
|
||||
}
|
||||
|
||||
Creature* CreateCreature::Create() {
|
||||
auto rand = Arbutils::Random();
|
||||
auto rand = ArbUt::Random();
|
||||
auto species = this->_library->GetSpeciesLibrary()->Get(this->_species.GetHash());
|
||||
auto variant = species->GetVariant(this->_variant);
|
||||
Library::TalentIndex talent;
|
||||
@@ -48,7 +48,7 @@ Creature* CreateCreature::Create() {
|
||||
if (gender == static_cast<Library::Gender>(-1)) {
|
||||
gender = species->GetRandomGender(rand);
|
||||
}
|
||||
borrowed_ptr<const Library::Item> heldItem;
|
||||
ArbUt::BorrowedPtr<const Library::Item> heldItem;
|
||||
if (!this->_heldItem.Empty()) {
|
||||
if (!_library->GetItemLibrary()->TryGet(this->_heldItem.GetHash(), heldItem)) {
|
||||
throw CreatureException("Invalid held item.");
|
||||
@@ -56,7 +56,7 @@ Creature* CreateCreature::Create() {
|
||||
}
|
||||
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
|
||||
|
||||
auto attacks = List<LearnedAttack*>(_attacks.Count());
|
||||
auto attacks = ArbUt::List<LearnedAttack*>(_attacks.Count());
|
||||
for (size_t i = 0; i < _attacks.Count(); i++) {
|
||||
auto kv = _attacks[i];
|
||||
attacks.Append(new LearnedAttack(std::get<0>(kv), std::get<1>(kv)));
|
||||
|
||||
@@ -6,33 +6,30 @@
|
||||
#include "../Library/BattleLibrary.hpp"
|
||||
#include "Creature.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class CreateCreature {
|
||||
const BattleLibrary* _library;
|
||||
Arbutils::CaseInsensitiveConstString _species;
|
||||
Arbutils::CaseInsensitiveConstString _variant = "default"_cnc;
|
||||
ArbUt::CaseInsensitiveConstString _species;
|
||||
ArbUt::CaseInsensitiveConstString _variant = "default"_cnc;
|
||||
uint8_t _level;
|
||||
std::string _nickname = "";
|
||||
|
||||
Arbutils::CaseInsensitiveConstString _talent = ""_cnc;
|
||||
ArbUt::CaseInsensitiveConstString _talent = ""_cnc;
|
||||
Library::Gender _gender = static_cast<Library::Gender>(-1);
|
||||
uint8_t _coloring = 0;
|
||||
Arbutils::CaseInsensitiveConstString _heldItem = ""_cnc;
|
||||
ArbUt::CaseInsensitiveConstString _heldItem = ""_cnc;
|
||||
uint32_t _identifier = 0;
|
||||
List<std::tuple<borrowed_ptr<const Library::AttackData>, AttackLearnMethod>> _attacks;
|
||||
ArbUt::List<std::tuple<ArbUt::BorrowedPtr<const Library::AttackData>, AttackLearnMethod>> _attacks;
|
||||
|
||||
public:
|
||||
CreateCreature(const BattleLibrary* library, const Arbutils::CaseInsensitiveConstString& species, uint8_t level)
|
||||
CreateCreature(const BattleLibrary* library, const ArbUt::CaseInsensitiveConstString& species, uint8_t level)
|
||||
: _library(library), _species(species), _level(level), _attacks(library->GetSettings()->GetMaximalMoves()) {
|
||||
}
|
||||
|
||||
CreateCreature WithVariant(const Arbutils::CaseInsensitiveConstString& variant);
|
||||
CreateCreature WithVariant(const ArbUt::CaseInsensitiveConstString& variant);
|
||||
CreateCreature WithNickname(std::string nickname);
|
||||
CreateCreature WithGender(Library::Gender gender);
|
||||
CreateCreature WithAttack(const Arbutils::CaseInsensitiveConstString& attackName,
|
||||
AttackLearnMethod learnMethod);
|
||||
CreateCreature WithAttack(const ArbUt::CaseInsensitiveConstString& attackName, AttackLearnMethod learnMethod);
|
||||
|
||||
Creature* Create();
|
||||
};
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
|
||||
using namespace CreatureLib;
|
||||
|
||||
Battling::Creature::Creature(const BattleLibrary* library, const borrowed_ptr<const Library::CreatureSpecies>& species,
|
||||
const borrowed_ptr<const Library::SpeciesVariant>& variant, uint8_t level,
|
||||
Battling::Creature::Creature(const BattleLibrary* library,
|
||||
const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
|
||||
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, uint8_t level,
|
||||
uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring,
|
||||
const borrowed_ptr<const Library::Item> heldItem, std::string nickname,
|
||||
const Library::TalentIndex& talent, const List<LearnedAttack*>& attacks,
|
||||
const ArbUt::BorrowedPtr<const Library::Item> heldItem, std::string nickname,
|
||||
const Library::TalentIndex& talent, const ArbUt::List<LearnedAttack*>& attacks,
|
||||
bool allowedExperienceGain)
|
||||
: _library(library), _species(species), _variant(variant), _level(level), _experience(experience),
|
||||
_uniqueIdentifier(uid), _gender(gender), _coloring(coloring), _heldItem(heldItem), _nickname(std::move(nickname)),
|
||||
@@ -146,7 +147,7 @@ void Battling::Creature::OverrideActiveTalent(const ConstString& talent) {
|
||||
_activeTalent = this->_library->LoadScript(ScriptCategory::Talent, talent);
|
||||
}
|
||||
|
||||
const List<uint8_t>& Battling::Creature::GetTypes() const noexcept {
|
||||
const ArbUt::List<uint8_t>& Battling::Creature::GetTypes() const noexcept {
|
||||
// HOOK: override types.
|
||||
return this->_variant->GetTypes();
|
||||
}
|
||||
@@ -164,7 +165,7 @@ size_t Battling::Creature::ScriptCount() const {
|
||||
return c;
|
||||
}
|
||||
|
||||
void Battling::Creature::GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) {
|
||||
void Battling::Creature::GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) {
|
||||
scripts.Append(ScriptWrapper::FromScript(&_activeTalent));
|
||||
scripts.Append(ScriptWrapper::FromScript(&_status));
|
||||
scripts.Append(ScriptWrapper::FromSet(&_volatile));
|
||||
@@ -186,27 +187,27 @@ void Battling::Creature::AddExperience(uint32_t amount) {
|
||||
_experience = exp;
|
||||
_level = level;
|
||||
}
|
||||
borrowed_ptr<const Library::CreatureSpecies> Battling::Creature::GetDisplaySpecies() const noexcept {
|
||||
ArbUt::BorrowedPtr<const Library::CreatureSpecies> Battling::Creature::GetDisplaySpecies() const noexcept {
|
||||
auto species = _displaySpecies;
|
||||
if (species == nullptr)
|
||||
species = _species;
|
||||
return species;
|
||||
}
|
||||
borrowed_ptr<const Library::SpeciesVariant> Battling::Creature::GetDisplayVariant() const noexcept {
|
||||
ArbUt::BorrowedPtr<const Library::SpeciesVariant> Battling::Creature::GetDisplayVariant() const noexcept {
|
||||
auto variant = _displayVariant;
|
||||
if (variant == nullptr)
|
||||
variant = _variant;
|
||||
return variant;
|
||||
}
|
||||
void Battling::Creature::SetHeldItem(const ConstString& itemName) {
|
||||
borrowed_ptr<const Library::Item> item;
|
||||
ArbUt::BorrowedPtr<const Library::Item> item;
|
||||
if (!_library->GetItemLibrary()->TryGet(itemName.GetHash(), item)) {
|
||||
throw CreatureException("Item not found.");
|
||||
}
|
||||
_heldItem = item;
|
||||
}
|
||||
void Battling::Creature::SetHeldItem(uint32_t itemNameHash) {
|
||||
borrowed_ptr<const Library::Item> item;
|
||||
ArbUt::BorrowedPtr<const Library::Item> item;
|
||||
if (!_library->GetItemLibrary()->TryGet(itemNameHash, item)) {
|
||||
throw CreatureException("Item not found.");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define CREATURELIB_BATTLECREATURE_HPP
|
||||
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <Arbutils/Memory/borrowed_ptr.hpp>
|
||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||
#include "../../Library/ClampedStatisticSet.hpp"
|
||||
#include "../../Library/CreatureData/CreatureSpecies.hpp"
|
||||
#include "../../Library/Items/Item.hpp"
|
||||
@@ -12,8 +12,6 @@
|
||||
#include "DamageSource.hpp"
|
||||
#include "LearnedAttack.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
// Forward declare battle class
|
||||
class Battle;
|
||||
@@ -24,18 +22,18 @@ namespace CreatureLib::Battling {
|
||||
protected:
|
||||
const BattleLibrary* _library;
|
||||
|
||||
borrowed_ptr<const Library::CreatureSpecies> _species;
|
||||
borrowed_ptr<const Library::SpeciesVariant> _variant;
|
||||
ArbUt::BorrowedPtr<const Library::CreatureSpecies> _species;
|
||||
ArbUt::BorrowedPtr<const Library::SpeciesVariant> _variant;
|
||||
|
||||
borrowed_ptr<const Library::CreatureSpecies> _displaySpecies = nullptr;
|
||||
borrowed_ptr<const Library::SpeciesVariant> _displayVariant = nullptr;
|
||||
ArbUt::BorrowedPtr<const Library::CreatureSpecies> _displaySpecies = nullptr;
|
||||
ArbUt::BorrowedPtr<const Library::SpeciesVariant> _displayVariant = nullptr;
|
||||
|
||||
uint8_t _level;
|
||||
uint32_t _experience;
|
||||
uint32_t _uniqueIdentifier;
|
||||
Library::Gender _gender;
|
||||
uint8_t _coloring;
|
||||
borrowed_ptr<const Library::Item> _heldItem;
|
||||
ArbUt::BorrowedPtr<const Library::Item> _heldItem;
|
||||
uint32_t _currentHealth;
|
||||
|
||||
Library::ClampedStatisticSet<int8_t, -6, 6> _statBoost;
|
||||
@@ -51,10 +49,10 @@ namespace CreatureLib::Battling {
|
||||
Script* _activeTalent = nullptr;
|
||||
|
||||
bool _hasOverridenTalent;
|
||||
ConstString _overridenTalentName = ""_cnc;
|
||||
ArbUt::CaseInsensitiveConstString _overridenTalentName = ""_cnc;
|
||||
std::unordered_set<Creature*> _seenOpponents = {};
|
||||
|
||||
List<LearnedAttack*> _attacks;
|
||||
ArbUt::List<LearnedAttack*> _attacks;
|
||||
bool _allowedExperienceGain;
|
||||
|
||||
Script* _status = nullptr;
|
||||
@@ -64,11 +62,11 @@ namespace CreatureLib::Battling {
|
||||
void OnFaint();
|
||||
|
||||
public:
|
||||
Creature(const BattleLibrary* library, const borrowed_ptr<const Library::CreatureSpecies>& species,
|
||||
const borrowed_ptr<const Library::SpeciesVariant>& variant, uint8_t level, uint32_t experience,
|
||||
Creature(const BattleLibrary* library, const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
|
||||
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant, uint8_t level, uint32_t experience,
|
||||
uint32_t uid, Library::Gender gender, uint8_t coloring,
|
||||
const borrowed_ptr<const Library::Item> heldItem, std::string nickname,
|
||||
const Library::TalentIndex& talent, const List<LearnedAttack*>& attacks,
|
||||
const ArbUt::BorrowedPtr<const Library::Item> heldItem, std::string nickname,
|
||||
const Library::TalentIndex& talent, const ArbUt::List<LearnedAttack*>& attacks,
|
||||
bool allowedExperienceGain = true);
|
||||
|
||||
virtual ~Creature() {
|
||||
@@ -84,22 +82,24 @@ namespace CreatureLib::Battling {
|
||||
_currentHealth = GetBoostedStat(Library::Statistic::Health);
|
||||
}
|
||||
|
||||
inline const borrowed_ptr<const Library::CreatureSpecies>& GetSpecies() const noexcept { return _species; }
|
||||
inline const borrowed_ptr<const Library::SpeciesVariant>& GetVariant() const noexcept { return _variant; }
|
||||
inline const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& GetSpecies() const noexcept {
|
||||
return _species;
|
||||
}
|
||||
inline const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& GetVariant() const noexcept { return _variant; }
|
||||
inline uint8_t GetLevel() const noexcept { return _level; }
|
||||
inline uint32_t GetExperience() const noexcept { return _experience; }
|
||||
inline Library::Gender GetGender() const noexcept { return _gender; }
|
||||
inline uint8_t GetColoring() const noexcept { return _coloring; }
|
||||
inline bool HasHeldItem(const ConstString& name) const noexcept {
|
||||
inline bool HasHeldItem(const ArbUt::CaseInsensitiveConstString& name) const noexcept {
|
||||
return _heldItem != nullptr && _heldItem->GetName() == name;
|
||||
}
|
||||
inline bool HasHeldItem(uint32_t nameHash) const noexcept {
|
||||
return _heldItem != nullptr && _heldItem->GetName() == nameHash;
|
||||
}
|
||||
inline const borrowed_ptr<const Library::Item>& GetHeldItem() const noexcept { return _heldItem; }
|
||||
void SetHeldItem(const ConstString& itemName);
|
||||
inline const ArbUt::BorrowedPtr<const Library::Item>& GetHeldItem() const noexcept { return _heldItem; }
|
||||
void SetHeldItem(const ArbUt::CaseInsensitiveConstString& itemName);
|
||||
void SetHeldItem(uint32_t itemNameHash);
|
||||
inline void SetHeldItem(const borrowed_ptr<const Library::Item>& item) noexcept { _heldItem = item; };
|
||||
inline void SetHeldItem(const ArbUt::BorrowedPtr<const Library::Item>& item) noexcept { _heldItem = item; };
|
||||
|
||||
inline uint32_t GetCurrentHealth() const noexcept { return _currentHealth; }
|
||||
|
||||
@@ -110,37 +110,37 @@ namespace CreatureLib::Battling {
|
||||
bool IsOnBattleField() const { return _onBattleField; }
|
||||
|
||||
const std::string& GetNickname() const noexcept { return _nickname; }
|
||||
const ConstString& GetActiveTalent() const;
|
||||
const ArbUt::CaseInsensitiveConstString& GetActiveTalent() const;
|
||||
|
||||
[[nodiscard]] bool IsFainted() const noexcept;
|
||||
[[nodiscard]] const List<uint8_t>& GetTypes() const noexcept;
|
||||
[[nodiscard]] const ArbUt::List<uint8_t>& GetTypes() const noexcept;
|
||||
[[nodiscard]] bool HasType(uint8_t type) const noexcept;
|
||||
|
||||
uint32_t GetMaxHealth() const noexcept { return _boostedStats.GetHealth(); }
|
||||
void ChangeLevelBy(int8_t amount);
|
||||
void Damage(uint32_t damage, DamageSource source);
|
||||
void Heal(uint32_t amount, bool canRevive = false);
|
||||
void OverrideActiveTalent(const ConstString& talent);
|
||||
void OverrideActiveTalent(const ArbUt::CaseInsensitiveConstString& talent);
|
||||
void AddExperience(uint32_t amount);
|
||||
|
||||
void MarkOpponentAsSeen(Creature* creature) { _seenOpponents.insert(creature); }
|
||||
const std::unordered_set<Creature*>& GetSeenOpponents() const { return _seenOpponents; }
|
||||
|
||||
size_t ScriptCount() const override;
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;
|
||||
void ClearVolatileScripts();
|
||||
void AddVolatileScript(const ConstString& name);
|
||||
void AddVolatileScript(const ArbUt::CaseInsensitiveConstString& name);
|
||||
void AddVolatileScript(Script* script);
|
||||
void RemoveVolatileScript(const ConstString& name);
|
||||
void RemoveVolatileScript(const ArbUt::CaseInsensitiveConstString& name);
|
||||
void RemoveVolatileScript(Script* script);
|
||||
bool HasVolatileScript(const ConstString& name) const;
|
||||
bool HasVolatileScript(const ArbUt::CaseInsensitiveConstString& name) const;
|
||||
|
||||
const List<LearnedAttack*>& GetAttacks() noexcept { return _attacks; }
|
||||
const ArbUt::List<LearnedAttack*>& GetAttacks() noexcept { return _attacks; }
|
||||
|
||||
borrowed_ptr<const Library::CreatureSpecies> GetDisplaySpecies() const noexcept;
|
||||
borrowed_ptr<const Library::SpeciesVariant> GetDisplayVariant() const noexcept;
|
||||
ArbUt::BorrowedPtr<const Library::CreatureSpecies> GetDisplaySpecies() const noexcept;
|
||||
ArbUt::BorrowedPtr<const Library::SpeciesVariant> GetDisplayVariant() const noexcept;
|
||||
|
||||
void SetDisplaySpecies(const borrowed_ptr<const Library::CreatureSpecies>& species) noexcept {
|
||||
void SetDisplaySpecies(const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species) noexcept {
|
||||
_displaySpecies = species;
|
||||
}
|
||||
void SetDisplayVariant(const Library::SpeciesVariant* variant) noexcept { _displayVariant = variant; };
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class CreatureParty {
|
||||
Arbutils::Collections::List<Creature*> _party;
|
||||
ArbUt::List<Creature*> _party;
|
||||
|
||||
public:
|
||||
CreatureParty(size_t size) noexcept : _party(size) {}
|
||||
CreatureParty(Arbutils::Collections::List<Creature*> party) noexcept : _party(party) {}
|
||||
CreatureParty(ArbUt::List<Creature*> party) noexcept : _party(party) {}
|
||||
CreatureParty(std::initializer_list<Creature*> party) noexcept : _party(party) {}
|
||||
|
||||
virtual ~CreatureParty() noexcept {
|
||||
@@ -38,8 +38,8 @@ namespace CreatureLib::Battling {
|
||||
return false;
|
||||
}
|
||||
|
||||
Arbutils::Collections::List<Creature*>& GetParty() noexcept { return _party; }
|
||||
const Arbutils::Collections::List<Creature*>& GetParty() const noexcept { return _party; }
|
||||
ArbUt::List<Creature*>& GetParty() noexcept { return _party; }
|
||||
const ArbUt::List<Creature*>& GetParty() const noexcept { return _party; }
|
||||
|
||||
size_t GetLength() const noexcept { return _party.Count(); }
|
||||
};
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#include <vector>
|
||||
#include "Creature.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class ExecutingAttack : public ScriptSource {
|
||||
public:
|
||||
@@ -38,16 +36,16 @@ namespace CreatureLib::Battling {
|
||||
};
|
||||
|
||||
private:
|
||||
List<Creature*> _targets;
|
||||
ArbUt::List<Creature*> _targets;
|
||||
uint8_t _numberHits;
|
||||
List<HitData> _hits;
|
||||
ArbUt::List<HitData> _hits;
|
||||
Creature* _user;
|
||||
LearnedAttack* _attack;
|
||||
Script* _script;
|
||||
|
||||
public:
|
||||
ExecutingAttack(const List<Creature*>& targets, uint8_t numberHits, Creature* user, LearnedAttack* attack,
|
||||
Script* script)
|
||||
ExecutingAttack(const ArbUt::List<Creature*>& targets, uint8_t numberHits, Creature* user,
|
||||
LearnedAttack* attack, Script* script)
|
||||
: _targets(targets.Count()), _numberHits(numberHits), _hits(targets.Count() * numberHits), _user(user),
|
||||
_attack(attack), _script(script) {
|
||||
AssertNotNull(user)
|
||||
@@ -79,7 +77,7 @@ namespace CreatureLib::Battling {
|
||||
}
|
||||
|
||||
bool IsCreatureTarget(Creature* creature) noexcept { return _targets.IndexOf(creature) != (size_t)-1; }
|
||||
const List<Creature*>& GetTargets() noexcept { return _targets; }
|
||||
const ArbUt::List<Creature*>& GetTargets() noexcept { return _targets; }
|
||||
uint8_t GetNumberOfHits() const noexcept { return _numberHits; }
|
||||
|
||||
Creature* GetUser() noexcept { return _user; }
|
||||
@@ -88,7 +86,7 @@ namespace CreatureLib::Battling {
|
||||
size_t ScriptCount() const override { return _user->ScriptCount() + 1; }
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override {
|
||||
scripts.Append(ScriptWrapper::FromScript(&_script));
|
||||
_user->GetActiveScripts(scripts);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
#include "LearnedAttack.hpp"
|
||||
#include <Arbutils/Assert.hpp>
|
||||
CreatureLib::Battling::LearnedAttack::LearnedAttack(const borrowed_ptr<const CreatureLib::Library::AttackData>& attack,
|
||||
uint8_t maxUses, AttackLearnMethod learnMethod)
|
||||
CreatureLib::Battling::LearnedAttack::LearnedAttack(
|
||||
const ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData>& attack, uint8_t maxUses,
|
||||
AttackLearnMethod learnMethod)
|
||||
: _attack(attack), _maxUses(maxUses), _remainingUses(maxUses), _learnMethod(learnMethod) {
|
||||
AssertNotNull(_attack)
|
||||
}
|
||||
|
||||
CreatureLib::Battling::LearnedAttack::LearnedAttack(const borrowed_ptr<const CreatureLib::Library::AttackData>& attack,
|
||||
AttackLearnMethod learnMethod)
|
||||
CreatureLib::Battling::LearnedAttack::LearnedAttack(
|
||||
const ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData>& attack, AttackLearnMethod learnMethod)
|
||||
: _attack(attack), _maxUses(attack->GetBaseUsages()), _remainingUses(_maxUses), _learnMethod(learnMethod) {
|
||||
AssertNotNull(_attack)
|
||||
}
|
||||
|
||||
const borrowed_ptr<const CreatureLib::Library::AttackData>&
|
||||
const ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData>&
|
||||
CreatureLib::Battling::LearnedAttack::GetAttack() const noexcept {
|
||||
return _attack;
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
#ifndef CREATURELIB_LEARNEDATTACK_HPP
|
||||
#define CREATURELIB_LEARNEDATTACK_HPP
|
||||
|
||||
#include <Arbutils/Memory/borrowed_ptr.hpp>
|
||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||
#include <memory>
|
||||
#include "../../Library/Attacks/AttackData.hpp"
|
||||
#include "AttackLearnMethod.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class LearnedAttack {
|
||||
borrowed_ptr<const Library::AttackData> _attack;
|
||||
ArbUt::BorrowedPtr<const Library::AttackData> _attack;
|
||||
uint8_t _maxUses;
|
||||
uint8_t _remainingUses;
|
||||
AttackLearnMethod _learnMethod;
|
||||
|
||||
public:
|
||||
LearnedAttack(const borrowed_ptr<const CreatureLib::Library::AttackData>& attack, uint8_t maxUses,
|
||||
LearnedAttack(const ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData>& attack, uint8_t maxUses,
|
||||
AttackLearnMethod learnMethod);
|
||||
LearnedAttack(const borrowed_ptr<const CreatureLib::Library::AttackData>& attack,
|
||||
LearnedAttack(const ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData>& attack,
|
||||
AttackLearnMethod learnMethod);
|
||||
|
||||
virtual ~LearnedAttack() = default;
|
||||
|
||||
const borrowed_ptr<const Library::AttackData>& GetAttack() const noexcept;
|
||||
const ArbUt::BorrowedPtr<const Library::AttackData>& GetAttack() const noexcept;
|
||||
uint8_t GetMaxUses() const noexcept;
|
||||
uint8_t GetRemainingUses() const noexcept;
|
||||
AttackLearnMethod GetLearnMethod() const noexcept;
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include "../../Library/EffectParameter.hpp"
|
||||
|
||||
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class BaseTurnChoice;
|
||||
class AttackTurnChoice;
|
||||
@@ -21,13 +19,12 @@ namespace CreatureLib::Battling {
|
||||
virtual void Stack(){};
|
||||
virtual void OnRemove(){};
|
||||
|
||||
virtual const ConstString& GetName() const noexcept = 0;
|
||||
virtual const ArbUt::CaseInsensitiveConstString& GetName() const noexcept = 0;
|
||||
|
||||
virtual void
|
||||
OnInitialize(const Arbutils::Collections::List<CreatureLib::Library::EffectParameter*>& parameters){};
|
||||
virtual void OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){};
|
||||
virtual void OnBeforeTurn(const BaseTurnChoice* choice){};
|
||||
|
||||
virtual void ChangeAttack(AttackTurnChoice* choice, ConstString* outAttack){};
|
||||
virtual void ChangeAttack(AttackTurnChoice* choice, ArbUt::CaseInsensitiveConstString* outAttack){};
|
||||
virtual void PreventAttack(ExecutingAttack* attack, bool* outResult){};
|
||||
virtual void FailAttack(ExecutingAttack* attack, bool* outFailed){};
|
||||
virtual void StopBeforeAttack(ExecutingAttack* attack, bool* outResult){};
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#include "ScriptSet.hpp"
|
||||
#include "ScriptWrapper.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class ScriptAggregator {
|
||||
const ScriptWrapper* _scripts;
|
||||
@@ -18,7 +16,7 @@ namespace CreatureLib::Battling {
|
||||
|
||||
public:
|
||||
ScriptAggregator(){};
|
||||
explicit ScriptAggregator(const List<ScriptWrapper>& scripts)
|
||||
explicit ScriptAggregator(const ArbUt::List<ScriptWrapper>& scripts)
|
||||
: _scripts(scripts.RawData()), _size(scripts.Count()){};
|
||||
|
||||
inline void Reset() {
|
||||
|
||||
@@ -14,7 +14,9 @@ namespace CreatureLib::Battling {
|
||||
virtual ~ScriptResolver() = default;
|
||||
|
||||
virtual void Initialize(BattleLibrary* library){};
|
||||
virtual Script* LoadScript(ScriptCategory category, const ConstString& scriptName) const { return nullptr; };
|
||||
virtual Script* LoadScript(ScriptCategory category, const ArbUt::CaseInsensitiveConstString& scriptName) const {
|
||||
return nullptr;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class ScriptSet {
|
||||
Arbutils::Collections::List<Script*> _scripts;
|
||||
Arbutils::Collections::Dictionary<uint32_t, size_t> _lookup;
|
||||
ArbUt::List<Script*> _scripts;
|
||||
ArbUt::Dictionary<uint32_t, size_t> _lookup;
|
||||
|
||||
public:
|
||||
~ScriptSet() {
|
||||
@@ -33,7 +33,7 @@ namespace CreatureLib::Battling {
|
||||
_lookup.Insert(script->GetName(), _scripts.Count() - 1);
|
||||
}
|
||||
|
||||
Script* Get(const ConstString& key) const { return Get(key.GetHash()); }
|
||||
Script* Get(const ArbUt::CaseInsensitiveConstString& key) const { return Get(key.GetHash()); }
|
||||
|
||||
Script* Get(uint32_t keyHash) const noexcept {
|
||||
size_t v;
|
||||
@@ -43,7 +43,7 @@ namespace CreatureLib::Battling {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Remove(const ConstString& key) { Remove(key.GetHash()); }
|
||||
void Remove(const ArbUt::CaseInsensitiveConstString& key) { Remove(key.GetHash()); }
|
||||
|
||||
void Remove(uint32_t keyHash) {
|
||||
size_t v;
|
||||
@@ -65,13 +65,13 @@ namespace CreatureLib::Battling {
|
||||
_lookup.Clear();
|
||||
}
|
||||
|
||||
bool Has(const ConstString& key) const { return _lookup.Has(key); }
|
||||
bool Has(const ArbUt::CaseInsensitiveConstString& key) const { return _lookup.Has(key); }
|
||||
|
||||
bool Has(uint32_t keyHash) const { return _lookup.Has(keyHash); }
|
||||
|
||||
inline size_t Count() const { return _scripts.Count(); }
|
||||
|
||||
const Arbutils::Collections::List<Script*>* GetIterator() const { return &_scripts; }
|
||||
const ArbUt::List<Script*>* GetIterator() const { return &_scripts; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
namespace CreatureLib::Battling {
|
||||
class ScriptSource {
|
||||
bool _areScriptsInitialized = false;
|
||||
List<ScriptWrapper> _scripts;
|
||||
ArbUt::List<ScriptWrapper> _scripts;
|
||||
ScriptAggregator _scriptsIterator;
|
||||
|
||||
protected:
|
||||
virtual void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) = 0;
|
||||
virtual void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) = 0;
|
||||
void ResetActiveScripts() { _areScriptsInitialized = false; }
|
||||
|
||||
public:
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace CreatureLib::Battling {
|
||||
size_t ScriptCount() const override { return 1 + GetUser()->ScriptCount(); }
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override {
|
||||
scripts.Append(ScriptWrapper::FromScript(&_attackScript));
|
||||
GetUser()->GetActiveScripts(scripts);
|
||||
}
|
||||
|
||||
@@ -13,9 +13,7 @@ namespace CreatureLib::Battling {
|
||||
size_t ScriptCount() const override { return GetUser()->ScriptCount(); }
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||
GetUser()->GetActiveScripts(scripts);
|
||||
}
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override { GetUser()->GetActiveScripts(scripts); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,7 @@ namespace CreatureLib::Battling {
|
||||
size_t ScriptCount() const override { return GetUser()->ScriptCount(); }
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||
GetUser()->GetActiveScripts(scripts);
|
||||
}
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override { GetUser()->GetActiveScripts(scripts); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,7 @@ namespace CreatureLib::Battling {
|
||||
size_t ScriptCount() const override { return GetUser()->ScriptCount(); }
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||
GetUser()->GetActiveScripts(scripts);
|
||||
}
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override { GetUser()->GetActiveScripts(scripts); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "AttackData.hpp"
|
||||
#include <utility>
|
||||
|
||||
CreatureLib::Library::AttackData::AttackData(const ConstString& name, uint8_t type,
|
||||
CreatureLib::Library::AttackData::AttackData(const ArbUt::CaseInsensitiveConstString& name, uint8_t type,
|
||||
CreatureLib::Library::AttackCategory category, uint8_t power,
|
||||
uint8_t accuracy, uint8_t baseUsage,
|
||||
CreatureLib::Library::AttackTarget target, int8_t priority,
|
||||
@@ -9,7 +9,7 @@ CreatureLib::Library::AttackData::AttackData(const ConstString& name, uint8_t ty
|
||||
: _name(name), _type(type), _category(category), _basePower(power), _accuracy(accuracy), _baseUsages(baseUsage),
|
||||
_target(target), _priority(priority), _effect(effect), _flags(std::move(flags)) {}
|
||||
|
||||
bool CreatureLib::Library::AttackData::HasFlag(const ConstString& key) const noexcept {
|
||||
bool CreatureLib::Library::AttackData::HasFlag(const ArbUt::CaseInsensitiveConstString& key) const noexcept {
|
||||
return this->_flags.find(key) != this->_flags.end();
|
||||
}
|
||||
bool CreatureLib::Library::AttackData::HasFlag(uint32_t key) const noexcept {
|
||||
|
||||
@@ -9,12 +9,10 @@
|
||||
#include "AttackTarget.hpp"
|
||||
#include "SecondaryEffect.hpp"
|
||||
|
||||
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class AttackData {
|
||||
protected:
|
||||
ConstString _name;
|
||||
ArbUt::CaseInsensitiveConstString _name;
|
||||
uint8_t _type;
|
||||
AttackCategory _category;
|
||||
uint8_t _basePower;
|
||||
@@ -26,12 +24,12 @@ namespace CreatureLib::Library {
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
|
||||
public:
|
||||
AttackData(const ConstString& name, uint8_t type, AttackCategory category, uint8_t power, uint8_t accuracy,
|
||||
uint8_t baseUsage, AttackTarget target, int8_t priority, const SecondaryEffect* effect,
|
||||
std::unordered_set<uint32_t> flags);
|
||||
AttackData(const ArbUt::CaseInsensitiveConstString& name, uint8_t type, AttackCategory category, uint8_t power,
|
||||
uint8_t accuracy, uint8_t baseUsage, AttackTarget target, int8_t priority,
|
||||
const SecondaryEffect* effect, std::unordered_set<uint32_t> flags);
|
||||
virtual ~AttackData() = default;
|
||||
|
||||
inline const ConstString& GetName() const noexcept { return _name; }
|
||||
inline const ArbUt::CaseInsensitiveConstString& GetName() const noexcept { return _name; }
|
||||
inline const uint8_t GetType() const noexcept { return _type; }
|
||||
inline AttackCategory GetCategory() const noexcept { return _category; }
|
||||
inline uint8_t GetBasePower() const noexcept { return _basePower; }
|
||||
@@ -44,7 +42,7 @@ namespace CreatureLib::Library {
|
||||
}
|
||||
inline const std::unique_ptr<const SecondaryEffect>& GetSecondaryEffect() const noexcept { return _effect; }
|
||||
|
||||
bool HasFlag(const ConstString& key) const noexcept;
|
||||
bool HasFlag(const ArbUt::CaseInsensitiveConstString& key) const noexcept;
|
||||
bool HasFlag(uint32_t keyHash) const noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,18 +6,17 @@
|
||||
#include <any>
|
||||
#include "../EffectParameter.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
namespace CreatureLib::Library {
|
||||
class SecondaryEffect {
|
||||
private:
|
||||
float _chance;
|
||||
Arbutils::CaseInsensitiveConstString _effectName;
|
||||
List<EffectParameter*> _parameters;
|
||||
ArbUt::CaseInsensitiveConstString _effectName;
|
||||
ArbUt::List<EffectParameter*> _parameters;
|
||||
|
||||
public:
|
||||
SecondaryEffect() noexcept : _chance(0), _effectName() {}
|
||||
SecondaryEffect(float chance, const Arbutils::CaseInsensitiveConstString& effectName,
|
||||
const List<EffectParameter*>& parameters) noexcept
|
||||
SecondaryEffect(float chance, const ArbUt::CaseInsensitiveConstString& effectName,
|
||||
const ArbUt::List<EffectParameter*>& parameters) noexcept
|
||||
: _chance(chance), _effectName(effectName), _parameters(parameters) {}
|
||||
|
||||
~SecondaryEffect() {
|
||||
@@ -27,10 +26,8 @@ namespace CreatureLib::Library {
|
||||
}
|
||||
|
||||
constexpr inline float GetChance() const noexcept { return _chance; }
|
||||
constexpr inline const Arbutils::CaseInsensitiveConstString& GetEffectName() const noexcept {
|
||||
return _effectName;
|
||||
}
|
||||
const inline List<EffectParameter*>& GetParameters() const noexcept { return _parameters; }
|
||||
constexpr inline const ArbUt::CaseInsensitiveConstString& GetEffectName() const noexcept { return _effectName; }
|
||||
const inline ArbUt::List<EffectParameter*>& GetParameters() const noexcept { return _parameters; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <Arbutils/Memory/borrowed_ptr.hpp>
|
||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||
#include <Arbutils/Random.hpp>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
template <class T> class BaseLibrary {
|
||||
Arbutils::Collections::Dictionary<uint32_t, std::unique_ptr<const T>> _values;
|
||||
Arbutils::Collections::List<uint32_t> _listValues;
|
||||
ArbUt::Dictionary<uint32_t, std::unique_ptr<const T>> _values;
|
||||
ArbUt::List<uint32_t> _listValues;
|
||||
size_t _index;
|
||||
|
||||
public:
|
||||
@@ -22,7 +22,7 @@ namespace CreatureLib::Library {
|
||||
|
||||
virtual ~BaseLibrary() { _values.Clear(); }
|
||||
|
||||
inline void Insert(const Arbutils::CaseInsensitiveConstString& key, const T* value) {
|
||||
inline void Insert(const ArbUt::CaseInsensitiveConstString& key, const T* value) {
|
||||
AssertNotNull(value)
|
||||
_values.GetStdMap().insert({key.GetHash(), std::unique_ptr<const T>(value)});
|
||||
_listValues.Append(key);
|
||||
@@ -33,7 +33,7 @@ namespace CreatureLib::Library {
|
||||
_listValues.Append(hashedKey);
|
||||
}
|
||||
|
||||
inline void Delete(const Arbutils::CaseInsensitiveConstString& key) {
|
||||
inline void Delete(const ArbUt::CaseInsensitiveConstString& key) {
|
||||
_values.erase(key.GetHash());
|
||||
auto k = _listValues.IndexOf(key);
|
||||
_listValues.Remove(k);
|
||||
@@ -44,10 +44,10 @@ namespace CreatureLib::Library {
|
||||
_listValues.Remove(k);
|
||||
}
|
||||
|
||||
bool TryGet(const Arbutils::CaseInsensitiveConstString& name, borrowed_ptr<const T>& out) const {
|
||||
bool TryGet(const ArbUt::CaseInsensitiveConstString& name, ArbUt::BorrowedPtr<const T>& out) const {
|
||||
return TryGet(name.GetHash(), out);
|
||||
}
|
||||
bool TryGet(uint32_t hashedKey, borrowed_ptr<const T>& out) const {
|
||||
bool TryGet(uint32_t hashedKey, ArbUt::BorrowedPtr<const T>& out) const {
|
||||
auto find = _values.GetStdMap().find(hashedKey);
|
||||
if (find == _values.GetStdMap().end())
|
||||
return false;
|
||||
@@ -55,27 +55,29 @@ namespace CreatureLib::Library {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline borrowed_ptr<const T> Get(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(const ArbUt::CaseInsensitiveConstString& name) const {
|
||||
return _values.Get(name.GetHash());
|
||||
}
|
||||
[[nodiscard]] inline borrowed_ptr<const T> Get(uint32_t hashedKey) const { return _values.Get(hashedKey); }
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> Get(uint32_t hashedKey) const {
|
||||
return _values.Get(hashedKey);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline borrowed_ptr<const T> operator[](const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T>
|
||||
operator[](const ArbUt::CaseInsensitiveConstString& name) const {
|
||||
return Get(name);
|
||||
}
|
||||
[[nodiscard]] inline borrowed_ptr<const T> operator[](uint32_t hashedKey) const { return Get(hashedKey); }
|
||||
[[nodiscard]] inline const Arbutils::Collections::Dictionary<uint32_t, const std::unique_ptr<const T>>&
|
||||
GetIterator() const {
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const T> operator[](uint32_t hashedKey) const { return Get(hashedKey); }
|
||||
[[nodiscard]] inline const ArbUt::Dictionary<uint32_t, const std::unique_ptr<const T>>& GetIterator() const {
|
||||
return _values;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t GetCount() const { return _values.Count(); }
|
||||
|
||||
inline borrowed_ptr<const T> GetRandomValue(Arbutils::Random rand = Arbutils::Random()) const {
|
||||
inline ArbUt::BorrowedPtr<const T> GetRandomValue(ArbUt::Random rand = ArbUt::Random()) const {
|
||||
auto i = rand.Get(_listValues.Count());
|
||||
return _values[_listValues[i]];
|
||||
}
|
||||
inline borrowed_ptr<const T> GetRandomValue(Arbutils::Random* rand) const {
|
||||
inline ArbUt::BorrowedPtr<const T> GetRandomValue(ArbUt::Random* rand) const {
|
||||
auto i = rand->Get(_listValues.Count());
|
||||
return _values[_listValues[i]];
|
||||
}
|
||||
|
||||
@@ -3,19 +3,21 @@
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
CreatureSpecies::CreatureSpecies(uint16_t id, const ConstString& name, const SpeciesVariant* defaultVariant,
|
||||
float genderRatio, const ConstString& growthRate, uint8_t captureRate)
|
||||
CreatureSpecies::CreatureSpecies(uint16_t id, const ArbUt::CaseInsensitiveConstString& name,
|
||||
const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
const ArbUt::CaseInsensitiveConstString& growthRate, uint8_t captureRate)
|
||||
: _name(name), _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate), _variants(1) {
|
||||
AssertNotNull(defaultVariant)
|
||||
SetVariant("default"_cnc, defaultVariant);
|
||||
}
|
||||
|
||||
bool CreatureSpecies::HasVariant(const ConstString& name) const { return _variants.Has(name); }
|
||||
bool CreatureSpecies::HasVariant(const ArbUt::CaseInsensitiveConstString& name) const { return _variants.Has(name); }
|
||||
|
||||
bool CreatureSpecies::TryGetVariant(const ConstString& name, borrowed_ptr<const SpeciesVariant>& out) const {
|
||||
bool CreatureSpecies::TryGetVariant(const ArbUt::CaseInsensitiveConstString& name,
|
||||
ArbUt::BorrowedPtr<const SpeciesVariant>& out) const {
|
||||
return TryGetVariant(name.GetHash(), out);
|
||||
}
|
||||
bool CreatureSpecies::TryGetVariant(uint32_t hash, borrowed_ptr<const SpeciesVariant>& out) const {
|
||||
bool CreatureSpecies::TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const SpeciesVariant>& out) const {
|
||||
auto find = _variants.GetStdMap().find(hash);
|
||||
if (find == _variants.end())
|
||||
return false;
|
||||
@@ -23,17 +25,18 @@ bool CreatureSpecies::TryGetVariant(uint32_t hash, borrowed_ptr<const SpeciesVar
|
||||
return true;
|
||||
}
|
||||
|
||||
borrowed_ptr<const SpeciesVariant> CreatureSpecies::GetVariant(const ConstString& name) const {
|
||||
ArbUt::BorrowedPtr<const SpeciesVariant>
|
||||
CreatureSpecies::GetVariant(const ArbUt::CaseInsensitiveConstString& name) const {
|
||||
return _variants.Get(name);
|
||||
}
|
||||
borrowed_ptr<const SpeciesVariant> CreatureSpecies::GetVariant(uint32_t key) const { return _variants.Get(key); }
|
||||
ArbUt::BorrowedPtr<const SpeciesVariant> CreatureSpecies::GetVariant(uint32_t key) const { return _variants.Get(key); }
|
||||
bool CreatureSpecies::HasVariant(uint32_t hash) const { return _variants.Has(hash); }
|
||||
|
||||
void CreatureSpecies::SetVariant(const ConstString& name, const SpeciesVariant* variant) {
|
||||
void CreatureSpecies::SetVariant(const ArbUt::CaseInsensitiveConstString& name, const SpeciesVariant* variant) {
|
||||
_variants.GetStdMap().insert({name, std::unique_ptr<const SpeciesVariant>(variant)});
|
||||
}
|
||||
|
||||
Gender CreatureSpecies::GetRandomGender(Arbutils::Random& rand) const {
|
||||
Gender CreatureSpecies::GetRandomGender(ArbUt::Random& rand) const {
|
||||
// TODO: Genderless creatures
|
||||
auto val = rand.GetDouble();
|
||||
if (val >= this->_genderRate)
|
||||
|
||||
@@ -3,52 +3,52 @@
|
||||
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <Arbutils/Memory/borrowed_ptr.hpp>
|
||||
#include <Arbutils/Memory/BorrowedPtr.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "../Gender.hpp"
|
||||
#include "SpeciesVariant.hpp"
|
||||
|
||||
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
/*!
|
||||
\brief This holds the data required for a species of a creature, so the general data we can describe different
|
||||
creatures with.
|
||||
*/
|
||||
class CreatureSpecies {
|
||||
const ConstString _name;
|
||||
const ArbUt::CaseInsensitiveConstString _name;
|
||||
uint16_t _id;
|
||||
float _genderRate;
|
||||
const ConstString _growthRate;
|
||||
const ArbUt::CaseInsensitiveConstString _growthRate;
|
||||
uint8_t _captureRate;
|
||||
Arbutils::Collections::Dictionary<uint32_t, std::unique_ptr<const SpeciesVariant>> _variants;
|
||||
ArbUt::Dictionary<uint32_t, std::unique_ptr<const SpeciesVariant>> _variants;
|
||||
|
||||
public:
|
||||
CreatureSpecies(uint16_t id, const ConstString& name, const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
const ConstString& growthRate, uint8_t captureRate);
|
||||
CreatureSpecies(uint16_t id, const ArbUt::CaseInsensitiveConstString& name,
|
||||
const SpeciesVariant* defaultVariant, float genderRatio,
|
||||
const ArbUt::CaseInsensitiveConstString& growthRate, uint8_t captureRate);
|
||||
|
||||
virtual ~CreatureSpecies() { _variants.Clear(); }
|
||||
|
||||
inline uint16_t GetId() const { return _id; }
|
||||
inline float GetGenderRate() const { return _genderRate; }
|
||||
inline const ConstString& GetGrowthRate() const { return _growthRate; }
|
||||
inline const ArbUt::CaseInsensitiveConstString& GetGrowthRate() const { return _growthRate; }
|
||||
inline uint8_t GetCaptureRate() const { return _captureRate; }
|
||||
|
||||
[[nodiscard]] bool HasVariant(const ConstString& key) const;
|
||||
[[nodiscard]] bool HasVariant(const ArbUt::CaseInsensitiveConstString& key) const;
|
||||
[[nodiscard]] bool HasVariant(uint32_t hash) const;
|
||||
[[nodiscard]] bool TryGetVariant(const ConstString& name, borrowed_ptr<const SpeciesVariant>& out) const;
|
||||
[[nodiscard]] bool TryGetVariant(uint32_t hash, borrowed_ptr<const SpeciesVariant>& out) const;
|
||||
[[nodiscard]] borrowed_ptr<const SpeciesVariant> GetVariant(const ConstString& key) const;
|
||||
[[nodiscard]] borrowed_ptr<const SpeciesVariant> GetVariant(uint32_t key) const;
|
||||
[[nodiscard]] Gender GetRandomGender(Arbutils::Random& rand) const;
|
||||
[[nodiscard]] const ConstString& GetName() const { return _name; }
|
||||
[[nodiscard]] bool TryGetVariant(const ArbUt::CaseInsensitiveConstString& name,
|
||||
ArbUt::BorrowedPtr<const SpeciesVariant>& out) const;
|
||||
[[nodiscard]] bool TryGetVariant(uint32_t hash, ArbUt::BorrowedPtr<const SpeciesVariant>& out) const;
|
||||
[[nodiscard]] ArbUt::BorrowedPtr<const SpeciesVariant>
|
||||
GetVariant(const ArbUt::CaseInsensitiveConstString& key) const;
|
||||
[[nodiscard]] ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(uint32_t key) const;
|
||||
[[nodiscard]] Gender GetRandomGender(ArbUt::Random& rand) const;
|
||||
[[nodiscard]] const ArbUt::CaseInsensitiveConstString& GetName() const { return _name; }
|
||||
|
||||
void SetVariant(const ConstString& name, const SpeciesVariant* variant);
|
||||
void SetVariant(const ArbUt::CaseInsensitiveConstString& name, const SpeciesVariant* variant);
|
||||
|
||||
const Arbutils::Collections::Dictionary<uint32_t, std::unique_ptr<const SpeciesVariant>>&
|
||||
GetVariantsIterator() const {
|
||||
const ArbUt::Dictionary<uint32_t, std::unique_ptr<const SpeciesVariant>>& GetVariantsIterator() const {
|
||||
return _variants;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
void LearnableAttacks::AddLevelAttack(uint8_t level, const AttackData* attack) {
|
||||
|
||||
List<const AttackData*> levelData;
|
||||
ArbUt::List<const AttackData*> levelData;
|
||||
if (_learnedByLevel.TryGet(level, levelData)) {
|
||||
levelData.Append(attack);
|
||||
} else {
|
||||
@@ -14,6 +13,6 @@ void LearnableAttacks::AddLevelAttack(uint8_t level, const AttackData* attack) {
|
||||
_distinctAttacks.insert(attack);
|
||||
}
|
||||
|
||||
const List<const AttackData*>& LearnableAttacks::GetAttacksForLevel(uint8_t level) const {
|
||||
const ArbUt::List<const AttackData*>& LearnableAttacks::GetAttacksForLevel(uint8_t level) const {
|
||||
return _learnedByLevel.Get(level);
|
||||
}
|
||||
|
||||
@@ -8,17 +8,15 @@
|
||||
#include <unordered_map>
|
||||
#include "../Attacks/AttackData.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class LearnableAttacks {
|
||||
protected:
|
||||
Dictionary<uint8_t, List<const AttackData*>> _learnedByLevel;
|
||||
ArbUt::Dictionary<uint8_t, ArbUt::List<const AttackData*>> _learnedByLevel;
|
||||
std::unordered_set<const AttackData*> _distinctAttacks;
|
||||
|
||||
public:
|
||||
explicit LearnableAttacks(size_t levelAttackCapacity)
|
||||
: _learnedByLevel(Dictionary<uint8_t, List<const AttackData*>>(levelAttackCapacity)) {
|
||||
: _learnedByLevel(ArbUt::Dictionary<uint8_t, ArbUt::List<const AttackData*>>(levelAttackCapacity)) {
|
||||
for (auto kv : _learnedByLevel) {
|
||||
for (auto attack : kv.second) {
|
||||
AssertNotNull(attack)
|
||||
@@ -31,9 +29,9 @@ namespace CreatureLib::Library {
|
||||
|
||||
void AddLevelAttack(uint8_t level, const AttackData* attack);
|
||||
|
||||
const List<const AttackData*>& GetAttacksForLevel(uint8_t level) const;
|
||||
const ArbUt::List<const AttackData*>& GetAttacksForLevel(uint8_t level) const;
|
||||
|
||||
virtual const AttackData* GetRandomAttack(Arbutils::Random& rand) const {
|
||||
virtual const AttackData* GetRandomAttack(ArbUt::Random& rand) const {
|
||||
if (_distinctAttacks.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
const List<uint8_t>& CreatureLib::Library::SpeciesVariant::GetTypes() const { return _types; }
|
||||
const ArbUt::List<uint8_t>& CreatureLib::Library::SpeciesVariant::GetTypes() const { return _types; }
|
||||
|
||||
size_t CreatureLib::Library::SpeciesVariant::GetTypeCount() const { return _types.Count(); }
|
||||
|
||||
@@ -13,7 +13,7 @@ uint16_t CreatureLib::Library::SpeciesVariant::GetStatistic(CreatureLib::Library
|
||||
}
|
||||
|
||||
const CreatureLib::Library::TalentIndex
|
||||
CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ConstString& talent) const {
|
||||
CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ArbUt::CaseInsensitiveConstString& talent) const {
|
||||
for (size_t i = 0; i < _talents.Count(); i++) {
|
||||
if (_talents.At(i) == talent) {
|
||||
return TalentIndex(false, i);
|
||||
@@ -27,7 +27,7 @@ CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ConstString& talent)
|
||||
throw CreatureException("The given talent is not a valid talent for this creature.");
|
||||
}
|
||||
|
||||
CreatureLib::Library::TalentIndex CreatureLib::Library::SpeciesVariant::GetRandomTalent(Arbutils::Random* rand) const {
|
||||
CreatureLib::Library::TalentIndex CreatureLib::Library::SpeciesVariant::GetRandomTalent(ArbUt::Random* rand) const {
|
||||
return TalentIndex(false, rand->Get(_talents.Count()));
|
||||
}
|
||||
|
||||
@@ -36,10 +36,11 @@ CreatureLib::Library::SpeciesVariant::GetLearnableAttacks() const {
|
||||
return _attacks;
|
||||
}
|
||||
|
||||
CreatureLib::Library::SpeciesVariant::SpeciesVariant(ConstString name, float height, float weight,
|
||||
uint32_t baseExperience, List<uint8_t> types,
|
||||
CreatureLib::Library::SpeciesVariant::SpeciesVariant(ArbUt::CaseInsensitiveConstString name, float height, float weight,
|
||||
uint32_t baseExperience, ArbUt::List<uint8_t> types,
|
||||
CreatureLib::Library::StatisticSet<uint16_t> baseStats,
|
||||
List<ConstString> talents, List<ConstString> secretTalents,
|
||||
ArbUt::List<ArbUt::CaseInsensitiveConstString> talents,
|
||||
ArbUt::List<ArbUt::CaseInsensitiveConstString> secretTalents,
|
||||
const LearnableAttacks* attacks)
|
||||
: _name(std::move(name)), _height(height), _weight(weight), _baseExperience(baseExperience),
|
||||
_types(std::move(types)), _baseStatistics(baseStats), _talents(std::move(talents)),
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#include "../StatisticSet.hpp"
|
||||
#include "LearnableAttacks.hpp"
|
||||
#include "TalentIndex.hpp"
|
||||
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
/*!
|
||||
@@ -17,47 +15,52 @@ namespace CreatureLib::Library {
|
||||
*/
|
||||
class SpeciesVariant {
|
||||
protected:
|
||||
ConstString _name;
|
||||
ArbUt::CaseInsensitiveConstString _name;
|
||||
float _height;
|
||||
float _weight;
|
||||
uint32_t _baseExperience;
|
||||
|
||||
private:
|
||||
List<uint8_t> _types;
|
||||
ArbUt::List<uint8_t> _types;
|
||||
Library::StatisticSet<uint16_t> _baseStatistics;
|
||||
List<ConstString> _talents;
|
||||
List<ConstString> _secretTalents;
|
||||
ArbUt::List<ArbUt::CaseInsensitiveConstString> _talents;
|
||||
ArbUt::List<ArbUt::CaseInsensitiveConstString> _secretTalents;
|
||||
std::unique_ptr<const LearnableAttacks> _attacks;
|
||||
|
||||
public:
|
||||
SpeciesVariant(ConstString name, float height, float weight, uint32_t baseExperience, List<uint8_t> types,
|
||||
Library::StatisticSet<uint16_t> baseStats, List<ConstString> talents,
|
||||
List<ConstString> secretTalents, const LearnableAttacks* attacks);
|
||||
SpeciesVariant(ArbUt::CaseInsensitiveConstString name, float height, float weight, uint32_t baseExperience,
|
||||
ArbUt::List<uint8_t> types, Library::StatisticSet<uint16_t> baseStats,
|
||||
ArbUt::List<ArbUt::CaseInsensitiveConstString> talents,
|
||||
ArbUt::List<ArbUt::CaseInsensitiveConstString> secretTalents, const LearnableAttacks* attacks);
|
||||
|
||||
virtual ~SpeciesVariant() = default;
|
||||
|
||||
inline const ConstString& GetName() const { return _name; }
|
||||
inline const ArbUt::CaseInsensitiveConstString& GetName() const { return _name; }
|
||||
inline float GetHeight() const { return _height; }
|
||||
inline float GetWeight() const { return _weight; }
|
||||
inline uint32_t GetBaseExperience() const { return _baseExperience; }
|
||||
|
||||
[[nodiscard]] size_t GetTypeCount() const;
|
||||
[[nodiscard]] uint8_t GetType(size_t index) const;
|
||||
[[nodiscard]] const List<uint8_t>& GetTypes() const;
|
||||
[[nodiscard]] const ArbUt::List<uint8_t>& GetTypes() const;
|
||||
[[nodiscard]] uint16_t GetStatistic(Library::Statistic stat) const;
|
||||
[[nodiscard]] const size_t GetTalentCount() const { return _talents.Count(); }
|
||||
[[nodiscard]] const size_t GetSecretTalentCount() const { return _secretTalents.Count(); }
|
||||
[[nodiscard]] const ConstString& GetTalent(const TalentIndex& index) const {
|
||||
[[nodiscard]] const ArbUt::CaseInsensitiveConstString& GetTalent(const TalentIndex& index) const {
|
||||
if (index.IsSecret())
|
||||
return _secretTalents.At(index.GetIndex());
|
||||
return _talents.At(index.GetIndex());
|
||||
}
|
||||
[[nodiscard]] const TalentIndex GetTalentIndex(const ConstString& talent) const;
|
||||
[[nodiscard]] const TalentIndex GetTalentIndex(const ArbUt::CaseInsensitiveConstString& talent) const;
|
||||
|
||||
[[nodiscard]] const std::unique_ptr<const CreatureLib::Library::LearnableAttacks>& GetLearnableAttacks() const;
|
||||
[[nodiscard]] TalentIndex GetRandomTalent(Arbutils::Random* rand) const;
|
||||
[[nodiscard]] inline const List<ConstString>& GetTalents() const { return _talents; }
|
||||
[[nodiscard]] inline const List<ConstString>& GetSecretTalents() const { return _secretTalents; }
|
||||
[[nodiscard]] TalentIndex GetRandomTalent(ArbUt::Random* rand) const;
|
||||
[[nodiscard]] inline const ArbUt::List<ArbUt::CaseInsensitiveConstString>& GetTalents() const {
|
||||
return _talents;
|
||||
}
|
||||
[[nodiscard]] inline const ArbUt::List<ArbUt::CaseInsensitiveConstString>& GetSecretTalents() const {
|
||||
return _secretTalents;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,14 +11,14 @@ namespace CreatureLib::Library {
|
||||
class EffectParameter {
|
||||
private:
|
||||
EffectParameterType _type = EffectParameterType::None;
|
||||
std::variant<bool, int64_t, float, Arbutils::CaseInsensitiveConstString> _value;
|
||||
std::variant<bool, int64_t, float, ArbUt::CaseInsensitiveConstString> _value;
|
||||
|
||||
public:
|
||||
EffectParameter() : _type(EffectParameterType::None){};
|
||||
explicit EffectParameter(bool b) : _type(EffectParameterType::Bool), _value(b){};
|
||||
explicit EffectParameter(int64_t i) : _type(EffectParameterType::Int), _value(i){};
|
||||
explicit EffectParameter(float f) : _type(EffectParameterType::Float), _value(f){};
|
||||
explicit EffectParameter(const Arbutils::CaseInsensitiveConstString& s)
|
||||
explicit EffectParameter(const ArbUt::CaseInsensitiveConstString& s)
|
||||
: _type(EffectParameterType::String), _value(s){};
|
||||
EffectParameter(const EffectParameter& other) = delete;
|
||||
EffectParameter& operator=(const EffectParameter& other) = delete;
|
||||
@@ -54,13 +54,13 @@ namespace CreatureLib::Library {
|
||||
}
|
||||
return std::get<float>(_value);
|
||||
}
|
||||
const Arbutils::CaseInsensitiveConstString& AsString() const {
|
||||
const ArbUt::CaseInsensitiveConstString& AsString() const {
|
||||
if (_type != EffectParameterType::String) {
|
||||
std::stringstream ss;
|
||||
ss << "Cast effect parameter to string, but was " << EffectParameterTypeHelper::ToString(_type);
|
||||
throw CreatureException(ss.str());
|
||||
}
|
||||
return std::get<Arbutils::CaseInsensitiveConstString>(_value);
|
||||
return std::get<ArbUt::CaseInsensitiveConstString>(_value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <unordered_map>
|
||||
#include "GrowthRate.hpp"
|
||||
|
||||
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||
using ConstString = ArbUt::CaseInsensitiveConstString;
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class GrowthRateLibrary {
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
namespace CreatureLib::Library {
|
||||
class LookupGrowthRate : public GrowthRate {
|
||||
protected:
|
||||
Arbutils::Collections::List<uint32_t> _experience;
|
||||
ArbUt::List<uint32_t> _experience;
|
||||
|
||||
public:
|
||||
LookupGrowthRate(const Arbutils::Collections::List<uint32_t>& experience) : _experience(experience) {}
|
||||
LookupGrowthRate(const ArbUt::List<uint32_t>& experience) : _experience(experience) {}
|
||||
|
||||
uint8_t CalculateLevel(uint32_t experience) const override {
|
||||
for (uint8_t i = 0; i < _experience.Count(); i++) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "Item.hpp"
|
||||
|
||||
bool CreatureLib::Library::Item::HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const noexcept {
|
||||
bool CreatureLib::Library::Item::HasFlag(const ArbUt::CaseInsensitiveConstString& flag) const noexcept {
|
||||
return this->_flags.find(flag) != this->_flags.end();
|
||||
}
|
||||
bool CreatureLib::Library::Item::HasFlag(uint32_t flag) const noexcept {
|
||||
return this->_flags.find(flag) != this->_flags.end();
|
||||
}
|
||||
|
||||
CreatureLib::Library::Item::Item(const Arbutils::CaseInsensitiveConstString& name,
|
||||
CreatureLib::Library::Item::Item(const ArbUt::CaseInsensitiveConstString& name,
|
||||
CreatureLib::Library::ItemCategory category,
|
||||
CreatureLib::Library::BattleItemCategory battleCategory, int32_t price,
|
||||
const std::unordered_set<uint32_t>& flags)
|
||||
|
||||
@@ -10,22 +10,22 @@
|
||||
namespace CreatureLib::Library {
|
||||
class Item {
|
||||
protected:
|
||||
Arbutils::CaseInsensitiveConstString _name;
|
||||
ArbUt::CaseInsensitiveConstString _name;
|
||||
ItemCategory _category;
|
||||
BattleItemCategory _battleCategory;
|
||||
int32_t _price;
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
|
||||
public:
|
||||
Item(const Arbutils::CaseInsensitiveConstString& name, ItemCategory category, BattleItemCategory battleCategory,
|
||||
Item(const ArbUt::CaseInsensitiveConstString& name, ItemCategory category, BattleItemCategory battleCategory,
|
||||
int32_t price, const std::unordered_set<uint32_t>& flags);
|
||||
|
||||
inline const Arbutils::CaseInsensitiveConstString& GetName() const noexcept { return _name; }
|
||||
inline const ArbUt::CaseInsensitiveConstString& GetName() const noexcept { return _name; }
|
||||
inline ItemCategory GetCategory() const noexcept { return _category; }
|
||||
inline BattleItemCategory GetBattleCategory() const noexcept { return _battleCategory; }
|
||||
inline const int32_t GetPrice() const noexcept { return _price; }
|
||||
|
||||
bool HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const noexcept;
|
||||
bool HasFlag(const ArbUt::CaseInsensitiveConstString& flag) const noexcept;
|
||||
bool HasFlag(uint32_t flag) const noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
using namespace CreatureLib::Library;
|
||||
|
||||
float TypeLibrary::GetEffectiveness(uint8_t attacking, const List<uint8_t>& defensive) const {
|
||||
float TypeLibrary::GetEffectiveness(uint8_t attacking, const ArbUt::List<uint8_t>& defensive) const {
|
||||
return std::accumulate(
|
||||
defensive.begin(), defensive.end(), (float)1,
|
||||
[this, attacking](float init, uint8_t defense) { return init * GetSingleEffectiveness(attacking, defense); });
|
||||
@@ -14,10 +14,10 @@ float TypeLibrary::GetSingleEffectiveness(uint8_t attacking, uint8_t defensive)
|
||||
return _effectiveness[attacking][defensive];
|
||||
}
|
||||
|
||||
uint8_t TypeLibrary::GetTypeId(const ConstString& key) const { return _types.Get(key); }
|
||||
uint8_t TypeLibrary::GetTypeId(const ArbUt::CaseInsensitiveConstString& key) const { return _types.Get(key); }
|
||||
uint8_t TypeLibrary::GetTypeId(uint32_t s) const { return _types.Get(s); }
|
||||
|
||||
uint8_t TypeLibrary::RegisterType(const ConstString& key) {
|
||||
uint8_t TypeLibrary::RegisterType(const ArbUt::CaseInsensitiveConstString& key) {
|
||||
_types.Insert(key, _types.Count());
|
||||
_effectiveness.Resize(_types.Count());
|
||||
for (auto& eff : _effectiveness) {
|
||||
|
||||
@@ -6,23 +6,21 @@
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
class TypeLibrary {
|
||||
Dictionary<uint32_t, uint8_t> _types;
|
||||
List<List<float>> _effectiveness;
|
||||
ArbUt::Dictionary<uint32_t, uint8_t> _types;
|
||||
ArbUt::List<ArbUt::List<float>> _effectiveness;
|
||||
|
||||
public:
|
||||
TypeLibrary(size_t initialCapacity = 20) : _types(Dictionary<uint32_t, uint8_t>(initialCapacity)) {}
|
||||
TypeLibrary(size_t initialCapacity = 20) : _types(ArbUt::Dictionary<uint32_t, uint8_t>(initialCapacity)) {}
|
||||
|
||||
uint8_t GetTypeId(const ConstString& s) const;
|
||||
uint8_t GetTypeId(const ArbUt::CaseInsensitiveConstString& s) const;
|
||||
uint8_t GetTypeId(uint32_t s) const;
|
||||
[[nodiscard]] float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const;
|
||||
[[nodiscard]] float GetEffectiveness(uint8_t attacking, const List<uint8_t>& defensive) const;
|
||||
[[nodiscard]] float GetEffectiveness(uint8_t attacking, const ArbUt::List<uint8_t>& defensive) const;
|
||||
|
||||
uint8_t RegisterType(const ConstString& typeName);
|
||||
uint8_t RegisterType(const ArbUt::CaseInsensitiveConstString& typeName);
|
||||
uint8_t RegisterType(uint32_t typeHash);
|
||||
void SetEffectiveness(uint8_t attacking, uint8_t defensive, float effectiveness);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user