Renamed Script --> BattleScript, some cleanup on it.
continuous-integration/drone/push Build is passing Details

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

View File

@ -57,7 +57,7 @@ export BattleParty* const* CreatureLib_Battle_GetParties(const Battle* p) {
return reinterpret_cast<BattleParty* const*>(p->GetParties().RawData());
}
export Script* CreatureLib_Battle_GetVolatileScript(Battle* p, const char* key) {
export BattleScript* CreatureLib_Battle_GetVolatileScript(Battle* p, const char* key) {
auto v = p->GetVolatileScript(ArbUt::StringView::CalculateHash(key));
if (!v.has_value()) {
return nullptr;
@ -67,12 +67,14 @@ export Script* CreatureLib_Battle_GetVolatileScript(Battle* p, const char* key)
export uint8_t CreatureLib_Battle_AddVolatileScriptByName(Battle* p, const char* key) {
Try(p->AddVolatileScript(ArbUt::StringView(key));)
}
export uint8_t CreatureLib_Battle_AddVolatileScript(Battle* p, Script* script) { Try(p->AddVolatileScript(script);) }
export uint8_t CreatureLib_Battle_AddVolatileScript(Battle* p, BattleScript* script) {
Try(p->AddVolatileScript(script);)
}
export uint8_t CreatureLib_Battle_RemoveVolatileScript(Battle* p, const char* key) {
Try(p->RemoveVolatileScript(ArbUt::StringView::CalculateHash(key));)
}
export uint8_t CreatureLib_Battle_RemoveVolatileScriptWithScript(Battle* p, Script* script) {
export uint8_t CreatureLib_Battle_RemoveVolatileScriptWithScript(Battle* p, BattleScript* script) {
Try(p->RemoveVolatileScript(script);)
}
export bool CreatureLib_Battle_HasVolatileScript(Battle* p, const char* key) {

View File

@ -0,0 +1,95 @@
#include "../../src/Battling/ScriptHandling/BattleScript.hpp"
#include "../Core.hpp"
using namespace CreatureLib::Battling;
export void CreatureLib_Script_Destruct(BattleScript* p) { delete p; }
export uint8_t CreatureLib_Script_Stack(BattleScript* p) { Try(p->Stack()); }
export uint8_t CreatureLib_Script_OnRemove(BattleScript* p) { Try(p->OnRemove()); }
export const char* CreatureLib_Script_GetName(BattleScript* p) { return p->GetName().c_str(); }
export uint8_t CreatureLib_Script_OnBeforeTurn(BattleScript* p, const BaseTurnChoice* choice) {
Try(p->OnBeforeTurn(choice));
}
export uint8_t CreatureLib_Script_ChangeAttack(BattleScript* p, AttackTurnChoice* choice, const char*& outAttack) {
Try(auto sv = ArbUt::StringView(outAttack); p->ChangeAttack(choice, &sv); outAttack = sv.c_str(););
}
export uint8_t CreatureLib_Script_PreventAttack(BattleScript* p, ExecutingAttack* attack, bool* outResult) {
Try(p->PreventAttack(attack, outResult));
}
export uint8_t CreatureLib_Script_FailAttack(BattleScript* p, ExecutingAttack* attack, bool* outResult) {
Try(p->FailAttack(attack, outResult));
}
export uint8_t CreatureLib_Script_StopBeforeAttack(BattleScript* p, ExecutingAttack* attack, bool* outResult) {
Try(p->StopBeforeAttack(attack, outResult));
}
export uint8_t CreatureLib_Script_OnBeforeAttack(BattleScript* p, ExecutingAttack* attack) {
Try(p->OnBeforeAttack(attack));
}
export uint8_t CreatureLib_Script_FailIncomingAttack(BattleScript* p, ExecutingAttack* attack, Creature* target,
bool* outResult) {
Try(p->FailIncomingAttack(attack, target, outResult));
}
export uint8_t CreatureLib_Script_IsInvulnerable(BattleScript* p, ExecutingAttack* attack, Creature* target,
bool* outResult) {
Try(p->IsInvulnerable(attack, target, outResult));
}
export uint8_t CreatureLib_Script_OnAttackMiss(BattleScript* p, ExecutingAttack* attack, Creature* target) {
Try(p->OnAttackMiss(attack, target));
}
export uint8_t CreatureLib_Script_ChangeAttackType(BattleScript* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, uint8_t* outType) {
Try(p->ChangeAttackType(attack, target, hitNumber, outType))
}
export uint8_t CreatureLib_Script_OverrideBasePower(BattleScript* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, uint8_t* basePower) {
Try(p->OverrideBasePower(attack, target, hitNumber, basePower));
}
export uint8_t CreatureLib_Script_ChangeDamageStatsUser(BattleScript* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, Creature** statsUser) {
Try(p->ChangeDamageStatsUser(attack, target, hitNumber, statsUser));
}
export uint8_t CreatureLib_Script_BypassDefensiveStat(BattleScript* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, bool* bypass) {
Try(p->BypassDefensiveStat(attack, target, hitNumber, bypass));
}
export uint8_t CreatureLib_Script_BypassOffensiveStat(BattleScript* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, bool* bypass) {
Try(p->BypassOffensiveStat(attack, target, hitNumber, bypass));
}
export uint8_t CreatureLib_Script_ModifyStatModifier(BattleScript* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, float* modifier) {
Try(p->ModifyStatModifier(attack, target, hitNumber, modifier));
}
export uint8_t CreatureLib_Script_ModifyDamageModifier(BattleScript* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, float* modifier) {
Try(p->ModifyDamageModifier(attack, target, hitNumber, modifier));
}
export uint8_t CreatureLib_Script_OverrideDamage(BattleScript* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, uint32_t* damage) {
Try(p->OverrideDamage(attack, target, hitNumber, damage));
}
export uint8_t CreatureLib_Script_PreventSecondaryEffects(BattleScript* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, bool* outResult) {
Try(p->PreventSecondaryEffects(attack, target, hitNumber, outResult));
}
export uint8_t CreatureLib_Script_OnSecondaryEffect(BattleScript* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber) {
Try(p->OnSecondaryEffect(attack, target, hitNumber));
}
export uint8_t CreatureLib_Script_OnAfterHits(BattleScript* p, ExecutingAttack* attack, Creature* target) {
Try(p->OnAfterHits(attack, target));
}
export uint8_t CreatureLib_Script_PreventSelfSwitch(BattleScript* p, const SwitchTurnChoice* choice, bool* outResult) {
Try(p->PreventSelfSwitch(choice, outResult));
}
export uint8_t CreatureLib_Script_ModifyEffectChance(BattleScript* p, const ExecutingAttack* attack, Creature* target,
float* chance) {
Try(p->ModifyEffectChance(attack, target, chance));
}
export uint8_t CreatureLib_Script_ModifyIncomingEffectChance(BattleScript* p, const ExecutingAttack* attack,
Creature* target, float* chance) {
Try(p->ModifyIncomingEffectChance(attack, target, chance));
}

View File

@ -86,13 +86,13 @@ export uint8_t CreatureLib_Creature_ClearVolatileScripts(Creature* p) { Try(p->C
export uint8_t CreatureLib_Creature_AddVolatileScriptByName(Creature* p, const char* scriptName) {
Try(p->AddVolatileScript(ArbUt::StringView(scriptName));)
}
export uint8_t CreatureLib_Creature_AddVolatileScript(Creature* p, Script* script) {
export uint8_t CreatureLib_Creature_AddVolatileScript(Creature* p, BattleScript* script) {
Try(p->AddVolatileScript(script);)
}
export uint8_t CreatureLib_Creature_RemoveVolatileScriptByName(Creature* p, const char* scriptName) {
Try(p->RemoveVolatileScript(ArbUt::StringView(scriptName));)
}
export uint8_t CreatureLib_Creature_RemoveVolatileScript(Creature* p, Script* script) {
export uint8_t CreatureLib_Creature_RemoveVolatileScript(Creature* p, BattleScript* script) {
Try(p->RemoveVolatileScript(script);)
}
export bool CreatureLib_Creature_HasVolatileScript(Creature* p, const char* scriptName) {

View File

@ -4,9 +4,10 @@ using namespace CreatureLib::Battling;
export uint8_t CreatureLib_ExecutingAttack_Construct(ExecutingAttack*& out, Creature* const* targets,
size_t targetCount, uint8_t numberHits, Creature* user,
LearnedAttack* attack, Script* script) {
LearnedAttack* attack, BattleScript* script) {
Try(auto ls = ArbUt::List<ArbUt::OptionalBorrowedPtr<Creature>>(targetCount);
for (size_t i = 0; i < targetCount; i++) { ls.Append(targets[i]); } auto s = std::unique_ptr<Script>(script);
for (size_t i = 0; i < targetCount; i++) { ls.Append(targets[i]); } auto s =
std::unique_ptr<BattleScript>(script);
out = new ExecutingAttack(ls, numberHits, user, attack, s);)
}

View File

@ -1,93 +0,0 @@
#include "../../src/Battling/ScriptHandling/Script.hpp"
#include "../Core.hpp"
using namespace CreatureLib::Battling;
export void CreatureLib_Script_Destruct(Script* p) { delete p; }
export uint8_t CreatureLib_Script_Stack(Script* p) { Try(p->Stack()); }
export uint8_t CreatureLib_Script_OnRemove(Script* p) { Try(p->OnRemove()); }
export const char* CreatureLib_Script_GetName(Script* p) { return p->GetName().c_str(); }
export uint8_t CreatureLib_Script_OnBeforeTurn(Script* p, const BaseTurnChoice* choice) {
Try(p->OnBeforeTurn(choice));
}
export uint8_t CreatureLib_Script_ChangeAttack(Script* p, AttackTurnChoice* choice, const char*& outAttack) {
Try(auto sv = ArbUt::StringView(outAttack); p->ChangeAttack(choice, &sv); outAttack = sv.c_str(););
}
export uint8_t CreatureLib_Script_PreventAttack(Script* p, ExecutingAttack* attack, bool* outResult) {
Try(p->PreventAttack(attack, outResult));
}
export uint8_t CreatureLib_Script_FailAttack(Script* p, ExecutingAttack* attack, bool* outResult) {
Try(p->FailAttack(attack, outResult));
}
export uint8_t CreatureLib_Script_StopBeforeAttack(Script* p, ExecutingAttack* attack, bool* outResult) {
Try(p->StopBeforeAttack(attack, outResult));
}
export uint8_t CreatureLib_Script_OnBeforeAttack(Script* p, ExecutingAttack* attack) { Try(p->OnBeforeAttack(attack)); }
export uint8_t CreatureLib_Script_FailIncomingAttack(Script* p, ExecutingAttack* attack, Creature* target,
bool* outResult) {
Try(p->FailIncomingAttack(attack, target, outResult));
}
export uint8_t CreatureLib_Script_IsInvulnerable(Script* p, ExecutingAttack* attack, Creature* target,
bool* outResult) {
Try(p->IsInvulnerable(attack, target, outResult));
}
export uint8_t CreatureLib_Script_OnAttackMiss(Script* p, ExecutingAttack* attack, Creature* target) {
Try(p->OnAttackMiss(attack, target));
}
export uint8_t CreatureLib_Script_ChangeAttackType(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, uint8_t* outType) {
Try(p->ChangeAttackType(attack, target, hitNumber, outType))
}
export uint8_t CreatureLib_Script_OverrideBasePower(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, uint8_t* basePower) {
Try(p->OverrideBasePower(attack, target, hitNumber, basePower));
}
export uint8_t CreatureLib_Script_ChangeDamageStatsUser(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, Creature** statsUser) {
Try(p->ChangeDamageStatsUser(attack, target, hitNumber, statsUser));
}
export uint8_t CreatureLib_Script_BypassDefensiveStat(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, bool* bypass) {
Try(p->BypassDefensiveStat(attack, target, hitNumber, bypass));
}
export uint8_t CreatureLib_Script_BypassOffensiveStat(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, bool* bypass) {
Try(p->BypassOffensiveStat(attack, target, hitNumber, bypass));
}
export uint8_t CreatureLib_Script_ModifyStatModifier(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, float* modifier) {
Try(p->ModifyStatModifier(attack, target, hitNumber, modifier));
}
export uint8_t CreatureLib_Script_ModifyDamageModifier(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, float* modifier) {
Try(p->ModifyDamageModifier(attack, target, hitNumber, modifier));
}
export uint8_t CreatureLib_Script_OverrideDamage(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, uint32_t* damage) {
Try(p->OverrideDamage(attack, target, hitNumber, damage));
}
export uint8_t CreatureLib_Script_PreventSecondaryEffects(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, bool* outResult) {
Try(p->PreventSecondaryEffects(attack, target, hitNumber, outResult));
}
export uint8_t CreatureLib_Script_OnSecondaryEffect(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber) {
Try(p->OnSecondaryEffect(attack, target, hitNumber));
}
export uint8_t CreatureLib_Script_OnAfterHits(Script* p, ExecutingAttack* attack, Creature* target) {
Try(p->OnAfterHits(attack, target));
}
export uint8_t CreatureLib_Script_PreventSelfSwitch(Script* p, const SwitchTurnChoice* choice, bool* outResult) {
Try(p->PreventSelfSwitch(choice, outResult));
}
export uint8_t CreatureLib_Script_ModifyEffectChance(Script* p, const ExecutingAttack* attack, Creature* target,
float* chance) {
Try(p->ModifyEffectChance(attack, target, chance));
}
export uint8_t CreatureLib_Script_ModifyIncomingEffectChance(Script* p, const ExecutingAttack* attack, Creature* target,
float* chance) {
Try(p->ModifyIncomingEffectChance(attack, target, chance));
}

View File

@ -9,7 +9,7 @@ export void CreatureLib_ScriptResolver_Destruct(const ScriptResolver* p) { delet
export uint8_t CreatureLib_ScriptResolver_Initialize(ScriptResolver* p, BattleLibrary* library) {
Try(p->Initialize(library);)
};
export uint8_t CreatureLib_ScriptResolver_LoadScript(Script*& out, ScriptResolver* p, ScriptCategory category,
export uint8_t CreatureLib_ScriptResolver_LoadScript(BattleScript*& out, ScriptResolver* p, ScriptCategory category,
const char* scriptName) {
Try(out = p->LoadScript(category, ArbUt::StringView(scriptName));)
};

View File

@ -29,7 +29,7 @@ export uint8_t CreatureLib_AttackTurnChoice_GetPriority(int8_t& out, AttackTurnC
Try(out = p->GetPriority());
}
SMART_GET_FUNC(AttackTurnChoice, GetAttackScript, Script*)
SMART_GET_FUNC(AttackTurnChoice, GetAttackScript, BattleScript*)
export uint8_t CreatureLib_AttackTurnChoice_GetTargetSideIndex(const AttackTurnChoice* p) {
return p->GetTarget().GetSideIndex();
}

View File

@ -43,6 +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 ArbUt::StringView& scriptName) const {
BattleScript* BattleLibrary::LoadScript(ScriptCategory category, const ArbUt::StringView& scriptName) const {
return _scriptResolver->LoadScript(category, scriptName);
}

View File

@ -41,7 +41,7 @@ namespace CreatureLib::Battling {
return _experienceLibrary;
}
[[nodiscard]] Script* LoadScript(ScriptCategory category, const ArbUt::StringView& scriptName) const;
[[nodiscard]] BattleScript* LoadScript(ScriptCategory category, const ArbUt::StringView& scriptName) const;
};
}

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 {

View File

@ -10,14 +10,17 @@ namespace CreatureLib::Battling {
class ExecutingAttack;
class Creature;
class Script {
class BattleScript {
public:
virtual ~Script() = default;
BattleScript() = default;
NO_COPY_OR_MOVE(BattleScript);
virtual ~BattleScript() = default;
virtual void Stack(){};
virtual void OnRemove(){};
virtual const ArbUt::StringView& GetName() const noexcept = 0;
[[nodiscard]] virtual const ArbUt::StringView& GetName() const noexcept = 0;
virtual void
OnInitialize([[maybe_unused]] const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){};
@ -37,31 +40,31 @@ namespace CreatureLib::Battling {
[[maybe_unused]] bool* outResult){};
virtual void OnAttackMiss([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target){};
virtual void ChangeAttackType([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] uint8_t hitNumber, [[maybe_unused]] uint8_t* outType){};
[[maybe_unused]] u8 hitNumber, [[maybe_unused]] u8* outType){};
virtual void ChangeEffectiveness([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] uint8_t hitNumber, [[maybe_unused]] float* effectiveness){};
[[maybe_unused]] u8 hitNumber, [[maybe_unused]] float* effectiveness){};
virtual void OverrideBasePower([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] uint8_t hitIndex, [[maybe_unused]] uint8_t* basePower){};
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] u8* basePower){};
virtual void ChangeDamageStatsUser([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] uint8_t hitIndex, [[maybe_unused]] Creature** statsUser){};
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] Creature** statsUser){};
virtual void BypassDefensiveStat([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] uint8_t hitIndex, [[maybe_unused]] bool* bypass){};
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] bool* bypass){};
virtual void BypassOffensiveStat([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] uint8_t hitIndex, [[maybe_unused]] bool* bypass){};
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] bool* bypass){};
virtual void ModifyStatModifier([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] uint8_t hitIndex, [[maybe_unused]] float* modifier){};
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] float* modifier){};
virtual void ModifyDamageModifier([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] uint8_t hitIndex, [[maybe_unused]] float* modifier){};
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] float* modifier){};
virtual void OverrideDamage([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] uint8_t hitIndex, [[maybe_unused]] uint32_t* damage){};
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] u32* damage){};
virtual void PreventSecondaryEffects([[maybe_unused]] const ExecutingAttack* attack,
[[maybe_unused]] Creature* target, [[maybe_unused]] uint8_t hitNumber,
[[maybe_unused]] Creature* target, [[maybe_unused]] u8 hitNumber,
[[maybe_unused]] bool* outResult){};
virtual void OnSecondaryEffect([[maybe_unused]] const ExecutingAttack* attack,
[[maybe_unused]] Creature* target, [[maybe_unused]] uint8_t hitNumber){};
[[maybe_unused]] Creature* target, [[maybe_unused]] u8 hitNumber){};
virtual void OnAfterHits([[maybe_unused]] const ExecutingAttack* attack, [[maybe_unused]] Creature* target){};

