Renamed Script --> BattleScript, some cleanup on it.
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2021-03-07 10:26:41 +01:00
parent d70c6a224a
commit 5178d5dcc0
25 changed files with 204 additions and 182 deletions

View File

@@ -165,6 +165,6 @@ void Battle::AddVolatileScript(const ArbUt::StringView& key) {
}
return _volatile.Add(script.value().GetRaw());
}
void Battle::AddVolatileScript(Script* script) { return _volatile.Add(script); }
void Battle::RemoveVolatileScript(Script* script) { _volatile.Remove(script->GetName()); }
void Battle::AddVolatileScript(BattleScript* script) { return _volatile.Add(script); }
void Battle::RemoveVolatileScript(BattleScript* script) { _volatile.Remove(script->GetName()); }
void Battle::DisplayText(const ArbUt::StringView& text) { TriggerEventListener<DisplayTextEvent>(text); }

View File

@@ -86,17 +86,17 @@ namespace CreatureLib::Battling {
const ArbUt::UniquePtrList<BattleParty>& GetParties() const noexcept { return _parties; }
const ArbUt::UniquePtrList<BattleSide>& GetSides() const noexcept { return _sides; }
std::optional<ArbUt::BorrowedPtr<Script>> GetVolatileScript(const ArbUt::StringView& key) const {
std::optional<ArbUt::BorrowedPtr<BattleScript>> GetVolatileScript(const ArbUt::StringView& key) const {
return _volatile.Get(key);
}
std::optional<ArbUt::BorrowedPtr<Script>> GetVolatileScript(uint32_t keyHash) const noexcept {
std::optional<ArbUt::BorrowedPtr<BattleScript>> GetVolatileScript(uint32_t keyHash) const noexcept {
return _volatile.Get(keyHash);
}
void AddVolatileScript(const ArbUt::StringView& key);
void AddVolatileScript(Script* script);
void AddVolatileScript(BattleScript* script);
void RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
void RemoveVolatileScript(uint32_t keyHash) { _volatile.Remove(keyHash); }
void RemoveVolatileScript(Script* script);
void RemoveVolatileScript(BattleScript* script);
bool HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
bool HasVolatileScript(uint32_t keyHash) const { return _volatile.Has(keyHash); }

View File

@@ -17,7 +17,7 @@ namespace CreatureLib::Battling {
_uniqueIdentifier(uid), _gender(gender), _coloring(coloring), _heldItem(heldItem),
_nickname(std::move(nickname)), _talentIndex(talent), _hasOverridenTalent(false), _attacks(attacks),
_allowedExperienceGain(allowedExperienceGain) {
_activeTalent = std::unique_ptr<Script>(_library->LoadScript(ScriptCategory::Talent, GetActiveTalent()));
_activeTalent = std::unique_ptr<BattleScript>(_library->LoadScript(ScriptCategory::Talent, GetActiveTalent()));
for (auto t : _variant->GetTypes()) {
_types.push_back(t);
}
@@ -58,7 +58,7 @@ namespace CreatureLib::Battling {
}
// Grab the new active talent.
_activeTalent = std::unique_ptr<Script>(_library->LoadScript(ScriptCategory::Talent, GetActiveTalent()));
_activeTalent = std::unique_ptr<BattleScript>(_library->LoadScript(ScriptCategory::Talent, GetActiveTalent()));
// We modify the health of the creature by the change in its max health.
auto prevHealth = GetBoostedStat(CreatureLib::Library::Statistic::Health);
@@ -292,9 +292,9 @@ namespace CreatureLib::Battling {
_volatile.Add(script.value().GetRaw());
}
void Creature::AddVolatileScript(Script* script) { _volatile.Add(script); }
void Creature::AddVolatileScript(BattleScript* script) { _volatile.Add(script); }
void Creature::RemoveVolatileScript(const ArbUt::BasicStringView& name) { _volatile.Remove(name); }
void Creature::RemoveVolatileScript(Script* script) { _volatile.Remove(script->GetName()); }
void Creature::RemoveVolatileScript(BattleScript* script) { _volatile.Remove(script->GetName()); }
bool Creature::HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
void Creature::AddAttack(LearnedAttack* attack) {
for (size_t i = 0; i < _attacks.Count(); i++) {

View File

@@ -45,7 +45,7 @@ namespace CreatureLib::Battling {
std::string _nickname = "";
CreatureLib::Library::TalentIndex _talentIndex;
std::unique_ptr<Script> _activeTalent = nullptr;
std::unique_ptr<BattleScript> _activeTalent = nullptr;
bool _hasOverridenTalent;
ArbUt::StringView _overridenTalentName;
@@ -54,7 +54,7 @@ namespace CreatureLib::Battling {
ArbUt::OptionalUniquePtrList<LearnedAttack> _attacks;
bool _allowedExperienceGain;
std::unique_ptr<Script> _status = nullptr;
std::unique_ptr<BattleScript> _status = nullptr;
ScriptSet _volatile = {};
std::vector<uint8_t> _types;
@@ -135,9 +135,9 @@ namespace CreatureLib::Battling {
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override;
void ClearVolatileScripts();
void AddVolatileScript(const ArbUt::StringView& name);
void AddVolatileScript(Script* script);
void AddVolatileScript(BattleScript* script);
void RemoveVolatileScript(const ArbUt::BasicStringView& name);
void RemoveVolatileScript(Script* script);
void RemoveVolatileScript(BattleScript* script);
bool HasVolatileScript(const ArbUt::BasicStringView& name) const;
const ArbUt::OptionalUniquePtrList<LearnedAttack>& GetAttacks() noexcept { return _attacks; }

View File

@@ -34,17 +34,17 @@ namespace CreatureLib::Battling {
std::unique_ptr<HitData[]> _hits;
ArbUt::BorrowedPtr<Creature> _user;
ArbUt::BorrowedPtr<LearnedAttack> _attack;
std::unique_ptr<Script> _script = nullptr;
std::unique_ptr<BattleScript> _script = nullptr;
ArbUt::List<ArbUt::OptionalBorrowedPtr<Creature>> _targets;
public:
ExecutingAttack(const ArbUt::List<ArbUt::OptionalBorrowedPtr<Creature>>& targets, uint8_t numberHits,
ArbUt::BorrowedPtr<Creature> user, const ArbUt::BorrowedPtr<LearnedAttack>& attack,
const std::unique_ptr<Script>& script)
const std::unique_ptr<BattleScript>& script)
: _numberHits(numberHits), _hits(std::make_unique<HitData[]>(targets.Count() * numberHits)), _user(user),
_attack(attack), _targets(targets) {
// Take ownership of the script of the attack choice, and give attack choice our initial nullptr.
_script.swap(const_cast<std::unique_ptr<Script>&>(script));
_script.swap(const_cast<std::unique_ptr<BattleScript>&>(script));
}
ExecutingAttack(const ExecutingAttack&) = delete;
ExecutingAttack& operator=(const ExecutingAttack&) = delete;
@@ -97,7 +97,7 @@ namespace CreatureLib::Battling {
inline const ArbUt::BorrowedPtr<LearnedAttack>& GetAttack() noexcept { return _attack; }
size_t ScriptCount() const override { return _user->ScriptCount() + 1; }
inline ArbUt::BorrowedPtr<Script> GetScript() const noexcept { return _script; }
inline ArbUt::BorrowedPtr<BattleScript> GetScript() const noexcept { return _script; }
protected:
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override {