View File

@ -1,7 +1,7 @@
#ifndef CREATURELIB_SCRIPTAGGREGATOR_HPP
#define CREATURELIB_SCRIPTAGGREGATOR_HPP
#include "Script.hpp"
#include "BattleScript.hpp"
#include "ScriptSet.hpp"
#include "ScriptWrapper.hpp"
@ -45,7 +45,7 @@ namespace CreatureLib::Battling {
}
inline bool HasNext() { return _index < _size; }
std::optional<ArbUt::BorrowedPtr<Script>> GetNextNotNull() {
std::optional<ArbUt::BorrowedPtr<BattleScript>> GetNextNotNull() {
while (HasNext()) {
auto s = GetNext();
return s;
@ -53,7 +53,7 @@ namespace CreatureLib::Battling {
return {};
}
ArbUt::BorrowedPtr<Script> GetNext() {
ArbUt::BorrowedPtr<BattleScript> GetNext() {
auto& current = _scripts[_index];
if (!current.IsSet()) {
auto s = current.GetScript();

View File

@ -1,7 +1,7 @@
#ifndef CREATURELIB_SCRIPTRESOLVER_HPP
#define CREATURELIB_SCRIPTRESOLVER_HPP
#include "Script.hpp"
#include "BattleScript.hpp"
#include "ScriptCategory.hpp"
namespace CreatureLib::Battling {
@ -12,8 +12,8 @@ namespace CreatureLib::Battling {
virtual ~ScriptResolver() = default;
virtual void Initialize([[maybe_unused]] BattleLibrary* library){};
virtual Script* LoadScript([[maybe_unused]] ScriptCategory category,
[[maybe_unused]] const ArbUt::StringView& scriptName) {
virtual BattleScript* LoadScript([[maybe_unused]] ScriptCategory category,
[[maybe_unused]] const ArbUt::StringView& scriptName) {
return nullptr;
};
};

View File

@ -2,11 +2,11 @@
#define CREATURELIB_SCRIPTSET_HPP
#include <any>
#include "Script.hpp"
#include "BattleScript.hpp"
namespace CreatureLib::Battling {
class ScriptSet {
ArbUt::UniquePtrList<Script> _scripts;
ArbUt::UniquePtrList<BattleScript> _scripts;
ArbUt::Dictionary<uint32_t, size_t> _lookup;
public:
@ -15,7 +15,7 @@ namespace CreatureLib::Battling {
static constexpr size_t defaultCapacity = 8;
ScriptSet() : _scripts(defaultCapacity), _lookup(defaultCapacity){};
void Add(Script* script) {
void Add(BattleScript* script) {
auto v = _lookup.TryGet(script->GetName());
if (v.has_value()) {
_scripts[v.value()]->Stack();
@ -27,11 +27,11 @@ namespace CreatureLib::Battling {
_lookup.Insert(script->GetName(), _scripts.Count() - 1);
}
std::optional<ArbUt::BorrowedPtr<Script>> Get(const ArbUt::BasicStringView& key) const {
std::optional<ArbUt::BorrowedPtr<BattleScript>> Get(const ArbUt::BasicStringView& key) const {
return Get(key.GetHash());
}
std::optional<ArbUt::BorrowedPtr<Script>> Get(uint32_t keyHash) const noexcept {
std::optional<ArbUt::BorrowedPtr<BattleScript>> Get(uint32_t keyHash) const noexcept {
auto v = _lookup.TryGet(keyHash);
if (v.has_value()) {
return _scripts[v.value()];
@ -66,7 +66,7 @@ namespace CreatureLib::Battling {
inline size_t Count() const { return _scripts.Count(); }
inline const ArbUt::UniquePtrList<Script>& GetIterator() const { return _scripts; }
inline const ArbUt::UniquePtrList<BattleScript>& GetIterator() const { return _scripts; }
};
}

View File

@ -1,7 +1,7 @@
#ifndef CREATURELIB_SCRIPTWRAPPER_HPP
#define CREATURELIB_SCRIPTWRAPPER_HPP
#include "Script.hpp"
#include "BattleScript.hpp"
#include "ScriptSet.hpp"
namespace CreatureLib::Battling {
@ -9,20 +9,20 @@ namespace CreatureLib::Battling {
bool _isSet;
union {
std::unique_ptr<Script> const* _script;
std::unique_ptr<BattleScript> const* _script;
const ScriptSet* _scriptSet;
};
ScriptWrapper(std::unique_ptr<Script>* s, bool isSet) : _isSet(isSet), _script(s){};
ScriptWrapper(std::unique_ptr<BattleScript>* s, bool isSet) : _isSet(isSet), _script(s){};
ScriptWrapper(ScriptSet* s, bool isSet) : _isSet(isSet), _scriptSet(s){};
public:
static inline ScriptWrapper FromScript(std::unique_ptr<Script>* s) { return ScriptWrapper(s, false); }
static inline ScriptWrapper FromScript(std::unique_ptr<BattleScript>* s) { return ScriptWrapper(s, false); }
static inline ScriptWrapper FromSet(ScriptSet* s) { return ScriptWrapper(s, true); }
inline bool IsSet() const noexcept { return _isSet; }
inline const std::unique_ptr<Script>* GetScript() const noexcept { return _script; }
inline const std::unique_ptr<BattleScript>* GetScript() const noexcept { return _script; }
inline const ScriptSet* GetScriptSet() const noexcept { return _scriptSet; }
inline bool HasValue() const noexcept {

View File

@ -12,7 +12,7 @@ namespace CreatureLib::Battling {
class AttackTurnChoice : public BaseTurnChoice {
ArbUt::BorrowedPtr<LearnedAttack> _attack;
CreatureIndex _target;
std::unique_ptr<Script> _attackScript = nullptr;
std::unique_ptr<BattleScript> _attackScript = nullptr;
int8_t _priority = 0;
void ResolveScript() {
@ -24,8 +24,8 @@ namespace CreatureLib::Battling {
if (_attack->GetAttack()->HasSecondaryEffect()) {
auto library = battle.GetValue()->GetLibrary();
auto& effect = _attack->GetAttack()->GetSecondaryEffect();
_attackScript =
std::unique_ptr<Script>(library->LoadScript(ScriptCategory::Attack, effect->GetEffectName()));
_attackScript = std::unique_ptr<BattleScript>(
library->LoadScript(ScriptCategory::Attack, effect->GetEffectName()));
if (_attackScript != nullptr) {
_attackScript->OnInitialize(effect->GetParameters());
}
@ -41,7 +41,7 @@ namespace CreatureLib::Battling {
_priority = _attack->GetAttack()->GetPriority();
}
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target,
Script* script)
BattleScript* script)
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {
_priority = _attack->GetAttack()->GetPriority();
}
@ -57,7 +57,7 @@ namespace CreatureLib::Battling {
const CreatureIndex& GetTarget() const noexcept { return _target; }
const std::unique_ptr<Script>& GetAttackScript() const noexcept { return _attackScript; }
const std::unique_ptr<BattleScript>& GetAttackScript() const noexcept { return _attackScript; }
size_t ScriptCount() const override { return 1 + GetUser()->ScriptCount(); }
protected:

View File

@ -14,4 +14,14 @@ using level_int_t = uint64_t;
using level_int_t = uint8_t;
#endif
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
#endif // CREATURELIB_DEFINES_HPP

View File

@ -28,6 +28,7 @@
#include <Arbutils/Enum.hpp>
#include <Arbutils/Exception.hpp>
#include <Arbutils/Memory/Memory.hpp>
#include <Arbutils/Misc.hpp>
#include <Arbutils/Precompiled.hxx>
#include <Arbutils/StringView.hpp>

View File

@ -7,7 +7,7 @@
using namespace CreatureLib;
using namespace CreatureLib::Battling;
class TestScript : public Script {
class TestScript : public BattleScript {
private:
ArbUt::StringView _name;
@ -21,8 +21,8 @@ public:
TEST_CASE("Script Aggregator properly iterates containing script.") {
auto script = std::make_unique<TestScript>("test");
auto ran = 0;
auto vec =
ArbUt::List<ScriptWrapper>{ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script))};
auto vec = ArbUt::List<ScriptWrapper>{
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<BattleScript>*>(&script))};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
@ -36,10 +36,10 @@ TEST_CASE("Script Aggregator properly iterates multiple scripts.") {
auto script2 = std::make_unique<TestScript>("test2");
auto script3 = std::make_unique<TestScript>("test3");
auto ran = 0;
auto vec =
ArbUt::List<ScriptWrapper>{ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script)),
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script2)),
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script3))};
auto vec = ArbUt::List<ScriptWrapper>{
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<BattleScript>*>(&script)),
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<BattleScript>*>(&script2)),
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<BattleScript>*>(&script3))};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
@ -49,9 +49,9 @@ TEST_CASE("Script Aggregator properly iterates multiple scripts.") {
}
TEST_CASE("Script Aggregator properly iterates Script Set.") {
Script* script = new TestScript("test");
Script* script2 = new TestScript("test2");
Script* script3 = new TestScript("test3");
BattleScript* script = new TestScript("test");
BattleScript* script2 = new TestScript("test2");
BattleScript* script3 = new TestScript("test3");
auto ran = 0;
auto set = ScriptSet();
set.Add(script);
@ -68,14 +68,15 @@ TEST_CASE("Script Aggregator properly iterates Script Set.") {
TEST_CASE("Script Aggregator properly iterates data of Script Set and Script.") {
auto script = std::make_unique<TestScript>("test");
Script* script2 = new TestScript("test2");
Script* script3 = new TestScript("test3");
BattleScript* script2 = new TestScript("test2");
BattleScript* script3 = new TestScript("test3");
auto ran = 0;
auto set = ScriptSet();
set.Add(script2);
set.Add(script3);
auto vec = ArbUt::List<ScriptWrapper>{
ScriptWrapper::FromSet(&set), ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script))};
ScriptWrapper::FromSet(&set),
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<BattleScript>*>(&script))};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNextNotNull();
@ -86,14 +87,15 @@ TEST_CASE("Script Aggregator properly iterates data of Script Set and Script.")
TEST_CASE("Script Aggregator properly iterates data of Script and Script Set.") {
auto script = std::make_unique<TestScript>("test");
Script* script2 = new TestScript("test2");
Script* script3 = new TestScript("test3");
BattleScript* script2 = new TestScript("test2");
BattleScript* script3 = new TestScript("test3");
auto ran = 0;
auto set = ScriptSet();
set.Add(script2);
set.Add(script3);
auto vec = ArbUt::List<ScriptWrapper>{
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script)), ScriptWrapper::FromSet(&set)};
auto vec =
ArbUt::List<ScriptWrapper>{ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<BattleScript>*>(&script)),
ScriptWrapper::FromSet(&set)};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNextNotNull();
@ -104,16 +106,17 @@ TEST_CASE("Script Aggregator properly iterates data of Script and Script Set.")
TEST_CASE("Script Aggregator properly iterates data of Script, Script Set and Script.") {
auto script = std::make_unique<TestScript>("test");
Script* script2 = new TestScript("test2");
Script* script3 = new TestScript("test3");
BattleScript* script2 = new TestScript("test2");
BattleScript* script3 = new TestScript("test3");
auto script4 = std::make_unique<TestScript>("test4");
auto ran = 0;
auto set = ScriptSet();
set.Add(script2);
set.Add(script3);
auto vec = ArbUt::List<ScriptWrapper>{
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script)), ScriptWrapper::FromSet(&set),
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script4))};
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<BattleScript>*>(&script)),
ScriptWrapper::FromSet(&set),
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<BattleScript>*>(&script4))};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNextNotNull();

View File

@ -7,7 +7,7 @@
using namespace CreatureLib;
using namespace CreatureLib::Battling;
class TestScript : public Script {
class TestScript : public BattleScript {
private:
ArbUt::StringView _name;

View File

@ -6,7 +6,7 @@
using namespace CreatureLib;
using namespace CreatureLib::Battling;
class TestScript : public Script {
class TestScript : public BattleScript {
private:
ArbUt::StringView _name;
@ -19,7 +19,7 @@ public:
class ScriptSourceWithScriptPtr : public ScriptSource {
public:
std::unique_ptr<Script> ScriptPtr = nullptr;
std::unique_ptr<BattleScript> ScriptPtr = nullptr;
protected:
size_t ScriptCount() const override { return 1; }